Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f10a91ff
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看板
提交
f10a91ff
编写于
11月 09, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>refactor sync interface
上级
98a7907b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
26 addition
and
18 deletion
+26
-18
include/libs/sync/sync.h
include/libs/sync/sync.h
+7
-7
source/libs/sync/inc/raft.h
source/libs/sync/inc/raft.h
+1
-1
source/libs/sync/src/raft_handle_election_message.c
source/libs/sync/src/raft_handle_election_message.c
+1
-1
source/libs/sync/src/raft_handle_vote_resp_message.c
source/libs/sync/src/raft_handle_vote_resp_message.c
+2
-2
source/libs/sync/src/raft_replication.c
source/libs/sync/src/raft_replication.c
+1
-1
source/libs/sync/src/sync.c
source/libs/sync/src/sync.c
+8
-0
source/libs/sync/src/sync_raft_impl.c
source/libs/sync/src/sync_raft_impl.c
+6
-6
未找到文件。
include/libs/sync/sync.h
浏览文件 @
f10a91ff
...
...
@@ -29,10 +29,10 @@ typedef int64_t SyncIndex;
typedef
uint64_t
SyncTerm
;
typedef
enum
{
TAOS_SYNC_
ROL
E_FOLLOWER
=
0
,
TAOS_SYNC_
ROL
E_CANDIDATE
=
1
,
TAOS_SYNC_
ROL
E_LEADER
=
2
,
}
ESync
Rol
e
;
TAOS_SYNC_
STAT
E_FOLLOWER
=
0
,
TAOS_SYNC_
STAT
E_CANDIDATE
=
1
,
TAOS_SYNC_
STAT
E_LEADER
=
2
,
}
ESync
Stat
e
;
typedef
struct
{
void
*
data
;
...
...
@@ -55,7 +55,7 @@ typedef struct {
int32_t
selfIndex
;
int32_t
replica
;
SNodeInfo
node
[
TSDB_MAX_REPLICA
];
ESync
Rol
e
role
[
TSDB_MAX_REPLICA
];
ESync
Stat
e
role
[
TSDB_MAX_REPLICA
];
}
SNodesRole
;
typedef
struct
SSyncFSM
{
...
...
@@ -159,9 +159,9 @@ void syncStop(const SSyncNode*);
int32_t
syncPropose
(
SSyncNode
*
syncNode
,
const
SSyncBuffer
*
pBuf
,
void
*
pData
,
bool
isWeak
);
//
int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode);
int32_t
syncAddNode
(
SSyncNode
syncNode
,
const
SNodeInfo
*
pNode
);
//
int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode);
int32_t
syncRemoveNode
(
SSyncNode
syncNode
,
const
SNodeInfo
*
pNode
);
extern
int32_t
sDebugFlag
;
...
...
source/libs/sync/inc/raft.h
浏览文件 @
f10a91ff
...
...
@@ -68,7 +68,7 @@ struct SSyncRaft {
int
maxMsgSize
;
SSyncRaftProgressTracker
*
tracker
;
ESync
Rol
e
state
;
ESync
Stat
e
state
;
// isLearner is true if the local raft node is a learner.
bool
isLearner
;
...
...
source/libs/sync/src/raft_handle_election_message.c
浏览文件 @
f10a91ff
...
...
@@ -19,7 +19,7 @@
#include "raft_message.h"
int
syncRaftHandleElectionMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
)
{
if
(
pRaft
->
state
==
TAOS_SYNC_
ROL
E_LEADER
)
{
if
(
pRaft
->
state
==
TAOS_SYNC_
STAT
E_LEADER
)
{
syncDebug
(
"[%d:%d] ignoring RAFT_MSG_INTERNAL_ELECTION because already leader"
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
);
return
0
;
}
...
...
source/libs/sync/src/raft_handle_vote_resp_message.c
浏览文件 @
f10a91ff
...
...
@@ -23,7 +23,7 @@ int syncRaftHandleVoteRespMessage(SSyncRaft* pRaft, const SSyncMessage* pMsg) {
int
quorum
;
int
voterIndex
;
assert
(
pRaft
->
state
==
TAOS_SYNC_
ROL
E_CANDIDATE
);
assert
(
pRaft
->
state
==
TAOS_SYNC_
STAT
E_CANDIDATE
);
voterIndex
=
syncRaftConfigurationIndexOfNode
(
pRaft
,
pMsg
->
from
);
if
(
voterIndex
==
-
1
)
{
...
...
@@ -31,7 +31,7 @@ int syncRaftHandleVoteRespMessage(SSyncRaft* pRaft, const SSyncMessage* pMsg) {
return
0
;
}
if
(
pRaft
->
state
!=
TAOS_SYNC_
ROL
E_CANDIDATE
)
{
if
(
pRaft
->
state
!=
TAOS_SYNC_
STAT
E_CANDIDATE
)
{
syncError
(
"[%d:%d] is not candidate, ignore vote resp"
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
);
return
0
;
}
...
...
source/libs/sync/src/raft_replication.c
浏览文件 @
f10a91ff
...
...
@@ -23,7 +23,7 @@ static int sendAppendEntries(SSyncRaft* pRaft, int i, SyncIndex index, SyncTerm
int
syncRaftReplicate
(
SSyncRaft
*
pRaft
,
int
i
)
{
#if 0
assert(pRaft->state == TAOS_SYNC_
ROL
E_LEADER);
assert(pRaft->state == TAOS_SYNC_
STAT
E_LEADER);
assert(i >= 0 && i < pRaft->leaderState.nProgress);
SyncNodeId nodeId = pRaft->cluster.nodeInfo[i].nodeId;
...
...
source/libs/sync/src/sync.c
浏览文件 @
f10a91ff
...
...
@@ -167,6 +167,14 @@ int32_t syncPropose(SSyncNode* syncNode, const SSyncBuffer* pBuf, void* pData, b
void
syncReconfig
(
const
SSyncNode
*
pNode
,
const
SSyncCluster
*
pCfg
)
{}
int32_t
syncAddNode
(
SSyncNode
syncNode
,
const
SNodeInfo
*
pNode
)
{
return
0
;
}
int32_t
syncRemoveNode
(
SSyncNode
syncNode
,
const
SNodeInfo
*
pNode
)
{
return
0
;
}
// process rpc rsp message from other sync server
static
void
syncProcessRsp
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
...
...
source/libs/sync/src/sync_raft_impl.c
浏览文件 @
f10a91ff
...
...
@@ -44,7 +44,7 @@ void syncRaftBecomeFollower(SSyncRaft* pRaft, SyncTerm term, SyncNodeId leaderId
resetRaft
(
pRaft
,
term
);
pRaft
->
tickFp
=
tickElection
;
pRaft
->
leaderId
=
leaderId
;
pRaft
->
state
=
TAOS_SYNC_
ROL
E_FOLLOWER
;
pRaft
->
state
=
TAOS_SYNC_
STAT
E_FOLLOWER
;
syncInfo
(
"[%d:%d] became followe at term %"
PRId64
""
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
pRaft
->
term
);
}
...
...
@@ -58,7 +58,7 @@ void syncRaftBecomePreCandidate(SSyncRaft* pRaft) {
**/
pRaft
->
stepFp
=
stepCandidate
;
pRaft
->
tickFp
=
tickElection
;
pRaft
->
state
=
TAOS_SYNC_
ROL
E_CANDIDATE
;
pRaft
->
state
=
TAOS_SYNC_
STAT
E_CANDIDATE
;
pRaft
->
candidateState
.
inPreVote
=
true
;
syncInfo
(
"[%d:%d] became pre-candidate at term %"
PRId64
""
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
pRaft
->
term
);
}
...
...
@@ -72,17 +72,17 @@ void syncRaftBecomeCandidate(SSyncRaft* pRaft) {
resetRaft
(
pRaft
,
pRaft
->
term
+
1
);
pRaft
->
tickFp
=
tickElection
;
pRaft
->
voteFor
=
pRaft
->
selfId
;
pRaft
->
state
=
TAOS_SYNC_
ROL
E_CANDIDATE
;
pRaft
->
state
=
TAOS_SYNC_
STAT
E_CANDIDATE
;
syncInfo
(
"[%d:%d] became candidate at term %"
PRId64
""
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
pRaft
->
term
);
}
void
syncRaftBecomeLeader
(
SSyncRaft
*
pRaft
)
{
assert
(
pRaft
->
state
!=
TAOS_SYNC_
ROL
E_FOLLOWER
);
assert
(
pRaft
->
state
!=
TAOS_SYNC_
STAT
E_FOLLOWER
);
pRaft
->
stepFp
=
stepLeader
;
resetRaft
(
pRaft
,
pRaft
->
term
);
pRaft
->
leaderId
=
pRaft
->
leaderId
;
pRaft
->
state
=
TAOS_SYNC_
ROL
E_LEADER
;
pRaft
->
state
=
TAOS_SYNC_
STAT
E_LEADER
;
// TODO: check if there is pending config log
int
nPendingConf
=
syncRaftLogNumOfPendingConf
(
pRaft
->
log
);
if
(
nPendingConf
>
1
)
{
...
...
@@ -263,7 +263,7 @@ static bool maybeCommit(SSyncRaft* pRaft) {
* trigger I/O requests for newly appended log entries or heartbeats.
**/
static
int
triggerAll
(
SSyncRaft
*
pRaft
)
{
assert
(
pRaft
->
state
==
TAOS_SYNC_
ROL
E_LEADER
);
assert
(
pRaft
->
state
==
TAOS_SYNC_
STAT
E_LEADER
);
int
i
;
for
(
i
=
0
;
i
<
pRaft
->
cluster
.
replica
;
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录