Define and enforce durability semantics for caller-supplied data and WAL streams
Summary
This is a pre-existing stream-contract limitation, not introduced by #3027.
LiteDB accepts caller-owned/custom streams for data and WAL storage. The engine can call Write, Flush, and (for IDurableStream) FlushToDisk, but it cannot currently prove that an arbitrary stream actually publishes the bytes it claims to publish.
Examples that remain unsafe/undefined include:
- a custom stream whose
Flush()does not release its buffered bytes; - a buffering wrapper that replays bytes from a failed write later at a different position;
- a custom durable stream whose durability primitive does not match the semantics LiteDB assumes;
- several engines sharing a custom caller stream without an external synchronization/durability contract.
#3027 adds defensive flushing for non-MemoryStream caller streams and closes several concrete torn-WAL windows, but these more general semantics already existed in 5.0.21.
Why track this
The public stream API should say clearly which guarantees LiteDB can provide and when it must fail closed instead of implying file-level durability for an arbitrary Stream.
Desired outcome
- Document the required semantics for caller-supplied data/log streams:
- positioning/read/write behavior;
- what
Flush()must guarantee; - what
IDurableStream.FlushToDisk()must guarantee; - ownership and cross-engine synchronization rules.
- Decide whether unsafe stream classes can be rejected/detected up front or whether the contract must remain caller responsibility.
- Add adversarial contract tests for buffering, failed writes, replay-after-failure, and multi-engine use.
- Ensure
$database.durableLogFlushor equivalent diagnostics do not claim a stronger durability guarantee than the supplied stream can actually provide.
Related: #3027, #2242, #2940.
Source: litedb-org/LiteDB