@harperfast/rocksdb-js 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -14
- package/bin/rocksdb-js.mjs +67 -3
- package/dist/index.cjs +205 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1283 -1124
- package/dist/index.d.mts +1283 -1124
- package/dist/index.mjs +207 -38
- package/dist/index.mjs.map +1 -1
- package/docs/backups.md +15 -0
- package/docs/stats.md +2 -0
- package/docs/transaction-log.md +10 -0
- package/package.json +17 -17
package/dist/index.d.cts
CHANGED
|
@@ -1,104 +1,121 @@
|
|
|
1
1
|
import { ExtendedIterable } from "@harperfast/extended-iterable";
|
|
2
|
-
|
|
3
2
|
//#region src/backup.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Options for creating a backup via `db.backup()`.
|
|
6
|
-
*
|
|
7
|
-
* Backups are whole-database: every column family, the manifest, and (unless
|
|
8
|
-
* `backupLogFiles` is disabled) the write-ahead log are captured. A backup is
|
|
9
|
-
* not scoped to an individual `Store`.
|
|
10
|
-
*/
|
|
4
|
+
* Options for creating a backup via `db.backup()`.
|
|
5
|
+
*
|
|
6
|
+
* Backups are whole-database: every column family, the manifest, and (unless
|
|
7
|
+
* `backupLogFiles` is disabled) the write-ahead log are captured. A backup is
|
|
8
|
+
* not scoped to an individual `Store`.
|
|
9
|
+
*/
|
|
11
10
|
interface BackupOptions {
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
* Include write-ahead log files in the backup. Defaults to `true`.
|
|
13
|
+
*/
|
|
15
14
|
backupLogFiles?: boolean;
|
|
16
15
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
* Preflight the destination volume and reject the backup when it lacks room.
|
|
17
|
+
* Defaults to `true`. The rejection is an I/O error whose message reports the
|
|
18
|
+
* available and required bytes (it is not distinguishable by an `err.code`).
|
|
19
|
+
*
|
|
20
|
+
* The required size is estimated conservatively as a *full* copy of the
|
|
21
|
+
* database's live files, plus the transaction-log snapshot when
|
|
22
|
+
* `transactionLogs` is enabled (a backup only ever copies files, so this can
|
|
23
|
+
* never under-estimate the bytes written). For incremental backups to a
|
|
24
|
+
* right-sized volume this may over-reject — set `false` to skip the check in
|
|
25
|
+
* that case. The check also self-disables when free space is unknowable (e.g.
|
|
26
|
+
* some network filesystems report 0), so it never blocks a backup on an
|
|
27
|
+
* untrustworthy number.
|
|
28
|
+
*
|
|
29
|
+
* Only applies to directory-target backups; the streaming backup path is
|
|
30
|
+
* unaffected.
|
|
31
|
+
*/
|
|
32
|
+
checkDiskSpace?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Flush the memtable before backing up. Defaults to `true` when the database
|
|
35
|
+
* was opened with `disableWAL` (otherwise unflushed data would be lost from
|
|
36
|
+
* the backup), and `false` otherwise.
|
|
37
|
+
*/
|
|
21
38
|
flushBeforeBackup?: boolean;
|
|
22
39
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
* Number of background threads used to copy files. Defaults to `1`.
|
|
41
|
+
*/
|
|
25
42
|
maxBackgroundOperations?: number;
|
|
26
43
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
* Arbitrary application metadata stored with the backup and returned by
|
|
45
|
+
* `backups.list()`.
|
|
46
|
+
*/
|
|
30
47
|
metadata?: string;
|
|
31
48
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
* Distinguish shared files by checksum to avoid collisions across databases.
|
|
50
|
+
* Defaults to `true`. Only relevant when `shareTableFiles` is enabled.
|
|
51
|
+
*/
|
|
35
52
|
shareFilesWithChecksum?: boolean;
|
|
36
53
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
* Share table/blob files between backups in the same directory to enable
|
|
55
|
+
* incremental backups. Defaults to `true`.
|
|
56
|
+
*/
|
|
40
57
|
shareTableFiles?: boolean;
|
|
41
58
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
* `fsync` backup files — including the transaction log snapshot when
|
|
60
|
+
* `transactionLogs` is enabled — for crash consistency. Defaults to `true`.
|
|
61
|
+
*/
|
|
45
62
|
sync?: boolean;
|
|
46
63
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
* Snapshot the transaction log store into
|
|
65
|
+
* `<backupDir>/transaction_logs/<backupId>/`. Defaults to `false`. This is an
|
|
66
|
+
* all-or-nothing snapshot per backup (not incremental); `backups.delete()` and
|
|
67
|
+
* `backups.purge()` remove the corresponding log snapshots, and
|
|
68
|
+
* `backups.restore()` restores them into the database directory.
|
|
69
|
+
*
|
|
70
|
+
* The snapshot is staged and atomically renamed into place after every file
|
|
71
|
+
* is copied (and fsynced, per `sync`), so a crash mid-backup can never leave
|
|
72
|
+
* a partial snapshot: a backup id either has its complete log snapshot or
|
|
73
|
+
* none at all.
|
|
74
|
+
*
|
|
75
|
+
* The log snapshot is captured just after the RocksDB engine snapshot, so it
|
|
76
|
+
* may include entries committed between the two — the restored logs can run
|
|
77
|
+
* slightly ahead of the restored key-value data, never behind it. That bias
|
|
78
|
+
* is safe for redo-style logs that are replayed against the restored data.
|
|
79
|
+
*/
|
|
63
80
|
transactionLogs?: boolean;
|
|
64
81
|
}
|
|
65
82
|
/**
|
|
66
|
-
* The level of incremental restore to perform.
|
|
67
|
-
*
|
|
68
|
-
* - `purgeAllFiles` (default): purge the destination directory and restore all
|
|
69
|
-
* files from the backup. Destructive but always correct.
|
|
70
|
-
* - `keepLatestDbSessionIdFiles`: efficiently restore a healthy database,
|
|
71
|
-
* reusing existing files that match the backup.
|
|
72
|
-
* - `verifyChecksum`: reuse existing destination files whose checksums match the
|
|
73
|
-
* backup, replacing only mismatched/corrupt files.
|
|
74
|
-
*/
|
|
83
|
+
* The level of incremental restore to perform.
|
|
84
|
+
*
|
|
85
|
+
* - `purgeAllFiles` (default): purge the destination directory and restore all
|
|
86
|
+
* files from the backup. Destructive but always correct.
|
|
87
|
+
* - `keepLatestDbSessionIdFiles`: efficiently restore a healthy database,
|
|
88
|
+
* reusing existing files that match the backup.
|
|
89
|
+
* - `verifyChecksum`: reuse existing destination files whose checksums match the
|
|
90
|
+
* backup, replacing only mismatched/corrupt files.
|
|
91
|
+
*/
|
|
75
92
|
type RestoreMode = "purgeAllFiles" | "keepLatestDbSessionIdFiles" | "verifyChecksum";
|
|
76
93
|
/**
|
|
77
|
-
* Options for restoring a backup via `backups.restore()`.
|
|
78
|
-
*/
|
|
94
|
+
* Options for restoring a backup via `backups.restore()`.
|
|
95
|
+
*/
|
|
79
96
|
interface RestoreOptions {
|
|
80
97
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
* The backup id to restore. Defaults to the latest non-corrupt backup.
|
|
99
|
+
*/
|
|
83
100
|
backupId?: number;
|
|
84
101
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
* Directory to restore write-ahead log files into. Defaults to the database
|
|
103
|
+
* directory.
|
|
104
|
+
*/
|
|
88
105
|
walDir?: string;
|
|
89
106
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
* Keep existing log files in `walDir` rather than overwriting them. Defaults
|
|
108
|
+
* to `false`.
|
|
109
|
+
*/
|
|
93
110
|
keepLogFiles?: boolean;
|
|
94
111
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
* The restore strategy. Defaults to `purgeAllFiles`, which is destructive.
|
|
113
|
+
*/
|
|
97
114
|
mode?: RestoreMode;
|
|
98
115
|
}
|
|
99
116
|
/**
|
|
100
|
-
* Information about a single backup, as returned by `backups.list()`.
|
|
101
|
-
*/
|
|
117
|
+
* Information about a single backup, as returned by `backups.list()`.
|
|
118
|
+
*/
|
|
102
119
|
interface BackupInfo {
|
|
103
120
|
/** The backup id (monotonically increasing integer). */
|
|
104
121
|
backupId: number;
|
|
@@ -112,45 +129,64 @@ interface BackupInfo {
|
|
|
112
129
|
appMetadata: string;
|
|
113
130
|
}
|
|
114
131
|
/**
|
|
115
|
-
* Backup management operations that act on a backup directory and do not
|
|
116
|
-
* require an open database. To create a backup, use the `db.backup()` instance
|
|
117
|
-
* method instead (it needs a live database for a consistent snapshot).
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* import { backups } from '@harperfast/rocksdb-js';
|
|
122
|
-
*
|
|
123
|
-
* const id = await db.backup('/path/to/backups');
|
|
124
|
-
* db.close();
|
|
125
|
-
* await backups.restore('/path/to/backups', '/path/to/restored-db');
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
132
|
+
* Backup management operations that act on a backup directory and do not
|
|
133
|
+
* require an open database. To create a backup, use the `db.backup()` instance
|
|
134
|
+
* method instead (it needs a live database for a consistent snapshot).
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* import { backups } from '@harperfast/rocksdb-js';
|
|
139
|
+
*
|
|
140
|
+
* const id = await db.backup('/path/to/backups');
|
|
141
|
+
* db.close();
|
|
142
|
+
* await backups.restore('/path/to/backups', '/path/to/restored-db');
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
128
145
|
declare const backups: {
|
|
129
146
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
* Restores a database from a backup directory into a (closed) database
|
|
148
|
+
* directory. The default mode purges the destination directory, so it must
|
|
149
|
+
* not point at a live database.
|
|
150
|
+
*
|
|
151
|
+
* Holds the backup directory lock in shared mode for the duration: multiple
|
|
152
|
+
* restores can read concurrently, but a writer (`db.backup()`, `delete`,
|
|
153
|
+
* `purge`) rejects while a restore is in flight rather than deleting files
|
|
154
|
+
* out from under it — and a restore rejects while a writer holds the lock.
|
|
155
|
+
*
|
|
156
|
+
* The shared lock needs no write access to `backupDir`, so restoring from a
|
|
157
|
+
* read-only backup directory (immutable/WORM store, read-only-mounted volume)
|
|
158
|
+
* works: the lock is taken on an existing `.backup.lock` read-only, degrading
|
|
159
|
+
* to a no-op only when the media is read-only for every process (`EROFS`). A
|
|
160
|
+
* mere permission denial hard-fails instead — it doesn't prove a privileged
|
|
161
|
+
* writer isn't running.
|
|
162
|
+
*/
|
|
134
163
|
restore(backupDir: string, dbDir: string, options?: RestoreOptions): Promise<void>;
|
|
135
164
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
165
|
+
* Lists the non-corrupt backups in a backup directory, ordered by id.
|
|
166
|
+
*/
|
|
138
167
|
list(backupDir: string): Promise<BackupInfo[]>;
|
|
139
168
|
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
169
|
+
* Deletes a specific backup. Shared files are reference-counted and only
|
|
170
|
+
* removed once no remaining backup references them.
|
|
171
|
+
*/
|
|
143
172
|
delete(backupDir: string, backupId: number): Promise<void>;
|
|
144
173
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
* Deletes all but the newest `keepCount` backups.
|
|
175
|
+
*/
|
|
147
176
|
purge(backupDir: string, keepCount: number): Promise<void>;
|
|
148
177
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
178
|
+
* Verifies a backup's file sizes, and optionally their checksums (which
|
|
179
|
+
* requires reading all backed-up data).
|
|
180
|
+
*
|
|
181
|
+
* When the backup was created with `transactionLogs: true`, the backup's
|
|
182
|
+
* transaction log snapshot (`<backupDir>/transaction_logs/<backupId>/`) is
|
|
183
|
+
* also validated — every log file's header and entry framing must be intact
|
|
184
|
+
* (snapshots are copied on committed entry boundaries, so even a torn tail
|
|
185
|
+
* is a verification failure). Set `verifyTransactionLogs: false` to skip.
|
|
186
|
+
*/
|
|
152
187
|
verify(backupDir: string, backupId: number, options?: {
|
|
153
188
|
verifyWithChecksum?: boolean;
|
|
189
|
+
verifyTransactionLogs?: boolean;
|
|
154
190
|
}): Promise<void>;
|
|
155
191
|
};
|
|
156
192
|
//#endregion
|
|
@@ -190,14 +226,14 @@ interface DBIteratorValue<T> {
|
|
|
190
226
|
value: T;
|
|
191
227
|
}
|
|
192
228
|
/**
|
|
193
|
-
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
194
|
-
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
195
|
-
* fallback path used for oversized data or stable-buffer decoders).
|
|
196
|
-
*
|
|
197
|
-
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
198
|
-
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
199
|
-
* so this class is responsible for building the `IteratorResult`.
|
|
200
|
-
*/
|
|
229
|
+
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
230
|
+
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
231
|
+
* fallback path used for oversized data or stable-buffer decoders).
|
|
232
|
+
*
|
|
233
|
+
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
234
|
+
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
235
|
+
* so this class is responsible for building the `IteratorResult`.
|
|
236
|
+
*/
|
|
201
237
|
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
202
238
|
#private;
|
|
203
239
|
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
@@ -221,8 +257,8 @@ type CompactOptions = {
|
|
|
221
257
|
end?: Key;
|
|
222
258
|
};
|
|
223
259
|
/**
|
|
224
|
-
* Options for the `Store` class.
|
|
225
|
-
*/
|
|
260
|
+
* Options for the `Store` class.
|
|
261
|
+
*/
|
|
226
262
|
interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transactionLogRetentionMs"> {
|
|
227
263
|
decoder?: Encoder | null;
|
|
228
264
|
encoder?: Encoder | null;
|
|
@@ -236,266 +272,276 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transaction
|
|
|
236
272
|
maxKeySize?: number;
|
|
237
273
|
pessimistic?: boolean;
|
|
238
274
|
/**
|
|
239
|
-
|
|
240
|
-
|
|
275
|
+
* If `true`, the encoder will use a random access structure.
|
|
276
|
+
*/
|
|
241
277
|
randomAccessStructure?: boolean;
|
|
242
278
|
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
279
|
+
* When `true`, the database is opened in read-only mode. Write operations
|
|
280
|
+
* will throw an error with code `ERR_DATABASE_READONLY`.
|
|
281
|
+
*/
|
|
246
282
|
readOnly?: boolean;
|
|
247
283
|
sharedStructuresKey?: symbol;
|
|
248
284
|
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
285
|
+
* A string containing the amount of time or the number of milliseconds to
|
|
286
|
+
* retain transaction logs before purging.
|
|
287
|
+
*
|
|
288
|
+
* @default '3d' (3 days)
|
|
289
|
+
*/
|
|
254
290
|
transactionLogRetention?: number | string;
|
|
255
291
|
}
|
|
256
292
|
/**
|
|
257
|
-
* Options for the `getUserSharedBuffer()` method.
|
|
258
|
-
*/
|
|
293
|
+
* Options for the `getUserSharedBuffer()` method.
|
|
294
|
+
*/
|
|
259
295
|
type UserSharedBufferOptions = {
|
|
260
296
|
callback?: UserSharedBufferCallback;
|
|
261
297
|
};
|
|
262
298
|
/**
|
|
263
|
-
* The return type of `getUserSharedBuffer()`.
|
|
264
|
-
*/
|
|
299
|
+
* The return type of `getUserSharedBuffer()`.
|
|
300
|
+
*/
|
|
265
301
|
type ArrayBufferWithNotify = ArrayBuffer & {
|
|
266
302
|
cancel: () => void;
|
|
267
303
|
notify: () => void;
|
|
268
304
|
};
|
|
269
305
|
/**
|
|
270
|
-
* A store wraps the `NativeDatabase` binding and database settings so that a
|
|
271
|
-
* single database instance can be shared between the main `RocksDatabase`
|
|
272
|
-
* instance and the `Transaction` instance.
|
|
273
|
-
*
|
|
274
|
-
* This store should not be shared between `RocksDatabase` instances.
|
|
275
|
-
*/
|
|
306
|
+
* A store wraps the `NativeDatabase` binding and database settings so that a
|
|
307
|
+
* single database instance can be shared between the main `RocksDatabase`
|
|
308
|
+
* instance and the `Transaction` instance.
|
|
309
|
+
*
|
|
310
|
+
* This store should not be shared between `RocksDatabase` instances.
|
|
311
|
+
*/
|
|
276
312
|
declare class Store {
|
|
277
313
|
/**
|
|
278
|
-
|
|
279
|
-
|
|
314
|
+
* The database instance.
|
|
315
|
+
*/
|
|
280
316
|
db: NativeDatabase;
|
|
281
317
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
318
|
+
* The decoder instance. This is commonly the same as the `encoder`
|
|
319
|
+
* instance.
|
|
320
|
+
*/
|
|
285
321
|
decoder: Encoder | null;
|
|
286
322
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
323
|
+
* Whether the decoder copies the buffer when encoding values.
|
|
324
|
+
*/
|
|
289
325
|
decoderCopies: boolean;
|
|
290
326
|
/**
|
|
291
|
-
|
|
292
|
-
|
|
327
|
+
* Whether to disable the write ahead log.
|
|
328
|
+
*/
|
|
293
329
|
disableWAL: boolean;
|
|
294
330
|
/**
|
|
295
|
-
|
|
296
|
-
|
|
331
|
+
* Whether to enable RocksDB statistics.
|
|
332
|
+
*/
|
|
297
333
|
enableStats: boolean;
|
|
298
334
|
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
335
|
+
* Reusable buffer for encoding values using `writeKey()` when the custom
|
|
336
|
+
* encoder does not provide a `encode()` method.
|
|
337
|
+
*/
|
|
302
338
|
encodeBuffer: BufferWithDataView;
|
|
303
339
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
340
|
+
* The encoder instance.
|
|
341
|
+
*/
|
|
306
342
|
encoder: Encoder | null;
|
|
307
343
|
/**
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
344
|
+
* The encoding used to encode values. Defaults to `'msgpack'` in
|
|
345
|
+
* `RocksDatabase.open()`.
|
|
346
|
+
*/
|
|
311
347
|
encoding: Encoding | null;
|
|
312
348
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
349
|
+
* Encoder specific option used to signal that the data should be frozen.
|
|
350
|
+
*/
|
|
315
351
|
freezeData: boolean;
|
|
316
352
|
/**
|
|
317
|
-
|
|
318
|
-
|
|
353
|
+
* Reusable buffer for encoding keys.
|
|
354
|
+
*/
|
|
319
355
|
keyBuffer: BufferWithDataView;
|
|
320
356
|
/**
|
|
321
|
-
|
|
322
|
-
|
|
357
|
+
* The key encoding to use for keys. Defaults to `'ordered-binary'`.
|
|
358
|
+
*/
|
|
323
359
|
keyEncoding: KeyEncoding;
|
|
324
360
|
/**
|
|
325
|
-
|
|
326
|
-
|
|
361
|
+
* The maximum key size.
|
|
362
|
+
*/
|
|
327
363
|
maxKeySize: number;
|
|
328
364
|
/**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
365
|
+
* The maximum number of table files RocksDB keeps open. `0` (the default)
|
|
366
|
+
* derives a budget from the effective per-process open-file limit (an
|
|
367
|
+
* eighth of the limit — several databases can share one process — clamped
|
|
368
|
+
* to `[1024, 262144]`); `-1` holds every table file open (the RocksDB
|
|
369
|
+
* default, which can exhaust the process file-descriptor limit when
|
|
370
|
+
* compaction falls behind under sustained ingest); a positive `int32` is
|
|
371
|
+
* an explicit cap.
|
|
372
|
+
*/
|
|
373
|
+
maxOpenFiles?: number;
|
|
374
|
+
/**
|
|
375
|
+
* The maximum number of memtables that can be queued per column family
|
|
376
|
+
* before writes stall. Higher values absorb write bursts while flushes catch
|
|
377
|
+
* up, at the cost of memory.
|
|
378
|
+
*/
|
|
333
379
|
maxWriteBufferNumber?: number;
|
|
334
380
|
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
381
|
+
* The bytes of recent memtable history to retain in memory for transaction
|
|
382
|
+
* conflict checking. `-1` derives the value from
|
|
383
|
+
* `maxWriteBufferNumber * writeBufferSize`.
|
|
384
|
+
*/
|
|
339
385
|
maxWriteBufferSizeToMaintain?: number;
|
|
340
386
|
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
387
|
+
* The total memtable budget in bytes across all column families. When the
|
|
388
|
+
* sum of memtables reaches this size, RocksDB flushes the largest one. `0`
|
|
389
|
+
* disables the global trigger so per-CF `writeBufferSize` drives flushing.
|
|
390
|
+
*/
|
|
345
391
|
dbWriteBufferSize?: number;
|
|
346
392
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
393
|
+
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
394
|
+
*/
|
|
349
395
|
name: string;
|
|
350
396
|
/**
|
|
351
|
-
|
|
352
|
-
|
|
397
|
+
* Whether to disable the block cache.
|
|
398
|
+
*/
|
|
353
399
|
noBlockCache?: boolean;
|
|
354
400
|
/**
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
401
|
+
* The number of threads to use for parallel operations. This is a RocksDB
|
|
402
|
+
* option. When undefined, the native layer picks
|
|
403
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
404
|
+
*/
|
|
359
405
|
parallelismThreads?: number;
|
|
360
406
|
/**
|
|
361
|
-
|
|
362
|
-
|
|
407
|
+
* The path to the database.
|
|
408
|
+
*/
|
|
363
409
|
path: string;
|
|
364
410
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
411
|
+
* Whether to use pessimistic locking for transactions. When `true`,
|
|
412
|
+
* transactions will fail as soon as a conflict is detected. When `false`,
|
|
413
|
+
* transactions will only fail when `commit()` is called.
|
|
414
|
+
*/
|
|
369
415
|
pessimistic: boolean;
|
|
370
416
|
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
417
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
418
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
419
|
+
*/
|
|
374
420
|
readOnly: boolean;
|
|
375
421
|
/**
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
422
|
+
* Encoder specific flag used to signal that the encoder should use a random
|
|
423
|
+
* access structure.
|
|
424
|
+
*/
|
|
379
425
|
randomAccessStructure: boolean;
|
|
380
426
|
/**
|
|
381
|
-
|
|
382
|
-
|
|
427
|
+
* The function used to encode keys.
|
|
428
|
+
*/
|
|
383
429
|
readKey: ReadKeyFunction<Key>;
|
|
384
430
|
/**
|
|
385
|
-
|
|
386
|
-
|
|
431
|
+
* The key used to store shared structures.
|
|
432
|
+
*/
|
|
387
433
|
sharedStructuresKey?: symbol;
|
|
388
434
|
/**
|
|
389
|
-
|
|
390
|
-
|
|
435
|
+
* The level of statistics to capture.
|
|
436
|
+
*/
|
|
391
437
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
392
438
|
/**
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
439
|
+
* The threshold for the transaction log file's last modified time to be
|
|
440
|
+
* older than the retention period before it is rotated to the next sequence
|
|
441
|
+
* number. A threshold of 0 means ignore age check.
|
|
442
|
+
*/
|
|
397
443
|
transactionLogMaxAgeThreshold?: number;
|
|
398
444
|
/**
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
445
|
+
* The maximum size of a transaction log before it is rotated to the next
|
|
446
|
+
* sequence number.
|
|
447
|
+
*/
|
|
402
448
|
transactionLogMaxSize?: number;
|
|
403
449
|
/**
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
450
|
+
* A string containing the amount of time or the number of milliseconds to
|
|
451
|
+
* retain transaction logs before purging.
|
|
452
|
+
*
|
|
453
|
+
* @default '3d' (3 days)
|
|
454
|
+
*/
|
|
409
455
|
transactionLogRetention?: number | string;
|
|
410
456
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
457
|
+
* The path to the transaction logs directory.
|
|
458
|
+
*/
|
|
413
459
|
transactionLogsPath?: string;
|
|
414
460
|
/**
|
|
415
|
-
|
|
416
|
-
|
|
461
|
+
* Whether this store's column family participates in the VerificationTable.
|
|
462
|
+
*/
|
|
417
463
|
verificationTable?: boolean;
|
|
418
464
|
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
465
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
466
|
+
* sealed and flushed.
|
|
467
|
+
*/
|
|
422
468
|
writeBufferSize?: number;
|
|
423
469
|
/**
|
|
424
|
-
|
|
425
|
-
|
|
470
|
+
* The function used to encode keys using the shared `keyBuffer`.
|
|
471
|
+
*/
|
|
426
472
|
writeKey: WriteKeyFunction;
|
|
427
473
|
/**
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
474
|
+
* Initializes the store with a new `NativeDatabase` instance.
|
|
475
|
+
*
|
|
476
|
+
* @param path - The path to the database.
|
|
477
|
+
* @param options - The options for the store.
|
|
478
|
+
*/
|
|
433
479
|
constructor(path: string, options?: StoreOptions);
|
|
434
480
|
/**
|
|
435
|
-
|
|
436
|
-
|
|
481
|
+
* Closes the database.
|
|
482
|
+
*/
|
|
437
483
|
close(): void;
|
|
438
484
|
/**
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
485
|
+
* Compacts the entire key range of the database asynchronously.
|
|
486
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
491
|
+
* await db.compact();
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
448
494
|
compact(options?: CompactOptions): Promise<void>;
|
|
449
495
|
/**
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
496
|
+
* Creates a backup of the entire database (all column families) into the
|
|
497
|
+
* given directory and resolves with the new backup id. Parent directories
|
|
498
|
+
* are created as needed. See `backups` for restore and management.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const id = await db.backup('/path/to/backups');
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
459
505
|
backup(backupDir: string, options?: BackupOptions): Promise<number>;
|
|
460
506
|
backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
|
|
461
507
|
/**
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
508
|
+
* Compacts the entire key range of the database synchronously.
|
|
509
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
514
|
+
* db.compactSync();
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
471
517
|
compactSync(options?: CompactOptions): void;
|
|
472
518
|
/**
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
519
|
+
* Decodes a key from the database.
|
|
520
|
+
*
|
|
521
|
+
* @param key - The key to decode.
|
|
522
|
+
* @returns The decoded key.
|
|
523
|
+
*/
|
|
478
524
|
decodeKey(key: Buffer): Key;
|
|
479
525
|
/**
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
526
|
+
* Decodes a value from the database.
|
|
527
|
+
*
|
|
528
|
+
* @param value - The value to decode.
|
|
529
|
+
* @returns The decoded value.
|
|
530
|
+
*/
|
|
485
531
|
decodeValue(value: BufferWithDataView): any;
|
|
486
532
|
/**
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
533
|
+
* Encodes a key for the database.
|
|
534
|
+
*
|
|
535
|
+
* @param key - The key to encode.
|
|
536
|
+
* @returns The encoded key.
|
|
537
|
+
*/
|
|
492
538
|
encodeKey(key: Key): BufferWithDataView;
|
|
493
539
|
/**
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
540
|
+
* Encodes a value for the database.
|
|
541
|
+
*
|
|
542
|
+
* @param value - The value to encode.
|
|
543
|
+
* @returns The encoded value.
|
|
544
|
+
*/
|
|
499
545
|
encodeValue(value: any): BufferWithDataView | Uint8Array;
|
|
500
546
|
get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
|
|
501
547
|
getCount(context: StoreContext, options?: StoreRangeOptions): number;
|
|
@@ -504,118 +550,118 @@ declare class Store {
|
|
|
504
550
|
getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
|
|
505
551
|
getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
|
|
506
552
|
/**
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
553
|
+
* Checks if the data method options object contains a transaction ID and
|
|
554
|
+
* returns it.
|
|
555
|
+
*/
|
|
510
556
|
getTxnId(options?: DBITransactional | unknown): number | undefined;
|
|
511
557
|
/**
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
558
|
+
* Gets or creates a buffer that can be shared across worker threads.
|
|
559
|
+
*
|
|
560
|
+
* @param key - The key to get or create the buffer for.
|
|
561
|
+
* @param defaultBuffer - The default buffer to copy and use if the buffer
|
|
562
|
+
* does not exist.
|
|
563
|
+
* @param [options] - The options for the buffer.
|
|
564
|
+
* @param [options.callback] - A optional callback is called when `notify()`
|
|
565
|
+
* on the returned buffer is called.
|
|
566
|
+
* @returns An `ArrayBuffer` that is internally backed by a rocksdb-js
|
|
567
|
+
* managed buffer. The buffer also has `notify()` and `cancel()` methods
|
|
568
|
+
* that can be used to notify the specified `options.callback`.
|
|
569
|
+
*/
|
|
524
570
|
getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
|
|
525
571
|
/**
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
572
|
+
* Checks if a lock exists.
|
|
573
|
+
* @param key The lock key.
|
|
574
|
+
* @returns `true` if the lock exists, `false` otherwise
|
|
575
|
+
*/
|
|
530
576
|
hasLock(key: Key): boolean;
|
|
531
577
|
/**
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
578
|
+
* Checks if the database is open.
|
|
579
|
+
*
|
|
580
|
+
* @returns `true` if the database is open, `false` otherwise.
|
|
581
|
+
*/
|
|
536
582
|
isOpen(): boolean;
|
|
537
583
|
/**
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
584
|
+
* Lists all transaction log names.
|
|
585
|
+
*
|
|
586
|
+
* @returns an array of transaction log names.
|
|
587
|
+
*/
|
|
542
588
|
listLogs(): string[];
|
|
543
589
|
/**
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
590
|
+
* Opens the database. This must be called before any database operations
|
|
591
|
+
* are performed.
|
|
592
|
+
*/
|
|
547
593
|
open(): boolean;
|
|
548
594
|
putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
|
|
549
595
|
removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
|
|
550
596
|
/**
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
597
|
+
* Attempts to acquire a lock for a given key. If the lock is available,
|
|
598
|
+
* the function returns `true` and the optional callback is never called.
|
|
599
|
+
* If the lock is not available, the function returns `false` and the
|
|
600
|
+
* callback is queued until the lock is released.
|
|
601
|
+
*
|
|
602
|
+
* @param key - The key to lock.
|
|
603
|
+
* @param onUnlocked - A callback to call when the lock is released.
|
|
604
|
+
* @returns `true` if the lock was acquired, `false` otherwise.
|
|
605
|
+
*/
|
|
560
606
|
tryLock(key: Key, onUnlocked?: () => void): boolean;
|
|
561
607
|
/**
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
608
|
+
* Releases the lock on the given key and calls any queued `onUnlocked`
|
|
609
|
+
* callback handlers.
|
|
610
|
+
*
|
|
611
|
+
* @param key - The key to unlock.
|
|
612
|
+
*/
|
|
567
613
|
unlock(key: Key): void;
|
|
568
614
|
/**
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
615
|
+
* Gets or creates a transaction log instance.
|
|
616
|
+
*
|
|
617
|
+
* @param context - The context to use for the transaction log.
|
|
618
|
+
* @param name - The name of the transaction log.
|
|
619
|
+
* @returns The transaction log.
|
|
620
|
+
*/
|
|
575
621
|
useLog(context: StoreContext, name: string | number): TransactionLog;
|
|
576
622
|
/**
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
623
|
+
* Checks the process-global verification table for a fresh version match
|
|
624
|
+
* on `key`. Returns `true` when the table currently records `version` for
|
|
625
|
+
* this database+column-family. Provides a fast cache-freshness check
|
|
626
|
+
* before falling back to a full read.
|
|
627
|
+
*/
|
|
582
628
|
verifyVersion(key: Key, version: number): boolean;
|
|
583
629
|
/**
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
630
|
+
* Seeds the verification-table slot for `key` with `version`. Has no
|
|
631
|
+
* effect if the slot is currently lock-tagged or the table is disabled.
|
|
632
|
+
* Useful after a full read where the caller already knows the version.
|
|
633
|
+
*/
|
|
588
634
|
populateVersion(key: Key, version: number): void;
|
|
589
635
|
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
636
|
+
* Acquires a lock on the given key and calls the callback.
|
|
637
|
+
*
|
|
638
|
+
* @param key - The key to lock.
|
|
639
|
+
* @param callback - The callback to call when the lock is acquired.
|
|
640
|
+
* @returns A promise that resolves when the lock is acquired.
|
|
641
|
+
*/
|
|
596
642
|
withLock(key: Key, callback: () => void | Promise<void>): Promise<void>;
|
|
597
643
|
}
|
|
598
644
|
interface GetOptions {
|
|
599
645
|
/**
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
646
|
+
* When set, the native layer checks the verification table before reading.
|
|
647
|
+
* If the slot holds this version, returns `FRESH_VERSION_FLAG` immediately
|
|
648
|
+
* (the cached value is still valid). After a DB read, also seeds the slot
|
|
649
|
+
* with the version extracted from the value.
|
|
650
|
+
*/
|
|
605
651
|
expectedVersion?: number;
|
|
606
652
|
/**
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
653
|
+
* When `true`, after a DB read the native layer automatically seeds the
|
|
654
|
+
* verification-table slot with the version extracted from the value.
|
|
655
|
+
* Eliminates the need for a separate `populateVersion` call on cold reads.
|
|
656
|
+
*
|
|
657
|
+
* @default false
|
|
658
|
+
*/
|
|
613
659
|
populateVersion?: boolean;
|
|
614
660
|
/**
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
661
|
+
* Whether to skip decoding the value.
|
|
662
|
+
*
|
|
663
|
+
* @default false
|
|
664
|
+
*/
|
|
619
665
|
skipDecode?: boolean;
|
|
620
666
|
}
|
|
621
667
|
interface PutOptions {
|
|
@@ -627,55 +673,55 @@ interface PutOptions {
|
|
|
627
673
|
//#endregion
|
|
628
674
|
//#region src/transaction.d.ts
|
|
629
675
|
/**
|
|
630
|
-
* Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
|
|
631
|
-
* transaction encountered an IsBusy conflict. The native layer parks on VT
|
|
632
|
-
* slots and resolves only after the conflicting transaction releases its write
|
|
633
|
-
* intent, so callers should retry immediately without any backoff delay.
|
|
634
|
-
*/
|
|
676
|
+
* Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
|
|
677
|
+
* transaction encountered an IsBusy conflict. The native layer parks on VT
|
|
678
|
+
* slots and resolves only after the conflicting transaction releases its write
|
|
679
|
+
* intent, so callers should retry immediately without any backoff delay.
|
|
680
|
+
*/
|
|
635
681
|
declare const RETRY_NOW: number;
|
|
636
682
|
/**
|
|
637
|
-
* Provides transaction level operations to a transaction callback.
|
|
638
|
-
*/
|
|
683
|
+
* Provides transaction level operations to a transaction callback.
|
|
684
|
+
*/
|
|
639
685
|
declare class Transaction extends DBI {
|
|
640
686
|
#private;
|
|
641
687
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
688
|
+
* Create a new transaction.
|
|
689
|
+
*
|
|
690
|
+
* @param store - The base store interface for this transaction.
|
|
691
|
+
* @param options - The options for the transaction.
|
|
692
|
+
*/
|
|
647
693
|
constructor(store: Store, options?: NativeTransactionOptions);
|
|
648
694
|
/**
|
|
649
|
-
|
|
650
|
-
|
|
695
|
+
* Abort the transaction.
|
|
696
|
+
*/
|
|
651
697
|
abort(): void;
|
|
652
698
|
/**
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
699
|
+
* Commit the transaction.
|
|
700
|
+
*
|
|
701
|
+
* Returns `RETRY_NOW` when `coordinatedRetry: true` and an IsBusy conflict
|
|
702
|
+
* was detected. The caller should retry the transaction body immediately.
|
|
703
|
+
*/
|
|
658
704
|
commit(): Promise<typeof RETRY_NOW | void>;
|
|
659
705
|
/**
|
|
660
|
-
|
|
661
|
-
|
|
706
|
+
* Commit the transaction synchronously.
|
|
707
|
+
*/
|
|
662
708
|
commitSync(): void;
|
|
663
709
|
/**
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
710
|
+
* Returns the transaction start timestamp in seconds. Defaults to the time at which
|
|
711
|
+
* the transaction was created.
|
|
712
|
+
*
|
|
713
|
+
* @returns The transaction start timestamp in seconds.
|
|
714
|
+
*/
|
|
669
715
|
getTimestamp(): number;
|
|
670
716
|
/**
|
|
671
|
-
|
|
672
|
-
|
|
717
|
+
* Get the transaction id.
|
|
718
|
+
*/
|
|
673
719
|
get id(): number;
|
|
674
720
|
/**
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
721
|
+
* Set the transaction start timestamp in seconds.
|
|
722
|
+
*
|
|
723
|
+
* @param timestamp - The timestamp to set in seconds.
|
|
724
|
+
*/
|
|
679
725
|
setTimestamp(timestamp?: number): void;
|
|
680
726
|
}
|
|
681
727
|
//#endregion
|
|
@@ -685,317 +731,317 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
685
731
|
//#region src/dbi.d.ts
|
|
686
732
|
interface RocksDBOptions {
|
|
687
733
|
/**
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
734
|
+
* When `true`, RocksDB will do some enhancements for prefetching the data.
|
|
735
|
+
* Defaults to `true`. Note that RocksDB defaults this to `false`.
|
|
736
|
+
*/
|
|
691
737
|
adaptiveReadahead?: boolean;
|
|
692
738
|
/**
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
739
|
+
* When `true`, RocksDB will prefetch some data async and apply it if reads
|
|
740
|
+
* are sequential and its internal automatic prefetching. Defaults to
|
|
741
|
+
* `true`. Note that RocksDB defaults this to `false`.
|
|
742
|
+
*/
|
|
697
743
|
asyncIO?: boolean;
|
|
698
744
|
/**
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
745
|
+
* When `true`, RocksDB will auto-tune the readahead size during scans
|
|
746
|
+
* internally based on the block cache data when block caching is enabled,
|
|
747
|
+
* an end key (e.g. upper bound) is set, and prefix is the same as the start
|
|
748
|
+
* key. Defaults to `true`.
|
|
749
|
+
*/
|
|
704
750
|
autoReadaheadSize?: boolean;
|
|
705
751
|
/**
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
752
|
+
* When `true`, after the iterator is closed, a background job is scheduled
|
|
753
|
+
* to flush the job queue and delete obsolete files. Defaults to `true`.
|
|
754
|
+
* Note that RocksDB defaults this to `false`.
|
|
755
|
+
*/
|
|
710
756
|
backgroundPurgeOnIteratorCleanup?: boolean;
|
|
711
757
|
/**
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
758
|
+
* When `true`, the iterator will fill the block cache. Filling the block
|
|
759
|
+
* cache is not desirable for bulk scans and could impact eviction order.
|
|
760
|
+
* Defaults to `false`. Note that RocksDB defaults this to `true`.
|
|
761
|
+
*/
|
|
716
762
|
fillCache?: boolean;
|
|
717
763
|
/**
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
764
|
+
* The RocksDB readahead size. RocksDB does auto-readahead for iterators
|
|
765
|
+
* when there is more than two reads for a table file. The readahead
|
|
766
|
+
* starts at 8KB and doubles on every additional read up to 256KB. This
|
|
767
|
+
* option can help if most of the range scans are large and if a larger
|
|
768
|
+
* readahead than that enabled by auto-readahead is needed. Using a large
|
|
769
|
+
* readahead size (> 2MB) can typically improve the performance of forward
|
|
770
|
+
* iteration on spinning disks. Defaults to `0`.
|
|
771
|
+
*/
|
|
726
772
|
readaheadSize?: number;
|
|
727
773
|
/**
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
774
|
+
* When `true`, creates a "tailing iterator" which is a special iterator
|
|
775
|
+
* that has a view of the complete database including newly added data and
|
|
776
|
+
* is optimized for sequential reads. This will return records that were
|
|
777
|
+
* inserted into the database after the creation of the iterator. Defaults
|
|
778
|
+
* to `false`.
|
|
779
|
+
*/
|
|
734
780
|
tailing?: boolean;
|
|
735
781
|
}
|
|
736
782
|
interface RangeOptions extends RocksDBOptions {
|
|
737
783
|
/**
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
784
|
+
* The range end key, otherwise known as the "upper bound". Defaults to
|
|
785
|
+
* the last key in the database.
|
|
786
|
+
*/
|
|
741
787
|
end?: Key | Uint8Array;
|
|
742
788
|
/**
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
789
|
+
* When `true`, the iterator will exclude the first key if it matches the start key.
|
|
790
|
+
* Defaults to `false`.
|
|
791
|
+
*/
|
|
746
792
|
exclusiveStart?: boolean;
|
|
747
793
|
/**
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
794
|
+
* When `true`, the iterator will include the last key if it matches the end
|
|
795
|
+
* key. Defaults to `false`.
|
|
796
|
+
*/
|
|
751
797
|
inclusiveEnd?: boolean;
|
|
752
798
|
/**
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
799
|
+
* The range start key, otherwise known as the "lower bound". Defaults to
|
|
800
|
+
* the first key in the database.
|
|
801
|
+
*/
|
|
756
802
|
start?: Key | Uint8Array;
|
|
757
803
|
}
|
|
758
804
|
interface IteratorOptions extends RangeOptions {
|
|
759
805
|
/**
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
806
|
+
* The maximum number of entries to yield. When set, iteration stops after
|
|
807
|
+
* `limit` entries regardless of the range bounds. Values <= 0 yield nothing.
|
|
808
|
+
* Unset means no limit.
|
|
809
|
+
*/
|
|
764
810
|
limit?: number;
|
|
765
811
|
/**
|
|
766
|
-
|
|
767
|
-
|
|
812
|
+
* A specific key to match which may result in zero, one, or many values.
|
|
813
|
+
*/
|
|
768
814
|
key?: Key;
|
|
769
815
|
/**
|
|
770
|
-
|
|
771
|
-
|
|
816
|
+
* When `true`, only returns the number of values for the given query.
|
|
817
|
+
*/
|
|
772
818
|
onlyCount?: boolean;
|
|
773
819
|
/**
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
820
|
+
* When `true`, the iterator will iterate in reverse order. Defaults to
|
|
821
|
+
* `false`.
|
|
822
|
+
*/
|
|
777
823
|
reverse?: boolean;
|
|
778
824
|
/**
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
825
|
+
* When `true`, decodes and returns the value. When `false`, the value is
|
|
826
|
+
* omitted. Defaults to `true`.
|
|
827
|
+
*/
|
|
782
828
|
values?: boolean;
|
|
783
829
|
/**
|
|
784
|
-
|
|
785
|
-
|
|
830
|
+
* When `true`, the iterator will only return the values.
|
|
831
|
+
*/
|
|
786
832
|
valuesOnly?: boolean;
|
|
787
833
|
}
|
|
788
834
|
interface DBITransactional {
|
|
789
835
|
transaction?: Transaction;
|
|
790
836
|
}
|
|
791
837
|
/**
|
|
792
|
-
* The base class for all database operations. This base class is shared by
|
|
793
|
-
* `RocksDatabase` and `Transaction`.
|
|
794
|
-
*
|
|
795
|
-
* This class is not meant to be used directly.
|
|
796
|
-
*/
|
|
838
|
+
* The base class for all database operations. This base class is shared by
|
|
839
|
+
* `RocksDatabase` and `Transaction`.
|
|
840
|
+
*
|
|
841
|
+
* This class is not meant to be used directly.
|
|
842
|
+
*/
|
|
797
843
|
declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
798
844
|
/**
|
|
799
|
-
|
|
800
|
-
|
|
845
|
+
* The RocksDB context for `get()`, `put()`, and `remove()`.
|
|
846
|
+
*/
|
|
801
847
|
_context: StoreContext;
|
|
802
848
|
/**
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
849
|
+
* The database store instance. The store instance is tied to the database
|
|
850
|
+
* instance and shared with transaction instances.
|
|
851
|
+
*/
|
|
806
852
|
store: Store;
|
|
807
853
|
/**
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
854
|
+
* Initializes the DBI context.
|
|
855
|
+
*
|
|
856
|
+
* @param store - The store instance.
|
|
857
|
+
* @param transaction - The transaction instance.
|
|
858
|
+
*/
|
|
813
859
|
constructor(store: Store, transaction?: NativeTransaction);
|
|
814
860
|
/**
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
861
|
+
* Adds a listener for the given key.
|
|
862
|
+
*
|
|
863
|
+
* @param event - The event name to add the listener for.
|
|
864
|
+
* @param callback - The callback to add.
|
|
865
|
+
*/
|
|
820
866
|
addListener(event: string, callback: (...args: any[]) => void): this;
|
|
821
867
|
/**
|
|
822
|
-
|
|
823
|
-
|
|
868
|
+
* Retrieves the value for the given key, then returns the decoded value.
|
|
869
|
+
*/
|
|
824
870
|
get(key: Key, options?: GetOptions & T): MaybePromise<any | undefined>;
|
|
825
871
|
/**
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
872
|
+
* Retrieves the binary data for the given key. This is just like `get()`,
|
|
873
|
+
* but bypasses the decoder.
|
|
874
|
+
*
|
|
875
|
+
* Note: Used by HDBreplication.
|
|
876
|
+
*/
|
|
831
877
|
getBinary(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
|
|
832
878
|
/**
|
|
833
|
-
|
|
834
|
-
|
|
879
|
+
* Synchronously retrieves the binary data for the given key.
|
|
880
|
+
*/
|
|
835
881
|
getBinarySync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
|
|
836
882
|
/**
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
883
|
+
* Retrieves the binary data for the given key using a preallocated,
|
|
884
|
+
* reusable buffer. Data in the buffer is only valid until the next get
|
|
885
|
+
* operation (including cursor operations).
|
|
886
|
+
*
|
|
887
|
+
* Note: The reusable buffer slightly differs from a typical buffer:
|
|
888
|
+
* - `.length` is set to the size of the value
|
|
889
|
+
* - `.byteLength` is set to the size of the full allocated memory area for
|
|
890
|
+
* the buffer (usually much larger).
|
|
891
|
+
*/
|
|
846
892
|
getBinaryFast(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
|
|
847
893
|
/**
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
894
|
+
* Synchronously retrieves the binary data for the given key using a
|
|
895
|
+
* preallocated, reusable buffer. Data in the buffer is only valid until the
|
|
896
|
+
* next get operation (including cursor operations).
|
|
897
|
+
*/
|
|
852
898
|
getBinaryFastSync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
|
|
853
899
|
/**
|
|
854
|
-
|
|
855
|
-
|
|
900
|
+
* Retrieves all keys within a range.
|
|
901
|
+
*/
|
|
856
902
|
getKeys(options?: IteratorOptions & T): any | undefined;
|
|
857
903
|
/**
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
904
|
+
* Retrieves the number of keys within a range.
|
|
905
|
+
*
|
|
906
|
+
* @param options - The range options.
|
|
907
|
+
* @returns The number of keys within the range.
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```typescript
|
|
911
|
+
* const total = db.getKeysCount();
|
|
912
|
+
* const range = db.getKeysCount({ start: 'a', end: 'z' });
|
|
913
|
+
* ```
|
|
914
|
+
*/
|
|
869
915
|
getKeysCount(options?: RangeOptions & T): number;
|
|
870
916
|
/**
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
917
|
+
* Retrieves a range of keys and their values.
|
|
918
|
+
*
|
|
919
|
+
* @param options - The iterator options.
|
|
920
|
+
* @returns A range iterable.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* for (const { key, value } of db.getRange()) {
|
|
925
|
+
* console.log({ key, value });
|
|
926
|
+
* }
|
|
927
|
+
*
|
|
928
|
+
* for (const { key, value } of db.getRange({ start: 'a', end: 'z' })) {
|
|
929
|
+
* console.log({ key, value });
|
|
930
|
+
* }
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
887
933
|
getRange(options?: IteratorOptions & T): any | undefined;
|
|
888
934
|
/**
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
935
|
+
* Synchronously retrieves the value for the given key, then returns the
|
|
936
|
+
* decoded value.
|
|
937
|
+
*/
|
|
892
938
|
getSync(key: Key, options?: GetOptions & T): any | undefined;
|
|
893
939
|
/**
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
940
|
+
* Gets the number of listeners for the given key.
|
|
941
|
+
*
|
|
942
|
+
* @param event - The event name to get the listeners for.
|
|
943
|
+
* @returns The number of listeners for the given key.
|
|
944
|
+
*/
|
|
899
945
|
listeners(event: string | BufferWithDataView): number;
|
|
900
946
|
/**
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
947
|
+
* Notifies an event for the given key.
|
|
948
|
+
*
|
|
949
|
+
* @param event - The event name to emit the event for.
|
|
950
|
+
* @param args - The arguments to emit.
|
|
951
|
+
* @returns `true` if there were listeners, `false` otherwise.
|
|
952
|
+
*/
|
|
907
953
|
notify(event: string, ...args: any[]): boolean;
|
|
908
954
|
/**
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
955
|
+
* Alias for `removeListener()`.
|
|
956
|
+
*
|
|
957
|
+
* @param event - The event name to remove the listener for.
|
|
958
|
+
* @param callback - The callback to remove.
|
|
959
|
+
*/
|
|
914
960
|
off(event: string, callback: (...args: any[]) => void): this;
|
|
915
961
|
/**
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
962
|
+
* Alias for `addListener()`.
|
|
963
|
+
*
|
|
964
|
+
* @param event - The event name to add the listener for.
|
|
965
|
+
* @param callback - The callback to add.
|
|
966
|
+
*/
|
|
921
967
|
on(event: string, callback: (...args: any[]) => void): this;
|
|
922
968
|
/**
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
969
|
+
* Adds a one-time listener, then automatically removes it.
|
|
970
|
+
*
|
|
971
|
+
* @param event - The event name to add the listener for.
|
|
972
|
+
* @param callback - The callback to add.
|
|
973
|
+
*/
|
|
928
974
|
once(event: string, callback: (...args: any[]) => void): this;
|
|
929
975
|
/**
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
976
|
+
* Stores a value for the given key.
|
|
977
|
+
*
|
|
978
|
+
* @param key - The key to store the value for.
|
|
979
|
+
* @param value - The value to store.
|
|
980
|
+
* @param options - The put options.
|
|
981
|
+
* @returns The key and value.
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```typescript
|
|
985
|
+
* await db.put('a', 'b');
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
942
988
|
put(key: Key, value: any, options?: PutOptions & T): Promise<void>;
|
|
943
989
|
/**
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
990
|
+
* Synchronously stores a value for the given key.
|
|
991
|
+
*
|
|
992
|
+
* @param key - The key to store the value for.
|
|
993
|
+
* @param value - The value to store.
|
|
994
|
+
* @param options - The put options.
|
|
995
|
+
* @returns The key and value.
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```typescript
|
|
999
|
+
* db.putSync('a', 'b');
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
956
1002
|
putSync(key: Key, value: any, options?: PutOptions & T): void;
|
|
957
1003
|
/**
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1004
|
+
* Removes a value for the given key. If the key does not exist, it will
|
|
1005
|
+
* not error.
|
|
1006
|
+
*
|
|
1007
|
+
* @param key - The key to remove the value for.
|
|
1008
|
+
* @param options - The remove options.
|
|
1009
|
+
* @returns The key and value.
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```typescript
|
|
1013
|
+
* await db.remove('a');
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
970
1016
|
remove(key: Key, options?: T): Promise<void>;
|
|
971
1017
|
/**
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1018
|
+
* Removes a value for the given key. If the key does not exist, it will
|
|
1019
|
+
* not error.
|
|
1020
|
+
*
|
|
1021
|
+
* @param key - The key to remove the value for.
|
|
1022
|
+
* @param options - The remove options.
|
|
1023
|
+
* @returns The key and value.
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```typescript
|
|
1027
|
+
* db.removeSync('a');
|
|
1028
|
+
* ```
|
|
1029
|
+
*/
|
|
984
1030
|
removeSync(key: Key, options?: T): void;
|
|
985
1031
|
/**
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1032
|
+
* Removes an event listener. You must specify the exact same callback that was
|
|
1033
|
+
* used in `addListener()`.
|
|
1034
|
+
*
|
|
1035
|
+
* @param event - The event name to remove the listener for.
|
|
1036
|
+
* @param callback - The callback to remove.
|
|
1037
|
+
*/
|
|
992
1038
|
removeListener(event: string, callback: (value?: any) => void): boolean;
|
|
993
1039
|
/**
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1040
|
+
* Get or create a transaction log instance.
|
|
1041
|
+
*
|
|
1042
|
+
* @param name - The name of the transaction log.
|
|
1043
|
+
* @returns The transaction log.
|
|
1044
|
+
*/
|
|
999
1045
|
useLog(name: string | number): TransactionLog;
|
|
1000
1046
|
}
|
|
1001
1047
|
//#endregion
|
|
@@ -1049,6 +1095,8 @@ type StatsBasics = {
|
|
|
1049
1095
|
"txnlog.transactionsWritten": number;
|
|
1050
1096
|
"txnlog.bytesWritten": number;
|
|
1051
1097
|
"txnlog.replayGapBytes": number;
|
|
1098
|
+
"commitPipeline.logQueueDepth": number;
|
|
1099
|
+
"commitPipeline.commitQueueDepth": number;
|
|
1052
1100
|
};
|
|
1053
1101
|
type StatsCuratedExtras = {
|
|
1054
1102
|
"rocksdb.block.cache.hit": number;
|
|
@@ -1367,24 +1415,132 @@ interface GetStatsMethod {
|
|
|
1367
1415
|
getStats(all: true): StatsAll;
|
|
1368
1416
|
}
|
|
1369
1417
|
//#endregion
|
|
1418
|
+
//#region src/validate-transaction-log.d.ts
|
|
1419
|
+
/**
|
|
1420
|
+
* The validation result for a single transaction log file within a store, as
|
|
1421
|
+
* returned by {@link validateTransactionLogStore}.
|
|
1422
|
+
*/
|
|
1423
|
+
interface TransactionLogFileValidation {
|
|
1424
|
+
/** File name relative to the store directory, e.g. `"3.txnlog"`. */
|
|
1425
|
+
file: string;
|
|
1426
|
+
/** Sequence number parsed from the file name. */
|
|
1427
|
+
sequence: number;
|
|
1428
|
+
/** On-disk file size in bytes. */
|
|
1429
|
+
size: number;
|
|
1430
|
+
/** Number of well-formed entry frames. */
|
|
1431
|
+
entries: number;
|
|
1432
|
+
/** End offset of the validly framed data (header + well-formed entries). */
|
|
1433
|
+
validBytes: number;
|
|
1434
|
+
/** `true` when `errors` is empty. */
|
|
1435
|
+
valid: boolean;
|
|
1436
|
+
/**
|
|
1437
|
+
* Conditions that make the file invalid: a bad/missing header, an
|
|
1438
|
+
* unsupported version, or a mid-file framing break. With `strict`, a torn
|
|
1439
|
+
* tail is also reported here.
|
|
1440
|
+
*/
|
|
1441
|
+
errors: string[];
|
|
1442
|
+
/**
|
|
1443
|
+
* Conditions that do not invalidate the file: a torn tail (recoverable —
|
|
1444
|
+
* open-time recovery truncates it without losing committed entries) and
|
|
1445
|
+
* per-entry anomalies such as suspicious timestamps or undefined flag bits.
|
|
1446
|
+
*/
|
|
1447
|
+
warnings: string[];
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* The result of validating a transaction log store directory, as returned by
|
|
1451
|
+
* {@link validateTransactionLogStore}.
|
|
1452
|
+
*/
|
|
1453
|
+
interface TransactionLogStoreValidation {
|
|
1454
|
+
/** The validated store directory. */
|
|
1455
|
+
path: string;
|
|
1456
|
+
/**
|
|
1457
|
+
* `true` when there are no store-level errors and every log file is valid.
|
|
1458
|
+
*/
|
|
1459
|
+
valid: boolean;
|
|
1460
|
+
/** Per-file validation results, ordered by sequence number. */
|
|
1461
|
+
files: TransactionLogFileValidation[];
|
|
1462
|
+
/**
|
|
1463
|
+
* Store-level errors: malformed file names, an unreadable file, or a
|
|
1464
|
+
* corrupt `txn.state`.
|
|
1465
|
+
*/
|
|
1466
|
+
errors: string[];
|
|
1467
|
+
/**
|
|
1468
|
+
* Store-level warnings: sequence gaps, unexpected directory entries, or an
|
|
1469
|
+
* implausible `txn.state` flushed position.
|
|
1470
|
+
*/
|
|
1471
|
+
warnings: string[];
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Options for {@link validateTransactionLogStore}.
|
|
1475
|
+
*/
|
|
1476
|
+
interface ValidateTransactionLogStoreOptions {
|
|
1477
|
+
/**
|
|
1478
|
+
* Report conditions that indicate an incomplete snapshot — a torn tail, a
|
|
1479
|
+
* sequence gap, or a `txn.state` flushed position beyond the newest log
|
|
1480
|
+
* file or beyond its file's actual size — as errors instead of warnings. A
|
|
1481
|
+
* torn tail on a live store is a normal crash artifact that open-time
|
|
1482
|
+
* recovery truncates, but a backup snapshot captures every surviving file
|
|
1483
|
+
* on committed entry boundaries and must be clean end to end —
|
|
1484
|
+
* `backups.verify()` validates snapshots with `strict: true`. Defaults to
|
|
1485
|
+
* `false`.
|
|
1486
|
+
*/
|
|
1487
|
+
strict?: boolean;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Validates a transaction log store directory: every `<sequence>.txnlog` file
|
|
1491
|
+
* is checked for a valid header (token, version) and intact v1 entry framing
|
|
1492
|
+
* (using the same scan as open-time crash recovery), file-name and sequence
|
|
1493
|
+
* continuity are checked, and the `txn.state` side file (when present) is
|
|
1494
|
+
* checked for shape and a plausible flushed position. The result reports
|
|
1495
|
+
* per-file entry counts, errors, and warnings; it does not throw when the
|
|
1496
|
+
* store is invalid — check `result.valid`.
|
|
1497
|
+
*
|
|
1498
|
+
* Runs entirely in native code on a worker thread and does not require (or
|
|
1499
|
+
* open) a database, so it works on the store of a closed database and on the
|
|
1500
|
+
* per-backup snapshots under `<backupDir>/transaction_logs/<backupId>/` alike.
|
|
1501
|
+
*
|
|
1502
|
+
* Validating a store that is being actively appended to can spuriously report
|
|
1503
|
+
* a torn tail for the current log file — the tail of an in-flight append is
|
|
1504
|
+
* indistinguishable from a crash artifact.
|
|
1505
|
+
*
|
|
1506
|
+
* Rejects if `path` does not exist or is not a directory (a bad argument, as
|
|
1507
|
+
* opposed to an invalid store).
|
|
1508
|
+
*
|
|
1509
|
+
* @param path The store directory, e.g. `<dbDir>/transaction_logs/<name>`.
|
|
1510
|
+
* @param options Validation options.
|
|
1511
|
+
*
|
|
1512
|
+
* @example
|
|
1513
|
+
* ```typescript
|
|
1514
|
+
* import { validateTransactionLogStore } from '@harperfast/rocksdb-js';
|
|
1515
|
+
*
|
|
1516
|
+
* const result = await validateTransactionLogStore('/path/to/db/transaction_logs/mylog');
|
|
1517
|
+
* if (!result.valid) {
|
|
1518
|
+
* for (const file of result.files) {
|
|
1519
|
+
* console.error(file.file, file.errors);
|
|
1520
|
+
* }
|
|
1521
|
+
* }
|
|
1522
|
+
* ```
|
|
1523
|
+
*/
|
|
1524
|
+
declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
|
|
1525
|
+
//#endregion
|
|
1370
1526
|
//#region src/load-binding.d.ts
|
|
1371
1527
|
type NativeTransactionOptions = {
|
|
1372
1528
|
/**
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1529
|
+
* Whether to disable snapshots.
|
|
1530
|
+
*
|
|
1531
|
+
* @default false
|
|
1532
|
+
*/
|
|
1377
1533
|
disableSnapshot?: boolean;
|
|
1378
1534
|
/**
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1535
|
+
* When `true`, an `IsBusy` conflict at commit time is resolved with the
|
|
1536
|
+
* `RETRY_NOW` sentinel value instead of being rejected. The native layer
|
|
1537
|
+
* may park on a VT slot before resolving, so the JS retry fires only after
|
|
1538
|
+
* the conflicting transaction has committed and released its write intent.
|
|
1539
|
+
*
|
|
1540
|
+
* Use together with `verificationTable: true` on the database.
|
|
1541
|
+
*
|
|
1542
|
+
* @default false
|
|
1543
|
+
*/
|
|
1388
1544
|
coordinatedRetry?: boolean;
|
|
1389
1545
|
};
|
|
1390
1546
|
type NativeTransaction = {
|
|
@@ -1421,23 +1577,23 @@ type TransactionEntry = {
|
|
|
1421
1577
|
endTxn: boolean;
|
|
1422
1578
|
};
|
|
1423
1579
|
/**
|
|
1424
|
-
* A position within a transaction log, identifying a log file by its sequence
|
|
1425
|
-
* number and a byte `offset` within that file.
|
|
1426
|
-
*/
|
|
1580
|
+
* A position within a transaction log, identifying a log file by its sequence
|
|
1581
|
+
* number and a byte `offset` within that file.
|
|
1582
|
+
*/
|
|
1427
1583
|
type TransactionLogPosition = {
|
|
1428
1584
|
sequence: number;
|
|
1429
1585
|
offset: number;
|
|
1430
1586
|
};
|
|
1431
1587
|
/**
|
|
1432
|
-
* A detailed statistics snapshot for a single transaction log store, returned
|
|
1433
|
-
* by {@link TransactionLog.getStats}. All sizes are in bytes; timestamps are
|
|
1434
|
-
* milliseconds since the Unix epoch.
|
|
1435
|
-
*
|
|
1436
|
-
* Memory note: `memory.mappedBytes` is virtual address space — the active write
|
|
1437
|
-
* file is mapped at the full configured `maxFileSize` on POSIX, so it does not
|
|
1438
|
-
* reflect resident memory. `memory.overlayBytes` (POSIX only; 0 on Windows) is
|
|
1439
|
-
* the file-backed portion and is the closer proxy for real consumption.
|
|
1440
|
-
*/
|
|
1588
|
+
* A detailed statistics snapshot for a single transaction log store, returned
|
|
1589
|
+
* by {@link TransactionLog.getStats}. All sizes are in bytes; timestamps are
|
|
1590
|
+
* milliseconds since the Unix epoch.
|
|
1591
|
+
*
|
|
1592
|
+
* Memory note: `memory.mappedBytes` is virtual address space — the active write
|
|
1593
|
+
* file is mapped at the full configured `maxFileSize` on POSIX, so it does not
|
|
1594
|
+
* reflect resident memory. `memory.overlayBytes` (POSIX only; 0 on Windows) is
|
|
1595
|
+
* the file-backed portion and is the closer proxy for real consumption.
|
|
1596
|
+
*/
|
|
1441
1597
|
type TransactionLogStats = {
|
|
1442
1598
|
name: string;
|
|
1443
1599
|
path: string;
|
|
@@ -1497,10 +1653,10 @@ type TransactionLog = {
|
|
|
1497
1653
|
_logBuffers: Map<number, WeakRef<LogBuffer>>;
|
|
1498
1654
|
};
|
|
1499
1655
|
/**
|
|
1500
|
-
* Shape of options that can be passed to the native iterator constructor for
|
|
1501
|
-
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
1502
|
-
* options are passed via the bitmask `flags` argument instead.
|
|
1503
|
-
*/
|
|
1656
|
+
* Shape of options that can be passed to the native iterator constructor for
|
|
1657
|
+
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
1658
|
+
* options are passed via the bitmask `flags` argument instead.
|
|
1659
|
+
*/
|
|
1504
1660
|
type NativeIteratorAdvancedOptions = {
|
|
1505
1661
|
adaptiveReadahead?: boolean;
|
|
1506
1662
|
asyncIO?: boolean;
|
|
@@ -1511,11 +1667,11 @@ type NativeIteratorAdvancedOptions = {
|
|
|
1511
1667
|
tailing?: boolean;
|
|
1512
1668
|
};
|
|
1513
1669
|
/**
|
|
1514
|
-
* The result of a single native iterator step. A number value matches one of
|
|
1515
|
-
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
1516
|
-
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
1517
|
-
* needs a stable value buffer.
|
|
1518
|
-
*/
|
|
1670
|
+
* The result of a single native iterator step. A number value matches one of
|
|
1671
|
+
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
1672
|
+
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
1673
|
+
* needs a stable value buffer.
|
|
1674
|
+
*/
|
|
1519
1675
|
type NativeIteratorResult = number | {
|
|
1520
1676
|
key: Buffer;
|
|
1521
1677
|
value?: Buffer;
|
|
@@ -1531,6 +1687,7 @@ type NativeDatabaseOptions = {
|
|
|
1531
1687
|
dbWriteBufferSize?: number;
|
|
1532
1688
|
disableWAL?: boolean;
|
|
1533
1689
|
enableStats?: boolean;
|
|
1690
|
+
maxOpenFiles?: number;
|
|
1534
1691
|
maxWriteBufferNumber?: number;
|
|
1535
1692
|
maxWriteBufferSizeToMaintain?: number;
|
|
1536
1693
|
mode?: NativeDatabaseMode;
|
|
@@ -1544,11 +1701,11 @@ type NativeDatabaseOptions = {
|
|
|
1544
1701
|
transactionLogRetentionMs?: number;
|
|
1545
1702
|
transactionLogsPath?: string;
|
|
1546
1703
|
/**
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1704
|
+
* When true, transaction writes to this column family invalidate the
|
|
1705
|
+
* VerificationTable slot for each written key at write time (not at
|
|
1706
|
+
* commit time). Enable only for column families whose records are
|
|
1707
|
+
* cached (e.g. the primary CF of a table). Default: false.
|
|
1708
|
+
*/
|
|
1552
1709
|
verificationTable?: boolean;
|
|
1553
1710
|
writeBufferSize?: number;
|
|
1554
1711
|
};
|
|
@@ -1559,16 +1716,16 @@ type PurgeLogsOptions = {
|
|
|
1559
1716
|
before?: number;
|
|
1560
1717
|
destroy?: boolean;
|
|
1561
1718
|
/**
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1719
|
+
* When `true`, count the entries in each purged log file (extra work) and
|
|
1720
|
+
* return `PurgedLog[]` instead of the default `string[]` of file paths.
|
|
1721
|
+
*/
|
|
1565
1722
|
includeEntryCounts?: boolean;
|
|
1566
1723
|
name?: string;
|
|
1567
1724
|
};
|
|
1568
1725
|
/**
|
|
1569
|
-
* A purged transaction log file and the number of entries it held, returned by
|
|
1570
|
-
* `purgeLogs()` when `includeEntryCounts` is `true`.
|
|
1571
|
-
*/
|
|
1726
|
+
* A purged transaction log file and the number of entries it held, returned by
|
|
1727
|
+
* `purgeLogs()` when `includeEntryCounts` is `true`.
|
|
1728
|
+
*/
|
|
1572
1729
|
type PurgedLog = {
|
|
1573
1730
|
path: string;
|
|
1574
1731
|
entries: number;
|
|
@@ -1633,47 +1790,47 @@ type NativeDatabase = {
|
|
|
1633
1790
|
type RocksDatabaseConfig = {
|
|
1634
1791
|
blockCacheSize?: number;
|
|
1635
1792
|
/**
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1793
|
+
* Number of slots in the process-global verification table. Each slot is
|
|
1794
|
+
* 8 bytes; the default of 128K slots is 1 MB. Set to 0 to disable.
|
|
1795
|
+
*
|
|
1796
|
+
* Must be configured before the first database is opened. Once the table
|
|
1797
|
+
* is materialized, attempts to change this value will throw.
|
|
1798
|
+
*/
|
|
1642
1799
|
verificationTableEntries?: number;
|
|
1643
1800
|
compactOnClose?: boolean;
|
|
1644
1801
|
/**
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1802
|
+
* Total memtable memory limit (bytes) shared across every database opened
|
|
1803
|
+
* in this process. When set, RocksDB uses a single `WriteBufferManager` so
|
|
1804
|
+
* write buffers are bounded process-wide rather than per database. 0 (the
|
|
1805
|
+
* default) disables the manager.
|
|
1806
|
+
*
|
|
1807
|
+
* Can be updated at runtime; the new size takes effect on the existing
|
|
1808
|
+
* manager via `SetBufferSize`.
|
|
1809
|
+
*/
|
|
1653
1810
|
writeBufferManagerSize?: number;
|
|
1654
1811
|
/**
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1812
|
+
* When `true`, memtable memory is "charged" against the shared block cache
|
|
1813
|
+
* so the block cache and write buffers draw from a single pool. During
|
|
1814
|
+
* write bursts the cache shrinks to make room for memtables; once
|
|
1815
|
+
* memtables flush, the cache can grow back into the reclaimed space.
|
|
1816
|
+
*
|
|
1817
|
+
* Has no effect when the block cache is disabled (size 0) or
|
|
1818
|
+
* `writeBufferManagerSize` is 0. Must be set on the same `config()` call
|
|
1819
|
+
* that first enables the manager — changing it after the manager has been
|
|
1820
|
+
* created has no effect on the running instance.
|
|
1821
|
+
*
|
|
1822
|
+
* @default false
|
|
1823
|
+
*/
|
|
1667
1824
|
writeBufferManagerCostToCache?: boolean;
|
|
1668
1825
|
/**
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1826
|
+
* When `true`, writes are stalled once the manager's `buffer_size` is
|
|
1827
|
+
* exceeded, providing a hard cap on memtable memory. When `false`,
|
|
1828
|
+
* memtables are allowed to grow past the limit and flushes are simply
|
|
1829
|
+
* scheduled more aggressively. Off by default to favor write throughput
|
|
1830
|
+
* over hard memory bounding.
|
|
1831
|
+
*
|
|
1832
|
+
* @default false
|
|
1833
|
+
*/
|
|
1677
1834
|
writeBufferManagerAllowStall?: boolean;
|
|
1678
1835
|
};
|
|
1679
1836
|
type RegistryStatusDB = {
|
|
@@ -1694,10 +1851,10 @@ declare const constants: {
|
|
|
1694
1851
|
POPULATE_VERSION_FLAG: number;
|
|
1695
1852
|
FRESH_VERSION_FLAG: number;
|
|
1696
1853
|
/**
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1854
|
+
* Sentinel value resolved (not rejected) by `commit()` when
|
|
1855
|
+
* `coordinatedRetry: true` and the transaction encountered an IsBusy
|
|
1856
|
+
* conflict. JS should retry the transaction body immediately.
|
|
1857
|
+
*/
|
|
1701
1858
|
RETRY_NOW_VALUE: number;
|
|
1702
1859
|
TRANSACTION_LOG_TOKEN: number;
|
|
1703
1860
|
TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
|
|
@@ -1718,36 +1875,38 @@ declare const registryStatus: () => RegistryStatus;
|
|
|
1718
1875
|
declare const shutdown: () => void;
|
|
1719
1876
|
declare const currentThreadId: () => number;
|
|
1720
1877
|
/**
|
|
1721
|
-
* Advises the kernel that the file-backed pages of every mapped transaction log
|
|
1722
|
-
* are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
|
|
1723
|
-
* without being freed — useful during replication catch-up, where a full read of
|
|
1724
|
-
* the logs would otherwise inflate the container's reclaimable cache toward its
|
|
1725
|
-
* cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
|
|
1726
|
-
*
|
|
1727
|
-
* The transaction log registry is a process-global singleton shared across all
|
|
1728
|
-
* worker threads, so a single call cools every worker's maps. Call it on an
|
|
1729
|
-
* interval from one thread (e.g. an `unref()`ed timer on the main thread).
|
|
1730
|
-
*
|
|
1731
|
-
* @returns the number of maps cooled and total file-backed bytes advised.
|
|
1732
|
-
*/
|
|
1878
|
+
* Advises the kernel that the file-backed pages of every mapped transaction log
|
|
1879
|
+
* are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
|
|
1880
|
+
* without being freed — useful during replication catch-up, where a full read of
|
|
1881
|
+
* the logs would otherwise inflate the container's reclaimable cache toward its
|
|
1882
|
+
* cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
|
|
1883
|
+
*
|
|
1884
|
+
* The transaction log registry is a process-global singleton shared across all
|
|
1885
|
+
* worker threads, so a single call cools every worker's maps. Call it on an
|
|
1886
|
+
* interval from one thread (e.g. an `unref()`ed timer on the main thread).
|
|
1887
|
+
*
|
|
1888
|
+
* @returns the number of maps cooled and total file-backed bytes advised.
|
|
1889
|
+
*/
|
|
1733
1890
|
declare const coolTransactionLogs: () => {
|
|
1734
1891
|
maps: number;
|
|
1735
1892
|
bytes: number;
|
|
1736
1893
|
};
|
|
1737
1894
|
/**
|
|
1738
|
-
* Creates a native file lock using the specified file path (`flock` on POSIX,
|
|
1739
|
-
* `LockFileEx` on Windows)
|
|
1740
|
-
*
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
|
|
1746
|
-
|
|
1895
|
+
* Creates a native file lock using the specified file path (`flock` on POSIX,
|
|
1896
|
+
* `LockFileEx` on Windows), creating the file and any missing parent
|
|
1897
|
+
* directories. Exclusive by default; pass `shared` for a shared (reader) lock
|
|
1898
|
+
* that coexists with other shared holders but conflicts with an exclusive
|
|
1899
|
+
* holder in either direction. Returns an opaque non-zero token to pass to
|
|
1900
|
+
* `fileLockRelease`, or `0` if a conflicting holder — in any process,
|
|
1901
|
+
* container, or worker thread — currently has it. Throws on a hard error. The
|
|
1902
|
+
* OS handle is owned entirely in native code (no fd crosses into JS), and the
|
|
1903
|
+
* kernel releases the lock when the handle closes, including on process death.
|
|
1904
|
+
*/
|
|
1905
|
+
declare const tryFileLock: (file: string, shared?: boolean) => number;
|
|
1747
1906
|
/**
|
|
1748
|
-
* Releases a file lock acquired via `tryFileLock`. A no-op for
|
|
1749
|
-
* token `0` or an unknown token.
|
|
1750
|
-
*/
|
|
1907
|
+
* Releases a file lock acquired via `tryFileLock`. A no-op for
|
|
1908
|
+
* token `0` or an unknown token.
|
|
1909
|
+
*/
|
|
1751
1910
|
declare const fileLockRelease: (token: number) => void;
|
|
1752
1911
|
declare const stats: {
|
|
1753
1912
|
StatsLevel: {
|
|
@@ -1763,32 +1922,32 @@ declare const stats: {
|
|
|
1763
1922
|
//#endregion
|
|
1764
1923
|
//#region src/backup-stream.d.ts
|
|
1765
1924
|
/**
|
|
1766
|
-
* Options for streaming a backup via `db.backup(stream)`.
|
|
1767
|
-
*/
|
|
1925
|
+
* Options for streaming a backup via `db.backup(stream)`.
|
|
1926
|
+
*/
|
|
1768
1927
|
interface BackupStreamOptions {
|
|
1769
1928
|
/**
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1929
|
+
* Flush the memtable before streaming. Defaults to `true` when the database
|
|
1930
|
+
* was opened with `disableWAL` (otherwise unflushed data would be missing
|
|
1931
|
+
* from the stream), and `false` otherwise — matching `db.backup(dir)`.
|
|
1932
|
+
*/
|
|
1774
1933
|
flushBeforeBackup?: boolean;
|
|
1775
1934
|
/**
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1935
|
+
* Gzip-compress the archive before writing it to the stream, producing a
|
|
1936
|
+
* `.tar.gz` stream instead of a plain `.tar`. Defaults to `false`.
|
|
1937
|
+
*
|
|
1938
|
+
* Compression runs in the runtime's `CompressionStream`, downstream of the tar
|
|
1939
|
+
* encoder, so end-to-end backpressure is preserved. RocksDB SST files are
|
|
1940
|
+
* usually already block-compressed, so the additional savings vary with the
|
|
1941
|
+
* data and the configured compression.
|
|
1942
|
+
*/
|
|
1784
1943
|
gzip?: boolean;
|
|
1785
1944
|
/**
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1945
|
+
* Also stream the transaction log store as `transaction_logs/<store>/…`
|
|
1946
|
+
* entries (each `*.txnlog` and `txn.state` file) after the database files.
|
|
1947
|
+
* Defaults to `false`. Extraction reconstructs them next to the database, and
|
|
1948
|
+
* their mtimes are preserved so the store's age-based rotation/retention stays
|
|
1949
|
+
* correct.
|
|
1950
|
+
*/
|
|
1792
1951
|
transactionLogs?: boolean;
|
|
1793
1952
|
}
|
|
1794
1953
|
//#endregion
|
|
@@ -1796,418 +1955,418 @@ interface BackupStreamOptions {
|
|
|
1796
1955
|
type TransactionCallback<T> = (txn: Transaction, attempt: number) => T | PromiseLike<T>;
|
|
1797
1956
|
interface RocksDatabaseOptions extends StoreOptions {
|
|
1798
1957
|
/**
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1958
|
+
* The column family name.
|
|
1959
|
+
*
|
|
1960
|
+
* @default 'default'
|
|
1961
|
+
*/
|
|
1803
1962
|
name?: string;
|
|
1804
1963
|
}
|
|
1805
1964
|
interface TransactionOptions extends NativeTransactionOptions {
|
|
1806
1965
|
/**
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1966
|
+
* The maximum number of times to retry the transaction.
|
|
1967
|
+
*
|
|
1968
|
+
* @default 3
|
|
1969
|
+
*/
|
|
1811
1970
|
maxRetries?: number;
|
|
1812
1971
|
/**
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1972
|
+
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
1973
|
+
*
|
|
1974
|
+
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
1975
|
+
*/
|
|
1817
1976
|
retryOnBusy?: boolean;
|
|
1818
1977
|
}
|
|
1819
1978
|
type RocksDBStat = StatsValue;
|
|
1820
1979
|
type RocksDBStats = StatsDefault | StatsAll;
|
|
1821
1980
|
/**
|
|
1822
|
-
* The main class for interacting with a RocksDB database.
|
|
1823
|
-
*
|
|
1824
|
-
* Before using this class, you must open the database first.
|
|
1825
|
-
*
|
|
1826
|
-
* @example
|
|
1827
|
-
* ```typescript
|
|
1828
|
-
* const db = RocksDatabase.open('/path/to/database');
|
|
1829
|
-
* await db.put('key', 'value');
|
|
1830
|
-
* const value = await db.get('key');
|
|
1831
|
-
* db.close();
|
|
1832
|
-
* ```
|
|
1833
|
-
*/
|
|
1981
|
+
* The main class for interacting with a RocksDB database.
|
|
1982
|
+
*
|
|
1983
|
+
* Before using this class, you must open the database first.
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```typescript
|
|
1987
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1988
|
+
* await db.put('key', 'value');
|
|
1989
|
+
* const value = await db.get('key');
|
|
1990
|
+
* db.close();
|
|
1991
|
+
* ```
|
|
1992
|
+
*/
|
|
1834
1993
|
declare class RocksDatabase extends DBI<DBITransactional> {
|
|
1835
1994
|
#private;
|
|
1836
1995
|
constructor(pathOrStore: string | Store, options?: RocksDatabaseOptions);
|
|
1837
1996
|
/**
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1997
|
+
* Removes all data from the database asynchronously.
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* ```typescript
|
|
2001
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2002
|
+
* await db.clear();
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
1846
2005
|
clear(): Promise<void>;
|
|
1847
2006
|
/**
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
2007
|
+
* Removes all entries from the database synchronously.
|
|
2008
|
+
*
|
|
2009
|
+
* @example
|
|
2010
|
+
* ```typescript
|
|
2011
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2012
|
+
* db.clearSync();
|
|
2013
|
+
* ```
|
|
2014
|
+
*/
|
|
1856
2015
|
clearSync(): void;
|
|
1857
2016
|
/**
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
2017
|
+
* Closes the database.
|
|
2018
|
+
*
|
|
2019
|
+
* @example
|
|
2020
|
+
* ```typescript
|
|
2021
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2022
|
+
* db.close();
|
|
2023
|
+
* ```
|
|
2024
|
+
*/
|
|
1866
2025
|
close(): void;
|
|
1867
2026
|
/**
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2027
|
+
* Compacts the entire key range of the database asynchronously.
|
|
2028
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
2029
|
+
*
|
|
2030
|
+
* @example
|
|
2031
|
+
* ```typescript
|
|
2032
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2033
|
+
* await db.compact();
|
|
2034
|
+
* ```
|
|
2035
|
+
*/
|
|
1877
2036
|
compact(options?: CompactOptions): Promise<void>;
|
|
1878
2037
|
/**
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2038
|
+
* Creates a backup of the entire database (all column families) into the
|
|
2039
|
+
* given directory, creating parent directories as needed, and resolves with
|
|
2040
|
+
* the new backup id. Use the `backups` namespace to restore, list, delete,
|
|
2041
|
+
* purge, or verify backups.
|
|
2042
|
+
*
|
|
2043
|
+
* When the database was opened with `disableWAL`, the memtable is flushed
|
|
2044
|
+
* before the backup by default so unflushed data is not lost.
|
|
2045
|
+
*
|
|
2046
|
+
* @example
|
|
2047
|
+
* ```typescript
|
|
2048
|
+
* import { backups } from '@harperfast/rocksdb-js';
|
|
2049
|
+
*
|
|
2050
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2051
|
+
* const id = await db.backup('/path/to/backups');
|
|
2052
|
+
* ```
|
|
2053
|
+
*/
|
|
1895
2054
|
backup(backupDir: string, options?: BackupOptions): Promise<number>;
|
|
1896
2055
|
/**
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
2056
|
+
* Streams a consistent snapshot of the entire database to a `WritableStream`
|
|
2057
|
+
* as a tar archive, with no intermediate copy written to disk. Resolves once
|
|
2058
|
+
* the stream has been fully written and closed.
|
|
2059
|
+
*
|
|
2060
|
+
* Backpressure is honored end to end, so a slow consumer (e.g. a network or
|
|
2061
|
+
* S3 upload) paces the backup rather than buffering it in memory. The archive
|
|
2062
|
+
* unpacks with any tar tool into a directory that opens as a RocksDB database.
|
|
2063
|
+
*
|
|
2064
|
+
* @example
|
|
2065
|
+
* ```typescript
|
|
2066
|
+
* const file = await fetch(uploadUrl, { method: 'PUT', body: stream });
|
|
2067
|
+
* await db.backup(stream); // `stream` is the request's WritableStream
|
|
2068
|
+
* ```
|
|
2069
|
+
*/
|
|
1911
2070
|
backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
|
|
1912
2071
|
/**
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
2072
|
+
* Creates a hardlinked, point-in-time, fully independent copy of the entire
|
|
2073
|
+
* database (all column families) at `targetPath` and resolves once written.
|
|
2074
|
+
*
|
|
2075
|
+
* Unlike a backup, a checkpoint is a normal, writable sibling database: open
|
|
2076
|
+
* it with {@link RocksDatabase.open} and it diverges independently from the
|
|
2077
|
+
* source. SST and blob files are hardlinked when `targetPath` is on the same
|
|
2078
|
+
* filesystem as the database and copied otherwise (other files such as the
|
|
2079
|
+
* MANIFEST are always copied), so the operation is near-instant on the same
|
|
2080
|
+
* filesystem. The memtable is flushed so the checkpoint includes the latest
|
|
2081
|
+
* writes even when the WAL is disabled.
|
|
2082
|
+
*
|
|
2083
|
+
* Parent directories are created as needed. `targetPath` itself must not
|
|
2084
|
+
* already exist (RocksDB creates the checkpoint directory) and rejects with
|
|
2085
|
+
* `Create checkpoint failed: target path exists` if it does. The caller is
|
|
2086
|
+
* responsible for eventual cleanup of the directory.
|
|
2087
|
+
*
|
|
2088
|
+
* @example
|
|
2089
|
+
* ```typescript
|
|
2090
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2091
|
+
* await db.createCheckpoint('/path/to/checkpoint');
|
|
2092
|
+
* const branch = RocksDatabase.open('/path/to/checkpoint');
|
|
2093
|
+
* ```
|
|
2094
|
+
*/
|
|
1936
2095
|
createCheckpoint(targetPath: string): Promise<void>;
|
|
1937
2096
|
/**
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
2097
|
+
* Compacts the entire key range of the database synchronously.
|
|
2098
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
2099
|
+
*
|
|
2100
|
+
* @example
|
|
2101
|
+
* ```typescript
|
|
2102
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2103
|
+
* db.compactSync();
|
|
2104
|
+
* ```
|
|
2105
|
+
*/
|
|
1947
2106
|
compactSync(options?: CompactOptions): void;
|
|
1948
2107
|
/**
|
|
1949
|
-
|
|
1950
|
-
|
|
2108
|
+
* Returns the list of column families in the RocksDB database.
|
|
2109
|
+
*/
|
|
1951
2110
|
get columns(): string[];
|
|
1952
2111
|
/**
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2112
|
+
* Set global database settings.
|
|
2113
|
+
*
|
|
2114
|
+
* @param options - The options for the database.
|
|
2115
|
+
*
|
|
2116
|
+
* @example
|
|
2117
|
+
* ```typescript
|
|
2118
|
+
* RocksDatabase.config({ blockCacheSize: 1024 * 1024 });
|
|
2119
|
+
* ```
|
|
2120
|
+
*/
|
|
1962
2121
|
static config(options: RocksDatabaseConfig): void;
|
|
1963
2122
|
/**
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2123
|
+
* Registers a process-wide event listener. Internal events emitted by the
|
|
2124
|
+
* native binding use namespaced keys (e.g. `'transactionLog:warning'`).
|
|
2125
|
+
*
|
|
2126
|
+
* Listeners are not tied to any specific database — they fire for every
|
|
2127
|
+
* matching event emitted in this process.
|
|
2128
|
+
*
|
|
2129
|
+
* @example
|
|
2130
|
+
* ```typescript
|
|
2131
|
+
* RocksDatabase.on('transactionLog:warning', (warning) => {
|
|
2132
|
+
* console.warn(warning);
|
|
2133
|
+
* });
|
|
2134
|
+
* ```
|
|
2135
|
+
*/
|
|
1977
2136
|
static on(event: string, callback: (...args: any[]) => void): void;
|
|
1978
2137
|
/**
|
|
1979
|
-
|
|
1980
|
-
|
|
2138
|
+
* Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
|
|
2139
|
+
*/
|
|
1981
2140
|
static addListener(event: string, callback: (...args: any[]) => void): void;
|
|
1982
2141
|
/**
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2142
|
+
* Removes a previously-registered process-wide event listener. The
|
|
2143
|
+
* callback identity must match the one passed to {@link RocksDatabase.on}.
|
|
2144
|
+
*
|
|
2145
|
+
* @returns `true` if a matching listener was removed.
|
|
2146
|
+
*/
|
|
1988
2147
|
static off(event: string, callback: (...args: any[]) => void): boolean;
|
|
1989
2148
|
/**
|
|
1990
|
-
|
|
1991
|
-
|
|
2149
|
+
* Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
|
|
2150
|
+
*/
|
|
1992
2151
|
static removeListener(event: string, callback: (...args: any[]) => void): boolean;
|
|
1993
2152
|
/**
|
|
1994
|
-
|
|
1995
|
-
|
|
2153
|
+
* Returns the number of process-wide listeners registered for the given event.
|
|
2154
|
+
*/
|
|
1996
2155
|
static listenerCount(event: string): number;
|
|
1997
2156
|
/**
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2157
|
+
* Emits a process-wide event. Mostly intended for tests and as a peer to
|
|
2158
|
+
* {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
|
|
2159
|
+
* `napi/global_events.h` directly rather than round-tripping through JS.
|
|
2160
|
+
*
|
|
2161
|
+
* @returns `true` if there was at least one listener.
|
|
2162
|
+
*/
|
|
2004
2163
|
static notify(event: string, ...args: any[]): boolean;
|
|
2005
2164
|
destroy(): void;
|
|
2006
2165
|
drop(): Promise<void>;
|
|
2007
2166
|
dropSync(): void;
|
|
2008
2167
|
get encoder(): Encoder | null;
|
|
2009
2168
|
/**
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2169
|
+
* Flushes the underlying database by performing a commit or clearing any buffered operations.
|
|
2170
|
+
*
|
|
2171
|
+
* @return {void} Does not return a value.
|
|
2172
|
+
*/
|
|
2014
2173
|
flush(): Promise<void>;
|
|
2015
2174
|
/**
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2175
|
+
* Synchronously flushes the underlying database by performing a commit or clearing any buffered operations.
|
|
2176
|
+
*
|
|
2177
|
+
* @return {void} Does not return a value.
|
|
2178
|
+
*/
|
|
2020
2179
|
flushSync(): void;
|
|
2021
2180
|
/**
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2181
|
+
* Gets a RocksDB database property as an integer.
|
|
2182
|
+
*
|
|
2183
|
+
* @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.num-blob-files').
|
|
2184
|
+
* @returns The property value as a number.
|
|
2185
|
+
*
|
|
2186
|
+
* @example
|
|
2187
|
+
* ```typescript
|
|
2188
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2189
|
+
* const blobFiles = db.getDBIntProperty('rocksdb.num-blob-files');
|
|
2190
|
+
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
2191
|
+
* ```
|
|
2192
|
+
*/
|
|
2034
2193
|
getDBIntProperty(propertyName: string): number | undefined;
|
|
2035
2194
|
/**
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2195
|
+
* Gets a RocksDB database property as a string.
|
|
2196
|
+
*
|
|
2197
|
+
* @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.levelstats').
|
|
2198
|
+
* @returns The property value as a string.
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```typescript
|
|
2202
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2203
|
+
* const levelStats = db.getDBProperty('rocksdb.levelstats');
|
|
2204
|
+
* const stats = db.getDBProperty('rocksdb.stats');
|
|
2205
|
+
* ```
|
|
2206
|
+
*/
|
|
2048
2207
|
getDBProperty(propertyName: string): string | undefined;
|
|
2049
2208
|
/**
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2209
|
+
* Retrieves the estimated number of keys in the database.
|
|
2210
|
+
*
|
|
2211
|
+
* @example
|
|
2212
|
+
* ```typescript
|
|
2213
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2214
|
+
* const estimated = db.getEstimatedKeyCount();
|
|
2215
|
+
* console.log(estimated);
|
|
2216
|
+
* ```
|
|
2217
|
+
*/
|
|
2059
2218
|
getEstimatedKeyCount(): number;
|
|
2060
2219
|
/**
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2220
|
+
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
2221
|
+
* milliseconds represented as a decimal number.
|
|
2222
|
+
*
|
|
2223
|
+
* @returns The current monotonic timestamp in milliseconds.
|
|
2224
|
+
*/
|
|
2066
2225
|
getMonotonicTimestamp(): number;
|
|
2067
2226
|
/**
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2227
|
+
* Returns a number representing a unix timestamp of the oldest unreleased
|
|
2228
|
+
* snapshot.
|
|
2229
|
+
*
|
|
2230
|
+
* @returns The oldest snapshot timestamp.
|
|
2231
|
+
*/
|
|
2073
2232
|
getOldestSnapshotTimestamp(): number;
|
|
2074
2233
|
/**
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2234
|
+
* Gets a RocksDB statistic.
|
|
2235
|
+
*
|
|
2236
|
+
* @param statName - The name of the statistic to retrieve.
|
|
2237
|
+
* @returns The statistic value.
|
|
2238
|
+
*/
|
|
2080
2239
|
getStat(statName: string): RocksDBStat;
|
|
2081
2240
|
/**
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2241
|
+
* Gets the RocksDB statistics. The RocksDB ticker/histogram stats require
|
|
2242
|
+
* statistics to be enabled, but the result always includes a summarized,
|
|
2243
|
+
* aggregate set of `txnlog.*` keys (across all of this database's transaction
|
|
2244
|
+
* logs), regardless of whether statistics are enabled. For detailed per-log
|
|
2245
|
+
* statistics, including memory-map usage, use `log.getStats()` on the log
|
|
2246
|
+
* returned by {@link RocksDatabase#useLog}.
|
|
2247
|
+
*
|
|
2248
|
+
* @example
|
|
2249
|
+
* ```typescript
|
|
2250
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2251
|
+
* const stats = db.getStats();
|
|
2252
|
+
* stats['txnlog.totalSizeBytes']; // bytes across all transaction logs
|
|
2253
|
+
* ```
|
|
2254
|
+
*/
|
|
2096
2255
|
getStats(all?: false): StatsDefault;
|
|
2097
2256
|
getStats(all: true): StatsAll;
|
|
2098
2257
|
/**
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2258
|
+
* Gets or creates a buffer that can be shared across worker threads.
|
|
2259
|
+
*
|
|
2260
|
+
* @param key - The key to get or create the buffer for.
|
|
2261
|
+
* @param defaultBuffer - The default buffer to copy and use if the buffer
|
|
2262
|
+
* does not exist.
|
|
2263
|
+
* @param [options] - The options for the buffer.
|
|
2264
|
+
* @param [options.callback] - A optional callback that receives
|
|
2265
|
+
* key-specific events.
|
|
2266
|
+
* @returns An `ArrayBuffer` that is internally backed by a shared block of
|
|
2267
|
+
* memory. The buffer also has `notify()` and `cancel()` methods that can be
|
|
2268
|
+
* used to notify the specified `options.callback`.
|
|
2269
|
+
*
|
|
2270
|
+
* @example
|
|
2271
|
+
* ```typescript
|
|
2272
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2273
|
+
* const buffer = db.getUserSharedBuffer('foo', new ArrayBuffer(10));
|
|
2274
|
+
*/
|
|
2116
2275
|
getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
|
|
2117
2276
|
/**
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2277
|
+
* Returns whether the database has a lock for the given key.
|
|
2278
|
+
*
|
|
2279
|
+
* @param key - The key to check.
|
|
2280
|
+
* @returns `true` if the database has a lock for the given key, `false`
|
|
2281
|
+
* otherwise.
|
|
2282
|
+
*
|
|
2283
|
+
* @example
|
|
2284
|
+
* ```typescript
|
|
2285
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2286
|
+
* db.hasLock('foo'); // false
|
|
2287
|
+
* db.tryLock('foo', () => {});
|
|
2288
|
+
* db.hasLock('foo'); // true
|
|
2289
|
+
* ```
|
|
2290
|
+
*/
|
|
2132
2291
|
hasLock(key: Key): boolean;
|
|
2133
2292
|
ifNoExists(_key: Key): Promise<void>;
|
|
2134
2293
|
/**
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2294
|
+
* Checks the process-global verification table for a fresh version match
|
|
2295
|
+
* on `key`. Returns `true` when the table currently records `version`. Use
|
|
2296
|
+
* this as a fast cache-freshness check before falling back to a full read:
|
|
2297
|
+
*
|
|
2298
|
+
* ```typescript
|
|
2299
|
+
* if (db.verifyVersion(key, cachedEntry.version)) {
|
|
2300
|
+
* return cachedEntry.value;
|
|
2301
|
+
* }
|
|
2302
|
+
* const value = db.getSync(key);
|
|
2303
|
+
* db.populateVersion(key, extractVersion(value));
|
|
2304
|
+
* ```
|
|
2305
|
+
*/
|
|
2147
2306
|
verifyVersion(key: Key, version: number): boolean;
|
|
2148
2307
|
/**
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2308
|
+
* Seeds the verification-table slot for `key` with `version`. Has no
|
|
2309
|
+
* effect if the slot is currently lock-tagged or if the verification
|
|
2310
|
+
* table is disabled.
|
|
2311
|
+
*/
|
|
2153
2312
|
populateVersion(key: Key, version: number): void;
|
|
2154
2313
|
/**
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2314
|
+
* Returns whether the database is open.
|
|
2315
|
+
*
|
|
2316
|
+
* @returns `true` if the database is open, `false` otherwise.
|
|
2317
|
+
*/
|
|
2159
2318
|
isOpen(): boolean;
|
|
2160
2319
|
/**
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2320
|
+
* Lists all transaction log names.
|
|
2321
|
+
*
|
|
2322
|
+
* @returns an array of transaction log names.
|
|
2323
|
+
*/
|
|
2165
2324
|
listLogs(): string[];
|
|
2166
2325
|
/**
|
|
2167
|
-
|
|
2168
|
-
|
|
2326
|
+
* The name of the database.
|
|
2327
|
+
*/
|
|
2169
2328
|
get name(): string;
|
|
2170
2329
|
/**
|
|
2171
|
-
|
|
2172
|
-
|
|
2330
|
+
* Whether the database is open in readonly mode.
|
|
2331
|
+
*/
|
|
2173
2332
|
get readOnly(): boolean;
|
|
2174
2333
|
/**
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2334
|
+
* Sugar method for opening a database.
|
|
2335
|
+
*
|
|
2336
|
+
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
2337
|
+
* @param options - The options for the database.
|
|
2338
|
+
* @returns A new RocksDatabase instance.
|
|
2339
|
+
*
|
|
2340
|
+
* @example
|
|
2341
|
+
* ```typescript
|
|
2342
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2343
|
+
* ```
|
|
2344
|
+
*/
|
|
2186
2345
|
static open(pathOrStore: string | Store, options?: RocksDatabaseOptions): RocksDatabase;
|
|
2187
2346
|
/**
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2347
|
+
* Opens the database. This function returns immediately if the database is
|
|
2348
|
+
* already open.
|
|
2349
|
+
*
|
|
2350
|
+
* @returns A new RocksDatabase instance.
|
|
2351
|
+
*
|
|
2352
|
+
* @example
|
|
2353
|
+
* ```typescript
|
|
2354
|
+
* const db = new RocksDatabase('/path/to/database');
|
|
2355
|
+
* db.open();
|
|
2356
|
+
* ```
|
|
2357
|
+
*/
|
|
2199
2358
|
open(): RocksDatabase;
|
|
2200
2359
|
/**
|
|
2201
|
-
|
|
2202
|
-
|
|
2360
|
+
* Returns the path to the database.
|
|
2361
|
+
*/
|
|
2203
2362
|
get path(): string;
|
|
2204
2363
|
/**
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2364
|
+
* Purges transaction logs.
|
|
2365
|
+
*
|
|
2366
|
+
* By default returns the paths of the deleted log files. Pass
|
|
2367
|
+
* `includeEntryCounts: true` to instead return, for each deleted file, its
|
|
2368
|
+
* path and the number of entries it held (`{ path, entries }`).
|
|
2369
|
+
*/
|
|
2211
2370
|
purgeLogs(options: PurgeLogsOptions & {
|
|
2212
2371
|
includeEntryCounts: true;
|
|
2213
2372
|
}): PurgedLog[];
|
|
@@ -2216,93 +2375,93 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2216
2375
|
}): string[];
|
|
2217
2376
|
purgeLogs(options?: PurgeLogsOptions): string[] | PurgedLog[];
|
|
2218
2377
|
/**
|
|
2219
|
-
|
|
2220
|
-
|
|
2378
|
+
* The status of the database.
|
|
2379
|
+
*/
|
|
2221
2380
|
get status(): "open" | "closed";
|
|
2222
2381
|
/**
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2382
|
+
* Executes all operations in the callback as a single transaction.
|
|
2383
|
+
*
|
|
2384
|
+
* @param callback - A async function that receives the transaction as an argument.
|
|
2385
|
+
* @returns A promise that resolves the `callback` return value.
|
|
2386
|
+
*
|
|
2387
|
+
* @example
|
|
2388
|
+
* ```typescript
|
|
2389
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2390
|
+
* await db.transaction(async (txn) => {
|
|
2391
|
+
* await txn.put('key', 'value');
|
|
2392
|
+
* });
|
|
2393
|
+
* ```
|
|
2394
|
+
*/
|
|
2236
2395
|
transaction<T>(callback: TransactionCallback<T>, options?: TransactionOptions): Promise<T | void>;
|
|
2237
2396
|
/**
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2397
|
+
* Executes all operations in the callback as a single transaction.
|
|
2398
|
+
*
|
|
2399
|
+
* @param callback - A function that receives the transaction as an
|
|
2400
|
+
* argument. If the callback return promise-like value, it is awaited
|
|
2401
|
+
* before committing the transaction. Otherwise, the callback is treated as
|
|
2402
|
+
* synchronous.
|
|
2403
|
+
* @returns The `callback` return value.
|
|
2404
|
+
*
|
|
2405
|
+
* @example
|
|
2406
|
+
* ```typescript
|
|
2407
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2408
|
+
* await db.transaction(async (txn) => {
|
|
2409
|
+
* await txn.put('key', 'value');
|
|
2410
|
+
* });
|
|
2411
|
+
* ```
|
|
2412
|
+
*/
|
|
2254
2413
|
transactionSync<T>(callback: TransactionCallback<T>, options?: TransactionOptions): T | PromiseLike<T> | void;
|
|
2255
2414
|
/**
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2415
|
+
* Attempts to acquire a lock for a given key. If the lock is available,
|
|
2416
|
+
* the function returns `true` and the optional callback is never called.
|
|
2417
|
+
* If the lock is not available, the function returns `false` and the
|
|
2418
|
+
* callback is queued until the lock is released.
|
|
2419
|
+
*
|
|
2420
|
+
* @param key - The key to lock.
|
|
2421
|
+
* @param onUnlocked - A callback to call when the lock is released.
|
|
2422
|
+
*
|
|
2423
|
+
* @example
|
|
2424
|
+
* ```typescript
|
|
2425
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2426
|
+
* db.tryLock('foo', () => {
|
|
2427
|
+
* console.log('lock acquired');
|
|
2428
|
+
* });
|
|
2429
|
+
* ```
|
|
2430
|
+
* @returns `true` if the lock was acquired, `false` otherwise.
|
|
2431
|
+
*/
|
|
2273
2432
|
tryLock(key: Key, onUnlocked?: () => void): boolean;
|
|
2274
2433
|
/**
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2434
|
+
* Releases the lock on the given key and calls any queued `onUnlocked`
|
|
2435
|
+
* callback handlers.
|
|
2436
|
+
*
|
|
2437
|
+
* @param key - The key to unlock.
|
|
2438
|
+
* @returns `true` if the lock was released or `false` if the lock did not
|
|
2439
|
+
* exist.
|
|
2440
|
+
*
|
|
2441
|
+
* @example
|
|
2442
|
+
* ```typescript
|
|
2443
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2444
|
+
* db.tryLock('foo', () => {});
|
|
2445
|
+
* db.unlock('foo'); // returns `true`
|
|
2446
|
+
* db.unlock('foo'); // already unlocked, returns `false`
|
|
2447
|
+
* ```
|
|
2448
|
+
*/
|
|
2290
2449
|
unlock(key: Key): void;
|
|
2291
2450
|
/**
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2451
|
+
* Excecutes a function using a thread-safe lock to ensure mutual
|
|
2452
|
+
* exclusion.
|
|
2453
|
+
*
|
|
2454
|
+
* @param callback - A callback to call when the lock is acquired.
|
|
2455
|
+
* @returns A promise that resolves when the lock is acquired.
|
|
2456
|
+
*
|
|
2457
|
+
* @example
|
|
2458
|
+
* ```typescript
|
|
2459
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
2460
|
+
* await db.withLock(async (waited) => {
|
|
2461
|
+
* console.log('lock acquired', waited);
|
|
2462
|
+
* });
|
|
2463
|
+
* ```
|
|
2464
|
+
*/
|
|
2306
2465
|
withLock(key: Key, callback: () => void | Promise<void>): Promise<void> | undefined;
|
|
2307
2466
|
}
|
|
2308
2467
|
//#endregion
|
|
@@ -2323,10 +2482,10 @@ interface TransactionLog$1 {
|
|
|
2323
2482
|
version: number;
|
|
2324
2483
|
}
|
|
2325
2484
|
/**
|
|
2326
|
-
* Loads an entire transaction log file into memory.
|
|
2327
|
-
* @param path - The path to the transaction log file.
|
|
2328
|
-
* @returns The transaction log.
|
|
2329
|
-
*/
|
|
2485
|
+
* Loads an entire transaction log file into memory.
|
|
2486
|
+
* @param path - The path to the transaction log file.
|
|
2487
|
+
* @returns The transaction log.
|
|
2488
|
+
*/
|
|
2330
2489
|
declare function parseTransactionLog(path: string, options?: {
|
|
2331
2490
|
skipData?: boolean;
|
|
2332
2491
|
}): TransactionLog$1;
|
|
@@ -2337,5 +2496,5 @@ declare const versions: {
|
|
|
2337
2496
|
"rocksdb-js": string;
|
|
2338
2497
|
};
|
|
2339
2498
|
//#endregion
|
|
2340
|
-
export { type BackupInfo, type BackupOptions, type BackupStreamOptions, DBI, DBIterator, type GetStatsMethod, type IteratorOptions, type Key, type RestoreMode, type RestoreOptions, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsAll, type StatsAllExtras, type StatsBasics, type StatsCurated, type StatsCuratedExtras, type StatsDefault, type StatsHistogramData, type StatsValue, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, type TransactionLogPosition, type TransactionLogStats, backups, constants, coolTransactionLogs, currentThreadId, fileLockRelease, parseTransactionLog, registryStatus, shutdown, stats, tryFileLock, versions };
|
|
2499
|
+
export { type BackupInfo, type BackupOptions, type BackupStreamOptions, DBI, DBIterator, type GetStatsMethod, type IteratorOptions, type Key, type RestoreMode, type RestoreOptions, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsAll, type StatsAllExtras, type StatsBasics, type StatsCurated, type StatsCuratedExtras, type StatsDefault, type StatsHistogramData, type StatsValue, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, type TransactionLogFileValidation, type TransactionLogPosition, type TransactionLogStats, type TransactionLogStoreValidation, type ValidateTransactionLogStoreOptions, backups, constants, coolTransactionLogs, currentThreadId, fileLockRelease, parseTransactionLog, registryStatus, shutdown, stats, tryFileLock, validateTransactionLogStore, versions };
|
|
2341
2500
|
//# sourceMappingURL=index.d.cts.map
|