defuss-dbsonl 0.4.0 → 0.6.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/ARCH.md +11 -5
- package/CHANGELOG.md +52 -0
- package/README.md +28 -15
- package/dist/index.cjs +611 -74
- package/dist/index.d.cts +51 -5
- package/dist/index.d.mts +51 -5
- package/dist/index.mjs +612 -75
- package/dist/server.cjs +31 -19
- package/dist/server.mjs +31 -19
- package/dist/{types-B_SuDjVq.d.cts → types-7kcIxgpp.d.cts} +7 -1
- package/dist/{types-B_SuDjVq.d.mts → types-7kcIxgpp.d.mts} +7 -1
- package/docs/API.md +10 -6
- package/docs/FORMAT.md +6 -4
- package/docs/PERFORMANCE.md +119 -36
- package/package.json +15 -6
package/ARCH.md
CHANGED
|
@@ -18,7 +18,7 @@ flowchart TD
|
|
|
18
18
|
|
|
19
19
|
## Why this design
|
|
20
20
|
|
|
21
|
-
VERIFIED: A persistent B+tree avoids a database-sized RAM map without requiring a second database dependency. Fanout 32 trades modest page sizes for logarithmic tree navigation. Values are separate DSON frames; pages contain only keys, references and revisions. Rewriting a path rather than mutating it gives readers stable roots with no undo log. A batch coalesces edits in private dirty nodes and persists each final dirty page once, avoiding unobservable intermediate roots. A bounded
|
|
21
|
+
VERIFIED: A persistent B+tree avoids a database-sized RAM map without requiring a second database dependency. Fanout 32 trades modest page sizes for logarithmic tree navigation. Values are separate DSON frames; pages contain only keys, references and revisions. Rewriting a path rather than mutating it gives readers stable roots with no undo log. A batch coalesces edits in private dirty nodes and persists each final dirty page once, avoiding unobservable intermediate roots. An edit whose path is already dirty or cached runs synchronously; only a page read awaits. A bounded cache stores decoded pages, never application values. It evicts by second chance: a hit only marks its page, and eviction moves a marked page to the back once. Exact LRU reordered the Map on every hit, about 5% of a memory commit. Index pages are written by `encodePage`, which produces the same frames as `encodeFrame` in trusted mode about 30% faster because it knows the few property names pages use. A commit edits cached copies of the pages on its paths instead of rereading them, and adds the pages it wrote once their root is published; a page address within a generation never changes meaning, because only an unpublished tail is ever rewritten. Open reads constant-size metadata and generation length, not every value.
|
|
22
22
|
|
|
23
23
|
VERIFIED: A two-slot manifest avoids relying on atomic rename, which Storage and OPFS do not expose uniformly. Each slot is a checksummed DSON frame in a 4096-byte region. The newest valid publication wins. Writers append after the published end, flush, then replace the older slot. A partial slot is ignored. An empty head whose generations are all empty is an interrupted create: only `create: true` initializes it, because no slot was published; invalid fields in a checksummed slot, a missing referenced generation or committed truncation fail closed. A failed publication reports `COMMIT_UNCERTAIN`; reread the revision before retrying. Successful publication increments the logical revision once per nonempty batch.
|
|
24
24
|
|
|
@@ -26,21 +26,27 @@ VERIFIED: These choices spend extra write bandwidth on index paths and two small
|
|
|
26
26
|
|
|
27
27
|
## Ownership and lock order
|
|
28
28
|
|
|
29
|
-
VERIFIED: The commit lock serializes head inspection and publication. A snapshot takes a shared generation pin while holding that lock, then releases the commit lock. Portable reads acquire short I/O locks because Storage 0.3
|
|
29
|
+
VERIFIED: The commit lock serializes head inspection and publication. A snapshot takes a shared generation pin while holding that lock, then releases the commit lock. While a handle's own commit group holds the lock, that handle pins the group's last flushed head instead: nobody else can publish or collect then, and the group releases the lock only after those pins are granted. Readers therefore never see a head before its flush. Portable reads acquire short I/O locks because Storage 0.3 and OPFS grant exclusive handle ownership. Native reads use independent read-only descriptors: committed prefixes are immutable, writers truncate only unpublished tails, and the pin prevents removal. A native snapshot therefore reads concurrently with appends. The lifetime of a read session does not reserve the commit lock.
|
|
30
30
|
|
|
31
31
|
VERIFIED: Native locks are separate whole-file locks scoped to open descriptions/handles; they do not expire with a clock or heartbeat. A paused process cannot lose ownership to a second writer. The kernel releases ownership on process death. Web Locks release when their worker/context dies. Memory coordination is instance-local. Raw Storage writes and unrelated processes ignoring the protocol are outside the ownership contract.
|
|
32
32
|
|
|
33
33
|
VERIFIED: Acquisition order is commit lock, generation pin, I/O lock. Snapshot readers use their pin and, for portable adapters, short I/O locks without reacquiring the commit lock. A direct `get()` holds the commit lock until its bounded lookup finishes, which also excludes collection without a separate snapshot pin. Compaction pins both its source and candidate generation before releasing the commit lock. It writes only the candidate and reads the source in short operations. Publication compares the original publication number, so even another compaction causes a conflict. Exclusive compaction keeps the commit lock through the copy for guaranteed progress.
|
|
34
34
|
|
|
35
|
+
VERIFIED: Commits queued on one handle form a group: the next lock holder checks every member in queue order, appends all of their values and pages with one writer, flushes the generation once and publishes one head. Each member keeps its own revision, so the group equals sequential commits that no reader observed in between. A group is capped by one batch's operation and byte budgets; any failure before publication retries its members one at a time, so one member cannot fail another. The alternative, one publication per commit, paid two flushes per commit: with four writers on Node under macOS, about 8 ms per commit. Grouping cuts the flushes per commit; the cost is that a member waits for the slowest check in its group.
|
|
36
|
+
|
|
37
|
+
VERIFIED: A forming group first sets the head that new snapshots pin, then waits while transactions on its handle hold a snapshot but have not queued their commit, waking on every arrival, for at most half the previous group's publication time. Without the wait, four transaction writers on one handle alternated between groups of one and three members, because the writer released first committed again while the other three were still in the next group; on Node under macOS that cost 4.4 ms per commit, and the wait brought it to 2.1 ms in full groups of four. A transaction that outlasts one wait is not waited for again, and a writer with no transaction in flight never waits. An earlier variant waited before setting the pinned head, so snapshots that started during its wait queued behind the lock it held; it measured slower and was dropped.
|
|
38
|
+
|
|
39
|
+
VERIFIED: A transaction checks the revisions of the keys it read, not the database revision. The commit lock makes the check and publication atomic, so every read is still current at the commit point and the transactions serialize in commit order. Absence is recorded as revision 0, so a key that appears is a conflict. Scans fall back to the database revision, because a range cannot be rechecked without listing what was absent. The whole-database check it replaced rejected disjoint writers: four writers on separate keys retried 1.5 to 2.1 times per commit.
|
|
40
|
+
|
|
35
41
|
## Native read and write performance
|
|
36
42
|
|
|
37
|
-
VERIFIED: Every database handle owns a connection with at most two idle read descriptors and
|
|
43
|
+
VERIFIED: Every database handle owns a connection with at most two idle read descriptors and at most eight idle lock descriptors, one per lock name: normally the commit lock, the I/O locks of the head and the current generation, and its pin. Reopening a lock file cost about 60 µs on macOS, three times per transaction. Only an unlocked descriptor is reused, so simultaneous owners still hold distinct open file descriptions and flock keeps them apart. In-flight reads retain their descriptors until completion. Local FIFO admission avoids polling for same-connection commit-lock contention; separate processes still acquire the same kernel lock. Every lock attempt uses the nonblocking call of the shipped N-API binding of pinned `@lickle/lock` 0.0.1. No blocking lock acquisition or timeout-based ownership is introduced.
|
|
38
44
|
|
|
39
|
-
VERIFIED: `get()` reads the current head under the commit lock on every call. It can overlap this with a lookup through the previously parsed root. That candidate is accepted only if every head byte is unchanged; otherwise it is discarded and the current root is read. Both branches are drained before releasing the lock, including on errors. A per-handle 8 KiB parse cache avoids repeated DSON decoding, not fresh I/O. Aligned comparisons use 32-bit words; measured manual unrolling was not retained because it regressed Node.
|
|
45
|
+
VERIFIED: `get()` reads the current head under the commit lock on every call. It can overlap this with a lookup through the previously parsed root. That candidate is accepted only if every head byte is unchanged; otherwise it is discarded and the current root is read. Both branches are drained before releasing the lock, including on errors. Native connections read that 8 KiB manifest with a blocking call even when values use asynchronous I/O: every operation reads it, it stays in the page cache, and a blocking read of it took 0.4 to 0.6 µs against 9 to 18 µs for a thread-pool round trip. A cold manifest blocks the event loop for one 8 KiB read. A per-handle 8 KiB parse cache avoids repeated DSON decoding, not fresh I/O; publication patches in the slot it wrote, so the writer's next read of its own head needs no decode. Aligned comparisons use 32-bit words; measured manual unrolling was not retained because it regressed Node.
|
|
40
46
|
|
|
41
47
|
VERIFIED: Known-length record references are checked against both committed end and the record budget before allocation. Native reads then fetch and checksum the complete frame. Values are decoded anew for every point lookup. Each native scan or compaction keeps one read-ahead window of at most 64 KiB within its pinned prefix. Large values bypass that window. The writer buffers at most 64 KiB, drains it before the file flush, and only then publishes the head, so buffering never reorders data ahead of publication.
|
|
42
48
|
|
|
43
|
-
VERIFIED: Native read descriptors do not participate in Storage's exclusive handle registry. This is limited to regular, read-only files and the DBSONL immutability protocol; mutations still use Storage and its I/O lock. `collect()` unlinks unpinned files and closes its connection's idle reader for each removed generation. Another idle process may still hold an unlinked descriptor until eviction or database close; OS disk-space release can therefore lag namespace removal. Closing all idle database handles releases those resources. Replacing live head or generation inodes outside this protocol is unsupported.
|
|
49
|
+
VERIFIED: Native read descriptors do not participate in Storage's exclusive handle registry. This is limited to regular, read-only files and the DBSONL immutability protocol; mutations still use Storage and its I/O lock. `collect()` unlinks unpinned files and closes its connection's idle reader and idle pin and I/O lock descriptors for each removed generation, so no descriptor of an unlinked lock file is reused. Another idle process may still hold an unlinked descriptor until eviction or database close; OS disk-space release can therefore lag namespace removal. Closing all idle database handles releases those resources. Replacing live head or generation inodes outside this protocol is unsupported.
|
|
44
50
|
|
|
45
51
|
## Reclamation and crashes
|
|
46
52
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
VERIFIED: Snapshots have `scanBatches({gte?, lt?, limit?, signal?, batchSize?, maxBatchBytes?, sizeOf?})`, which yields the rows of `scan` as arrays of at most 256 rows and 4 MiB by default, with one tracked pull per batch and one tree step per leaf. It is ported from the 0.4-based fork that defuss-dataview's DBSONL adapter used, with the option names and guarantees that adapter checks: a nonempty array per batch, at most `batchSize` rows and `sizeOf` applied once per row.
|
|
6
|
+
|
|
7
|
+
VERIFIED: Scans now read ahead 64 KiB on every backend, not only on backends with a positional `read`, so a memory or OPFS scan no longer opens, reads and closes the file once per row.
|
|
8
|
+
|
|
9
|
+
VERIFIED: defuss-dson is now 1.5.1, which writes the same frames as 1.3.0, reads each frame through one reader and converts frame offsets to int32 values, which Bun needs to decode at full speed when the offsets come from decoded index pages. `scanBatches` decodes the frames of a leaf that the read window already holds in one `decodeFrames` call; when a frame fails, it rereads that run frame by frame, so errors arrive at the same row as before.
|
|
10
|
+
|
|
11
|
+
VERIFIED: In three runs of the new `make bench-scan` over 100,000 documents, the row scan on memory storage took 0.61 of 0.5.0's time under Node and 0.63 under Bun; `scanBatches` took 0.46 and 0.52 on memory storage and 0.73 and 0.84 on native storage. Against the same source on defuss-dson 1.4.0, the version bump alone took 12% off `scanBatches` on Node memory storage and 8% on native storage, and `decodeFrames` another 6% on both; under Bun, 4% and 0%, then 5% on both. `vendor/defuss-dbsonl-0.5.0.tgz` is the published 0.5.0 package these runs compare against.
|
|
12
|
+
|
|
13
|
+
VERIFIED: `tests/batches.test.ts` covers batch scans on memory and native storage, and the packed-package and browser suites call `scanBatches` too. The on-disk format and lock protocol are unchanged.
|
|
14
|
+
|
|
15
|
+
## 0.5.1
|
|
16
|
+
|
|
17
|
+
VERIFIED: `package.json` names the project website, https://dbsonl.defuss.org, as its homepage, and links the GitHub repository and issue tracker. The README explains installing from npm: on 2026-11-16, `bun add defuss-dbsonl@0.5.0` and `npm install defuss-dbsonl@0.5.0` each installed five packages in an empty project with no install script, and the `/server` entry stored and read a value under Node.js and Bun on macOS arm64.
|
|
18
|
+
|
|
19
|
+
VERIFIED: The website describes 0.5.0: per-key transaction conflicts, commit groups, the second-chance page cache and the `make bench` figures of three runs on the 0.5.0 source. Against v0.3.0 in those runs no figure was slower in all three, and atomic batches took 1.6 times less time under Node.js and 2.4 times less under Bun. `docs/PERFORMANCE.md` has the tables; the 0.4.0 runs moved to `validation/bench-macos-arm64-0.4.0.json`.
|
|
20
|
+
|
|
21
|
+
VERIFIED: Below the hero, the website compares defuss-dbsonl with Redis 8.10.3 in the 16 pairings of `make bench-redis`. It shows the headline figures, four gauges that follow a runtime and storage switch, opening on Bun flushed to disk, and two dumbbell charts drawn with ECharts 6.1.0. The tables moved into that section. Under the DSON line, the hero has a second rotating line listing what defuss-dbsonl adds. `make e2e` checks that both charts draw, that the switches move the gauges, and that the page still does not scroll sideways at iPhone size.
|
|
22
|
+
|
|
23
|
+
VERIFIED: `tests/contracts.test.ts` adds eight tests for documented contracts no other test reached. Coverage rose from 91.33% to 93.86% of statements, 86.17% to 90.15% of branches, 96.39% to 97.29% of functions and 97.67% to 98.41% of lines. No production code changed.
|
|
24
|
+
|
|
25
|
+
## 0.5.0
|
|
26
|
+
|
|
27
|
+
VERIFIED: The website fits phones: code and tables scroll sideways instead of wrapping, tables tint every other row, cards put their icon beside the heading, and the install tabs stack. `make e2e` now also drives the website in WebKit at iPhone size, including the OPFS counter and the menu sheet, and fails if the page scrolls sideways.
|
|
28
|
+
|
|
29
|
+
VERIFIED: The OPFS demo replaces a worker that leaves a request unanswered for 5 s, retries a failed open on the next click and shows the browser error behind a failure. The demo was reported to stop on an iPhone after a delete; desktop WebKit and Chromium did not reproduce it, so the cause is still open.
|
|
30
|
+
|
|
31
|
+
VERIFIED: Commits got cheaper without changing the format or the lock protocol. A commit edits cached copies of the index pages on its paths instead of rereading and decoding them, and caches the pages it publishes. Publication patches the manifest parse cache, skips the directory sync (a commit creates no file), and truncates only when a failed commit left a tail. Native connections reuse one idle descriptor per lock name instead of reopening a lock file for every I/O lock and pin. In single-process probes on macOS arm64, a memory transaction fell from 0.31–0.38 ms to 0.14–0.15 ms and a durable Bun transaction from 1.16 ms to 0.50 ms; durable Node commits stay bound by their two flushes, which took about 3 ms each under Node on that host.
|
|
32
|
+
|
|
33
|
+
VERIFIED: Behavior change: a transaction now conflicts only when a key it read changed, appeared or disappeared after its snapshot, instead of on any concurrent commit. Writers on disjoint keys no longer retry; write skew and point-read phantoms are still rejected, and a transaction that scanned falls back to the whole-database check. With four contending writers, retries fell from 1.5 to 2.1 per commit to none.
|
|
34
|
+
|
|
35
|
+
VERIFIED: Commits queued on one handle publish as a group: one append, one generation flush and one head flush, with a revision and receipt per commit. A cancelled, conflicting or failing member is rejected alone. A transaction started while its handle's group holds the commit lock pins the last flushed head instead of waiting behind the group's flushes.
|
|
36
|
+
|
|
37
|
+
VERIFIED: A forming commit group waits, at most half the previous group's publication time, for transactions on its handle that already hold a snapshot. Four transaction writers on one handle had alternated between groups of one and three members; in full groups a contended durable Node commit fell from 4.4 to 2.1 ms on macOS arm64, and a contended memory commit from 65 to 59 µs under Node and from 72 to 63 µs under Bun. A transaction that outlasts one wait is not waited for again.
|
|
38
|
+
|
|
39
|
+
VERIFIED: defuss-dson is now 1.4.0, which writes the same frames as 1.3.0. In microbenchmarks of dbsonl's values, pages and manifests on macOS arm64 it encoded three to five times faster and decoded 2.5 to 6 times faster. Index pages and manifests use its `trusted` mode, which skips the per-property checks for plain data the engine built itself. On macOS arm64 a 24-entry leaf page encoded in 9 to 12 µs instead of 49 to 53 µs and decoded in 12 to 15 µs instead of 42 to 65 µs.
|
|
40
|
+
|
|
41
|
+
VERIFIED: Index pages are written by a page-specific DSON writer with the same bytes as `encodeFrame` in trusted mode (checked on 2000 generated pages per test run), about 30% faster per page, and the page cache evicts by second chance instead of reordering on every hit. Together they took a contended memory commit from 59 to 49 µs under Node and from 63 to 56 µs under Bun in single-process probes.
|
|
42
|
+
|
|
43
|
+
VERIFIED: Index edits and buffered appends run synchronously unless they need I/O, and native connections read the 8 KiB manifest with a blocking call; a cold manifest blocks the event loop for one 8 KiB read. A durable point read fell from 45 to 27 µs under Node and to about 33 µs under Bun in single-process probes.
|
|
44
|
+
|
|
45
|
+
VERIFIED: In `make bench-redis` on macOS arm64, defuss-dbsonl now takes less time than Redis in 12 of 16 pairings, against 4 for 0.4.0. The single durable Node writes still lose, because each commit flushes twice and a flush took about 3 ms under Node there, and so do the 1000-write batches in memory, where encoding each value as its own DSON frame costs more than Redis's `JSON.stringify`. `docs/PERFORMANCE.md` has the table.
|
|
46
|
+
|
|
47
|
+
VERIFIED: defuss-storage is now 0.3.1.
|
|
48
|
+
|
|
49
|
+
VERIFIED: `make bench-redis` compares the current build with a throwaway loopback Redis pinned in `mise.toml`: point reads, 1000-write batches, `WATCH`/`MULTI`/`EXEC` transactions against `transaction()`, and four contending writers. Each engine's turn starts after a full garbage collection, because otherwise one engine's garbage was collected inside the other's timed work. `docs/PERFORMANCE.md` has the results.
|
|
50
|
+
|
|
3
51
|
## 0.4.0
|
|
4
52
|
|
|
5
53
|
Breaking changes:
|
|
@@ -9,6 +57,10 @@ Breaking changes:
|
|
|
9
57
|
|
|
10
58
|
VERIFIED: Format 2 and the lock protocol are unchanged; the packed-package suite runs 0.2.0 and 0.4.0 writers concurrently against one database. `openDbsonl(..., { create: true })` completes an interrupted create: an empty head file whose generation files are all empty. Any persisted byte still fails closed with `CORRUPT`. Writer index-page loads use one known-length read. Browser tests cover directory-handle Storage through the format-2 API.
|
|
11
59
|
|
|
60
|
+
VERIFIED: Added a project website in `docs/index.html` whose demos run the library in the visitor's tab: a snapshot during transfers, a transaction conflict, a DSON round trip and an OPFS counter that survives reloads. `make e2e` drives every demo against the installed tarball. The npm package ships only the Markdown pages from `docs/`.
|
|
61
|
+
|
|
62
|
+
VERIFIED: `make bench` measures the vendored v0.2.0 and v0.3.0 builds beside the current build in one session. In three macOS arm64 runs, Bun ran some 0.4.0 read workloads slower than 0.3.0: snapshot reads and scans on memory storage by 20% to 26%, and scans on native storage by 12% to 34%. Node showed no consistent difference. `docs/PERFORMANCE.md` has the tables.
|
|
63
|
+
|
|
12
64
|
## 0.3.0
|
|
13
65
|
|
|
14
66
|
VERIFIED: Preserved format 2, all public operations, portable backends and legacy exports. Added per-database native descriptor ownership, local FIFO commit admission, nonblocking native lock attempts, concurrent positional reads and pipelined fresh-head/value reads. Metadata parsing is cached only while freshly read bytes match. Point values remain uncached and detached.
|
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
# defuss-dbsonl 0.
|
|
1
|
+
# defuss-dbsonl 0.6.0
|
|
2
2
|
|
|
3
|
-
Transactional key-value storage for Node.js, Bun and browser workers. Values are DSON, so dates, binary views, bigint, `undefined` and cyclic references survive storage. It is built on
|
|
3
|
+
Transactional key-value storage for Node.js, Bun and browser workers. Values are DSON, so dates, binary views, bigint, `undefined` and cyclic references survive storage. It is built on [defuss-dson](https://dson.defuss.org) 1.5.1 and [defuss-storage](https://storage.defuss.org) 0.3.1 and ships TypeScript declarations with ESM and CommonJS builds. It is designed as the backing store and API of [defuss-dataview](https://dataview.defuss.org), which adds filters, sorting and paging for table and tree grids. Project website: [dbsonl.defuss.org](https://dbsonl.defuss.org).
|
|
4
4
|
|
|
5
5
|
VERIFIED: A database is a persistent copy-on-write B+tree with immutable snapshots, atomic batches, optimistic serializable transactions, compaction and process-safe coordination. Opening reads two small manifest slots instead of replaying a log, and readers never block writers.
|
|
6
6
|
|
|
7
|
-
## Install
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
bun add defuss-dbsonl
|
|
11
|
+
# or
|
|
12
|
+
npm install defuss-dbsonl
|
|
12
13
|
```
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
The package is on the npm registry. It needs Node.js 20.19 or newer, Bun, or a dedicated browser worker with OPFS and Web Locks. `defuss-dson` and `defuss-storage` install with it.
|
|
16
|
+
|
|
17
|
+
VERIFIED: The native lock addon, `@lickle/lock`, ships prebuilt binaries as optional dependencies for Linux x64 glibc, macOS x64 and arm64, and Windows x64, so nothing compiles during installation. On 2026-11-16, `bun add defuss-dbsonl@0.5.0` and `npm install defuss-dbsonl@0.5.0` in empty projects each installed five packages, none of which declares an install script, and the `/server` entry stored and read a value under both Node.js and Bun on macOS arm64.
|
|
18
|
+
|
|
19
|
+
To install a local build instead, `make release` writes the tarball to `validation/`; add it with `bun add ./validation/defuss-dbsonl-<version>.tgz`.
|
|
20
|
+
|
|
21
|
+
## Use
|
|
15
22
|
|
|
16
23
|
```ts
|
|
17
24
|
import { openDbsonl } from 'defuss-dbsonl';
|
|
@@ -41,7 +48,9 @@ try {
|
|
|
41
48
|
}
|
|
42
49
|
```
|
|
43
50
|
|
|
44
|
-
The transaction callback runs once. A concurrent commit makes it fail with `CONFLICT` instead of retrying, because a retry would repeat any side effects in your callback. Retry explicitly where that is safe.
|
|
51
|
+
The transaction callback runs once. A concurrent commit that changed a key the callback read makes it fail with `CONFLICT` instead of retrying, because a retry would repeat any side effects in your callback; after a scan, any concurrent commit does. Retry explicitly where that is safe. Concurrent batches and transactions on one handle publish together: one write and one pair of flushes for the queued group, while each keeps its own revision and receipt. `ifRevision` gives compare-and-swap for changes prepared outside a transaction.
|
|
52
|
+
|
|
53
|
+
For bulk reads, a snapshot's `scanBatches()` yields the same rows as `scan()` in arrays of up to 256. It tracks one pull per batch instead of one per row, so a full scan takes less time; [API](docs/API.md) has its byte budget and options.
|
|
45
54
|
|
|
46
55
|
Memory storage needs no platform entry:
|
|
47
56
|
|
|
@@ -80,11 +89,11 @@ Each row names the obvious alternative, the reason it was not taken and the cost
|
|
|
80
89
|
|
|
81
90
|
| Concern | Plausible alternative | Chosen | Why | Cost |
|
|
82
91
|
| --- | --- | --- | --- | --- |
|
|
83
|
-
| Finding keys | In-memory key map rebuilt by replaying a log | Persistent B+tree, fanout 32, bounded
|
|
92
|
+
| Finding keys | In-memory key map rebuilt by replaying a log | Persistent B+tree, fanout 32, bounded page cache | Memory does not grow with key count and open needs no replay | Uncached point reads perform disk I/O |
|
|
84
93
|
| Readers versus writers | Read locks that block commits | Immutable roots and shared generation pins | A slow reader cannot stall writers | Old generations stay on disk until readers close |
|
|
85
94
|
| Atomic publication | Write a new file, then rename it | Two checksummed head slots, written alternately | OPFS and Storage expose no uniform atomic rename | Every commit writes one 4 KiB slot |
|
|
86
|
-
| Multiple writers | One owning process | OS whole-file locks or Web Locks, held per commit | Independent processes and workers can share one database | Commits still serialize to keep one revision order |
|
|
87
|
-
| Transactions |
|
|
95
|
+
| Multiple writers | One owning process | OS whole-file locks or Web Locks, held per commit group | Independent processes and workers can share one database | Commits still serialize to keep one revision order |
|
|
96
|
+
| Transactions | One revision check for the whole database | Each point read rechecked at commit; the whole-database check after a scan | Writers on disjoint keys commit without retrying, and write skew and phantoms are still ruled out | A transaction keeps the revision of every key it read, up to `maxTransactionOperations` keys, then falls back to the whole-database check |
|
|
88
97
|
| Space reuse | In-place updates or a background vacuum | Explicit `compact()` and `collect()` | No hidden I/O; the application chooses when to pay | Compaction needs disk space for one live copy |
|
|
89
98
|
| Stale locks | Lock files that expire after a timeout | Kernel locks released on process death | A paused process never loses ownership to a second writer | Requires the native addon on servers |
|
|
90
99
|
|
|
@@ -92,34 +101,38 @@ VERIFIED: `compact()` lets writers continue while it copies and returns `CONFLIC
|
|
|
92
101
|
|
|
93
102
|
## Guarantees and boundaries
|
|
94
103
|
|
|
95
|
-
VERIFIED: A published root makes a whole batch visible at once. Values and index pages are flushed before a head slot is written
|
|
104
|
+
VERIFIED: A published root makes a whole batch visible at once. Values and index pages are flushed before a head slot is written. Native factories also sync the directory after creating or removing a file, before any head refers to it; a commit only appends to and overwrites existing files. Two checksummed slots survive an interrupted write of either one. A writer reuses any unpublished tail left by a failed commit. Published corruption fails validation; nothing repairs data automatically, because a guessed repair can turn damage into silent data loss.
|
|
96
105
|
|
|
97
106
|
VERIFIED: Native locking uses `@lickle/lock` 0.0.1, which takes whole-file `flock`/`LockFileEx` locks through a Node-API addon. Version 0.3.0 was tested on Linux x64; on 2026-11-14 the full suite, including process termination and the packed-package run, also passed on macOS arm64. Both used Node 24.22.1 and Bun 1.4.3. Chromium workers were tested with real OPFS, directory handles and Web Locks. Memory backends coordinate only clients that share one backend object.
|
|
98
107
|
|
|
99
|
-
VERIFIED: No test run has exercised power cuts, network filesystems, Windows
|
|
108
|
+
VERIFIED: No test run has exercised power cuts, network filesystems, Windows or Firefox, so their behavior is unknown. WebKit has run only the website demos, including the OPFS counter, in Playwright's WebKit build at iPhone size; the browser test suite runs in Chromium. The addon ships binaries for Linux x64 glibc, macOS x64/arm64 and Windows x64. The native factory refuses to start where directory sync is unsupported, rather than silently promising less durability. OPFS has no directory-sync API and reports `durability: 'file'`; memory reports `'memory'`. There is no distributed consensus, encryption or protection against hostile writers.
|
|
100
109
|
|
|
101
110
|
Resource budgets cap retained engine work. The page cache is bounded by encoded bytes and page count, independent of key count. Decoded values, active traversal paths, caller-held values, snapshots and the memory adapter's stored bytes are outside that budget. [API](docs/API.md) lists the defaults and error codes.
|
|
102
111
|
|
|
103
112
|
## Compatibility
|
|
104
113
|
|
|
105
|
-
VERIFIED: Versions 0.2 through 0.
|
|
114
|
+
VERIFIED: Versions 0.2 through 0.6 share the on-disk format and the lock protocol. The packed-package suite runs 0.2.0 and the current build concurrently on Node and Bun against one database, so upgrading needs no migration.
|
|
106
115
|
|
|
107
116
|
Version 0.4.0 renamed the native entry from `defuss-dbsonl/node` to `defuss-dbsonl/server` and removed the `/legacy` and `/records` subpaths. Data in the v0.1 log format must be migrated with defuss-dbsonl 0.3.x first; that release ships `defuss-dbsonl/legacy` and `examples/migrate.ts`. See [CHANGELOG.md](CHANGELOG.md).
|
|
108
117
|
|
|
109
118
|
## Develop and verify
|
|
110
119
|
|
|
111
120
|
```sh
|
|
112
|
-
make setup # pinned Node/Bun via mise, dependencies, Chromium, VAE runtime
|
|
121
|
+
make setup # pinned Node/Bun/Redis via mise, dependencies, Chromium, WebKit, VAE runtime
|
|
113
122
|
make verify # lint, tests, coverage, packed-package e2e
|
|
114
123
|
make bench # matched v0.2 versus current benchmarks
|
|
124
|
+
make bench-scan # full scans, row by row and in batches, against the vendored 0.5.0
|
|
125
|
+
make bench-redis # current build versus a throwaway loopback Redis, run as mise exec -- make bench-redis
|
|
126
|
+
make dev # rebuild the website demos and serve docs/ on 127.0.0.1:3000
|
|
115
127
|
make vae # verification, review and documentation gate
|
|
116
128
|
make release # tarball, source ZIP and checksums; never publishes or commits
|
|
117
129
|
```
|
|
118
130
|
|
|
119
|
-
VERIFIED: `make verify` runs strict type checks, lint, real-storage tests, coverage thresholds and a packed-package suite on Node, Bun and Chromium. That suite runs mixed Node/Bun processes on both 0.2.0 and the current build, kills writers mid-batch and runs concurrent browser workers. `make release` packages only after the pinned defuss-vae 0.9.0 gate passes for the current source fingerprint. `make` lists every target; `.env.example` documents the browser executable overrides.
|
|
131
|
+
VERIFIED: `make verify` runs strict type checks, lint, real-storage tests, coverage thresholds and a packed-package suite on Node, Bun and Chromium, plus the website in WebKit at iPhone size. That suite runs mixed Node/Bun processes on both 0.2.0 and the current build, kills writers mid-batch and runs concurrent browser workers. `make release` packages only after the pinned defuss-vae 0.9.0 gate passes for the current source fingerprint. `make` lists every target; `.env.example` documents the browser executable overrides.
|
|
120
132
|
|
|
121
133
|
| Page | Answers |
|
|
122
134
|
| --- | --- |
|
|
135
|
+
| [docs/index.html](docs/index.html) | The project website, with demos that run the library in the visitor's tab; `make site` rebuilds its bundles |
|
|
123
136
|
| [ARCH.md](ARCH.md) | Why the protocol is built this way: lock order, crashes, reclamation, security |
|
|
124
137
|
| [docs/API.md](docs/API.md) | Every operation, option default, budget and error code |
|
|
125
138
|
| [docs/FORMAT.md](docs/FORMAT.md) | Files on disk, slot layout and publication order |
|