|
3 | 3 | #include "common/compiler_util.h"
|
4 | 4 | DIAGNOSTIC_PUSH
|
5 | 5 | DIAGNOSTIC_IGNORE("-Wclass-memaccess")
|
| 6 | +#include <bthread/bthread.h> |
6 | 7 | #include <bthread/execution_queue.h>
|
7 | 8 | DIAGNOSTIC_POP
|
8 | 9 |
|
9 | 10 | #include "common/config.h"
|
10 | 11 | #include "util/threadpool.h"
|
11 | 12 |
|
12 | 13 | namespace starrocks {
|
| 14 | +const int64_t kRetryIntervalMs = 50; |
13 | 15 |
|
14 | 16 | // Used to run bthread::ExecutionQueue task in pthread instead of bthread.
|
15 | 17 | // Reference: https://github.com/apache/incubator-brpc/blob/master/docs/cn/execution_queue.md
|
16 | 18 | class AsyncDeltaWriterExecutor : public bthread::Executor {
|
17 | 19 | public:
|
18 |
| - Status init() { |
| 20 | + Status init(int max_queue_size = 40960) { |
19 | 21 | if (_thread_pool != nullptr) {
|
20 | 22 | return Status::InternalError("already initialized");
|
21 | 23 | }
|
22 | 24 | return ThreadPoolBuilder("delta_writer")
|
23 | 25 | .set_min_threads(config::number_tablet_writer_threads / 2)
|
24 | 26 | .set_max_threads(std::max<int>(1, config::number_tablet_writer_threads))
|
25 |
| - .set_max_queue_size(40960) |
| 27 | + .set_max_queue_size(max_queue_size) |
26 | 28 | .set_idle_timeout(MonoDelta::FromMilliseconds(5 * 60 * 1000))
|
27 | 29 | .build(&_thread_pool);
|
28 | 30 | }
|
29 | 31 |
|
30 | 32 | int submit(void* (*fn)(void*), void* args) override {
|
31 |
| - auto st = _thread_pool->submit_func([=]() { fn(args); }); |
| 33 | + Status st; |
| 34 | + while (true) { |
| 35 | + st = _thread_pool->submit_func([=]() { fn(args); }); |
| 36 | + if (!st.is_service_unavailable()) break; |
| 37 | + LOG(INFO) << "async_delta_writer is busy, retry after " << kRetryIntervalMs << "ms"; |
| 38 | + bthread_usleep(kRetryIntervalMs * 1000); |
| 39 | + } |
32 | 40 | LOG_IF(WARNING, !st.ok()) << st;
|
33 | 41 | return st.ok() ? 0 : -1;
|
34 | 42 | }
|
|
0 commit comments