@harperfast/rocksdb-js 2.8.0 → 2.9.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 +337 -19
- package/dist/index.cjs +271 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +317 -34
- package/dist/index.d.mts +317 -34
- package/dist/index.mjs +270 -36
- package/dist/index.mjs.map +1 -1
- package/docs/stats.md +46 -1
- package/docs/transaction-log.md +18 -5
- package/docs/transaction-timestamp-integrity-design.md +123 -0
- package/package.json +19 -19
package/dist/index.d.cts
CHANGED
|
@@ -142,7 +142,7 @@ interface BackupInfo {
|
|
|
142
142
|
* await backups.restore('/path/to/backups', '/path/to/restored-db');
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
|
-
declare const backups: {
|
|
145
|
+
export declare const backups: {
|
|
146
146
|
/**
|
|
147
147
|
* Restores a database from a backup directory into a (closed) database
|
|
148
148
|
* directory. The default mode purges the destination directory, so it must
|
|
@@ -234,7 +234,7 @@ interface DBIteratorValue<T> {
|
|
|
234
234
|
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
235
235
|
* so this class is responsible for building the `IteratorResult`.
|
|
236
236
|
*/
|
|
237
|
-
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
237
|
+
export declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
238
238
|
#private;
|
|
239
239
|
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
240
240
|
store: Store;
|
|
@@ -372,8 +372,55 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "compression" | "comp
|
|
|
372
372
|
* will throw an error with code `ERR_DATABASE_READONLY`, except for
|
|
373
373
|
* `flush()`/`flushSync()`/`compact()`/`compactSync()`, which succeed as
|
|
374
374
|
* no-ops.
|
|
375
|
+
*
|
|
376
|
+
* A read-only open is a **point-in-time snapshot**: it replays the MANIFEST
|
|
377
|
+
* as of the open and never sees later writes. It is safe against a
|
|
378
|
+
* quiescent database (nothing else writing), but **unsafe against a live
|
|
379
|
+
* writer**: the open holds no reference on the files it is about to read,
|
|
380
|
+
* so a concurrent compaction or blob GC in the writing process can delete
|
|
381
|
+
* one mid-open and the open fails with `ERR_CONCURRENT_COMPACTION` (the
|
|
382
|
+
* database is not corrupt — the reader lost a race). Even a successful open
|
|
383
|
+
* can fail *later reads* the same way: files the snapshot references are
|
|
384
|
+
* opened lazily, and the writer keeps deleting obsolete ones. To follow a
|
|
385
|
+
* database another process is actively writing, open a secondary instead
|
|
386
|
+
* (see `secondaryPath`) — that is the supported mode for a live follower.
|
|
375
387
|
*/
|
|
376
388
|
readOnly?: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Opens the database as a **secondary instance**: a read-only follower of a
|
|
391
|
+
* live primary that tolerates the primary deleting files and sees new
|
|
392
|
+
* writes on each `catchUpWithPrimary()` / `catchUpWithPrimarySync()` call.
|
|
393
|
+
* This is the supported way to read a database another process is actively
|
|
394
|
+
* writing (a plain `readOnly` open is only safe against a quiescent
|
|
395
|
+
* database — see `readOnly`).
|
|
396
|
+
*
|
|
397
|
+
* The value is the secondary instance's own workspace directory (RocksDB
|
|
398
|
+
* keeps the secondary's private state there; it is created if missing).
|
|
399
|
+
* It must be distinct from the database `path` (enforced at open) and
|
|
400
|
+
* exclusive to one secondary instance — two secondaries sharing a
|
|
401
|
+
* workspace corrupt each other's state. Reusing a workspace in-process for
|
|
402
|
+
* a DIFFERENT database is rejected at open (the same database and
|
|
403
|
+
* workspace share the one follower instance), and a kernel advisory lock
|
|
404
|
+
* on `<secondaryPath>/.secondary.lock`
|
|
405
|
+
* excludes other processes — but on filesystems without advisory locking
|
|
406
|
+
* (e.g. FUSE/9p mounts behind Docker Desktop bind mounts) the lock
|
|
407
|
+
* degrades to a no-op, and on network filesystems it does not exclude
|
|
408
|
+
* across hosts, so workspace exclusivity is the caller's job there.
|
|
409
|
+
*
|
|
410
|
+
* Implies `readOnly: true` (combining with an explicit `readOnly: false`
|
|
411
|
+
* throws) and forces `maxOpenFiles: -1`: every table and blob file is
|
|
412
|
+
* opened and held for the life of each version, which is what makes the
|
|
413
|
+
* primary's file deletions safe — note the file-descriptor footprint on
|
|
414
|
+
* large databases. Column families created by the primary after the
|
|
415
|
+
* secondary opens are invisible until the secondary reopens.
|
|
416
|
+
*
|
|
417
|
+
* Note: RocksDB upstream documents secondary instances as unsupported in
|
|
418
|
+
* combination with integrated BlobDB (which this library enables for
|
|
419
|
+
* values >= 2KB); this library's pinned RocksDB build handles blob files
|
|
420
|
+
* in secondary mode and it is covered by tests, but the combination is
|
|
421
|
+
* not guaranteed by upstream.
|
|
422
|
+
*/
|
|
423
|
+
secondaryPath?: string;
|
|
377
424
|
sharedStructuresKey?: symbol;
|
|
378
425
|
/**
|
|
379
426
|
* A string containing the amount of time or the number of milliseconds to
|
|
@@ -407,7 +454,7 @@ type ArrayBufferWithNotify = ArrayBuffer & {
|
|
|
407
454
|
* already owns throws. (Sharing with the owning database's `Transaction`
|
|
408
455
|
* instances is expected and allowed.)
|
|
409
456
|
*/
|
|
410
|
-
declare class Store {
|
|
457
|
+
export declare class Store {
|
|
411
458
|
#private;
|
|
412
459
|
/**
|
|
413
460
|
* The database instance.
|
|
@@ -544,6 +591,11 @@ declare class Store {
|
|
|
544
591
|
* The path to the database.
|
|
545
592
|
*/
|
|
546
593
|
path: string;
|
|
594
|
+
/**
|
|
595
|
+
* The open database's resolved filesystem identity, read once from
|
|
596
|
+
* `NativeDatabase.identityPath`. `undefined` until opened.
|
|
597
|
+
*/
|
|
598
|
+
identityPath?: string;
|
|
547
599
|
/**
|
|
548
600
|
* Whether to use pessimistic locking for transactions. When `true`,
|
|
549
601
|
* transactions will fail as soon as a conflict is detected. When `false`,
|
|
@@ -557,6 +609,13 @@ declare class Store {
|
|
|
557
609
|
* no-ops.
|
|
558
610
|
*/
|
|
559
611
|
readOnly: boolean;
|
|
612
|
+
/**
|
|
613
|
+
* The secondary instance's workspace directory when the database is opened
|
|
614
|
+
* as a secondary (see `RocksDatabaseOptions.secondaryPath`); `undefined`
|
|
615
|
+
* otherwise. A secondary is read-only, so `readOnly` is `true` whenever
|
|
616
|
+
* this is set.
|
|
617
|
+
*/
|
|
618
|
+
secondaryPath?: string;
|
|
560
619
|
/**
|
|
561
620
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
562
621
|
* access structure.
|
|
@@ -616,6 +675,24 @@ declare class Store {
|
|
|
616
675
|
* @param options - The options for the store.
|
|
617
676
|
*/
|
|
618
677
|
constructor(path: string, options?: StoreOptions);
|
|
678
|
+
/**
|
|
679
|
+
* Creates an independent `Store` for another column family of the same
|
|
680
|
+
* database, used by {@link RocksDatabase#use}. The returned store shares the
|
|
681
|
+
* underlying database but must have its own codec state: a mutable
|
|
682
|
+
* encoder/decoder instance cannot be shared across column families (opening a
|
|
683
|
+
* view mutates the encoder's `name`, and clearing a view resets its
|
|
684
|
+
* `structures`), so a pre-constructed instance is rejected here — supply an
|
|
685
|
+
* encoder factory (`{ Encoder }`) or a named `encoding` instead.
|
|
686
|
+
*
|
|
687
|
+
* Override this in a `Store` subclass whose constructor cannot be recreated
|
|
688
|
+
* from `(path, options)` (e.g. it takes injected dependencies) or that needs
|
|
689
|
+
* to control how a view's codec state is built.
|
|
690
|
+
*
|
|
691
|
+
* @param name - The column family name for the derived store.
|
|
692
|
+
* @param options - Options overriding this store's, for the derived store.
|
|
693
|
+
* @returns A new, independent `Store` bound to `name`.
|
|
694
|
+
*/
|
|
695
|
+
createColumnFamilyStore(name: string, options?: StoreOptions): Store;
|
|
619
696
|
/**
|
|
620
697
|
* Closes the database.
|
|
621
698
|
*/
|
|
@@ -835,7 +912,7 @@ declare const RETRY_NOW: number;
|
|
|
835
912
|
/**
|
|
836
913
|
* Provides transaction level operations to a transaction callback.
|
|
837
914
|
*/
|
|
838
|
-
declare class Transaction extends DBI {
|
|
915
|
+
export declare class Transaction extends DBI {
|
|
839
916
|
#private;
|
|
840
917
|
/**
|
|
841
918
|
* Create a new transaction.
|
|
@@ -869,10 +946,12 @@ declare class Transaction extends DBI {
|
|
|
869
946
|
*/
|
|
870
947
|
commitSync(): void;
|
|
871
948
|
/**
|
|
872
|
-
* Returns the transaction
|
|
873
|
-
* the transaction
|
|
949
|
+
* Returns the transaction timestamp in milliseconds since the Unix epoch. It
|
|
950
|
+
* defaults to a process-wide monotonic value assigned when the transaction
|
|
951
|
+
* was created. A producer may use this value as its write identity; the
|
|
952
|
+
* transaction log uses it as the batch key.
|
|
874
953
|
*
|
|
875
|
-
* @returns The transaction
|
|
954
|
+
* @returns The transaction timestamp in milliseconds.
|
|
876
955
|
*/
|
|
877
956
|
getTimestamp(): number;
|
|
878
957
|
/**
|
|
@@ -880,9 +959,14 @@ declare class Transaction extends DBI {
|
|
|
880
959
|
*/
|
|
881
960
|
get id(): number;
|
|
882
961
|
/**
|
|
883
|
-
*
|
|
962
|
+
* Overrides the transaction timestamp in milliseconds since the Unix epoch.
|
|
963
|
+
* Call this before reading the timestamp or staging writes when adopting an
|
|
964
|
+
* origin timestamp for replication or replay. Once a write or log entry is
|
|
965
|
+
* staged, the timestamp is frozen, but reapplying the same timestamp remains
|
|
966
|
+
* idempotent while the transaction is pending. The value must be finite,
|
|
967
|
+
* positive, and below 8640000000000000.
|
|
884
968
|
*
|
|
885
|
-
* @param timestamp - The timestamp to set in
|
|
969
|
+
* @param timestamp - The timestamp to set in milliseconds.
|
|
886
970
|
*/
|
|
887
971
|
setTimestamp(timestamp?: number): void;
|
|
888
972
|
}
|
|
@@ -1024,7 +1108,7 @@ interface DBITransactional {
|
|
|
1024
1108
|
*
|
|
1025
1109
|
* This class is not meant to be used directly.
|
|
1026
1110
|
*/
|
|
1027
|
-
declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
1111
|
+
export declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
1028
1112
|
/**
|
|
1029
1113
|
* The RocksDB context for `get()`, `put()`, and `remove()`.
|
|
1030
1114
|
*/
|
|
@@ -1230,7 +1314,13 @@ declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
|
1230
1314
|
}
|
|
1231
1315
|
//#endregion
|
|
1232
1316
|
//#region src/stats.d.ts
|
|
1233
|
-
/**
|
|
1317
|
+
/**
|
|
1318
|
+
* Database-level RocksDB statistics types for `db.getStats()` / `db.getStat()`.
|
|
1319
|
+
*
|
|
1320
|
+
* The `writeBufferManager.*` keys are the exception to "database-level": the
|
|
1321
|
+
* WriteBufferManager is a process-wide singleton, so those values describe every
|
|
1322
|
+
* database in the process. See `getWriteBufferManagerStats()`.
|
|
1323
|
+
*/
|
|
1234
1324
|
type StatsHistogramData = {
|
|
1235
1325
|
average: number;
|
|
1236
1326
|
count: number;
|
|
@@ -1282,6 +1372,11 @@ type StatsBasics = {
|
|
|
1282
1372
|
"txnlog.replayGapBytes": number;
|
|
1283
1373
|
"commitPipeline.logQueueDepth": number;
|
|
1284
1374
|
"commitPipeline.commitQueueDepth": number;
|
|
1375
|
+
"writeBufferManager.bufferSize": number;
|
|
1376
|
+
"writeBufferManager.memoryUsage": number;
|
|
1377
|
+
"writeBufferManager.mutableMemoryUsage": number;
|
|
1378
|
+
"writeBufferManager.stallActive": number;
|
|
1379
|
+
"writeBufferManager.stallActiveMs": number;
|
|
1285
1380
|
};
|
|
1286
1381
|
type StatsCuratedExtras = {
|
|
1287
1382
|
"rocksdb.block.cache.hit": number;
|
|
@@ -1746,7 +1841,7 @@ interface ValidateTransactionLogStoreOptions {
|
|
|
1746
1841
|
* }
|
|
1747
1842
|
* ```
|
|
1748
1843
|
*/
|
|
1749
|
-
declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
|
|
1844
|
+
export declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
|
|
1750
1845
|
//#endregion
|
|
1751
1846
|
//#region src/load-binding.d.ts
|
|
1752
1847
|
/**
|
|
@@ -1769,7 +1864,7 @@ declare function validateTransactionLogStore(path: string, options?: ValidateTra
|
|
|
1769
1864
|
* });
|
|
1770
1865
|
* ```
|
|
1771
1866
|
*/
|
|
1772
|
-
interface BackgroundError extends Error {
|
|
1867
|
+
export interface BackgroundError extends Error {
|
|
1773
1868
|
/** Always `'BackgroundError'`. */
|
|
1774
1869
|
name: string;
|
|
1775
1870
|
/** Discriminator for the error class; always `'background'` here. */
|
|
@@ -1925,7 +2020,7 @@ type TransactionLogStats = {
|
|
|
1925
2020
|
maxAgeThreshold: number;
|
|
1926
2021
|
};
|
|
1927
2022
|
};
|
|
1928
|
-
type TransactionLog = {
|
|
2023
|
+
export type TransactionLog = {
|
|
1929
2024
|
new (db: NativeDatabase, name: string): TransactionLog;
|
|
1930
2025
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
1931
2026
|
getLogFileSize(sequenceId?: number): number;
|
|
@@ -1966,7 +2061,7 @@ type NativeIteratorResult = number | {
|
|
|
1966
2061
|
value?: Buffer;
|
|
1967
2062
|
};
|
|
1968
2063
|
declare class NativeIteratorCls {
|
|
1969
|
-
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
2064
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions, transactionId?: number);
|
|
1970
2065
|
next(): NativeIteratorResult;
|
|
1971
2066
|
return(): void;
|
|
1972
2067
|
throw(err?: unknown): void;
|
|
@@ -2017,6 +2112,15 @@ type NativeDatabaseOptions = {
|
|
|
2017
2112
|
noBlockCache?: boolean;
|
|
2018
2113
|
parallelismThreads?: number;
|
|
2019
2114
|
readOnly?: boolean;
|
|
2115
|
+
/**
|
|
2116
|
+
* A present, non-empty string opens the database via `DB::OpenAsSecondary`:
|
|
2117
|
+
* a read-only follower of a live primary that advances with
|
|
2118
|
+
* `catchUpWithPrimary()`. The value is the secondary instance's own
|
|
2119
|
+
* workspace directory (created if missing), distinct from `path` (the
|
|
2120
|
+
* primary's data directory) and exclusive to one secondary instance.
|
|
2121
|
+
* Implies `readOnly: true` and forces `maxOpenFiles: -1`.
|
|
2122
|
+
*/
|
|
2123
|
+
secondaryPath?: string;
|
|
2020
2124
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
2021
2125
|
transactionLogMaxAgeThreshold?: number;
|
|
2022
2126
|
transactionLogMaxSize?: number;
|
|
@@ -2101,6 +2205,8 @@ type NativeDatabase = {
|
|
|
2101
2205
|
flushBeforeBackup?: boolean;
|
|
2102
2206
|
transactionLogs?: boolean;
|
|
2103
2207
|
}): void;
|
|
2208
|
+
catchUpWithPrimary(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
2209
|
+
catchUpWithPrimarySync(): void;
|
|
2104
2210
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
2105
2211
|
clearSync(): void;
|
|
2106
2212
|
close(): void;
|
|
@@ -2140,6 +2246,7 @@ type NativeDatabase = {
|
|
|
2140
2246
|
getSync(keyLengthOrKeyBuffer: number | Buffer, flags: number, txnId?: number, expectedVersion?: number): Buffer;
|
|
2141
2247
|
getUserSharedBuffer(key: BufferWithDataView, defaultBuffer: ArrayBuffer, callback?: UserSharedBufferCallback): ArrayBuffer;
|
|
2142
2248
|
hasLock(key: BufferWithDataView): boolean;
|
|
2249
|
+
identityPath: string | undefined;
|
|
2143
2250
|
listeners(event: string | BufferWithDataView): number;
|
|
2144
2251
|
listLogs(): string[];
|
|
2145
2252
|
opened: boolean;
|
|
@@ -2243,10 +2350,84 @@ type RegistryStatus = RegistryStatusDB[];
|
|
|
2243
2350
|
* `new BackgroundError()` (which would omit `severity` / `writesDisabled` / …)
|
|
2244
2351
|
* is a type error.
|
|
2245
2352
|
*/
|
|
2246
|
-
declare const BackgroundError: new (details: Pick<BackgroundError, "message" | "severity" | "severityName" | "writesDisabled" | "reason" | "reasonName"> & {
|
|
2353
|
+
export declare const BackgroundError: new (details: Pick<BackgroundError, "message" | "severity" | "severityName" | "writesDisabled" | "reason" | "reasonName"> & {
|
|
2247
2354
|
type?: string;
|
|
2248
2355
|
}) => BackgroundError;
|
|
2249
|
-
|
|
2356
|
+
/**
|
|
2357
|
+
* Live state of the process-wide `WriteBufferManager` singleton — see
|
|
2358
|
+
* {@link getWriteBufferManagerStats}.
|
|
2359
|
+
*/
|
|
2360
|
+
type WriteBufferManagerStats = {
|
|
2361
|
+
/**
|
|
2362
|
+
* Whether a manager has been created in this process. `bufferSize`,
|
|
2363
|
+
* `memoryUsage`, `mutableMemoryUsage`, `stallActive`, `stallActiveMs`,
|
|
2364
|
+
* `watchdogRunning` and `columnFamilies` are 0/false when not; `allowStall`
|
|
2365
|
+
* and `costToCache` still reflect the configured setting, and
|
|
2366
|
+
* `inventoryAvailable` is `true`.
|
|
2367
|
+
*/
|
|
2368
|
+
enabled: boolean;
|
|
2369
|
+
/** The manager's budget in bytes (`writeBufferManagerSize`, live). */
|
|
2370
|
+
bufferSize: number;
|
|
2371
|
+
/** Total memtable memory charged to the manager, in bytes. */
|
|
2372
|
+
memoryUsage: number;
|
|
2373
|
+
/** The share of `memoryUsage` held by active (mutable) memtables, in bytes. */
|
|
2374
|
+
mutableMemoryUsage: number;
|
|
2375
|
+
allowStall: boolean;
|
|
2376
|
+
costToCache: boolean;
|
|
2377
|
+
stallActive: boolean;
|
|
2378
|
+
/**
|
|
2379
|
+
* How long the current stall has been active, in milliseconds; 0 when not
|
|
2380
|
+
* stalled. Sampled once a second by the stall watchdog, so it is 0 for the
|
|
2381
|
+
* first second of a stall and whenever `watchdogRunning` is false.
|
|
2382
|
+
*/
|
|
2383
|
+
stallActiveMs: number;
|
|
2384
|
+
/**
|
|
2385
|
+
* Whether the stall watchdog is running. It runs only while a manager exists
|
|
2386
|
+
* with `writeBufferManagerAllowStall`, and only when
|
|
2387
|
+
* `ROCKSDB_JS_WBM_STALL_WARN_MS` is not `0`.
|
|
2388
|
+
*/
|
|
2389
|
+
watchdogRunning: boolean;
|
|
2390
|
+
/**
|
|
2391
|
+
* Live column families across every database attached to this manager. A
|
|
2392
|
+
* dropped column family keeps charging the manager until its last handle
|
|
2393
|
+
* closes, so it is counted until then.
|
|
2394
|
+
*/
|
|
2395
|
+
columnFamilies: number;
|
|
2396
|
+
/**
|
|
2397
|
+
* `false` when the column-family inventory could not be collected because the
|
|
2398
|
+
* database registry was locked — most plausibly by a close that is itself
|
|
2399
|
+
* waiting out this stall. `columnFamilies` is then `0` and
|
|
2400
|
+
* `maxWriteBufferSizeToMaintain` empty; every other field is still live.
|
|
2401
|
+
*/
|
|
2402
|
+
inventoryAvailable: boolean;
|
|
2403
|
+
/**
|
|
2404
|
+
* Effective per-column-family `max_write_buffer_size_to_maintain` (as a decimal
|
|
2405
|
+
* string) to the number of those column families holding it. Effective, not
|
|
2406
|
+
* requested: RocksDB rewrites a requested `0` for a transaction database.
|
|
2407
|
+
*/
|
|
2408
|
+
maxWriteBufferSizeToMaintain: Record<string, number>;
|
|
2409
|
+
};
|
|
2410
|
+
/**
|
|
2411
|
+
* Reads the live state of the process-wide `WriteBufferManager`: its budget,
|
|
2412
|
+
* charged memory, mutable share, stall state, and attached column-family
|
|
2413
|
+
* inventory. The manager is shared by every database and worker thread in the
|
|
2414
|
+
* process.
|
|
2415
|
+
*
|
|
2416
|
+
* A WriteBufferManager stall does not pass through RocksDB's `WriteController`,
|
|
2417
|
+
* so it is not reflected by `rocksdb.stall.micros`, `db.isWriteStalled()`, or
|
|
2418
|
+
* the `'writeStall'` event. Use `stallActive` to distinguish this condition from
|
|
2419
|
+
* an idle database.
|
|
2420
|
+
*
|
|
2421
|
+
* @example
|
|
2422
|
+
* ```typescript
|
|
2423
|
+
* const wbm = getWriteBufferManagerStats();
|
|
2424
|
+
* if (wbm.stallActive) {
|
|
2425
|
+
* log.warn(`writes stalled for ${wbm.stallActiveMs}ms`);
|
|
2426
|
+
* }
|
|
2427
|
+
* ```
|
|
2428
|
+
*/
|
|
2429
|
+
export declare const getWriteBufferManagerStats: () => WriteBufferManagerStats;
|
|
2430
|
+
export declare const constants: {
|
|
2250
2431
|
ALWAYS_CREATE_NEW_BUFFER_FLAG: number;
|
|
2251
2432
|
NOT_IN_MEMORY_CACHE_FLAG: number;
|
|
2252
2433
|
ONLY_IF_IN_MEMORY_CACHE_FLAG: number;
|
|
@@ -2282,6 +2463,7 @@ declare const constants: {
|
|
|
2282
2463
|
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
2283
2464
|
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
2284
2465
|
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
2466
|
+
ITERATOR_HAS_TRANSACTION_ID_FLAG: number;
|
|
2285
2467
|
ITERATOR_RESULT_DONE: number;
|
|
2286
2468
|
ITERATOR_RESULT_FAST: number;
|
|
2287
2469
|
};
|
|
@@ -2293,13 +2475,13 @@ declare const constants: {
|
|
|
2293
2475
|
* always present. Use it to validate a `compression` option or to pick an
|
|
2294
2476
|
* algorithm that is actually available at runtime.
|
|
2295
2477
|
*/
|
|
2296
|
-
declare const supportedCompression: readonly string[];
|
|
2478
|
+
export declare const supportedCompression: readonly string[];
|
|
2297
2479
|
declare const NativeDatabase: NativeDatabase;
|
|
2298
2480
|
declare const NativeTransaction: NativeTransaction;
|
|
2299
|
-
declare const TransactionLog: TransactionLog;
|
|
2300
|
-
declare const registryStatus: () => RegistryStatus;
|
|
2301
|
-
declare const shutdown: () => void;
|
|
2302
|
-
declare const currentThreadId: () => number;
|
|
2481
|
+
export declare const TransactionLog: TransactionLog;
|
|
2482
|
+
export declare const registryStatus: () => RegistryStatus;
|
|
2483
|
+
export declare const shutdown: () => void;
|
|
2484
|
+
export declare const currentThreadId: () => number;
|
|
2303
2485
|
/**
|
|
2304
2486
|
* Advises the kernel that the file-backed pages of every mapped transaction log
|
|
2305
2487
|
* are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
|
|
@@ -2313,7 +2495,7 @@ declare const currentThreadId: () => number;
|
|
|
2313
2495
|
*
|
|
2314
2496
|
* @returns the number of maps cooled and total file-backed bytes advised.
|
|
2315
2497
|
*/
|
|
2316
|
-
declare const coolTransactionLogs: () => {
|
|
2498
|
+
export declare const coolTransactionLogs: () => {
|
|
2317
2499
|
maps: number;
|
|
2318
2500
|
bytes: number;
|
|
2319
2501
|
};
|
|
@@ -2328,13 +2510,13 @@ declare const coolTransactionLogs: () => {
|
|
|
2328
2510
|
* OS handle is owned entirely in native code (no fd crosses into JS), and the
|
|
2329
2511
|
* kernel releases the lock when the handle closes, including on process death.
|
|
2330
2512
|
*/
|
|
2331
|
-
declare const tryFileLock: (file: string, shared?: boolean) => number;
|
|
2513
|
+
export declare const tryFileLock: (file: string, shared?: boolean) => number;
|
|
2332
2514
|
/**
|
|
2333
2515
|
* Releases a file lock acquired via `tryFileLock`. A no-op for
|
|
2334
2516
|
* token `0` or an unknown token.
|
|
2335
2517
|
*/
|
|
2336
|
-
declare const fileLockRelease: (token: number) => void;
|
|
2337
|
-
declare const stats: {
|
|
2518
|
+
export declare const fileLockRelease: (token: number) => void;
|
|
2519
|
+
export declare const stats: {
|
|
2338
2520
|
StatsLevel: {
|
|
2339
2521
|
DisableAll: number;
|
|
2340
2522
|
ExceptTickers: number;
|
|
@@ -2400,7 +2582,7 @@ interface CountEstimatorOptions extends CountEstimateOptions {}
|
|
|
2400
2582
|
* results are memoized per checkpoint, so repeated reads between `advance()`
|
|
2401
2583
|
* calls are free.
|
|
2402
2584
|
*/
|
|
2403
|
-
declare class CountEstimator {
|
|
2585
|
+
export declare class CountEstimator {
|
|
2404
2586
|
#private;
|
|
2405
2587
|
constructor(store: Store, options?: CountEstimatorOptions);
|
|
2406
2588
|
/**
|
|
@@ -2467,7 +2649,7 @@ type RocksDBStats = StatsDefault | StatsAll;
|
|
|
2467
2649
|
* db.close();
|
|
2468
2650
|
* ```
|
|
2469
2651
|
*/
|
|
2470
|
-
declare class RocksDatabase extends DBI<DBITransactional> {
|
|
2652
|
+
export declare class RocksDatabase extends DBI<DBITransactional> {
|
|
2471
2653
|
#private;
|
|
2472
2654
|
constructor(pathOrStore: string | Store, options?: RocksDatabaseOptions);
|
|
2473
2655
|
/**
|
|
@@ -2674,6 +2856,36 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2674
2856
|
* @returns `true` if there was at least one listener.
|
|
2675
2857
|
*/
|
|
2676
2858
|
static notify(event: string, ...args: any[]): boolean;
|
|
2859
|
+
/**
|
|
2860
|
+
* Advances a secondary instance to the primary's current state by tailing
|
|
2861
|
+
* and replaying the primary's MANIFEST and WAL. A secondary does not see
|
|
2862
|
+
* the primary's writes until this (or {@link catchUpWithPrimarySync}) is
|
|
2863
|
+
* called. Concurrent reads through this handle remain safe while the
|
|
2864
|
+
* catch-up runs.
|
|
2865
|
+
*
|
|
2866
|
+
* Only valid on a database opened with the `secondaryPath` option; throws
|
|
2867
|
+
* with code `ERR_NOT_SECONDARY` otherwise.
|
|
2868
|
+
*
|
|
2869
|
+
* Advances the **database** view only. Against a cross-process primary,
|
|
2870
|
+
* transaction-log reads keep serving the stores discovered at open (a store
|
|
2871
|
+
* the primary creates later, and its appends, need a reopen); a primary in
|
|
2872
|
+
* the same process shares the store registry, so its stores and appends are
|
|
2873
|
+
* visible immediately. Either way a log entry can describe data this
|
|
2874
|
+
* handle's database view does not have yet — the log write completes before
|
|
2875
|
+
* the RocksDB commit for every writer, so consumers must tolerate the log
|
|
2876
|
+
* leading the database.
|
|
2877
|
+
*
|
|
2878
|
+
* Await one call before starting the next: the replay holds a libuv worker
|
|
2879
|
+
* for its whole duration and concurrent calls queue on a per-database mutex
|
|
2880
|
+
* while holding theirs, so overlapping catch-ups on a backlogged follower
|
|
2881
|
+
* can exhaust the default four-thread pool and stall unrelated I/O.
|
|
2882
|
+
*/
|
|
2883
|
+
catchUpWithPrimary(): Promise<void>;
|
|
2884
|
+
/**
|
|
2885
|
+
* Synchronous version of {@link catchUpWithPrimary}. The replay runs on the
|
|
2886
|
+
* JS thread, so prefer the async form unless the caller is already blocking.
|
|
2887
|
+
*/
|
|
2888
|
+
catchUpWithPrimarySync(): void;
|
|
2677
2889
|
destroy(): void;
|
|
2678
2890
|
drop(): Promise<void>;
|
|
2679
2891
|
dropSync(): void;
|
|
@@ -2793,6 +3005,27 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2793
3005
|
* ```
|
|
2794
3006
|
*/
|
|
2795
3007
|
getDBProperty(propertyName: string): string | undefined;
|
|
3008
|
+
/**
|
|
3009
|
+
* Whether RocksDB is currently applying write backpressure to this database —
|
|
3010
|
+
* either delaying (rate-limiting) or fully stopping writes. This is the
|
|
3011
|
+
* authoritative, live pull counterpart to the `'writeStall'`
|
|
3012
|
+
* [event](../README.md#event-writestall): the event pushes per-column-family
|
|
3013
|
+
* transitions (and is rate-limited), while this reads the current state on
|
|
3014
|
+
* demand and can never be stale.
|
|
3015
|
+
*
|
|
3016
|
+
* The write controller is database-wide (shared across every column family),
|
|
3017
|
+
* so this reflects the database as a whole, not a single column family — a
|
|
3018
|
+
* stall triggered by any column family stops writes for all of them. Reads
|
|
3019
|
+
* `rocksdb.is-write-stopped` and `rocksdb.actual-delayed-write-rate`.
|
|
3020
|
+
*
|
|
3021
|
+
* @example
|
|
3022
|
+
* ```typescript
|
|
3023
|
+
* db.on('writeStall', (cf) => {
|
|
3024
|
+
* if (db.isWriteStalled()) log.warn(`writes throttled/blocked (triggered by ${cf})`);
|
|
3025
|
+
* });
|
|
3026
|
+
* ```
|
|
3027
|
+
*/
|
|
3028
|
+
isWriteStalled(): boolean;
|
|
2796
3029
|
/**
|
|
2797
3030
|
* Retrieves the estimated number of keys in the database. This is an alias
|
|
2798
3031
|
* for `db.estimateCount().count`; use `estimateCount()` for range support
|
|
@@ -2961,13 +3194,22 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2961
3194
|
*/
|
|
2962
3195
|
listLogs(): string[];
|
|
2963
3196
|
/**
|
|
2964
|
-
* The name of the database.
|
|
3197
|
+
* The name of the database's column family.
|
|
2965
3198
|
*/
|
|
2966
3199
|
get name(): string;
|
|
2967
3200
|
/**
|
|
2968
|
-
* Whether the database is open in readonly mode.
|
|
3201
|
+
* Whether the database is open in readonly mode. Also `true` for a
|
|
3202
|
+
* secondary instance (see {@link secondaryPath}), which is read-only by
|
|
3203
|
+
* construction.
|
|
2969
3204
|
*/
|
|
2970
3205
|
get readOnly(): boolean;
|
|
3206
|
+
/**
|
|
3207
|
+
* The secondary instance's workspace directory when the database was opened
|
|
3208
|
+
* as a secondary (a read-only follower of a live primary — see the
|
|
3209
|
+
* `secondaryPath` open option), or `undefined` for a regular or plain
|
|
3210
|
+
* read-only open.
|
|
3211
|
+
*/
|
|
3212
|
+
get secondaryPath(): string | undefined;
|
|
2971
3213
|
/**
|
|
2972
3214
|
* Sugar method for opening a database.
|
|
2973
3215
|
*
|
|
@@ -3085,6 +3327,47 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
3085
3327
|
* ```
|
|
3086
3328
|
*/
|
|
3087
3329
|
unlock(key: Key): void;
|
|
3330
|
+
/**
|
|
3331
|
+
* Returns a `RocksDatabase` bound to the `name` column family of this same
|
|
3332
|
+
* database, opening (and creating, if missing) the column family on first
|
|
3333
|
+
* use. This is a factory — create-and-open sugar — not a stateful switch: the
|
|
3334
|
+
* returned view is an independent instance whose own reads/writes target its
|
|
3335
|
+
* column family, while sharing the underlying database (so a transaction,
|
|
3336
|
+
* backup, or checkpoint still spans every column family). Because the view
|
|
3337
|
+
* opens its own handle, this database need not itself be open — a discarded
|
|
3338
|
+
* parent (`new RocksDatabase(path).use('events')`) still yields a valid,
|
|
3339
|
+
* opened view.
|
|
3340
|
+
*
|
|
3341
|
+
* Get-or-create, backed by a weak cache: `db.use('events') === db.use('events')`
|
|
3342
|
+
* while the view is still referenced **and open**, and calling with this
|
|
3343
|
+
* database's own column-family name returns `this`. A view that has been
|
|
3344
|
+
* closed (or garbage-collected — the cache does not pin it) is transparently
|
|
3345
|
+
* recreated on the next `use()`. Views are independent handles: closing this
|
|
3346
|
+
* database does not close them, and vice versa — the underlying database
|
|
3347
|
+
* stays open until every handle is closed or collected.
|
|
3348
|
+
*
|
|
3349
|
+
* The view's store is derived by {@link Store#createColumnFamilyStore}, which
|
|
3350
|
+
* builds an independent store of the same class with its own codec state (so
|
|
3351
|
+
* views never share a mutable encoder/decoder) and inherits the options this
|
|
3352
|
+
* store was constructed with; pass `options` to override them for this column
|
|
3353
|
+
* family. A database configured with a pre-constructed encoder/decoder
|
|
3354
|
+
* instance cannot derive views (its state would be shared) — use an encoder
|
|
3355
|
+
* factory (`{ Encoder }`) or a named `encoding`, or override
|
|
3356
|
+
* `createColumnFamilyStore` on a custom `Store`.
|
|
3357
|
+
*
|
|
3358
|
+
* @param name - The column family name.
|
|
3359
|
+
* @param options - Options for the column family, overriding inherited ones.
|
|
3360
|
+
* @returns A `RocksDatabase` bound to the column family.
|
|
3361
|
+
*
|
|
3362
|
+
* @example
|
|
3363
|
+
* ```typescript
|
|
3364
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
3365
|
+
* const events = db.use('events');
|
|
3366
|
+
* await events.put('e1', payload);
|
|
3367
|
+
* await db.put('k', 'v'); // default column family, unaffected
|
|
3368
|
+
* ```
|
|
3369
|
+
*/
|
|
3370
|
+
use(name: string, options?: RocksDatabaseOptions): RocksDatabase;
|
|
3088
3371
|
/**
|
|
3089
3372
|
* Excecutes a function using a thread-safe lock to ensure mutual
|
|
3090
3373
|
* exclusion.
|
|
@@ -3124,7 +3407,7 @@ interface TransactionLog$1 {
|
|
|
3124
3407
|
* @param path - The path to the transaction log file.
|
|
3125
3408
|
* @returns The transaction log.
|
|
3126
3409
|
*/
|
|
3127
|
-
declare function parseTransactionLog(path: string, options?: {
|
|
3410
|
+
export declare function parseTransactionLog(path: string, options?: {
|
|
3128
3411
|
skipData?: boolean;
|
|
3129
3412
|
}): TransactionLog$1;
|
|
3130
3413
|
//#endregion
|
|
@@ -3138,7 +3421,7 @@ declare function parseTransactionLog(path: string, options?: {
|
|
|
3138
3421
|
* The iterator is left positioned at `resyncPosition` (or at end-of-log when there is none), so a
|
|
3139
3422
|
* caller that chooses to recover the entries past the break calls `next()` again.
|
|
3140
3423
|
*/
|
|
3141
|
-
declare class CorruptFrameError extends RangeError {
|
|
3424
|
+
export declare class CorruptFrameError extends RangeError {
|
|
3142
3425
|
/** Sequence number of the log file the break is in. */
|
|
3143
3426
|
logId: number;
|
|
3144
3427
|
/** Offset of the broken frame. */
|
|
@@ -3151,10 +3434,10 @@ declare class CorruptFrameError extends RangeError {
|
|
|
3151
3434
|
}
|
|
3152
3435
|
//#endregion
|
|
3153
3436
|
//#region src/index.d.ts
|
|
3154
|
-
declare const versions: {
|
|
3437
|
+
export declare const versions: {
|
|
3155
3438
|
rocksdb: string;
|
|
3156
3439
|
"rocksdb-js": string;
|
|
3157
3440
|
};
|
|
3158
3441
|
//#endregion
|
|
3159
|
-
export {
|
|
3442
|
+
export type { BackgroundErrorOptions, BackupInfo, BackupOptions, BackupStreamOptions, CompressionAlgorithm, CompressionInfo, CompressionOption, CountEstimate, CountEstimateOptions, CountEstimatorOptions, FlushOptions, GetStatsMethod, IteratorOptions, Key, LogOptions, RestoreMode, RestoreOptions, RocksDBStat, RocksDBStats, RocksDatabaseOptions, StatsAll, StatsAllExtras, StatsBasics, StatsCurated, StatsCuratedExtras, StatsDefault, StatsHistogramData, StatsValue, StoreContext, StoreGetOptions, StoreIteratorOptions, StorePutOptions, StoreRangeOptions, StoreRemoveOptions, TransactionEntry, TransactionLogFileValidation, TransactionLogPosition, TransactionLogStats, TransactionLogStoreValidation, ValidateTransactionLogStoreOptions, WriteBufferManagerStats };
|
|
3160
3443
|
//# sourceMappingURL=index.d.cts.map
|