Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Incubator Pegasus
提交
49664ba7
Incubator Pegasus
项目概览
apache
/
Incubator Pegasus
通知
9
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Incubator Pegasus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
49664ba7
编写于
1月 09, 2019
作者:
Q
QinZuoyan
提交者:
GitHub
1月 09, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
server: improve manual compact to support max_concurrent_running_count limit (#250)
上级
a2bde68c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
4 deletion
+72
-4
scripts/pegasus_manual_compact.sh
scripts/pegasus_manual_compact.sh
+25
-0
src/base/pegasus_const.cpp
src/base/pegasus_const.cpp
+2
-0
src/base/pegasus_const.h
src/base/pegasus_const.h
+1
-0
src/server/pegasus_manual_compact_service.cpp
src/server/pegasus_manual_compact_service.cpp
+40
-4
src/server/pegasus_manual_compact_service.h
src/server/pegasus_manual_compact_service.h
+4
-0
未找到文件。
scripts/pegasus_manual_compact.sh
浏览文件 @
49664ba7
...
...
@@ -28,6 +28,10 @@ function usage()
echo
" skip or force, default is skip"
echo
" more details: https://github.com/facebook/rocksdb/wiki/Manual-Compaction"
echo
echo
" --max_concurrent_running_count <num>"
echo
" max concurrent running count limit, should be positive integer."
echo
" if not set, means no limit."
echo
echo
"for example:"
echo
echo
" 1) Start once type manual compact with default options:"
...
...
@@ -149,6 +153,7 @@ trigger_time=""
wait_only
=
"false"
target_level
=
"-1"
bottommost_level_compaction
=
"skip"
max_concurrent_running_count
=
""
while
[[
$#
>
0
]]
;
do
option_key
=
"
$1
"
case
${
option_key
}
in
...
...
@@ -179,6 +184,10 @@ while [[ $# > 0 ]]; do
bottommost_level_compaction
=
"
$2
"
shift
;;
--max_concurrent_running_count
)
max_concurrent_running_count
=
"
$2
"
shift
;;
-h
|
--help
)
usage
exit
0
...
...
@@ -255,6 +264,19 @@ if [ "${bottommost_level_compaction}" != "skip" -a "${bottommost_level_compactio
exit
1
fi
# check max_concurrent_running_count
if
[
"
${
max_concurrent_running_count
}
"
!=
""
]
;
then
expr
${
max_concurrent_running_count
}
+ 0 &>/dev/null
if
[
$?
-ne
0
]
;
then
echo
"ERROR: invalid max_concurrent_running_count:
${
max_concurrent_running_count
}
"
exit
1
fi
if
[
${
max_concurrent_running_count
}
-lt
0
]
;
then
echo
"ERROR: invalid max_concurrent_running_count:
${
max_concurrent_running_count
}
"
exit
1
fi
fi
# record start time
all_start_time
=
`
date
+%s
`
echo
"UID:
$UID
"
...
...
@@ -276,6 +298,9 @@ if [ "${type}" == "periodic" ] || [ "${type}" == "once" -a "${wait_only}" == "fa
if
[
"
${
bottommost_level_compaction
}
"
!=
""
]
;
then
set_env
${
cluster
}
${
app_name
}
"manual_compact.
${
type
}
.bottommost_level_compaction"
${
bottommost_level_compaction
}
fi
if
[
"
${
max_concurrent_running_count
}
"
!=
""
]
;
then
set_env
${
cluster
}
${
app_name
}
"manual_compact.max_concurrent_running_count"
${
max_concurrent_running_count
}
fi
set_env
${
cluster
}
${
app_name
}
"manual_compact.
${
type
}
.trigger_time"
${
trigger_time
}
echo
fi
...
...
src/base/pegasus_const.cpp
浏览文件 @
49664ba7
...
...
@@ -37,6 +37,8 @@ const std::string ROCKSDB_ENV_USAGE_SCENARIO_BULK_LOAD("bulk_load");
/// ```
const
std
::
string
MANUAL_COMPACT_KEY_PREFIX
(
"manual_compact."
);
const
std
::
string
MANUAL_COMPACT_DISABLED_KEY
(
MANUAL_COMPACT_KEY_PREFIX
+
"disabled"
);
const
std
::
string
MANUAL_COMPACT_MAX_CONCURRENT_RUNNING_COUNT_KEY
(
MANUAL_COMPACT_KEY_PREFIX
+
"max_concurrent_running_count"
);
const
std
::
string
MANUAL_COMPACT_PERIODIC_KEY_PREFIX
(
MANUAL_COMPACT_KEY_PREFIX
+
"periodic."
);
const
std
::
string
MANUAL_COMPACT_PERIODIC_TRIGGER_TIME_KEY
(
MANUAL_COMPACT_PERIODIC_KEY_PREFIX
+
...
...
src/base/pegasus_const.h
浏览文件 @
49664ba7
...
...
@@ -23,6 +23,7 @@ extern const std::string ROCKSDB_ENV_USAGE_SCENARIO_BULK_LOAD;
extern
const
std
::
string
MANUAL_COMPACT_KEY_PREFIX
;
extern
const
std
::
string
MANUAL_COMPACT_DISABLED_KEY
;
extern
const
std
::
string
MANUAL_COMPACT_MAX_CONCURRENT_RUNNING_COUNT_KEY
;
extern
const
std
::
string
MANUAL_COMPACT_PERIODIC_KEY_PREFIX
;
extern
const
std
::
string
MANUAL_COMPACT_PERIODIC_TRIGGER_TIME_KEY
;
...
...
src/server/pegasus_manual_compact_service.cpp
浏览文件 @
49664ba7
...
...
@@ -21,6 +21,7 @@ pegasus_manual_compact_service::pegasus_manual_compact_service(pegasus_server_im
:
replica_base
(
*
app
),
_app
(
app
),
_disabled
(
false
),
_max_concurrent_running_count
(
INT_MAX
),
_manual_compact_enqueue_time_ms
(
0
),
_manual_compact_start_running_time_ms
(
0
),
_manual_compact_last_finish_time_ms
(
0
),
...
...
@@ -53,6 +54,12 @@ void pegasus_manual_compact_service::start_manual_compact_if_needed(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
)
{
if
(
check_compact_disabled
(
envs
))
{
ddebug_replica
(
"ignored compact because disabled"
);
return
;
}
if
(
check_compact_max_concurrent_running_count
(
envs
)
<=
0
)
{
ddebug_replica
(
"ignored compact because max_concurrent_running_count <= 0"
);
return
;
}
...
...
@@ -79,8 +86,7 @@ void pegasus_manual_compact_service::start_manual_compact_if_needed(
manual_compact
(
options
);
});
}
else
{
ddebug_replica
(
"ignored this compact request because last one is on going or finished just now"
);
ddebug_replica
(
"ignored compact because last one is on going or just finished"
);
}
}
...
...
@@ -108,6 +114,25 @@ bool pegasus_manual_compact_service::check_compact_disabled(
return
new_disabled
;
}
int
pegasus_manual_compact_service
::
check_compact_max_concurrent_running_count
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
)
{
int
new_count
=
INT_MAX
;
auto
find
=
envs
.
find
(
MANUAL_COMPACT_MAX_CONCURRENT_RUNNING_COUNT_KEY
);
if
(
find
!=
envs
.
end
()
&&
!
dsn
::
buf2int32
(
find
->
second
,
new_count
))
{
derror_replica
(
"{}={} is invalid."
,
find
->
first
,
find
->
second
);
}
int
old_count
=
_max_concurrent_running_count
.
load
();
if
(
new_count
!=
old_count
)
{
// count changed
ddebug_replica
(
"max_concurrent_running_count changed from {} to {}"
,
old_count
,
new_count
);
_max_concurrent_running_count
.
store
(
new_count
);
}
return
new_count
;
}
bool
pegasus_manual_compact_service
::
check_once_compact
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
)
{
...
...
@@ -238,6 +263,17 @@ void pegasus_manual_compact_service::manual_compact(const rocksdb::CompactRangeO
// if we find manual compaction is disabled when transfer from queue to running,
// it would not to be started.
if
(
_disabled
.
load
())
{
ddebug_replica
(
"ignored compact because disabled"
);
_manual_compact_enqueue_time_ms
.
store
(
0
);
return
;
}
// if current running count exceeds the limit, it would not to be started.
_pfc_manual_compact_running_count
->
increment
();
if
(
_pfc_manual_compact_running_count
->
get_integer_value
()
>
_max_concurrent_running_count
)
{
_pfc_manual_compact_running_count
->
decrement
();
ddebug_replica
(
"ignored compact because exceed max_concurrent_running_count({})"
,
_max_concurrent_running_count
.
load
());
_manual_compact_enqueue_time_ms
.
store
(
0
);
return
;
}
...
...
@@ -245,12 +281,13 @@ void pegasus_manual_compact_service::manual_compact(const rocksdb::CompactRangeO
uint64_t
start
=
begin_manual_compact
();
uint64_t
finish
=
_app
->
do_manual_compact
(
options
);
end_manual_compact
(
start
,
finish
);
_pfc_manual_compact_running_count
->
decrement
();
}
uint64_t
pegasus_manual_compact_service
::
begin_manual_compact
()
{
ddebug_replica
(
"start to execute manual compaction"
);
_pfc_manual_compact_running_count
->
increment
();
uint64_t
start
=
now_timestamp
();
_manual_compact_start_running_time_ms
.
store
(
start
);
return
start
;
...
...
@@ -263,7 +300,6 @@ void pegasus_manual_compact_service::end_manual_compact(uint64_t start, uint64_t
_manual_compact_last_time_used_ms
.
store
(
finish
-
start
);
_manual_compact_enqueue_time_ms
.
store
(
0
);
_manual_compact_start_running_time_ms
.
store
(
0
);
_pfc_manual_compact_running_count
->
decrement
();
}
std
::
string
pegasus_manual_compact_service
::
query_compact_state
()
const
...
...
src/server/pegasus_manual_compact_service.h
浏览文件 @
49664ba7
...
...
@@ -31,6 +31,9 @@ private:
// return true if manual compaction is disabled.
bool
check_compact_disabled
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
);
// return max concurrent count.
int
check_compact_max_concurrent_running_count
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
);
// return true if need do once manual compaction.
bool
check_once_compact
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
envs
);
...
...
@@ -63,6 +66,7 @@ private:
// manual compact state
std
::
atomic
<
bool
>
_disabled
;
std
::
atomic
<
int
>
_max_concurrent_running_count
;
std
::
atomic
<
uint64_t
>
_manual_compact_enqueue_time_ms
;
std
::
atomic
<
uint64_t
>
_manual_compact_start_running_time_ms
;
std
::
atomic
<
uint64_t
>
_manual_compact_last_finish_time_ms
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录