Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
f852f38e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f852f38e
编写于
11月 26, 2020
作者:
R
robot-clickhouse
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Backport #17416 to 20.12: Fix backoff in BackgroundJobExecutor
上级
d3fd94c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
29 deletion
+28
-29
src/Storages/MergeTree/BackgroundJobsExecutor.cpp
src/Storages/MergeTree/BackgroundJobsExecutor.cpp
+25
-28
src/Storages/MergeTree/BackgroundJobsExecutor.h
src/Storages/MergeTree/BackgroundJobsExecutor.h
+3
-1
未找到文件。
src/Storages/MergeTree/BackgroundJobsExecutor.cpp
浏览文件 @
f852f38e
...
...
@@ -36,34 +36,31 @@ double IBackgroundJobExecutor::getSleepRandomAdd()
return
std
::
uniform_real_distribution
<
double
>
(
0
,
sleep_settings
.
task_sleep_seconds_when_no_work_random_part
)(
rng
);
}
void
IBackgroundJobExecutor
::
scheduleTask
(
bool
job_done
,
bool
with_backoff
)
void
IBackgroundJobExecutor
::
runTaskWithoutDelay
(
)
{
if
(
job_done
)
no_work_done_count
=
0
;
/// We have background jobs, schedule task as soon as possible
scheduling_task
->
schedule
();
}
void
IBackgroundJobExecutor
::
scheduleTask
(
bool
with_backoff
)
{
size_t
next_time_to_execute
;
if
(
with_backoff
)
{
no_work_done_count
=
0
;
/// We have background jobs, schedule task as soon as possible
scheduling_task
->
schedule
();
auto
no_work_done_times
=
no_work_done_count
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
next_time_to_execute
=
1000
*
(
std
::
min
(
sleep_settings
.
task_sleep_seconds_when_no_work_max
,
sleep_settings
.
thread_sleep_seconds_if_nothing_to_do
*
std
::
pow
(
sleep_settings
.
task_sleep_seconds_when_no_work_multiplier
,
no_work_done_times
))
+
getSleepRandomAdd
());
}
else
{
size_t
next_time_to_execute
;
if
(
with_backoff
)
{
auto
no_work_done_times
=
no_work_done_count
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
next_time_to_execute
=
1000
*
(
std
::
min
(
sleep_settings
.
task_sleep_seconds_when_no_work_max
,
sleep_settings
.
thread_sleep_seconds_if_nothing_to_do
*
std
::
pow
(
sleep_settings
.
task_sleep_seconds_when_no_work_multiplier
,
no_work_done_times
))
+
getSleepRandomAdd
());
}
else
{
next_time_to_execute
=
1000
*
sleep_settings
.
thread_sleep_seconds_if_nothing_to_do
;
}
scheduling_task
->
scheduleAfter
(
next_time_to_execute
,
false
);
next_time_to_execute
=
1000
*
sleep_settings
.
thread_sleep_seconds_if_nothing_to_do
;
}
scheduling_task
->
scheduleAfter
(
next_time_to_execute
,
false
);
}
namespace
...
...
@@ -105,42 +102,42 @@ try
/// Job done, decrement metric and reset no_work counter
CurrentMetrics
::
values
[
pool_config
.
tasks_metric
]
--
;
/// Job done, new empty space in pool, schedule background task
scheduleTask
(
true
);
runTaskWithoutDelay
(
);
}
catch
(...)
{
tryLogCurrentException
(
__PRETTY_FUNCTION__
);
CurrentMetrics
::
values
[
pool_config
.
tasks_metric
]
--
;
scheduleTask
(
fals
e
);
scheduleTask
(
/* with_backoff = */
tru
e
);
}
});
/// We've scheduled task in the background pool and when it will finish we will be triggered again. But this task can be
/// extremely long and we may have a lot of other small tasks to do, so we schedule ourselves here.
scheduleTask
(
true
);
runTaskWithoutDelay
(
);
}
catch
(...)
{
/// With our Pool settings scheduleOrThrowOnError shouldn't throw exceptions, but for safety catch added here
tryLogCurrentException
(
__PRETTY_FUNCTION__
);
CurrentMetrics
::
values
[
pool_config
.
tasks_metric
]
--
;
scheduleTask
(
fals
e
);
scheduleTask
(
/* with_backoff = */
tru
e
);
}
}
else
/// Pool is full and we have some work to do
{
scheduleTask
(
false
,
/* with_backoff = */
false
);
scheduleTask
(
/* with_backoff = */
false
);
}
}
else
/// Nothing to do, no jobs
{
scheduleTask
(
fals
e
);
scheduleTask
(
/* with_backoff = */
tru
e
);
}
}
catch
(...)
/// Exception while we looking for a task, reschedule
{
tryLogCurrentException
(
__PRETTY_FUNCTION__
);
scheduleTask
(
fals
e
);
scheduleTask
(
/* with_backoff = */
tru
e
);
}
void
IBackgroundJobExecutor
::
start
()
...
...
src/Storages/MergeTree/BackgroundJobsExecutor.h
浏览文件 @
f852f38e
...
...
@@ -117,7 +117,9 @@ private:
/// Function that executes in background scheduling pool
void
jobExecutingTask
();
/// Recalculate timeouts when we have to check for a new job
void
scheduleTask
(
bool
job_done
,
bool
with_backoff
=
false
);
void
scheduleTask
(
bool
with_backoff
);
/// Run background task as fast as possible and reset errors counter
void
runTaskWithoutDelay
();
/// Return random add for sleep in case of error
double
getSleepRandomAdd
();
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录