Mercurial > core / lisp/ffi/rocksdb/pkg.lisp
changeset 82: |
a606978326c7 |
parent: |
763fe90be2e6
|
child: |
dcab745f42ba |
author: |
ellis <ellis@rwest.io> |
date: |
Thu, 07 Dec 2023 22:40:32 -0500 |
permissions: |
-rw-r--r-- |
description: |
rocksdb ffi |
1 ;;; rocksdb.lisp --- low-level bindings to the RocksDB C API 3 ;; for the high-level interface, see rdb.lisp. 7 ;; if ur on archlinux and installed rocksdb via AUR you may receive an error from 8 ;; jemalloc: cannot allocate memory in static TLS block: 10 ;; https://github.com/veer66/cl-rocksdb/issues/1 12 ;; for best results, you should compile rocksdb from source - use j0ni's snippet as a 15 ;; make shared_lib DISABLE_JEMALLOC=1 && 16 ;; sudo cp librocksdb.so.* /usr/local/lib/ && 17 ;; sudo cp -rf include/* /usr/local/include/ 19 ;; https://github.com/facebook/rocksdb/blob/main/Makefile 21 ;; check /usr/local/include/rocksdb/c.h for the C API header, the source is under 24 ;; here are some important notes to keepin mind (from the API header): 26 C bindings for rocksdb. May be useful as a stable ABI that can be 27 used by programs that keep rocksdb in a shared library, or for 31 . getters for the option types 32 . custom comparators that implement key shortening 33 . capturing post-write-snapshot 34 . custom iter, db, env, cache implementations using just the C bindings 38 (1) We expose just opaque struct pointers and functions to clients. 39 This allows us to change internal representations without having to 42 (2) For simplicity, there is no equivalent to the Slice type. Instead, 43 the caller has to pass the pointer and length as separate 46 (3) Errors are represented by a null-terminated c string. NULL 47 means no error. All operations that can raise an error are passed 48 a "char** errptr" as the last argument. One of the following must 51 *errptr points to a malloc()ed null-terminated error message 52 On success, a leveldb routine leaves *errptr unchanged. 53 On failure, leveldb frees the old value of *errptr and 54 set *errptr to a malloc()ed error message. 56 (4) Bools have the type unsigned char (0 == false; rest == true) 58 (5) All of the pointer arguments must be non-NULL.|# 61 (defpackage :rocksdb/pkg 63 (:use :cl :std/base :std/alien :std/fu :std/sym) 64 (:import-from :std/fu :symb) 75 :rocksdb-checkpoint-object-create 76 :rocksdb-checkpoint-create 77 :rocksdb-open-column-families 78 :rocksdb-list-column-families-destroy 79 :rocksdb-list-column-families 80 :rocksdb-create-column-family 81 :rocksdb-create-column-families 82 :rocksdb-create-column-families-destroy 83 :rocksdb-drop-column-family 84 :rocksdb-column-family-handle-destroy 85 :rocksdb-column-family-handle-get-id 86 :rocksdb-column-family-handle-get-name 92 :rocksdb-get-cf-with-ts 98 :rocksdb-delete-range-cf 100 :rocksdb-multi-get-with-ts 101 :rocksdb-multi-get-cf 102 :rocksdb-multi-get-cf-with-ts 103 :rocksdb-batched-multi-get-cf 104 :rocksdb-cancel-all-background-work 106 :rocksdb-writebatch-create 107 :rocksdb-writebatch-create-from 108 :rocksdb-writebatch-destroy 109 :rocksdb-writebatch-clear 110 :rocksdb-writebatch-count 111 :rocksdb-writebatch-put 112 :rocksdb-writebatch-put-cf 113 :rocksdb-writebatch-put-cf-with-ts 114 :rocksdb-writebatch-putv 115 :rocksdb-writebatch-putv-cf 116 :rocksdb-writebatch-merge 117 :rocksdb-writebatch-mergev-cf 118 :rocksdb-writebatch-delete 119 :rocksdb-writebatch-delete-cf 120 :rocksdb-writebatch-delete-cf-with-ts 121 :rocksdb-writebatch-singledelete-cf 122 :rocksdb-writebatch-singledelete-cf-with-ts 123 :rocksdb-writebatch-deletev 124 :rocksdb-writebatch-deletev-cf 125 :rocksdb-writebatch-deletev-cf-with-ts 126 :rocksdb-writebatch-delete-range 127 :rocksdb-writebatch-delete-range-cf 128 :rocksdb-writebatch-delete-rangev 129 :rocksdb-writebatch-delete-rangev-cf 130 :rocksdb-writebatch-put-log-data 131 :rocksdb-writebatch-iterate 132 :rocksdb-writebatch-data 133 :rocksdb-writebatch-set-save-point 134 :rocksdb-writebatch-rollback-to-save-point 135 :rocksdb-writebatch-pop-save-point 138 :rocksdb-flushoptions-create 139 :rocksdb-flushoptions-destroy 140 :rocksdb-flushoptions-get-wait 141 :rocksdb-flushoptions-set-wait 147 :rocksdb-cache-create-lru 148 ;; BLOCK-BASED OPTIONS 149 :rocksdb-block-based-table-options 150 :rocksdb-block-based-options-create 151 :rocksdb-block-based-options-destroy 152 :rocksdb-block-based-options-set-block-cache 155 :rocksdb-load-latest-options 156 :rocksdb-load-latest-options-destroy 158 :rocksdb-set-options-cf 160 :rocksdb-options-create 161 :rocksdb-options-destroy 162 :rocksdb-options-increase-parallelism 163 :rocksdb-options-optimize-for-point-lookup 164 :rocksdb-options-optimize-level-style-compaction 165 :rocksdb-options-optimize-universal-style-compaction 166 :rocksdb-options-set-allow-ingest-behind 167 :rocksdb-options-get-allow-ingest-behind 168 :rocksdb-options-set-compaction-filter 169 :rocksdb-options-set-compaction-filter-factory 170 :rocksdb-options-compaction-readahead-size 171 :rocksdb-options-get-compaction-readahead-size 172 :rocksdb-options-set-comparator 173 :rocksdb-options-set-merge-operator 174 :rocksdb-options-set-uint64add-merge-operator 175 :rocksdb-options-set-compression-per-level 176 :rocksdb-options-set-create-if-missing 177 :rocksdb-options-get-create-if-missing 178 :rocksdb-options-set-create-missing-column-families 179 :rocksdb-options-get-create-missing-column-families 180 :rocksdb-options-set-error-if-exists 181 :rocksdb-options-get-error-if-exists 182 :rocksdb-options-set-paranoid-checks 183 :rocksdb-options-get-paranoid-checks 184 :rocksdb-options-set-db-paths 185 :rocksdb-options-set-env 186 :rocksdb-options-set-info-log 187 :rocksdb-options-set-info-log-level 188 :rocksdb-options-get-info-log-level 189 :rocksdb-options-set-write-buffer-size 190 :rocksdb-options-get-write-buffer-size 191 :rocksdb-options-set-db-write-buffer-size 192 :rocksdb-options-get-db-write-buffer-size 193 :rocksdb-options-set-max-open-files 194 :rocksdb-options-get-max-open-files 195 :rocksdb-options-set-max-total-wal-size 196 :rocksdb-options-get-max-total-wal-size 197 :rocksdb-options-set-compression-options 198 :rocksdb-options-set-compression-options-zstd-max-train-bytes 199 :rocksdb-options-get-compression-options-zstd-max-train-bytes 200 :rocksdb-options-set-compression-options-use-zstd-dict-trainer 201 :rocksdb-options-get-compression-options-use-zstd-dict-trainer 202 :rocksdb-options-set-compression-options-parallel-threads 203 :rocksdb-options-get-compression-options-parallel-threads 204 :rocksdb-options-set-compression-options-max-dict-buffer-bytes 205 :rocksdb-options-get-compression-options-max-dict-buffer-bytes 206 :rocksdb-options-set-block-based-table-factory 208 :rocksdb-options-set-enable-blob-files 209 :rocksdb-options-get-enable-blob-files 210 :rocksdb-options-set-min-blob-size 211 :rocksdb-options-set-blob-file-size 212 :rocksdb-options-set-blob-compression-type 213 :rocksdb-options-get-blob-compression-type 214 :rocksdb-options-set-enable-blob-gc 215 :rocksdb-options-get-enable-blob-gc 216 :rocksdb-options-set-blob-gc-age-cutoff 217 :rocksdb-options-get-blob-gc-age-cutoff 218 :rocksdb-options-set-blob-gc-force-threshold 219 :rocksdb-options-get-blob-gc-force-threshold 220 :rocksdb-options-set-blob-compaction-readahead-size 221 :rocksdb-options-get-blob-compaction-readahead-size 222 :rocksdb-options-set-blob-file-starting-level 223 :rocksdb-options-set-blob-cache 224 :rocksdb-options-set-prepopulate-blob-cache 225 :rocksdb-options-get-prepopulate-blob-cache 228 :rocksdb-readoptions-create 229 :rocksdb-readoptions-destroy 231 :rocksdb-writeoptions 232 :rocksdb-writeoptions-create 233 :rocksdb-writeoptions-destroy 235 :rocksdb-compactoptions 236 :rocksdb-compact-range-cf 237 :rocksdb-suggest-compact-range 238 :rocksdb-suggest-compact-range-cf 239 :rocksdb-compact-range-opt 240 :rocksdb-compact-range-cf-opt 243 :rocksdb-iter-seek-to-first 244 :rocksdb-iter-seek-to-last 246 :rocksdb-iter-seek-for-prev 249 :rocksdb-create-iterator 252 :rocksdb-iter-timestamp 253 :rocksdb-iter-destroy 255 :rocksdb-iter-get-error 256 :rocksdb-get-updates-since 257 :rocksdb-create-iterator-cf 258 :rocksdb-create-iterators 259 :rocksdb-create-snapshot 260 :rocksdb-release-snapshot 261 :rocksdb-property-value 262 :rocksdb-property-int 263 :rocksdb-property-int-cf 264 :rocksdb-property-value-cf 265 :rocksdb-approximate-sizes 266 :rocksdb-approximate-sizes-cf 267 :rocksdb-wal-iter-next 268 :rocksdb-wal-iter-valid 269 :rocksdb-wal-iter-status 270 :rocksdb-wal-iter-get-batch 271 :rocksdb-wal-iter-destroy)) 273 (in-package :rocksdb) 275 (defun load-rocksdb () 276 (unless (member :rocksdb *features*) 277 (sb-alien:load-shared-object "librocksdb.so" :dont-save t) 278 (push :rocksdb *features*))) 283 (defmacro with-errptr (name result-type &rest args) 284 `(define-alien-routine ,name ,result-type ,@args (errptr rocksdb-errptr))) 286 (defmacro define-opt (name &rest fields) 288 (define-alien-type ,name (struct ,(symbolicate name '-t))) 289 (define-alien-routine ,(symbolicate name '-create) (* ,name)) 290 (define-alien-routine ,(symbolicate name '-destroy) void 297 'define-alien-routine 298 (symbolicate name '-set- (car f)) 304 'define-alien-routine 305 (symbolicate name '-set- f) 310 (defmacro define-opaque (ty) `(define-alien-type ,ty (struct ,(symbolicate ty '-t)))) 313 (define-alien-type rocksdb-errptr (* t)) 315 (define-opaque rocksdb) 316 (define-opaque rocksdb) 317 (define-opaque rocksdb-iterator) 318 (define-opaque rocksdb-backup-engine) 319 (define-opaque rocksdb-backup-engine-info) 320 (define-opaque rocksdb-backup-engine-options) 321 (define-opaque rocksdb-restore-options) 322 (define-opaque rocksdb-memory-allocator) 323 (define-opaque rocksdb-lru-cache-options) 324 (define-opaque rocksdb-hyper-clock-cache-options) 325 (define-opaque rocksdb-cache) 326 (define-opaque rocksdb-compactionfilter) 327 (define-opaque rocksdb-compactionfiltercontext) 328 (define-opaque rocksdb-compactionfilterfactory) 329 (define-opaque rocksdb-comparator) 330 (define-opaque rocksdb-dbpath) 331 (define-opaque rocksdb-env) 332 (define-opaque rocksdb-fifo-compaction-options) 333 (define-opaque rocksdb-filelock) 334 (define-opaque rocksdb-filterpolicy) 335 (define-opaque rocksdb-logger) 336 (define-opaque rocksdb-mergeoperator) 337 (define-opaque rocksdb-compactoptions) 338 (define-opaque rocksdb-cuckoo-table-options) 339 (define-opaque rocksdb-randomfile) 340 (define-opaque rocksdb-seqfile) 341 (define-opaque rocksdb-slicetransform) 342 (define-opaque rocksdb-snapshot) 343 (define-opaque rocksdb-writeablefile) 344 (define-opaque rocksdb-writebatch) 345 (define-opaque rocksdb-livefiles) 346 (define-opaque rocksdb-column-family-handle) 347 (define-opaque rocksdb-column-family-metadata) 348 (define-opaque rocksdb-level-metadata) 349 (define-opaque rocksdb-sst-file-metadata) 350 (define-opaque rocksdb-envoptions) 351 (define-opaque rocksdb-ingestexternalfileoptions) 352 (define-opaque rocksdb-sstfilewriter) 353 (define-opaque rocksdb-ratelimiter) 354 (define-opaque rocksdb-perfcontext) 355 (define-opaque rocksdb-pinnableslice) 356 (define-opaque rocksdb-transactiondb-options) 357 (define-opaque rocksdb-transactiondb) 358 (define-opaque rocksdb-transaction-options) 359 (define-opaque rocksdb-optimistictransactiondb) 360 (define-opaque rocksdb-optimistictransaction-options) 361 (define-opaque rocksdb-transaction) 362 (define-opaque rocksdb-checkpoint) 363 (define-opaque rocksdb-wal-iterator) 364 (define-opaque rocksdb-wal-readoptions) 365 (define-opaque rocksdb-memory-comsumers) 366 (define-opaque rocksdb-memory-usage) 367 (define-opaque rocksdb-universal-compaction-options) 368 (define-opaque rocksdb-statistics-histogram-data) 371 (define-opt rocksdb-block-based-options 374 (cache-index-and-filter-blocks 377 (define-opt rocksdb-options 379 (block-based-table-factory 380 (table-options (* rocksdb-block-based-table-options))) 381 (allow-ingest-behind (val unsigned-char)) 382 (merge-operator (comparator (* rocksdb-comparator)))) 384 (define-opt rocksdb-writeoptions) 385 (define-opt rocksdb-readoptions) 386 (define-opt rocksdb-flushoptions 387 (wait (val unsigned-char))) 389 (define-alien-routine rocksdb-options-increase-parallelism void 390 (opt (* rocksdb-options)) (total-threads int)) 392 (define-alien-routine rocksdb-options-optimize-level-style-compaction void 393 (opt (* rocksdb-options)) 394 (memtable-memory-budget unsigned-long)) 396 (define-alien-routine rocksdb-flushoptions-get-wait unsigned-char (* rocksdb-flushoptions)) 398 (with-errptr rocksdb-load-latest-options 401 (env (* rocksdb-env)) 402 (ignore-unknown-options boolean) 403 (cache (* rocksdb-cache)) 404 (db-options (* (* rocksdb-options))) 405 (num-column-families (* size-t)) 406 (column-family-names (* (* c-string))) 407 (column-family-options (* (* (* rocksdb-options))))) 409 (define-alien-routine rocksdb-load-latest-options-destroy void 410 (db-options (* (* rocksdb-options))) 411 (list-column-family-names (* c-string)) 412 (list-column-family-options (* (* rocksdb-options))) 420 (keys (array c-string)) 421 (values (array c-string))) 423 (with-errptr rocksdb-set-options-cf 426 (handle (* rocksdb-column-family-handle)) 428 (keys (array c-string)) 429 (values (array c-string))) 432 (with-errptr rocksdb-open (* rocksdb) 433 (opt (* rocksdb-options)) 436 (define-alien-routine rocksdb-close void 439 (define-alien-routine rocksdb-cancel-all-background-work void 443 (with-errptr rocksdb-put 446 (options (* rocksdb-writeoptions)) 452 (with-errptr rocksdb-get 455 (options (* rocksdb-readoptions)) 460 (with-errptr rocksdb-delete 463 (options (* rocksdb-writeoptions)) 467 (with-errptr rocksdb-merge 470 (opt (* rocksdb-writeoptions)) 476 (with-errptr rocksdb-merge-cf 479 (opt (* rocksdb-writeoptions)) 480 (cf (* rocksdb-column-family-handle)) 486 (with-errptr rocksdb-write 489 (opt (* rocksdb-writeoptions)) 490 (batch (* rocksdb-writebatch))) 492 (with-errptr rocksdb-get-cf 495 (opt (* rocksdb-readoptions)) 500 (define-alien-routine rocksdb-multi-get void 502 (opt (* rocksdb-readoptions)) 504 (keys-list (array c-string)) 505 (keys-list-sizes (array size-t)) 506 (values-list (array c-string)) 507 (values-list-sizes (array size-t)) 508 (errs (array rocksdb-errptr))) 510 (define-alien-routine rocksdb-multi-get-cf void 512 (opt (* rocksdb-readoptions)) 513 (cfs (array rocksdb-column-family-handle)) 515 (keys-list (array c-string)) 516 (keys-list-sizes (array size-t)) 517 (values-list (array c-string)) 518 (values-list-sizes (array size-t)) 519 (errs (array rocksdb-errptr))) 521 (define-alien-routine rocksdb-cache-create-lru (* rocksdb) (capacity unsigned-int)) 523 (with-errptr rocksdb-flush void 525 (options (* rocksdb-flushoptions))) 528 (with-errptr rocksdb-create-column-family 529 (* rocksdb-column-family-handle) 531 (column-family-options (* rocksdb-options)) 532 (column-family-name c-string)) 534 (with-errptr rocksdb-create-column-families 535 (array rocksdb-column-family-handle) 537 (column-family-options (* rocksdb-options)) 538 (num-column-familes int) 539 (column-family-names (array c-string)) 542 (define-alien-routine rocksdb-create-column-families-destroy void 543 (list (array rocksdb-column-family-handle))) 545 (define-alien-routine rocksdb-column-family-handle-destroy void 546 (* rocksdb-column-family-handle)) 548 (define-alien-routine rocksdb-column-family-handle-get-id unsigned-int 549 (* rocksdb-column-family-handle)) 551 (define-alien-routine rocksdb-column-family-handle-get-name c-string 552 (handle (* rocksdb-column-family-handle)) 553 (name-len (* size-t))) 555 (with-errptr rocksdb-drop-column-family 558 (handle (* rocksdb-column-family-handle))) 560 (with-errptr rocksdb-open-column-families 562 (options (* rocksdb-options)) 564 (num-column-families int) 565 (column-family-names (array c-string)) 566 (column-family-options (array rocksdb-options)) 567 (column-family-handles (array rocksdb-column-family-handle))) 569 (with-errptr rocksdb-list-column-families 571 (opt (* rocksdb-options)) 575 (define-alien-routine rocksdb-list-column-families-destroy void 576 (list (array c-string)) 579 (with-errptr rocksdb-put-cf 582 (opt (* rocksdb-writeoptions)) 583 (cf (* rocksdb-column-family-handle)) 589 (with-errptr rocksdb-delete-cf 592 (options (* rocksdb-writeoptions)) 593 (cf (* rocksdb-column-family-handle)) 597 (with-errptr rocksdb-delete-range-cf 600 (options (* rocksdb-writeoptions)) 601 (cf (* rocksdb-column-family-handle)) 603 (start-key-len size-t) 605 (end-key-len size-t)) 607 (with-errptr rocksdb-destroy-db void 608 (opts (* rocksdb-options)) 612 (define-alien-routine rocksdb-create-iterator (* rocksdb-iterator) 614 (opt (* rocksdb-readoptions))) 615 (define-alien-routine rocksdb-iter-destroy void 616 (iter (* rocksdb-iterator))) 617 (define-alien-routine rocksdb-iter-seek-to-first void 618 (iter (* rocksdb-iterator))) 619 (define-alien-routine rocksdb-iter-valid boolean 620 (iter (* rocksdb-iterator))) 621 (define-alien-routine rocksdb-iter-next void 622 (iter (* rocksdb-iterator))) 623 (define-alien-routine rocksdb-iter-prev void 624 (iter (* rocksdb-iterator))) 625 (define-alien-routine rocksdb-iter-key (* char) 626 (iter (* rocksdb-iterator)) 627 (klen-ptr (* size-t))) 628 (define-alien-routine rocksdb-iter-value (* char) 629 (iter (* rocksdb-iterator)) 630 (vlen-ptr (* size-t)))