airborne12 commented on code in PR #71217:
URL: https://github.com/apache/doris/pull/71217#discussion_r4763817614


##########
fe/fe-core/src/main/java/org/apache/doris/task/AgentBatchTask.java:
##########
@@ -187,6 +187,9 @@ public void run() {
                 address = new TNetworkAddress(host, backend.getBePort());
                 client = ClientPool.backendPool.borrowObject(address);
                 for (AgentTask task : tasks) {
+                    if (task.isCancelled()) {

Review Comment:
   Confirmed and fixed in 03d44168539.
   
   The flag is read before `toAgentTaskRequest`, so a request converted before 
the cancel is still sent, and a finish report of the original task then lifted 
the FE barrier. The FE cannot see such a request, so the fence now lives on the 
BE: each tablet keeps the newest index change job id that has run on each 
index, and `IndexBuilder` checks and records it under the tablet's 
build-inverted-index lock, before it picks any rowset. A request of an older 
job is rejected with `CANCELLED`. A job on an index starts only after the 
previous job on it is done, and job ids only grow, so an older request is 
always a late one. In your sequence, the buffered DROP arrives after the BUILD 
ran on that tablet and is rejected; if it runs before the BUILD, the BUILD 
rebuilds the index afterwards.
   
   The FE queue barrier is removed. Cancel still marks the tasks so that 
`AgentBatchTask` skips them; that only matters for a BE that restarted, and so 
forgot its record, after the newer job ran there. 
`IndexBuilderTest.RejectsRequestOfOlderIndexChangeJob` runs BUILD job 20, then 
a DROP of job 10 (rejected, index kept), then a DROP of job 30 (accepted).
   



##########
fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java:
##########
@@ -764,6 +764,14 @@ private static void taskReport(long backendId, 
Map<TTaskType, Set<Long>> running
         AgentBatchTask batchTask = new 
AgentBatchTask(Config.report_resend_batch_task_num_per_rpc);
         long taskReportTime = System.currentTimeMillis();
         for (AgentTask task : diffTasks) {
+            if (task.isCancelled()) {
+                // The BE does not hold this cancelled task. A request sent 
before the cancel has arrived or failed
+                // once the RPC timeout has passed, so after that the BE will 
not run the task.
+                if (taskReportTime - task.getCancelTimeMs() >= 
Config.backend_rpc_timeout_ms) {

Review Comment:
   Confirmed and fixed in 03d44168539.
   
   `taskReportTime` is when the FE handles the report, and a report carries no 
snapshot time, so an old or retried snapshot could release the barrier while 
the DROP was still queued on the BE. The report-diff removal is reverted. 
Whether a late request may run is now decided on the BE when it runs: 
`IndexBuilder` compares its job id with the newest job that has already run on 
that tablet index and rejects an older one. The order and age of task reports 
no longer matter.
   



##########
fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java:
##########
@@ -173,6 +173,18 @@ public void setAlterInvertedIndexInfo(boolean isDropOp, 
List<Index> alterInverte
         this.alterInvertedIndexes = alterInvertedIndexes;
     }
 
+    public boolean isDropOp() {
+        return isDropOp;
+    }
+
+    // Whether a BE may still run a task of this cancelled job: cancelling 
does not stop the requests a BE has
+    // received, so their tasks stay in AgentTaskQueue until the BE reports 
them or no longer holds them.
+    public boolean hasPendingTasks() {
+        return jobState == JobState.CANCELLED
+                && invertedIndexBatchTask.getAllTasks().stream()

Review Comment:
   Confirmed and fixed in 03d44168539.
   
   `AgentBatchTask.backendIdToTasks` has no `@SerializedName`, so the barrier 
was lost on replay. The barrier no longer lives on the FE: the BE keeps the 
newest index change job id per tablet index and rejects a request of an older 
job (`IndexBuilderTest.RejectsRequestOfOlderIndexChangeJob`). Job ids come from 
`MetaIdGenerator`, which journals its batch end before handing out ids, so a 
new master gives every new job a larger id than any job the old master created. 
The BE check therefore holds across FE failover without journaling anything new.
   



##########
fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java:
##########
@@ -173,6 +173,18 @@ public void setAlterInvertedIndexInfo(boolean isDropOp, 
List<Index> alterInverte
         this.alterInvertedIndexes = alterInvertedIndexes;
     }
 
+    public boolean isDropOp() {
+        return isDropOp;
+    }
+
+    // Whether a BE may still run a task of this cancelled job: cancelling 
does not stop the requests a BE has
+    // received, so their tasks stay in AgentTaskQueue until the BE reports 
them or no longer holds them.
+    public boolean hasPendingTasks() {
+        return jobState == JobState.CANCELLED
+                && invertedIndexBatchTask.getAllTasks().stream()
+                        .anyMatch(task -> !task.isFinished() && 
AgentTaskQueue.contains(task));

Review Comment:
   Confirmed and fixed in 03d44168539.
   
   `AgentTaskCleanupDaemon` could abort the cancelled tasks after three failed 
liveness checks while the BE still had them queued. With the FE barrier 
removed, eviction no longer releases anything: a surviving DROP that runs after 
the newer BUILD on that tablet is rejected by the BE's job id check, and one 
that runs before it is followed by the BUILD. The check is in BE memory, so a 
BE that only missed heartbeats keeps it.
   



-- 
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]

Reply via email to