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

docs: the migration's anonymous peak is the 5-second snapshot, not compaction

Upstream measured it by phase, and it inverts how we had been planning the
window. The seal snapshot takes anon from ~375 MB to 774 MB in five seconds,
because it serialises the whole in-memory store into one buffer, compresses
into a second, then verifies by reading back and fully decompressing. So the
peak is roughly working set plus one serialised copy of the store.

Compaction never raised anonymous memory at all, even on a 626 MB env - it
streams the mmapped env with small buffers, so its cost is reclaimable page
cache. Two consequences: a large env does not threaten memory, so dropping a
big collection would not have helped and it is as well that nobody did; and
the thing that can kill the boot is identical work on every attempt, so under
a cap it cannot fit it loops at the same point rather than retrying into
success. Progress is not persisted per project.

Our own 1092 MiB was a CGROUP peak and therefore included page cache. Only
the anonymous part has to fit, so quoting it as the requirement overstates
it - the same measure-the-wrong-quantity error as reading VmHWM while
forgetting the LMDB mmap is file-backed. Both appear in this file now, which
suggests the lesson is "name the quantity, not just the number".

And the safest pre-flight number is the running server's own hourly snapshot:
same store, same code, same config, happening today and surviving. A number
from the thing itself beats any number from a container.
fszontagh 1 месяц назад
Родитель
Сommit
bcbbad35ec
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      CLAUDE.md

+ 11 - 0
CLAUDE.md

@@ -162,6 +162,17 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Debian 13 (trixie) gRPC cmake config is broken** unless `protobuf-compiler-grpc` + `libgrpc++-dev` + `libprotobuf-dev` are installed - `find_package(gRPC CONFIG)` (used transitively by `smartbotic-db-clientConfig.cmake`) fails on a `gRPCTargets.cmake` referencing missing plugin files. The Docker base installs them.
 - **THE 2.17.x MIGRATION'S MEMORY PEAK SCALES WITH THE DATASET, AND IT OOM-KILLS. Measure it against the box you are deploying to, on the data you are deploying over.** Measured on 2.17.2 with the PUBLISHED debs in a Debian 13 container (not an upstream image - prod installs the deb), prod's own config, over a copy of prod's data directory: **204 s, cgroup `memory.peak` 1092 MiB, process `VmHWM` 1212 MiB**, ending `CLEAN` / `sealed: yes`. Under a **900 MiB cap it was OOM-KILLED** during compaction. Prod is **1973 MB with NO SWAP**, and the running database holds ~757 MB RSS which is freed when it restarts, so the margin is real but not generous.
   **The same run on 2.17.1 OOM-kills identically, so this is NOT a version regression - it is the DATA.** Friday's copy held 24733 rows and peaked at 364 MiB anonymous; today's held 33321 rows, 35% more, and peaks near 1.1 GB. **A migration memory figure is therefore a measurement of one corpus on one day, exactly like a search baseline**, and the earlier comfortable number would have been carried straight into a window had the second run not been made. An OOM is RECOVERABLE - the migration re-runs at the next boot and skips completed work - so the failure mode is a longer outage rather than lost credentials, which is worth telling consumers when asking for the window.
+- **THE MIGRATION'S ANONYMOUS PEAK IS THE 5-SECOND SEAL SNAPSHOT, NOT THE MINUTES OF COMPACTION - so size the box against the STORE, not against the biggest env.** Measured upstream by phase, sampling `memory.stat` every second against the log (22.5k docs, a 626 MB and a 262 MB env):
+
+  | phase | anon max | page cache max |
+  |---|---|---|
+  | boot + row pass | 456 MB (load spike, then ~375) | 218 MB |
+  | **seal snapshot (5 s)** | **774 MB** | 259 MB |
+  | compaction (3m10s) | 373 MB, FLAT | 263 MB |
+
+  The snapshot serialises the whole in-memory store into one buffer, compresses into a second, writes, then verifies by reading back and fully decompressing - so the peak is roughly **working set + one serialised copy of the store**, about +400 MB there. **Compaction never raised anonymous memory at all**, even on a 626 MB env, because `mdb_env_copy2` streams the mmapped env with small buffers; its cost is reclaimable page cache. Two consequences that inverted our planning: a large ENV does not threaten memory (so dropping a big collection would not have helped), and the thing that CAN kill the boot is identical work on every attempt, so under a cap it cannot fit it **loops at the same point** rather than retrying into eventual success. Progress is not persisted per project either.
+  **Our own 1092 MiB figure was a cgroup peak and therefore INCLUDED page cache; only the anonymous part has to fit.** Quoting it as the memory requirement overstates it - the same measure-the-wrong-quantity error as reading `VmHWM` and forgetting the LMDB mmap is file-backed.
+  **The safest pre-flight number is the running server's own periodic snapshot.** `snapshot_interval_sec` is 3600 on prod, so it performs this exact serialise-compress-verify hourly and survives it; sampling its RSS across one ("Created snapshot at sequence ...") gives the peak the first boot has to reproduce, on the same store, same code and same config. A number from the thing itself beats any number from a container.
 - **A SECOND RESTART IS NOT NEEDED ON 2.17.2, measured rather than reasoned.** Our `KeyStore`/`SettingsStore` bootstraps DO perform the online upgrade after the migration, and the log says so - but with **0 rows and 0 history versions rewritten**, because the collections are already ciphertext through the bare-alias merge. `encryption-verify` then reports `sealed: yes`, `CLEAN`, exit 0. So the window is TWO steps and ONE compaction (upgrade, then start vectorapi), with verify as the branch: plain `CLEAN` means done, `CLEAN (UNSEALED: ...)` means take the reseal inside the window. On 2.17.1 that same flag move requested a reseal that compacted every project, which is where the obsolete three-step plan came from.
   Note the upstream log line still says "old plaintext copies are removed at the next restart" even when it rewrote NOTHING, which contradicts verify's `sealed: yes` and would have an operator restart for no reason. Trust verify.
 - **MOVING THE CLIENT PACKAGE UNDER AN EXISTING BINARY IS AN ABI QUESTION, AND IT IS CHEAP TO TEST.** Every 2.x client shares one SONAME, so apt will happily put a 2.17.2 `libsmartbotic-db-client.so.2` under a server binary compiled against 2.14.0 headers - and the documented failure mode is that it installs fine and segfaults later. Verified before deploying rather than hoped: a Debian 13 container holding the real `smartbotic-vectorapi 0.12.0-1` deb plus `libsmartbotic-db-client 2.17.2-1`, against a 2.17.2 server, answered **21 of 21 calls** correctly - including `POST /indexes` with `unique`, which exercises `CreateIndexResult`, the by-value struct whose SIZE is the thing that would break, and a 409 duplicate refusal, which proves `duplicateExamples` crossed the boundary intact. `/api/v1/version` reported `db_client: 2.17.2` so the new library really was loaded. Repeat this whenever `DB_CLIENT_VERSION` and the deployed client diverge; it takes minutes and the alternative is a restart days later.