@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 CHANGED
@@ -106,11 +106,26 @@ Sets global database settings.
106
106
  Defaults to 32MB. Set to `0` (zero) disables block cache for future opened databases. Existing
107
107
  block cache for any opened databases is resized immediately. Negative values throw an error.
108
108
  - `compactOnClose: boolean` When `true`, compacts the database on close. Defaults to `false`.
109
+ - `writeBufferManagerAllowStall: boolean` When `true`, writes are stalled once the manager's
110
+ `buffer_size` is exceeded, providing a hard cap on memtable memory. When `false`, memtables are
111
+ allowed to grow past the limit and flushes are simply scheduled more aggressively. Off by
112
+ default to favor write throughput over hard memory bounding. Defaults to `false`.
113
+ - `writeBufferManagerCostToCache: boolean` When `true`, memtable memory is "charged" against the
114
+ shared block cache so the block cache and write buffers draw from a single pool. During write
115
+ bursts the cache shrinks to make room for memtables; once memtables flush, the cache can grow
116
+ back into the reclaimed space. Defaults to `false`.
117
+ - `writeBufferManagerSize: number` Total memtable memory limit (bytes) shared across every
118
+ database opened in this process. When set, RocksDB uses a single `WriteBufferManager` so write
119
+ buffers are bounded process-wide rather than per database. A value of `0` disables the manager.
120
+ Defaults to `0`.
109
121
 
110
122
  ```typescript
111
123
  RocksDatabase.config({
112
124
  blockCacheSize: 100 * 1024 * 1024, // 100MB
113
125
  compactOnClose: true,
126
+ writeBufferManagerAllowStall: false,
127
+ writeBufferManagerCostToCache: false,
128
+ writeBufferManagerSize: 64 * 1024 * 1024, // 64MB
114
129
  });
115
130
  ```
116
131
 
@@ -1421,6 +1436,24 @@ To run the tests without code coverage, run:
1421
1436
  pnpm test
1422
1437
  ```
1423
1438
 
1439
+ #### Native C++ unit tests (GoogleTest)
1440
+
1441
+ Build and run standalone native tests (RocksDB + binding `core/` helpers, no Node in the test
1442
+ binary):
1443
+
1444
+ ```bash
1445
+ pnpm test:native
1446
+ ```
1447
+
1448
+ Coverage report for native tests (macOS/Linux; requires `lcov`):
1449
+
1450
+ ```bash
1451
+ pnpm coverage:native
1452
+ # open coverage/native/html/index.html
1453
+ ```
1454
+
1455
+ Note: Code coverage is not supported on Windows. Tests are run without coverage.
1456
+
1424
1457
  To run a specific test suite, for example `"ranges"`, run:
1425
1458
 
1426
1459
  ```bash
package/dist/index.cjs CHANGED
@@ -595,8 +595,6 @@ const VALUE_BUFFER = createFixedBuffer(64 * 1024);
595
595
  const ITERATOR_STATE_BUFFER = Buffer.allocUnsafeSlow(8);
596
596
  const ITERATOR_STATE = new Uint32Array(ITERATOR_STATE_BUFFER.buffer, ITERATOR_STATE_BUFFER.byteOffset, 2);
597
597
  const MAX_KEY_SIZE = 1024 * 1024;
598
- const RESET_BUFFER_MODE = 1024;
599
- const REUSE_BUFFER_MODE = 512;
600
598
  const SAVE_BUFFER_SIZE = 8192;
601
599
  /**
602
600
  * A store wraps the `NativeDatabase` binding and database settings so that a
@@ -658,6 +656,24 @@ var Store = class {
658
656
  */
659
657
  maxKeySize;
660
658
  /**
659
+ * The maximum number of memtables that can be queued per column family
660
+ * before writes stall. Higher values absorb write bursts while flushes catch
661
+ * up, at the cost of memory.
662
+ */
663
+ maxWriteBufferNumber;
664
+ /**
665
+ * The bytes of recent memtable history to retain in memory for transaction
666
+ * conflict checking. `-1` derives the value from
667
+ * `maxWriteBufferNumber * writeBufferSize`.
668
+ */
669
+ maxWriteBufferSizeToMaintain;
670
+ /**
671
+ * The total memtable budget in bytes across all column families. When the
672
+ * sum of memtables reaches this size, RocksDB flushes the largest one. `0`
673
+ * disables the global trigger so per-CF `writeBufferSize` drives flushing.
674
+ */
675
+ dbWriteBufferSize;
676
+ /**
661
677
  * The name of the store (e.g. the column family). Defaults to `'default'`.
662
678
  */
663
679
  name;
