Commit c87f85e
committed
feat(fts): split compaction into dedicated module and add crash-safe LSM merge
The monolithic compact.rs handler and inverted.rs grew beyond the 500-line
limit and mixed unrelated concerns. Both are replaced with proper directory
modules:
- handlers/compact/ — budget tracking, FTS merge logic, maintenance
orchestration, segment-level helpers, stats, and runner are now separate
files. The module covers vector, CSR, and FTS compaction in a single
coordinated handler so the maintenance cycle has one entry point.
- engine/sparse/inverted/ — InvertedIndex is split into core, indexing,
search, compaction, synonyms, and error sub-modules following the
one-concern-per-file rule.
Two new operations are added to the redb FTS backend:
- compact_commit: writes the merged segment and removes all source segments
inside a single redb write transaction. A crash mid-compaction leaves the
original segments intact; the maintenance cycle retries on the next pass.
Double-counted postings from a partial commit are no longer possible.
- list_all_fts_collections: scans the SEGMENTS table to enumerate every
(tenant, collection) pair that has at least one segment, so maintenance
can discover compaction candidates without a separate registry.
The remove_segment path propagates the redb error instead of silently
swallowing Ok(None); a corrupt index or aborted transaction now surfaces
at the call site.
Two executor accessors are added so integration tests and bootstrapping
code can prime segments and resolve tenant→database mappings without
going through the normal indexing path:
- CoreLoop::fts_write_segment — writes a raw segment blob directly into
the LSM segment store, bypassing the memtable flush path.
- CoreLoop::fts_list_segments — returns the segment IDs for a collection.
- ExecutorMaintenance::set_tenant_database — primes the tenant→database
map so the maintenance budget tracker can resolve per-database CPU caps
for tenants that have not yet been seen in a request.
The new fts_compaction_budget integration test verifies that the
per-database maintenance CPU budget gates FTS LSM compaction: a database
under its cap has segments merged, while a database with its budget
pre-exhausted defers compaction without touching its segments.1 parent ac2d047 commit c87f85e
23 files changed
Lines changed: 2228 additions & 1298 deletions
File tree
- nodedb
- src
- data/executor
- core_loop
- handlers
- compact
- engine/sparse
- fts_redb/backend
- inverted
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
166 | 202 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
| |||
0 commit comments