be/src/agent/task_worker_pool.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 <condition_variable> |
22 | | #include <deque> |
23 | | #include <functional> |
24 | | #include <memory> |
25 | | #include <mutex> |
26 | | #include <string> |
27 | | #include <string_view> |
28 | | |
29 | | #include "common/status.h" |
30 | | |
31 | | namespace doris { |
32 | | |
33 | | class ExecEnv; |
34 | | class StorageEngine; |
35 | | class CloudStorageEngine; |
36 | | class Thread; |
37 | | class ThreadPool; |
38 | | class TReportRequest; |
39 | | class TTabletInfo; |
40 | | class TAgentTaskRequest; |
41 | | class ClusterInfo; |
42 | | |
43 | | class TaskWorkerPoolIf { |
44 | | public: |
45 | 80 | virtual ~TaskWorkerPoolIf() = default; |
46 | | |
47 | | virtual Status submit_task(const TAgentTaskRequest& task) = 0; |
48 | | }; |
49 | | |
50 | | class TaskWorkerPool : public TaskWorkerPoolIf { |
51 | | public: |
52 | | TaskWorkerPool(std::string_view name, int worker_count, |
53 | | std::function<void(const TAgentTaskRequest&)> callback); |
54 | | |
55 | | ~TaskWorkerPool() override; |
56 | | |
57 | | void stop(); |
58 | | |
59 | | Status submit_task(const TAgentTaskRequest& task) override; |
60 | | |
61 | | protected: |
62 | | std::atomic_bool _stopped {false}; |
63 | | std::unique_ptr<ThreadPool> _thread_pool; |
64 | | std::function<void(const TAgentTaskRequest&)> _callback; |
65 | | }; |
66 | | |
67 | | class PublishVersionWorkerPool final : public TaskWorkerPool { |
68 | | public: |
69 | | PublishVersionWorkerPool(StorageEngine& engine); |
70 | | |
71 | | ~PublishVersionWorkerPool() override; |
72 | | |
73 | | private: |
74 | | void publish_version_callback(const TAgentTaskRequest& task); |
75 | | |
76 | | StorageEngine& _engine; |
77 | | }; |
78 | | |
79 | | class PriorTaskWorkerPool final : public TaskWorkerPoolIf { |
80 | | public: |
81 | | PriorTaskWorkerPool(const std::string& name, int normal_worker_count, |
82 | | int high_prior_worker_count, |
83 | | std::function<void(const TAgentTaskRequest& task)> callback); |
84 | | |
85 | | ~PriorTaskWorkerPool() override; |
86 | | |
87 | | void stop(); |
88 | | |
89 | | Status submit_task(const TAgentTaskRequest& task) override; |
90 | | |
91 | | Status submit_high_prior_and_cancel_low(TAgentTaskRequest& task); |
92 | | |
93 | | private: |
94 | | void normal_loop(); |
95 | | |
96 | | void high_prior_loop(); |
97 | | |
98 | | bool _stopped {false}; |
99 | | |
100 | | std::mutex _mtx; |
101 | | std::condition_variable _normal_condv; |
102 | | std::deque<std::unique_ptr<TAgentTaskRequest>> _normal_queue; |
103 | | std::condition_variable _high_prior_condv; |
104 | | std::deque<std::unique_ptr<TAgentTaskRequest>> _high_prior_queue; |
105 | | |
106 | | std::vector<std::shared_ptr<Thread>> _workers; |
107 | | |
108 | | std::function<void(const TAgentTaskRequest&)> _callback; |
109 | | }; |
110 | | |
111 | | class ReportWorker { |
112 | | public: |
113 | | ReportWorker(std::string name, const ClusterInfo* cluster_info, int report_interval_s, |
114 | | std::function<void()> callback); |
115 | | |
116 | | ~ReportWorker(); |
117 | | |
118 | 5 | std::string_view name() const { return _name; } |
119 | | |
120 | | // Notify the worker to report immediately |
121 | | void notify(); |
122 | | |
123 | | void stop(); |
124 | | |
125 | | private: |
126 | | std::string _name; |
127 | | std::shared_ptr<Thread> _thread; |
128 | | |
129 | | std::mutex _mtx; |
130 | | std::condition_variable _condv; |
131 | | bool _stopped {false}; |
132 | | bool _signal {false}; |
133 | | }; |
134 | | |
135 | | void alter_inverted_index_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
136 | | |
137 | | void alter_cloud_index_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
138 | | |
139 | | void check_consistency_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
140 | | |
141 | | void upload_callback(StorageEngine& engine, ExecEnv* env, const TAgentTaskRequest& req); |
142 | | |
143 | | void download_callback(StorageEngine& engine, ExecEnv* env, const TAgentTaskRequest& req); |
144 | | |
145 | | void download_callback(CloudStorageEngine& engine, ExecEnv* env, const TAgentTaskRequest& req); |
146 | | |
147 | | void make_snapshot_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
148 | | |
149 | | void release_snapshot_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
150 | | |
151 | | void release_snapshot_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
152 | | |
153 | | void move_dir_callback(StorageEngine& engine, ExecEnv* env, const TAgentTaskRequest& req); |
154 | | |
155 | | void move_dir_callback(CloudStorageEngine& engine, ExecEnv* env, const TAgentTaskRequest& req); |
156 | | |
157 | | void submit_table_compaction_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
158 | | |
159 | | void push_storage_policy_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
160 | | |
161 | | void push_index_policy_callback(const TAgentTaskRequest& req); |
162 | | |
163 | | void push_cooldown_conf_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
164 | | |
165 | | void create_tablet_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
166 | | |
167 | | void drop_tablet_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
168 | | |
169 | | void drop_tablet_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
170 | | |
171 | | void clear_transaction_task_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
172 | | |
173 | | void push_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
174 | | |
175 | | void cloud_push_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
176 | | |
177 | | void update_tablet_meta_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
178 | | |
179 | | void alter_tablet_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
180 | | |
181 | | void alter_cloud_tablet_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
182 | | |
183 | | void clone_callback(StorageEngine& engine, const ClusterInfo* cluster_info, |
184 | | const TAgentTaskRequest& req); |
185 | | |
186 | | void storage_medium_migrate_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
187 | | |
188 | | void gc_binlog_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
189 | | |
190 | | void clean_trash_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
191 | | |
192 | | void clean_udf_cache_callback(const TAgentTaskRequest& req); |
193 | | |
194 | | void visible_version_callback(StorageEngine& engine, const TAgentTaskRequest& req); |
195 | | |
196 | | void report_task_callback(const ClusterInfo* cluster_info); |
197 | | |
198 | | void report_disk_callback(StorageEngine& engine, const ClusterInfo* cluster_info); |
199 | | |
200 | | void report_disk_callback(CloudStorageEngine& engine, const ClusterInfo* cluster_info); |
201 | | |
202 | | void report_tablet_callback(StorageEngine& engine, const ClusterInfo* cluster_info); |
203 | | |
204 | | void report_tablet_callback(CloudStorageEngine& engine, const ClusterInfo* cluster_info); |
205 | | |
206 | | void calc_delete_bitmap_callback(CloudStorageEngine& engine, const TAgentTaskRequest& req); |
207 | | |
208 | | void report_index_policy_callback(const ClusterInfo* cluster_info); |
209 | | |
210 | | } // namespace doris |