airborne12 opened a new pull request, #71043: URL: https://github.com/apache/doris/pull/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: #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. ```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 #19063; branch-4.2 (#70352) and branch-4.1 (#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 - Human review: not stated 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
