Просмотр исходного кода

docs: the 1.9 GB of history is explained - WAL replay records history and ignores versioning OFF

Their prediction, confirmed to the second: a boot at 10-20 18:05:57 replayed
14998 WAL entries at 18:06:10, and both history files carry an mtime of
18:06:10.932872466 - the same nanosecond, one write pass. The boot existed only
because the preceding shutdown was SIGKILLed after a ten-minute hang while
writing a snapshot, so a stop that cannot finish manufactures the WAL that the
replay bug duplicates into history.

The same window also shows the snapshot-completeness warning firing on prod
with counts, and blaming a pre-v1.7.3 snapshot rather than the WAL rotation -
a warning that fires correctly and misdirects.
fszontagh 1 месяц назад
Родитель
Сommit
b96f09bf8d
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      CLAUDE.md

+ 6 - 0
CLAUDE.md

@@ -585,6 +585,12 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **The tell worth handing upstream: BOTH files were last written at the identical minute, 2026-10-20 18:06, and nothing has touched them since.** Two collections with history disabled growing ~60x between 10-15 and 10-20 and then stopping together points at one event rather than at ordinary writes - and the 10-17 to 10-19 crash loop replayed 69,616 WAL entries on each of roughly 120 boots. **If WAL replay records history, a crash loop silently inflates history on collections that have history switched off**, which would explain the size, the timing and the simultaneity. That is a hypothesis about their internals with one measurement behind it, so it goes to them as a question rather than into a changelog.
   **And my first attempt to measure it reported the YEAR as a document count.** `smartbotic-db-cli count <coll> | grep -oE '[0-9]+' | head -1` picked `2026` out of the CLI's own timestamped log line, so both collections came back as "2026 docs" and a post-prune check read "queue doc count unchanged: 2026" - a check that could not fail. The tell was two unrelated collections reporting the identical number. Parse the LABELLED field (`documents: 43370`), never the first integer in the output.
 
+- **THE 1.9 GB OF HISTORY IS EXPLAINED, AND THE EXPLANATION ARRIVED AS A FALSIFIABLE PREDICTION THAT THE JOURNAL CONFIRMED TO THE SECOND. WAL REPLAY RECORDS HISTORY AND IGNORES `versioning: OFF`.** The database owner read their own replay path rather than guessing, after first refuting my hypothesis on timing - I had blamed the 10-17 to 10-19 crash loop, and 10-20 18:06 is a day after it ended. Their three findings: replay applies UPDATE/UPSERT and DELETE through paths that call `saveToHistory`, and since history is written BEFORE the WAL entry, every replayed write re-appends a pure duplicate; recovery runs before the collection configs are loaded, so during replay `configFor()` returns the default and a versioning-OFF collection gets history anyway; and the cap is never enforced on append, which is why `--max-versions 1` at max 1 prunes nothing.
+  **The prediction they handed me was "a service start at or just before 10-20 18:06 with a large replay", and it is the shape to copy - a claim that names what would refute it.** Measured: `Starting recovery` at 18:05:57, `Replayed 14998 WAL entries from sequence 514598` at **18:06:10**, READY at 18:06:24 - and both history files carry an mtime of **2026-10-20 18:06:10.932872466**, the same nanosecond on both, at the second the replay finished. One boot, one write pass, the whole 1.86 GB. It is the only boot in the retained journal between the crash loop and the 10-22 windows.
+  **AND THE BOOT ONLY HAPPENED BECAUSE THE PRECEDING SHUTDOWN WAS SIGKILLED, WHICH MAKES THE TWO ONE INCIDENT: A STOP THAT CANNOT FINISH MANUFACTURES THE WAL THAT THE REPLAY BUG THEN DUPLICATES INTO HISTORY.** `Stopping` at 17:55:52, `State 'stop-sigterm' timed out. Killing.` at 18:05:56, SIGKILL to five processes - a ten-minute hang, while writing a snapshot (its warnings land at 17:56:11 and 17:57:43), so 14998 entries were left for the next boot. That was 2.17.2 with the old non-streaming writer on a 685 MB store; both of tonight's stops on 2.20.x completed in 18 s and 38 s, so the streaming writer should make it rare. Fixed upstream in 2.21.1: no history writes during replay, and the cap enforced from the snapshot loop when a capped file has grown (at least 16 MB and twice its size at the last prune), whose first snapshot prunes every capped file once - which is what will reclaim the 1.9 GB.
+  **THE SAME WINDOW ALSO SHOWS THE SNAPSHOT-COMPLETENESS BUG LOGGING ITSELF, AT WARNING, WITH COUNTS - AND POINTING AT THE WRONG CAUSE.** `Snapshot: 9 evicted documents in collection 'justice-pa:vectorapi_secrets' could not be loaded from WAL - they will be missing from the snapshot. Likely a pre-v1.7.3 snapshot already lost them.` and the same for 64 in `justice-pa:calls`. The consequence clause is exactly right and the trailing hint is false - it was the WAL rotation, not an ancient snapshot - so anyone who met that line would have filed it as history and stopped looking. **A warning that fires correctly and misdirects is worse than one nobody reads**, and this is the single message that could have surfaced the whole backup gap a year earlier. Raised with them for rewording.
+  Scale worth carrying into the 2.21.0 adopt step: that boot's memory check reads `52584 docs, 33000 evicted`. Eviction on prod is not marginal, which is why 7219 rows ended up stranded.
+
 ## Deploy / publish
 
 **`VERSION` and `api/openapi.json`'s `info.version` must agree, and `packaging/build.sh` now refuses to build unless they do** (`scripts/check-version-sync.sh`, run at the top level so it covers the local, Docker and publish paths alike). They drifted once: 0.10.0 was published with the docs claiming 0.9.2, and since `openapi.json` ships in the server package and is served at `/openapi.json`, the stale value was live. **Correcting it cost a whole release**, because a published version number is never reused for different content - which is why 0.10.0 exists but must never be deployed. A release step that relies on remembering is a release step that gets skipped, so it is a check rather than a checklist line.