|
@@ -240,8 +240,13 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
|
|
|
**IT IS A DISK AND GROWTH PROBLEM ONLY. I claimed history bytes dominate the at-rest encryption migration, and measured on prod's own data they do not matter to it at all.** That claim was inherited from the database team's sizing model and amplified by me, and one measurement would have settled it before I asked them for a boot mode and asked a consumer to weigh an escape hatch. Measured with 2.17.1 on a copy of prod's data directory (1.6 GB, 24753 docs, 65 collections, prod's own config, 900 MB cap): **190 seconds total**, of which the ENCRYPTION pass was **13 seconds** (24733 rows scanned, 19 encrypted, 26 history versions) and **compaction was 176 seconds, 167 of them novitax's single 339 MB env**. The seal was under a second.
|
|
**IT IS A DISK AND GROWTH PROBLEM ONLY. I claimed history bytes dominate the at-rest encryption migration, and measured on prod's own data they do not matter to it at all.** That claim was inherited from the database team's sizing model and amplified by me, and one measurement would have settled it before I asked them for a boot mode and asked a consumer to weigh an escape hatch. Measured with 2.17.1 on a copy of prod's data directory (1.6 GB, 24753 docs, 65 collections, prod's own config, 900 MB cap): **190 seconds total**, of which the ENCRYPTION pass was **13 seconds** (24733 rows scanned, 19 encrypted, 26 history versions) and **compaction was 176 seconds, 167 of them novitax's single 339 MB env**. The seal was under a second.
|
|
|
**The structural reason, which is what makes it general rather than a quirk of this dataset: the migration only rewrites history belonging to ENCRYPTED collections.** Our 114 MB `vectorapi_functions.hlog` and the consumer's 47 MB `kb_chunks.hlog` sit on `encrypted=false` collections, so they are scanned and left alone - `encryption-verify` reports `novitax:kb_chunks` with `history 18648, plaintext-required 0`. So the migration's cost tracks **the largest project's `data.mdb`, through compaction**, and almost nothing else. An operator with a huge history and a small env would read the old model and expect the opposite of what happens.
|
|
**The structural reason, which is what makes it general rather than a quirk of this dataset: the migration only rewrites history belonging to ENCRYPTED collections.** Our 114 MB `vectorapi_functions.hlog` and the consumer's 47 MB `kb_chunks.hlog` sit on `encrypted=false` collections, so they are scanned and left alone - `encryption-verify` reports `novitax:kb_chunks` with `history 18648, plaintext-required 0`. So the migration's cost tracks **the largest project's `data.mdb`, through compaction**, and almost nothing else. An operator with a huge history and a small env would read the old model and expect the opposite of what happens.
|
|
|
**Memory: plan with ANONYMOUS memory, not RSS, and expect RSS to look alarming.** Same run: `anon` 364 MiB, page cache 295 MiB, cgroup `memory.peak` pinned at the 900 MiB cap, and the process's `VmHWM` **1122 MiB - above the cgroup limit** - with `oom_kill 0`. That is not a contradiction: the LMDB mmap is file-backed, so resident mapped pages count toward the process high-water mark while the cgroup treats them as reclaimable cache and evicts rather than killing. "It needed 1.1 GB" and "it needed 364 MB" are both readable off one run and only the second is the planning number. Anyone watching RSS cross 1 GB on a 2 GB box mid-credential-migration will reach for the kill switch; the page-cache explanation is not something they will derive at that moment.
|
|
**Memory: plan with ANONYMOUS memory, not RSS, and expect RSS to look alarming.** Same run: `anon` 364 MiB, page cache 295 MiB, cgroup `memory.peak` pinned at the 900 MiB cap, and the process's `VmHWM` **1122 MiB - above the cgroup limit** - with `oom_kill 0`. That is not a contradiction: the LMDB mmap is file-backed, so resident mapped pages count toward the process high-water mark while the cgroup treats them as reclaimable cache and evicts rather than killing. "It needed 1.1 GB" and "it needed 364 MB" are both readable off one run and only the second is the planning number. Anyone watching RSS cross 1 GB on a 2 GB box mid-credential-migration will reach for the kill switch; the page-cache explanation is not something they will derive at that moment.
|
|
|
- **PRUNING IS NOT BACKGROUND HYGIENE. It takes a GLOBAL lock.** From database 2.17.1, `createCollection(existing, maxVersions = N)` with a lower N rewrites that collection's history keeping the newest N per document - but it runs synchronously while holding the store's global collection lock exclusively AND the global history-append lock, so essentially every operation that resolves a collection waits, **in every collection**, for its whole duration. Expect seconds to tens of seconds on a 100 MB file (unmeasured). So: never loop it under live traffic, give it a quiet moment or put it inside a window, and prune the big one alone. Moving it out of that lock is an upstream follow-up and is NOT in 2.17.1.
|
|
|
|
|
- **And it cannot be done BEFORE the encryption migration.** There is no mode that boots 2.17.1 without migrating - it runs before the listener opens - so "prune first to shorten the migration" is unreachable. Just as well: the prune path has no test against an unmigrated store (its test runs on a fresh 2.17.1 store and asserts only counts, not that surviving versions decrypt), so the escape hatch would have exercised new code against old on-disk format in a configuration nobody upgrades into. **The consumer who would have gained most from it was the one who decomposed the question correctly - "can it be deferred" is the easy half, "is the prune path safe against an unmigrated store" is the half that bites - and said they would rather have the long window.** Worth remembering as a pattern: when an optimisation needs a state that only the optimisation produces, the question is never whether you can get into that state.
|
|
|
|
|
|
|
+ **PRUNING NO LONGER TAKES A GLOBAL LOCK ON 2.17.2, AND THE NOTE THAT SAID IT DID WAS THE BASIS OF AN APPROVAL ROUND I SHOULD NOT HAVE RUN.** This paragraph used to read "it takes a GLOBAL lock ... essentially every operation that resolves a collection waits, in every collection". That was accurate for **2.17.1** and is **wrong for 2.17.2, which is what prod runs** (confirmed from their code 2026-10-15). In 2.17.2 the prune runs AFTER `createCollection` releases the store lock and holds only THAT COLLECTION's history-file lock. During it, history-recording writes to the SAME collection wait (update, patch, upsert of an existing id, delete), and because a waiting writer holds that collection's lock, reads of that collection can wait behind it. **Other collections are unaffected.** Memory is one counter per document id.
|
|
|
|
|
+ So the blast radius of pruning our own operational collections is our own function machinery, NOT the tenants' data: the shared `default:vectorapi_function_jobs` queue is the one with cross-project reach, since every project's cron and job writes record history there. I asked four consumer sessions to approve a "global stall" that 2.17.2 does not have, which is the cost of carrying a version-specific claim without re-checking it against the version actually deployed. **A note naming the version it was measured on still has to be re-read when the deployment moves past that version.**
|
|
|
|
|
+ **`versioningEnabled=false` NEEDS NO WINDOW AT ALL.** It is one small write to `_collection_meta`, touches no history and takes no history lock - so stopping the GROWTH and reclaiming the BYTES are two separate operations with completely different risk, and only the second wants a quiet moment.
|
|
|
|
|
+ **THE CALL ITSELF CARRIES A TRAP THAT HAS NOTHING TO DO WITH VERSIONS: `createCollection(name, defaultTtlSeconds, encrypted, maxVersions, vectorDimension)` APPLIES `defaultTtlSeconds` WHENEVER IT DIFFERS, AND 0 IS A REAL VALUE** meaning "no default expiry". So pruning a collection that HAS a default TTL by passing 0 silently CLEARS the expiry for every later insert. Read the current value first (`getCollectionInfo(...)->defaultTtlSeconds`) and pass it back. `encrypted=false` never downgrades and `vectorDimension=0` is ignored, so those two are safe to pass. Note `smartbotic-db-cli info` does NOT print the TTL at all, so the CLI cannot answer this question and its silence is not a zero. For OUR collections it happens to be moot - every `createCollection` call in `src/` passes 0 for that argument, so the stored value is already 0 - but that is a fact about our code, not about the API.
|
|
|
|
|
+ **And it cannot be done BEFORE the encryption migration.** There is no mode that boots 2.17.1 without migrating - it runs before the listener opens - so "prune first to shorten the migration" is unreachable. Just as well: the prune path had no test against an unmigrated store (**and this note used to add "its test asserts only counts, not that surviving versions decrypt", which is out of date: as of 2.17.1 the e2e test prunes 12 versions to a cap of 3 and reads the newest version's CONTENT back through `getVersionHistory`, plus the live document unchanged, and the unit test asserts exactly the newest 3 per document remain, oldest first and readable, with a second prune to the same cap changing nothing**), so the escape hatch would have exercised new code against old on-disk format in a configuration nobody upgrades into. **The consumer who would have gained most from it was the one who decomposed the question correctly - "can it be deferred" is the easy half, "is the prune path safe against an unmigrated store" is the half that bites - and said they would rather have the long window.** Worth remembering as a pattern: when an optimisation needs a state that only the optimisation produces, the question is never whether you can get into that state.
|
|
|
|
|
+ **"DISABLE VERSIONING" AND `maxVersions = 0` ARE OPPOSITES, AND OUR OWN PLAN HAD THEM THE WRONG WAY ROUND.** `maxVersions = 0` means **keep unlimited history** - it is the setting that CREATED these files. The off switch is `configureCollection(coll, {versioningEnabled = false})` (client 2.4.5+, settable on an EXISTING collection, and reversible because history already written stays readable). `client.hpp:547` states the distinction outright. Our written plan said "disable versioning by setting maxVersions=0 on the queue and the run log", which would have re-applied the defect while believing it was the fix, and it survived unchallenged until a consumer attached a CONDITION to their approval that forced the mechanism to be checked. **The approval that costs something is the one that finds a defect; an approval that only says yes tells you nothing you did not already believe.**
|
|
|
|
|
+ **It also follows that disabling versioning RECLAIMS NOTHING.** It stops new versions; the bytes already written stay. Stopping the growth and recovering the space are two operations, and only the second needs a quiet moment. There is **no supported way to discard a collection's history outright** while keeping the collection: the floor is `maxVersions = 1`, which keeps the newest version of every document id ever written, deleted rows included, since history outlives a delete so the row can be restored. `dropCollection` does remove the history file and is not an option for a live queue. A "discard history" operation is upstream ROADMAP.
|
|
|
**What disabling versioning costs**, confirmed from their code rather than assumed, because the plan is to turn it OFF for the queue and the run log and keep a small N (5-10) on the registry: version history and `restoreVersion`/`restoreToDate` stop working for new writes, and **a DELETED row can no longer be restored**, because restore-after-delete reads the pre-delete state from history. That is why the REGISTRY keeps versions - an accidentally deleted function is exactly the row worth recovering - while a claimed-and-deleted queue row has no reader. It does NOT touch the WAL, replication, the event stream (actor included) or `_version`, which still increments; none of them read history, and recovery is snapshots plus WAL.
|
|
**What disabling versioning costs**, confirmed from their code rather than assumed, because the plan is to turn it OFF for the queue and the run log and keep a small N (5-10) on the registry: version history and `restoreVersion`/`restoreToDate` stop working for new writes, and **a DELETED row can no longer be restored**, because restore-after-delete reads the pre-delete state from history. That is why the REGISTRY keeps versions - an accidentally deleted function is exactly the row worth recovering - while a claimed-and-deleted queue row has no reader. It does NOT touch the WAL, replication, the event stream (actor included) or `_version`, which still increments; none of them read history, and recovery is snapshots plus WAL.
|
|
|
- **`FailedPrecondition` means three different things** and must be branched on `FailureDetail.reason`: `missing_parent` and `delete_restricted` are 422, `read_only` is **503**, and an absent or unrecognised reason is **500**, never a guessed 422. Mapping the bare code to 422 told a caller that a read-only database was its own validation mistake, so it would fix its payload and retry forever instead of waiting. Use the `FailureDetail&` overloads wherever a call offers one - the reason-less `Failure` form cannot tell these apart.
|
|
- **`FailedPrecondition` means three different things** and must be branched on `FailureDetail.reason`: `missing_parent` and `delete_restricted` are 422, `read_only` is **503**, and an absent or unrecognised reason is **500**, never a guessed 422. Mapping the bare code to 422 told a caller that a read-only database was its own validation mistake, so it would fix its payload and retry forever instead of waiting. Use the `FailureDetail&` overloads wherever a call offers one - the reason-less `Failure` form cannot tell these apart.
|
|
|
- **A version conflict is `ErrorCode::Aborted`** (client 2.12.0) carrying `currentVersion`, and maps to **409** `version_conflict`. It used to arrive as `Unknown` and fold into 503 "retry as-is", which is the opposite of the required instruction: re-read first. Never match on the message text for this.
|
|
- **A version conflict is `ErrorCode::Aborted`** (client 2.12.0) carrying `currentVersion`, and maps to **409** `version_conflict`. It used to arrive as `Unknown` and fold into 503 "retry as-is", which is the opposite of the required instruction: re-read first. Never match on the message text for this.
|