Understand Overlapping Sync and Durability
masterWhen overlappingSync: true is enabled (default on non-Windows), LMDB allows disk flushing to occur in parallel with future transactions. This improves performance by not holding the writer lock during the slow flush process.
Managing Durability: There is a distinction between a transaction being committed (visible to other threads) and being flushed (durable on disk).
- Committed: The promise returned by
putorremoveresolves when the transaction is committed and visible. - Flushed: The
db.flushedproperty (or the.flushedproperty on a promise ifseparateFlushed: trueis set) resolves when the OS reports the data is truly durable on disk.
Note: overlappingSync is generally not recommended on Windows due to poor performance characteristics with large databases.
let db = open('my-db', { overlappingSync: true });
let written = db.put(key, value);
await written; // Wait for it to be committed (visible)
// Access the value immediately after commit
let v = db.get(key);
await db.flushed; // Wait for the last commit to be fully flushed to disk (durable)