@harperfast/rocksdb-js 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -105,10 +105,27 @@ Sets global database settings.
105
105
  - `blockCacheSize: number` The amount of memory in bytes to use to cache uncompressed blocks.
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
+ - `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`.
108
121
 
109
122
  ```typescript
110
123
  RocksDatabase.config({
111
124
  blockCacheSize: 100 * 1024 * 1024, // 100MB
125
+ compactOnClose: true,
126
+ writeBufferManagerAllowStall: false,
127
+ writeBufferManagerCostToCache: false,
128
+ writeBufferManagerSize: 64 * 1024 * 1024, // 64MB
112
129
  });
113
130
  ```
114
131
 
@@ -193,6 +210,33 @@ const entriesRemoved = db.clearSync();
193
210
  console.log(entriesRemoved); // 10
194
211
  ```
195
212
 
213
+ ### `db.compact(options?): Promise<void>`
214
+
215
+ Compacts a range of keys in the database. In RocksDB, deleted keys are not immediately removed from
216
+ the database. Instead, they are marked as deleted and a tombstone is written. This function
217
+ triggers a manual compaction which removes the tombstones and reclaims space. Only one compaction
218
+ per database path can be performed at a time.
219
+
220
+ - `options: object`
221
+ - `start?: Key` The start key of the range to compact.
222
+ - `end?: Key` The end key of the range to compact.
223
+
224
+ ```typescript
225
+ await db.compact();
226
+
227
+ await db.compact({ start: 'a', end: 'z' });
228
+ ```
229
+
230
+ ### `db.compactSync(options?): void`
231
+
232
+ Synchronous version of `compact()`.
233
+
234
+ ```typescript
235
+ db.compactSync();
236
+
237
+ db.compactSync({ start: 'a', end: 'z' });
238
+ ```
239
+
196
240
  ### `db.destroy(): void`
197
241
 
198
242
  Completely removes a database based on the `db` instance's path including all data, column families,
@@ -224,6 +268,23 @@ db.dropSync();
224
268
  db.close();
225
269
  ```
226
270
 
271
+ ### `db.flush(): Promise<void>`
272
+
273
+ Flushes all in-memory data to disk asynchronously.
274
+
275
+ ```typescript
276
+ await db.flush();
277
+ ```
278
+
279
+ ### `db.flushSync(): void`
280
+
281
+ Flushes all in-memory data to disk synchronously. Note that this can be an expensive operation, so
282
+ it is recommended to use `flush()` if you want to keep the event loop free.
283
+
284
+ ```typescript
285
+ db.flushSync();
286
+ ```
287
+
227
288
  ### `db.get(key: Key, options?: GetOptions): MaybePromise<any>`
228
289
 
229
290
  Retreives the value for a given key. If the key does not exist, it will resolve `undefined`.
@@ -248,6 +309,16 @@ Note that all errors are returned as rejected promises.
248
309
 
249
310
  Synchronous version of `get()`.
250
311
 
312
+ ### `db.getEstimatedKeyCount(): number`
313
+
314
+ Retrieves the estimated number of keys in the database. This is an alias for
315
+ `db.getDBIntProperty('rocksdb.estimate-num-keys')`.
316
+
317
+ ```typescript
318
+ const estimated = db.getEstimatedKeyCount();
319
+ console.log(estimated);
320
+ ```
321
+
251
322
  ### `db.getKeys(options?: IteratorOptions): ExtendedIterable`
252
323
 
253
324
  Retrieves all keys within a range.
