Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
551d7cfa
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看板
提交
551d7cfa
编写于
3月 06, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
29fab2e3
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
93 addition
and
76 deletion
+93
-76
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+8
-9
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-1
source/libs/sync/inc/syncRequestVote.h
source/libs/sync/inc/syncRequestVote.h
+0
-4
source/libs/sync/inc/syncRequestVoteReply.h
source/libs/sync/inc/syncRequestVoteReply.h
+0
-2
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+2
-2
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+1
-1
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+36
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+42
-54
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+2
-2
source/libs/sync/src/syncRequestVoteReply.c
source/libs/sync/src/syncRequestVoteReply.c
+1
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
551d7cfa
...
...
@@ -131,6 +131,7 @@ typedef struct SSyncNode {
// raft algorithm
SSyncFSM
*
pFsm
;
int32_t
quorum
;
SRaftId
leaderCache
;
// life cycle
int32_t
refCount
;
...
...
@@ -193,18 +194,16 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode);
int32_t
syncNodeStartElectTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeStopElectTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeResetElectTimer
(
SSyncNode
*
pSyncNode
,
int32_t
ms
);
int32_t
syncNodeStartHeartbeatTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeStopHeartbeatTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeResetHeartbeatTimer
(
SSyncNode
*
pSyncNode
,
int32_t
ms
);
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
);
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
);
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
);
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
);
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
);
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRequestVote
(
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
551d7cfa
...
...
@@ -30,7 +30,7 @@ extern "C" {
// encode as uint32
typedef
enum
ESyncMessageType
{
SYNC_UNKNOWN
=
77
,
SYNC_UNKNOWN
=
9999
,
SYNC_TIMEOUT
=
99
,
SYNC_PING
=
101
,
SYNC_PING_REPLY
=
103
,
...
...
source/libs/sync/inc/syncRequestVote.h
浏览文件 @
551d7cfa
...
...
@@ -28,10 +28,6 @@ extern "C" {
#include "syncRaft.h"
#include "taosdef.h"
void
requestVote
(
SRaft
*
pRaft
,
const
SyncRequestVote
*
pMsg
);
void
onRequestVote
(
SRaft
*
pRaft
,
const
SyncRequestVote
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncRequestVoteReply.h
浏览文件 @
551d7cfa
...
...
@@ -28,8 +28,6 @@ extern "C" {
#include "syncRaft.h"
#include "taosdef.h"
void
onRequestVoteReply
(
SRaft
*
pRaft
,
const
SyncRequestVoteReply
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
551d7cfa
...
...
@@ -15,7 +15,7 @@
#include "syncAppendEntries.h"
void
appendEntries
(
SRaft
*
pRaft
,
const
SyncAppendEntries
*
pMsg
)
{
int32_t
syncNodeAppendEntries
(
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
)
{
// TLA+ Spec
// AppendEntries(i, j) ==
// /\ i /= j
...
...
@@ -42,7 +42,7 @@ void appendEntries(SRaft *pRaft, const SyncAppendEntries *pMsg) {
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
}
void
onAppendEntries
(
SRaft
*
pRaft
,
const
SyncAppendEntries
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
// TLA+ Spec
// HandleAppendEntriesRequest(i, j, m) ==
// LET logOk == \/ m.mprevLogIndex = 0
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
551d7cfa
...
...
@@ -15,7 +15,7 @@
#include "syncAppendEntriesReply.h"
void
onAppendEntriesReply
(
SRaft
*
pRaft
,
const
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
// TLA+ Spec
// HandleAppendEntriesResponse(i, j, m) ==
// /\ m.mterm = currentTerm[i]
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
551d7cfa
...
...
@@ -245,6 +245,42 @@ static void *syncIOConsumerFunc(void *param) {
syncPingReplyDestroy
(
pSyncMsg
);
}
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_REQUEST_VOTE
)
{
if
(
io
->
FpOnSyncRequestVote
)
{
SyncRequestVote
*
pSyncMsg
;
pSyncMsg
=
syncRequestVoteBuild
(
pRpcMsg
->
contLen
);
syncRequestVoteFromRpcMsg
(
pRpcMsg
,
pSyncMsg
);
io
->
FpOnSyncRequestVote
(
io
->
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_REQUEST_VOTE_REPLY
)
{
if
(
io
->
FpOnSyncRequestVoteReply
)
{
SyncRequestVoteReply
*
pSyncMsg
;
pSyncMsg
=
SyncRequestVoteReplyBuild
();
syncRequestVoteReplyFromRpcMsg
(
pRpcMsg
,
pSyncMsg
);
io
->
FpOnSyncRequestVoteReply
(
io
->
pSyncNode
,
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
}
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_APPEND_ENTRIES
)
{
if
(
io
->
FpOnSyncAppendEntries
)
{
SyncAppendEntries
*
pSyncMsg
;
pSyncMsg
=
syncAppendEntriesBuild
(
pRpcMsg
->
contLen
);
syncAppendEntriesFromRpcMsg
(
pRpcMsg
,
pSyncMsg
);
io
->
FpOnSyncAppendEntries
(
io
->
pSyncNode
,
pSyncMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
}
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_APPEND_ENTRIES_REPLY
)
{
if
(
io
->
FpOnSyncAppendEntriesReply
)
{
SyncAppendEntriesReply
*
pSyncMsg
;
pSyncMsg
=
syncAppendEntriesReplyBuild
();
syncAppendEntriesReplyFromRpcMsg
(
pRpcMsg
,
pSyncMsg
);
io
->
FpOnSyncAppendEntriesReply
(
io
->
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_TIMEOUT
)
{
if
(
io
->
FpOnSyncTimeout
!=
NULL
)
{
SyncTimeout
*
pSyncMsg
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
551d7cfa
...
...
@@ -31,16 +31,16 @@ static void syncNodeEqElectTimer(void* param, void* tmrId);
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
);
static
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
);
static
int32_t
syncNodeRequestVote
(
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
);
static
int32_t
syncNodeAppendEntries
(
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
);
static
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
static
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
static
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
static
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
static
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
static
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
static
int32_t
syncNodeOnTimeoutCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
static
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
);
// ---------------------------------
int32_t
syncInit
()
{
...
...
@@ -188,8 +188,6 @@ int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode) {
return
0
;
}
int32_t
syncNodeResetElectTimer
(
SSyncNode
*
pSyncNode
,
int32_t
ms
)
{
return
0
;
}
int32_t
syncNodeStartHeartbeatTimer
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
pHeartbeatTimer
==
NULL
)
{
pSyncNode
->
pHeartbeatTimer
=
...
...
@@ -209,20 +207,6 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) {
return
0
;
}
int32_t
syncNodeResetHeartbeatTimer
(
SSyncNode
*
pSyncNode
,
int32_t
ms
)
{
return
0
;
}
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
)
{}
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{}
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
)
{}
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
)
{}
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
)
{}
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
)
{}
// ------ local funciton ---------
static
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
)
{
sTrace
(
"syncNodePing pSyncNode:%p "
,
pSyncNode
);
...
...
@@ -252,16 +236,6 @@ static int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, Syn
return
ret
;
}
static
int32_t
syncNodeRequestVote
(
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeAppendEntries
(
SSyncNode
*
ths
,
const
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
)
{
SEpSet
epSet
;
syncUtilraftId2EpSet
(
destRaftId
,
&
epSet
);
...
...
@@ -311,26 +285,6 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
return
ret
;
}
static
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
0
;
return
ret
;
}
static
int32_t
syncNodeOnTimeoutCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
)
{
int32_t
ret
=
0
;
sTrace
(
"<-- syncNodeOnTimeoutCb -->"
);
...
...
@@ -378,3 +332,37 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
static
void
syncNodeEqElectTimer
(
void
*
param
,
void
*
tmrId
)
{}
static
void
syncNodeEqHeartbeatTimer
(
void
*
param
,
void
*
tmrId
)
{}
static
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
pSyncNode
->
leaderCache
.
addr
=
0
;
pSyncNode
->
leaderCache
.
vgId
=
0
;
}
syncNodeStopHeartbeatTimer
(
pSyncNode
);
syncNodeStartElectTimer
(
pSyncNode
);
}
static
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
pSyncNode
->
leaderCache
=
pSyncNode
->
raftId
;
// next Index +=1
// match Index = 0;
syncNodeStopElectTimer
(
pSyncNode
);
syncNodeStartHeartbeatTimer
(
pSyncNode
);
// appendEntries;
}
static
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
);
pSyncNode
->
state
=
TAOS_SYNC_STATE_CANDIDATE
;
}
static
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
)
{}
static
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
)
{}
static
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
)
{}
\ No newline at end of file
source/libs/sync/src/syncRequestVote.c
浏览文件 @
551d7cfa
...
...
@@ -15,7 +15,7 @@
#include "syncRequestVote.h"
void
requestVote
(
SRaft
*
pRaft
,
const
SyncRequestVote
*
pMsg
)
{
int32_t
syncNodeRequestVote
(
SSyncNode
*
ths
,
const
SyncRequestVote
*
pMsg
)
{
// TLA+ Spec
// RequestVote(i, j) ==
// /\ state[i] = Candidate
...
...
@@ -29,7 +29,7 @@ void requestVote(SRaft *pRaft, const SyncRequestVote *pMsg) {
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
}
void
onRequestVote
(
SRaft
*
pRaft
,
const
SyncRequestVote
*
pMsg
)
{
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
)
{
// TLA+ Spec
// HandleRequestVoteRequest(i, j, m) ==
// LET logOk == \/ m.mlastLogTerm > LastTerm(log[i])
...
...
source/libs/sync/src/syncRequestVoteReply.c
浏览文件 @
551d7cfa
...
...
@@ -15,7 +15,7 @@
#include "syncRequestVoteReply.h"
void
onRequestVoteReply
(
SRaft
*
pRaft
,
const
SyncRequestVoteReply
*
pMsg
)
{
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
)
{
// TLA+ Spec
// HandleRequestVoteResponse(i, j, m) ==
// \* This tallies votes even when the current state is not Candidate, but
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录