Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8f883399
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看板
未验证
提交
8f883399
编写于
10月 27, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 27, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17709 from taosdata/feature/3.0_mhli
refactor(sync): delete some code
上级
e1378fcb
a8109b7f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
182 deletion
+0
-182
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+0
-182
未找到文件。
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
8f883399
...
...
@@ -89,188 +89,6 @@
// /\ UNCHANGED <<candidateVars, leaderVars>>
//
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
code
;
SyncIndex
delBegin
=
pMsg
->
prevLogIndex
+
1
;
SyncIndex
delEnd
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
// invert roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
;
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
index
,
&
pRollBackEntry
);
ASSERT
(
code
==
0
);
ASSERT
(
pRollBackEntry
!=
NULL
);
if
(
syncUtilUserRollback
(
pRollBackEntry
->
msgType
))
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pRollBackEntry
->
index
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
ths
,
cbMeta
.
index
);
cbMeta
.
isWeak
=
pRollBackEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pRollBackEntry
->
seqNum
;
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
rpcFreeCont
(
rpcMsg
.
pCont
);
}
syncEntryDestory
(
pRollBackEntry
);
}
}
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
return
code
;
}
// if FromIndex > walCommitVer, return 0
// else return num of pass entries
static
int32_t
syncNodeDoMakeLogSame
(
SSyncNode
*
ths
,
SyncIndex
FromIndex
)
{
int32_t
code
=
0
;
int32_t
pass
=
0
;
SyncIndex
delBegin
=
FromIndex
;
SyncIndex
delEnd
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
// invert roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
;
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
index
,
&
pRollBackEntry
);
ASSERT
(
code
==
0
);
ASSERT
(
pRollBackEntry
!=
NULL
);
if
(
syncUtilUserRollback
(
pRollBackEntry
->
msgType
))
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pRollBackEntry
->
index
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
ths
,
cbMeta
.
index
);
cbMeta
.
isWeak
=
pRollBackEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pRollBackEntry
->
seqNum
;
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
rpcFreeCont
(
rpcMsg
.
pCont
);
}
syncEntryDestory
(
pRollBackEntry
);
}
}
// update delete begin
SyncIndex
walCommitVer
=
logStoreWalCommitVer
(
ths
->
pLogStore
);
if
(
delBegin
<=
walCommitVer
)
{
delBegin
=
walCommitVer
+
1
;
pass
=
walCommitVer
-
delBegin
+
1
;
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"update delete begin to %"
PRId64
,
delBegin
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
}
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"make log same from:%"
PRId64
", delbegin:%"
PRId64
", pass:%d"
,
FromIndex
,
delBegin
,
pass
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
return
pass
;
}
int32_t
syncNodePreCommit
(
SSyncNode
*
ths
,
SSyncRaftEntry
*
pEntry
,
int32_t
code
)
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
// leader transfer
if
(
pEntry
->
originalRpcType
==
TDMT_SYNC_LEADER_TRANSFER
)
{
int32_t
code
=
syncDoLeaderTransfer
(
ths
,
&
rpcMsg
,
pEntry
);
ASSERT
(
code
==
0
);
}
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
ths
,
cbMeta
.
index
);
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
cbMeta
.
code
=
code
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
return
0
;
}
static
bool
syncNodeOnAppendEntriesBatchLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntriesBatch
*
pMsg
)
{
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
{
return
true
;
}
SyncIndex
myLastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
if
(
pMsg
->
prevLogIndex
>
myLastIndex
)
{
sDebug
(
"vgId:%d, sync log not ok, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
SyncTerm
myPreLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
pMsg
->
prevLogIndex
+
1
);
if
(
myPreLogTerm
==
SYNC_TERM_INVALID
)
{
sDebug
(
"vgId:%d, sync log not ok2, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
if
(
pMsg
->
prevLogIndex
<=
myLastIndex
&&
pMsg
->
prevLogTerm
==
myPreLogTerm
)
{
return
true
;
}
sDebug
(
"vgId:%d, sync log not ok3, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
// really pre log match
// prevLogIndex == -1
static
bool
syncNodeOnAppendEntriesLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntries
*
pMsg
)
{
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
{
return
true
;
}
SyncIndex
myLastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
if
(
pMsg
->
prevLogIndex
>
myLastIndex
)
{
sDebug
(
"vgId:%d, sync log not ok, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
SyncTerm
myPreLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
pMsg
->
prevLogIndex
+
1
);
if
(
myPreLogTerm
==
SYNC_TERM_INVALID
)
{
sDebug
(
"vgId:%d, sync log not ok2, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
if
(
pMsg
->
prevLogIndex
<=
myLastIndex
&&
pMsg
->
prevLogTerm
==
myPreLogTerm
)
{
return
true
;
}
sDebug
(
"vgId:%d, sync log not ok3, preindex:%"
PRId64
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
int32_t
syncNodeFollowerCommit
(
SSyncNode
*
ths
,
SyncIndex
newCommitIndex
)
{
// maybe update commit index, leader notice me
if
(
newCommitIndex
>
ths
->
commitIndex
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录