Repository navigation
fix(engine) #5723: a copied type keeps its index definitions, its records' content, and index entries - #5734
Conversation
…ords' content, and index entries `Schema.copyType()` was reported as resetting every index's page size on the copy. It did, and that turned out to be the least of it: the same thirty lines held three defects, and the two that were not reported are the ones that made the copy wrong rather than differently tuned. The copy had no data in its indexes. They were created inside the record-copy transaction, and each bucket's build runs in its own `joinCurrent=false` transaction, which from inside an enclosing one neither sees the records still pending in it nor commits the entries it produces. Every index on the copy came out empty, so any query the planner routed through one answered nothing. The build now runs after the copy has committed. The copied records were empty. `ImmutableDocument.propertiesAsMap()` was the one accessor of that class that did not lazy-load: it answered an empty map whenever the record had not been materialised, which is the state of every record from `iterateType()` / `scanBucket()`. `copyType()` created the right number of records, each with no properties. Same silent emptiness for a `DetachedDocument` built off a scan. And the index definitions were rebuilt from three attributes. The three-argument `createTypeIndex` overload kept the index type, the uniqueness flag and the property list, and defaulted the tuned page size, the null strategy, the collations, and the whole type-specific configuration - a copied FULL_TEXT index ranked with the default analyzer, a copied GEOSPATIAL one dropped to the default resolution, a copied LSM_VECTOR one came up with dimensions 0. Carrying a definition into a new index file gets an accessor of its own, `IndexInternal.getMetadataForNewFile()`, alongside the `getPageSizeForNewFile()` #5713 introduced. `getMetadata()` cannot answer it for the wrapper index types: the full-text analyzers live on `FullTextIndexMetadata` and the geospatial resolution on plain fields, while `getMetadata()` delegates to the underlying LSM-Tree. `IndexMetadata.copy()` is now polymorphic across all five metadata classes, so no field list can be forgotten; per-index runtime state (the vector build state, the full-text corpus counters) deliberately does not ride along, since the new file starts empty.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
🟢 Coverage 82.81% diff coverage · -6.83% coverage variation
Metric Results Coverage variation ✅ -6.83% coverage variation Diff coverage ✅ 82.81% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (57b73c2) 150808 115267 76.43% Head commit (0867503) 182975 (+32167) 127358 (+12091) 69.60% (-6.83%) 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 (#5734) 64 53 82.81% 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.
Code Review - PR #5734Thorough, well-diagnosed change. The write-up traces three distinct defects hiding behind one reported symptom, each is root-caused rather than patched, and the regression coverage is genuinely strong (behavioural assertions like the English-stem lookup and the spatial query prove the effect of the carried-over configuration, not just a persisted attribute). A few observations, mostly confirmations with a couple of things worth a conscious decision. Design - the parts I like
Things worth a deliberate decision
Minor
Test coverageStrong. The 8 cases plus the lazy-loading regression cover page size (LSM_TREE and the HASH validating path), null strategy, CI collation, full-text analyzer/BM25, geospatial precision, vector dimensions, and the manual-name non-collision, and defect 1 (empty indexes) is asserted both via The deferred carry-over sites ( Overall: solid fix, good tests, ready modulo the small clarifications above. Automated review by Claude - please verify independently. |
…pe atomicity contract, unresolvable-RID test Review follow-ups on #5734. `LSMTreeGeoIndex.getMetadataForNewFile()` reassembled the definition by hand, copying the base fields the metadata hierarchy already knows how to copy. Moved into `GeoIndexMetadata.from(base, precision, tokenization)`, where `copyCommonTo()` is reachable, so the wrapper reads like its full-text and sparse-vector siblings. It cannot simply return a stored instance the way they do: this class holds the resolution and the layout as plain fields and its underlying LSM-Tree carries only a base `IndexMetadata`, which is why the override exists at all. `copyType()` now documents that it is deliberately not atomic. The index build has to run outside the record-copy transaction to see the records, which puts a commit boundary mid-operation; the `catch` that drops the new type is the safety net that makes that acceptable, and the source type is only ever read. Added a case asserting `propertiesAsMap()` REPORTS a record whose RID no longer resolves rather than answering an empty map. That is the deliberate half of the lazy-loading change - the same contract the other accessors of the class have carried since #2560 - and it was worth pinning down rather than leaving to be inferred. Left as is: the second `buffer.position()` in `propertiesAsMap()` reads redundant but is not. `checkForLazyLoading()` leaves the buffer at 0 when an after-read event returns a different record and the buffer is re-serialised, so removing it would break the encryption path. Commented in place so it survives the next reader.
Code ReviewReviewed the full diff against the source. This is a strong, carefully-scoped fix. The root-cause analysis (three distinct defects in the same ~30 lines) is accurate, and each fix is targeted rather than papered over. A few notes below, mostly praise plus a couple of minor observations. What's done well
Minor observations (non-blocking)
ScopeLeaving I was unable to run the compile/test suite in this environment (build command not permitted here), so I'm relying on the local run reported in the description ( Nice work - the fix generalizes correctly and the tests assert behavior, not just fields. Automated review by Claude Code. |
Review follow-up on #5734. The SEVERE log in copyType() read "Error on renaming type", which is what sent issue #5723 to a renameType() that does not exist - a rename goes through LocalDocumentType.rename(), renames buckets in place, and never recreates an index. Nothing here renames anything and the source type is still there afterwards, so the message now says what happened. The genuinely-renaming messages in LocalDocumentType and LocalVertexType are correct as they stand and are left alone.
Review: #5734 - copyType keeps index definitions, record content, and index entriesReviewed the full diff and traced the touched paths ( A few observations, mostly minor. 1. Test coverage gap: the motivating conversion is document -> vertex, but no test copies to a vertex typeEvery case in 2.
|
…index name across a truncate Review follow-ups on #5734, both closing coverage gaps rather than changing behaviour. The conversion that motivates copyType() is document to vertex, and it takes the other branch of the record-copy loop, which every existing case missed: they all copy to a document type. The new case asserts the copy is a vertex type, its index is populated, and the record content came across. `LSMVectorIndexMetadata.copy()` carried only the collations before this PR and now goes through `copyCommonTo()`, which also carries the user-supplied index name. That reaches one caller outside copyType(): TRUNCATE TYPE, which drops and recreates the index from its own definition. Confirmed by test that a manually named LSM_VECTOR index now keeps its name across a truncate along with its dimensions and similarity, where it previously reverted to the auto-derived form. Mutation-checked: dropping the typeIndexName line from copyCommonTo() makes the new case fail. Left alone: the `metadata != null` branch in TypeIndex.getMetadataForNewFile() is indeed unreachable today - both setMetadata overloads throw - but it mirrors getMetadata() exactly, and the two should not drift if that field ever becomes assignable.
Review: #5734 - copyType keeps index definitions, record content, and index entriesReviewed the full diff plus the surrounding call sites ( What I verified as correct
Worth a second look (non-blocking)
Minor / style
TestsExcellent coverage - page size (LSM + HASH validating path), null strategy, CI collation asserted through a case-insensitive lookup, full-text analyzer/BM25 asserted through an English-stem query, geospatial precision through a spatial query, vector dimensions/similarity, manual-name non-collision, the vertex-conversion branch, and Overall: well-reasoned, well-tested, ready to merge once the maintainer is comfortable with the TRUNCATE-name behavior change noted in (1). |
…release notes Review follow-up on #5734. Routing LSMVectorIndexMetadata.copy() through the shared copyCommonTo() also carries the user-supplied index name, and that reaches TRUNCATE TYPE: a manually named LSM_VECTOR index now keeps its name across a truncate instead of coming back auto-derived. It is a fix and it is covered by a test, but it is the one effect of this PR outside copyType(), so it belongs in the notes rather than being left for someone to discover.
|
Responses to the latest review. (1) The TRUNCATE-name behaviour change is real, is a fix, and is covered by (2) The
// Extract from WHERE clause
if (info.whereClause != null) {
// WHERE can reference arbitrary fields, so we need all properties if we can't analyze it
// For safety, return null to indicate all properties needed
return null;
}
I removed the test rather than keep one that asserts nothing. The dead branch is pre-existing and out of scope here; it would be worth either wiring the push-down up or deleting it, separately. (3) (4) |
Review: #5734 - copyType keeps index definitions, record content, and index entriesI read the full diff and traced the touched paths ( Strengths
Observations / things to confirm
Style / minor
Nice work - the diagnosis-by-experiment note ("moving the loop back inside the transaction reproduces |
|
Follow-up filed as #5742: the four remaining carry-over sites ( |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5734 +/- ##
==========================================
+ Coverage 67.62% 67.65% +0.03%
==========================================
Files 1776 1776
Lines 150808 150951 +143
Branches 32002 32026 +24
==========================================
+ Hits 101978 102125 +147
+ Misses 35579 35551 -28
- Partials 13251 13275 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ords' content, and index entries (#5734) * fix(engine) #5723: a copied type keeps its index definitions, its records' content, and index entries `Schema.copyType()` was reported as resetting every index's page size on the copy. It did, and that turned out to be the least of it: the same thirty lines held three defects, and the two that were not reported are the ones that made the copy wrong rather than differently tuned. The copy had no data in its indexes. They were created inside the record-copy transaction, and each bucket's build runs in its own `joinCurrent=false` transaction, which from inside an enclosing one neither sees the records still pending in it nor commits the entries it produces. Every index on the copy came out empty, so any query the planner routed through one answered nothing. The build now runs after the copy has committed. The copied records were empty. `ImmutableDocument.propertiesAsMap()` was the one accessor of that class that did not lazy-load: it answered an empty map whenever the record had not been materialised, which is the state of every record from `iterateType()` / `scanBucket()`. `copyType()` created the right number of records, each with no properties. Same silent emptiness for a `DetachedDocument` built off a scan. And the index definitions were rebuilt from three attributes. The three-argument `createTypeIndex` overload kept the index type, the uniqueness flag and the property list, and defaulted the tuned page size, the null strategy, the collations, and the whole type-specific configuration - a copied FULL_TEXT index ranked with the default analyzer, a copied GEOSPATIAL one dropped to the default resolution, a copied LSM_VECTOR one came up with dimensions 0. Carrying a definition into a new index file gets an accessor of its own, `IndexInternal.getMetadataForNewFile()`, alongside the `getPageSizeForNewFile()` #5713 introduced. `getMetadata()` cannot answer it for the wrapper index types: the full-text analyzers live on `FullTextIndexMetadata` and the geospatial resolution on plain fields, while `getMetadata()` delegates to the underlying LSM-Tree. `IndexMetadata.copy()` is now polymorphic across all five metadata classes, so no field list can be forgotten; per-index runtime state (the vector build state, the full-text corpus counters) deliberately does not ride along, since the new file starts empty. * fix(engine) #5723: address code review - geo metadata factory, copyType atomicity contract, unresolvable-RID test Review follow-ups on #5734. `LSMTreeGeoIndex.getMetadataForNewFile()` reassembled the definition by hand, copying the base fields the metadata hierarchy already knows how to copy. Moved into `GeoIndexMetadata.from(base, precision, tokenization)`, where `copyCommonTo()` is reachable, so the wrapper reads like its full-text and sparse-vector siblings. It cannot simply return a stored instance the way they do: this class holds the resolution and the layout as plain fields and its underlying LSM-Tree carries only a base `IndexMetadata`, which is why the override exists at all. `copyType()` now documents that it is deliberately not atomic. The index build has to run outside the record-copy transaction to see the records, which puts a commit boundary mid-operation; the `catch` that drops the new type is the safety net that makes that acceptable, and the source type is only ever read. Added a case asserting `propertiesAsMap()` REPORTS a record whose RID no longer resolves rather than answering an empty map. That is the deliberate half of the lazy-loading change - the same contract the other accessors of the class have carried since #2560 - and it was worth pinning down rather than leaving to be inferred. Left as is: the second `buffer.position()` in `propertiesAsMap()` reads redundant but is not. `checkForLazyLoading()` leaves the buffer at 0 when an after-read event returns a different record and the buffer is re-serialised, so removing it would break the encryption path. Commented in place so it survives the next reader. * fix(engine) #5723: copyType's failure log says copying, not renaming Review follow-up on #5734. The SEVERE log in copyType() read "Error on renaming type", which is what sent issue #5723 to a renameType() that does not exist - a rename goes through LocalDocumentType.rename(), renames buckets in place, and never recreates an index. Nothing here renames anything and the source type is still there afterwards, so the message now says what happened. The genuinely-renaming messages in LocalDocumentType and LocalVertexType are correct as they stand and are left alone. * test(engine) #5723: cover the document-to-vertex copy and the vector index name across a truncate Review follow-ups on #5734, both closing coverage gaps rather than changing behaviour. The conversion that motivates copyType() is document to vertex, and it takes the other branch of the record-copy loop, which every existing case missed: they all copy to a document type. The new case asserts the copy is a vertex type, its index is populated, and the record content came across. `LSMVectorIndexMetadata.copy()` carried only the collations before this PR and now goes through `copyCommonTo()`, which also carries the user-supplied index name. That reaches one caller outside copyType(): TRUNCATE TYPE, which drops and recreates the index from its own definition. Confirmed by test that a manually named LSM_VECTOR index now keeps its name across a truncate along with its dimensions and similarity, where it previously reverted to the auto-derived form. Mutation-checked: dropping the typeIndexName line from copyCommonTo() makes the new case fail. Left alone: the `metadata != null` branch in TypeIndex.getMetadataForNewFile() is indeed unreachable today - both setMetadata overloads throw - but it mirrors getMetadata() exactly, and the two should not drift if that field ever becomes assignable. * docs(engine) #5723: state the TRUNCATE TYPE index-name change in the release notes Review follow-up on #5734. Routing LSMVectorIndexMetadata.copy() through the shared copyCommonTo() also carries the user-supplied index name, and that reaches TRUNCATE TYPE: a manually named LSM_VECTOR index now keeps its name across a truncate instead of coming back auto-derived. It is a fix and it is covered by a test, but it is the one effect of this PR outside copyType(), so it belongs in the notes rather than being left for someone to discover. (cherry picked from commit 4140df2)
…ite (ArcadeData#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 ArcadeData#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.
Closes #5723.
The issue reports that
LocalSchema.copyType()loses the page size of every index on the copy. It does. Writing the regression test for it surfaced two more defects in the same thirty lines, and they are the ones that make the copy wrong rather than differently tuned.(The issue names
renameType(). There is no such method:ALTER TYPE ... NAME ...goes throughLocalDocumentType.rename(), which renames buckets in place and never recreates an index. The affected method iscopyType(), which is what a document-to-vertex conversion goes through.)1. Every index on the copy came out EMPTY
The indexes were created inside the transaction that copies the records.
TypeIndexBuilder.create()builds each bucket's index in its own transaction (joinCurrent=false), which from inside an enclosing transaction neither sees the records still pending in it nor commits the entries it produces. So the copy carried indexes with zero entries, and any query the planner routed through one answered nothing - silently, since an empty index is indistinguishable from a type with no matching rows.Verified by experiment, not by reading: moving the loop back inside the transaction reproduces
entries=0exactly.2. The copied records were EMPTY
ImmutableDocument.propertiesAsMap()was the one accessor of that class that did not callcheckForLazyLoading()- it returnedCollections.emptyMap()wheneverbuffer == null, which is the state of every record handed out byiterateType()andscanBucket().copyType()reads each source record that way, so it faithfully created the right number of records, each with no properties. The same silent emptiness hit aDetachedDocumentbuilt off a record straight from a scan.It now loads first, like
get(),has(),getPropertyNames(),toMap()andtoJSON()already did. The empty map remains the answer only for a record that genuinely cannot be materialised (no database, no RID, or an after-read event that filtered it away), so the class's exception-propagation contract from #2560 is preserved - the two new entries inImmutableDocumentLazyLoadingInconsistencyTest's accessor list assert exactly that.3. The reported one, wider than reported
The copy went through the three-argument
createTypeIndexoverload, so the index type, the uniqueness flag and the property list survived and everything else was replaced by a default: the tuned page size from the report, the null strategy, the collations that make a lookup case-insensitive, and the entire type-specific configuration. That last one is not a tuning difference - a copiedFULL_TEXTindex tokenized and ranked with the default analyzer, a copiedGEOSPATIALindex dropped to the default geohash resolution, and a copiedLSM_VECTORindex came up withdimensions0.The better alternative to the suggested fix
The issue suggests passing
getPageSizeForNewFile()through. That fixes one attribute of five and leaves a copied full-text or vector index broken, so the fix generalises the accessor instead of the call:IndexInternal.getMetadataForNewFile(), the companion of thegetPageSizeForNewFile()that HASH index silently corrupts when created with a page size above 65536 (16-bit slot offsets, no validation) #5713 introduced. It exists becausegetMetadata()cannot answer this question for the wrapper index types:LSMTreeFullTextIndexkeeps its analyzers and BM25 parameters in its ownFullTextIndexMetadataandLSMTreeGeoIndexkeeps its resolution and layout in plain fields, while bothgetMetadata()s delegate to the underlying LSM-Tree and hand back a definition with none of it.IndexMetadata.copy(typeName, propertyNames, bucketId)promoted fromLSMVectorIndexMetadatato a polymorphic method with overrides on all four subclasses, plus afinal copyCommonTo()for the shared fields. There is no second field list to keep in sync, which is the point. Per-index RUNTIME state deliberately does not ride along - the dense vector index's build state, the full-text corpus counters - because the new file starts empty and inherited statistics would describe a different set of records.A user-supplied index name is the one attribute deliberately not carried over: it is unique across the schema and still belongs to the source type, so the copy takes the auto-derived
NewType[properties]form rather than colliding with it.Deliberately out of scope
The other sites that rebuild an index from its own definition -
TruncateTypeStatement,DatabaseChecker(CHECK DATABASE FIX), and bothLocalDocumentTypepropagation paths - still readgetMetadata()and so still lose a full-text or geospatial configuration. Each is a distinct user-visible operation that deserves its own regression test and its own blast radius, which is the same reasoning #5723 used to split itself off from #5717; a follow-up issue tracks them.RebuildIndexStatementis already correct - it reconstructs the typed metadata from the persisted JSON - and could now use the new accessor instead, but that is a refactor with no behaviour change.Tests
Issue5723CopyTypeIndexConfigurationTest(new, 8 cases): page size onLSM_TREEand onHASH(where the value goes back through the validating creation path #5713 added), null strategy, CI collation asserted through a case-insensitive lookup on the copy, full-text analyzer/BM25/operator asserted through an English-stem lookup, geospatial precision asserted through a spatial query, vector dimensions and similarity, and the manual-index-name non-collision. Plusentries == 1on the copy, which is what catches defect 1.ImmutableDocumentLazyLoadingInconsistencyTest:propertiesAsMap()andpropertiesAsMap(fields)added to the exception-propagation and happy-path accessor lists, and a new case asserting a record straight offiterateType()answers its properties.Verified locally:
com.arcadedb.query.**10330 tests 0 failures,com.arcadedb.database.**176 tests 0 failures,com.arcadedb.schema.** + com.arcadedb.index.**942 tests with one unrelated timing flake (LSMVectorIndexRecoveryTest#vectorNeighborsShouldReturnCorrectCountAfterIncrementalInsertAndRebuild, an inactivity-rebuild deadline assertion, passes in isolation),com.arcadedb.graph.** + com.arcadedb.serializer.**336 tests 0 failures.🤖 Generated with Claude Code
https://claude.ai/code/session_01FjD6rXVew2fQhhh8n44GAz