Repository navigation
fix(#8169): DROP TYPE deregisters the type's ALIASES, so the dropped type is not re-serialised into schema.json - #8195
Conversation
…type is not re-serialised into schema.json LocalSchema.dropType removed exactly one key from the schema's shared type map - the type's own name - and nothing removed the alias keys, which kept pointing at the dropped, bucket-less LocalDocumentType instance. serializeConfiguration() iterates typeMap().values() and keys each entry by t.getName(), so the dropped instance - still reachable through its surviving alias key - was written back into schema.json under its own name with an empty bucket list and came back alive, unusable, at the next open. It also kept existsType(alias) answering true, made a later ALTER TYPE ... ALIASES refuse the alias while naming a type that no longer existed, and left the instance in getTypes(), which is what CHECK DATABASE walks. The drop resolves its argument through getType(), which resolves aliases, so the raw argument was also the wrong thing to compare: DROP TYPE <alias> walked past the materialized-view and continuous-aggregate guards and past the typeBeingDropped suppression, both of which compare against a canonical name. Deregister every name the type answers to, with the two-argument remove(key, value) setAliases already uses so a name since taken over by another type is not taken away from it, and resolve the canonical name once up front for the guards and the suppression flag. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 3 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ -6.19% coverage variation |
| Diff coverage | ✅ 100.00% diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (382ae09) 187750 156313 83.26% Head commit (c294d60) 220299 (+32549) 169765 (+13452) 77.06% (-6.19%) 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 (#8195) 10 10 100.00% 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.
ReviewSolid, well-targeted fix. Correctness
Nit
Test coverageGood breadth: in-memory dedup ( PR description mismatchThe PR title and diff are about issue #8169 (DROP TYPE/aliases), but the PR body's summary, test plan, and "Coverage"/"Adversarial pass" sections all describe a different change - a Note: I wasn't able to execute |
…t, and cover the continuous-aggregate alias guards The comment carried "serializeConfiguration()" over from the issue report; no such method exists in LocalSchema. The loop that re-serialised the dropped type lives in toJSON(), which saveConfiguration() reaches through update(toJSON()). Corrected in the production comment, the test javadoc and the test's inline comment. The materialized-view alias guard had a test and its continuous-aggregate twin did not. Added one for the source type and one for the backing type; both fail against a build with only the two ca. comparisons reverted to the raw argument, so they reach the branch they name. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ReviewI read the change against the surrounding code (guard call sites, Correctness — looks right
Test coverage — thoroughThe new test class covers the direct bug ( One gap acknowledged directly in the PR description that's worth flagging for visibility rather than blocking: the fix doesn't repair a Minor / non-blocking
Style / conventions
Overall: solid, well-scoped fix with unusually thorough regression coverage and an honest accounting of what isn't covered. No blocking issues found. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8195 +/- ##
=========================================
Coverage 74.92% 74.93%
Complexity 2602 2602
=========================================
Files 2004 2004
Lines 187750 187754 +4
Branches 39270 39272 +2
=========================================
+ Hits 140677 140695 +18
+ Misses 31476 31464 -12
+ Partials 15597 15595 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #8169
Summary
LocalSchema.dropTyperemoved exactly one key from the schema's shared type map - the type's own name - andnothing anywhere removed the alias keys, which kept pointing at the dropped, bucket-less
LocalDocumentTypeinstance. The damaging consequence is not the stale lookup:
toJSON(), reached fromsaveConfiguration(),iterates
typeMap().values()and keys each entry byt.getName(), so the dropped instance - still reachablethrough its surviving alias key - was written back into
schema.jsonunder its own name with an empty bucketlist, and came back alive, unusable, at the next open. The drop also resolves its argument through
getType(),which resolves aliases, so the raw argument was the wrong thing to compare and the wrong thing to remove
whenever the caller named the type by one of its aliases. The fix deregisters every name the type answers to,
with the two-argument
remove(key, value)thatsetAliasesalready uses so a name since taken over by anothertype is not taken away from it, and resolves the canonical name once up front for the three places in
dropTypethat were comparing the caller's string against a canonical one.Test plan
mvn -o -pl engine test -Dtest=Issue8169DropTypeLeavesAliasesTest- 8 tests, all of which fail onmainmvn -o -pl engine test -Dtest='com.arcadedb.schema.*Test,MaterializedView*Test,ContinuousAggregate*Test'- 759 passmvn -o -pl engine clean test -DexcludedGroups=benchmark,vector,slow- 16177 tests, 0 failures, 22 skippedCREATE DOCUMENT TYPE Order; ALTER TYPE Order ALIASES PO; DROP TYPE Order;then reopen thedatabase -
existsType("Order")andexistsType("PO")both answerfalse, andschema.jsoncarries onlythe surviving types
ALTER TYPE Invoice ALIASES POsucceeds instead of being refused with"already used by type 'Order'"
Completeness
The invariant
The sweep
Every mutation of the shared type map in the tree:
LocalSchema.java:2514is the only remover that can leave a key behind, and it is the one this PR changes.The
LocalDocumentTypesites are all two-argument removes already and all belong torename()andsetAliases(), neither of which removes a type.Every reader that iterates the map's values, which is what makes a stale key damaging rather than merely wrong:
:3586is the resurrection: it is the loop insidepublic synchronized JSONObject toJSON(), whichsaveConfiguration()reaches throughupdate(toJSON())- anddropType's ownfinallycallssaveConfiguration().:2401is whygetTypes()listed the dropped type, which is in turn whyCHECK DATABASEwalked it: the run that proved the tests fail onmainshowsDatabaseChecker.checkDocuments -> countType -> SchemaException: Type with name 'Order' was not foundin every suppressed stack.
Every caller of
dropTypein the tree:All of them reach the single
LocalSchema.dropTypethis PR fixes;RemoteSchema.dropTypeissuesDROP TYPE <name>as SQL and has no separate server path.Entry-point coverage
LocalSchema.dropType(<own name>)leaves alias keys in the mapdropTypeDeregistersTheTypeAliasesDROP TYPE <name>->DropTypeStatement.executeDDL->dropTypesqlDropTypeDeregistersTheTypeAliasesAndFreesThemForAlterTypeALTER TYPE Other ALIASES <alias>refused after the drop (#8064'sputIfAbsent)anAliasFreedByDropTypeCanBeClaimedByAnotherType(API) and the SQL test abovesaveConfiguration()->toJSON()->schema.json-> reopenaDroppedTypeDoesNotComeBackAfterAReopen, which asserts the FILE and then the reopenLocalSchema.dropType(<alias>):getType()resolves aliases, so the argument can be onedropTypeThroughAnAliasDropsTheTypeItselfdropType(<alias>)vs the materialized-view guards, which compared the raw argumentdropTypeThroughAnAliasIsStillRefusedForAMaterializedViewSourceTypedropType(<alias>)vs the continuous-aggregate guards, source type and backing type...ForAContinuousAggregateSourceTypeand...ForAContinuousAggregateBackingType, added in review cycle 1dropType(<alias>)vstypeBeingDropped, compared againstaffectedType.getName()atLocalSchema.java:1785reportPartitionSuitabilityAfterSchemaChange(), a diagnostic wrapped in its owncatch (RuntimeException)that only logs; it has no observable hook to assert on. It now receives the samecanonicalTypeNamethe guard tests do exerciseRemoteSchema.dropType(HTTP client)network/.../RemoteSchema.java:129issuesDROP TYPE <name>as SQL; the server executes the path the SQL test coversMongoDBCollectionWrapper.dropCollection/MongoDBDatabaseWrapperLocalSchema.dropType; the Mongo surface exposes no way to set ALIASES, so the alias set is always empty thereOrientDBImporter/XMLImporterFormatcopyTyperollback,MaterializedViewBuilder/ContinuousAggregateBuilderrollbackLocalDocumentType.rename()- moves the name key, leaves the alias keysremove(oldName, this)is name-only by design, and the comment at:376explains the orderingLocalDocumentType.setAliases()- deregisters the aliases the new set dropsremove(alias, this)since #8064, covered byIssue8064SetAliasesAtomicReservationTestReachability
LocalSchema.dropTypeis the engine's only type-drop path (the caller grep above), it is reached by SQLDROP TYPEthroughDropTypeStatement:95, and nothing gates it behind a flag. The changed lines run on everydrop: all eight tests fail on
mainand pass here. The two continuous-aggregate tests were additionallychecked against a build with only the two
ca.guard comparisons reverted to the raw argument, and fail there(
Tests run: 2, Failures: 2), so they reach the branch they name.Known gaps
This PR fixes the writer; it does not repair
schema.jsonfiles written by an affected version. The manualremedy now works and sticks (
DROP TYPE <name>a second time removes it for good, alias included), which itdid not before, but that needs a release note and possibly a load-time warning for a type restored with zero
buckets. Filed rather than folded in: repairing prior-version state is a separate decision, and mixing it in
would make the regression test unable to distinguish the two behaviours.
Residual risk
setAliases,createProperty, ...) can still write entries back into the shared schema. That is a general property ofstale dropped-type references and predates this issue; no SQL path reaches it, because every
ALTER TYPEresolves the type by name first and a dropped name no longer resolves.
getTypeOrNull(typeName)for the guards runs beforerecordFileChangestakes the database write lock, so aconcurrent rename landing between the resolution and the drop would make
canonicalTypeNamestale. Thatwindow existed before this change as well - the guards compared the raw argument, which a rename invalidates
the same way - so it is narrowed, not widened. The removal itself is unaffected: it uses
type.getName()read under the write lock.
DROP TYPE <alias>now drops the whole type rather thanbeing refused. The alternative would be to refuse it and require the canonical name. Dropping was chosen
because it is what the code already did to the type's buckets, indexes and edge files before this PR - it
simply failed to finish the job - so refusing would be a larger behaviour change than the issue asked for.
Adversarial pass
The
Tasktool is not available in this session, so the Phase 1.5 subagent could not be spawned; the pass wasrun inline against the diff instead, which loses the independence it is meant to buy. Stating that plainly
rather than claiming a pass that did not happen. What it turned up, all verified by reading the tree:
dropType's argument can be an alias, becausegetType()resolves them. Three placescompared or stored the caller's raw string: the materialized-view/continuous-aggregate guards, the
typeBeingDroppedsuppression flag, and the map removal itself. The first letsDROP TYPE <alias>drop aview's source type out from under it. Covered by the table above.
aliasesfield, so it could re-register itself." Itcannot re-register on its own - nothing re-reads that field except
setAliases, which only a caller holdinga stale reference can invoke, and
toJSON, which is only reached from the walk overtypeMap().values()that the instance is no longer in. Left as residual risk above rather than cleared, since clearing the field
would make the removal loop's own input disappear.
not by alias." The whole body runs inside
recordFileChanges, which executes under the database write lock(see the comment at its
recordingDepth++line), the same locksetAliasesandrenametake for theirreservations, so no concurrent DDL can observe the intermediate state.
Review cycles
Cycle 1 -
69621fb-claudereviewed and raised three points, all acted on:serializeConfigurationin this class; the actual call chain issaveConfiguration()->toJSON()." Correct, and verified:grep -rn serializeConfiguration engine/srcreturned only my own comment, and the
typeMap().values()loop sits insidepublic synchronized JSONObject toJSON(), whichsaveConfiguration()reaches throughupdate(toJSON()).The name came from the issue report and I carried it over without checking it. Fixed in the production
comment, the test class javadoc, the test's inline comment, and in this description.
ContinuousAggregateImplguard path isn't exercised by an alias-specific test." Fair.Added
dropTypeThroughAnAliasIsStillRefusedForAContinuousAggregateSourceTypeand...ForAContinuousAggregateBackingType, and proved both can fail (see Reachability above).columnIndex)." Correct, and it was notwhat I wrote. A sibling agent working on Aggregation push-down reads MultiColumnAggregationRequest.columnIndex as a row index in the mutable half and a schema index in the sealed half #8140 overwrote this PR's description after it was opened,
carrying the
Closes #8169line away with it and replacing it withCloses #8140- so this PR was, for awhile, pointed at the wrong issue and DROP TYPE leaves the type's ALIASES in the schema type map, so the dropped type is re-serialised into schema.json and comes back alive after a restart #8169 would not have auto-closed. It also overwrote my draft in the
shared scratchpad directory, so the body below is a reconstruction rather than a restore. Flagging it
because the accident is invisible unless a reviewer reads the body against the diff, and
claudecatchingit is the only reason it was noticed.
codacy-productionreported 0 new issues.coderabbitaihit its OSS review limit on69621fband posted nofindings.
Cycle 2 -
c294d60-claudere-reviewed the amended head and found nothing blocking: "solid,well-scoped fix with unusually thorough regression coverage and an honest accounting of what isn't covered. No
blocking issues found." It independently confirmed the three things the fix turns on - that
toJSON()at~3586keystypeMap().values()byt.getName(), thattypeBeingDroppedis compared at:1785against acanonical name so passing
canonicalTypeNamethere is consistent rather than incidental, and thatgetAliases()hands back avolatile Set.copyOf(...)snapshot so the removal loop cannot tear or throwagainst a concurrent
setAliases. It also noted thatsetAliasesalready refuses a type aliasing its ownname, so the alias loop and the canonical removal cannot fight over one map entry.
Nothing was applied in cycle 2 and nothing was deferred: its three "minor / non-blocking" notes (the two
typeMap()lookups, the pre-lock resolution window, and theDROP TYPE <alias>semantics) each agree with aposition already stated under Residual risk, and it asked for no change. Working tree empty, no open review
threads, so the loop exits here.
Deferred items
None from the reviewer. One process note for the maintainer: CodeRabbit never reviewed this PR. It was rate
limited on
69621fb("You've used all free OSS reviews for now") and its check onc294d60reportsReview rate limitedrather than a pass over the diff, sopulls/8195/reviewsandpulls/8195/commentsareboth empty. Nothing is unresolved, because nothing was ever raised - but this PR has had one bot reviewer, not
two, which is worth knowing before merging.
🤖 Generated with Claude Code