Skip to content

Commit 443bcba

Browse files
branch-4.1: [fix](job-manager) cancelTaskById should not be blocked by unrelated streaming jobs #62940 (#63262)
Cherry-picked from #62940 --------- Co-authored-by: wudi <wudi@selectdb.com>
1 parent f692ae6 commit 443bcba

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

fe/fe-core/src/main/java/org/apache/doris/job/manager/JobManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@ public void replayDeleteJob(T replayJob) throws JobException {
424424
*/
425425
public void cancelTaskById(String jobName, Long taskId) throws JobException {
426426
for (T job : jobMap.values()) {
427-
if (job.getJobConfig().getExecuteType().equals(JobExecuteType.STREAMING)) {
428-
throw new JobException("streaming job not support cancel task by id");
429-
}
430427
if (job.getJobName().equals(jobName)) {
428+
if (job.getJobConfig().getExecuteType().equals(JobExecuteType.STREAMING)) {
429+
throw new JobException("streaming job not support cancel task by id");
430+
}
431431
job.cancelTaskById(taskId);
432432
job.logUpdateOperation();
433433
return;

fe/fe-core/src/test/java/org/apache/doris/job/manager/JobManagerTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@
1919

2020
import org.apache.doris.analysis.UserIdentity;
2121
import org.apache.doris.common.AnalysisException;
22+
import org.apache.doris.common.jmockit.Deencapsulation;
23+
import org.apache.doris.job.base.AbstractJob;
24+
import org.apache.doris.job.base.JobExecuteType;
25+
import org.apache.doris.job.base.JobExecutionConfiguration;
26+
import org.apache.doris.job.exception.JobException;
2227
import org.apache.doris.qe.ConnectContext;
2328
import org.apache.doris.utframe.TestWithFeService;
2429

2530
import com.google.common.collect.Sets;
2631
import mockit.Expectations;
2732
import org.junit.Assert;
2833
import org.junit.Test;
34+
import org.mockito.Mockito;
2935

3036
import java.io.IOException;
3137
import java.util.HashSet;
38+
import java.util.Map;
3239

3340
public class JobManagerTest {
3441
@Test
@@ -62,4 +69,37 @@ public void testJobAuth() throws IOException, AnalysisException {
6269
Assert.assertTrue(e.getMessage().contains("table1"));
6370
}
6471
}
72+
73+
private static AbstractJob mockJob(long id, String name, JobExecuteType type) {
74+
AbstractJob job = Mockito.mock(AbstractJob.class);
75+
Mockito.when(job.getJobId()).thenReturn(id);
76+
Mockito.when(job.getJobName()).thenReturn(name);
77+
JobExecutionConfiguration cfg = new JobExecutionConfiguration();
78+
cfg.setExecuteType(type);
79+
Mockito.when(job.getJobConfig()).thenReturn(cfg);
80+
return job;
81+
}
82+
83+
@Test
84+
@SuppressWarnings({"unchecked", "rawtypes"})
85+
public void testCancelTaskByIdNotBlockedByOtherStreamingJob() throws JobException {
86+
JobManager manager = new JobManager();
87+
AbstractJob streamingJob = mockJob(1L, "streaming_job", JobExecuteType.STREAMING);
88+
AbstractJob batchJob = mockJob(2L, "batch_job", JobExecuteType.RECURRING);
89+
Map<Long, AbstractJob> jobMap = (Map<Long, AbstractJob>) Deencapsulation.getField(manager, "jobMap");
90+
jobMap.put(1L, streamingJob);
91+
jobMap.put(2L, batchJob);
92+
93+
// Cancelling the batch job must not be blocked by the unrelated streaming job in jobMap.
94+
manager.cancelTaskById("batch_job", 100L);
95+
Mockito.verify(batchJob).cancelTaskById(100L);
96+
97+
// Cancelling the streaming job itself still rejected.
98+
try {
99+
manager.cancelTaskById("streaming_job", 100L);
100+
Assert.fail("expected JobException for streaming job");
101+
} catch (JobException e) {
102+
Assert.assertTrue(e.getMessage().contains("streaming job not support"));
103+
}
104+
}
65105
}

0 commit comments

Comments
 (0)