Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3f3fb4a2
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3f3fb4a2
编写于
12月 28, 2021
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add node by manual operation
上级
829fd712
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
18 deletion
+85
-18
contrib/test/craft/common.h
contrib/test/craft/common.h
+1
-0
contrib/test/craft/raftMain.c
contrib/test/craft/raftMain.c
+63
-13
contrib/test/craft/raftServer.c
contrib/test/craft/raftServer.c
+21
-5
未找到文件。
contrib/test/craft/common.h
浏览文件 @
3f3fb4a2
...
...
@@ -20,6 +20,7 @@ typedef struct {
}
Addr
;
typedef
struct
{
int
voter
;
Addr
me
;
Addr
peers
[
MAX_PEERS
];
int
peersCount
;
...
...
contrib/test/craft/raftMain.c
浏览文件 @
3f3fb4a2
...
...
@@ -104,7 +104,7 @@ const char* state2String(unsigned short state) {
void
printRaftConfiguration
(
struct
raft_configuration
*
c
)
{
printf
(
"configuration:
\n
"
);
for
(
int
i
=
0
;
i
<
c
->
n
;
++
i
)
{
printf
(
"%llu -- %d -- %s
\n
"
,
c
->
servers
->
id
,
c
->
servers
->
role
,
c
->
servers
->
address
);
printf
(
"%llu -- %d -- %s
\n
"
,
c
->
servers
[
i
].
id
,
c
->
servers
[
i
].
role
,
c
->
servers
[
i
].
address
);
}
}
...
...
@@ -119,11 +119,9 @@ void printRaftState(struct raft *r) {
printf
(
"last_applied: %llu
\n
"
,
r
->
last_applied
);
printf
(
"last_stored: %llu
\n
"
,
r
->
last_stored
);
/*
printf
(
"configuration_index: %llu
\n
"
,
r
->
configuration_index
);
printf
(
"configuration_uncommitted_index: %llu
\n
"
,
r
->
configuration_uncommitted_index
);
printRaftConfiguration
(
&
r
->
configuration
);
*/
printf
(
"----------------------------
\n
"
);
}
...
...
@@ -164,6 +162,18 @@ void getValue(const char *key) {
}
}
void
raft_change_cb_add
(
struct
raft_change
*
req
,
int
status
)
{
printf
(
"raft_change_cb_add status:%d ...
\n
"
,
status
);
}
void
raft_change_cb_assign
(
struct
raft_change
*
req
,
int
status
)
{
printf
(
"raft_change_cb_assign status:%d ...
\n
"
,
status
);
}
void
raft_change_cb_remove
(
struct
raft_change
*
req
,
int
status
)
{
printf
(
"raft_change_cb_remove status:%d ...
\n
"
,
status
);
}
void
console
(
SRaftServer
*
pRaftServer
)
{
while
(
1
)
{
char
cmd_buf
[
COMMAND_LEN
];
...
...
@@ -193,30 +203,59 @@ void console(SRaftServer *pRaftServer) {
parseCommand
(
cmd_buf
,
cmd
,
param1
,
param2
,
TOKEN_LEN
);
if
(
strcmp
(
cmd
,
"addnode"
)
==
0
)
{
printf
(
"not support
\n
"
);
//
printf("not support \n");
/*
char
host
[
HOST_LEN
];
uint32_t
port
;
parseAddr
(
param1
,
host
,
HOST_LEN
,
&
port
);
uint64_t
rid
=
raftId
(
host
,
port
);
struct
raft_change
*
req
=
raft_malloc
(
sizeof
(
*
req
));
int r = raft_add(&pRaftServer->raft, req, rid, param1,
NULL
);
int
r
=
raft_add
(
&
pRaftServer
->
raft
,
req
,
rid
,
param1
,
raft_change_cb_add
);
if
(
r
!=
0
)
{
printf("raft_add: %s \n", raft_errmsg(&pRaftServer->raft));
printf
(
"raft_add
error
: %s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
}
printf
(
"add node: %lu %s
\n
"
,
rid
,
param1
);
struct
raft_change
*
req2
=
raft_malloc
(
sizeof
(
*
req2
));
r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, NULL);
r
=
raft_assign
(
&
pRaftServer
->
raft
,
req2
,
rid
,
RAFT_VOTER
,
raft_change_cb_assign
);
if
(
r
!=
0
)
{
printf
(
"raft_assign error: %s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
}
printf
(
"raft_assign: %s %d
\n
"
,
param1
,
RAFT_VOTER
);
}
else
if
(
strcmp
(
cmd
,
"activate"
)
==
0
)
{
char
host
[
HOST_LEN
];
uint32_t
port
;
parseAddr
(
param1
,
host
,
HOST_LEN
,
&
port
);
uint64_t
rid
=
raftId
(
host
,
port
);
struct
raft_change
*
req2
=
raft_malloc
(
sizeof
(
*
req2
));
int
r
=
raft_assign
(
&
pRaftServer
->
raft
,
req2
,
rid
,
RAFT_VOTER
,
raft_change_cb_assign
);
if
(
r
!=
0
)
{
printf("raft_assign: %s \n", raft_errmsg(&pRaftServer->raft));
printf
(
"raft_assign
error
: %s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
}
*/
printf
(
"raft_assign: %s %d
\n
"
,
param1
,
RAFT_VOTER
);
}
else
if
(
strcmp
(
cmd
,
"dropnode"
)
==
0
)
{
printf
(
"not support
\n
"
);
char
host
[
HOST_LEN
];
uint32_t
port
;
parseAddr
(
param1
,
host
,
HOST_LEN
,
&
port
);
uint64_t
rid
=
raftId
(
host
,
port
);
struct
raft_change
*
req
=
raft_malloc
(
sizeof
(
*
req
));
int
r
=
raft_remove
(
&
pRaftServer
->
raft
,
req
,
rid
,
raft_change_cb_remove
);
if
(
r
!=
0
)
{
printf
(
"raft_remove: %s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
}
printf
(
"drop node: %lu %s
\n
"
,
rid
,
param1
);
}
else
if
(
strcmp
(
cmd
,
"put"
)
==
0
)
{
char
buf
[
256
];
...
...
@@ -234,6 +273,7 @@ void console(SRaftServer *pRaftServer) {
}
else
if
(
strcmp
(
cmd
,
"help"
)
==
0
)
{
printf
(
"addnode
\"
127.0.0.1:8888
\"
\n
"
);
printf
(
"activate
\"
127.0.0.1:8888
\"
\n
"
);
printf
(
"dropnode
\"
127.0.0.1:8888
\"
\n
"
);
printf
(
"put key value
\n
"
);
printf
(
"get key
\n
"
);
...
...
@@ -256,7 +296,9 @@ void *startConsoleFunc(void *param) {
// Config ---------------------------------
void
usage
()
{
printf
(
"
\n
usage:
\n
"
);
printf
(
"%s --me=127.0.0.1:10000 --dir=./data
\n
"
,
exe_name
);
printf
(
"%s --me=127.0.0.1:10000 --dir=./data --voter
\n
"
,
exe_name
);
printf
(
"%s --me=127.0.0.1:10001 --dir=./data
\n
"
,
exe_name
);
printf
(
"%s --me=127.0.0.1:10002 --dir=./data
\n
"
,
exe_name
);
printf
(
"
\n
"
);
printf
(
"%s --me=127.0.0.1:10000 --peers=127.0.0.1:10001,127.0.0.1:10002 --dir=./data
\n
"
,
exe_name
);
printf
(
"%s --me=127.0.0.1:10001 --peers=127.0.0.1:10000,127.0.0.1:10002 --dir=./data
\n
"
,
exe_name
);
...
...
@@ -271,13 +313,15 @@ void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
option_index
=
0
;
static
struct
option
long_options
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"voter"
,
no_argument
,
NULL
,
'v'
},
{
"peers"
,
required_argument
,
NULL
,
'p'
},
{
"me"
,
required_argument
,
NULL
,
'm'
},
{
"dir"
,
required_argument
,
NULL
,
'd'
},
{
NULL
,
0
,
NULL
,
0
}
};
while
((
option_value
=
getopt_long
(
argc
,
argv
,
"hp:m:d:"
,
long_options
,
&
option_index
))
!=
-
1
)
{
pConf
->
voter
=
0
;
while
((
option_value
=
getopt_long
(
argc
,
argv
,
"hvp:m:d:"
,
long_options
,
&
option_index
))
!=
-
1
)
{
switch
(
option_value
)
{
case
'm'
:
{
parseAddr
(
optarg
,
pConf
->
me
.
host
,
sizeof
(
pConf
->
me
.
host
),
&
pConf
->
me
.
port
);
...
...
@@ -295,6 +339,10 @@ void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
break
;
}
case
'v'
:
{
pConf
->
voter
=
1
;
break
;
}
case
'd'
:
{
snprintf
(
pConf
->
dir
,
sizeof
(
pConf
->
dir
),
"%s"
,
optarg
);
...
...
@@ -338,6 +386,8 @@ int main(int argc, char **argv) {
exit
(
-
1
);
}
signal
(
SIGPIPE
,
SIG_IGN
);
SRaftServerConfig
conf
;
parseConf
(
argc
,
argv
,
&
conf
);
printConf
(
&
conf
);
...
...
contrib/test/craft/raftServer.c
浏览文件 @
3f3fb4a2
...
...
@@ -85,29 +85,45 @@ int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf,
pRaftServer
->
fsm
=
pFsm
;
ret
=
uv_loop_init
(
&
pRaftServer
->
loop
);
if
(
!
ret
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
assert
(
0
);
}
ret
=
raft_uv_tcp_init
(
&
pRaftServer
->
transport
,
&
pRaftServer
->
loop
);
if
(
!
ret
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
assert
(
0
);
}
ret
=
raft_uv_init
(
&
pRaftServer
->
io
,
&
pRaftServer
->
loop
,
pRaftServer
->
dir
,
&
pRaftServer
->
transport
);
if
(
!
ret
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
assert
(
0
);
}
ret
=
raft_init
(
&
pRaftServer
->
raft
,
&
pRaftServer
->
io
,
pRaftServer
->
fsm
,
pRaftServer
->
raftId
,
pRaftServer
->
address
);
if
(
!
ret
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
raft_errmsg
(
&
pRaftServer
->
raft
));
assert
(
0
);
}
struct
raft_configuration
conf
;
raft_configuration_init
(
&
conf
);
raft_configuration_add
(
&
conf
,
pRaftServer
->
raftId
,
pRaftServer
->
address
,
RAFT_VOTER
);
if
(
pConf
->
voter
==
0
)
{
raft_configuration_add
(
&
conf
,
pRaftServer
->
raftId
,
pRaftServer
->
address
,
RAFT_SPARE
);
}
else
{
raft_configuration_add
(
&
conf
,
pRaftServer
->
raftId
,
pRaftServer
->
address
,
RAFT_VOTER
);
}
printf
(
"add myself: %llu - %s
\n
"
,
pRaftServer
->
raftId
,
pRaftServer
->
address
);
for
(
int
i
=
0
;
i
<
pConf
->
peersCount
;
++
i
)
{
const
Addr
*
pAddr
=
&
pConf
->
peers
[
i
];
raft_id
rid
=
raftId
(
pAddr
->
host
,
pAddr
->
port
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录