walpack 0.2.0
walpack: ^0.2.0 copied to clipboard
High-performance, crash-safe, single-file binary container with chunked storage and append-only write-ahead log (WAL) for Dart.
0.2.0 #
Audit fixes. Several items change behavior; see Breaking.
- Breaking:
WalPack.openFilenow defaults toAdjacentLockStrategy(<path>.locknext to the container). The old default,TempDirLockStrategy, chose its lock directory fromXDG_RUNTIME_DIR/TMPDIR, so processes with different environments could lock different files and lose writes.TempDirLockStrategyno longer readsXDG_RUNTIME_DIR; pass a sharedlockDirectorywhen using it. Do not mix 0.1.x and 0.2.x processes on the same container. - Breaking:
commit()/compact(rewrite:)rejectasynccallbacks withArgumentError, and builders throwStateErroronce the callback returned (previously operations after the firstawaitwere silently dropped). - Breaking: Unknown superblock and WAL frame flag bits are rejected.
- Commits whose frame would exceed
maxFramePayloadBytes/maxIndexHeaderBytesare rejected before writing (previously they were acknowledged and then truncated away on the next open). - WAL recovery distinguishes a torn tail from mid-WAL corruption: damage
followed by intact frames, undecodable CRC-valid frames (including JS
53-bit overflows), and frames above the reader's limits are no longer
truncated. Writable opens throw
WalPackCorruptException; read-only opens serve the intact prefix and reportWalPack.walCorruption. - Frame headers are CRC-checked before any field is decoded (fixes a throw on Web for garbage headers).
- Automatic compaction failures no longer fail the already-durable commit;
see
CommitCommitted.autoCompactionError. compact()works on empty containers and after deleting every chunk.verifyIntegrity()reports sync failures instead of throwing.- Reads on transient-handle backends (Windows default
keepHandleOpen: false) re-sync after an external compaction instead of using stale offsets. - POSIX: parent directory is fsynced after container creation and after the
compaction rename; compaction preserves permission bits, follows symlinks,
and sweeps orphaned
*.compact.*.tmpfiles. Lock paths resolve symlinks to the file itself; read-only handles open existing lock files read-only and fall back to unlocked reads when the lock file cannot be created (e.g. a read-only directory). Directory fsync runs on a helper isolate unlessIoMode.syncis used. - Validation: superblock offsets/
baseSeqbounds and entry invariants, TOC range overflow, duplicate put keys / index names inside a frame,WalPackOptions(minCompressBytes,defaultCodecId, compaction policy, limits). stats/shouldCompactno longer scan every chunk on each commit.MemoryStorageBackend: empty writes no longer extend the buffer; newtrackDurability/simulateCrash()model unflushed data loss.FaultInjectionBackendgains truncate, read, and post-swap faults.- LZ4 decoder accepts the reference encoding of empty input (
0x00). WalPack.inMemorycloses its backend when opening fails; ownership rules forWalPack.openare documented.
Performance:
- Secondary and primary-key indexes merge their overlay geometrically: bulk inserts and WAL replay are amortized O(1) per key instead of O(N / 256) (e.g. 200k indexed puts: 49.8 s -> 5.2 s; single indexed commit on a 205k base: 219 us -> 26 us).
decodeBaseIndexavoids per-chunk map copies (~2.4x faster cold open of indexed snapshots).- Compaction batches small pass-through chunks into coalesced reads and vectored writes while keeping key order and byte-identical output (~4x faster for 200k small chunks).
New APIs:
WalPack.watch()stream of external changes;commitWithRetry(read, write)optimistic read-modify-write withWalPackConflictException.copyTo(StorageBackend),exportBytes(), andbackupToFile(path)(walpack_io) for consistent copies of a live container.CommitBuilder.deletePrefix/deleteRange;skipIfUnchanged:onputChunk/putChunkWith;startAfterpagination forkeysWithPrefix/readPrefix.WalPackOptions.lockTimeout(andtimeout:on the file lock strategies).package:walpack/testing.dartwithSharedMemoryStoragefor multi-handle tests without files.
Behavior changes:
- Read results (
readChunk,readChunks,readPrefix,readChunkRaw,readOps) are always read-only views. - Deleting an absent key queues nothing (
CommitNoOpwhen nothing else is queued). - Synchronous accessors (
containsChunk,chunkMeta,chunkKeys,chunks,chunkCount, index names,stats) throwWalPackClosedExceptionafterclose(). WalPackCorruptExceptioncarries the filepathwhen opened viaopenFile;WalPackAppIdMismatchException.actualisnull(printed as(none)) for containers without an app id.
0.1.0 #
- Initial release of
walpack: single-file binary container (WLPKv1) with immutable chunked snapshot storage, append-only CRC32-C Write-Ahead Log (WAL), and Copy-on-Write (CoW) compaction (atomicReplace+rename()). - High-throughput pure-Dart primitives built on
pro_binary:- Slicing-by-8 CRC32-C (including
crc32cCombineGF(2) composition to eliminate duplicate chunk scans during WAL commits) and 32-bit stripe XXH32 integrity checks. - Pure-Dart LZ4 block codec (L1 hash table + exponential doubling match
decoder + 64-bit fast-loop) plus native
ZLibChunkCodec. - Scatter-gather commit frames (
writeView+takeChunks()), a zero-builderappendOp()/appendOpWith()fast path, optionalreadCacheBytesLRU cache, and offset-sorted read-coalescedreadChunks()batch reads. - Native sorted primary-key binary search (
keysWithPrefix,keysInRange,readPrefix,readRange) and Snapshot+WALint/Stringsecondary indexes (queryIntIndex,queryStringIndex,readIntIndex,readStringIndex). IoStorageBackendwith lazy single open, dirty-trackedclose(), cursor tracking (_knownPos),IoMode(hybridwith<= 256 KiBsync path /sync/async), Windows transient-handle support (keepHandleOpen), and 512 KiBFastCopyStorageBackend.copyRangeTopass-through compaction.
- Slicing-by-8 CRC32-C (including
- Production hardening & cross-process coordination:
WalPackLimitsbounded decoding (including bounded chunked ZLib inflation against oversized/zip-bomb payloads) and structural TOC/Base Index/WAL validation (duplicate keys, duplicate index ordinals,[64, tocOffset]range checks, bounded strings/frames).- Isolated
MemoryStorageBackend.readAtcopies, strict bounds validation across storage backends, canonicalizedAdjacentLockStrategy, and synchronized lock-registry cleanup. - Live partial-write rollback (
truncate(_walEndOffset)) on failed commits. - Optimistic Concurrency Control (
expectedSeq->CommitConflict) andGenerationAwareLockStrategy(TempDirLockStrategy,AdjacentLockStrategy) with 8-byte lock-file generation tracking. - Pluggable
StorageBackend(native file I/O, Web/WASMMemoryStorageBackend,FaultInjectionBackend), verified across unit/fuzz/oracle/interop/Node.js suites.