Repository navigation
feat(indexer): one leaf size for import, rebuild and incremental builds - #2051
Conversation
588c20f to
aee1a2d
Compare
Bulk import sizes leaves by row count (250,000) independently of the leaflet size, while rebuild and incremental builds derived the leaf size as leaflet_rows × leaflets_per_leaf. Changing leaflet_rows on an IndexerConfig therefore also changed leaf size, and a non-default import geometry could not be reproduced by later builds. IndexerConfig gains leaf_target_rows: Option<usize>. The default, new() and large() presets set it to DEFAULT_LEAF_TARGET_ROWS, the size import uses; small() and with_leaflets_per_leaf() leave it None and keep the derived size, which tests rely on for multi-leaf coverage at small scale. Rebuild and incremental builds read effective_leaf_target_rows(). DEFAULT_LEAFLET_ROWS and DEFAULT_LEAF_TARGET_ROWS replace the 25,000 and 250,000 literals in import, the CLI and the indexer presets. Defaults are unchanged: 25,000-row leaflets in 250,000-row leaves.
aee1a2d to
05612dd
Compare
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz yes to the explicit leaf target, and no design pushback on how it's done. One question rather than a request: after this PR the leaf half of an index's geometry is stable across builds, but the leaflet half (and any non-default import leaf size) still comes from whatever IndexerConfig the next build happens to carry. Recording the targets in the index root would let an index keep the geometry it was written with. That's a format-level decision for later, not this PR's. Good to merge once it's ready. It conflicts trivially with #2035 in rebuild.rs, whichever of the two lands second.
Full review below:
✅ Approve with nits.
Nice, small and well-scoped, @bplatz. I checked the two things I'd worry about with a geometry change. First, defaults: 25,000 × 10 is 250,000 under every default preset, so no default-configured index changes. Second, existing indexes: the diff touches no reader or format code, and incremental builds already keep a differently-sized leaf and grow it in place below the split ceiling (incremental_branch.rs:393-405). An index from either side reads and maintains on the other, with no reindex. Mixed geometries aren't new either, since a non-default import followed by builds already produced them. Targeting next is consistent with the releasing doc, since the new public field on a non-#[non_exhaustive] IndexerConfig breaks struct literals that don't use ... Solo's construction does use ..IndexerConfig::default() and is unaffected.
The one item I'd most like to see before merge is a test of the wiring: today you can revert all three build sites and the indexer suite stays green. The other two inline notes are cheap folds: builder-order dependence, and import's dead --leaflets-per-leaf.
One more small thing with no anchor: it_fastpath_1652_regression (:501) uses IndexerConfig::default().with_leaflet_rows(3), so its reindex now writes one leaf of 3-row leaflets where it used to write many 30-row leaves. It still passes (I ran it), and the #1652 bug it pins is a leaflet-boundary bug, so it's still covered; it just no longer crosses leaf boundaries. Adding .with_leaflets_per_leaf(10) there brings the old shape back if that matters to you.
Adherence to repo commitments:
- Patterns/abstractions: ✔ One explicit target on the existing
IndexerConfig, constants replacing literals; no parallel mechanism. - Performance (speed first, memory second): ✔ No default geometry changes; no hot path touched. No performance-degradation risk. If the leaflet default is lowered later, #2048's 64 KiB header+directory read still covers a 250,000-row leaf down to ~760-row leaflets.
- Deployment targets: ✔ n/a — config that every host's index build reads identically; solo compiles and behaves unchanged.
- Testing:
⚠️ The helper is pinned and goes red under mutation; the three build sites that use it aren't pinned (inline). - Conventions: ✔ Multi-line commit body, self-describing title, clippy and fmt green; doc comments updated alongside the constants.
Verified locally at branch HEAD (05612ddd5): cargo test -p fluree-db-indexer --lib config:: (new test by name). Mutation checks on the helper (red) and on the three build sites (434 green, so untested). cargo test -p fluree-db-api --test it_fastpath_1652_regression (green). Trial merges against origin/main (clean) and #2035 (one trivial rebuild.rs conflict).
Approving so you can merge when ready, but maybe worth folding in the test first.
|
|
||
| // Determine output directory for binary index artifacts | ||
| let staging_in_temp = config.data_dir.is_none(); | ||
| let leaf_target_rows = config.effective_leaf_target_rows(); |
There was a problem hiding this comment.
🟠 Should address: the behavior this PR changes isn't pinned by any test, only the helper is
leaf_target_rows_derives_unless_set covers effective_leaf_target_rows() itself, but nothing checks that the builds use it. I reverted this line and both incremental sites (build/incremental.rs:458 and :4813) to the old leaflet_rows × leaflets_per_leaf, and the whole fluree-db-indexer lib suite still passes (434 tests). Reverting just the helper does turn your test red, so the gap is specifically the wiring.
A rebuild over ~100 rows with IndexerConfig::default().with_leaflet_rows(10), asserting one leaf per sort order, would pin it: the old code writes ten. If an incremental build is cheap to drive in the same test, asserting the merged leaf stays one leaf would cover the other two sites.
|
|
||
| pub fn with_leaflets_per_leaf(mut self, n: usize) -> Self { | ||
| self.leaflets_per_leaf = n.max(1); | ||
| self.leaf_target_rows = None; |
There was a problem hiding this comment.
🟡 Optional / nit: with_leaflets_per_leaf silently discards an explicit leaf target set before it
Because this line resets the target, IndexerConfig::default().with_leaf_target_rows(1_000).with_leaflets_per_leaf(4) ends up deriving leaflet_rows × 4, and with_leaf_target_rows(1_000) is dropped without a word. Builder chains usually don't depend on call order, so this will surprise someone eventually.
Two ways out. Make "derive" explicit: small() sets None itself, and with_leaflets_per_leaf only clears the target when it still holds the preset default. Or let an explicit with_leaf_target_rows win regardless of order. A one-line doc on both builders would be the minimum. I recognize this is minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
| pub leaflet_rows: usize, | ||
| /// Number of leaflets per leaf file. Default: 10. | ||
| /// Larger values produce fewer, bigger leaf files (less tree depth, bigger reads). | ||
| pub leaflets_per_leaf: usize, |
There was a problem hiding this comment.
🟡 Optional / nit: import's leaflets_per_leaf is a dead knob, and the CLI advertises it
Your code didn't introduce this, but it's the import-side twin of what this PR unifies. ImportConfig::leaflets_per_leaf is declared here, defaulted (:331) and settable (:3242), but never read: import sizes leaves only by leaf_target_rows (:6274). fluree create --import still exposes --leaflets-per-leaf with help text saying larger values produce fewer leaf files (fluree-db-cli/src/cli.rs:365-368), forwards it (commands/create.rs:556), and echoes it in its JSON output (:617-618). So the flag does nothing, and there's no CLI flag for the knob that does act (leaf_target_rows).
Since this PR is about one leaf size across import, rebuild and incremental, it seems the right place to either drop the field and flag, or map --leaflets-per-leaf onto leaf_target_rows the way with_leaflets_per_leaf derives it for builds. Happy to talk it through if you'd rather keep the flag for compatibility.
…acing Rebuild, incremental and import now size leaves by `leaf_rows` alone (renamed from `leaf_target_rows`, default `DEFAULT_LEAF_ROWS`) on both `IndexerConfig` and `ImportConfig`. `leaflets_per_leaf` is gone: it was a second way to state the leaf size, and on import it was never read. `fluree create --import` drops `--leaflet-rows` and `--leaflets-per-leaf`. The first sized the import's leaflets while later builds went back to the default; the second did nothing. Readers accept any geometry, so the defaults stay ours to tune. Tests that shrink the geometry now set both sizes explicitly. A new `grp_index` test pins the wiring: with 10-row leaflets, a rebuild, an incremental merge and a named graph's first build each keep one leaf per order. Reverting any one of the three build sites turns it red.
… namespace `Fluree::content_store` takes a `StorageNamespace` since the ledger lifecycle change on next; the test passed the ledger id.
Summary
The three ways an index gets built didn't agree on leaf size:
leaflet_rows × leaflets_per_leaf.So changing
leaflet_rowson anIndexerConfigalso changed the leaf size, and a later build couldn't reproduce an import's geometry. With 4,096-row leaflets, for example, an import writes 250,000-row leaves, but a rebuild with the same leaflet size wrote 40,960-row leaves.This PR gives all three paths one leaf size and makes the geometry the engine's to choose, not the user's:
IndexerConfigandImportConfigeach have two geometry fields with the same names,leaflet_rowsandleaf_rows. They default toDEFAULT_LEAFLET_ROWS(25,000) andDEFAULT_LEAF_ROWS(250,000). Leaf size never derives from leaflet size.leaflets_per_leafis gone from both configs and both builders. It was a second way to state the leaf size, with a precedence rule between the two; on import it was never read.leaf_rows.fluree create --importno longer takes geometry flags (below).Readers accept any geometry, and incremental builds keep an existing leaf's size, so the defaults can change in a release without a reindex.
Defaults are unchanged: 25,000-row leaflets in 250,000-row leaves, the same as
25,000 × 10today. Code that setsleaflet_rowsnow keeps 250,000-row leaves, including onIndexerConfig::small(), which used to shrink them too.This is groundwork for evaluating smaller leaflet sizes. Changing the leaflet default is a separate decision and isn't part of this PR.
Breaking changes
fluree create --importdrops--leaflet-rowsand--leaflets-per-leaf; scripts passing either now get a usage error.--leaflet-rowssized only the import's leaflets, and every later rebuild or incremental build went back to the default, so a ledger ended up with two leaflet sizes.--leaflets-per-leafdid nothing. The import status file no longer records either undersettings.IndexerConfig::leaf_target_rows: Option<usize>is nowleaf_rows: usize, andwith_leaf_target_rowsiswith_leaf_rows.leaflets_per_leaf,with_leaflets_per_leafandeffective_leaf_target_rowsare removed.ImportConfig::leaf_target_rowsandImportBuilder::leaf_target_rowsare nowleaf_rows.ImportConfig::leaflets_per_leafandImportBuilder::leaflets_per_leafare removed.DEFAULT_LEAF_TARGET_ROWSis nowDEFAULT_LEAF_ROWS.Tests
it_leaf_rows_wiring(grp_index): with 10-row leaflets and the default leaf size, three builds each keep one leaf per order in every graph: a rebuild over 300 rows, then an incremental build that merges 300 more into the default graph and builds a new named graph for the first time. Reverting any one of the three build sites to leaflet-derived sizing turns it red: the rebuild writes 3 default-graph leaves per order, the merge 6, the named graph's first build 3.leaf_rows_is_independent_of_leaflet_rowscovers the config.it_query_sparql_indexed,it_fastpath_1652_regression,it_trigger_index_incremental,it_stats_sketch_formatandit_ledger_info_reindex_cache.Follow-up: #2107 (unused
IndexerConfigsizing fields and thesmall/large/newpresets).