Mercurial > core / lisp/ffi/rocksdb/merge.lisp
changeset 611: |
57813b8ee029 |
parent: |
1a5828267b90
|
child: |
c48704d7b06f |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Mon, 19 Aug 2024 19:25:55 -0400 |
permissions: |
-rw-r--r-- |
description: |
more rocksdb work, slice -> slicetransform |
1 ;;; rocksdb/merge.lisp --- RocksDB Merge Operators 3 ;; RocksDB Lisp Merge Operator API 7 ;; When to use built-in ROCKSDB-MERGE: 9 ;; - You have data that needs to be incrementally updated. 11 ;; - You would usually need to read the data before knowing what the new value would be. 13 ;; Oterwise as far as the FFI is concerned - which doesn't support 14 ;; AssociateMerge, you should use the Generic Merge API. 16 ;; When to use Associative Merge (unavailable in C/LISP API): 18 ;; - merge operands are formatted the same as Put values AND 20 ;; - it is okay to combine multiple operands into one 22 ;; When to use Generic Merge (this API): 24 ;; - you are unable to use Associate Merge 26 ;; - it is possible to combine multiple operands 30 ;; impl: https://github.com/facebook/rocksdb/wiki/Merge-Operator-Implementation 32 ;; wiki: https://github.com/facebook/rocksdb/wiki/merge-operator 37 (defvar *rocksdb-partial-merge-lambda-list* 38 '((key (array unsigned-char)) 40 (ops (array (array unsigned-char))) 41 (ops-length (* size-t)) 43 (success (array unsigned-char)) 44 (new-vlen (* size-t)))) 46 (defvar *rocksdb-full-merge-lambda-list* 47 '((key (array unsigned-char)) 49 (existing-val (array unsigned-char)) 50 (existing-vlen size-t) 51 (ops (array (array unsigned-char))) 52 (ops-length (* size-t)) 54 (success (array unsigned-char)) 55 (new-vlen (* size-t)))) 58 Gives the client a way to express the read -> modify -> write semantics 59 key: (IN) The key that's associated with this merge operation. 60 existing: (IN) null indicates that the key does not exist before this op 61 operand_list:(IN) the sequence of merge operations to apply, front() first. 62 new_value: (OUT) Client is responsible for filling the merge result here 63 logger: (IN) Client could use this to log errors during merge. 65 Return true on success. Return false failure / error / corruption. 67 ;; FullMerge() is used when a Put/Delete is the *existing_value (or null) 68 (define-alien-type rocksdb-full-merge-function 72 (array (array unsigned-char)) 79 This function performs merge(left_op, right_op) 80 when both the operands are themselves merge operation types. 81 Save the result in *new_value and return true. If it is impossible 82 or infeasible to combine the two operations, return false instead. 84 ;; PartialMerge() is used to combine two-merge operands (if possible) 85 (define-alien-type rocksdb-partial-merge-function 89 (array (array unsigned-char)) 95 (define-alien-type rocksdb-delete-value-function 100 (define-alien-type rocksdb-destructor-function 101 (function void (* t))) 104 The name of the MergeOperator. Used to check for MergeOperator 105 mismatches (i.e., a DB created with one MergeOperator is 106 accessed using a different MergeOperator) 108 (define-alien-type rocksdb-name-function 111 ;; (sb-alien::define-alien-callable mangle int () 0) 113 (define-alien-routine rocksdb-mergeoperator-create (* rocksdb-mergeoperator) 115 (destructor (* rocksdb-destructor-function)) 116 (full-merge (* rocksdb-full-merge-function)) 117 (partial-merge (* rocksdb-partial-merge-function)) 118 (delete-value (* rocksdb-delete-value-function)) 119 (name (* rocksdb-name-function))) 121 #| [[file:~/dev/comp/core/c/rocksdb.h::/* Merge Operator */]] |# 123 (define-alien-routine rocksdb-mergeoperator-destroy void (self (* rocksdb-mergeoperator))) 125 (define-alien-callable rocksdb-destructor void ((self (* t))) 129 (define-alien-callable rocksdb-name c-string () (make-alien-string (symbol-name (gensym "rocksdb:")))) 131 ;;; Associative Merge 134 (define-alien-callable rocksdb-concat-merge-name c-string () (make-alien-string "cc:concat")) 136 (define-alien-callable rocksdb-concat-full-merge boolean 137 ((key (array unsigned-char)) 139 (existing-val (array unsigned-char)) 140 (existing-vlen size-t) 141 (ops (array (array unsigned-char))) 142 (ops-length (* size-t)) 144 (success (array unsigned-char)) 145 (new-vlen (* size-t))) 146 (log:debug! (list key klen existing-val existing-vlen ops ops-length num-ops success new-vlen)) 149 (define-alien-callable rocksdb-concat-partial-merge boolean 150 ((key (array unsigned-char)) 152 (ops (array (array unsigned-char))) 153 (ops-length (* size-t)) 155 (success (array unsigned-char)) 156 (new-vlen (* size-t))) 157 (log:debug! (list key klen ops ops-length num-ops success new-vlen)) 160 (define-alien-callable rocksdb-delete-value void 163 (value-length size-t)) 164 (declare (ignore state)) 165 ;; TODO 2024-08-18: test if this is needed 166 (unless (zerop value-length) 167 (log:trace! "deleting value:" value)