Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9786ba2f
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看板
提交
9786ba2f
编写于
6月 23, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sync): update nextindex, matchindex when backto nolog
上级
2f2715ac
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
13 deletion
+71
-13
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+9
-12
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+5
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+47
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+9
-0
未找到文件。
include/libs/sync/sync.h
浏览文件 @
9786ba2f
...
...
@@ -28,6 +28,7 @@ extern bool gRaftDetailLog;
#define SYNC_INDEX_BEGIN 0
#define SYNC_INDEX_INVALID -1
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
typedef
uint64_t
SyncNodeId
;
typedef
int32_t
SyncGroupId
;
...
...
include/libs/sync/syncTools.h
浏览文件 @
9786ba2f
...
...
@@ -43,7 +43,7 @@ void setElectTimerMS(int64_t rid, int32_t electTimerMS);
void
setHeartbeatTimerMS
(
int64_t
rid
,
int32_t
hbTimerMS
);
// for compatibility, the same as syncPropose
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncForwardToPeer
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
// utils
const
char
*
syncUtilState2String
(
ESyncState
state
);
...
...
@@ -468,7 +468,7 @@ typedef struct SyncLeaderTransfer {
SRaftId destId;
*/
SNodeInfo
newNodeInfo
;
SRaftId
newLeaderId
;
SRaftId
newLeaderId
;
}
SyncLeaderTransfer
;
SyncLeaderTransfer
*
syncLeaderTransferBuild
(
int32_t
vgId
);
...
...
@@ -489,17 +489,16 @@ void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg);
void
syncLeaderTransferLog
(
const
SyncLeaderTransfer
*
pMsg
);
void
syncLeaderTransferLog2
(
char
*
s
,
const
SyncLeaderTransfer
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncReconfigFinish
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
SSyncCfg
oldCfg
;
SSyncCfg
newCfg
;
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
SSyncCfg
oldCfg
;
SSyncCfg
newCfg
;
SyncIndex
newCfgIndex
;
SyncTerm
newCfgTerm
;
uint64_t
newCfgSeqNum
;
SyncTerm
newCfgTerm
;
uint64_t
newCfgSeqNum
;
}
SyncReconfigFinish
;
...
...
@@ -521,8 +520,6 @@ void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg);
void
syncReconfigFinishLog
(
const
SyncReconfigFinish
*
pMsg
);
void
syncReconfigFinishLog2
(
char
*
s
,
const
SyncReconfigFinish
*
pMsg
);
// on message ----------------------
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
9786ba2f
...
...
@@ -436,6 +436,11 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries
}
SyncTerm
myPreLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
pMsg
->
prevLogIndex
+
1
);
if
(
myPreLogTerm
==
SYNC_TERM_INVALID
)
{
sError
(
"vgId:%d sync get pre term error, preindex:%ld"
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
if
(
pMsg
->
prevLogIndex
<=
myLastIndex
&&
pMsg
->
prevLogTerm
==
myPreLogTerm
)
{
if
(
gRaftDetailLog
)
{
sTrace
(
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
9786ba2f
...
...
@@ -345,7 +345,7 @@ bool syncCanLeaderTransfer(int64_t rid) {
return
matchOK
;
}
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
syncForwardToPeer
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
syncPropose
(
rid
,
pMsg
,
isWeak
);
return
ret
;
}
...
...
@@ -1888,6 +1888,16 @@ SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode) {
return
syncStartIndex
;
}
SyncIndex
syncNodeGetPreIndex
(
SSyncNode
*
pSyncNode
,
SyncIndex
index
)
{
SyncIndex
preIndex
=
index
-
1
;
if
(
preIndex
<
SYNC_INDEX_INVALID
)
{
preIndex
=
SYNC_INDEX_INVALID
;
}
return
preIndex
;
}
/*
SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) {
ASSERT(index >= SYNC_INDEX_BEGIN);
...
...
@@ -1900,7 +1910,42 @@ SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) {
SyncIndex preIndex = index - 1;
return preIndex;
}
*/
SyncTerm
syncNodeGetPreTerm
(
SSyncNode
*
pSyncNode
,
SyncIndex
index
)
{
if
(
index
<
SYNC_INDEX_BEGIN
)
{
return
SYNC_TERM_INVALID
;
}
if
(
index
==
SYNC_INDEX_BEGIN
)
{
return
0
;
}
SyncTerm
preTerm
=
0
;
SyncIndex
preIndex
=
index
-
1
;
SSyncRaftEntry
*
pPreEntry
=
NULL
;
int32_t
code
=
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSyncNode
->
pLogStore
,
preIndex
,
&
pPreEntry
);
if
(
code
==
0
)
{
ASSERT
(
pPreEntry
!=
NULL
);
preTerm
=
pPreEntry
->
term
;
taosMemoryFree
(
pPreEntry
);
return
preTerm
;
}
else
{
if
(
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
)
{
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
,
.
lastConfigIndex
=
-
1
};
if
(
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
(
pSyncNode
->
pFsm
,
&
snapshot
);
if
(
snapshot
.
lastApplyIndex
==
preIndex
)
{
return
snapshot
.
lastApplyTerm
;
}
}
}
}
return
SYNC_TERM_INVALID
;
}
#if 0
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
ASSERT(index >= SYNC_INDEX_BEGIN);
...
...
@@ -1938,6 +1983,7 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
ASSERT(0);
return -1;
}
#endif
#if 0
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
9786ba2f
...
...
@@ -139,6 +139,15 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
// pre index, pre term
SyncIndex
preLogIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
nextIndex
);
SyncTerm
preLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
nextIndex
);
if
(
preLogTerm
==
SYNC_TERM_INVALID
)
{
SyncIndex
newNextIndex
=
syncNodeGetLastIndex
(
pSyncNode
)
+
1
;
syncIndexMgrSetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
,
newNextIndex
);
syncIndexMgrSetIndex
(
pSyncNode
->
pMatchIndex
,
pDestId
,
SYNC_INDEX_INVALID
);
sError
(
"vgId:%d sync get pre term error, nextIndex:%ld, update next-index:%ld, match-index:%d, raftid:%ld"
,
pSyncNode
->
vgId
,
nextIndex
,
newNextIndex
,
SYNC_INDEX_INVALID
,
pDestId
->
addr
);
return
-
1
;
}
// batch optimized
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录