@kedem/okdb 3.2.1 → 3.3.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/CHANGELOG.md CHANGED
@@ -4,6 +4,48 @@ All notable changes to `@kedem/okdb` are documented here. Format loosely follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.0.0/); versions follow [SemVer](https://semver.org/).
5
5
  Dates are release dates.
6
6
 
7
+ ## [3.3.0] - 2026-11-26
8
+
9
+ ### Changed
10
+
11
+ - **Compaction is online and in place.** `compact()` and automatic compaction no longer copy the env into a new file and swap
12
+ it in. Data moves from the end of `data.mdb` into free space near the front, in short steps between ordinary writes, and the
13
+ free end of the file is cut off. No freeze, no drain, no `ENV_DRAINING`, no peer reopening the file, and **no extra disk
14
+ space** (the copy needed about 1.2× the live data free). The full-text index files and the embeddings vector envs
15
+ (`~<env>:emb:<type>`) are reclaimed the same way; a loaded `graph` search view lets go of its snapshot during a reclaim.
16
+ Ordinary writes keep LMDB's normal page allocation; only while a reclaim runs do they prefer free pages near the front
17
+ (from the free list already in memory, at no extra cost).
18
+ A reclaim ends when nothing more can be moved or cut right now (space still held by a long-running reader, for example):
19
+ a later run cuts the rest.
20
+ Automatic steps move up to `autoCompact.reclaimBudget` pages (default 500) every `autoCompact.reclaimIntervalMs` (default
21
+ 100 ms); an explicit `compact()` runs back to back. One process reclaims an env at a time (the compaction lease).
22
+ On NVMe, 200k documents with 70% deleted: 419 → 172 MB, about 5 ms per automatic step.
23
+ - **Automatic compaction starts earlier:** at 20% free space (`autoCompact.wastedRatioThreshold`, was 50%) and from 10 MB
24
+ (`autoCompact.minFileBytes`, was 100 MB), since a reclaim costs little. It shrinks the file to the live data plus 10%,
25
+ room for ordinary writes without growing the file again. The Storage card's "reclaimable" warning uses the same threshold.
26
+ - **The copy is still there:** `compact({ rebuild: true })` (a fully re-sorted file, including the full-text index's own
27
+ copy), or `autoCompact.mode: 'copy'` for the old automatic behaviour. `repair()` is unchanged.
28
+ - **`compact()` results** carry `reason: 'reclaim'` for an online reclaim. A `compact()` during an automatic reclaim takes it
29
+ over instead of failing with `REBUILD_IN_PROGRESS`; one while another process reclaims returns `skipped`.
30
+ - **Admin:** the env Storage card shows "reclaiming online" while any process of the store reclaims the env, the newest
31
+ outcome ("reclaimed online · 130 MB → 45.9 MB"), and a **Compact now** button; it refreshes itself while a reclaim runs.
32
+ System → Data Ops → Compact offers _Compact (online)_, _Rebuild (copy)_ and _Logical rebuild (repair)_.
33
+ `GET /api/system/storage` adds `reclaiming`, `compactMode` and `lastReclaim` per env; `POST /api/env/:env/compact` accepts
34
+ `rebuild: true`.
35
+ - **Windows:** a mapped file cannot shrink, so there the last process to close an env cuts the file (data has already moved
36
+ to the front). Other platforms cut while running.
37
+
38
+ ### Fixed
39
+
40
+ - **"Reclaimable" counted space a compaction cannot give back.** The live size walked each sub-DB's tree pages and missed the
41
+ sub-trees of indexes with many values per key, so "file − live" overstated free space (a real brain store showed 27%
42
+ reclaimable with 9% free) and the automatic compaction could fire again and again for nothing. Live is now the pages in
43
+ use minus the free list: `liveBytes` / `reclaimablePct` (Storage card, `storageStats`) and the automatic trigger agree with
44
+ what a reclaim frees.
45
+ - **`autoCompact: false` did not turn automatic compaction off** (since the 3.0 native core): only `{ enabled: false }` was read.
46
+ Both forms work now; the types accept `false`. Found by the mixed-version test, where an automatic reclaim held the
47
+ compaction lease.
48
+
7
49
  ## [3.2.1] - 2026-11-25
8
50
 
9
51
  ### Fixed