Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Incubator Pegasus
提交
e17d5c7a
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 搜索 >>
未验证
提交
e17d5c7a
编写于
10月 22, 2020
作者:
S
Smilencer
提交者:
GitHub
10月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(hotkey): collector can be terminated by timeout (#625)
上级
8e8510b4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
6 deletion
+46
-6
src/server/hotkey_collector.cpp
src/server/hotkey_collector.cpp
+40
-4
src/server/hotkey_collector.h
src/server/hotkey_collector.h
+4
-0
src/server/test/capacity_unit_calculator_test.cpp
src/server/test/capacity_unit_calculator_test.cpp
+2
-2
未找到文件。
src/server/hotkey_collector.cpp
浏览文件 @
e17d5c7a
...
...
@@ -21,16 +21,24 @@
#include <dsn/utility/smart_pointers.h>
#include "base/pegasus_key_schema.h"
#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/flags.h>
namespace
pegasus
{
namespace
server
{
DSN_DEFINE_int32
(
"pegasus.server"
,
max_seconds_to_detect_hotkey
,
150
,
"the max time (in seconds) allowed to capture hotkey, will stop if hotkey's not found"
);
hotkey_collector
::
hotkey_collector
(
dsn
::
replication
::
hotkey_type
::
type
hotkey_type
,
dsn
::
replication
::
replica_base
*
r_base
)
:
replica_base
(
r_base
),
_state
(
hotkey_collector_state
::
STOPPED
),
_hotkey_type
(
hotkey_type
),
_internal_collector
(
std
::
make_shared
<
hotkey_empty_data_collector
>
())
_internal_collector
(
std
::
make_shared
<
hotkey_empty_data_collector
>
()),
_collector_start_time_second
(
0
)
{
}
...
...
@@ -65,7 +73,18 @@ void hotkey_collector::capture_hash_key(const dsn::blob &hash_key, int64_t weigh
_internal_collector
->
capture_data
(
hash_key
,
weight
);
}
void
hotkey_collector
::
analyse_data
()
{
_internal_collector
->
analyse_data
();
}
void
hotkey_collector
::
analyse_data
()
{
switch
(
_state
.
load
())
{
case
hotkey_collector_state
::
COARSE_DETECTING
:
if
(
!
terminate_if_timeout
())
{
_internal_collector
->
analyse_data
();
}
return
;
default:
return
;
}
}
void
hotkey_collector
::
on_start_detect
(
dsn
::
replication
::
detect_hotkey_response
&
resp
)
{
...
...
@@ -88,6 +107,7 @@ void hotkey_collector::on_start_detect(dsn::replication::detect_hotkey_response
dwarn_replica
(
hint
);
return
;
case
hotkey_collector_state
::
STOPPED
:
_collector_start_time_second
=
dsn_now_s
();
// TODO: (Tangyanzhao) start coarse detecting
_state
.
store
(
hotkey_collector_state
::
COARSE_DETECTING
);
resp
.
err
=
dsn
::
ERR_OK
;
...
...
@@ -105,13 +125,29 @@ void hotkey_collector::on_start_detect(dsn::replication::detect_hotkey_response
void
hotkey_collector
::
on_stop_detect
(
dsn
::
replication
::
detect_hotkey_response
&
resp
)
{
_state
.
store
(
hotkey_collector_state
::
STOPPED
);
_internal_collector
.
reset
();
terminate
();
resp
.
err
=
dsn
::
ERR_OK
;
std
::
string
hint
=
fmt
::
format
(
"{} hotkey stopped, cache cleared"
,
dsn
::
enum_to_string
(
_hotkey_type
));
ddebug_replica
(
hint
);
}
void
hotkey_collector
::
terminate
()
{
_state
.
store
(
hotkey_collector_state
::
STOPPED
);
_internal_collector
.
reset
();
_collector_start_time_second
=
0
;
}
bool
hotkey_collector
::
terminate_if_timeout
()
{
if
(
dsn_now_s
()
>=
_collector_start_time_second
+
FLAGS_max_seconds_to_detect_hotkey
)
{
ddebug_replica
(
"hotkey collector work time is exhausted but no hotkey has been found"
);
terminate
();
return
true
;
}
return
false
;
}
}
// namespace server
}
// namespace pegasus
src/server/hotkey_collector.h
浏览文件 @
e17d5c7a
...
...
@@ -79,9 +79,13 @@ public:
private:
void
on_start_detect
(
dsn
::
replication
::
detect_hotkey_response
&
resp
);
void
on_stop_detect
(
dsn
::
replication
::
detect_hotkey_response
&
resp
);
void
terminate
();
bool
terminate_if_timeout
();
std
::
atomic
<
hotkey_collector_state
>
_state
;
const
dsn
::
replication
::
hotkey_type
::
type
_hotkey_type
;
std
::
shared_ptr
<
internal_collector_base
>
_internal_collector
;
uint64_t
_collector_start_time_second
;
};
class
internal_collector_base
...
...
src/server/test/capacity_unit_calculator_test.cpp
浏览文件 @
e17d5c7a
...
...
@@ -30,8 +30,8 @@ public:
explicit
mock_capacity_unit_calculator
(
dsn
::
replication
::
replica_base
*
r
)
:
capacity_unit_calculator
(
r
,
std
::
make_shared
<
hotkey_collector
>
(
dsn
::
replication
::
hotkey_type
::
READ
,
this
),
std
::
make_shared
<
hotkey_collector
>
(
dsn
::
replication
::
hotkey_type
::
WRITE
,
this
))
std
::
make_shared
<
hotkey_collector
>
(
dsn
::
replication
::
hotkey_type
::
READ
,
r
),
std
::
make_shared
<
hotkey_collector
>
(
dsn
::
replication
::
hotkey_type
::
WRITE
,
r
))
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录