Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d72d2d69
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看板
提交
d72d2d69
编写于
6月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): SyncAppendEntries
上级
39d0b652
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
37 addition
and
3 deletion
+37
-3
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
source/libs/sync/inc/syncRaftStore.h
source/libs/sync/inc/syncRaftStore.h
+2
-2
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+32
-1
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+2
-0
未找到文件。
include/libs/sync/sync.h
浏览文件 @
d72d2d69
...
...
@@ -144,6 +144,7 @@ typedef struct SSyncLogStore {
// refactor, log[0 .. n] ==> log[m .. n]
int32_t
(
*
syncLogSetBeginIndex
)(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
beginIndex
);
int32_t
(
*
syncLogResetBeginIndex
)(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
(
*
syncLogBeginIndex
)(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
(
*
syncLogEndIndex
)(
struct
SSyncLogStore
*
pLogStore
);
bool
(
*
syncLogIsEmpty
)(
struct
SSyncLogStore
*
pLogStore
);
...
...
source/libs/sync/inc/syncRaftStore.h
浏览文件 @
d72d2d69
...
...
@@ -49,8 +49,8 @@ void raftStoreClearVote(SRaftStore *pRaftStore);
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
);
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
);
int32_t
raftStoreFromJson
(
SRaftStore
*
pRaftStore
,
cJSON
*
pJson
);
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
);
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
);
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
);
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
);
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
d72d2d69
...
...
@@ -469,6 +469,8 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
sInfo
(
"syncNodeMakeLogSame, from %ld to %ld"
,
delBegin
,
delEnd
);
logStoreSimpleLog2
(
"after syncNodeMakeLogSame"
,
ths
->
pLogStore
);
return
code
;
}
...
...
@@ -495,19 +497,30 @@ static int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry) {
// prevLogIndex == -1
static
bool
syncNodeOnAppendEntriesLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntries
*
pMsg
)
{
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
{
sTrace
(
"syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld"
,
pMsg
->
prevLogIndex
);
return
true
;
}
SyncIndex
myLastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
if
(
pMsg
->
prevLogIndex
>
myLastIndex
)
{
sTrace
(
"syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld"
,
pMsg
->
prevLogIndex
,
myLastIndex
);
return
false
;
}
SyncTerm
myPreLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
pMsg
->
prevLogIndex
+
1
);
if
(
pMsg
->
prevLogIndex
<=
myLastIndex
&&
pMsg
->
prevLogTerm
==
myPreLogTerm
)
{
sTrace
(
"syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, "
"myPreLogTerm:%lu"
,
pMsg
->
prevLogIndex
,
myLastIndex
,
pMsg
->
prevLogTerm
,
myPreLogTerm
);
return
true
;
}
sTrace
(
"syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, "
"myPreLogTerm:%lu"
,
pMsg
->
prevLogIndex
,
myLastIndex
,
pMsg
->
prevLogTerm
,
myPreLogTerm
);
return
false
;
}
...
...
@@ -517,7 +530,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
// print log
char
logBuf
[
128
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv SyncAppendEntries, term:%lu"
,
ths
->
pRaftStore
->
currentTerm
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv SyncAppendEntries, vgId:%d, term:%lu"
,
ths
->
vgId
,
ths
->
pRaftStore
->
currentTerm
);
syncAppendEntriesLog2
(
logBuf
,
pMsg
);
// if I am standby, to be added into a raft group, I should process SyncAppendEntries msg
...
...
@@ -551,6 +565,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
do
{
bool
condition
=
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
;
if
(
condition
)
{
sTrace
(
"recv SyncAppendEntries, candidate to follower"
);
syncNodeBecomeFollower
(
ths
);
// do not reply?
return
ret
;
...
...
@@ -586,6 +602,12 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
bool
condition
=
condition1
||
condition2
||
condition3
;
if
(
condition
)
{
sTrace
(
"recv SyncAppendEntries, fake match, myLastIndex:%ld, syncLogBeginIndex:%ld, syncLogEndIndex:%ld, "
"condition1:%d, condition2:%d, condition3:%d"
,
myLastIndex
,
ths
->
pLogStore
->
syncLogBeginIndex
(
ths
->
pLogStore
),
ths
->
pLogStore
->
syncLogEndIndex
(
ths
->
pLogStore
),
condition1
,
condition2
,
condition3
);
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
pReply
->
srcId
=
ths
->
myRaftId
;
...
...
@@ -623,6 +645,12 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
bool
condition
=
condition1
||
condition2
;
if
(
condition
)
{
sTrace
(
"recv SyncAppendEntries, not match, syncLogBeginIndex:%ld, syncLogEndIndex:%ld, condition1:%d, "
"condition2:%d, logOK:%d"
,
ths
->
pLogStore
->
syncLogBeginIndex
(
ths
->
pLogStore
),
ths
->
pLogStore
->
syncLogEndIndex
(
ths
->
pLogStore
),
condition1
,
condition2
,
logOK
);
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
pReply
->
srcId
=
ths
->
myRaftId
;
...
...
@@ -660,6 +688,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
// has entries in SyncAppendEntries msg
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
sTrace
(
"recv SyncAppendEntries, match, myLastIndex:%ld, hasExtraEntries:%d, hasAppendEntries:%d"
,
myLastIndex
,
hasExtraEntries
,
hasAppendEntries
);
if
(
hasExtraEntries
)
{
// make log same, rollback deleted entries
code
=
syncNodeMakeLogSame
(
ths
,
pMsg
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
d72d2d69
...
...
@@ -56,6 +56,8 @@ static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex b
return
0
;
}
int32_t
raftLogResetBeginIndex
(
struct
SSyncLogStore
*
pLogStore
)
{
return
0
;
}
static
SyncIndex
raftLogBeginIndex
(
struct
SSyncLogStore
*
pLogStore
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录