Coverage Report

Created: 2026-08-04 11:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/pipeline/task_scheduler.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <atomic>
21
#include <chrono>
22
#include <condition_variable>
23
#include <cstddef>
24
#include <list>
25
#include <memory>
26
#include <mutex>
27
#include <utility>
28
#include <vector>
29
30
#include "common/status.h"
31
#include "exec/pipeline/pipeline_task.h"
32
#include "exec/pipeline/task_queue.h"
33
#include "runtime/query_context.h"
34
#include "util/thread.h"
35
#include "util/uid_util.h"
36
37
namespace doris {
38
class ExecEnv;
39
class ThreadPool;
40
} // namespace doris
41
42
namespace doris {
43
44
class HybridTaskScheduler;
45
class TaskScheduler {
46
public:
47
    virtual ~TaskScheduler();
48
49
    virtual Status submit(PipelineTaskSPtr task);
50
51
    virtual Status start();
52
53
    virtual void stop();
54
55
176
    virtual std::vector<std::pair<std::string, std::vector<int>>> thread_debug_info() {
56
176
        return {{_name, _fix_thread_pool->debug_info()}};
57
176
    }
58
59
protected:
60
    std::string _name;
61
    bool _need_to_stop = false;
62
    bool _shutdown = false;
63
    const int _num_threads;
64
65
private:
66
    friend class HybridTaskScheduler;
67
68
    TaskScheduler(int core_num, std::string name, std::shared_ptr<CgroupCpuCtl> cgroup_cpu_ctl)
69
90
            : _name(std::move(name)),
70
90
              _num_threads(core_num),
71
90
              _task_queue(core_num),
72
90
              _cgroup_cpu_ctl(cgroup_cpu_ctl) {
73
90
        LOG(INFO) << "TaskScheduler " << _name << " created with " << core_num << " threads.";
74
90
    }
75
84
    TaskScheduler() : _num_threads(0), _task_queue(0) {}
76
    std::unique_ptr<ThreadPool> _fix_thread_pool;
77
78
    MultiCoreTaskQueue _task_queue;
79
    std::weak_ptr<CgroupCpuCtl> _cgroup_cpu_ctl;
80
81
    void _do_work(int index);
82
};
83
84
class HybridTaskScheduler MOCK_REMOVE(final) : public TaskScheduler {
85
public:
86
    HybridTaskScheduler(int exec_thread_num, int blocking_exec_thread_num, std::string name,
87
                        std::shared_ptr<CgroupCpuCtl> cgroup_cpu_ctl)
88
45
            : _blocking_scheduler(blocking_exec_thread_num, name + "_blocking_scheduler",
89
45
                                  cgroup_cpu_ctl),
90
45
              _simple_scheduler(exec_thread_num, name + "_simple_scheduler", cgroup_cpu_ctl) {}
91
23
    ~HybridTaskScheduler() override {
92
23
        DCHECK(_blocking_scheduler._shutdown)
93
0
                << _blocking_scheduler._name << ": " << _blocking_scheduler._shutdown << " "
94
0
                << _blocking_scheduler._need_to_stop << " " << _blocking_scheduler._num_threads;
95
23
        DCHECK(_simple_scheduler._shutdown)
96
0
                << _simple_scheduler._name << ": " << _simple_scheduler._shutdown << " "
97
0
                << _simple_scheduler._need_to_stop << " " << _simple_scheduler._num_threads;
98
23
    }
99
100
    Status submit(PipelineTaskSPtr task) override;
101
102
    Status start() override;
103
104
    void stop() override;
105
106
88
    std::vector<std::pair<std::string, std::vector<int>>> thread_debug_info() override {
107
88
        return {_blocking_scheduler.thread_debug_info()[0],
108
88
                _simple_scheduler.thread_debug_info()[0]};
109
88
    }
110
111
private:
112
    TaskScheduler _blocking_scheduler;
113
    TaskScheduler _simple_scheduler;
114
};
115
} // namespace doris