@@ -667,7 +683,8 @@ var Store = class {
667
683
  noBlockCache;
668
684
  /**
669
685
  * The number of threads to use for parallel operations. This is a RocksDB
670
- * option.
686
+ * option. When undefined, the native layer picks
687
+ * `max(1, hardware_concurrency() / 2)`.
671
688
  */
672
689
  parallelismThreads;
673
690
  /**
@@ -725,6 +742,11 @@ var Store = class {
725
742
  */
726
743
  transactionLogsPath;
727
744
  /**
745
+ * The per-column-family memtable size in bytes at which the memtable is
746
+ * sealed and flushed.
747
+ */
748
+ writeBufferSize;
749
+ /**
728
750
  * The function used to encode keys using the shared `keyBuffer`.
729
751
  */
730
752
  writeKey;
@@ -739,6 +761,7 @@ var Store = class {
739
761
  if (options !== void 0 && options !== null && typeof options !== "object") throw new TypeError("Database options must be an object");
740
762
  const { keyEncoding, readKey, writeKey } = initKeyEncoder(options?.keyEncoding, options?.keyEncoder);
741
763
  this.db = new NativeDatabase();
764
+ this.dbWriteBufferSize = options?.dbWriteBufferSize;
742
765
  this.decoder = options?.decoder ?? null;
743
766
  this.disableWAL = options?.disableWAL ?? false;
744
767
  this.enableStats = options?.enableStats ?? false;
@@ -749,9 +772,11 @@ var Store = class {
749
772
  this.keyBuffer = KEY_BUFFER;
750
773
  this.keyEncoding = keyEncoding;
751
774
  this.maxKeySize = options?.maxKeySize ?? MAX_KEY_SIZE;
775
+ this.maxWriteBufferNumber = options?.maxWriteBufferNumber;
776
+ this.maxWriteBufferSizeToMaintain = options?.maxWriteBufferSizeToMaintain;
752
777
  this.name = options?.name ?? "default";
753
778
  this.noBlockCache = options?.noBlockCache;
754
- this.parallelismThreads = options?.parallelismThreads ?? 1;
779
+ this.parallelismThreads = options?.parallelismThreads;
755
780
  this.path = path;
756
781
  this.pessimistic = options?.pessimistic ?? false;
757
782
  this.readOnly = options?.readOnly ?? false;
@@ -763,6 +788,7 @@ var Store = class {
763
788
  this.transactionLogMaxSize = options?.transactionLogMaxSize;
764
789
  this.transactionLogRetention = options?.transactionLogRetention;
765
790
  this.transactionLogsPath = options?.transactionLogsPath;
791
+ this.writeBufferSize = options?.writeBufferSize;
766
792
  this.writeKey = writeKey;
767
793
  }
768
794
  /**
@@ -858,7 +884,7 @@ var Store = class {
858
884
  encodeValue(value) {
859
885
  if (value && value["binary-data"]) return value["binary-data"];
860
886
  if (typeof this.encoder?.encode === "function") {
861
- if (this.encoder.copyBuffers) return this.encoder.encode(value, REUSE_BUFFER_MODE | RESET_BUFFER_MODE);
887
+ if (this.encoder.copyBuffers) return this.encoder.encode(value, 1536);
862
888
  const valueBuffer = this.encoder.encode(value);
863
889
  if (typeof valueBuffer === "string") return Buffer.from(valueBuffer);
864
890
  return valueBuffer;
@@ -1024,8 +1050,11 @@ var Store = class {
1024
1050
  open() {
1025
1051
  if (this.db.opened) return true;
1026
1052
  this.db.open(this.path, {
1053
+ dbWriteBufferSize: this.dbWriteBufferSize,
1027
1054
  disableWAL: this.disableWAL,
1028
1055
  enableStats: this.enableStats,
1056
+ maxWriteBufferNumber: this.maxWriteBufferNumber,
1057
+ maxWriteBufferSizeToMaintain: this.maxWriteBufferSizeToMaintain,
1029
1058
  mode: this.pessimistic ? "pessimistic" : "optimistic",
1030
1059
  name: this.name,
1031
1060
  noBlockCache: this.noBlockCache,
@@ -1035,7 +1064,8 @@ var Store = class {
1035
1064
  transactionLogMaxAgeThreshold: this.transactionLogMaxAgeThreshold,
1036
1065
  transactionLogMaxSize: this.transactionLogMaxSize,
1037
1066
  transactionLogRetentionMs: this.transactionLogRetention ? parseDuration(this.transactionLogRetention) : void 0,
1038
- transactionLogsPath: this.transactionLogsPath
1067
+ transactionLogsPath: this.transactionLogsPath,
1068
+ writeBufferSize: this.writeBufferSize
1039
1069
  });
1040
1070
  return false;
1041
1071
  }
@@ -2068,7 +2098,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
2068
2098
  //#region src/index.ts
2069
2099
  const versions = {
2070
2100
  rocksdb: version,
2071
- "rocksdb-js": "1.2.0"
2101
+ "rocksdb-js": "1.3.0"
2072
2102
  };
2073
2103
 
2074
2104
  //#endregion