# HG changeset patch # User Richard Westhaver # Date 1723779394 14400 # Node ID 5b2ca5b2a9db45bf815b71bf2635363c5b013437 # Parent 46e9425cf3c2792f6b9c13076d08bcaeec785626 rocksdb merge-op progress diff -r 46e9425cf3c2 -r 5b2ca5b2a9db lisp.sk --- a/lisp.sk Thu Aug 15 21:54:36 2024 -0400 +++ b/lisp.sk Thu Aug 15 23:36:34 2024 -0400 @@ -2,4 +2,8 @@ :name "core/lisp" :src "lisp" :description "CC Lisp Core" -:components ((:lisp-system "prelude.asd") (:lisp-system "user.asd") (:lisp-system "core.asd")) +:components +((:lisp-system "prelude.asd") + (:lisp-system "user.asd") + (:lisp-system "core.asd") + (:lisp-system "std/std.asd")) diff -r 46e9425cf3c2 -r 5b2ca5b2a9db lisp/ffi/rocksdb/merge.lisp --- a/lisp/ffi/rocksdb/merge.lisp Thu Aug 15 21:54:36 2024 -0400 +++ b/lisp/ffi/rocksdb/merge.lisp Thu Aug 15 23:36:34 2024 -0400 @@ -34,6 +34,16 @@ ;;; Code: (in-package :rocksdb) +#| +Gives the client a way to express the read -> modify -> write semantics +key: (IN) The key that's associated with this merge operation. +existing: (IN) null indicates that the key does not exist before this op +operand_list:(IN) the sequence of merge operations to apply, front() first. +new_value: (OUT) Client is responsible for filling the merge result here +logger: (IN) Client could use this to log errors during merge. + +Return true on success. Return false failure / error / corruption. +|# ;; FullMerge() is used when a Put/Delete is the *existing_value (or null) (define-alien-type rocksdb-full-merge-function (function (* t) @@ -44,6 +54,13 @@ int (array unsigned-char) (* size-t))) + +#| +This function performs merge(left_op, right_op) +when both the operands are themselves merge operation types. +Save the result in *new_value and return true. If it is impossible +or infeasible to combine the two operations, return false instead. +|# ;; PartialMerge() is used to combine two-merge operands (if possible) (define-alien-type rocksdb-partial-merge-function (function (* t) @@ -63,6 +80,11 @@ (define-alien-type rocksdb-destructor-function (function void (* t))) +#| +The name of the MergeOperator. Used to check for MergeOperator +mismatches (i.e., a DB created with one MergeOperator is +accessed using a different MergeOperator) +|# (define-alien-type rocksdb-name-function (function c-string)) @@ -76,7 +98,7 @@ (full-merge (* rocksdb-full-merge-function)) (partial-merge (* rocksdb-partial-merge-function)) (delete-value (* rocksdb-delete-value-function)) - (name c-string)) + (name (* rocksdb-name-function))) #| [[file:~/dev/comp/core/c/rocksdb.h::/* Merge Operator */]] |# @@ -101,7 +123,7 @@ (define-alien-callable rocksdb-name c-string () (make-alien-string (symbol-name (gensym "rocksdb:")))) -(define-alien-callable rocksdb-concat-full-merge (* t) +(define-alien-callable rocksdb-concat-full-merge boolean ((key (array unsigned-char)) (klen size-t) (existing-val (array unsigned-char)) @@ -112,9 +134,9 @@ (success (array unsigned-char)) (new-vlen (* size-t))) (log:debug! (list key klen existing-val existing-vlen ops ops-length num-ops success new-vlen)) - nil) + 1) -(define-alien-callable rocksdb-concat-partial-merge (* t) +(define-alien-callable rocksdb-concat-partial-merge boolean ((key (array unsigned-char)) (klen size-t) (ops (array (array unsigned-char))) @@ -123,4 +145,4 @@ (success (array unsigned-char)) (new-vlen (* size-t))) (log:debug! (list key klen ops ops-length num-ops success new-vlen)) - nil) + 0) diff -r 46e9425cf3c2 -r 5b2ca5b2a9db lisp/ffi/rocksdb/pkg.lisp --- a/lisp/ffi/rocksdb/pkg.lisp Thu Aug 15 21:54:36 2024 -0400 +++ b/lisp/ffi/rocksdb/pkg.lisp Thu Aug 15 23:36:34 2024 -0400 @@ -77,7 +77,10 @@ :*rocksdb-properties* :rocksdb-num-files-at-level :rocksdb-compression-ratio-at-level - :rocksdb-aggregated-table-properties-at-level)) + :rocksdb-aggregated-table-properties-at-level + :rocksdb-concat-partial-merge + :rocksdb-concat-full-merge + :rocksdb-name)) (in-package :rocksdb) diff -r 46e9425cf3c2 -r 5b2ca5b2a9db lisp/ffi/rocksdb/rocksdb.asd --- a/lisp/ffi/rocksdb/rocksdb.asd Thu Aug 15 21:54:36 2024 -0400 +++ b/lisp/ffi/rocksdb/rocksdb.asd Thu Aug 15 23:36:34 2024 -0400 @@ -8,7 +8,7 @@ ;;; Code: (defsystem "rocksdb" - :depends-on (:std) + :depends-on (:std :log) :serial t :components ((:file "pkg") (:file "macs") diff -r 46e9425cf3c2 -r 5b2ca5b2a9db lisp/ffi/rocksdb/tests.lisp --- a/lisp/ffi/rocksdb/tests.lisp Thu Aug 15 21:54:36 2024 -0400 +++ b/lisp/ffi/rocksdb/tests.lisp Thu Aug 15 23:36:34 2024 -0400 @@ -373,4 +373,26 @@ (deftest merge () "Test low-level merge-operator functionality using ALIEN-CALLBACKs." - nil) + (is (with-alien ((k (array unsigned-char)) + (v (array unsigned-char)) + (ops (array (array unsigned-char))) + (s (array unsigned-char))) + (alien-funcall + (alien-callable-function + 'rocksdb-concat-full-merge) + k 0 v 0 ops (make-alien size-t 0) 0 s (make-alien size-t 0)))) + (is + (not + (with-alien ((k (array unsigned-char)) + (ops (array (array unsigned-char))) + (s (array unsigned-char))) + (alien-funcall + (alien-callable-function + 'rocksdb-concat-partial-merge) + k 0 ops (make-alien size-t 0) 0 s (make-alien size-t 0))))) + (alien-callable-function 'rocksdb-concat-full-merge) + (alien-callable-function 'rocksdb-concat-partial-merge) + (is (integerp + (parse-integer + (string-trim "rocksdb:" (alien-funcall (alien-callable-function 'rocksdb-name))))))) +