Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8ae9fb6a
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看板
提交
8ae9fb6a
编写于
3月 14, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync index
上级
9734b9b0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
6 deletion
+66
-6
source/libs/sync/inc/syncRaftStore.h
source/libs/sync/inc/syncRaftStore.h
+6
-0
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+1
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+28
-6
source/libs/sync/src/syncRaftStore.c
source/libs/sync/src/syncRaftStore.c
+29
-0
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-0
未找到文件。
source/libs/sync/inc/syncRaftStore.h
浏览文件 @
8ae9fb6a
...
...
@@ -43,6 +43,12 @@ int32_t raftStorePersist(SRaftStore *pRaftStore);
int32_t
raftStoreSerialize
(
SRaftStore
*
pRaftStore
,
char
*
buf
,
size_t
len
);
int32_t
raftStoreDeserialize
(
SRaftStore
*
pRaftStore
,
char
*
buf
,
size_t
len
);
bool
raftStoreHasVoted
(
SRaftStore
*
pRaftStore
);
void
raftStoreVote
(
SRaftStore
*
pRaftStore
,
SRaftId
*
pRaftId
);
void
raftStoreClearVote
(
SRaftStore
*
pRaftStore
);
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
);
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
);
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
);
void
raftStorePrint2
(
char
*
s
,
SRaftStore
*
pObj
);
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
8ae9fb6a
...
...
@@ -34,6 +34,7 @@ void syncUtilnodeInfo2EpSet(const SNodeInfo* pNodeInfo, SEpSet* pEpSet);
void
syncUtilraftId2EpSet
(
const
SRaftId
*
raftId
,
SEpSet
*
pEpSet
);
void
syncUtilnodeInfo2raftId
(
const
SNodeInfo
*
pNodeInfo
,
SyncGroupId
vgId
,
SRaftId
*
raftId
);
bool
syncUtilSameId
(
const
SRaftId
*
pId1
,
const
SRaftId
*
pId2
);
bool
syncUtilEmptyId
(
const
SRaftId
*
pId
);
// ---- SSyncBuffer ----
void
syncUtilbufBuild
(
SSyncBuffer
*
syncBuf
,
size_t
len
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
8ae9fb6a
...
...
@@ -21,6 +21,7 @@
#include "syncEnv.h"
#include "syncIndexMgr.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncReplication.h"
...
...
@@ -52,6 +53,9 @@ static void syncNodeFollower2Candidate(SSyncNode* pSyncNode);
static
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
);
static
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
);
// raft vote ----
static
void
syncNodeVoteForTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
,
SRaftId
*
pRaftId
);
static
void
syncNodeVoteForSelf
(
SSyncNode
*
pSyncNode
);
// ---------------------------------
int32_t
syncInit
()
{
...
...
@@ -602,13 +606,9 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
// raft state change ----
static
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
)
{
if
(
term
>
pSyncNode
->
pRaftStore
->
currentTerm
)
{
pSyncNode
->
pRaftStore
->
currentTerm
=
term
;
raftStorePersist
(
pSyncNode
->
pRaftStore
);
raftStoreSetTerm
(
pSyncNode
->
pRaftStore
,
term
);
syncNodeBecomeFollower
(
pSyncNode
);
pSyncNode
->
pRaftStore
->
voteFor
=
EMPTY_RAFT_ID
;
raftStorePersist
(
pSyncNode
->
pRaftStore
);
raftStoreClearVote
(
pSyncNode
->
pRaftStore
);
}
}
...
...
@@ -679,3 +679,25 @@ static void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
syncNodeBecomeFollower
(
pSyncNode
);
}
// raft vote ----
static
void
syncNodeVoteForTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
,
SRaftId
*
pRaftId
)
{
assert
(
term
==
pSyncNode
->
pRaftStore
->
currentTerm
);
assert
(
!
raftStoreHasVoted
(
pSyncNode
->
pRaftStore
));
raftStoreVote
(
pSyncNode
->
pRaftStore
,
pRaftId
);
}
static
void
syncNodeVoteForSelf
(
SSyncNode
*
pSyncNode
)
{
syncNodeVoteForTerm
(
pSyncNode
,
pSyncNode
->
pRaftStore
->
currentTerm
,
&
(
pSyncNode
->
myRaftId
));
SyncRequestVoteReply
*
pMsg
=
syncRequestVoteReplyBuild
();
pMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
pSyncNode
->
myRaftId
;
pMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
voteGranted
=
true
;
voteGrantedVote
(
pSyncNode
->
pVotesGranted
,
pMsg
);
votesRespondAdd
(
pSyncNode
->
pVotesRespond
,
pMsg
);
syncRequestVoteReplyDestroy
(
pMsg
);
}
\ No newline at end of file
source/libs/sync/src/syncRaftStore.c
浏览文件 @
8ae9fb6a
...
...
@@ -15,6 +15,8 @@
#include "syncRaftStore.h"
#include "cJSON.h"
#include "syncEnv.h"
#include "syncUtil.h"
// private function
static
int32_t
raftStoreInit
(
SRaftStore
*
pRaftStore
);
...
...
@@ -135,6 +137,33 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
return
0
;
}
bool
raftStoreHasVoted
(
SRaftStore
*
pRaftStore
)
{
bool
b
=
syncUtilEmptyId
(
&
(
pRaftStore
->
voteFor
));
return
b
;
}
void
raftStoreVote
(
SRaftStore
*
pRaftStore
,
SRaftId
*
pRaftId
)
{
assert
(
!
raftStoreHasVoted
(
pRaftStore
));
assert
(
!
syncUtilEmptyId
(
pRaftId
));
pRaftStore
->
voteFor
=
*
pRaftId
;
raftStorePersist
(
pRaftStore
);
}
void
raftStoreClearVote
(
SRaftStore
*
pRaftStore
)
{
pRaftStore
->
voteFor
=
EMPTY_RAFT_ID
;
raftStorePersist
(
pRaftStore
);
}
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
)
{
++
(
pRaftStore
->
currentTerm
);
raftStorePersist
(
pRaftStore
);
}
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
)
{
pRaftStore
->
currentTerm
=
term
;
raftStorePersist
(
pRaftStore
);
}
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
)
{
char
serialized
[
RAFT_STORE_BLOCK_SIZE
];
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
8ae9fb6a
...
...
@@ -74,6 +74,8 @@ bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
return
ret
;
}
bool
syncUtilEmptyId
(
const
SRaftId
*
pId
)
{
return
(
pId
->
addr
==
0
&&
pId
->
vgId
==
0
);
}
// ---- SSyncBuffer -----
void
syncUtilbufBuild
(
SSyncBuffer
*
syncBuf
,
size_t
len
)
{
syncBuf
->
len
=
len
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录