Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
82f89875
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
82f89875
编写于
12月 22, 2021
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add raftServer code
上级
489c2ca9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
169 addition
and
0 deletion
+169
-0
contrib/test/craft/raftMain.c
contrib/test/craft/raftMain.c
+107
-0
contrib/test/craft/raftServer.c
contrib/test/craft/raftServer.c
+20
-0
contrib/test/craft/raftServer.h
contrib/test/craft/raftServer.h
+42
-0
未找到文件。
contrib/test/craft/raftMain.c
0 → 100644
浏览文件 @
82f89875
#include <stdio.h>
#include <raft.h>
#include <raft/uv.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <getopt.h>
#include "raftServer.h"
#define COMMAND_LEN 128
const
char
*
exe_name
;
void
*
startServerFunc
(
void
*
param
)
{
SRaftServer
*
pServer
=
(
SRaftServer
*
)
param
;
int32_t
r
=
raftServerStart
(
pServer
);
assert
(
r
==
0
);
return
NULL
;
}
// Console ---------------------------------
void
console
(
SRaftServer
*
pRaftServer
)
{
while
(
1
)
{
char
cmd_buf
[
COMMAND_LEN
];
memset
(
cmd_buf
,
0
,
sizeof
(
cmd_buf
));
char
*
ret
=
fgets
(
cmd_buf
,
COMMAND_LEN
,
stdin
);
if
(
!
ret
)
{
exit
(
-
1
);
}
int
pos
=
strlen
(
cmd_buf
);
if
(
cmd_buf
[
pos
-
1
]
==
'\n'
)
{
cmd_buf
[
pos
-
1
]
=
'\0'
;
}
if
(
strncmp
(
cmd_buf
,
""
,
COMMAND_LEN
)
==
0
)
{
continue
;
}
printf
(
"cmd_buf: [%s]
\n
"
,
cmd_buf
);
}
}
void
*
startConsoleFunc
(
void
*
param
)
{
SRaftServer
*
pServer
=
(
SRaftServer
*
)
param
;
console
(
pServer
);
return
NULL
;
}
// Config ---------------------------------
#define DIR_LEN 128
#define HOST_LEN 128
typedef
struct
SRaftServerConfig
{
char
host
[
HOST_LEN
];
uint32_t
port
;
char
dir
[
DIR_LEN
];
}
SRaftServerConfig
;
void
parseConf
(
int
argc
,
char
**
argv
,
SRaftServerConfig
*
pConf
)
{
snprintf
(
pConf
->
dir
,
sizeof
(
pConf
->
dir
),
"%s"
,
argv
[
1
]);
sscanf
(
argv
[
2
],
"%u"
,
&
pConf
->
port
);
snprintf
(
pConf
->
dir
,
sizeof
(
pConf
->
dir
),
"%s"
,
argv
[
3
]);
}
// -----------------------------------------
void
usage
()
{
printf
(
"
\n
"
);
printf
(
"usage: %s host port dir
\n
"
,
exe_name
);
printf
(
"eg : %s 127.0.0.1 10000 ./data
\n
"
,
exe_name
);
printf
(
"
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
int32_t
ret
;
exe_name
=
argv
[
0
];
if
(
argc
!=
4
)
{
usage
();
exit
(
-
1
);
}
SRaftServerConfig
conf
;
parseConf
(
argc
,
argv
,
&
conf
);
struct
raft_fsm
fsm
;
initFsm
(
&
fsm
);
SRaftServer
raftServer
;
ret
=
raftServerInit
(
&
raftServer
,
&
conf
,
&
fsm
);
pthread_t
tidRaftServer
;
pthread_create
(
&
tidRaftServer
,
NULL
,
startServerFunc
,
&
raftServer
);
pthread_t
tidConsole
;
pthread_create
(
&
tidConsole
,
NULL
,
startConsoleFunc
,
&
raftServer
);
while
(
1
)
{
sleep
(
10
);
}
return
0
;
}
contrib/test/craft/raftServer.c
0 → 100644
浏览文件 @
82f89875
#include "raftServer.h"
int32_t
raftServerInit
(
SRaftServer
*
pRaftServer
,
struct
SRaftServerConfig
*
pConf
,
struct
raft_fsm
*
pFsm
)
{
return
0
;
}
int32_t
raftServerStart
(
SRaftServer
*
pRaftServer
)
{
}
void
raftServerClose
(
SRaftServer
*
pRaftServer
)
{
}
int32_t
initFsm
(
struct
raft_fsm
*
fsm
)
{
return
0
;
}
contrib/test/craft/raftServer.h
0 → 100644
浏览文件 @
82f89875
#ifndef TDENGINE_RAFT_SERVER_H
#define TDENGINE_RAFT_SERVER_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "raft.h"
#include "raft/uv.h"
#define DIR_LEN 128
#define ADDRESS_LEN 128
typedef
struct
{
char
dir
[
DIR_LEN
];
/* Data dir of UV I/O backend */
char
address
[
ADDRESS_LEN
];
/* Raft instance address */
raft_id
raftId
;
/* For vote */
struct
raft_fsm
*
fsm
;
/* Sample application FSM */
struct
raft
raft
;
/* Raft instance */
struct
raft_io
io
;
/* UV I/O backend */
struct
uv_loop_s
loop
;
/* UV loop */
struct
raft_uv_transport
transport
;
/* UV I/O backend transport */
}
SRaftServer
;
struct
SRaftServerConfig
;
int32_t
raftServerInit
(
SRaftServer
*
pRaftServer
,
struct
SRaftServerConfig
*
pConf
,
struct
raft_fsm
*
pFsm
);
int32_t
raftServerStart
(
SRaftServer
*
pRaftServer
);
void
raftServerClose
(
SRaftServer
*
pRaftServer
);
int
initFsm
(
struct
raft_fsm
*
fsm
);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_RAFT_SERVER_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录