This is an automated email from the ASF dual-hosted git repository.

JNSimba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new c853a51fe84 [fix](fe) Isolate streaming job control tasks from insert 
execution (#70467)
c853a51fe84 is described below

commit c853a51fe84ef12ad1fc31a3816aae0c493d8463
Author: wudi <[email protected]>
AuthorDate: Tue Dec 1 14:26:25 2026 +0800

    [fix](fe) Isolate streaming job control tasks from insert execution (#70467)
    
    ### Background
    
    The job scheduler submits ordinary insert tasks and streaming job
    control tasks to the same insert executor. Streaming data tasks already
    execute through a separate scheduler, while periodic control tasks
    handle metadata, split progress and lifecycle checks.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: None
    PR Type: Fix
    
    Problem Summary:
    
    Long-running insert jobs can occupy the insert executor and delay
    streaming control tasks. Add an independent bounded executor for jobs
    whose existing execution mode is STREAMING, covering both timer dispatch
    and immediate submission. Keep streaming jobs classified as INSERT so
    existing job queries and metrics retain their classification. Most of
    the diff adds isolation tests.
---
 .../main/java/org/apache/doris/common/Config.java  |  10 ++
 .../doris/job/executor/DispatchTaskHandler.java    |  10 +-
 .../job/manager/TaskDisruptorGroupManager.java     |  21 ++-
 .../job/manager/TaskDisruptorGroupManagerTest.java | 193 +++++++++++++++++++++
 4 files changed, 230 insertions(+), 4 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java 
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index d50ff07e294..afd6a9e878a 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -1916,6 +1916,16 @@ public class Config extends ConfigBase {
             + "be greater than 0, if it is <=0, default is 10.")
     public static int job_insert_task_consumer_thread_num = 10;
 
+    @ConfField(masterOnly = true, description = "The number of threads used to 
run streaming job control tasks. "
+            + "These threads are separate from insert execution and streaming 
data execution. "
+            + "If the value is <=0, the default is 10.")
+    public static int job_streaming_task_consumer_thread_num = 10;
+
+    @ConfField(masterOnly = true, description = "The size of the streaming job 
control task waiting queue. "
+            + "If the size is <=0, 1024 will be used. If the size is not a 
power of two, "
+            + "the nearest power of two will be automatically selected.")
+    public static int streaming_task_queue_size = 1024;
+
     @ConfField(masterOnly = true, description = "The number of threads used to 
consume MTMV tasks, the value should "
             + "be greater than 0, if it is <=0, default is 10.")
     public static int job_mtmv_task_consumer_thread_num = 10;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/executor/DispatchTaskHandler.java
 
b/fe/fe-core/src/main/java/org/apache/doris/job/executor/DispatchTaskHandler.java
index 85223772779..df2b2d94077 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/executor/DispatchTaskHandler.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/executor/DispatchTaskHandler.java
@@ -18,6 +18,7 @@
 package org.apache.doris.job.executor;
 
 import org.apache.doris.job.base.AbstractJob;
+import org.apache.doris.job.base.JobExecuteType;
 import org.apache.doris.job.common.JobType;
 import org.apache.doris.job.common.TaskType;
 import org.apache.doris.job.disruptor.TimerJobEvent;
@@ -40,8 +41,11 @@ public class DispatchTaskHandler<T extends AbstractJob> 
implements WorkHandler<T
 
     private final Map<JobType, TaskProcessor> disruptorMap;
 
-    public DispatchTaskHandler(Map<JobType, TaskProcessor> disruptorMap) {
+    private final TaskProcessor streamingTaskProcessor;
+
+    public DispatchTaskHandler(Map<JobType, TaskProcessor> disruptorMap, 
TaskProcessor streamingTaskProcessor) {
         this.disruptorMap = disruptorMap;
+        this.streamingTaskProcessor = streamingTaskProcessor;
     }
 
 
@@ -63,8 +67,10 @@ public class DispatchTaskHandler<T extends AbstractJob> 
implements WorkHandler<T
                     return;
                 }
                 JobType jobType = event.getJob().getJobType();
+                TaskProcessor processor = 
event.getJob().getJobConfig().getExecuteType() == JobExecuteType.STREAMING
+                        ? streamingTaskProcessor : disruptorMap.get(jobType);
                 for (AbstractTask task : tasks) {
-                    if (!disruptorMap.get(jobType).addTask(task)) {
+                    if (!processor.addTask(task)) {
                         try {
                             task.cancel(true);
                         } finally {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/manager/TaskDisruptorGroupManager.java
 
b/fe/fe-core/src/main/java/org/apache/doris/job/manager/TaskDisruptorGroupManager.java
index 98023a4b596..a81116d475c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/manager/TaskDisruptorGroupManager.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/manager/TaskDisruptorGroupManager.java
@@ -20,6 +20,7 @@ package org.apache.doris.job.manager;
 import org.apache.doris.common.Config;
 import org.apache.doris.common.CustomThreadFactory;
 import org.apache.doris.job.base.AbstractJob;
+import org.apache.doris.job.base.JobExecuteType;
 import org.apache.doris.job.base.JobExecutionConfiguration;
 import org.apache.doris.job.common.JobType;
 import org.apache.doris.job.disruptor.TaskDisruptor;
@@ -43,6 +44,8 @@ public class TaskDisruptorGroupManager<T extends 
AbstractTask> {
 
     private final Map<JobType, TaskProcessor> disruptorMap = new 
EnumMap<>(JobType.class);
 
+    private TaskProcessor streamingTaskProcessor;
+
     @Getter
     private TaskDisruptor<TimerJobEvent<AbstractJob>> dispatchDisruptor;
 
@@ -66,9 +69,15 @@ public class TaskDisruptorGroupManager<T extends 
AbstractTask> {
 
     private static final int DISPATCH_MTMV_TASK_QUEUE_SIZE = 
normalizeRingbufferSize(Config.mtmv_task_queue_size);
 
+    private static final int STREAMING_CONTROL_THREAD_NUM = 
Config.job_streaming_task_consumer_thread_num > 0
+            ? Config.job_streaming_task_consumer_thread_num : 10;
+
+    private static final int STREAMING_CONTROL_QUEUE_SIZE = 
normalizeRingbufferSize(Config.streaming_task_queue_size);
+
     public void init() {
         registerInsertDisruptor();
         registerMTMVDisruptor();
+        registerStreamingDisruptor();
         //when all task queue is ready, dispatch task to registered task 
executor
         registerDispatchDisruptor();
     }
@@ -78,7 +87,7 @@ public class TaskDisruptorGroupManager<T extends 
AbstractTask> {
         ThreadFactory dispatchThreadFactory = new 
CustomThreadFactory("dispatch-task");
         WorkHandler[] dispatchTaskExecutorHandlers = new 
WorkHandler[DISPATCH_TIMER_JOB_CONSUMER_THREAD_NUM];
         for (int i = 0; i < DISPATCH_TIMER_JOB_CONSUMER_THREAD_NUM; i++) {
-            dispatchTaskExecutorHandlers[i] = new 
DispatchTaskHandler(this.disruptorMap);
+            dispatchTaskExecutorHandlers[i] = new 
DispatchTaskHandler(this.disruptorMap, streamingTaskProcessor);
         }
         EventTranslatorVararg<TimerJobEvent<AbstractJob>> eventTranslator =
                 (event, sequence, args) -> event.setJob((AbstractJob) args[0]);
@@ -103,9 +112,17 @@ public class TaskDisruptorGroupManager<T extends 
AbstractTask> {
         disruptorMap.put(JobType.MV, mtmvTaskProcessor);
     }
 
+    private void registerStreamingDisruptor() {
+        ThreadFactory threadFactory = new 
CustomThreadFactory("streaming-job-schedule");
+        streamingTaskProcessor = new 
TaskProcessor(STREAMING_CONTROL_THREAD_NUM,
+                STREAMING_CONTROL_QUEUE_SIZE, threadFactory);
+    }
+
     public boolean dispatchInstantTask(AbstractTask task, JobType jobType,
             JobExecutionConfiguration jobExecutionConfiguration) {
-        return disruptorMap.get(jobType).addTask(task);
+        TaskProcessor processor = jobExecutionConfiguration.getExecuteType() 
== JobExecuteType.STREAMING
+                ? streamingTaskProcessor : disruptorMap.get(jobType);
+        return processor.addTask(task);
     }
 
     /**
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/job/manager/TaskDisruptorGroupManagerTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/job/manager/TaskDisruptorGroupManagerTest.java
index 661bdcdcca2..bc624c9dc15 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/job/manager/TaskDisruptorGroupManagerTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/job/manager/TaskDisruptorGroupManagerTest.java
@@ -17,12 +17,205 @@
 
 package org.apache.doris.job.manager;
 
+import org.apache.doris.common.jmockit.Deencapsulation;
+import org.apache.doris.job.base.JobExecuteType;
+import org.apache.doris.job.base.JobExecutionConfiguration;
+import org.apache.doris.job.common.JobStatus;
+import org.apache.doris.job.common.JobType;
+import org.apache.doris.job.common.TaskStatus;
+import org.apache.doris.job.common.TaskType;
+import org.apache.doris.job.disruptor.TimerJobEvent;
+import org.apache.doris.job.executor.DispatchTaskHandler;
+import org.apache.doris.job.executor.TaskProcessor;
+import org.apache.doris.job.extensions.insert.InsertTask;
+import org.apache.doris.job.extensions.insert.streaming.StreamingInsertJob;
+import 
org.apache.doris.job.extensions.insert.streaming.StreamingJobSchedulerTask;
+import org.apache.doris.job.extensions.mtmv.MTMVTask;
+import org.apache.doris.job.scheduler.JobScheduler;
+import org.apache.doris.job.task.AbstractTask;
 
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
 public class TaskDisruptorGroupManagerTest {
 
+    private final CountDownLatch release = new CountDownLatch(1);
+    private final TaskDisruptorGroupManager<AbstractTask> manager = new 
TaskDisruptorGroupManager<>();
+    private Map<JobType, TaskProcessor> processors;
+    private TaskProcessor streamingTaskProcessor;
+
+    @BeforeEach
+    public void setUp() {
+        manager.init();
+        processors = Deencapsulation.getField(manager, "disruptorMap");
+        streamingTaskProcessor = Deencapsulation.getField(manager, 
"streamingTaskProcessor");
+    }
+
+    @AfterEach
+    public void tearDown() {
+        release.countDown();
+        manager.getDispatchDisruptor().shutdown();
+        processors.values().forEach(TaskProcessor::shutdown);
+        streamingTaskProcessor.shutdown();
+    }
+
+    @Test
+    public void testInsertSaturationDoesNotBlockStreamingControl() throws 
Exception {
+        assertPoolIsolation(false);
+    }
+
+    @Test
+    public void testStreamingControlSaturationDoesNotBlockInsert() throws 
Exception {
+        assertPoolIsolation(true);
+    }
+
+    private void assertPoolIsolation(boolean blockStreaming) throws Exception {
+        saturate(blockStreaming);
+        CountDownLatch completed = new CountDownLatch(1);
+        Assertions.assertTrue(submit(!blockStreaming, completed::countDown),
+                "The other processor must accept work while this processor is 
full");
+        Assertions.assertTrue(completed.await(5, TimeUnit.SECONDS));
+    }
+
+    private void saturate(boolean streaming) throws Exception {
+        TaskProcessor processor = streaming ? streamingTaskProcessor : 
processors.get(JobType.INSERT);
+        ThreadPoolExecutor executor = Deencapsulation.getField(processor, 
"executor");
+        int workers = executor.getCorePoolSize();
+        CountDownLatch started = new CountDownLatch(workers);
+        for (int i = 0; i < workers; i++) {
+            Assertions.assertTrue(submit(streaming, () -> {
+                started.countDown();
+                await(release);
+            }));
+        }
+        Assertions.assertTrue(started.await(5, TimeUnit.SECONDS));
+        int queueSize = executor.getQueue().remainingCapacity();
+        for (int i = 0; i < queueSize; i++) {
+            Assertions.assertTrue(submit(streaming, () -> await(release)));
+        }
+    }
+
+    @Test
+    public void testTimerRejectionAllowsNextTick() throws Exception {
+        saturate(true);
+        TestStreamingJob job = new TestStreamingJob();
+        TimerJobEvent<StreamingInsertJob> event = new TimerJobEvent<>();
+        event.setJob(job);
+        DispatchTaskHandler<StreamingInsertJob> handler = new 
DispatchTaskHandler<>(processors, streamingTaskProcessor);
+        handler.onEvent(event);
+        Assertions.assertTrue(job.getRunningTasks().isEmpty());
+        Assertions.assertTrue(job.isReadyForScheduling(null));
+        Assertions.assertEquals(1L, job.completed.getCount());
+
+        release.countDown();
+        ThreadPoolExecutor executor = 
Deencapsulation.getField(streamingTaskProcessor, "executor");
+        CountDownLatch drained = new CountDownLatch(1);
+        // Wait for one worker to drain the bounded queue before submitting 
the next tick.
+        Assertions.assertTrue(executor.getQueue().offer(drained::countDown, 5, 
TimeUnit.SECONDS));
+        Assertions.assertTrue(drained.await(5, TimeUnit.SECONDS));
+        handler.onEvent(event);
+        Assertions.assertTrue(job.completed.await(5, TimeUnit.SECONDS));
+    }
+
+    @Test
+    public void testInstantStreamingDispatchWhileInsertIsFull() throws 
Exception {
+        saturate(false);
+        TestStreamingJob job = new TestStreamingJob();
+        JobScheduler<StreamingInsertJob, Map<Object, Object>> scheduler = new 
JobScheduler<>(Collections.emptyMap());
+        Deencapsulation.setField(scheduler, "taskDisruptorGroupManager", 
manager);
+        scheduler.schedulerInstantJob(job, TaskType.MANUAL, null);
+        Assertions.assertTrue(job.completed.await(5, TimeUnit.SECONDS));
+    }
+
+    @Test
+    public void testMtmvDispatchWhileInsertIsFull() throws Exception {
+        saturate(false);
+        CountDownLatch completed = new CountDownLatch(1);
+        MTMVTask task = new MTMVTask() {
+            @Override
+            public void runTask() {
+                completed.countDown();
+            }
+        };
+        task.setStatus(TaskStatus.PENDING);
+        JobExecutionConfiguration config = new JobExecutionConfiguration();
+        config.setExecuteType(JobExecuteType.RECURRING);
+        Assertions.assertTrue(manager.dispatchInstantTask(task, JobType.MV, 
config));
+        Assertions.assertTrue(completed.await(5, TimeUnit.SECONDS));
+    }
+
+    private static class TestStreamingJob extends StreamingInsertJob {
+        private final CountDownLatch completed = new CountDownLatch(1);
+
+        TestStreamingJob() {
+            setJobId(1L);
+            setJobName("isolation");
+            setJobStatus(JobStatus.PENDING);
+            JobExecutionConfiguration config = new JobExecutionConfiguration();
+            config.setExecuteType(JobExecuteType.STREAMING);
+            setJobConfig(config);
+        }
+
+        @Override
+        public List<StreamingJobSchedulerTask> createTasks(TaskType taskType, 
Map<Object, Object> context) {
+            StreamingJobSchedulerTask task = new 
StreamingJobSchedulerTask(this) {
+                @Override
+                public void runTask() {
+                    getRunningTasks().remove(this);
+                    completed.countDown();
+                }
+            };
+            List<StreamingJobSchedulerTask> tasks = 
Collections.singletonList(task);
+            initTasks(tasks, taskType);
+            return tasks;
+        }
+    }
+
+    private boolean submit(boolean streaming, Runnable action) {
+        JobExecutionConfiguration config = new JobExecutionConfiguration();
+        config.setExecuteType(streaming ? JobExecuteType.STREAMING : 
JobExecuteType.RECURRING);
+        return manager.dispatchInstantTask(task(streaming, action), 
JobType.INSERT, config);
+    }
+
+    private AbstractTask task(boolean streaming, Runnable action) {
+        AbstractTask task;
+        if (streaming) {
+            task = new StreamingJobSchedulerTask(null) {
+                @Override
+                public void runTask() {
+                    action.run();
+                }
+            };
+        } else {
+            task = new InsertTask("isolation", "db", "SELECT 1", null) {
+                @Override
+                public void runTask() {
+                    action.run();
+                }
+            };
+        }
+        task.setStatus(TaskStatus.PENDING);
+        return task;
+    }
+
+    private static void await(CountDownLatch latch) {
+        try {
+            Assertions.assertTrue(latch.await(30, TimeUnit.SECONDS));
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new AssertionError(e);
+        }
+    }
+
     @Test
     public void testInit() {
         Assertions.assertEquals(1024, 
TaskDisruptorGroupManager.normalizeRingbufferSize(1024));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to