airborne12 opened a new pull request, #71217: URL: https://github.com/apache/doris/pull/71217
### Background `BUILD INDEX idx ON t PARTITION (p)` and `DROP INDEX idx ON t PARTITION (p)` (#62181) run as one index change job per partition. The job puts one `ALTER_INVERTED_INDEX` task per replica in an `AgentBatchTask`, which an agent-task thread sends to the BEs one BE after another, and keeps each task in `AgentTaskQueue` until its BE reports it; the task report handler resends queued tasks that a BE does not hold. `CANCEL BUILD INDEX`, a timeout, or repeated task failures cancel a job. The FE rejects a new job while an unfinished job on the same partition and index exists, and a partition drop keeps the index in the table schema, so a later `BUILD INDEX` on that partition is valid. ### What problem does this PR solve? Issue Number: None Related PR: #23760 (added CANCEL BUILD INDEX), #62181 (added DROP INDEX ON PARTITION), #70357 (DROP INDEX ON PARTITION on branch-4.1), #70352 (same for branch-4.2, open; its review found this), #71043, #71122, #71128, #71130 (open, edit the same block of SchemaChangeHandler) PR Type: Bugfix Problem Summary: A cancelled index change job stops conflicting at once, but its requests can still reach and run on the BEs. So after a cancelled `DROP INDEX idx ON t PARTITION (p1)`, a `BUILD INDEX idx ON t PARTITION (p1)` can finish first, and a late DROP request then deletes the index it built while the BUILD shows FINISHED. This PR stops sending a cancelled job's tasks and keeps them queued, never resent, until their BE reports them or no longer holds them; until then the job blocks jobs of the other direction on its partition and index. Same-direction jobs are not blocked, since a late request finds nothing left to do. ### Details - **Frequency:** Intermittent; not observed in a cluster, found by code review of #70352. Triggers when a partition DROP (or BUILD) is cancelled while some requests are unsent or not yet run, for example while the sender is slow to reach one BE, and an opposite job runs first there. - **Root cause:** `SchemaChangeHandler.isConflictingIndexChangeJob` skips done jobs, CANCELLED included. `IndexChangeJob.cancelInternal` only removes the tasks from `AgentTaskQueue`, but `AgentBatchTask.run` sends every task without consulting the queue, and `EngineIndexChangeTask` on the BE checks neither job id nor schema version. Out of the queue, their finish reports are dropped, so the FE cannot tell when they are done. - **Why existing tests missed it:** Unit tests: `IndexChangeJobTest` checks only the job state after a cancel, and `SchemaChangeHandlerTest#testDropIndexRejectedByPendingBuildOfSameIndex` checks that an unfinished job blocks the opposite one, not a cancelled one. Regression: `test_build_index` and `test_build_index_fault` cancel a RUNNING BUILD and build again, the same direction, and no suite can hold back one request of a job. - **Fix:** Cancel marks the tasks cancelled instead of removing them. `AgentBatchTask` skips cancelled tasks, and the task report handler never resends one; it removes one that the BE's report does not list once `backend_rpc_timeout_ms` has passed since the cancel, by when any request sent before it has arrived or failed. A finish report, or the existing cleanup of dropped or dead BEs, removes it too. A cancelled job conflicts with an opposite job while one of its unfinished tasks is queued. - **Other paths and branches:** Both directions are fenced, since a late BUILD after a new partition DROP would rebuild the index; the light full-table `DROP INDEX` uses the same check. The fence does not survive an FE restart or master change (`AgentTaskQueue` is in memory). Cloud mode shares the code. The conflict skip dates from #23760; the DROP-then-BUILD case exists on master since #62181, on branch-4.1 through #70357, and on branch-4.2 with #70352. - **Behavior change:** After a cancel, an opposite job on the same partition and index fails with the existing conflict error until the cancelled tasks are done; for tasks the BE does not hold, that is `backend_rpc_timeout_ms` (60 s by default) plus one task report. Cancelling a BUILD and building again is not affected. ### Testing All runs were local FE unit tests on master 5d3b20272b8 plus this change. - New `SchemaChangeHandlerTest#testCancelledPartitionDropBlocksBuildUntilItsTasksAreQuiet` cancels a partition DROP with two queued tasks; BUILD INDEX on the partition stays rejected while a finish report (through `MasterImpl`) releases one task and task reports release the other only after the RPC timeout, never resending it; then BUILD is accepted. A sender run after the cancel builds no request. On the unfixed code it fails at the first BUILD (`Expected java.lang.Exception to be thrown, but nothing was thrown`); without the sender check it fails because both DROP requests are built. - New `testCancelledPartitionBuildDoesNotBlockAnotherBuild`: BUILD right after a cancelled BUILD is accepted, as `test_build_index` expects; passes before and after the fix. - `SchemaChangeHandlerTest` (48 tests), `IndexChangeJobTest`, `CloudIndexTest`, `AgentTaskTest`, `AgentTaskCleanupDaemonTest`, `MasterImplDeleteTaskTest`, `ChangelogReportHandlerTest`, and `RemoteSpillReportHandlerTest` pass (100 tests); `build.sh --fe` reports 0 checkstyle violations. ### Notes for Reviewers - `IndexChangeJob.cancelInternal` no longer calls `AgentTaskQueue.removeBatchTask`: the queue entry is how the FE still hears about the task. - #71043, #71122, #71128, and #71130 also edit this block of `SchemaChangeHandler`; whichever merges later needs a rebase there. ### Release note After an inverted index change job is cancelled, a BUILD INDEX or DROP INDEX of the other direction on the same partition and index is rejected until the BEs are done with the cancelled job's tasks, so a late request of the cancelled job can no longer undo it. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Partially verified: no cluster run; the race is reproduced only through the FE unit test ### AI Disclosure - Tool: Claude Code (Claude Opus 5.5) - Generated: code, tests, this description - Human review: not stated - Prompts: Fix two FE findings from the review of the branch-4.2 backport #70352 on master, one PR each; for this one, keep a cancelled partition index change job conflicting until its tasks have finished, failed, or been reported, or a timeout passes, on the FE, reusing the job's batch task tracking and keeping the change small, with an FE unit test that cancels a RUNNING partition DROP and checks BUILD INDEX is rejected until the tasks complete. 🤖 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]
