Skip to content

feat(indexer): one leaf size for import, rebuild and incremental builds - #2051

Merged
bplatz merged 4 commits into
nextfrom
feat/leaf-geometry-target
Oct 14, 2026
Merged

bplatz merged 4 commits into
nextfrom
feat/leaf-geometry-target

Conversation

@bplatz

@bplatz bplatz commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The three ways an index gets built didn't agree on leaf size:

  • Bulk import sizes leaves by row count (250,000), independent of the leaflet size.
  • Rebuild and incremental builds derived the leaf size as leaflet_rows × leaflets_per_leaf.

So changing leaflet_rows on an IndexerConfig also 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:

  • IndexerConfig and ImportConfig each have two geometry fields with the same names, leaflet_rows and leaf_rows. They default to DEFAULT_LEAFLET_ROWS (25,000) and DEFAULT_LEAF_ROWS (250,000). Leaf size never derives from leaflet size.
  • leaflets_per_leaf is 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.
  • Rebuilds, incremental merges and a graph's first incremental build all read leaf_rows.
  • fluree create --import no 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 × 10 today. Code that sets leaflet_rows now keeps 250,000-row leaves, including on IndexerConfig::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

  • CLI: fluree create --import drops --leaflet-rows and --leaflets-per-leaf; scripts passing either now get a usage error. --leaflet-rows sized 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-leaf did nothing. The import status file no longer records either under settings.
  • Rust API:
    • IndexerConfig::leaf_target_rows: Option<usize> is now leaf_rows: usize, and with_leaf_target_rows is with_leaf_rows. leaflets_per_leaf, with_leaflets_per_leaf and effective_leaf_target_rows are removed.
    • ImportConfig::leaf_target_rows and ImportBuilder::leaf_target_rows are now leaf_rows. ImportConfig::leaflets_per_leaf and ImportBuilder::leaflets_per_leaf are removed.
    • DEFAULT_LEAF_TARGET_ROWS is now DEFAULT_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_rows covers the config.
  • Tests that shrink the geometry to cross leaf boundaries set both sizes now, keeping their previous layouts: it_query_sparql_indexed, it_fastpath_1652_regression, it_trigger_index_incremental, it_stats_sketch_format and it_ledger_info_reindex_cache.

Follow-up: #2107 (unused IndexerConfig sizing fields and the small/large/new presets).

@bplatz bplatz added enhancement New feature or request area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches labels Oct 10, 2026
@bplatz
bplatz requested a review from a team October 10, 2026 15:59
@bplatz
bplatz force-pushed the feat/leaf-geometry-target branch from 588c20f to aee1a2d Compare October 11, 2026 17:44
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.

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment thread fluree-db-indexer/src/build/rebuild.rs Outdated

// 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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 545e1dd

Comment thread fluree-db-indexer/src/config.rs Outdated

pub fn with_leaflets_per_leaf(mut self, n: usize) -> Self {
self.leaflets_per_leaf = n.max(1);
self.leaf_target_rows = None;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 545e1dd

Comment thread fluree-db-api/src/import.rs Outdated
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 545e1dd

…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.
@bplatz bplatz added the breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section label Oct 13, 2026
… namespace

`Fluree::content_store` takes a `StorageNamespace` since the ledger
lifecycle change on next; the test passed the ledger id.
@bplatz
bplatz merged commit 240bad1 into next Oct 14, 2026
19 checks passed
@bplatz
bplatz deleted the feat/leaf-geometry-target branch October 14, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants