@harperfast/rocksdb-js 1.1.1 → 1.3.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 +128 -20
- package/bin/rocksdb-js.mjs +568 -0
- package/dist/index.cjs +198 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -7
- package/dist/index.d.mts +175 -7
- package/dist/index.mjs +198 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -20
package/dist/index.d.cts
CHANGED
|
@@ -36,16 +36,21 @@ interface DBIteratorValue<T> {
|
|
|
36
36
|
value: T;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Wraps
|
|
40
|
-
*
|
|
39
|
+
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
40
|
+
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
41
|
+
* fallback path used for oversized data or stable-buffer decoders).
|
|
42
|
+
*
|
|
43
|
+
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
44
|
+
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
45
|
+
* so this class is responsible for building the `IteratorResult`.
|
|
41
46
|
*/
|
|
42
47
|
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
43
48
|
#private;
|
|
44
|
-
iterator:
|
|
49
|
+
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
45
50
|
store: Store;
|
|
46
|
-
constructor(iterator:
|
|
51
|
+
constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean);
|
|
47
52
|
[Symbol.iterator](): Iterator<DBIteratorValue<T>>;
|
|
48
|
-
next(
|
|
53
|
+
next(): IteratorResult<DBIteratorValue<T>>;
|
|
49
54
|
return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
|
|
50
55
|
throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
|
|
51
56
|
}
|
|
@@ -57,6 +62,10 @@ type StoreIteratorOptions = IteratorOptions & DBITransactional;
|
|
|
57
62
|
type StorePutOptions = PutOptions & DBITransactional;
|
|
58
63
|
type StoreRangeOptions = RangeOptions & DBITransactional;
|
|
59
64
|
type StoreRemoveOptions = DBITransactional | unknown;
|
|
65
|
+
type CompactOptions = {
|
|
66
|
+
start?: Key;
|
|
67
|
+
end?: Key;
|
|
68
|
+
};
|
|
60
69
|
/**
|
|
61
70
|
* Options for the `Store` class.
|
|
62
71
|
*/
|
|
@@ -163,6 +172,24 @@ declare class Store {
|
|
|
163
172
|
*/
|
|
164
173
|
maxKeySize: number;
|
|
165
174
|
/**
|
|
175
|
+
* The maximum number of memtables that can be queued per column family
|
|
176
|
+
* before writes stall. Higher values absorb write bursts while flushes catch
|
|
177
|
+
* up, at the cost of memory.
|
|
178
|
+
*/
|
|
179
|
+
maxWriteBufferNumber?: number;
|
|
180
|
+
/**
|
|
181
|
+
* The bytes of recent memtable history to retain in memory for transaction
|
|
182
|
+
* conflict checking. `-1` derives the value from
|
|
183
|
+
* `maxWriteBufferNumber * writeBufferSize`.
|
|
184
|
+
*/
|
|
185
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
186
|
+
/**
|
|
187
|
+
* The total memtable budget in bytes across all column families. When the
|
|
188
|
+
* sum of memtables reaches this size, RocksDB flushes the largest one. `0`
|
|
189
|
+
* disables the global trigger so per-CF `writeBufferSize` drives flushing.
|
|
190
|
+
*/
|
|
191
|
+
dbWriteBufferSize?: number;
|
|
192
|
+
/**
|
|
166
193
|
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
167
194
|
*/
|
|
168
195
|
name: string;
|
|
@@ -172,9 +199,10 @@ declare class Store {
|
|
|
172
199
|
noBlockCache?: boolean;
|
|
173
200
|
/**
|
|
174
201
|
* The number of threads to use for parallel operations. This is a RocksDB
|
|
175
|
-
* option.
|
|
202
|
+
* option. When undefined, the native layer picks
|
|
203
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
176
204
|
*/
|
|
177
|
-
parallelismThreads
|
|
205
|
+
parallelismThreads?: number;
|
|
178
206
|
/**
|
|
179
207
|
* The path to the database.
|
|
180
208
|
*/
|
|
@@ -230,6 +258,11 @@ declare class Store {
|
|
|
230
258
|
*/
|
|
231
259
|
transactionLogsPath?: string;
|
|
232
260
|
/**
|
|
261
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
262
|
+
* sealed and flushed.
|
|
263
|
+
*/
|
|
264
|
+
writeBufferSize?: number;
|
|
265
|
+
/**
|
|
233
266
|
* The function used to encode keys using the shared `keyBuffer`.
|
|
234
267
|
*/
|
|
235
268
|
writeKey: WriteKeyFunction;
|
|
@@ -245,6 +278,28 @@ declare class Store {
|
|
|
245
278
|
*/
|
|
246
279
|
close(): void;
|
|
247
280
|
/**
|
|
281
|
+
* Compacts the entire key range of the database asynchronously.
|
|
282
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
287
|
+
* await db.compact();
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Compacts the entire key range of the database synchronously.
|
|
293
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
298
|
+
* db.compactSync();
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
compactSync(options?: CompactOptions): void;
|
|
302
|
+
/**
|
|
248
303
|
* Decodes a key from the database.
|
|
249
304
|
*
|
|
250
305
|
* @param key - The key to decode.
|
|
@@ -429,10 +484,43 @@ type TransactionLog = {
|
|
|
429
484
|
_lastCommittedPosition: Float64Array;
|
|
430
485
|
_logBuffers: Map<number, WeakRef<LogBuffer>>;
|
|
431
486
|
};
|
|
487
|
+
/**
|
|
488
|
+
* Shape of options that can be passed to the native iterator constructor for
|
|
489
|
+
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
490
|
+
* options are passed via the bitmask `flags` argument instead.
|
|
491
|
+
*/
|
|
492
|
+
type NativeIteratorAdvancedOptions = {
|
|
493
|
+
adaptiveReadahead?: boolean;
|
|
494
|
+
asyncIO?: boolean;
|
|
495
|
+
autoReadaheadSize?: boolean;
|
|
496
|
+
backgroundPurgeOnIteratorCleanup?: boolean;
|
|
497
|
+
fillCache?: boolean;
|
|
498
|
+
readaheadSize?: number;
|
|
499
|
+
tailing?: boolean;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* The result of a single native iterator step. A number value matches one of
|
|
503
|
+
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
504
|
+
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
505
|
+
* needs a stable value buffer.
|
|
506
|
+
*/
|
|
507
|
+
type NativeIteratorResult = number | {
|
|
508
|
+
key: Buffer;
|
|
509
|
+
value?: Buffer;
|
|
510
|
+
};
|
|
511
|
+
declare class NativeIteratorCls {
|
|
512
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
513
|
+
next(): NativeIteratorResult;
|
|
514
|
+
return(): void;
|
|
515
|
+
throw(err?: unknown): void;
|
|
516
|
+
}
|
|
432
517
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
433
518
|
type NativeDatabaseOptions = {
|
|
519
|
+
dbWriteBufferSize?: number;
|
|
434
520
|
disableWAL?: boolean;
|
|
435
521
|
enableStats?: boolean;
|
|
522
|
+
maxWriteBufferNumber?: number;
|
|
523
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
436
524
|
mode?: NativeDatabaseMode;
|
|
437
525
|
name?: string;
|
|
438
526
|
noBlockCache?: boolean;
|
|
@@ -443,6 +531,7 @@ type NativeDatabaseOptions = {
|
|
|
443
531
|
transactionLogMaxSize?: number;
|
|
444
532
|
transactionLogRetentionMs?: number;
|
|
445
533
|
transactionLogsPath?: string;
|
|
534
|
+
writeBufferSize?: number;
|
|
446
535
|
};
|
|
447
536
|
type ResolveCallback<T> = (value: T) => void;
|
|
448
537
|
type RejectCallback = (err: Error) => void;
|
|
@@ -469,6 +558,8 @@ type NativeDatabase = {
|
|
|
469
558
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
470
559
|
clearSync(): void;
|
|
471
560
|
close(): void;
|
|
561
|
+
compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
|
|
562
|
+
compactSync(start?: Key, end?: Key): void;
|
|
472
563
|
columns: string[];
|
|
473
564
|
destroy(): void;
|
|
474
565
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
@@ -497,6 +588,7 @@ type NativeDatabase = {
|
|
|
497
588
|
removeSync(key: BufferWithDataView, txnId?: number): void;
|
|
498
589
|
setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
499
590
|
setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
591
|
+
setIteratorState(buffer: Buffer | Uint8Array): void;
|
|
500
592
|
tryLock(key: BufferWithDataView, callback?: () => void): boolean;
|
|
501
593
|
unlock(key: BufferWithDataView): void;
|
|
502
594
|
useLog(name: string): TransactionLog;
|
|
@@ -504,6 +596,41 @@ type NativeDatabase = {
|
|
|
504
596
|
};
|
|
505
597
|
type RocksDatabaseConfig = {
|
|
506
598
|
blockCacheSize?: number;
|
|
599
|
+
compactOnClose?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* Total memtable memory limit (bytes) shared across every database opened
|
|
602
|
+
* in this process. When set, RocksDB uses a single `WriteBufferManager` so
|
|
603
|
+
* write buffers are bounded process-wide rather than per database. 0 (the
|
|
604
|
+
* default) disables the manager.
|
|
605
|
+
*
|
|
606
|
+
* Can be updated at runtime; the new size takes effect on the existing
|
|
607
|
+
* manager via `SetBufferSize`.
|
|
608
|
+
*/
|
|
609
|
+
writeBufferManagerSize?: number;
|
|
610
|
+
/**
|
|
611
|
+
* When `true`, memtable memory is "charged" against the shared block cache
|
|
612
|
+
* so the block cache and write buffers draw from a single pool. During
|
|
613
|
+
* write bursts the cache shrinks to make room for memtables; once
|
|
614
|
+
* memtables flush, the cache can grow back into the reclaimed space.
|
|
615
|
+
*
|
|
616
|
+
* Has no effect when the block cache is disabled (size 0) or
|
|
617
|
+
* `writeBufferManagerSize` is 0. Must be set on the same `config()` call
|
|
618
|
+
* that first enables the manager — changing it after the manager has been
|
|
619
|
+
* created has no effect on the running instance.
|
|
620
|
+
*
|
|
621
|
+
* @default false
|
|
622
|
+
*/
|
|
623
|
+
writeBufferManagerCostToCache?: boolean;
|
|
624
|
+
/**
|
|
625
|
+
* When `true`, writes are stalled once the manager's `buffer_size` is
|
|
626
|
+
* exceeded, providing a hard cap on memtable memory. When `false`,
|
|
627
|
+
* memtables are allowed to grow past the limit and flushes are simply
|
|
628
|
+
* scheduled more aggressively. Off by default to favor write throughput
|
|
629
|
+
* over hard memory bounding.
|
|
630
|
+
*
|
|
631
|
+
* @default false
|
|
632
|
+
*/
|
|
633
|
+
writeBufferManagerAllowStall?: boolean;
|
|
507
634
|
};
|
|
508
635
|
type RegistryStatusDB = {
|
|
509
636
|
path: string;
|
|
@@ -523,6 +650,14 @@ declare const constants: {
|
|
|
523
650
|
TRANSACTION_LOG_TOKEN: number;
|
|
524
651
|
TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
|
|
525
652
|
TRANSACTION_LOG_FILE_HEADER_SIZE: number;
|
|
653
|
+
ITERATOR_REVERSE_FLAG: number;
|
|
654
|
+
ITERATOR_INCLUSIVE_END_FLAG: number;
|
|
655
|
+
ITERATOR_EXCLUSIVE_START_FLAG: number;
|
|
656
|
+
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
657
|
+
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
658
|
+
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
659
|
+
ITERATOR_RESULT_DONE: number;
|
|
660
|
+
ITERATOR_RESULT_FAST: number;
|
|
526
661
|
};
|
|
527
662
|
declare const NativeDatabase: NativeDatabase;
|
|
528
663
|
declare const NativeTransaction: NativeTransaction;
|
|
@@ -975,6 +1110,28 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
975
1110
|
*/
|
|
976
1111
|
close(): void;
|
|
977
1112
|
/**
|
|
1113
|
+
* Compacts the entire key range of the database asynchronously.
|
|
1114
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1119
|
+
* await db.compact();
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
1122
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Compacts the entire key range of the database synchronously.
|
|
1125
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1130
|
+
* db.compactSync();
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
compactSync(options?: CompactOptions): void;
|
|
1134
|
+
/**
|
|
978
1135
|
* Returns the list of column families in the RocksDB database.
|
|
979
1136
|
*/
|
|
980
1137
|
get columns(): string[];
|
|
@@ -1034,6 +1191,17 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1034
1191
|
*/
|
|
1035
1192
|
getDBProperty(propertyName: string): string | undefined;
|
|
1036
1193
|
/**
|
|
1194
|
+
* Retrieves the estimated number of keys in the database.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* ```typescript
|
|
1198
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1199
|
+
* const estimated = db.getEstimatedKeyCount();
|
|
1200
|
+
* console.log(estimated);
|
|
1201
|
+
* ```
|
|
1202
|
+
*/
|
|
1203
|
+
getEstimatedKeyCount(): number;
|
|
1204
|
+
/**
|
|
1037
1205
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1038
1206
|
* milliseconds represented as a decimal number.
|
|
1039
1207
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -36,16 +36,21 @@ interface DBIteratorValue<T> {
|
|
|
36
36
|
value: T;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Wraps
|
|
40
|
-
*
|
|
39
|
+
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
40
|
+
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
41
|
+
* fallback path used for oversized data or stable-buffer decoders).
|
|
42
|
+
*
|
|
43
|
+
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
44
|
+
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
45
|
+
* so this class is responsible for building the `IteratorResult`.
|
|
41
46
|
*/
|
|
42
47
|
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
43
48
|
#private;
|
|
44
|
-
iterator:
|
|
49
|
+
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
45
50
|
store: Store;
|
|
46
|
-
constructor(iterator:
|
|
51
|
+
constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean);
|
|
47
52
|
[Symbol.iterator](): Iterator<DBIteratorValue<T>>;
|
|
48
|
-
next(
|
|
53
|
+
next(): IteratorResult<DBIteratorValue<T>>;
|
|
49
54
|
return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
|
|
50
55
|
throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
|
|
51
56
|
}
|
|
@@ -57,6 +62,10 @@ type StoreIteratorOptions = IteratorOptions & DBITransactional;
|
|
|
57
62
|
type StorePutOptions = PutOptions & DBITransactional;
|
|
58
63
|
type StoreRangeOptions = RangeOptions & DBITransactional;
|
|
59
64
|
type StoreRemoveOptions = DBITransactional | unknown;
|
|
65
|
+
type CompactOptions = {
|
|
66
|
+
start?: Key;
|
|
67
|
+
end?: Key;
|
|
68
|
+
};
|
|
60
69
|
/**
|
|
61
70
|
* Options for the `Store` class.
|
|
62
71
|
*/
|
|
@@ -163,6 +172,24 @@ declare class Store {
|
|
|
163
172
|
*/
|
|
164
173
|
maxKeySize: number;
|
|
165
174
|
/**
|
|
175
|
+
* The maximum number of memtables that can be queued per column family
|
|
176
|
+
* before writes stall. Higher values absorb write bursts while flushes catch
|
|
177
|
+
* up, at the cost of memory.
|
|
178
|
+
*/
|
|
179
|
+
maxWriteBufferNumber?: number;
|
|
180
|
+
/**
|
|
181
|
+
* The bytes of recent memtable history to retain in memory for transaction
|
|
182
|
+
* conflict checking. `-1` derives the value from
|
|
183
|
+
* `maxWriteBufferNumber * writeBufferSize`.
|
|
184
|
+
*/
|
|
185
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
186
|
+
/**
|
|
187
|
+
* The total memtable budget in bytes across all column families. When the
|
|
188
|
+
* sum of memtables reaches this size, RocksDB flushes the largest one. `0`
|
|
189
|
+
* disables the global trigger so per-CF `writeBufferSize` drives flushing.
|
|
190
|
+
*/
|
|
191
|
+
dbWriteBufferSize?: number;
|
|
192
|
+
/**
|
|
166
193
|
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
167
194
|
*/
|
|
168
195
|
name: string;
|
|
@@ -172,9 +199,10 @@ declare class Store {
|
|
|
172
199
|
noBlockCache?: boolean;
|
|
173
200
|
/**
|
|
174
201
|
* The number of threads to use for parallel operations. This is a RocksDB
|
|
175
|
-
* option.
|
|
202
|
+
* option. When undefined, the native layer picks
|
|
203
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
176
204
|
*/
|
|
177
|
-
parallelismThreads
|
|
205
|
+
parallelismThreads?: number;
|
|
178
206
|
/**
|
|
179
207
|
* The path to the database.
|
|
180
208
|
*/
|
|
@@ -230,6 +258,11 @@ declare class Store {
|
|
|
230
258
|
*/
|
|
231
259
|
transactionLogsPath?: string;
|
|
232
260
|
/**
|
|
261
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
262
|
+
* sealed and flushed.
|
|
263
|
+
*/
|
|
264
|
+
writeBufferSize?: number;
|
|
265
|
+
/**
|
|
233
266
|
* The function used to encode keys using the shared `keyBuffer`.
|
|
234
267
|
*/
|
|
235
268
|
writeKey: WriteKeyFunction;
|
|
@@ -245,6 +278,28 @@ declare class Store {
|
|
|
245
278
|
*/
|
|
246
279
|
close(): void;
|
|
247
280
|
/**
|
|
281
|
+
* Compacts the entire key range of the database asynchronously.
|
|
282
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
287
|
+
* await db.compact();
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Compacts the entire key range of the database synchronously.
|
|
293
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
298
|
+
* db.compactSync();
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
compactSync(options?: CompactOptions): void;
|
|
302
|
+
/**
|
|
248
303
|
* Decodes a key from the database.
|
|
249
304
|
*
|
|
250
305
|
* @param key - The key to decode.
|
|
@@ -429,10 +484,43 @@ type TransactionLog = {
|
|
|
429
484
|
_lastCommittedPosition: Float64Array;
|
|
430
485
|
_logBuffers: Map<number, WeakRef<LogBuffer>>;
|
|
431
486
|
};
|
|
487
|
+
/**
|
|
488
|
+
* Shape of options that can be passed to the native iterator constructor for
|
|
489
|
+
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
490
|
+
* options are passed via the bitmask `flags` argument instead.
|
|
491
|
+
*/
|
|
492
|
+
type NativeIteratorAdvancedOptions = {
|
|
493
|
+
adaptiveReadahead?: boolean;
|
|
494
|
+
asyncIO?: boolean;
|
|
495
|
+
autoReadaheadSize?: boolean;
|
|
496
|
+
backgroundPurgeOnIteratorCleanup?: boolean;
|
|
497
|
+
fillCache?: boolean;
|
|
498
|
+
readaheadSize?: number;
|
|
499
|
+
tailing?: boolean;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* The result of a single native iterator step. A number value matches one of
|
|
503
|
+
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
504
|
+
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
505
|
+
* needs a stable value buffer.
|
|
506
|
+
*/
|
|
507
|
+
type NativeIteratorResult = number | {
|
|
508
|
+
key: Buffer;
|
|
509
|
+
value?: Buffer;
|
|
510
|
+
};
|
|
511
|
+
declare class NativeIteratorCls {
|
|
512
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
513
|
+
next(): NativeIteratorResult;
|
|
514
|
+
return(): void;
|
|
515
|
+
throw(err?: unknown): void;
|
|
516
|
+
}
|
|
432
517
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
433
518
|
type NativeDatabaseOptions = {
|
|
519
|
+
dbWriteBufferSize?: number;
|
|
434
520
|
disableWAL?: boolean;
|
|
435
521
|
enableStats?: boolean;
|
|
522
|
+
maxWriteBufferNumber?: number;
|
|
523
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
436
524
|
mode?: NativeDatabaseMode;
|
|
437
525
|
name?: string;
|
|
438
526
|
noBlockCache?: boolean;
|
|
@@ -443,6 +531,7 @@ type NativeDatabaseOptions = {
|
|
|
443
531
|
transactionLogMaxSize?: number;
|
|
444
532
|
transactionLogRetentionMs?: number;
|
|
445
533
|
transactionLogsPath?: string;
|
|
534
|
+
writeBufferSize?: number;
|
|
446
535
|
};
|
|
447
536
|
type ResolveCallback<T> = (value: T) => void;
|
|
448
537
|
type RejectCallback = (err: Error) => void;
|
|
@@ -469,6 +558,8 @@ type NativeDatabase = {
|
|
|
469
558
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
470
559
|
clearSync(): void;
|
|
471
560
|
close(): void;
|
|
561
|
+
compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
|
|
562
|
+
compactSync(start?: Key, end?: Key): void;
|
|
472
563
|
columns: string[];
|
|
473
564
|
destroy(): void;
|
|
474
565
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
@@ -497,6 +588,7 @@ type NativeDatabase = {
|
|
|
497
588
|
removeSync(key: BufferWithDataView, txnId?: number): void;
|
|
498
589
|
setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
499
590
|
setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
591
|
+
setIteratorState(buffer: Buffer | Uint8Array): void;
|
|
500
592
|
tryLock(key: BufferWithDataView, callback?: () => void): boolean;
|
|
501
593
|
unlock(key: BufferWithDataView): void;
|
|
502
594
|
useLog(name: string): TransactionLog;
|
|
@@ -504,6 +596,41 @@ type NativeDatabase = {
|
|
|
504
596
|
};
|
|
505
597
|
type RocksDatabaseConfig = {
|
|
506
598
|
blockCacheSize?: number;
|
|
599
|
+
compactOnClose?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* Total memtable memory limit (bytes) shared across every database opened
|
|
602
|
+
* in this process. When set, RocksDB uses a single `WriteBufferManager` so
|
|
603
|
+
* write buffers are bounded process-wide rather than per database. 0 (the
|
|
604
|
+
* default) disables the manager.
|
|
605
|
+
*
|
|
606
|
+
* Can be updated at runtime; the new size takes effect on the existing
|
|
607
|
+
* manager via `SetBufferSize`.
|
|
608
|
+
*/
|
|
609
|
+
writeBufferManagerSize?: number;
|
|
610
|
+
/**
|
|
611
|
+
* When `true`, memtable memory is "charged" against the shared block cache
|
|
612
|
+
* so the block cache and write buffers draw from a single pool. During
|
|
613
|
+
* write bursts the cache shrinks to make room for memtables; once
|
|
614
|
+
* memtables flush, the cache can grow back into the reclaimed space.
|
|
615
|
+
*
|
|
616
|
+
* Has no effect when the block cache is disabled (size 0) or
|
|
617
|
+
* `writeBufferManagerSize` is 0. Must be set on the same `config()` call
|
|
618
|
+
* that first enables the manager — changing it after the manager has been
|
|
619
|
+
* created has no effect on the running instance.
|
|
620
|
+
*
|
|
621
|
+
* @default false
|
|
622
|
+
*/
|
|
623
|
+
writeBufferManagerCostToCache?: boolean;
|
|
624
|
+
/**
|
|
625
|
+
* When `true`, writes are stalled once the manager's `buffer_size` is
|
|
626
|
+
* exceeded, providing a hard cap on memtable memory. When `false`,
|
|
627
|
+
* memtables are allowed to grow past the limit and flushes are simply
|
|
628
|
+
* scheduled more aggressively. Off by default to favor write throughput
|
|
629
|
+
* over hard memory bounding.
|
|
630
|
+
*
|
|
631
|
+
* @default false
|
|
632
|
+
*/
|
|
633
|
+
writeBufferManagerAllowStall?: boolean;
|
|
507
634
|
};
|
|
508
635
|
type RegistryStatusDB = {
|
|
509
636
|
path: string;
|
|
@@ -523,6 +650,14 @@ declare const constants: {
|
|
|
523
650
|
TRANSACTION_LOG_TOKEN: number;
|
|
524
651
|
TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
|
|
525
652
|
TRANSACTION_LOG_FILE_HEADER_SIZE: number;
|
|
653
|
+
ITERATOR_REVERSE_FLAG: number;
|
|
654
|
+
ITERATOR_INCLUSIVE_END_FLAG: number;
|
|
655
|
+
ITERATOR_EXCLUSIVE_START_FLAG: number;
|
|
656
|
+
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
657
|
+
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
658
|
+
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
659
|
+
ITERATOR_RESULT_DONE: number;
|
|
660
|
+
ITERATOR_RESULT_FAST: number;
|
|
526
661
|
};
|
|
527
662
|
declare const NativeDatabase: NativeDatabase;
|
|
528
663
|
declare const NativeTransaction: NativeTransaction;
|
|
@@ -975,6 +1110,28 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
975
1110
|
*/
|
|
976
1111
|
close(): void;
|
|
977
1112
|
/**
|
|
1113
|
+
* Compacts the entire key range of the database asynchronously.
|
|
1114
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1119
|
+
* await db.compact();
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
1122
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Compacts the entire key range of the database synchronously.
|
|
1125
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1130
|
+
* db.compactSync();
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
compactSync(options?: CompactOptions): void;
|
|
1134
|
+
/**
|
|
978
1135
|
* Returns the list of column families in the RocksDB database.
|
|
979
1136
|
*/
|
|
980
1137
|
get columns(): string[];
|
|
@@ -1034,6 +1191,17 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1034
1191
|
*/
|
|
1035
1192
|
getDBProperty(propertyName: string): string | undefined;
|
|
1036
1193
|
/**
|
|
1194
|
+
* Retrieves the estimated number of keys in the database.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* ```typescript
|
|
1198
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1199
|
+
* const estimated = db.getEstimatedKeyCount();
|
|
1200
|
+
* console.log(estimated);
|
|
1201
|
+
* ```
|
|
1202
|
+
*/
|
|
1203
|
+
getEstimatedKeyCount(): number;
|
|
1204
|
+
/**
|
|
1037
1205
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1038
1206
|
* milliseconds represented as a decimal number.
|
|
1039
1207
|
*
|