Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Incubator Pegasus
提交
e147550a
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 搜索 >>
未验证
提交
e147550a
编写于
9月 29, 2020
作者:
S
Smilencer
提交者:
GitHub
9月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(hotspot): add a function to start hotkey detecting in shell commands (#605)
上级
704994ba
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
177 addition
and
34 deletion
+177
-34
rdsn
rdsn
+1
-1
src/shell/command_utils.h
src/shell/command_utils.h
+36
-0
src/shell/commands.h
src/shell/commands.h
+4
-1
src/shell/commands/detect_hotkey.cpp
src/shell/commands/detect_hotkey.cpp
+126
-0
src/shell/commands/disk_rebalance.cpp
src/shell/commands/disk_rebalance.cpp
+0
-32
src/shell/main.cpp
src/shell/main.cpp
+10
-0
未找到文件。
rdsn
@
69102a78
比较
fafbd599
...
69102a78
Subproject commit
fafbd599d1df48b36bade4d08940ab79837aaf3b
Subproject commit
69102a786f3b888155bc18b8b6c58031c7d2fd98
src/shell/command_utils.h
浏览文件 @
e147550a
...
...
@@ -5,6 +5,42 @@
#pragma once
#include <map>
#include <string>
#include <set>
#include "shell/argh.h"
#include <dsn/dist/fmt_logging.h>
inline
bool
validate_cmd
(
const
argh
::
parser
&
cmd
,
const
std
::
set
<
std
::
string
>
&
params
,
const
std
::
set
<
std
::
string
>
&
flags
)
{
if
(
cmd
.
size
()
>
1
)
{
fmt
::
print
(
stderr
,
"too many params!
\n
"
);
return
false
;
}
for
(
const
auto
&
param
:
cmd
.
params
())
{
if
(
params
.
find
(
param
.
first
)
==
params
.
end
())
{
fmt
::
print
(
stderr
,
"unknown param {} = {}
\n
"
,
param
.
first
,
param
.
second
);
return
false
;
}
}
for
(
const
auto
&
flag
:
cmd
.
flags
())
{
if
(
params
.
find
(
flag
)
!=
params
.
end
())
{
fmt
::
print
(
stderr
,
"missing value of {}
\n
"
,
flag
);
return
false
;
}
if
(
flags
.
find
(
flag
)
==
flags
.
end
())
{
fmt
::
print
(
stderr
,
"unknown flag {}
\n
"
,
flag
);
return
false
;
}
}
return
true
;
}
#define verify_logged(exp, ...) \
do { \
...
...
src/shell/commands.h
浏览文件 @
e147550a
...
...
@@ -25,7 +25,6 @@
#include <pegasus/error.h>
#include "command_executor.h"
#include "command_utils.h"
#include "command_helper.h"
#include "args.h"
...
...
@@ -262,3 +261,7 @@ bool pause_bulk_load(command_executor *e, shell_context *sc, arguments args);
bool
restart_bulk_load
(
command_executor
*
e
,
shell_context
*
sc
,
arguments
args
);
bool
cancel_bulk_load
(
command_executor
*
e
,
shell_context
*
sc
,
arguments
args
);
// == detect hotkey (see 'commands/detect_hotkey.cpp') == //
bool
detect_hotkey
(
command_executor
*
e
,
shell_context
*
sc
,
arguments
args
);
src/shell/commands/detect_hotkey.cpp
0 → 100644
浏览文件 @
e147550a
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "shell/commands.h"
#include "shell/argh.h"
#include <dsn/dist/replication/replication_types.h>
bool
generate_hotkey_request
(
dsn
::
replication
::
detect_hotkey_request
&
req
,
const
std
::
string
&
hotkey_action
,
const
std
::
string
&
hotkey_type
,
int
app_id
,
int
partition_index
,
std
::
string
&
err_info
)
{
if
(
!
strcasecmp
(
hotkey_type
.
c_str
(),
"read"
))
{
req
.
type
=
dsn
::
replication
::
hotkey_type
::
type
::
READ
;
}
else
if
(
!
strcasecmp
(
hotkey_type
.
c_str
(),
"write"
))
{
req
.
type
=
dsn
::
replication
::
hotkey_type
::
type
::
WRITE
;
}
else
{
err_info
=
fmt
::
format
(
"
\"
{}
\"
is an invalid hotkey type (should be 'read' or 'write')
\n
"
,
hotkey_type
);
return
false
;
}
if
(
!
strcasecmp
(
hotkey_action
.
c_str
(),
"start"
))
{
req
.
action
=
dsn
::
replication
::
detect_action
::
START
;
}
else
if
(
!
strcasecmp
(
hotkey_action
.
c_str
(),
"stop"
))
{
req
.
action
=
dsn
::
replication
::
detect_action
::
STOP
;
}
else
{
err_info
=
fmt
::
format
(
"
\"
{}
\"
is an invalid hotkey detect action (should be 'start' or 'stop')
\n
"
,
hotkey_action
);
return
false
;
}
req
.
pid
=
dsn
::
gpid
(
app_id
,
partition_index
);
return
true
;
}
// TODO: (Tangyanzhao) merge hotspot_partition_calculator::send_detect_hotkey_request
bool
detect_hotkey
(
command_executor
*
e
,
shell_context
*
sc
,
arguments
args
)
{
// detect_hotkey
// <-a|--app_id str><-p|--partition_index num><-t|--hotkey_type read|write>
// <-c|--detect_action start|stop><-d|--address str>
const
std
::
set
<
std
::
string
>
params
=
{
"a"
,
"app_id"
,
"p"
,
"partition_index"
,
"c"
,
"hotkey_action"
,
"t"
,
"hotkey_type"
,
"d"
,
"address"
};
const
std
::
set
<
std
::
string
>
flags
=
{};
argh
::
parser
cmd
(
args
.
argc
,
args
.
argv
,
argh
::
parser
::
PREFER_PARAM_FOR_UNREG_OPTION
);
if
(
!
validate_cmd
(
cmd
,
params
,
flags
))
{
return
false
;
}
int
app_id
;
if
(
!
dsn
::
buf2int32
(
cmd
({
"-a"
,
"--app_id"
}).
str
(),
app_id
))
{
fmt
::
print
(
stderr
,
"
\"
{}
\"
is an invalid num
\n
"
,
cmd
({
"-a"
,
"--app_id"
}).
str
());
return
false
;
}
int
partition_index
;
if
(
!
dsn
::
buf2int32
(
cmd
({
"-p"
,
"--partition_index"
}).
str
(),
partition_index
))
{
fmt
::
print
(
stderr
,
"
\"
{}
\"
is an invalid num
\n
"
,
cmd
({
"-p"
,
"--partition_index"
}).
str
());
return
false
;
}
dsn
::
rpc_address
target_address
;
std
::
string
ip_str
=
cmd
({
"-d"
,
"--address"
}).
str
();
if
(
!
target_address
.
from_string_ipv4
(
ip_str
.
c_str
()))
{
fmt
::
print
(
"invalid ip, error={}
\n
"
,
ip_str
);
return
false
;
}
std
::
string
err_info
;
std
::
string
hotkey_action
=
cmd
({
"-c"
,
"--hotkey_action"
}).
str
();
std
::
string
hotkey_type
=
cmd
({
"-t"
,
"--hotkey_type"
}).
str
();
dsn
::
replication
::
detect_hotkey_request
req
;
if
(
!
generate_hotkey_request
(
req
,
hotkey_action
,
hotkey_type
,
app_id
,
partition_index
,
err_info
))
{
fmt
::
print
(
stderr
,
err_info
);
return
false
;
}
detect_hotkey_response
resp
;
auto
err
=
sc
->
ddl_client
->
detect_hotkey
(
dsn
::
rpc_address
(
target_address
),
req
,
resp
);
if
(
err
!=
dsn
::
ERR_OK
)
{
fmt
::
print
(
stderr
,
"Hotkey detect rpc sending failed, in {}.{}, error_hint:{}
\n
"
,
app_id
,
partition_index
,
err
.
to_string
());
return
false
;
}
if
(
resp
.
err
!=
dsn
::
ERR_OK
)
{
fmt
::
print
(
stderr
,
"Hotkey detect rpc performed failed, in {}.{}, error_hint:{} {}
\n
"
,
app_id
,
partition_index
,
resp
.
err
,
resp
.
err_hint
);
return
false
;
}
return
true
;
}
src/shell/commands/disk_rebalance.cpp
浏览文件 @
e147550a
...
...
@@ -10,40 +10,8 @@
#include <fmt/ostream.h>
#include <dsn/utility/errors.h>
#include <dsn/utility/output_utils.h>
#include <dsn/utility/string_conv.h>
#include <dsn/dist/replication/duplication_common.h>
bool
validate_cmd
(
const
argh
::
parser
&
cmd
,
const
std
::
set
<
std
::
string
>
&
params
,
const
std
::
set
<
std
::
string
>
&
flags
)
{
if
(
cmd
.
size
()
>
1
)
{
fmt
::
print
(
stderr
,
"too many params!
\n
"
);
return
false
;
}
for
(
const
auto
&
param
:
cmd
.
params
())
{
if
(
params
.
find
(
param
.
first
)
==
params
.
end
())
{
fmt
::
print
(
stderr
,
"unknown param {} = {}
\n
"
,
param
.
first
,
param
.
second
);
return
false
;
}
}
for
(
const
auto
&
flag
:
cmd
.
flags
())
{
if
(
params
.
find
(
flag
)
!=
params
.
end
())
{
fmt
::
print
(
stderr
,
"missing value of {}
\n
"
,
flag
);
return
false
;
}
if
(
flags
.
find
(
flag
)
==
flags
.
end
())
{
fmt
::
print
(
stderr
,
"unknown flag {}
\n
"
,
flag
);
return
false
;
}
}
return
true
;
}
bool
query_disk_info
(
shell_context
*
sc
,
const
argh
::
parser
&
cmd
,
...
...
src/shell/main.cpp
浏览文件 @
e147550a
...
...
@@ -474,6 +474,16 @@ static command_executor commands[] = {
"<-a --app_name str> [-f --forced]"
,
cancel_bulk_load
,
},
{
"detect_hotkey"
,
"start or stop hotkey detection on a replica of a replica server"
,
"<-a|--app_id num> "
"<-p|--partition_index num> "
"<-t|--hotkey_type read|write> "
"<-c|--detect_action start|stop> "
"<-d|--address str>"
,
detect_hotkey
,
},
{
"exit"
,
"exit shell"
,
""
,
exit_shell
,
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录