@harperfast/rocksdb-js 2.8.0 → 2.9.1
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 +357 -27
- package/dist/index.cjs +290 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +327 -38
- package/dist/index.d.mts +327 -38
- package/dist/index.mjs +289 -41
- 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.mts
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.
|
|
@@ -504,10 +551,16 @@ declare class Store {
|
|
|
504
551
|
/**
|
|
505
552
|
* The bytes of recent memtable history to retain in memory for transaction
|
|
506
553
|
* conflict checking. `-1` derives the value from
|
|
507
|
-
* `maxWriteBufferNumber * writeBufferSize`, except
|
|
508
|
-
* `writeBufferManager
|
|
509
|
-
* that manager and is only trimmable down to this target, so a
|
|
510
|
-
* budget cannot hold
|
|
554
|
+
* `maxWriteBufferNumber * writeBufferSize`, except when a
|
|
555
|
+
* `writeBufferManager` is configured, where it derives `1`: retained history
|
|
556
|
+
* is charged to that manager and is only trimmable down to this target, so a
|
|
557
|
+
* target the budget cannot hold is memory the manager never reclaims, and
|
|
558
|
+
* stalls writes permanently when `writeBufferManagerAllowStall` is on. Any
|
|
559
|
+
* configured manager, not only a stalling one — that flag is mutable at
|
|
560
|
+
* runtime while this value is fixed when the family is created. `1`, not `0`, because
|
|
561
|
+
* RocksDB's transaction wrappers rewrite a `0` target to the derived value —
|
|
562
|
+
* so `0` asks for the largest history rather than none, and an explicit `0`
|
|
563
|
+
* is normalized to `1` for that reason. Set a positive number to size it
|
|
511
564
|
* yourself against the budget and the column-family count.
|
|
512
565
|
*/
|
|
513
566
|
maxWriteBufferSizeToMaintain?: number;
|
|
@@ -544,6 +597,11 @@ declare class Store {
|
|
|
544
597
|
* The path to the database.
|
|
545
598
|
*/
|
|
546
599
|
path: string;
|
|
600
|
+
/**
|
|
601
|
+
* The open database's resolved filesystem identity, read once from
|
|
602
|
+
* `NativeDatabase.identityPath`. `undefined` until opened.
|
|
603
|
+
*/
|
|
604
|
+
identityPath?: string;
|
|
547
605
|
/**
|
|
548
606
|
* Whether to use pessimistic locking for transactions. When `true`,
|
|
549
607
|
* transactions will fail as soon as a conflict is detected. When `false`,
|
|
@@ -557,6 +615,13 @@ declare class Store {
|
|
|
557
615
|
* no-ops.
|
|
558
616
|
*/
|
|
559
617
|
readOnly: boolean;
|
|
618
|
+
/**
|
|
619
|
+
* The secondary instance's workspace directory when the database is opened
|
|
620
|
+
* as a secondary (see `RocksDatabaseOptions.secondaryPath`); `undefined`
|
|
621
|
+
* otherwise. A secondary is read-only, so `readOnly` is `true` whenever
|
|
622
|
+
* this is set.
|
|
623
|
+
*/
|
|
624
|
+
secondaryPath?: string;
|
|
560
625
|
/**
|
|
561
626
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
562
627
|
* access structure.
|
|
@@ -616,6 +681,24 @@ declare class Store {
|
|
|
616
681
|
* @param options - The options for the store.
|
|
617
682
|
*/
|
|
618
683
|
constructor(path: string, options?: StoreOptions);
|
|
684
|
+
/**
|
|
685
|
+
* Creates an independent `Store` for another column family of the same
|
|
686
|
+
* database, used by {@link RocksDatabase#use}. The returned store shares the
|
|
687
|
+
* underlying database but must have its own codec state: a mutable
|
|
688
|
+
* encoder/decoder instance cannot be shared across column families (opening a
|
|
689
|
+
* view mutates the encoder's `name`, and clearing a view resets its
|
|
690
|
+
* `structures`), so a pre-constructed instance is rejected here — supply an
|
|
691
|
+
* encoder factory (`{ Encoder }`) or a named `encoding` instead.
|
|
692
|
+
*
|
|
693
|
+
* Override this in a `Store` subclass whose constructor cannot be recreated
|
|
694
|
+
* from `(path, options)` (e.g. it takes injected dependencies) or that needs
|
|
695
|
+
* to control how a view's codec state is built.
|
|
696
|
+
*
|
|
697
|
+
* @param name - The column family name for the derived store.
|
|
698
|
+
* @param options - Options overriding this store's, for the derived store.
|
|
699
|
+
* @returns A new, independent `Store` bound to `name`.
|
|
700
|
+
*/
|
|
701
|
+
createColumnFamilyStore(name: string, options?: StoreOptions): Store;
|
|
619
702
|
/**
|
|
620
703
|
* Closes the database.
|
|
621
704
|
*/
|
|
@@ -835,7 +918,7 @@ declare const RETRY_NOW: number;
|
|
|
835
918
|
/**
|
|
836
919
|
* Provides transaction level operations to a transaction callback.
|
|
837
920
|
*/
|
|
838
|
-
declare class Transaction extends DBI {
|
|
921
|
+
export declare class Transaction extends DBI {
|
|
839
922
|
#private;
|
|
840
923
|
/**
|
|
841
924
|
* Create a new transaction.
|
|
@@ -869,10 +952,12 @@ declare class Transaction extends DBI {
|
|
|
869
952
|
*/
|
|
870
953
|
commitSync(): void;
|
|
871
954
|
/**
|
|
872
|
-
* Returns the transaction
|
|
873
|
-
* the transaction
|
|
955
|
+
* Returns the transaction timestamp in milliseconds since the Unix epoch. It
|
|
956
|
+
* defaults to a process-wide monotonic value assigned when the transaction
|
|
957
|
+
* was created. A producer may use this value as its write identity; the
|
|
958
|
+
* transaction log uses it as the batch key.
|
|
874
959
|
*
|
|
875
|
-
* @returns The transaction
|
|
960
|
+
* @returns The transaction timestamp in milliseconds.
|
|
876
961
|
*/
|
|
877
962
|
getTimestamp(): number;
|
|
878
963
|
/**
|
|
@@ -880,9 +965,14 @@ declare class Transaction extends DBI {
|
|
|
880
965
|
*/
|
|
881
966
|
get id(): number;
|
|
882
967
|
/**
|
|
883
|
-
*
|
|
968
|
+
* Overrides the transaction timestamp in milliseconds since the Unix epoch.
|
|
969
|
+
* Call this before reading the timestamp or staging writes when adopting an
|
|
970
|
+
* origin timestamp for replication or replay. Once a write or log entry is
|
|
971
|
+
* staged, the timestamp is frozen, but reapplying the same timestamp remains
|
|
972
|
+
* idempotent while the transaction is pending. The value must be finite,
|
|
973
|
+
* positive, and below 8640000000000000.
|
|
884
974
|
*
|
|
885
|
-
* @param timestamp - The timestamp to set in
|
|
975
|
+
* @param timestamp - The timestamp to set in milliseconds.
|
|
886
976
|
*/
|
|
887
977
|
setTimestamp(timestamp?: number): void;
|
|
888
978
|
}
|
|
@@ -1024,7 +1114,7 @@ interface DBITransactional {
|
|
|
1024
1114
|
*
|
|
1025
1115
|
* This class is not meant to be used directly.
|
|
1026
1116
|
*/
|
|
1027
|
-
declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
1117
|
+
export declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
1028
1118
|
/**
|
|
1029
1119
|
* The RocksDB context for `get()`, `put()`, and `remove()`.
|
|
1030
1120
|
*/
|
|
@@ -1230,7 +1320,13 @@ declare class DBI<T extends DBITransactional | unknown = unknown> {
|
|
|
1230
1320
|
}
|
|
1231
1321
|
//#endregion
|
|
1232
1322
|
//#region src/stats.d.ts
|
|
1233
|
-
/**
|
|
1323
|
+
/**
|
|
1324
|
+
* Database-level RocksDB statistics types for `db.getStats()` / `db.getStat()`.
|
|
1325
|
+
*
|
|
1326
|
+
* The `writeBufferManager.*` keys are the exception to "database-level": the
|
|
1327
|
+
* WriteBufferManager is a process-wide singleton, so those values describe every
|
|
1328
|
+
* database in the process. See `getWriteBufferManagerStats()`.
|
|
1329
|
+
*/
|
|
1234
1330
|
type StatsHistogramData = {
|
|
1235
1331
|
average: number;
|
|
1236
1332
|
count: number;
|
|
@@ -1282,6 +1378,11 @@ type StatsBasics = {
|
|
|
1282
1378
|
"txnlog.replayGapBytes": number;
|
|
1283
1379
|
"commitPipeline.logQueueDepth": number;
|
|
1284
1380
|
"commitPipeline.commitQueueDepth": number;
|
|
1381
|
+
"writeBufferManager.bufferSize": number;
|
|
1382
|
+
"writeBufferManager.memoryUsage": number;
|
|
1383
|
+
"writeBufferManager.mutableMemoryUsage": number;
|
|
1384
|
+
"writeBufferManager.stallActive": number;
|
|
1385
|
+
"writeBufferManager.stallActiveMs": number;
|
|
1285
1386
|
};
|
|
1286
1387
|
type StatsCuratedExtras = {
|
|
1287
1388
|
"rocksdb.block.cache.hit": number;
|
|
@@ -1746,7 +1847,7 @@ interface ValidateTransactionLogStoreOptions {
|
|
|
1746
1847
|
* }
|
|
1747
1848
|
* ```
|
|
1748
1849
|
*/
|
|
1749
|
-
declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
|
|
1850
|
+
export declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
|
|
1750
1851
|
//#endregion
|
|
1751
1852
|
//#region src/load-binding.d.ts
|
|
1752
1853
|
/**
|
|
@@ -1769,7 +1870,7 @@ declare function validateTransactionLogStore(path: string, options?: ValidateTra
|
|
|
1769
1870
|
* });
|
|
1770
1871
|
* ```
|
|
1771
1872
|
*/
|
|
1772
|
-
interface BackgroundError extends Error {
|
|
1873
|
+
export interface BackgroundError extends Error {
|
|
1773
1874
|
/** Always `'BackgroundError'`. */
|
|
1774
1875
|
name: string;
|
|
1775
1876
|
/** Discriminator for the error class; always `'background'` here. */
|
|
@@ -1925,7 +2026,7 @@ type TransactionLogStats = {
|
|
|
1925
2026
|
maxAgeThreshold: number;
|
|
1926
2027
|
};
|
|
1927
2028
|
};
|
|
1928
|
-
type TransactionLog = {
|
|
2029
|
+
export type TransactionLog = {
|
|
1929
2030
|
new (db: NativeDatabase, name: string): TransactionLog;
|
|
1930
2031
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
1931
2032
|
getLogFileSize(sequenceId?: number): number;
|
|
@@ -1966,7 +2067,7 @@ type NativeIteratorResult = number | {
|
|
|
1966
2067
|
value?: Buffer;
|
|
1967
2068
|
};
|
|
1968
2069
|
declare class NativeIteratorCls {
|
|
1969
|
-
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
2070
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions, transactionId?: number);
|
|
1970
2071
|
next(): NativeIteratorResult;
|
|
1971
2072
|
return(): void;
|
|
1972
2073
|
throw(err?: unknown): void;
|
|
@@ -2017,6 +2118,15 @@ type NativeDatabaseOptions = {
|
|
|
2017
2118
|
noBlockCache?: boolean;
|
|
2018
2119
|
parallelismThreads?: number;
|
|
2019
2120
|
readOnly?: boolean;
|
|
2121
|
+
/**
|
|
2122
|
+
* A present, non-empty string opens the database via `DB::OpenAsSecondary`:
|
|
2123
|
+
* a read-only follower of a live primary that advances with
|
|
2124
|
+
* `catchUpWithPrimary()`. The value is the secondary instance's own
|
|
2125
|
+
* workspace directory (created if missing), distinct from `path` (the
|
|
2126
|
+
* primary's data directory) and exclusive to one secondary instance.
|
|
2127
|
+
* Implies `readOnly: true` and forces `maxOpenFiles: -1`.
|
|
2128
|
+
*/
|
|
2129
|
+
secondaryPath?: string;
|
|
2020
2130
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
2021
2131
|
transactionLogMaxAgeThreshold?: number;
|
|
2022
2132
|
transactionLogMaxSize?: number;
|
|
@@ -2101,6 +2211,8 @@ type NativeDatabase = {
|
|
|
2101
2211
|
flushBeforeBackup?: boolean;
|
|
2102
2212
|
transactionLogs?: boolean;
|
|
2103
2213
|
}): void;
|
|
2214
|
+
catchUpWithPrimary(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
2215
|
+
catchUpWithPrimarySync(): void;
|
|
2104
2216
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
2105
2217
|
clearSync(): void;
|
|
2106
2218
|
close(): void;
|
|
@@ -2140,6 +2252,7 @@ type NativeDatabase = {
|
|
|
2140
2252
|
getSync(keyLengthOrKeyBuffer: number | Buffer, flags: number, txnId?: number, expectedVersion?: number): Buffer;
|
|
2141
2253
|
getUserSharedBuffer(key: BufferWithDataView, defaultBuffer: ArrayBuffer, callback?: UserSharedBufferCallback): ArrayBuffer;
|
|
2142
2254
|
hasLock(key: BufferWithDataView): boolean;
|
|
2255
|
+
identityPath: string | undefined;
|
|
2143
2256
|
listeners(event: string | BufferWithDataView): number;
|
|
2144
2257
|
listLogs(): string[];
|
|
2145
2258
|
opened: boolean;
|
|
@@ -2243,10 +2356,84 @@ type RegistryStatus = RegistryStatusDB[];
|
|
|
2243
2356
|
* `new BackgroundError()` (which would omit `severity` / `writesDisabled` / …)
|
|
2244
2357
|
* is a type error.
|
|
2245
2358
|
*/
|
|
2246
|
-
declare const BackgroundError: new (details: Pick<BackgroundError, "message" | "severity" | "severityName" | "writesDisabled" | "reason" | "reasonName"> & {
|
|
2359
|
+
export declare const BackgroundError: new (details: Pick<BackgroundError, "message" | "severity" | "severityName" | "writesDisabled" | "reason" | "reasonName"> & {
|
|
2247
2360
|
type?: string;
|
|
2248
2361
|
}) => BackgroundError;
|
|
2249
|
-
|
|
2362
|
+
/**
|
|
2363
|
+
* Live state of the process-wide `WriteBufferManager` singleton — see
|
|
2364
|
+
* {@link getWriteBufferManagerStats}.
|
|
2365
|
+
*/
|
|
2366
|
+
type WriteBufferManagerStats = {
|
|
2367
|
+
/**
|
|
2368
|
+
* Whether a manager has been created in this process. `bufferSize`,
|
|
2369
|
+
* `memoryUsage`, `mutableMemoryUsage`, `stallActive`, `stallActiveMs`,
|
|
2370
|
+
* `watchdogRunning` and `columnFamilies` are 0/false when not; `allowStall`
|
|
2371
|
+
* and `costToCache` still reflect the configured setting, and
|
|
2372
|
+
* `inventoryAvailable` is `true`.
|
|
2373
|
+
*/
|
|
2374
|
+
enabled: boolean;
|
|
2375
|
+
/** The manager's budget in bytes (`writeBufferManagerSize`, live). */
|
|
2376
|
+
bufferSize: number;
|
|
2377
|
+
/** Total memtable memory charged to the manager, in bytes. */
|
|
2378
|
+
memoryUsage: number;
|
|
2379
|
+
/** The share of `memoryUsage` held by active (mutable) memtables, in bytes. */
|
|
2380
|
+
mutableMemoryUsage: number;
|
|
2381
|
+
allowStall: boolean;
|
|
2382
|
+
costToCache: boolean;
|
|
2383
|
+
stallActive: boolean;
|
|
2384
|
+
/**
|
|
2385
|
+
* How long the current stall has been active, in milliseconds; 0 when not
|
|
2386
|
+
* stalled. Sampled once a second by the stall watchdog, so it is 0 for the
|
|
2387
|
+
* first second of a stall and whenever `watchdogRunning` is false.
|
|
2388
|
+
*/
|
|
2389
|
+
stallActiveMs: number;
|
|
2390
|
+
/**
|
|
2391
|
+
* Whether the stall watchdog is running. It runs only while a manager exists
|
|
2392
|
+
* with `writeBufferManagerAllowStall`, and only when
|
|
2393
|
+
* `ROCKSDB_JS_WBM_STALL_WARN_MS` is not `0`.
|
|
2394
|
+
*/
|
|
2395
|
+
watchdogRunning: boolean;
|
|
2396
|
+
/**
|
|
2397
|
+
* Live column families across every database attached to this manager. A
|
|
2398
|
+
* dropped column family keeps charging the manager until its last handle
|
|
2399
|
+
* closes, so it is counted until then.
|
|
2400
|
+
*/
|
|
2401
|
+
columnFamilies: number;
|
|
2402
|
+
/**
|
|
2403
|
+
* `false` when the column-family inventory could not be collected because the
|
|
2404
|
+
* database registry was locked — most plausibly by a close that is itself
|
|
2405
|
+
* waiting out this stall. `columnFamilies` is then `0` and
|
|
2406
|
+
* `maxWriteBufferSizeToMaintain` empty; every other field is still live.
|
|
2407
|
+
*/
|
|
2408
|
+
inventoryAvailable: boolean;
|
|
2409
|
+
/**
|
|
2410
|
+
* Effective per-column-family `max_write_buffer_size_to_maintain` (as a decimal
|
|
2411
|
+
* string) to the number of those column families holding it. Effective, not
|
|
2412
|
+
* requested: RocksDB rewrites a requested `0` for a transaction database.
|
|
2413
|
+
*/
|
|
2414
|
+
maxWriteBufferSizeToMaintain: Record<string, number>;
|
|
2415
|
+
};
|
|
2416
|
+
/**
|
|
2417
|
+
* Reads the live state of the process-wide `WriteBufferManager`: its budget,
|
|
2418
|
+
* charged memory, mutable share, stall state, and attached column-family
|
|
2419
|
+
* inventory. The manager is shared by every database and worker thread in the
|
|
2420
|
+
* process.
|
|
2421
|
+
*
|
|
2422
|
+
* A WriteBufferManager stall does not pass through RocksDB's `WriteController`,
|
|
2423
|
+
* so it is not reflected by `rocksdb.stall.micros`, `db.isWriteStalled()`, or
|
|
2424
|
+
* the `'writeStall'` event. Use `stallActive` to distinguish this condition from
|
|
2425
|
+
* an idle database.
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
* ```typescript
|
|
2429
|
+
* const wbm = getWriteBufferManagerStats();
|
|
2430
|
+
* if (wbm.stallActive) {
|
|
2431
|
+
* log.warn(`writes stalled for ${wbm.stallActiveMs}ms`);
|
|
2432
|
+
* }
|
|
2433
|
+
* ```
|
|
2434
|
+
*/
|
|
2435
|
+
export declare const getWriteBufferManagerStats: () => WriteBufferManagerStats;
|
|
2436
|
+
export declare const constants: {
|
|
2250
2437
|
ALWAYS_CREATE_NEW_BUFFER_FLAG: number;
|
|
2251
2438
|
NOT_IN_MEMORY_CACHE_FLAG: number;
|
|
2252
2439
|
ONLY_IF_IN_MEMORY_CACHE_FLAG: number;
|
|
@@ -2282,6 +2469,7 @@ declare const constants: {
|
|
|
2282
2469
|
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
2283
2470
|
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
2284
2471
|
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
2472
|
+
ITERATOR_HAS_TRANSACTION_ID_FLAG: number;
|
|
2285
2473
|
ITERATOR_RESULT_DONE: number;
|
|
2286
2474
|
ITERATOR_RESULT_FAST: number;
|
|
2287
2475
|
};
|
|
@@ -2293,13 +2481,13 @@ declare const constants: {
|
|
|
2293
2481
|
* always present. Use it to validate a `compression` option or to pick an
|
|
2294
2482
|
* algorithm that is actually available at runtime.
|
|
2295
2483
|
*/
|
|
2296
|
-
declare const supportedCompression: readonly string[];
|
|
2484
|
+
export declare const supportedCompression: readonly string[];
|
|
2297
2485
|
declare const NativeDatabase: NativeDatabase;
|
|
2298
2486
|
declare const NativeTransaction: NativeTransaction;
|
|
2299
|
-
declare const TransactionLog: TransactionLog;
|
|
2300
|
-
declare const registryStatus: () => RegistryStatus;
|
|
2301
|
-
declare const shutdown: () => void;
|
|
2302
|
-
declare const currentThreadId: () => number;
|
|
2487
|
+
export declare const TransactionLog: TransactionLog;
|
|
2488
|
+
export declare const registryStatus: () => RegistryStatus;
|
|
2489
|
+
export declare const shutdown: () => void;
|
|
2490
|
+
export declare const currentThreadId: () => number;
|
|
2303
2491
|
/**
|
|
2304
2492
|
* Advises the kernel that the file-backed pages of every mapped transaction log
|
|
2305
2493
|
* are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
|
|
@@ -2313,7 +2501,7 @@ declare const currentThreadId: () => number;
|
|
|
2313
2501
|
*
|
|
2314
2502
|
* @returns the number of maps cooled and total file-backed bytes advised.
|
|
2315
2503
|
*/
|
|
2316
|
-
declare const coolTransactionLogs: () => {
|
|
2504
|
+
export declare const coolTransactionLogs: () => {
|
|
2317
2505
|
maps: number;
|
|
2318
2506
|
bytes: number;
|
|
2319
2507
|
};
|
|
@@ -2328,13 +2516,13 @@ declare const coolTransactionLogs: () => {
|
|
|
2328
2516
|
* OS handle is owned entirely in native code (no fd crosses into JS), and the
|
|
2329
2517
|
* kernel releases the lock when the handle closes, including on process death.
|
|
2330
2518
|
*/
|
|
2331
|
-
declare const tryFileLock: (file: string, shared?: boolean) => number;
|
|
2519
|
+
export declare const tryFileLock: (file: string, shared?: boolean) => number;
|
|
2332
2520
|
/**
|
|
2333
2521
|
* Releases a file lock acquired via `tryFileLock`. A no-op for
|
|
2334
2522
|
* token `0` or an unknown token.
|
|
2335
2523
|
*/
|
|
2336
|
-
declare const fileLockRelease: (token: number) => void;
|
|
2337
|
-
declare const stats: {
|
|
2524
|
+
export declare const fileLockRelease: (token: number) => void;
|
|
2525
|
+
export declare const stats: {
|
|
2338
2526
|
StatsLevel: {
|
|
2339
2527
|
DisableAll: number;
|
|
2340
2528
|
ExceptTickers: number;
|
|
@@ -2400,7 +2588,7 @@ interface CountEstimatorOptions extends CountEstimateOptions {}
|
|
|
2400
2588
|
* results are memoized per checkpoint, so repeated reads between `advance()`
|
|
2401
2589
|
* calls are free.
|
|
2402
2590
|
*/
|
|
2403
|
-
declare class CountEstimator {
|
|
2591
|
+
export declare class CountEstimator {
|
|
2404
2592
|
#private;
|
|
2405
2593
|
constructor(store: Store, options?: CountEstimatorOptions);
|
|
2406
2594
|
/**
|
|
@@ -2467,7 +2655,7 @@ type RocksDBStats = StatsDefault | StatsAll;
|
|
|
2467
2655
|
* db.close();
|
|
2468
2656
|
* ```
|
|
2469
2657
|
*/
|
|
2470
|
-
declare class RocksDatabase extends DBI<DBITransactional> {
|
|
2658
|
+
export declare class RocksDatabase extends DBI<DBITransactional> {
|
|
2471
2659
|
#private;
|
|
2472
2660
|
constructor(pathOrStore: string | Store, options?: RocksDatabaseOptions);
|
|
2473
2661
|
/**
|
|
@@ -2674,6 +2862,36 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2674
2862
|
* @returns `true` if there was at least one listener.
|
|
2675
2863
|
*/
|
|
2676
2864
|
static notify(event: string, ...args: any[]): boolean;
|
|
2865
|
+
/**
|
|
2866
|
+
* Advances a secondary instance to the primary's current state by tailing
|
|
2867
|
+
* and replaying the primary's MANIFEST and WAL. A secondary does not see
|
|
2868
|
+
* the primary's writes until this (or {@link catchUpWithPrimarySync}) is
|
|
2869
|
+
* called. Concurrent reads through this handle remain safe while the
|
|
2870
|
+
* catch-up runs.
|
|
2871
|
+
*
|
|
2872
|
+
* Only valid on a database opened with the `secondaryPath` option; throws
|
|
2873
|
+
* with code `ERR_NOT_SECONDARY` otherwise.
|
|
2874
|
+
*
|
|
2875
|
+
* Advances the **database** view only. Against a cross-process primary,
|
|
2876
|
+
* transaction-log reads keep serving the stores discovered at open (a store
|
|
2877
|
+
* the primary creates later, and its appends, need a reopen); a primary in
|
|
2878
|
+
* the same process shares the store registry, so its stores and appends are
|
|
2879
|
+
* visible immediately. Either way a log entry can describe data this
|
|
2880
|
+
* handle's database view does not have yet — the log write completes before
|
|
2881
|
+
* the RocksDB commit for every writer, so consumers must tolerate the log
|
|
2882
|
+
* leading the database.
|
|
2883
|
+
*
|
|
2884
|
+
* Await one call before starting the next: the replay holds a libuv worker
|
|
2885
|
+
* for its whole duration and concurrent calls queue on a per-database mutex
|
|
2886
|
+
* while holding theirs, so overlapping catch-ups on a backlogged follower
|
|
2887
|
+
* can exhaust the default four-thread pool and stall unrelated I/O.
|
|
2888
|
+
*/
|
|
2889
|
+
catchUpWithPrimary(): Promise<void>;
|
|
2890
|
+
/**
|
|
2891
|
+
* Synchronous version of {@link catchUpWithPrimary}. The replay runs on the
|
|
2892
|
+
* JS thread, so prefer the async form unless the caller is already blocking.
|
|
2893
|
+
*/
|
|
2894
|
+
catchUpWithPrimarySync(): void;
|
|
2677
2895
|
destroy(): void;
|
|
2678
2896
|
drop(): Promise<void>;
|
|
2679
2897
|
dropSync(): void;
|
|
@@ -2793,6 +3011,27 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2793
3011
|
* ```
|
|
2794
3012
|
*/
|
|
2795
3013
|
getDBProperty(propertyName: string): string | undefined;
|
|
3014
|
+
/**
|
|
3015
|
+
* Whether RocksDB is currently applying write backpressure to this database —
|
|
3016
|
+
* either delaying (rate-limiting) or fully stopping writes. This is the
|
|
3017
|
+
* authoritative, live pull counterpart to the `'writeStall'`
|
|
3018
|
+
* [event](../README.md#event-writestall): the event pushes per-column-family
|
|
3019
|
+
* transitions (and is rate-limited), while this reads the current state on
|
|
3020
|
+
* demand and can never be stale.
|
|
3021
|
+
*
|
|
3022
|
+
* The write controller is database-wide (shared across every column family),
|
|
3023
|
+
* so this reflects the database as a whole, not a single column family — a
|
|
3024
|
+
* stall triggered by any column family stops writes for all of them. Reads
|
|
3025
|
+
* `rocksdb.is-write-stopped` and `rocksdb.actual-delayed-write-rate`.
|
|
3026
|
+
*
|
|
3027
|
+
* @example
|
|
3028
|
+
* ```typescript
|
|
3029
|
+
* db.on('writeStall', (cf) => {
|
|
3030
|
+
* if (db.isWriteStalled()) log.warn(`writes throttled/blocked (triggered by ${cf})`);
|
|
3031
|
+
* });
|
|
3032
|
+
* ```
|
|
3033
|
+
*/
|
|
3034
|
+
isWriteStalled(): boolean;
|
|
2796
3035
|
/**
|
|
2797
3036
|
* Retrieves the estimated number of keys in the database. This is an alias
|
|
2798
3037
|
* for `db.estimateCount().count`; use `estimateCount()` for range support
|
|
@@ -2961,13 +3200,22 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
2961
3200
|
*/
|
|
2962
3201
|
listLogs(): string[];
|
|
2963
3202
|
/**
|
|
2964
|
-
* The name of the database.
|
|
3203
|
+
* The name of the database's column family.
|
|
2965
3204
|
*/
|
|
2966
3205
|
get name(): string;
|
|
2967
3206
|
/**
|
|
2968
|
-
* Whether the database is open in readonly mode.
|
|
3207
|
+
* Whether the database is open in readonly mode. Also `true` for a
|
|
3208
|
+
* secondary instance (see {@link secondaryPath}), which is read-only by
|
|
3209
|
+
* construction.
|
|
2969
3210
|
*/
|
|
2970
3211
|
get readOnly(): boolean;
|
|
3212
|
+
/**
|
|
3213
|
+
* The secondary instance's workspace directory when the database was opened
|
|
3214
|
+
* as a secondary (a read-only follower of a live primary — see the
|
|
3215
|
+
* `secondaryPath` open option), or `undefined` for a regular or plain
|
|
3216
|
+
* read-only open.
|
|
3217
|
+
*/
|
|
3218
|
+
get secondaryPath(): string | undefined;
|
|
2971
3219
|
/**
|
|
2972
3220
|
* Sugar method for opening a database.
|
|
2973
3221
|
*
|
|
@@ -3085,6 +3333,47 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
3085
3333
|
* ```
|
|
3086
3334
|
*/
|
|
3087
3335
|
unlock(key: Key): void;
|
|
3336
|
+
/**
|
|
3337
|
+
* Returns a `RocksDatabase` bound to the `name` column family of this same
|
|
3338
|
+
* database, opening (and creating, if missing) the column family on first
|
|
3339
|
+
* use. This is a factory — create-and-open sugar — not a stateful switch: the
|
|
3340
|
+
* returned view is an independent instance whose own reads/writes target its
|
|
3341
|
+
* column family, while sharing the underlying database (so a transaction,
|
|
3342
|
+
* backup, or checkpoint still spans every column family). Because the view
|
|
3343
|
+
* opens its own handle, this database need not itself be open — a discarded
|
|
3344
|
+
* parent (`new RocksDatabase(path).use('events')`) still yields a valid,
|
|
3345
|
+
* opened view.
|
|
3346
|
+
*
|
|
3347
|
+
* Get-or-create, backed by a weak cache: `db.use('events') === db.use('events')`
|
|
3348
|
+
* while the view is still referenced **and open**, and calling with this
|
|
3349
|
+
* database's own column-family name returns `this`. A view that has been
|
|
3350
|
+
* closed (or garbage-collected — the cache does not pin it) is transparently
|
|
3351
|
+
* recreated on the next `use()`. Views are independent handles: closing this
|
|
3352
|
+
* database does not close them, and vice versa — the underlying database
|
|
3353
|
+
* stays open until every handle is closed or collected.
|
|
3354
|
+
*
|
|
3355
|
+
* The view's store is derived by {@link Store#createColumnFamilyStore}, which
|
|
3356
|
+
* builds an independent store of the same class with its own codec state (so
|
|
3357
|
+
* views never share a mutable encoder/decoder) and inherits the options this
|
|
3358
|
+
* store was constructed with; pass `options` to override them for this column
|
|
3359
|
+
* family. A database configured with a pre-constructed encoder/decoder
|
|
3360
|
+
* instance cannot derive views (its state would be shared) — use an encoder
|
|
3361
|
+
* factory (`{ Encoder }`) or a named `encoding`, or override
|
|
3362
|
+
* `createColumnFamilyStore` on a custom `Store`.
|
|
3363
|
+
*
|
|
3364
|
+
* @param name - The column family name.
|
|
3365
|
+
* @param options - Options for the column family, overriding inherited ones.
|
|
3366
|
+
* @returns A `RocksDatabase` bound to the column family.
|
|
3367
|
+
*
|
|
3368
|
+
* @example
|
|
3369
|
+
* ```typescript
|
|
3370
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
3371
|
+
* const events = db.use('events');
|
|
3372
|
+
* await events.put('e1', payload);
|
|
3373
|
+
* await db.put('k', 'v'); // default column family, unaffected
|
|
3374
|
+
* ```
|
|
3375
|
+
*/
|
|
3376
|
+
use(name: string, options?: RocksDatabaseOptions): RocksDatabase;
|
|
3088
3377
|
/**
|
|
3089
3378
|
* Excecutes a function using a thread-safe lock to ensure mutual
|
|
3090
3379
|
* exclusion.
|
|
@@ -3124,7 +3413,7 @@ interface TransactionLog$1 {
|
|
|
3124
3413
|
* @param path - The path to the transaction log file.
|
|
3125
3414
|
* @returns The transaction log.
|
|
3126
3415
|
*/
|
|
3127
|
-
declare function parseTransactionLog(path: string, options?: {
|
|
3416
|
+
export declare function parseTransactionLog(path: string, options?: {
|
|
3128
3417
|
skipData?: boolean;
|
|
3129
3418
|
}): TransactionLog$1;
|
|
3130
3419
|
//#endregion
|
|
@@ -3138,7 +3427,7 @@ declare function parseTransactionLog(path: string, options?: {
|
|
|
3138
3427
|
* The iterator is left positioned at `resyncPosition` (or at end-of-log when there is none), so a
|
|
3139
3428
|
* caller that chooses to recover the entries past the break calls `next()` again.
|
|
3140
3429
|
*/
|
|
3141
|
-
declare class CorruptFrameError extends RangeError {
|
|
3430
|
+
export declare class CorruptFrameError extends RangeError {
|
|
3142
3431
|
/** Sequence number of the log file the break is in. */
|
|
3143
3432
|
logId: number;
|
|
3144
3433
|
/** Offset of the broken frame. */
|
|
@@ -3151,10 +3440,10 @@ declare class CorruptFrameError extends RangeError {
|
|
|
3151
3440
|
}
|
|
3152
3441
|
//#endregion
|
|
3153
3442
|
//#region src/index.d.ts
|
|
3154
|
-
declare const versions: {
|
|
3443
|
+
export declare const versions: {
|
|
3155
3444
|
rocksdb: string;
|
|
3156
3445
|
"rocksdb-js": string;
|
|
3157
3446
|
};
|
|
3158
3447
|
//#endregion
|
|
3159
|
-
export {
|
|
3448
|
+
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
3449
|
//# sourceMappingURL=index.d.mts.map
|