Repository navigation
[fix](inverted index) Match index change job conflicts by partition ID - #71043
airborne12 wants to merge 1 commit into
Conversation
|
run buildall |
|
/review |
|
run buildall |
|
/review |
hello-stephen
left a comment
There was a problem hiding this comment.
Reviewed PR #71043 at base 6261b18dc35c0967bb7d4aaf7816d53104ea6779 and head 5c5d807d234f83f7ed924e5fc1ad329f6545a38d. No actionable regression found.
Checkpoint conclusions:
- Goal/scope: both conflict gates now follow stable partition IDs through rename; the change is focused and reuses the existing predicate.
- Concurrency/lifecycle: the table write lock protects the ID snapshot and diagnostic lookup. Rename preserves IDs; replacement uses distinct partitions/tablets, so old jobs cannot retarget by name.
- Compatibility/persistence: partitionId was already serialized, initialized before job publication, replayed, and used for BE tasks. The sole helper caller is updated.
- Parallel paths/conditions: BUILD, partition DROP, and full-table light DROP are covered; cloud/local index and final-state filters remain unchanged.
- Tests/results: the new FE test checks both rejection paths, current-name diagnostics, and retained metadata; fixture IDs match production. No expected-result files change. Tests were inspected, not executed.
- Atomicity/observability/performance: rejection remains before metadata mutation; diagnostics identify the current partition; asymptotic preflight cost is unchanged.
- Configuration, Thrift/protobuf, new FE/BE variables, visibility versions, and delete bitmaps: no changes requiring additional handling.
All three changed files and six supplied diff hunks were covered by the main review and two delegated reviews. Existing comments and requester focus were empty. One round converged with no actionable findings; detailed coverage and evidence-backed dismissals are recorded in ledger.md. Source-only review: no builds, tests, product edits, or GitHub publication.
Review converged after 1 round(s).
### Background BUILD INDEX and DROP INDEX on partitions create one index change job per partition. Before a new job is created, and before a whole-table light DROP INDEX changes metadata, the FE looks for an unfinished job of the same index on the same partition and rejects the statement, because jobs of one index are not ordered: a BUILD running after a DROP adds the dropped index back. RENAME PARTITION is allowed while such jobs run. ### What problem does this PR solve? Issue Number: None Related PR: apache#19063 (introduced matching jobs by partition name), apache#68674 (light DROP INDEX pre-check), apache#69443 (conflicts in either direction), apache#70352 (branch-4.2 backport where the bug was reported) PR Type: Bugfix Problem Summary: Both conflict checks compare the partition name stored in the job, which is the name at job creation. After a rename, a statement on the new name finds no conflict, so a DROP can run while a BUILD of the same index is still pending, and the BUILD restores the index afterwards. This PR matches jobs by partition ID, which a rename does not change. ```sql BUILD INDEX idx_v1 ON t PARTITION (p1); -- job still pending ALTER TABLE t RENAME PARTITION p1 p1_renamed; ALTER TABLE t DROP INDEX idx_v1 PARTITION (p1_renamed); ``` | | Result of the DROP | |---|---| | Before | Accepted; a second job for the same partition runs unordered with the pending BUILD | | After | `partition p1_renamed has been built specified index. please check your build stmt.` | ### Details - **Frequency:** Always, when an index statement names a partition that was renamed while an index change job of the same index on it is unfinished. - **Root cause:** `SchemaChangeHandler.hasIndexChangeJobOnPartition` and `checkNoIndexChangeJobOnPartitions` compare `IndexChangeJob.getPartitionName()`, which is captured at job creation, with the current partition names. `Env.renamePartition` only requires the table to be in NORMAL state, which index change jobs do not change. - **Why existing tests missed it:** Unit tests: `SchemaChangeHandlerTest#testDropIndexRejectedByPendingBuildOfSameIndex` and `#testDropIndexRejectedByIndexChangeJobKeepsMetadata` cover pending jobs but never rename the partition; they also built their jobs with a name only, so this PR sets the partition ID there as the production code does. Regression: `test_drop_index_on_partition` has no rename between index statements. - **Fix:** Both checks match `IndexChangeJob.getPartitionId()` (persisted since jobs were introduced) against partition IDs, and the light DROP error names the partition by its current name. - **Other paths and branches:** BUILD INDEX ON PARTITION uses the same `hasIndexChangeJobOnPartition`, so a duplicate BUILD after a rename is rejected too. The name match exists on every maintained branch since apache#19063; branch-4.2 (apache#70352) and branch-4.1 (apache#70357) also have the light DROP pre-check and partition DROP, where the bypass can lose a drop. ### Testing - `SchemaChangeHandlerTest#testIndexChangeConflictFollowsRenamedPartition` registers an unfinished BUILD of `idx_v1` on p1, renames p1 through SQL, and checks that both `DROP INDEX idx_v1 PARTITION (p1_renamed)` and `DROP INDEX idx_v1` are rejected with the new name in the message. On the unfixed code it fails with `Expected java.lang.Exception to be thrown, but nothing was thrown`; with the fix it passes. `SchemaChangeHandlerTest` (47), `IndexChangeJobTest` (22) and `CloudIndexTest` (9) pass. - No regression case: holding an index change job unfinished in a real cluster needs a delay hook that does not exist (the BE hooks only inject failures, which cancel the job after retries), so a SQL case would depend on timing. ### Release note Fix BUILD INDEX and DROP INDEX on partitions missing a conflict with an unfinished index change job when the partition was renamed after the job was created. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Ready ### AI Disclosure - Tool: Claude Code (Claude Opus 5.5) - Generated: code, tests, this description Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5c5d807 to
608a1da
Compare
|
run buildall |
|
/review |
hello-stephen
left a comment
There was a problem hiding this comment.
Source-only review completed for PR #71043 at head 608a1da against base d97993b. All three changed files and six diff hunks were covered by the main review and two delegated reviews. No actionable regressions found.
Checkpoint conclusions:
- Goal/tests: Stable partition IDs preserve conflicts after rename; the added test covers both DROP forms and metadata retention.
- Scope/reuse: Focused change reuses the existing conflict predicate.
- Concurrency: Table write-lock scope protects the ID snapshot and current-name lookup; no new lock-order or blocking-operation issue found.
- Lifecycle: IDs are assigned before job publication, survive rename/replay, and correctly distinguish replacement partitions. Test jobs are isolated from the scheduler and cleaned up.
- Compatibility: The ID was already persisted; all helper callers are updated.
- Parallel paths/conditions: BUILD, partition DROP and full-table DROP use consistent identity; cloud/local conflict rules and formal-partition scope are preserved.
- Observability: Rejections report the current partition name.
- Persistence/atomicity: Existing ID serialization/replay remains valid; rejection occurs before metadata mutation.
- Performance: Retains one job-history scan with constant-time partition membership checks.
- Configuration, Thrift/Protobuf, expected-result files and FE/BE fields: No changes.
- Additional risks: Partition replacement, stale-name reuse and table-wrapper delegation reviewed without finding an introduced defect.
No builds or tests were run, as requested. Detailed evidence and coverage are recorded in the review ledger. No existing comments were supplied.
Review converged after 1 round(s).
… partition ID apache#71043 ### Background BUILD INDEX and DROP INDEX on partitions create one index change job per partition. Before a new job is created, and before a whole-table light DROP INDEX changes metadata, the FE looks for an unfinished job of the same index on the same partition and rejects the statement, because jobs of one index are not ordered: a BUILD running after a DROP adds the dropped index back. RENAME PARTITION is allowed while such jobs run. ### What problem does this PR solve? Issue Number: None Related PR: apache#19063 (introduced matching jobs by partition name), apache#68674 (light DROP INDEX pre-check), apache#69443 (conflicts in either direction), apache#70352 (branch-4.2 backport where the bug was reported) PR Type: Bugfix Problem Summary: Both conflict checks compare the partition name stored in the job, which is the name at job creation. After a rename, a statement on the new name finds no conflict, so a DROP can run while a BUILD of the same index is still pending, and the BUILD restores the index afterwards. This PR matches jobs by partition ID, which a rename does not change. ```sql BUILD INDEX idx_v1 ON t PARTITION (p1); -- job still pending ALTER TABLE t RENAME PARTITION p1 p1_renamed; ALTER TABLE t DROP INDEX idx_v1 PARTITION (p1_renamed); ``` | | Result of the DROP | |---|---| | Before | Accepted; a second job for the same partition runs unordered with the pending BUILD | | After | `partition p1_renamed has been built specified index. please check your build stmt.` | ### Details - **Frequency:** Always, when an index statement names a partition that was renamed while an index change job of the same index on it is unfinished. - **Root cause:** `SchemaChangeHandler.hasIndexChangeJobOnPartition` and `checkNoIndexChangeJobOnPartitions` compare `IndexChangeJob.getPartitionName()`, which is captured at job creation, with the current partition names. `Env.renamePartition` only requires the table to be in NORMAL state, which index change jobs do not change. - **Why existing tests missed it:** Unit tests: `SchemaChangeHandlerTest#testDropIndexRejectedByPendingBuildOfSameIndex` and `#testDropIndexRejectedByIndexChangeJobKeepsMetadata` cover pending jobs but never rename the partition; they also built their jobs with a name only, so this PR sets the partition ID there as the production code does. Regression: `test_drop_index_on_partition` has no rename between index statements. - **Fix:** Both checks match `IndexChangeJob.getPartitionId()` (persisted since jobs were introduced) against partition IDs, and the light DROP error names the partition by its current name. - **Other paths and branches:** BUILD INDEX ON PARTITION uses the same `hasIndexChangeJobOnPartition`, so a duplicate BUILD after a rename is rejected too. The name match exists on every maintained branch since apache#19063; branch-4.2 (apache#70352) and branch-4.1 (apache#70357) also have the light DROP pre-check and partition DROP, where the bypass can lose a drop. ### Testing - `SchemaChangeHandlerTest#testIndexChangeConflictFollowsRenamedPartition` registers an unfinished BUILD of `idx_v1` on p1, renames p1 through SQL, and checks that both `DROP INDEX idx_v1 PARTITION (p1_renamed)` and `DROP INDEX idx_v1` are rejected with the new name in the message. On the unfixed code it fails with `Expected java.lang.Exception to be thrown, but nothing was thrown`; with the fix it passes. `SchemaChangeHandlerTest` (47), `IndexChangeJobTest` (22) and `CloudIndexTest` (9) pass. - No regression case: holding an index change job unfinished in a real cluster needs a delay hook that does not exist (the BE hooks only inject failures, which cancel the job after retries), so a SQL case would depend on timing. ### Release note Fix BUILD INDEX and DROP INDEX on partitions missing a conflict with an unfinished index change job when the partition was renamed after the job was created. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Ready ### AI Disclosure - Tool: Claude Code (Claude Opus 5.5) - Generated: code, tests, this description Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 5c5d807) Conflicts: fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java Adapted for branch-4.1: kept this branch's light DROP pre-check without the master-only clauses, passed the partition DROP pre-check its partitions as IDs, set the partition ID in the existing pending-build test, and expect the pre-check error for the partition drop.
### Background `DROP INDEX ... PARTITION` submits one `IndexChangeJob` per target partition, recording both `partitionId` and creation-time `partitionName`. `Env.renamePartition` updates the partition's name in `OlapTable` without modifying existing `IndexChangeJob` instances, while `SchemaChangeHandler.checkCanSetStoragePolicy` guards against enabling a `storage_policy` on partitions with unfinished partition drop jobs. ### What problem does this PR solve? Issue Number: None Related PR: apache#71216 (guards partition index drops against remote data), apache#71043 (matches index change job conflicts by partition ID) PR Type: Bugfix Problem Summary: When a `DROP INDEX ... PARTITION` job is unfinished (for example in `RUNNING` with queued BE tasks) and its partition is renamed with `ALTER TABLE t RENAME PARTITION p1 p_new`, `SchemaChangeHandler.checkCanSetStoragePolicy` previously compared partition names against `job.getPartitionName()`, missing the job across `MODIFY PARTITION (p_new)`, `MODIFY PARTITION (*)`, and table-level `SET ("storage_policy" = ...)`. Resolve target partition names to stable partition IDs under the table read lock (or read `olapTable.getPartitionIds()` directly for table-level policy updates), match `job.getPartitionId()`, and report the partition's current name in the error message. ### Details - **Frequency:** Always, when a partition with an unfinished `DROP INDEX ... PARTITION` job is renamed before setting a storage policy on the partition or table. Found by code review on apache#71216. - **Root cause:** `IndexChangeJob` retains its creation-time `partitionName` after `Env.renamePartition`, so `partitionNames.contains(indexChangeJob.getPartitionName())` in `SchemaChangeHandler.checkCanSetStoragePolicy` misses renamed partitions, and `Alter` also read `olapTable.getPartitionNames()` outside the table lock for table-level storage policy updates. - **Why existing tests missed it:** `SchemaChangeHandlerTest#testStoragePolicyRejectedWhileDropIndexOnPartitionIsUnfinished` tested `WAITING_TXN` without renaming the partition; `regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy` neither renames partitions nor configures a storage policy. - **Fix:** Expose `IndexChangeJob.getPartitionId()`, add a table-level `checkCanSetStoragePolicy(db, olapTable, storagePolicy)` overload so `olapTable.getPartitionIds()` is read inside `olapTable.readLock()`, resolve explicit/expanded partition names to partition IDs under the same lock, match `indexChangeJob.getPartitionId()`, and format the `DdlException` with `olapTable.getPartition(indexChangeJob.getPartitionId()).getName()`. - **Other paths and branches:** `IndexChangeJob.runWaitingTxnJob` already resolves the partition by `partitionId` before calling `checkPartitionHoldsOnlyLocalData`. Cloud mode rejects partition-scoped `DROP INDEX` in `DropIndexOp.validate`. Applies to the apache#71216 change targeting `master`. - **Behavior change:** Setting a storage policy on a renamed partition (via `MODIFY PARTITION`, `MODIFY PARTITION (*)`, or table-level `SET`) while its `DROP INDEX ... PARTITION` job is unfinished now fails with the partition's current name instead of succeeding. ### Testing - `SchemaChangeHandlerTest#testStoragePolicyRejectedAfterRenamingPartitionWithRunningDropIndexJob`: transitions a `DROP INDEX ... PARTITION (p1)` job to `RUNNING`, renames `p1` to `p_new`, and verifies that `MODIFY PARTITION (p_new)`, `MODIFY PARTITION (*)`, and table-level `SET ('storage_policy' = ...)` fail naming `p_new`, while `p2` can still receive a policy and `p_new` can after the job finishes. Fails before the fix (`Expected java.lang.Exception to be thrown, but nothing was thrown`) and passes after. - Ran `SchemaChangeHandlerTest` (53 tests), `IndexChangeJobTest` (23 tests), and `ModifyPartitionStoragePolicyTest` (2 tests) locally via `./run-fe-ut.sh`, plus `./build.sh --fe` (0 checkstyle violations). ### Release note None ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Partially verified: no cluster run with data on remote storage; verified via FE unit tests ### AI Disclosure - Tool: T3 Code (Gemini) - Generated: code, tests, commit message - Human review: pending review
…71043 #71122 (#71046) ### What problem does this PR solve? Issue Number: None Related PR: #71043 and #71122 (master fixes, open; this backport follows any change they get in review), #70357 (brought partition DROP INDEX and the light DROP pre-check to branch-4.1), #70352 (branch-4.2 backport whose review found both bugs) Problem Summary: Backport two partition DROP INDEX fixes to `branch-4.1`, one commit per source PR: | Source | Change | Pick | |---|---|---| | #71043 | BUILD INDEX and DROP INDEX on partitions, and the whole-table light DROP INDEX pre-check, found an unfinished index change job by the partition name stored in the job. `RENAME PARTITION` is allowed while such jobs run, so a statement on the new name missed the conflict: a DROP could run while a BUILD of the same index was pending, and the BUILD restored the index afterwards. The checks now match jobs by partition ID. | 43de3f6, adapted | | #71122 | DROP INDEX ON PARTITION on an inverted index of a VARIANT column, including a `field_pattern` index, was accepted and its job reached FINISHED, but the BE finds no index under a VARIANT root column, so nothing was deleted. The FE now rejects it, as BUILD INDEX already does for VARIANT columns. | a9f1845, adapted | Hunk audit for #71043 (commit 5c5d807): | File | Source hunk | Result | |---|---|---| | `IndexChangeJob.java` | `@@ -202,6 +202,10 @@ public class IndexChangeJob implements Writable {` | Ported | | `SchemaChangeHandler.java` | `@@ -3975,7 +3975,7 @@ public class SchemaChangeHandler extends AlterHandler {` | Ported | | `SchemaChangeHandler.java` | `@@ -4041,29 +4041,32 @@ public class SchemaChangeHandler extends AlterHandler {` | Adapted: kept this branch's light DROP pre-check, which has no add-and-drop or cluster checks; only the partition matching changes | | `SchemaChangeHandler.java` | (this branch only) partition DROP pre-check | Adapted: passes the selected partitions as IDs | | `SchemaChangeHandlerTest.java` | `@@ -1403,7 +1403,9 @@ public class SchemaChangeHandlerTest extends TestWithFeService {` | N-A: `testDropIndexRejectedByIndexChangeJobKeepsMetadata` does not exist on this branch | | `SchemaChangeHandlerTest.java` | `@@ -1493,6 +1495,7 @@ public class SchemaChangeHandlerTest extends TestWithFeService {` | Ported to this branch's `testDropIndexRejectedByPendingBuildOfSameIndex` | | `SchemaChangeHandlerTest.java` | `@@ -1516,6 +1519,54 @@ public class SchemaChangeHandlerTest extends TestWithFeService {` | Adapted: the partition DROP is rejected by this branch's pre-check, so the test expects "has an unfinished index change job" for both statements | Hunk audit for #71122 (commit df392dc): | File | Source hunk | Result | |---|---|---| | `SchemaChangeHandler.java` | `@@ -2664,6 +2664,15 @@ public class SchemaChangeHandler extends AlterHandler {` | Adapted: same check; the comment says the BE finds no index under a VARIANT root column, because this branch has no VARIANT values indexes (on master the BE finds only values indexes there) | | `SchemaChangeHandlerTest.java` | `@@ -265,6 +265,32 @@ public class SchemaChangeHandlerTest extends TestWithFeService {` | Adapted: placed after `expectException`, since the values index tests it follows on master do not exist here; `List.of` became `Lists.newArrayList` for this branch's Java 8 source level | | `test_drop_index_on_partition.groovy` | `@@ -270,4 +270,34 @@ suite("test_drop_index_on_partition", "inverted_index") {` | Ported as case 11 | ### Release note Fix BUILD INDEX and DROP INDEX on partitions missing a conflict with an unfinished index change job when the partition was renamed after the job was created. DROP INDEX ... ON PARTITION now fails with "DROP INDEX ON PARTITION is not supported for index <index> on VARIANT column <column>" for inverted indexes on VARIANT columns. Before, it reported success but kept the index on the named partitions. Drop the index from the whole table instead. ### Check List (For Author) - Test - [x] Regression test - [x] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Run locally on this branch with both picks: `./run-fe-ut.sh --run org.apache.doris.alter.SchemaChangeHandlerTest,org.apache.doris.alter.IndexChangeJobTest,org.apache.doris.alter.CloudIndexTest,org.apache.doris.cloud.alter.CloudSchemaChangeHandlerTest,org.apache.doris.catalog.IndexTest` passed (32, 18, 5, 12 and 2 tests), including the new `testIndexChangeConflictFollowsRenamedPartition` and `testDropIndexOnPartitionRejectsVariantColumnIndexes`. Both tests failed on master without their fixes (#71043, #71122). #71043 has no regression case: holding an index change job unfinished in a real cluster needs a delay hook that does not exist, so a SQL case would depend on timing. Case 11 of `test_drop_index_on_partition` (from #71122) was run against a local shared-nothing cluster on master only: it failed without the fix and passed with it; this branch's CI runs it. - Behavior changed: - [ ] No. - [x] Yes. Partition DROP of an index on a VARIANT column is now rejected (it used to report success and keep the index). - Does this need documentation? - [x] No. - [ ] Yes. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Background
BUILD INDEX and DROP INDEX on partitions create one index change job per partition. Before a new job is created, and before a whole-table light DROP INDEX changes metadata, the FE looks for an unfinished job of the same index on the same partition and rejects the statement, because jobs of one index are not ordered: a BUILD running after a DROP adds the dropped index back. RENAME PARTITION is allowed while such jobs run.
What problem does this PR solve?
Issue Number: None
Related PR: #19063 (introduced matching jobs by partition name), #68674 (light DROP INDEX pre-check), #69443 (conflicts in either direction), #70352 (branch-4.2 backport where the bug was reported)
PR Type: Bugfix
Problem Summary:
Both conflict checks compare the partition name stored in the job, which is the name at job creation. After a rename, a statement on the new name finds no conflict, so a DROP can run while a BUILD of the same index is still pending, and the BUILD restores the index afterwards. This PR matches jobs by partition ID, which a rename does not change.
partition p1_renamed has been built specified index. please check your build stmt.Details
SchemaChangeHandler.hasIndexChangeJobOnPartitionandcheckNoIndexChangeJobOnPartitionscompareIndexChangeJob.getPartitionName(), which is captured at job creation, with the current partition names.Env.renamePartitiononly requires the table to be in NORMAL state, which index change jobs do not change.SchemaChangeHandlerTest#testDropIndexRejectedByPendingBuildOfSameIndexand#testDropIndexRejectedByIndexChangeJobKeepsMetadatacover pending jobs but never rename the partition; they also built their jobs with a name only, so this PR sets the partition ID there as the production code does. Regression:test_drop_index_on_partitionhas no rename between index statements.IndexChangeJob.getPartitionId()(persisted since jobs were introduced) against partition IDs, and the light DROP error names the partition by its current name.hasIndexChangeJobOnPartition, so a duplicate BUILD after a rename is rejected too. The name match exists on every maintained branch since [Enhancement](alter inverted index) Improve alter inverted index performance with light weight add or drop inverted index #19063; branch-4.2 (branch-4.2: [fix](index) Backport partition DROP INDEX and index fixes #70352) and branch-4.1 (branch-4.1: [feature](index) Support partition DROP INDEX with conflict guards #70357) also have the light DROP pre-check and partition DROP, where the bypass can lose a drop.Testing
SchemaChangeHandlerTest#testIndexChangeConflictFollowsRenamedPartitionregisters an unfinished BUILD ofidx_v1on p1, renames p1 through SQL, and checks that bothDROP INDEX idx_v1 PARTITION (p1_renamed)andDROP INDEX idx_v1are rejected with the new name in the message. On the unfixed code it fails withExpected java.lang.Exception to be thrown, but nothing was thrown; with the fix it passes.SchemaChangeHandlerTest(47),IndexChangeJobTest(22) andCloudIndexTest(9) pass.Release note
Fix BUILD INDEX and DROP INDEX on partitions missing a conflict with an unfinished index change job when the partition was renamed after the job was created.
Check List (For Author)
AI Disclosure
🤖 Generated with Claude Code