@harperfast/rocksdb-js 2.2.0 → 2.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
@@ -1385,6 +1385,34 @@ import { versions } from '@harperfast/rocksdb-js';
1385
1385
  console.log(versions); // { "rocksdb": "10.10.1", "rocksdb-js": "0.1.2" }
1386
1386
  ```
1387
1387
 
1388
+ ## Checkpoints
1389
+
1390
+ ### `db.createCheckpoint(targetPath: string): Promise<void>`
1391
+
1392
+ Creates a [checkpoint](https://github.com/facebook/rocksdb/wiki/Checkpoints) — a point-in-time,
1393
+ fully independent copy of the entire database (all column families) at `targetPath` — and resolves
1394
+ once written. Unlike a backup, a checkpoint is a normal, writable database: open it as a new
1395
+ `RocksDatabase` and it diverges independently from the source.
1396
+
1397
+ SST and blob files are **hard-linked** when `targetPath` is on the **same filesystem** as the
1398
+ database, and **copied** otherwise; other files (such as the `MANIFEST`) are always copied. As a
1399
+ result the operation is near-instant on the same filesystem and as costly as a full copy across
1400
+ filesystems. The memtable is flushed so the checkpoint includes the latest writes even when the
1401
+ WAL is disabled.
1402
+
1403
+ Parent directories are created as needed. `targetPath` itself must not already exist — RocksDB
1404
+ creates the checkpoint directory — and the call rejects with `Create checkpoint failed: target
1405
+ path exists` if it does (other failures, such as a full disk, surface the RocksDB status message).
1406
+ The caller is responsible for opening the checkpoint and for eventually deleting the directory.
1407
+
1408
+ ```typescript
1409
+ const db = RocksDatabase.open('/path/to/database');
1410
+ await db.createCheckpoint('/path/to/checkpoint');
1411
+
1412
+ // The checkpoint is a normal, writable database.
1413
+ const branch = RocksDatabase.open('/path/to/checkpoint');
1414
+ ```
1415
+
1388
1416
  ## Backups
1389
1417
 
1390
1418
  Backups use RocksDB's `BackupEngine` to capture consistent, incremental, checksum-verified
package/dist/index.cjs CHANGED
@@ -1527,6 +1527,40 @@ var RocksDatabase = class RocksDatabase extends DBI {
1527
1527
  return this.store.backup(backupDir, options);
1528
1528
  }
1529
1529
  /**
1530
+ * Creates a hardlinked, point-in-time, fully independent copy of the entire
1531
+ * database (all column families) at `targetPath` and resolves once written.
1532
+ *
1533
+ * Unlike a backup, a checkpoint is a normal, writable sibling database: open
1534
+ * it with {@link RocksDatabase.open} and it diverges independently from the
1535
+ * source. SST and blob files are hardlinked when `targetPath` is on the same
1536
+ * filesystem as the database and copied otherwise (other files such as the
1537
+ * MANIFEST are always copied), so the operation is near-instant on the same
1538
+ * filesystem. The memtable is flushed so the checkpoint includes the latest
1539
+ * writes even when the WAL is disabled.
1540
+ *
1541
+ * Parent directories are created as needed. `targetPath` itself must not
1542
+ * already exist (RocksDB creates the checkpoint directory) and rejects with
1543
+ * `Create checkpoint failed: target path exists` if it does. The caller is
1544
+ * responsible for eventual cleanup of the directory.
1545
+ *
1546
+ * @example
1547
+ * ```typescript
1548
+ * const db = RocksDatabase.open('/path/to/database');
1549
+ * await db.createCheckpoint('/path/to/checkpoint');
1550
+ * const branch = RocksDatabase.open('/path/to/checkpoint');
1551
+ * ```
1552
+ */
1553
+ createCheckpoint(targetPath) {
1554
+ return new Promise((resolve, reject) => {
1555
+ if ((0, node_fs.existsSync)(targetPath)) {
1556
+ reject(/* @__PURE__ */ new Error("Create checkpoint failed: target path exists"));
1557
+ return;
1558
+ }
1559
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(targetPath), { recursive: true });
1560
+ this.store.db.createCheckpoint(resolve, reject, targetPath);
1561
+ });
1562
+ }
1563
+ /**
1530
1564
  * Compacts the entire key range of the database synchronously.
1531
1565
  * This triggers manual compaction which removes tombstones and reclaims space.
1532
1566
  *
@@ -2375,7 +2409,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
2375
2409
  //#region src/index.ts
2376
2410
  const versions = {
2377
2411
  rocksdb: version,
2378
- "rocksdb-js": "2.2.0"
2412
+ "rocksdb-js": "2.3.0"
2379
2413
  };
2380
2414
 
2381
2415
  //#endregion