changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/ffi/rocksdb/compaction.lisp

changeset 698: 96958d3eb5b0
parent: 57813b8ee029
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; rocksdb/compaction.lisp --- RocksDB Compaction
2 
3 ;; RocksDB Lisp Compaction Filter API
4 
5 ;;; Commentary:
6 
7 ;; compaction filters are like custom GC rules for the database. compactions
8 ;; run in the background and can be configured via the column-family-options
9 ;; or compactionfilterfactory API.
10 
11 ;; ref: https://github.com/facebook/rocksdb/wiki/Compaction-Filter
12 
13 #|
14 * RocksDB snapshots do not guarantee to preserve the state of the DB in the
15 presence of CompactionFilter. Data seen from a snapshot might disappear after
16 a table file created with a `CompactionFilter` is installed. If you use
17 snapshots, think twice about whether you want to use `CompactionFilter` and
18 whether you are using it in a safe way.
19 
20 * If multithreaded compaction is being used *and* a single CompactionFilter
21 instance was supplied via Options::compaction_filter, CompactionFilter
22 methods may be called from different threads concurrently. The application
23 must ensure that such calls are thread-safe. If the CompactionFilter was
24 created by a factory, then it will only ever be used by a single thread that
25 is doing the table file creation, and this call does not need to be
26 thread-safe. However, multiple filters may be in existence and operating
27 concurrently.
28 
29 * The key passed to the filtering methods includes the timestamp if
30 user-defined timestamps are enabled.
31 
32 * Exceptions MUST NOT propagate out of overridden functions into RocksDB,
33 because RocksDB is not exception-safe. This could cause undefined behavior
34 including data loss, unreported corruption, deadlocks, and more.
35 |#
36 ;;; Code:
37 (in-package :rocksdb)
38 
39 (define-alien-type rocksdb-filter-function
40  (function unsigned-char
41  (* t)
42  int
43  c-string
44  size-t
45  c-string
46  size-t
47  (* (array unsigned-char))
48  (* size-t)
49  (* unsigned-char)))
50 
51 (define-alien-type rocksdb-create-compaction-filter-function
52  (function (* rocksdb-compactionfilter)
53  (* t)
54  (* rocksdb-compactionfiltercontext)))
55 
56 (define-alien-routine rocksdb-compactionfilter-create (* rocksdb-compactionfilter)
57  (state (* t))
58  (destructor (* rocksdb-destructor-function))
59  (filter (* rocksdb-filter-function))
60  (name (* rocksdb-name-function)))
61 
62 (define-alien-routine rocksdb-compactionfilter-set-ignore-snapshots void
63  (self (* rocksdb-compactionfilter)) (val unsigned-char))
64 
65 (define-alien-routine rocksdb-compactionfilter-destroy void
66  (self (* rocksdb-compactionfilter)))
67 
68 ;;; Compaction Filter Context
69 (define-alien-routine rocksdb-compactionfiltercontext-is-full-compaction unsigned-char
70  (context (* rocksdb-compactionfiltercontext)))
71 
72 (define-alien-routine rocksdb-compactionfiltercontext-is-manual-compaction unsigned-char
73  (context (* rocksdb-compactionfiltercontext)))
74 
75 ;;; Compaction Filter Factory
76 (define-alien-routine rocksdb-compactionfilterfactory-create (* rocksdb-compactionfilterfactory)
77  (state (* t))
78  (destructor (* rocksdb-destructor-function))
79  (creator (* rocksdb-create-compaction-filter-function))
80  (name (* rocksdb-name-function)))
81 
82 (define-alien-routine rocksdb-compacitonfilterfactory-destroy void
83  (factory (* rocksdb-compactionfilterfactory)))
84 
85 (define-alien-callable rocksdb-filter-never unsigned-char
86  ((state (* t))
87  (level int)
88  (key (array unsigned-char))
89  (key-length size-t)
90  (existing-val (array unsigned-char))
91  (existing-val-length size-t)
92  (new-val (* (array unsigned-char)))
93  (new-val-length (* size-t))
94  (value-changed (* unsigned-char)))
95  (declare (ignore state level key key-length existing-val existing-val-length new-val new-val-length value-changed))
96  0)
97 
98 (define-alien-callable rocksdb-create-compaction-filter-never (* rocksdb-compactionfilter)
99  ((state (* t))
100  (context (* rocksdb-compactionfiltercontext)))
101  (rocksdb-compactionfilter-create
102  state
103  (alien-sap (alien-callable-function 'rocksdb-destructor))
104  (alien-sap (alien-callable-function 'rocksdb-filter-never))
105  context))