Repository navigation
fix(engine) #5765: creating a manual index no longer fences the database, and a guarded request answers for the index asked for - #5775
Conversation
…ase, and a guarded request answers for the index asked for ManualIndexBuilder.create() registered the new index's file under `index instanceof PaginatedComponent`, a test that never matched: LSMTreeIndex and HashIndex WRAP their paginated component rather than being one. The file stayed unknown to the schema, and the commit that creates it then failed resolving that file id AFTER its WAL append - which fences the database for recovery (#5053). Every manual index creation ended there, and the builder's own error callback threw on the fenced database, replacing the real cause with a bare fence error. Registration goes through index.getComponent() now, the same accessor the type-index path uses, and the cleanup callback no longer throws. Three defects the first one hid, each found by fixing the previous: - Schema.createManualIndex(indexType, ...) dropped its indexType argument, so every call through that deprecated overload failed with a NullPointerException inside the index factory. - A UNIQUE manual index could not commit an entry: TransactionIndexContext's lock collection and its uniqueness check both resolved the index's type name to reach the polymorphic index over the same properties, and a manual index has neither. It is now recognised as its own whole search space, which it is. - withNullStrategy(null) installed the null instead of leaving the default, and the index constructor refused it with "Index null strategy is null". null now means "not specified", the convention withPageSize already follows. An index kind that cannot be built without a type (FULL_TEXT, GEOSPATIAL, LSM_VECTOR, LSM_SPARSE_VECTOR) is refused by name instead of failing inside the factory with a NullPointerException or a ClassCastException. The guarded branch still carried the two defects #5675 removed from TypeIndexBuilder: a request differing only in uniqueness DROPPED the existing index behind a dead `x != null && x == null` null-strategy test, and the index kind was not compared at all. It follows the same rule as the type path now. There is no withReplaceIfIncompatible here: the setter raises on a manual builder, because the replacement it authorises elsewhere is a rebuild from the type's records and here it would be an unrecoverable delete of the only copy of the entries. fix(engine) #5765: CREATE INDEX IF NOT EXISTS compares the settings the METADATA clause named The guard compared the structural definition only - kind and uniqueness - so a guarded statement asking for 768 dimensions over a 384-dimension vector index was a silent no-op, and every vector written afterwards went unindexed. Same for full-text analyzers and geospatial precision. Only the settings the clause actually NAMED are compared, so a statement with no METADATA compares none and stays the no-op it has always been. The clause is read through the index type's own reader before comparing, so "384" and 384, "cosine" and COSINE are the one value each denotes. Both entry points ask the same question through one helper: the IF NOT EXISTS shortcut of CreateIndexStatement, which answers before a builder exists, and TypeIndexBuilder.create(). The read side of each per-type key set is covered by a test that fails if a key is added to one list and not the other. test(engine) #5765: poll for the vector rebuild instead of sleeping a fixed interval Two Thread.sleep(6_000) + hard assertion pairs in LSMVectorIndexRecoveryTest, and the ceilings in LSMVectorIndexRebuildTest computed as a multiple of the inactivity timeout - which makes the wait shortest exactly where the work is slowest. Four of them failed in a whole-package run here and passed in isolation. They share one absolute ceiling now; the class also runs faster, since a poll returns as soon as the rebuild lands. chore(engine) #5765: CREATE INDEX and REBUILD INDEX log their progress instead of printing dots to stdout
|
Tick the box to add this pull request to the merge queue (same as
|
…ex-builder # Conflicts: # docs/release-26.8.1.md
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 62 |
🟢 Coverage 88.98% diff coverage · -6.78% coverage variation
Metric Results Coverage variation ✅ -6.78% coverage variation Diff coverage ✅ 88.98% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (876635c) 151275 115849 76.58% Head commit (5bb7116) 183416 (+32141) 128023 (+12174) 69.80% (-6.78%) 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 (#5775) 118 105 88.98% 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.
Review: PR #5775 - manual index fencing + guarded-request settings comparisonReviewed the full diff and cross-checked the moving parts against the codebase ( Correctness - verified, looks right
One behavior change worth calling out explicitly
This is clearly deliberate and well-argued in the javadoc/release note (silent discard is the worse surprise), so I'm not asking to change it - just flagging that it's a semantic change to a previously-idempotent path. Two small asks:
Minor notes (non-blocking)
Style / conventionsMatches the repo: Nice work - the "each defect was hiding the next" writeup made this easy to follow. The behavior-change callout above is the only thing I'd want confirmed before merge. |
…ING, and say why the builder path does not re-wrap the clause Review follow-ups on #5775, both documentation-level. - The release note now frames the settings comparison as what it is for anyone with a re-runnable schema script: a guarded CREATE INDEX naming a setting MAY NOW RAISE where it used to be a no-op, including for the runtime-tunable keys a rebuild would not be needed to change (efSearch, mutationsBeforeRebuild, inactivityRebuildTimeoutMs, the cache sizes). Both ways back to an idempotent statement are spelled out: drop the keys the script does not actually require, or align the value with the existing index. - TypeIndexBuilder.create() calls findUnsatisfiedSettings without the try/catch the CreateIndexStatement shortcut wraps its own call in, and the invariant that makes that safe is now written down rather than implied: the SQL branches call withMetadata and withUserMetadata inside one try, so the clause has already been read - and any unreadable value already reported - before create() runs. A caller that sets the user clause without the parsed one has skipped that validation and gets the reader's own message; there is no such caller, and adding a second error path would only re-type an exception the reader already words correctly. Verified against the review's third ask: no CREATE INDEX IF NOT EXISTS with a METADATA clause exists outside engine/, and RemoteSchema.getOrCreateTypeIndex builds its guarded statement without one, so nothing outside the engine reaches the new comparison. Server module re-run against a freshly installed engine: 687 tests, 0 failures.
|
Thanks - all three asks addressed in 9f17194. 1. Release-note framing. Added a 2. Server/IT run. Done, and worth reporting how it went, because my first attempt produced a false regression.
With the engine actually installed from this branch: server module 687 tests, 0 failures, BUILD SUCCESS, that test included. A temporary diagnostic confirmed the values reaching On the specific worry - an existing test re-creating with a differing tuning value - I also grepped the repo: there is no 3. Full engine suite remains green at 10977 tests. |
|
Review: PR 5775 - manual index no longer fences the database, guarded requests answer for the index asked for Reviewed the full diff, the touched engine sources, and the new/changed tests. This is a high-quality, well-scoped fix. The commit messages and release notes explain not just what changed but why the previous code was wrong, and each fix is a real defect with a clear root cause. Strengths
Minor points / questions
Conventions / correctness checks
I could not run mvn in this sandbox (blocked), so I relied on the PR-stated verification (engine 10977/0/0, server 687/0, all modules compile) plus static review. Nothing in the diff suggests a compile or logic problem. Overall: clean, well-tested, well-explained. The minor points above are suggestions, not blockers. |
…d assert the file registration directly Round-two review follow-ups on #5775. - withUserMetadata deep-copies the clause. The callers hand the SAME JSONObject to withMetadata(JSONObject) and to withUserMetadata, and the two are read at different times: the first now, the second at create(). No withMetadata overload mutates it today - all four read it through fromUserMetadata - but the copy costs nothing at DDL time and means a future one could not silently change what a guarded request ends up comparing against. - A test asserts the registration itself rather than inferring it from the other tests happening to run. The index's file must resolve through the schema by its id, which is the call TransactionContext.commit2ndPhase makes for every file whose page count changed - past the WAL append, which is why an unregistered file fenced the database instead of failing the creation. The test pins the cause (getFileById resolves to the index's own component) and the consequence (the database still commits an unrelated write afterwards, which a fenced one cannot). Mutation-checked: restoring the `instanceof PaginatedComponent` test reproduces "commit of tx 4 failed after its WAL append". Three other review points taken as no-action, with reasons: refusing runtime-tunable settings on a guarded create is the intended semantics and is already documented as BREAKING; the TypeIndexBuilder invariant comment is the right mitigation for a caller shape that does not exist; and the mismatch message wording is already covered by tests.
|
Thanks - acted on the two points that harden something, declined three with reasons. 9ffb5f1. 2. Shared 4. Test gap: nothing asserted the DB is not fenced - agreed, and this was the best of the five. Added
Mutation-checked: putting the 1. Refusing runtime-tunable settings - keeping as is. It is the intended semantics and the release note now carries it under a 3. 5. Engine tests for the touched areas: 44/44 green ( |
Review of #5775 - manual index creation and guarded-create settings comparisonReviewed the full diff plus surrounding source ( Verified as correct
Minor observations (non-blocking)
Test coverageExcellent. Manual-index creation, unique-constraint commit, reopen persistence, the full guarded-branch matrix (unique-over-notunique, kind mismatch, notunique-over-unique no-op, idempotent, unguarded refusal), the deprecated overload, unsupported kinds, and the settings comparison across all four metadata types are covered. The BREAKING semantic change is clearly documented with both remediation paths. Nice work - no blocking concerns from my side. |
…e instead of stripping them per site Round-three review follow-up on #5775, the one observation with something to act on. "buildGraphNow" was removed at two sites - the IF NOT EXISTS reader and the LSM_VECTOR creation branch - because it directs the statement rather than configuring the index, so no index stores it and everything that reads the clause as configuration rejects it: fromUserMetadata refuses an unknown key, and the guarded comparison would report a mismatch for something an existing index cannot have. Both turn a well-formed statement into a 400. The key space is now one named DIRECTIVE_METADATA_KEYS set behind a stripDirectives() helper, so a future "do X now" key on another index type has an obvious place to be declared rather than being stripped at whichever site happens to notice it. No behaviour change: the same one key is removed in the same two places. Two other observations in that review need no change and are recorded here as judged: a future setter that cross-validates one METADATA key against another could validate against the default rather than the existing index's value when only one of the pair is named (no such coupling exists - every setter validates its own value), and the per-100k progress logging interval is already where it should be.
|
Thanks. One of the four had something to act on; the other three are compliments or forward-looking notes that need no change. 9735b71. 2. Directive-only keys - done. You're right that this deserved to be a convention rather than a habit: 3. 1 and 4 - no action. Tests re-run after the refactor: 50/50 green across the manual-index, settings-comparison, #5675 and DDL-parser suites. That is every point from all three rounds either implemented or judged with a reason, and no round raised a blocking concern - so this is ready for your review whenever you want it. |
Review of #5765 fix: manual index creation + guarded-request settings comparisonI read all four commits and traced the changed engine paths ( Strengths
The one thing to confirm before merge (already flagged BREAKING)The Minor / non-blocking
Security / performanceNo security concerns: the Verification I did / did not doI verified the referenced APIs exist and are used correctly ( Nice work - this is a thorough fix that leaves the paths better documented than it found them. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5775 +/- ##
==========================================
+ Coverage 67.77% 67.87% +0.10%
==========================================
Files 1783 1783
Lines 151332 151370 +38
Branches 32100 32108 +8
==========================================
+ Hits 102562 102748 +186
+ Misses 35491 35328 -163
- Partials 13279 13294 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ReviewI read through the full diff and traced the touched paths in Verified as correct
One thing worth a look (minor)There is an asymmetry for a plain ( CREATE INDEX ON Doc (x) NOTUNIQUE METADATA {"foo": 1}; -- succeeds, silently ignores foo
CREATE INDEX IF NOT EXISTS ON Doc (x) NOTUNIQUE METADATA {"foo": 1}; -- now 400So a re-runnable script that previously worked can start failing on its second run for a plain index. It is an edge case (metadata on a plain index is meaningless), but the create/guarded-recreate inconsistency is a little surprising. Two clean options: skip the comparison when the index type declares no user-metadata keys, or validate metadata on the plain-index creation path too so both ends agree. Notes (not blockers)
Style / conventionsAdheres well to the repo conventions: Overall: solid, well-reasoned work. Only the plain-index + Reviewed by Claude Code. |
…ase, and a guarded request answers for the index asked for (#5775) * fix(engine) #5765: creating a manual index no longer fences the database, and a guarded request answers for the index asked for ManualIndexBuilder.create() registered the new index's file under `index instanceof PaginatedComponent`, a test that never matched: LSMTreeIndex and HashIndex WRAP their paginated component rather than being one. The file stayed unknown to the schema, and the commit that creates it then failed resolving that file id AFTER its WAL append - which fences the database for recovery (#5053). Every manual index creation ended there, and the builder's own error callback threw on the fenced database, replacing the real cause with a bare fence error. Registration goes through index.getComponent() now, the same accessor the type-index path uses, and the cleanup callback no longer throws. Three defects the first one hid, each found by fixing the previous: - Schema.createManualIndex(indexType, ...) dropped its indexType argument, so every call through that deprecated overload failed with a NullPointerException inside the index factory. - A UNIQUE manual index could not commit an entry: TransactionIndexContext's lock collection and its uniqueness check both resolved the index's type name to reach the polymorphic index over the same properties, and a manual index has neither. It is now recognised as its own whole search space, which it is. - withNullStrategy(null) installed the null instead of leaving the default, and the index constructor refused it with "Index null strategy is null". null now means "not specified", the convention withPageSize already follows. An index kind that cannot be built without a type (FULL_TEXT, GEOSPATIAL, LSM_VECTOR, LSM_SPARSE_VECTOR) is refused by name instead of failing inside the factory with a NullPointerException or a ClassCastException. The guarded branch still carried the two defects #5675 removed from TypeIndexBuilder: a request differing only in uniqueness DROPPED the existing index behind a dead `x != null && x == null` null-strategy test, and the index kind was not compared at all. It follows the same rule as the type path now. There is no withReplaceIfIncompatible here: the setter raises on a manual builder, because the replacement it authorises elsewhere is a rebuild from the type's records and here it would be an unrecoverable delete of the only copy of the entries. fix(engine) #5765: CREATE INDEX IF NOT EXISTS compares the settings the METADATA clause named The guard compared the structural definition only - kind and uniqueness - so a guarded statement asking for 768 dimensions over a 384-dimension vector index was a silent no-op, and every vector written afterwards went unindexed. Same for full-text analyzers and geospatial precision. Only the settings the clause actually NAMED are compared, so a statement with no METADATA compares none and stays the no-op it has always been. The clause is read through the index type's own reader before comparing, so "384" and 384, "cosine" and COSINE are the one value each denotes. Both entry points ask the same question through one helper: the IF NOT EXISTS shortcut of CreateIndexStatement, which answers before a builder exists, and TypeIndexBuilder.create(). The read side of each per-type key set is covered by a test that fails if a key is added to one list and not the other. test(engine) #5765: poll for the vector rebuild instead of sleeping a fixed interval Two Thread.sleep(6_000) + hard assertion pairs in LSMVectorIndexRecoveryTest, and the ceilings in LSMVectorIndexRebuildTest computed as a multiple of the inactivity timeout - which makes the wait shortest exactly where the work is slowest. Four of them failed in a whole-package run here and passed in isolation. They share one absolute ceiling now; the class also runs faster, since a poll returns as soon as the rebuild lands. chore(engine) #5765: CREATE INDEX and REBUILD INDEX log their progress instead of printing dots to stdout * docs(engine) #5765: mark the guarded-create settings comparison BREAKING, and say why the builder path does not re-wrap the clause Review follow-ups on #5775, both documentation-level. - The release note now frames the settings comparison as what it is for anyone with a re-runnable schema script: a guarded CREATE INDEX naming a setting MAY NOW RAISE where it used to be a no-op, including for the runtime-tunable keys a rebuild would not be needed to change (efSearch, mutationsBeforeRebuild, inactivityRebuildTimeoutMs, the cache sizes). Both ways back to an idempotent statement are spelled out: drop the keys the script does not actually require, or align the value with the existing index. - TypeIndexBuilder.create() calls findUnsatisfiedSettings without the try/catch the CreateIndexStatement shortcut wraps its own call in, and the invariant that makes that safe is now written down rather than implied: the SQL branches call withMetadata and withUserMetadata inside one try, so the clause has already been read - and any unreadable value already reported - before create() runs. A caller that sets the user clause without the parsed one has skipped that validation and gets the reader's own message; there is no such caller, and adding a second error path would only re-type an exception the reader already words correctly. Verified against the review's third ask: no CREATE INDEX IF NOT EXISTS with a METADATA clause exists outside engine/, and RemoteSchema.getOrCreateTypeIndex builds its guarded statement without one, so nothing outside the engine reaches the new comparison. Server module re-run against a freshly installed engine: 687 tests, 0 failures. * fix(engine) #5765: copy the user METADATA clause into the builder, and assert the file registration directly Round-two review follow-ups on #5775. - withUserMetadata deep-copies the clause. The callers hand the SAME JSONObject to withMetadata(JSONObject) and to withUserMetadata, and the two are read at different times: the first now, the second at create(). No withMetadata overload mutates it today - all four read it through fromUserMetadata - but the copy costs nothing at DDL time and means a future one could not silently change what a guarded request ends up comparing against. - A test asserts the registration itself rather than inferring it from the other tests happening to run. The index's file must resolve through the schema by its id, which is the call TransactionContext.commit2ndPhase makes for every file whose page count changed - past the WAL append, which is why an unregistered file fenced the database instead of failing the creation. The test pins the cause (getFileById resolves to the index's own component) and the consequence (the database still commits an unrelated write afterwards, which a fenced one cannot). Mutation-checked: restoring the `instanceof PaginatedComponent` test reproduces "commit of tx 4 failed after its WAL append". Three other review points taken as no-action, with reasons: refusing runtime-tunable settings on a guarded create is the intended semantics and is already documented as BREAKING; the TypeIndexBuilder invariant comment is the right mitigation for a caller shape that does not exist; and the mismatch message wording is already covered by tests. * refactor(engine) #5765: declare the METADATA statement directives once instead of stripping them per site Round-three review follow-up on #5775, the one observation with something to act on. "buildGraphNow" was removed at two sites - the IF NOT EXISTS reader and the LSM_VECTOR creation branch - because it directs the statement rather than configuring the index, so no index stores it and everything that reads the clause as configuration rejects it: fromUserMetadata refuses an unknown key, and the guarded comparison would report a mismatch for something an existing index cannot have. Both turn a well-formed statement into a 400. The key space is now one named DIRECTIVE_METADATA_KEYS set behind a stripDirectives() helper, so a future "do X now" key on another index type has an obvious place to be declared rather than being stripped at whichever site happens to notice it. No behaviour change: the same one key is removed in the same two places. Two other observations in that review need no change and are recorded here as judged: a future setter that cross-validates one METADATA key against another could validate against the default rather than the existing index's value when only one of the pair is named (no such coupling exists - every setter validates its own value), and the per-100k progress logging interval is already where it should be. (cherry picked from commit 0b2ccfb)
Closes #5765.
All four items of the issue, plus four defects found while fixing item 1 - each of which the previous one was hiding.
Item 1 was sitting on top of a bigger one:
buildManualIndex(...).create()did not work at allManualIndexBuilder.create()registered the new index's file underindex instanceof PaginatedComponent. That test never matched:LSMTreeIndexandHashIndexwrap their paginated component rather than being one. The file stayed unknown to the schema, and the commit that creates it then failed resolving that file id - after its WAL append, which fences the whole database for recovery (#5053):Worse, the builder's own error callback then called
drop()on the fenced database, so the exception the caller saw was a bare fence error with the real cause nowhere in it. Registration goes throughindex.getComponent()now - the same accessor the type-index path uses - and the cleanup callback logs instead of throwing.Three more defects, each surfaced by fixing the one before it:
Schema.createManualIndex(indexType, ...)dropped itsindexTypeargument, so every call through that deprecated overload failed with aNullPointerExceptioninside the index factory.UNIQUEmanual index could not commit an entry. BothTransactionIndexContext.addFilesToLockandcheckUniqueIndexKeysresolved the index's type name to reach the polymorphic index over the same properties; a manual index has neither, and the null reachedgetType(). A manual index is now recognised as its own whole search space, which it is - nothing else indexes its keys.withNullStrategy(null)installed the null instead of leaving the default, and the index constructor refused it with "Index null strategy is null".nullnow means "not specified", the conventionwithPageSizealready follows.An index kind that cannot be built without a type (
FULL_TEXT,GEOSPATIAL,LSM_VECTOR,LSM_SPARSE_VECTOR) is refused by name instead of failing inside the factory with aNullPointerExceptionor aClassCastException.The
IF NOT EXISTShalf, as filedThe guarded branch carried the two defects #5675 removed from
TypeIndexBuilder: a request differing only in uniqueness dropped the existing index and recreated it (behind the deadx != null && x == nullnull-strategy test), and the index kind was not compared at all. It follows the same rule as the type path now.One departure from the issue's suggestion, deliberately. There is no
withReplaceIfIncompatibleopt-in on this path - the setter raisesUnsupportedOperationExceptionon a manual builder. On a type index the replacement is a rebuild from the type's records; a manual index has no records behind it, so the same operation is an unrecoverable delete of the only copy of its entries. Refusing at the setter rather than atcreate()puts the answer at the call that expresses the intent.One correction to the issue text
Item 1 says the defect is "reachable through
Schema.buildManualIndex(...), includingRemoteSchema". It is not:RemoteSchema.buildManualIndexandRemoteSchema.createManualIndexboth throwUnsupportedOperationException. This is embedded-API only.Item 3:
IF NOT EXISTScompares the settings theMETADATAclause namedEvery vector written afterwards is 768 long, none is indexed, and nothing said so.
Only the settings the clause actually NAMED are compared, which is what keeps this from reaching any statement that did not ask for it: a guarded statement with no
METADATAnames nothing and stays the plain no-op it has always been. Everything named IS compared, including the tuning knobs a rebuild would not be needed to change - writing a value into a statement and having it silently discarded is the surprise being removed, and a caller who means the no-op leaves the key out.The clause is read through the index type's own reader before comparing, so
{"dimensions": "384"}matches384and{"similarity": "euclidean"}matchesEUCLIDEAN. Both entry points ask through one helper - theIF NOT EXISTSshortcut ofCreateIndexStatement, which answers before a builder exists, andTypeIndexBuilder.create().The read side of each per-type key set (
getUserMetadataValue) mirrorsapplyUserMetadata, and a setting present in only one of the two would fail silently - an unreadable key compares null against null.IndexMetadataUserSettingComparisonTestcloses that: each key gets a pair of distinct valid values, so it does not depend on knowing any default, and adding a key togetUserMetadataKeys()without adding it there fails the key-set assertion.Item 2: the vector rebuild waits
The two
Thread.sleep(6_000)+ hard-assertion pairs are Awaitility now. I extended the same treatment toLSMVectorIndexRebuildTest: four of its tests failed in a whole-package run here and passed in isolation, the exact shape the issue describes. Their ceilings were computed as a multiple of the inactivity timeout, which makes the wait shortest exactly where the work is slowest - what varies under load is how long the rebuild takes, not how long the timer waits before starting it. They share one absolute ceiling now, and the class also got faster (24.6s -> 16.7s), since a poll returns as soon as the rebuild lands.Item 4
CREATE INDEXandREBUILD INDEXlog their per-100k progress instead of printing a dot toSystem.out.Verification
Issue5765ManualIndexIfNotExistsTest(12),Issue5765IndexSettingsIfNotExistsTest(8),IndexMetadataUserSettingComparisonTest(7)TransactionIndexContextguard, thewithType, or the guarded-branch rule fails a test🤖 Generated with Claude Code
https://claude.ai/code/session_01W8C35vrQkW1y1gaEvWzRPc