@@ -260,11 +331,11 @@ for (const key of db.getKeys()) {
260
331
 
261
332
  ### `db.getKeysCount(options?: RangeOptions): number`
262
333
 
263
- Retrieves the number of keys within a range.
334
+ Retrieves the exact number of keys in a database or a range.
264
335
 
265
336
  ```typescript
266
- const total = db.getKeysCount();
267
- const range = db.getKeysCount({ start: 'a', end: 'z' });
337
+ const count = db.getKeysCount(); // estimated number of keys
338
+ const range = db.getKeysCount({ start: 'a', end: 'z' }); // exact number of keys in the range
268
339
  ```
269
340
 
270
341
  ### `db.getMonotonicTimestamp(): number`
@@ -876,23 +947,6 @@ Note: If the `callback` throws an error, Node.js suppress the error. Node.js 18.
876
947
  `--force-node-api-uncaught-exceptions-policy` flag which will cause errors to emit the
877
948
  `'uncaughtException'` event. Future Node.js releases will enable this flag by default.
878
949
 
879
- ### `db.flush(): Promise<void>`
880
-
881
- Flushes all in-memory data to disk asynchronously.
882
-
883
- ```typescript
884
- await db.flush();
885
- ```
886
-
887
- ### `db.flushSync(): void`
888
-
889
- Flushes all in-memory data to disk synchronously. Note that this can be an expensive operation, so
890
- it is recommended to use `flush()` if you want to keep the event loop free.
891
-
892
- ```typescript
893
- db.flushSync();
894
- ```
895
-
896
950
  ## Transaction Log
897
951
 
898
952
  A user controlled API for logging transactions. This API is designed to be generic so that you can
@@ -1129,6 +1183,8 @@ The default `Store` contains the following methods which can be overridden:
1129
1183
 
1130
1184
  - `constructor(path, options?)`
1131
1185
  - `close()`
1186
+ - `compact(options?)`
1187
+ - `compactSync(options?)`
1132
1188
  - `decodeKey(key)`
1133
1189
  - `decodeValue(value)`
1134
1190
  - `encodeKey(key)`
@@ -1235,6 +1291,40 @@ Extends `RangeOptions`.
1235
1291
  - `options: object`
1236
1292
  - `reverse: boolean` When `true`, the iterator will iterate in reverse order. Defaults to `false`.
1237
1293
 
1294
+ ## CLI
1295
+
1296
+ The `rocksdb-js` CLI is a command line interface for interacting with RocksDB databases.
1297
+
1298
+ ```bash
1299
+ rocksdb-js [dbpath]
1300
+ ```
1301
+
1302
+ Options:
1303
+
1304
+ - `-h, --help` Show this help message
1305
+ - `-r, --readonly` Open the database in read-only mode
1306
+ - `-v, --version` Show the version information
1307
+
1308
+ Available commands:
1309
+
1310
+ - `clear` Clear all data in the current column family
1311
+ - `columns` List column families
1312
+ - `compact` Compact the current column family
1313
+ - `count` Count the number of keys in the current column family
1314
+ - `drop <column>` Permanently drop a column family
1315
+ - `exit` Exit the REPL
1316
+ - `get <key>` Get the value of a key
1317
+ - `help` Show this help message
1318
+ - `log [name] [file] [entry]` List the transaction log store names and log store files
1319
+ - `prop <key>` Get a RocksDB property (try "rocksdb.stats")
1320
+ - `purge-logs <name>` Purge transaction log files older than 3 days
1321
+ - `put <key> <value>` Set the value of a key
1322
+ - `query [start] [end]` Query a range of keys
1323
+ - `remove <key>` Delete a key
1324
+ - `repl` Open a JS sub-REPL; "db" refers to the current column family
1325
+ - `stats` Show the statistics for the current column family
1326
+ - `use [column]` Create a new column family or switch to an existing one
1327
+
1238
1328
  ## Development
1239
1329
 
1240
1330
  This package requires Node.js 18 or higher, pnpm, and a C++ compiler.
@@ -1346,6 +1436,24 @@ To run the tests without code coverage, run:
1346
1436
  pnpm test
1347
1437
  ```
1348
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
+
1349
1457
  To run a specific test suite, for example `"ranges"`, run:
1350
1458
 
1351
1459
  ```bash