Repository navigation
Rebuild the text index without holding writers up - #129
Merged
Merged
Conversation
REBUILD TEXT INDEX used to run as one operation inside the caller's transaction. The whole new index lived in heap, its pages counted against the transaction quota, and a concurrent text write made the commit redo the entire rebuild under the commit lock. The rebuild now runs in its own transaction. It reads the sections of its snapshot once, sorts postings and statistics in batches written to scratch/, and merges them into bulk-built trees whose pages are spilled as they fill. After the build it diffs the sections, revisions and documents of its snapshot against newer ones and replays the difference through the text derivation alone, so the commit only applies the last small difference. Payload erasures wait for a running rebuild, since removing a section's postings needs its text. Engine changes: - PostingIndex.bulk builds a posting index from ascending entries with the same inline and promotion rules as single adds. - Workspace.scratch gives a workspace that runs one derivation. - ChangeLog gives up on a diff that reads more than 64 nodes plus 16 per change and logs the root instead. A rebuilt tree shares no pages with the old one, so the old rule walked both trees under the lock. The statement is now refused inside BEGIN and on a pinned generation.
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #127. Merge after #124 to #127, and retarget to main once #127 is in.
REBUILD TEXT INDEXused to run inside the caller's transaction. The whole new index sat in heap, its pages counted against the transaction quota, and a text write committed during the rebuild made the commit redo all of it under the commit lock.What it does now:
BEGINand on a generation pinned withAT.scratch/in the database directory, and merges them (at most 128 files at a time) into bulk-built trees whose pages spill as they fill.Engine changes:
PostingIndex.bulk,Workspace.scratch, and a node bound inChangeLog. A tree rebuilt from scratch shares no pages with the old one, so the old diff rule read both trees under the commit lock to find few or no changes. It now gives up after 64 nodes plus 16 per change found and logs the root.An independent review found no correctness problem in the result. It did find that the first version still diffed the whole index under the lock and re-tokenised the corpus once per pass; both are fixed here, with tests that fail on the old code.
Tests:
TextRebuildTestcovers: matching the live index entry for entry from memory, from sorted runs, and through a multi-level merge; the page quota; commits folded in after the build and after catch-up, starting from a corrupted index; two rebuilds racing a writer; failure; branches; asynchronous durability with a checkpoint during the rebuild.Live over the wire:
Known limit: if writes arrive faster than the catch-up rounds can absorb, the difference applied at commit can still be large. The docs say so.
Merge order for the memory stack: #128 (CI fix), #124, #125, #126, #127, #129 (online text index rebuild), #130 (starter kit). Retarget each to main once the one below it merges. A private preview image built from #129 merged with #128 is at ghcr.io/metacoglabs/hstore-memory:0.2.0-dec80f2.