@harperfast/rocksdb-js 1.2.0 → 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 +33 -0
- package/dist/index.cjs +37 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -2
- package/dist/index.d.mts +64 -2
- package/dist/index.mjs +37 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -19
package/dist/index.d.cts
CHANGED
|
@@ -172,6 +172,24 @@ declare class Store {
|
|
|
172
172
|
*/
|
|
173
173
|
maxKeySize: number;
|
|
174
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
|
+
/**
|
|
175
193
|
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
176
194
|
*/
|
|
177
195
|
name: string;
|
|
@@ -181,9 +199,10 @@ declare class Store {
|
|
|
181
199
|
noBlockCache?: boolean;
|
|
182
200
|
/**
|
|
183
201
|
* The number of threads to use for parallel operations. This is a RocksDB
|
|
184
|
-
* option.
|
|
202
|
+
* option. When undefined, the native layer picks
|
|
203
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
185
204
|
*/
|
|
186
|
-
parallelismThreads
|
|
205
|
+
parallelismThreads?: number;
|
|
187
206
|
/**
|
|
188
207
|
* The path to the database.
|
|
189
208
|
*/
|
|
@@ -239,6 +258,11 @@ declare class Store {
|
|
|
239
258
|
*/
|
|
240
259
|
transactionLogsPath?: string;
|
|
241
260
|
/**
|
|
261
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
262
|
+
* sealed and flushed.
|
|
263
|
+
*/
|
|
264
|
+
writeBufferSize?: number;
|
|
265
|
+
/**
|
|
242
266
|
* The function used to encode keys using the shared `keyBuffer`.
|
|
243
267
|
*/
|
|
244
268
|
writeKey: WriteKeyFunction;
|
|
@@ -492,8 +516,11 @@ declare class NativeIteratorCls {
|
|
|
492
516
|
}
|
|
493
517
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
494
518
|
type NativeDatabaseOptions = {
|
|
519
|
+
dbWriteBufferSize?: number;
|
|
495
520
|
disableWAL?: boolean;
|
|
496
521
|
enableStats?: boolean;
|
|
522
|
+
maxWriteBufferNumber?: number;
|
|
523
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
497
524
|
mode?: NativeDatabaseMode;
|
|
498
525
|
name?: string;
|
|
499
526
|
noBlockCache?: boolean;
|
|
@@ -504,6 +531,7 @@ type NativeDatabaseOptions = {
|
|
|
504
531
|
transactionLogMaxSize?: number;
|
|
505
532
|
transactionLogRetentionMs?: number;
|
|
506
533
|
transactionLogsPath?: string;
|
|
534
|
+
writeBufferSize?: number;
|
|
507
535
|
};
|
|
508
536
|
type ResolveCallback<T> = (value: T) => void;
|
|
509
537
|
type RejectCallback = (err: Error) => void;
|
|
@@ -569,6 +597,40 @@ type NativeDatabase = {
|
|
|
569
597
|
type RocksDatabaseConfig = {
|
|
570
598
|
blockCacheSize?: number;
|
|
571
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;
|
|
572
634
|
};
|
|
573
635
|
type RegistryStatusDB = {
|
|
574
636
|
path: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -172,6 +172,24 @@ declare class Store {
|
|
|
172
172
|
*/
|
|
173
173
|
maxKeySize: number;
|
|
174
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
|
+
/**
|
|
175
193
|
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
176
194
|
*/
|
|
177
195
|
name: string;
|
|
@@ -181,9 +199,10 @@ declare class Store {
|
|
|
181
199
|
noBlockCache?: boolean;
|
|
182
200
|
/**
|
|
183
201
|
* The number of threads to use for parallel operations. This is a RocksDB
|
|
184
|
-
* option.
|
|
202
|
+
* option. When undefined, the native layer picks
|
|
203
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
185
204
|
*/
|
|
186
|
-
parallelismThreads
|
|
205
|
+
parallelismThreads?: number;
|
|
187
206
|
/**
|
|
188
207
|
* The path to the database.
|
|
189
208
|
*/
|
|
@@ -239,6 +258,11 @@ declare class Store {
|
|
|
239
258
|
*/
|
|
240
259
|
transactionLogsPath?: string;
|
|
241
260
|
/**
|
|
261
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
262
|
+
* sealed and flushed.
|
|
263
|
+
*/
|
|
264
|
+
writeBufferSize?: number;
|
|
265
|
+
/**
|
|
242
266
|
* The function used to encode keys using the shared `keyBuffer`.
|
|
243
267
|
*/
|
|
244
268
|
writeKey: WriteKeyFunction;
|
|
@@ -492,8 +516,11 @@ declare class NativeIteratorCls {
|
|
|
492
516
|
}
|
|
493
517
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
494
518
|
type NativeDatabaseOptions = {
|
|
519
|
+
dbWriteBufferSize?: number;
|
|
495
520
|
disableWAL?: boolean;
|
|
496
521
|
enableStats?: boolean;
|
|
522
|
+
maxWriteBufferNumber?: number;
|
|
523
|
+
maxWriteBufferSizeToMaintain?: number;
|
|
497
524
|
mode?: NativeDatabaseMode;
|
|
498
525
|
name?: string;
|
|
499
526
|
noBlockCache?: boolean;
|
|
@@ -504,6 +531,7 @@ type NativeDatabaseOptions = {
|
|
|
504
531
|
transactionLogMaxSize?: number;
|
|
505
532
|
transactionLogRetentionMs?: number;
|
|
506
533
|
transactionLogsPath?: string;
|
|
534
|
+
writeBufferSize?: number;
|
|
507
535
|
};
|
|
508
536
|
type ResolveCallback<T> = (value: T) => void;
|
|
509
537
|
type RejectCallback = (err: Error) => void;
|
|
@@ -569,6 +597,40 @@ type NativeDatabase = {
|
|
|
569
597
|
type RocksDatabaseConfig = {
|
|
570
598
|
blockCacheSize?: number;
|
|
571
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;
|
|
572
634
|
};
|
|
573
635
|
type RegistryStatusDB = {
|
|
574
636
|
path: string;
|
package/dist/index.mjs
CHANGED
|
@@ -570,8 +570,6 @@ const VALUE_BUFFER = createFixedBuffer(64 * 1024);
|
|
|
570
570
|
const ITERATOR_STATE_BUFFER = Buffer.allocUnsafeSlow(8);
|
|
571
571
|
const ITERATOR_STATE = new Uint32Array(ITERATOR_STATE_BUFFER.buffer, ITERATOR_STATE_BUFFER.byteOffset, 2);
|
|
572
572
|
const MAX_KEY_SIZE = 1024 * 1024;
|
|
573
|
-
const RESET_BUFFER_MODE = 1024;
|
|
574
|
-
const REUSE_BUFFER_MODE = 512;
|
|
575
573
|
const SAVE_BUFFER_SIZE = 8192;
|
|
576
574
|
/**
|
|
577
575
|
* A store wraps the `NativeDatabase` binding and database settings so that a
|
|
@@ -633,6 +631,24 @@ var Store = class {
|
|
|
633
631
|
*/
|
|
634
632
|
maxKeySize;
|
|
635
633
|
/**
|
|
634
|
+
* The maximum number of memtables that can be queued per column family
|
|
635
|
+
* before writes stall. Higher values absorb write bursts while flushes catch
|
|
636
|
+
* up, at the cost of memory.
|
|
637
|
+
*/
|
|
638
|
+
maxWriteBufferNumber;
|
|
639
|
+
/**
|
|
640
|
+
* The bytes of recent memtable history to retain in memory for transaction
|
|
641
|
+
* conflict checking. `-1` derives the value from
|
|
642
|
+
* `maxWriteBufferNumber * writeBufferSize`.
|
|
643
|
+
*/
|
|
644
|
+
maxWriteBufferSizeToMaintain;
|
|
645
|
+
/**
|
|
646
|
+
* The total memtable budget in bytes across all column families. When the
|
|
647
|
+
* sum of memtables reaches this size, RocksDB flushes the largest one. `0`
|
|
648
|
+
* disables the global trigger so per-CF `writeBufferSize` drives flushing.
|
|
649
|
+
*/
|
|
650
|
+
dbWriteBufferSize;
|
|
651
|
+
/**
|
|
636
652
|
* The name of the store (e.g. the column family). Defaults to `'default'`.
|
|
637
653
|
*/
|
|
638
654
|
name;
|
|
@@ -642,7 +658,8 @@ var Store = class {
|
|
|
642
658
|
noBlockCache;
|
|
643
659
|
/**
|
|
644
660
|
* The number of threads to use for parallel operations. This is a RocksDB
|
|
645
|
-
* option.
|
|
661
|
+
* option. When undefined, the native layer picks
|
|
662
|
+
* `max(1, hardware_concurrency() / 2)`.
|
|
646
663
|
*/
|
|
647
664
|
parallelismThreads;
|
|
648
665
|
/**
|
|
@@ -700,6 +717,11 @@ var Store = class {
|
|
|
700
717
|
*/
|
|
701
718
|
transactionLogsPath;
|
|
702
719
|
/**
|
|
720
|
+
* The per-column-family memtable size in bytes at which the memtable is
|
|
721
|
+
* sealed and flushed.
|
|
722
|
+
*/
|
|
723
|
+
writeBufferSize;
|
|
724
|
+
/**
|
|
703
725
|
* The function used to encode keys using the shared `keyBuffer`.
|
|
704
726
|
*/
|
|
705
727
|
writeKey;
|
|
@@ -714,6 +736,7 @@ var Store = class {
|
|
|
714
736
|
if (options !== void 0 && options !== null && typeof options !== "object") throw new TypeError("Database options must be an object");
|
|
715
737
|
const { keyEncoding, readKey, writeKey } = initKeyEncoder(options?.keyEncoding, options?.keyEncoder);
|
|
716
738
|
this.db = new NativeDatabase();
|
|
739
|
+
this.dbWriteBufferSize = options?.dbWriteBufferSize;
|
|
717
740
|
this.decoder = options?.decoder ?? null;
|
|
718
741
|
this.disableWAL = options?.disableWAL ?? false;
|
|
719
742
|
this.enableStats = options?.enableStats ?? false;
|
|
@@ -724,9 +747,11 @@ var Store = class {
|
|
|
724
747
|
this.keyBuffer = KEY_BUFFER;
|
|
725
748
|
this.keyEncoding = keyEncoding;
|
|
726
749
|
this.maxKeySize = options?.maxKeySize ?? MAX_KEY_SIZE;
|
|
750
|
+
this.maxWriteBufferNumber = options?.maxWriteBufferNumber;
|
|
751
|
+
this.maxWriteBufferSizeToMaintain = options?.maxWriteBufferSizeToMaintain;
|
|
727
752
|
this.name = options?.name ?? "default";
|
|
728
753
|
this.noBlockCache = options?.noBlockCache;
|
|
729
|
-
this.parallelismThreads = options?.parallelismThreads
|
|
754
|
+
this.parallelismThreads = options?.parallelismThreads;
|
|
730
755
|
this.path = path;
|
|
731
756
|
this.pessimistic = options?.pessimistic ?? false;
|
|
732
757
|
this.readOnly = options?.readOnly ?? false;
|
|
@@ -738,6 +763,7 @@ var Store = class {
|
|
|
738
763
|
this.transactionLogMaxSize = options?.transactionLogMaxSize;
|
|
739
764
|
this.transactionLogRetention = options?.transactionLogRetention;
|
|
740
765
|
this.transactionLogsPath = options?.transactionLogsPath;
|
|
766
|
+
this.writeBufferSize = options?.writeBufferSize;
|
|
741
767
|
this.writeKey = writeKey;
|
|
742
768
|
}
|
|
743
769
|
/**
|
|
@@ -833,7 +859,7 @@ var Store = class {
|
|
|
833
859
|
encodeValue(value) {
|
|
834
860
|
if (value && value["binary-data"]) return value["binary-data"];
|
|
835
861
|
if (typeof this.encoder?.encode === "function") {
|
|
836
|
-
if (this.encoder.copyBuffers) return this.encoder.encode(value,
|
|
862
|
+
if (this.encoder.copyBuffers) return this.encoder.encode(value, 1536);
|
|
837
863
|
const valueBuffer = this.encoder.encode(value);
|
|
838
864
|
if (typeof valueBuffer === "string") return Buffer.from(valueBuffer);
|
|
839
865
|
return valueBuffer;
|
|
@@ -999,8 +1025,11 @@ var Store = class {
|
|
|
999
1025
|
open() {
|
|
1000
1026
|
if (this.db.opened) return true;
|
|
1001
1027
|
this.db.open(this.path, {
|
|
1028
|
+
dbWriteBufferSize: this.dbWriteBufferSize,
|
|
1002
1029
|
disableWAL: this.disableWAL,
|
|
1003
1030
|
enableStats: this.enableStats,
|
|
1031
|
+
maxWriteBufferNumber: this.maxWriteBufferNumber,
|
|
1032
|
+
maxWriteBufferSizeToMaintain: this.maxWriteBufferSizeToMaintain,
|
|
1004
1033
|
mode: this.pessimistic ? "pessimistic" : "optimistic",
|
|
1005
1034
|
name: this.name,
|
|
1006
1035
|
noBlockCache: this.noBlockCache,
|
|
@@ -1010,7 +1039,8 @@ var Store = class {
|
|
|
1010
1039
|
transactionLogMaxAgeThreshold: this.transactionLogMaxAgeThreshold,
|
|
1011
1040
|
transactionLogMaxSize: this.transactionLogMaxSize,
|
|
1012
1041
|
transactionLogRetentionMs: this.transactionLogRetention ? parseDuration(this.transactionLogRetention) : void 0,
|
|
1013
|
-
transactionLogsPath: this.transactionLogsPath
|
|
1042
|
+
transactionLogsPath: this.transactionLogsPath,
|
|
1043
|
+
writeBufferSize: this.writeBufferSize
|
|
1014
1044
|
});
|
|
1015
1045
|
return false;
|
|
1016
1046
|
}
|
|
@@ -2043,7 +2073,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
2043
2073
|
//#region src/index.ts
|
|
2044
2074
|
const versions = {
|
|
2045
2075
|
rocksdb: version,
|
|
2046
|
-
"rocksdb-js": "1.
|
|
2076
|
+
"rocksdb-js": "1.3.0"
|
|
2047
2077
|
};
|
|
2048
2078
|
|
|
2049
2079
|
//#endregion
|