Skip to main content

walpack 0.2.0 copy "walpack: ^0.2.0" to clipboard
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.openFile now defaults to AdjacentLockStrategy (<path>.lock next to the container). The old default, TempDirLockStrategy, chose its lock directory from XDG_RUNTIME_DIR / TMPDIR, so processes with different environments could lock different files and lose writes. TempDirLockStrategy no longer reads XDG_RUNTIME_DIR; pass a shared lockDirectory when using it. Do not mix 0.1.x and 0.2.x processes on the same container.
  • Breaking: commit() / compact(rewrite:) reject async callbacks with ArgumentError, and builders throw StateError once the callback returned (previously operations after the first await were silently dropped).
  • Breaking: Unknown superblock and WAL frame flag bits are rejected.
  • Commits whose frame would exceed maxFramePayloadBytes / maxIndexHeaderBytes are 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 report WalPack.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.*.tmp files. 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 unless IoMode.sync is used.
  • Validation: superblock offsets/baseSeq bounds and entry invariants, TOC range overflow, duplicate put keys / index names inside a frame, WalPackOptions (minCompressBytes, defaultCodecId, compaction policy, limits).
  • stats / shouldCompact no longer scan every chunk on each commit.
  • MemoryStorageBackend: empty writes no longer extend the buffer; new trackDurability / simulateCrash() model unflushed data loss. FaultInjectionBackend gains truncate, read, and post-swap faults.
  • LZ4 decoder accepts the reference encoding of empty input (0x00).
  • WalPack.inMemory closes its backend when opening fails; ownership rules for WalPack.open are 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).
  • decodeBaseIndex avoids 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 with WalPackConflictException.
  • copyTo(StorageBackend), exportBytes(), and backupToFile(path) (walpack_io) for consistent copies of a live container.
  • CommitBuilder.deletePrefix / deleteRange; skipIfUnchanged: on putChunk / putChunkWith; startAfter pagination for keysWithPrefix / readPrefix.
  • WalPackOptions.lockTimeout (and timeout: on the file lock strategies).
  • package:walpack/testing.dart with SharedMemoryStorage for 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 (CommitNoOp when nothing else is queued).
  • Synchronous accessors (containsChunk, chunkMeta, chunkKeys, chunks, chunkCount, index names, stats) throw WalPackClosedException after close().
  • WalPackCorruptException carries the file path when opened via openFile; WalPackAppIdMismatchException.actual is null (printed as (none)) for containers without an app id.

0.1.0 #

  • Initial release of walpack: single-file binary container (WLPK v1) 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 crc32cCombine GF(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-builder appendOp() / appendOpWith() fast path, optional readCacheBytes LRU cache, and offset-sorted read-coalesced readChunks() batch reads.
    • Native sorted primary-key binary search (keysWithPrefix, keysInRange, readPrefix, readRange) and Snapshot+WAL int/String secondary indexes (queryIntIndex, queryStringIndex, readIntIndex, readStringIndex).
    • IoStorageBackend with lazy single open, dirty-tracked close(), cursor tracking (_knownPos), IoMode (hybrid with <= 256 KiB sync path / sync / async), Windows transient-handle support (keepHandleOpen), and 512 KiB FastCopyStorageBackend.copyRangeTo pass-through compaction.
  • Production hardening & cross-process coordination:
    • WalPackLimits bounded 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.readAt copies, strict bounds validation across storage backends, canonicalized AdjacentLockStrategy, and synchronized lock-registry cleanup.
    • Live partial-write rollback (truncate(_walEndOffset)) on failed commits.
    • Optimistic Concurrency Control (expectedSeq -> CommitConflict) and GenerationAwareLockStrategy (TempDirLockStrategy, AdjacentLockStrategy) with 8-byte lock-file generation tracking.
    • Pluggable StorageBackend (native file I/O, Web/WASM MemoryStorageBackend, FaultInjectionBackend), verified across unit/fuzz/oracle/interop/Node.js suites.
1
likes
160
points
--
downloads

Documentation

Documentation
API reference

Publisher

verified publisherpro100.dev

Weekly Downloads

High-performance, crash-safe, single-file binary container with chunked storage and append-only write-ahead log (WAL) for Dart.

Repository (GitHub)
View/report issues

Topics

#storage #binary #wal #container #database

License

MIT (license)

Dependencies

meta, pro_binary

More

Packages that depend on walpack