Skip to content

Store, Then Search

One segment lifecycle, two very different jobs.

Part 39 of 41ofFamiliars
  1. 1Session Zero
  2. 2Rolling for a Name
  3. 3The Haunted Handler
  4. 4The Sparse Wheel
  5. 5The Fork in the Path
  6. 6The Planet as a Prefix
  7. 7The Long Division
  8. 8The Line You Usually Cancel
  9. 9Sixteen Bytes Too Far
  10. 10Packing a UUID
  11. 11Bytes You Can Type
  12. 12The Shunting Yard
  13. 13Interchangeable Parts
  14. 14One Loop Per Core
  15. 15The Seam
  16. 16Append Only
  17. 17Who Owns the Tree
  18. 18Down the Flume
  19. 19The Syscalls That Lie
  20. 20Asking the Machine
  21. 21The Earth Is Not a Ball
  22. 22Smith and Schmidt
  23. 23Many Ways to Be Similar
  24. 24Built to Disappear
  25. 25Sometimes a Mutex Is Right
  26. 26Work, Not Threads
  27. 27Before the Program Runs
  28. 28No Collisions, Ever
  29. 29The Names Enums Throw Away
  30. 30The Bag of Holding
  31. 31A Map of Blocks
  32. 32Certainly Absent
  33. 33A Tree Made of Types
  34. 34Everything but the Views
  35. 35Who Owns the Wheel
  36. 36A Guest on the Loop
  37. 37Acknowledged Means Durable
  38. 38Sorted as Bytes
  39. 39Store, Then Search
  40. 40When Power Leaves
  41. 41Keys Stay Home

Part of Familiars, my collection of standalone C++ building blocks. This pair is strata and prospect.

A search index has two kinds of work that happen to live in the same files. One kind decides when bytes become durable, which readers can still see an old segment, and when it is safe to reclaim a file. The other turns a query into terms, postings, scores, and a ranked list of documents. The first set of rules matters to any persistent index. The second is specific to search.

I had already watched those concerns grow together inside Xapiand, where Xapian supplies the index underneath. The new pair is meant to replace that part of Xapiand and serve its successor, Elysian. That provenance explains the compatibility work, but neither library depends on the rest of the engine. strata is an embeddable segment store; prospect is a search layout built on it.

strata accepts batches, assigns document IDs, flushes immutable segments, merges them in the background, and publishes snapshots. A layout names the plugins that fill a segment. Its document layout needs only keys and stored records, which makes a key-value store. The core does not have a search term type or a BM25 score tucked into it. The architecture puts those sections in prospect’s ownership.

prospect supplies the inverted layout: a term dictionary, postings, positions, lengths, document values, and the machinery that reads them. It can change how those sections compress or how a scorer traverses them without inventing another commit protocol. One segment still has a table of contents and a versioned, checksummed footer. The same manifest records which segments form a committed index.

An application chooses either a document layout with keys and stored records or prospect's search layout with postings; both use strata for segments, manifests, and merges.

This boundary matters most during a merge. Merging is not merely concatenating files: live documents may move to new segment ordinals, postings need encoding again, and readers holding an older snapshot must still see its files. strata owns the file lifecycle and the ordinal map. prospect owns the meaning of its search sections and can reorder documents to improve compression and pruning. A storage concern stays in one place, and a search concern gets a hook where the bytes are written.

There is a tempting shortcut in a segment store: finish writing a new file, rename a manifest into place, and call the commit done. A power cut can make that manifest survive without the segment it names if the relevant sync and directory ordering are missing.

The commit sequence in strata syncs segment data and live-document state, writes and syncs the manifest, then syncs the directory. Recovery checks the manifest and the files it names; it fails on corruption instead of quietly opening an older view. Snapshots, manifests in use, and journal checkpoints also hold references that prevent premature reclamation. These rules are shared whether the segment contains only keys or a full inverted index.

The lifecycle gate exercised 10,000 crash points across 31 seeded workloads with zero lost commits or inconsistent opens. In a separate reclamation sweep it checked 16,274 manifests over 3,635 cut points. When the directory barrier was deliberately removed, 93 manifests named missing files. faultlab supplies the model and replayable cuts. That last number is useful because it shows the test can detect the failure the barrier is there to prevent. It is evidence for this modeled IO contract, not a promise about every real filesystem.

Once a snapshot exists, prospect can read immutable segments while writes continue. Its term dictionary points to compressed postings blocks. A query resolves terms, requests the ranges it needs, and walks document IDs in windows. BM25 supplies scores; block maxima let a top-k query skip work that cannot beat its current threshold. Phrase queries also need positions. Aggregations and exact totals can turn pruning off when they need to see every matching document. The read path spells out where each decision is made.

The query coroutine runs on the caller’s reactor. It can suspend for residency and yield between windows instead of parking a reactor thread behind disk access or a long scorer loop. This is an integration choice as much as an algorithm choice: the host remains responsible for scheduling, while the search code has explicit places to give time back.

The result is not yet a production replacement for Xapian. strata’s API and on-disk format are still changing. prospect’s status records query performance rows that have not met their target, even as later format work proceeds. In a format gate, 1,162 query lines produced no result mismatches, but some speed and size comparisons still lost. Correct results are necessary; they do not make the performance case by themselves.

For now the pair is most useful as an explicit way to build and test an index: one durable segment lifecycle, with a search layout that can evolve independently. That is the seam I wanted to keep.