Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
db1cb4a8
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看板
未验证
提交
db1cb4a8
编写于
4月 07, 2023
作者:
X
Xiaoyu Wang
提交者:
GitHub
4月 07, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20793 from taosdata/FIX/TD-23509-main
enh: refactor some func names of syncLogReplMgr
上级
8a21888f
0a147676
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
75 addition
and
75 deletion
+75
-75
source/libs/sync/inc/syncPipeline.h
source/libs/sync/inc/syncPipeline.h
+20
-20
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+4
-4
source/libs/sync/src/syncPipeline.c
source/libs/sync/src/syncPipeline.c
+46
-46
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+2
-2
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-2
未找到文件。
source/libs/sync/inc/syncPipeline.h
浏览文件 @
db1cb4a8
...
...
@@ -59,36 +59,36 @@ typedef struct SSyncLogBuffer {
}
SSyncLogBuffer
;
// SSyncLogRepMgr
SSyncLogReplMgr
*
syncLogRepl
Mgr
Create
();
void
syncLogRepl
Mgr
Destroy
(
SSyncLogReplMgr
*
pMgr
);
void
syncLogRepl
Mgr
Reset
(
SSyncLogReplMgr
*
pMgr
);
SSyncLogReplMgr
*
syncLogReplCreate
();
void
syncLogReplDestroy
(
SSyncLogReplMgr
*
pMgr
);
void
syncLogReplReset
(
SSyncLogReplMgr
*
pMgr
);
int32_t
syncNodeLogReplMgr
Init
(
SSyncNode
*
pNode
);
void
syncNodeLogReplMgr
Destroy
(
SSyncNode
*
pNode
);
int32_t
syncNodeLogRepl
Init
(
SSyncNode
*
pNode
);
void
syncNodeLogRepl
Destroy
(
SSyncNode
*
pNode
);
// access
static
FORCE_INLINE
int64_t
syncLogGetRetryBackoffTimeMs
(
SSyncLogReplMgr
*
pMgr
)
{
static
FORCE_INLINE
int64_t
syncLog
Repl
GetRetryBackoffTimeMs
(
SSyncLogReplMgr
*
pMgr
)
{
return
((
int64_t
)
1
<<
pMgr
->
retryBackoff
)
*
SYNC_LOG_REPL_RETRY_WAIT_MS
;
}
static
FORCE_INLINE
int32_t
syncLogGetNextRetryBackoff
(
SSyncLogReplMgr
*
pMgr
)
{
static
FORCE_INLINE
int32_t
syncLog
Repl
GetNextRetryBackoff
(
SSyncLogReplMgr
*
pMgr
)
{
return
TMIN
(
pMgr
->
retryBackoff
+
1
,
SYNC_MAX_RETRY_BACKOFF
);
}
SyncTerm
syncLogRepl
Mgr
GetPrevLogTerm
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
SyncTerm
syncLogReplGetPrevLogTerm
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLogReplMgr
ReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgr
ReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
);
int32_t
syncLogReplMgr
ReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgr
ReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLogRepl
ReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogRepl
ReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
);
int32_t
syncLogRepl
ReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogRepl
ReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLogReplMgr
ProcessReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgr
ProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgr
ProcessReplyAsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogRepl
ProcessReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogRepl
ProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogRepl
ProcessReplyAsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogRepl
Mgr
ProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncLogReplMgr
RetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncLogRepl
RetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
// SSyncLogBuffer
SSyncLogBuffer
*
syncLogBufferCreate
();
...
...
@@ -111,8 +111,8 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
int32_t
syncLogBufferValidate
(
SSyncLogBuffer
*
pBuf
);
int32_t
syncLogBufferRollback
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SyncIndex
toIndex
);
int32_t
sync
Log
FsmExecute
(
SSyncNode
*
pNode
,
SSyncFSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
,
int32_t
applyCode
);
int32_t
syncFsmExecute
(
SSyncNode
*
pNode
,
SSyncFSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
,
int32_t
applyCode
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
db1cb4a8
...
...
@@ -85,7 +85,7 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
sError
(
"vgId:%d, failed to get log repl mgr for src addr: 0x%016"
PRIx64
,
ths
->
vgId
,
pMsg
->
srcId
.
addr
);
return
-
1
;
}
(
void
)
syncLogRepl
Mgr
ProcessReply
(
pMgr
,
ths
,
pMsg
);
(
void
)
syncLogReplProcessReply
(
pMgr
,
ths
,
pMsg
);
}
return
0
;
}
source/libs/sync/src/syncMain.c
浏览文件 @
db1cb4a8
...
...
@@ -949,7 +949,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
pSyncNode
->
changing
=
false
;
// replication mgr
if
(
syncNodeLogRepl
Mgr
Init
(
pSyncNode
)
<
0
)
{
if
(
syncNodeLogReplInit
(
pSyncNode
)
<
0
)
{
sError
(
"vgId:%d, failed to init repl mgr since %s."
,
pSyncNode
->
vgId
,
terrstr
());
goto
_error
;
}
...
...
@@ -1122,7 +1122,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
syncNodeStopPingTimer
(
pSyncNode
);
syncNodeStopElectTimer
(
pSyncNode
);
syncNodeStopHeartbeatTimer
(
pSyncNode
);
syncNodeLogRepl
Mgr
Destroy
(
pSyncNode
);
syncNodeLogReplDestroy
(
pSyncNode
);
syncRespMgrDestroy
(
pSyncNode
->
pSyncRespMgr
);
pSyncNode
->
pSyncRespMgr
=
NULL
;
...
...
@@ -2164,7 +2164,7 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
if
(
syncLogBufferAppend
(
ths
->
pLogBuf
,
ths
,
pEntry
)
<
0
)
{
sError
(
"vgId:%d, failed to enqueue sync log buffer, index:%"
PRId64
,
ths
->
vgId
,
pEntry
->
index
);
ASSERT
(
terrno
!=
0
);
(
void
)
sync
Log
FsmExecute
(
ths
,
ths
->
pFsm
,
ths
->
state
,
raftStoreGetTerm
(
ths
),
pEntry
,
terrno
);
(
void
)
syncFsmExecute
(
ths
,
ths
->
pFsm
,
ths
->
state
,
raftStoreGetTerm
(
ths
),
pEntry
,
terrno
);
syncEntryDestroy
(
pEntry
);
return
-
1
;
}
...
...
@@ -2374,7 +2374,7 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
syncIndexMgrSetRecvTime
(
ths
->
pMatchIndex
,
&
pMsg
->
srcId
,
tsMs
);
return
syncLogRepl
Mgr
ProcessHeartbeatReply
(
pMgr
,
ths
,
pMsg
);
return
syncLogReplProcessHeartbeatReply
(
pMgr
,
ths
,
pMsg
);
}
int32_t
syncNodeOnHeartbeatReplyOld
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
...
...
source/libs/sync/src/syncPipeline.c
浏览文件 @
db1cb4a8
...
...
@@ -86,7 +86,7 @@ _err:
return
-
1
;
}
SyncTerm
syncLogRepl
Mgr
GetPrevLogTerm
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
SyncTerm
syncLogReplGetPrevLogTerm
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
SSyncRaftEntry
*
pEntry
=
NULL
;
SyncIndex
prevIndex
=
index
-
1
;
...
...
@@ -316,7 +316,7 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
pEntry
->
index
,
pEntry
->
term
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
SyncTerm
term
=
syncLogRepl
Mgr
GetPrevLogTerm
(
NULL
,
pNode
,
index
+
1
);
SyncTerm
term
=
syncLogReplGetPrevLogTerm
(
NULL
,
pNode
,
index
+
1
);
ASSERT
(
pEntry
->
term
>=
0
);
if
(
term
==
pEntry
->
term
)
{
ret
=
0
;
...
...
@@ -351,7 +351,7 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
pEntry
->
index
,
pEntry
->
term
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
SyncTerm
existPrevTerm
=
syncLogRepl
Mgr
GetPrevLogTerm
(
NULL
,
pNode
,
index
);
SyncTerm
existPrevTerm
=
syncLogReplGetPrevLogTerm
(
NULL
,
pNode
,
index
);
ASSERT
(
pEntry
->
term
==
pExist
->
term
&&
(
pEntry
->
index
>
pBuf
->
matchIndex
||
prevTerm
==
existPrevTerm
));
ret
=
0
;
goto
_out
;
...
...
@@ -482,8 +482,8 @@ _out:
return
matchIndex
;
}
int32_t
sync
Log
FsmExecute
(
SSyncNode
*
pNode
,
SSyncFSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
,
int32_t
applyCode
)
{
int32_t
syncFsmExecute
(
SSyncNode
*
pNode
,
SSyncFSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
,
int32_t
applyCode
)
{
if
(
pNode
->
replicaNum
==
1
&&
pNode
->
restoreFinish
&&
pNode
->
vgId
!=
1
)
{
return
0
;
}
...
...
@@ -564,7 +564,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
pEntry
->
term
,
TMSG_INFO
(
pEntry
->
originalRpcType
));
}
if
(
sync
Log
FsmExecute
(
pNode
,
pFsm
,
role
,
currentTerm
,
pEntry
,
0
)
!=
0
)
{
if
(
syncFsmExecute
(
pNode
,
pFsm
,
role
,
currentTerm
,
pEntry
,
0
)
!=
0
)
{
sError
(
"vgId:%d, failed to execute sync log entry. index:%"
PRId64
", term:%"
PRId64
", role:%d, current term:%"
PRId64
,
vgId
,
pEntry
->
index
,
pEntry
->
term
,
role
,
currentTerm
);
...
...
@@ -611,7 +611,7 @@ _out:
return
ret
;
}
void
syncLogRepl
Mgr
Reset
(
SSyncLogReplMgr
*
pMgr
)
{
void
syncLogReplReset
(
SSyncLogReplMgr
*
pMgr
)
{
if
(
pMgr
==
NULL
)
return
;
ASSERT
(
pMgr
->
startIndex
>=
0
);
...
...
@@ -625,14 +625,14 @@ void syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
pMgr
->
retryBackoff
=
0
;
}
int32_t
syncLogRepl
Mgr
RetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
int32_t
syncLogReplRetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
if
(
pMgr
->
endIndex
<=
pMgr
->
startIndex
)
{
return
0
;
}
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
if
(
pMgr
->
retryBackoff
==
SYNC_MAX_RETRY_BACKOFF
)
{
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
sWarn
(
"vgId:%d, reset sync log repl mgr since retry backoff exceeding limit. peer:%"
PRIx64
,
pNode
->
vgId
,
pDestId
->
addr
);
return
-
1
;
...
...
@@ -640,7 +640,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
int32_t
ret
=
-
1
;
bool
retried
=
false
;
int64_t
retryWaitMs
=
syncLogGetRetryBackoffTimeMs
(
pMgr
);
int64_t
retryWaitMs
=
syncLog
Repl
GetRetryBackoffTimeMs
(
pMgr
);
int64_t
nowMs
=
taosGetMonoTimestampMs
();
int
count
=
0
;
int64_t
firstIndex
=
-
1
;
...
...
@@ -657,7 +657,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
if
(
pMgr
->
states
[
pos
].
acked
)
{
if
(
pMgr
->
matchIndex
<
index
&&
pMgr
->
states
[
pos
].
timeMs
+
(
syncGetRetryMaxWaitMs
()
<<
3
)
<
nowMs
)
{
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
sWarn
(
"vgId:%d, reset sync log repl mgr since stagnation. index:%"
PRId64
", peer:%"
PRIx64
,
pNode
->
vgId
,
index
,
pDestId
->
addr
);
goto
_out
;
...
...
@@ -666,7 +666,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
}
bool
barrier
=
false
;
if
(
syncLogRepl
Mgr
ReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
if
(
syncLogReplReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate sync log entry since %s. index:%"
PRId64
", dest:%"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
goto
_out
;
...
...
@@ -687,7 +687,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
ret
=
0
;
_out:
if
(
retried
)
{
pMgr
->
retryBackoff
=
syncLogGetNextRetryBackoff
(
pMgr
);
pMgr
->
retryBackoff
=
syncLog
Repl
GetNextRetryBackoff
(
pMgr
);
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
sInfo
(
"vgId:%d, resend %d sync log entries. dest:%"
PRIx64
", indexes:%"
PRId64
" ..., terms: ... %"
PRId64
", retryWaitMs:%"
PRId64
", mgr: [%"
PRId64
" %"
PRId64
", %"
PRId64
"), buffer: [%"
PRId64
" %"
PRId64
...
...
@@ -698,7 +698,7 @@ _out:
return
ret
;
}
int32_t
syncLogRepl
Mgr
ProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncLogReplProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
SRaftId
destId
=
pMsg
->
srcId
;
ASSERT
(
pMgr
->
restored
==
false
);
...
...
@@ -716,7 +716,7 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
}
}
else
{
if
(
pMsg
->
lastSendIndex
<
pMgr
->
startIndex
||
pMsg
->
lastSendIndex
>=
pMgr
->
endIndex
)
{
syncLogRepl
Mgr
RetryOnNeed
(
pMgr
,
pNode
);
syncLogReplRetryOnNeed
(
pMgr
,
pNode
);
return
0
;
}
...
...
@@ -750,7 +750,7 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
SyncIndex
index
=
TMIN
(
pMsg
->
matchIndex
,
pNode
->
pLogBuf
->
matchIndex
);
if
(
pMsg
->
matchIndex
<
pNode
->
pLogBuf
->
matchIndex
)
{
term
=
syncLogRepl
Mgr
GetPrevLogTerm
(
pMgr
,
pNode
,
index
+
1
);
term
=
syncLogReplGetPrevLogTerm
(
pMgr
,
pNode
,
index
+
1
);
if
((
index
+
1
<
firstVer
)
||
(
term
<
0
)
||
(
term
!=
pMsg
->
lastMatchTerm
&&
(
index
+
1
==
firstVer
||
index
==
firstVer
)))
{
ASSERT
(
term
>=
0
||
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
);
...
...
@@ -773,53 +773,53 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
}
// attempt to replicate the raft log at index
(
void
)
syncLogRepl
Mgr
Reset
(
pMgr
);
return
syncLogRepl
Mgr
ReplicateProbe
(
pMgr
,
pNode
,
index
);
(
void
)
syncLogReplReset
(
pMgr
);
return
syncLogReplReplicateProbe
(
pMgr
,
pNode
,
index
);
}
int32_t
syncLogRepl
Mgr
ProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
)
{
int32_t
syncLogReplProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
)
{
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
taosThreadMutexLock
(
&
pBuf
->
mutex
);
if
(
pMsg
->
startTime
!=
0
&&
pMsg
->
startTime
!=
pMgr
->
peerStartTime
)
{
sInfo
(
"vgId:%d, reset sync log repl mgr in heartbeat. peer:%"
PRIx64
", start time:%"
PRId64
", old:%"
PRId64
""
,
pNode
->
vgId
,
pMsg
->
srcId
.
addr
,
pMsg
->
startTime
,
pMgr
->
peerStartTime
);
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
pMgr
->
peerStartTime
=
pMsg
->
startTime
;
}
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
0
;
}
int32_t
syncLogRepl
Mgr
ProcessReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncLogReplProcessReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
taosThreadMutexLock
(
&
pBuf
->
mutex
);
if
(
pMsg
->
startTime
!=
pMgr
->
peerStartTime
)
{
sInfo
(
"vgId:%d, reset sync log repl mgr in appendlog reply. peer:%"
PRIx64
", start time:%"
PRId64
", old:%"
PRId64
,
pNode
->
vgId
,
pMsg
->
srcId
.
addr
,
pMsg
->
startTime
,
pMgr
->
peerStartTime
);
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
pMgr
->
peerStartTime
=
pMsg
->
startTime
;
}
if
(
pMgr
->
restored
)
{
(
void
)
syncLogRepl
Mgr
ProcessReplyAsNormal
(
pMgr
,
pNode
,
pMsg
);
(
void
)
syncLogReplProcessReplyAsNormal
(
pMgr
,
pNode
,
pMsg
);
}
else
{
(
void
)
syncLogRepl
Mgr
ProcessReplyAsRecovery
(
pMgr
,
pNode
,
pMsg
);
(
void
)
syncLogReplProcessReplyAsRecovery
(
pMgr
,
pNode
,
pMsg
);
}
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
0
;
}
int32_t
syncLogRepl
Mgr
ReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
int32_t
syncLogReplReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
if
(
pMgr
->
restored
)
{
(
void
)
syncLogRepl
Mgr
ReplicateAttempt
(
pMgr
,
pNode
);
(
void
)
syncLogReplReplicateAttempt
(
pMgr
,
pNode
);
}
else
{
(
void
)
syncLogRepl
Mgr
ReplicateProbe
(
pMgr
,
pNode
,
pNode
->
pLogBuf
->
matchIndex
);
(
void
)
syncLogReplReplicateProbe
(
pMgr
,
pNode
,
pNode
->
pLogBuf
->
matchIndex
);
}
return
0
;
}
int32_t
syncLogRepl
Mgr
ReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
int32_t
syncLogReplReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
ASSERT
(
!
pMgr
->
restored
);
ASSERT
(
pMgr
->
startIndex
>=
0
);
int64_t
retryMaxWaitMs
=
syncGetRetryMaxWaitMs
();
...
...
@@ -829,12 +829,12 @@ int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
nowMs
<
pMgr
->
states
[
pMgr
->
startIndex
%
pMgr
->
size
].
timeMs
+
retryMaxWaitMs
)
{
return
0
;
}
(
void
)
syncLogRepl
Mgr
Reset
(
pMgr
);
(
void
)
syncLogReplReset
(
pMgr
);
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
bool
barrier
=
false
;
SyncTerm
term
=
-
1
;
if
(
syncLogRepl
Mgr
ReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
if
(
syncLogReplReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate log entry since %s. index:%"
PRId64
", dest: 0x%016"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
return
-
1
;
...
...
@@ -857,7 +857,7 @@ int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
return
0
;
}
int32_t
syncLogRepl
Mgr
ReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
int32_t
syncLogReplReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
ASSERT
(
pMgr
->
restored
);
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
...
...
@@ -879,7 +879,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
bool
barrier
=
false
;
SyncTerm
term
=
-
1
;
if
(
syncLogRepl
Mgr
ReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
if
(
syncLogReplReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate log entry since %s. index:%"
PRId64
", dest: 0x%016"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
return
-
1
;
...
...
@@ -902,7 +902,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
}
}
syncLogRepl
Mgr
RetryOnNeed
(
pMgr
,
pNode
);
syncLogReplRetryOnNeed
(
pMgr
,
pNode
);
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
sTrace
(
"vgId:%d, replicated %d msgs to peer:%"
PRIx64
". indexes:%"
PRId64
"..., terms: ...%"
PRId64
...
...
@@ -913,7 +913,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
return
0
;
}
int32_t
syncLogRepl
Mgr
ProcessReplyAsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncLogReplProcessReplyAsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
ASSERT
(
pMgr
->
restored
==
true
);
if
(
pMgr
->
startIndex
<=
pMsg
->
lastSendIndex
&&
pMsg
->
lastSendIndex
<
pMgr
->
endIndex
)
{
if
(
pMgr
->
startIndex
<
pMgr
->
matchIndex
&&
pMgr
->
retryBackoff
>
0
)
{
...
...
@@ -932,10 +932,10 @@ int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNo
pMgr
->
startIndex
=
pMgr
->
matchIndex
;
}
return
syncLogRepl
Mgr
ReplicateAttempt
(
pMgr
,
pNode
);
return
syncLogReplReplicateAttempt
(
pMgr
,
pNode
);
}
SSyncLogReplMgr
*
syncLogRepl
Mgr
Create
()
{
SSyncLogReplMgr
*
syncLogReplCreate
()
{
SSyncLogReplMgr
*
pMgr
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncLogReplMgr
));
if
(
pMgr
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -949,7 +949,7 @@ SSyncLogReplMgr* syncLogReplMgrCreate() {
return
pMgr
;
}
void
syncLogRepl
Mgr
Destroy
(
SSyncLogReplMgr
*
pMgr
)
{
void
syncLogReplDestroy
(
SSyncLogReplMgr
*
pMgr
)
{
if
(
pMgr
==
NULL
)
{
return
;
}
...
...
@@ -957,10 +957,10 @@ void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr) {
return
;
}
int32_t
syncNodeLogRepl
Mgr
Init
(
SSyncNode
*
pNode
)
{
int32_t
syncNodeLogReplInit
(
SSyncNode
*
pNode
)
{
for
(
int
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
i
++
)
{
ASSERT
(
pNode
->
logReplMgrs
[
i
]
==
NULL
);
pNode
->
logReplMgrs
[
i
]
=
syncLogRepl
Mgr
Create
();
pNode
->
logReplMgrs
[
i
]
=
syncLogReplCreate
();
if
(
pNode
->
logReplMgrs
[
i
]
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -970,9 +970,9 @@ int32_t syncNodeLogReplMgrInit(SSyncNode* pNode) {
return
0
;
}
void
syncNodeLogRepl
Mgr
Destroy
(
SSyncNode
*
pNode
)
{
void
syncNodeLogReplDestroy
(
SSyncNode
*
pNode
)
{
for
(
int
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
i
++
)
{
syncLogRepl
Mgr
Destroy
(
pNode
->
logReplMgrs
[
i
]);
syncLogReplDestroy
(
pNode
->
logReplMgrs
[
i
]);
pNode
->
logReplMgrs
[
i
]
=
NULL
;
}
}
...
...
@@ -1103,7 +1103,7 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
// reset repl mgr
for
(
int
i
=
0
;
i
<
pNode
->
replicaNum
;
i
++
)
{
SSyncLogReplMgr
*
pMgr
=
pNode
->
logReplMgrs
[
i
];
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
}
syncLogBufferValidate
(
pBuf
);
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
...
...
@@ -1127,8 +1127,8 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
return
pEntry
;
}
int32_t
syncLogRepl
Mgr
ReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
)
{
int32_t
syncLogReplReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
)
{
SSyncRaftEntry
*
pEntry
=
NULL
;
SRpcMsg
msgOut
=
{
0
};
bool
inBuf
=
false
;
...
...
@@ -1143,14 +1143,14 @@ int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
if
(
pMgr
)
{
sInfo
(
"vgId:%d, reset sync log repl mgr of peer:%"
PRIx64
" since %s. index:%"
PRId64
,
pNode
->
vgId
,
pDestId
->
addr
,
terrstr
(),
index
);
(
void
)
syncLogRepl
Mgr
Reset
(
pMgr
);
(
void
)
syncLogReplReset
(
pMgr
);
}
}
goto
_err
;
}
*
pBarrier
=
syncLogIsReplicationBarrier
(
pEntry
);
prevLogTerm
=
syncLogRepl
Mgr
GetPrevLogTerm
(
pMgr
,
pNode
,
index
);
prevLogTerm
=
syncLogReplGetPrevLogTerm
(
pMgr
,
pNode
,
index
);
if
(
prevLogTerm
<
0
)
{
sError
(
"vgId:%d, failed to get prev log term since %s. index:%"
PRId64
""
,
pNode
->
vgId
,
terrstr
(),
index
);
goto
_err
;
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
db1cb4a8
...
...
@@ -52,7 +52,7 @@ int32_t syncNodeReplicateReset(SSyncNode* pNode, SRaftId* pDestId) {
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
taosThreadMutexLock
(
&
pBuf
->
mutex
);
SSyncLogReplMgr
*
pMgr
=
syncNodeGetLogReplMgr
(
pNode
,
pDestId
);
syncLogRepl
Mgr
Reset
(
pMgr
);
syncLogReplReset
(
pMgr
);
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
0
;
}
...
...
@@ -74,7 +74,7 @@ int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
continue
;
}
SSyncLogReplMgr
*
pMgr
=
pNode
->
logReplMgrs
[
i
];
(
void
)
syncLogRepl
Mgr
ReplicateOnce
(
pMgr
,
pNode
);
(
void
)
syncLogReplReplicateOnce
(
pMgr
,
pNode
);
}
return
0
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
db1cb4a8
...
...
@@ -125,7 +125,7 @@ static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t buf
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
}
static
void
syncLogRepl
Mgr
States2Str
(
SSyncNode
*
pSyncNode
,
char
*
buf
,
int32_t
bufLen
)
{
static
void
syncLogReplStates2Str
(
SSyncNode
*
pSyncNode
,
char
*
buf
,
int32_t
bufLen
)
{
int
len
=
0
;
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%s"
,
"{"
);
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
i
++
)
{
...
...
@@ -178,7 +178,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
syncCfg2SimpleStr
(
&
pNode
->
raftCfg
.
cfg
,
cfgStr
,
sizeof
(
cfgStr
));
char
replMgrStatesStr
[
1024
]
=
""
;
syncLogRepl
Mgr
States2Str
(
pNode
,
replMgrStatesStr
,
sizeof
(
replMgrStatesStr
));
syncLogReplStates2Str
(
pNode
,
replMgrStatesStr
,
sizeof
(
replMgrStatesStr
));
char
bufferStatesStr
[
256
]
=
""
;
syncLogBufferStates2Str
(
pNode
,
bufferStatesStr
,
sizeof
(
bufferStatesStr
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录