Repository navigation
fix(schema): carry the whole index definition over at every rebuild site (#5742) - #6869
Conversation
…ite (#5742) An index rebuilt from its own definition read that definition with IndexInternal.getMetadata(), which on the WRAPPER index types answers with the underlying LSM-Tree's plain IndexMetadata. A full-text index keeps its analyzers, query-parser options and BM25 parameters in its own FullTextIndexMetadata, a geospatial one keeps its geohash resolution and storage layout as plain fields, and a sparse-vector one keeps its dimensionality, scoring modifier and weight quantization in its own metadata: none of that is reachable through the underlying index, so the recreated index silently came back with the DEFAULT configuration - a different analyzer and a different ranking, a different cell size - with nothing logged. Every site now reads getMetadataForNewFile(), the accessor added by #5734: - TRUNCATE TYPE recreated only an LSM_VECTOR index's metadata, through an explicit per-index-type branch. withType() has already swapped in the builder subclass that owns the type-specific settings, so one polymorphic withMetadata() call covers every index type and leaves no branch to forget. - REBUILD INDEX and CHECK DATABASE FIX share IndexMetadata.reconstructForRebuild, which reconstructed FULL_TEXT and GEOSPATIAL from the index's persisted JSON and fell through to getMetadata() for everything else. For LSM_SPARSE_VECTOR that did not merely lose the settings: the sparse builder refuses a plain IndexMetadata, so both operations FAILED on a sparse-vector index with "requires LSMSparseVectorIndexMetadata but got IndexMetadata". It now reads the one accessor and copies, keeping the two adjustments only a rebuild is entitled to make (zeroed BM25 corpus counters, GEOSPATIAL republished on the FRONTIER layout). - ALTER TYPE ... BUCKET +... and ALTER TYPE ... SUPERTYPE +... mint a sub-index for the new bucket. They hand the definition over as-is rather than copied: that sub-index belongs to the SAME logical index, which is what index creation does when it passes one metadata instance to every bucket sub-index, and what keeps the full-text corpus counters type-wide. A wrapper's definition is split in two, and schema RELOAD rebuilt the type-specific half from the bucket-level index JSON, which carries no "typeName" key - so fromJSON() skipped the base-field read and the collations and the manual index name stayed only on the underlying half. Reading the accessor would then have traded one silent loss for another (right analyzer, lost index name), so the two halves are joined back at load through IndexMetadata.inheritCommonSettingsFrom(). Also documents the one window copyType() cannot cover - a hard crash between the record commit and the index build leaves a populated type with empty indexes, which CHECK DATABASE does not report because its index check is structural - and names REBUILD INDEX as the repair. Issue5723CopyTypeIndexConfigurationTest.truncatingAManuallyNamedVectorIndexKeepsItsName ran its TRUNCATE TYPE inside a transaction, which takes the record-by-record path and never drops the index at all, so it asserted on a carry-over that had not happened.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 87.50% diff coverage · -6.43% coverage variation
Metric Results Coverage variation ✅ -6.43% coverage variation Diff coverage ✅ 87.50% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (9cf4d26) 167849 134907 80.37% Head commit (7504fd4) 200238 (+32389) 148055 (+13148) 73.94% (-6.43%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6869) 16 14 87.50% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughChangesIndex configuration carry-over
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change preserves full index definitions across rebuild, truncate, bucket, supertype, and reload paths, including type-specific settings. The supplied tests and engine suite are green, and no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and explains the defect, implementation, linked issue, affected operations, crash-window documentation, and regression tests. It does not use the repository template headings or include the checklist, but it provides the required substantive information. Full details: Linked Issues checkExplanation The changes address issue
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
ReviewSolid fix, and the write-up in the PR description makes the bug easy to verify against the code. The core idea (
Test coverage for the four sites plus the reopen/reload edge case is thorough and each case is asserted through the same One more call site with the same bug pattern
final IndexMetadata metadata = onBuckets.length > 0 ? onBuckets[0].getMetadata() : null;
if (replaced.metadata() != null)
restore.withMetadata(replaced.metadata());where This path is reached by Minor
Nothing else stood out on security or performance - this is schema/DDL-path code, not a hot path, and no new dependencies or unsafe patterns were introduced. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6869 +/- ##
==========================================
+ Coverage 71.78% 71.79% +0.01%
==========================================
Files 1881 1881
Lines 167849 167851 +2
Branches 35559 35559
==========================================
+ Hits 120485 120517 +32
+ Misses 32981 32954 -27
+ Partials 14383 14380 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #5742.
The defect
Any site that rebuilds an index from its own configuration has to read that configuration back and feed it through the creation path. They read it with
IndexInternal.getMetadata(), which for the WRAPPER index types answers with the underlying LSM-Tree's plainIndexMetadata:LSMTreeFullTextIndexkeeps its analyzers, query-parser options and BM25 parameters in its ownFullTextIndexMetadataLSMTreeGeoIndexkeeps its geohash resolution and storage layout as plain fieldsLSMSparseVectorIndexkeeps its dimensionality, scoring modifier and weight quantization in its ownLSMSparseVectorIndexMetadataNone of that is reachable through the underlying index, so each site silently recreated the index with the DEFAULT configuration - a different analyzer and a different ranking for a full-text index, a different cell size for a geospatial one. Nothing logged, and the index kept working.
What changed
Every site now reads
getMetadataForNewFile(), the accessor #5734 added for exactly this.TRUNCATE TYPEgetMetadata(), carried over only forLSM_VECTOR, behind an explicit per-index-type branchgetMetadataForNewFile().copy(...), one polymorphicwithMetadata()for every index typeREBUILD INDEX/CHECK DATABASE FIX(IndexMetadata.reconstructForRebuild)FULL_TEXT/GEOSPATIALreconstructed from the index's persisted JSON, everything elsegetMetadata()copy(), keeping the two adjustments only a rebuild may makeALTER TYPE ... BUCKET +...getMetadata()getMetadataForNewFile()ALTER TYPE ... SUPERTYPE +...getMetadata()getMetadataForNewFile()TRUNCATE TYPEloses its per-index-type branch entirely:withType()has already swapped in the builder subclass that owns those settings, so the polymorphic call lands on the override that reinstates them and there is no list to forget an index type from.LSM_SPARSE_VECTOR was worse than a silent loss. Falling through to
getMetadata()handed the sparse builder a plainIndexMetadata, which it refuses outright, soREBUILD INDEXandCHECK DATABASE FIXon a sparse-vector index failed:The half of the definition the accessor did not carry
A wrapper index's definition is split in two: the base settings (collations, the user-supplied index name) belong to the underlying LSM-Tree's metadata, the type-specific ones to the wrapper's own. Creation populates one instance carrying both halves, but a schema RELOAD rebuilds the type-specific half from the bucket-level index JSON, which carries no
typeNamekey - sofromJSON()skips the base-field read and those settings stay only on the underlying half. Switching the carry-over sites to the accessor without fixing that would have traded one silent loss for another: right analyzer, lost index name. The two halves are joined back at load through the newIndexMetadata.inheritCommonSettingsFrom(), andtruncateAfterAReopenKeepsBothHalvesOfTheDefinitionfails without it.Bucket/super-type propagation hands the instance over as-is
Not copied, unlike the other two sites: the sub-index minted there belongs to the SAME logical index. That is what index creation itself does when it passes one metadata instance to every bucket sub-index, and it is what keeps the full-text corpus counters type-wide instead of restarting them at zero for the new bucket.
copyType()'s crash windowThe issue also asks for a story on
copyType()'s deliberate non-atomicity. The existingcatchcovers a failure on either side of the commit boundary by dropping the copy; a hard crash in the same window leaves a populated type with empty or partial indexes, andCHECK DATABASEdoes not report it because its index check is STRUCTURAL (checkIntegrity()walks the key order of the index's own pages, so an index merely missing entries looks healthy). Rather than pay for atomicity - which would mean holding every copied record in one transaction - the javadoc now names the window explicitly and namesREBUILD INDEX <name>as the repair.Tests
New
Issue5742IndexConfigurationCarryOverTest, one case per user-visible operation - all five fail onmain:truncateTypeKeepsTheFullTextConfiguration- asserts behaviourally, on the English stem still matching after the truncate, not only on the attributetruncateTypeKeepsTheGeospatialPrecisionaddingABucketKeepsTheFullTextConfigurationaddingASuperTypeKeepsTheFullTextConfigurationrebuildIndexKeepsTheSparseVectorConfigurationcheckDatabaseFixKeepsTheSparseVectorConfigurationtruncateAfterAReopenKeepsBothHalvesOfTheDefinitionAlso fixed a vacuous existing test:
Issue5723CopyTypeIndexConfigurationTest.truncatingAManuallyNamedVectorIndexKeepsItsNameran itsTRUNCATE TYPEinside a transaction, which takes the record-by-record path and never drops the index at all (#6220), so it asserted on a carry-over that had not happened.Full
enginemodule suite green (13745 tests, 0 failures); vector lane green.Summary by CodeRabbit
Bug Fixes
Tests