Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dbe28cd4
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
dbe28cd4
编写于
2月 27, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sync code
上级
e8780ceb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
142 addition
and
16 deletion
+142
-16
include/libs/sync/sync.h
include/libs/sync/sync.h
+3
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+52
-7
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+0
-2
source/libs/sync/inc/syncRaft.h
source/libs/sync/inc/syncRaft.h
+5
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+75
-2
source/libs/sync/src/syncRaft.c
source/libs/sync/src/syncRaft.c
+7
-2
未找到文件。
include/libs/sync/sync.h
浏览文件 @
dbe28cd4
...
...
@@ -131,6 +131,9 @@ typedef struct SStateMgr {
typedef
struct
SSyncInfo
{
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
SSyncFSM
*
pFsm
;
}
SSyncInfo
;
struct
SSyncNode
;
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
dbe28cd4
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncMessage.h"
#include "taosdef.h"
#define sFatal(...) \
...
...
@@ -62,16 +63,60 @@ extern "C" {
} \
}
struct
SRaft
;
typedef
struct
SSyncNode
{
char
path
[
TSDB_FILENAME_LEN
];
int8_t
replica
;
int8_t
quorum
;
int8_t
selfIndex
;
uint32_t
vgId
;
int32_t
refCount
;
int64_t
rid
;
int8_t
replica
;
int8_t
quorum
;
SyncGroupId
vgId
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
struct
SRaft
*
pRaft
;
int32_t
(
*
FpPing
)(
struct
SSyncNode
*
ths
,
const
SyncPing
*
pMsg
);
int32_t
(
*
FpOnPing
)(
struct
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
(
*
FpOnPingReply
)(
struct
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
(
*
FpRequestVote
)(
struct
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
);
int32_t
(
*
FpOnRequestVote
)(
struct
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
(
*
FpOnRequestVoteReply
)(
struct
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
(
*
FpAppendEntries
)(
struct
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
);
int32_t
(
*
FpOnAppendEntries
)(
struct
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
(
*
FpOnAppendEntriesReply
)(
struct
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
}
SSyncNode
;
SSyncNode
*
syncNodeOpen
(
const
SSyncInfo
*
pSyncInfo
);
void
syncNodeClose
(
SSyncNode
*
pSyncNode
);
static
int32_t
doSyncNodePing
(
struct
SSyncNode
*
ths
,
const
SyncPing
*
pMsg
);
static
int32_t
onSyncNodePing
(
struct
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
static
int32_t
onSyncNodePingReply
(
struct
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
static
int32_t
doSyncNodeRequestVote
(
struct
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
);
static
int32_t
onSyncNodeRequestVote
(
struct
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
static
int32_t
onSyncNodeRequestVoteReply
(
struct
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
static
int32_t
doSyncNodeAppendEntries
(
struct
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
);
static
int32_t
onSyncNodeAppendEntries
(
struct
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
static
int32_t
onSyncNodeAppendEntriesReply
(
struct
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
dbe28cd4
...
...
@@ -43,7 +43,6 @@ typedef struct SyncPing {
const
SSyncBuffer
*
pData
;
}
SyncPing
,
RaftPing
;
typedef
struct
SyncPingReply
{
ESyncMessageType
msgType
;
const
SSyncBuffer
*
pData
;
...
...
@@ -63,7 +62,6 @@ typedef struct SyncClientRequestReply {
const
SSyncBuffer
*
pLeaderHint
;
}
SyncClientRequestReply
,
RaftClientRequestReply
;
typedef
struct
SyncRequestVote
{
ESyncMessageType
msgType
;
SyncTerm
currentTerm
;
...
...
source/libs/sync/inc/syncRaft.h
浏览文件 @
dbe28cd4
...
...
@@ -33,8 +33,8 @@ typedef struct SRaftId {
}
SRaftId
;
typedef
struct
SRaft
{
SRaftId
id
;
void
*
data
;
SRaftId
id
;
SSyncFSM
*
pFsm
;
int32_t
(
*
FpPing
)(
struct
SRaft
*
ths
,
const
RaftPing
*
pMsg
);
...
...
@@ -56,7 +56,9 @@ typedef struct SRaft {
}
SRaft
;
SRaft
*
raftCreate
(
SRaftId
raftId
,
void
*
data
);
SRaft
*
raftOpen
(
SRaftId
raftId
,
SSyncFSM
*
pFsm
);
void
raftClose
(
SRaft
*
pRaft
);
static
int32_t
doRaftPing
(
struct
SRaft
*
ths
,
const
RaftPing
*
pMsg
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
dbe28cd4
...
...
@@ -16,12 +16,17 @@
#include <stdint.h>
#include "sync.h"
#include "syncInt.h"
#include "syncRaft.h"
int32_t
syncInit
()
{
return
0
;
}
void
syncCleanUp
()
{}
int64_t
syncStart
(
const
SSyncInfo
*
pSyncInfo
)
{
return
0
;
}
int64_t
syncStart
(
const
SSyncInfo
*
pSyncInfo
)
{
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
assert
(
pSyncNode
!=
NULL
);
return
0
;
}
void
syncStop
(
int64_t
rid
)
{}
...
...
@@ -31,4 +36,72 @@ int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak) { r
ESyncState
syncGetMyRole
(
int64_t
rid
)
{
return
TAOS_SYNC_STATE_LEADER
;
}
void
syncGetNodesRole
(
int64_t
rid
,
SNodesRole
*
pNodeRole
)
{}
\ No newline at end of file
void
syncGetNodesRole
(
int64_t
rid
,
SNodesRole
*
pNodeRole
)
{}
SSyncNode
*
syncNodeOpen
(
const
SSyncInfo
*
pSyncInfo
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
malloc
(
sizeof
(
SSyncNode
));
assert
(
pSyncNode
!=
NULL
);
pSyncNode
->
FpPing
=
doSyncNodePing
;
pSyncNode
->
FpOnPing
=
onSyncNodePing
;
pSyncNode
->
FpOnPingReply
=
onSyncNodePingReply
;
pSyncNode
->
FpRequestVote
=
doSyncNodeRequestVote
;
pSyncNode
->
FpOnRequestVote
=
onSyncNodeRequestVote
;
pSyncNode
->
FpOnRequestVoteReply
=
onSyncNodeRequestVoteReply
;
pSyncNode
->
FpAppendEntries
=
doSyncNodeAppendEntries
;
pSyncNode
->
FpOnAppendEntries
=
onSyncNodeAppendEntries
;
pSyncNode
->
FpOnAppendEntriesReply
=
onSyncNodeAppendEntriesReply
;
return
pSyncNode
;
}
void
syncNodeClose
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
!=
NULL
);
raftClose
(
pSyncNode
->
pRaft
);
free
(
pSyncNode
);
}
static
int32_t
doSyncNodePing
(
struct
SSyncNode
*
ths
,
const
SyncPing
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpPing
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodePing
(
struct
SSyncNode
*
ths
,
SyncPing
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnPing
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodePingReply
(
struct
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnPingReply
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
doSyncNodeRequestVote
(
struct
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpRequestVote
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodeRequestVote
(
struct
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnRequestVote
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodeRequestVoteReply
(
struct
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnRequestVoteReply
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
doSyncNodeAppendEntries
(
struct
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpAppendEntries
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodeAppendEntries
(
struct
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnAppendEntries
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
static
int32_t
onSyncNodeAppendEntriesReply
(
struct
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
ths
->
pRaft
->
FpOnAppendEntriesReply
(
ths
->
pRaft
,
pMsg
);
return
ret
;
}
\ No newline at end of file
source/libs/sync/src/syncRaft.c
浏览文件 @
dbe28cd4
...
...
@@ -16,12 +16,12 @@
#include "syncRaft.h"
#include "sync.h"
SRaft
*
raft
Create
(
SRaftId
raftId
,
void
*
data
)
{
SRaft
*
raft
Open
(
SRaftId
raftId
,
SSyncFSM
*
pFsm
)
{
SRaft
*
pRaft
=
(
SRaft
*
)
malloc
(
sizeof
(
SRaft
));
assert
(
pRaft
!=
NULL
);
pRaft
->
id
=
raftId
;
pRaft
->
data
=
data
;
pRaft
->
pFsm
=
pFsm
;
pRaft
->
FpPing
=
doRaftPing
;
pRaft
->
FpOnPing
=
onRaftPing
;
...
...
@@ -38,6 +38,11 @@ SRaft* raftCreate(SRaftId raftId, void* data) {
return
pRaft
;
}
void
raftClose
(
SRaft
*
pRaft
)
{
assert
(
pRaft
!=
NULL
);
free
(
pRaft
);
}
static
int32_t
doRaftPing
(
struct
SRaft
*
ths
,
const
RaftPing
*
pMsg
)
{
return
0
;
}
static
int32_t
onRaftPing
(
struct
SRaft
*
ths
,
RaftPing
*
pMsg
)
{
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录