Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
363cbc89
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看板
提交
363cbc89
编写于
11月 18, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: update cbMeta rsp handle info in syncLogFsmExecute
上级
4526ff28
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
66 addition
and
67 deletion
+66
-67
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+1
-1
source/libs/sync/inc/syncCommit.h
source/libs/sync/inc/syncCommit.h
+5
-0
source/libs/sync/inc/syncLogBuffer.h
source/libs/sync/inc/syncLogBuffer.h
+21
-26
source/libs/sync/inc/syncReplication.h
source/libs/sync/inc/syncReplication.h
+3
-0
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+2
-0
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+0
-18
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+18
-0
source/libs/sync/src/syncLogBuffer.c
source/libs/sync/src/syncLogBuffer.c
+14
-18
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+0
-1
source/libs/transport/src/tmsgcb.c
source/libs/transport/src/tmsgcb.c
+2
-3
未找到文件。
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
363cbc89
...
...
@@ -415,7 +415,7 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm) {
walApplyVer
(
pVnode
->
pWal
,
pVnode
->
state
.
applied
);
pVnode
->
restored
=
true
;
v
Debug
(
"vgId:%d, sync restore finished"
,
pVnode
->
config
.
vgId
);
v
Info
(
"vgId:%d, sync restore finished"
,
pVnode
->
config
.
vgId
);
}
static
void
vnodeBecomeFollower
(
const
SSyncFSM
*
pFsm
)
{
...
...
source/libs/sync/inc/syncCommit.h
浏览文件 @
363cbc89
...
...
@@ -47,8 +47,13 @@ extern "C" {
//
void
syncOneReplicaAdvance
(
SSyncNode
*
pSyncNode
);
void
syncMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
);
bool
syncAgreeIndex
(
SSyncNode
*
pSyncNode
,
SRaftId
*
pRaftId
,
SyncIndex
index
);
bool
syncAgree
(
SSyncNode
*
pSyncNode
,
SyncIndex
index
);
bool
syncNodeAgreedUpon
(
SSyncNode
*
pNode
,
SyncIndex
index
);
int64_t
syncNodeUpdateCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
commitIndex
);
int64_t
syncNodeCheckCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
indexLikely
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncLogBuffer.h
浏览文件 @
363cbc89
...
...
@@ -41,8 +41,28 @@ typedef struct SSyncLogReplMgr {
int32_t
peerId
;
}
SSyncLogReplMgr
;
typedef
struct
SSyncLogBufEntry
{
SSyncRaftEntry
*
pItem
;
SyncIndex
prevLogIndex
;
SyncTerm
prevLogTerm
;
}
SSyncLogBufEntry
;
typedef
struct
SSyncLogBuffer
{
SSyncLogBufEntry
entries
[
TSDB_SYNC_LOG_BUFFER_SIZE
];
int64_t
startIndex
;
int64_t
commitIndex
;
int64_t
matchIndex
;
int64_t
endIndex
;
int64_t
size
;
TdThreadMutex
mutex
;
}
SSyncLogBuffer
;
// SSyncLogRepMgr
SSyncLogReplMgr
*
syncLogReplMgrCreate
();
void
syncLogReplMgrDestroy
(
SSyncLogReplMgr
*
pMgr
);
int32_t
syncLogReplMgrReset
(
SSyncLogReplMgr
*
pMgr
);
int32_t
syncNodeLogReplMgrInit
(
SSyncNode
*
pNode
);
void
syncNodeLogReplMgrDestroy
(
SSyncNode
*
pNode
);
...
...
@@ -69,35 +89,12 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Syn
int32_t
syncLogBufferReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgrReplicateAttemptedOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgrReplicateProbeOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogResetLogReplMgr
(
SSyncLogReplMgr
*
pMgr
);
int32_t
syncLogReplMgrProcessReplyInRecoveryMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessReplyInNormalMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrRetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgrProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncNodeSendAppendEntries
(
SSyncNode
*
pNode
,
const
SRaftId
*
destRaftId
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncNodeMaybeSendAppendEntries
(
SSyncNode
*
pNode
,
const
SRaftId
*
destRaftId
,
SRpcMsg
*
pRpcMsg
);
void
syncLogDestroyAppendEntries
(
SRpcMsg
*
pRpcMsg
);
// others
bool
syncLogReplMgrValidate
(
SSyncLogReplMgr
*
pMgr
);
typedef
struct
SSyncLogBufEntry
{
SSyncRaftEntry
*
pItem
;
SyncIndex
prevLogIndex
;
SyncTerm
prevLogTerm
;
}
SSyncLogBufEntry
;
typedef
struct
SSyncLogBuffer
{
SSyncLogBufEntry
entries
[
TSDB_SYNC_LOG_BUFFER_SIZE
];
int64_t
startIndex
;
int64_t
commitIndex
;
int64_t
matchIndex
;
int64_t
endIndex
;
int64_t
size
;
TdThreadMutex
mutex
;
}
SSyncLogBuffer
;
// SSyncLogBuffer
SSyncLogBuffer
*
syncLogBufferCreate
();
void
syncLogBufferDestroy
(
SSyncLogBuffer
*
pBuf
);
int32_t
syncLogBufferInit
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
);
...
...
@@ -117,8 +114,6 @@ int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SyncIndex toIndex);
int32_t
syncLogBufferReplicate
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
);
// others
bool
syncNodeAgreedUpon
(
SSyncNode
*
pNode
,
SyncIndex
index
);
void
syncIndexMgrSetIndex
(
SSyncIndexMgr
*
pSyncIndexMgr
,
const
SRaftId
*
pRaftId
,
SyncIndex
index
);
int64_t
syncNodeUpdateCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
commtIndex
);
int32_t
syncLogToAppendEntries
(
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
,
SRpcMsg
*
pRpcMsg
);
...
...
source/libs/sync/inc/syncReplication.h
浏览文件 @
363cbc89
...
...
@@ -53,6 +53,9 @@ int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* pDestId, SRpc
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicateOne
(
SSyncNode
*
pSyncNode
,
SRaftId
*
pDestId
,
bool
snapshot
);
int32_t
syncNodeSendAppendEntries
(
SSyncNode
*
pNode
,
const
SRaftId
*
destRaftId
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncNodeMaybeSendAppendEntries
(
SSyncNode
*
pNode
,
const
SRaftId
*
destRaftId
,
SRpcMsg
*
pRpcMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
363cbc89
...
...
@@ -87,6 +87,8 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceive
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnSnapshotReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
SyncIndex
syncNodeGetSnapshotConfigIndex
(
SSyncNode
*
pSyncNode
,
SyncIndex
snapshotLastApplyIndex
);
// start
#ifdef __cplusplus
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
363cbc89
...
...
@@ -39,24 +39,6 @@
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
//
int64_t
syncNodeUpdateCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
commitIndex
)
{
SyncIndex
lastVer
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
commitIndex
=
TMAX
(
commitIndex
,
ths
->
commitIndex
);
ths
->
commitIndex
=
TMIN
(
commitIndex
,
lastVer
);
ths
->
pLogStore
->
syncLogUpdateCommitIndex
(
ths
->
pLogStore
,
ths
->
commitIndex
);
return
ths
->
commitIndex
;
}
int64_t
syncNodeCheckCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
indexLikely
)
{
if
(
indexLikely
>
ths
->
commitIndex
&&
syncNodeAgreedUpon
(
ths
,
indexLikely
))
{
SyncIndex
commitIndex
=
indexLikely
;
syncNodeUpdateCommitIndex
(
ths
,
commitIndex
);
sInfo
(
"vgId:%d, agreed upon. role:%d, term:%"
PRId64
", index: %"
PRId64
""
,
ths
->
vgId
,
ths
->
state
,
ths
->
pRaftStore
->
currentTerm
,
commitIndex
);
}
return
ths
->
commitIndex
;
}
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntriesReply
*
pMsg
=
pRpcMsg
->
pCont
;
int32_t
ret
=
0
;
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
363cbc89
...
...
@@ -311,3 +311,21 @@ bool syncAgree(SSyncNode* pNode, SyncIndex index) {
}
return
false
;
}
int64_t
syncNodeUpdateCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
commitIndex
)
{
SyncIndex
lastVer
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
commitIndex
=
TMAX
(
commitIndex
,
ths
->
commitIndex
);
ths
->
commitIndex
=
TMIN
(
commitIndex
,
lastVer
);
ths
->
pLogStore
->
syncLogUpdateCommitIndex
(
ths
->
pLogStore
,
ths
->
commitIndex
);
return
ths
->
commitIndex
;
}
int64_t
syncNodeCheckCommitIndex
(
SSyncNode
*
ths
,
SyncIndex
indexLikely
)
{
if
(
indexLikely
>
ths
->
commitIndex
&&
syncNodeAgreedUpon
(
ths
,
indexLikely
))
{
SyncIndex
commitIndex
=
indexLikely
;
syncNodeUpdateCommitIndex
(
ths
,
commitIndex
);
sInfo
(
"vgId:%d, agreed upon. role:%d, term:%"
PRId64
", index: %"
PRId64
""
,
ths
->
vgId
,
ths
->
state
,
ths
->
pRaftStore
->
currentTerm
,
commitIndex
);
}
return
ths
->
commitIndex
;
}
source/libs/sync/src/syncLogBuffer.c
浏览文件 @
363cbc89
...
...
@@ -16,10 +16,13 @@
#define _DEFAULT_SOURCE
#include "syncLogBuffer.h"
#include "syncIndexMgr.h"
#include "syncInt.h"
#include "syncRaftEntry.h"
#include "syncRaftStore.h"
#include "syncReplication.h"
#include "syncRespMgr.h"
#include "syncSnapshot.h"
#include "syncUtil.h"
int64_t
syncLogBufferGetEndIndex
(
SSyncLogBuffer
*
pBuf
)
{
...
...
@@ -384,7 +387,7 @@ _out:
return
matchIndex
;
}
int32_t
syncLogFsmExecute
(
SSyncFSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
)
{
int32_t
syncLogFsmExecute
(
SSync
Node
*
pNode
,
SSync
FSM
*
pFsm
,
ESyncState
role
,
SyncTerm
term
,
SSyncRaftEntry
*
pEntry
)
{
ASSERT
(
pFsm
->
FpCommitCb
!=
NULL
&&
"No commit cb registered for the FSM"
);
SRpcMsg
rpcMsg
;
...
...
@@ -392,7 +395,7 @@ int32_t syncLogFsmExecute(SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncR
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
lastConfigIndex
=
-
1
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
pNode
,
pEntry
->
index
)
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
role
;
...
...
@@ -401,6 +404,7 @@ int32_t syncLogFsmExecute(SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncR
cbMeta
.
currentTerm
=
term
;
cbMeta
.
flag
=
-
1
;
(
void
)
syncRespMgrGetAndDel
(
pNode
->
pSyncRespMgr
,
cbMeta
.
seqNum
,
&
rpcMsg
.
info
);
pFsm
->
FpCommitCb
(
pFsm
,
&
rpcMsg
,
&
cbMeta
);
return
0
;
}
...
...
@@ -423,7 +427,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
ESyncState
role
=
pNode
->
state
;
SyncTerm
term
=
pNode
->
pRaftStore
->
currentTerm
;
SyncGroupId
vgId
=
pNode
->
vgId
;
int32_t
ret
=
0
;
int32_t
ret
=
-
1
;
int64_t
upperIndex
=
TMIN
(
commitIndex
,
pBuf
->
matchIndex
);
SSyncRaftEntry
*
pEntry
=
NULL
;
bool
inBuf
=
false
;
...
...
@@ -459,10 +463,9 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
continue
;
}
if
(
syncLogFsmExecute
(
pFsm
,
role
,
term
,
pEntry
)
!=
0
)
{
if
(
syncLogFsmExecute
(
p
Node
,
p
Fsm
,
role
,
term
,
pEntry
)
!=
0
)
{
sError
(
"vgId:%d, failed to execute raft entry in FSM. log index:%"
PRId64
", term:%"
PRId64
""
,
vgId
,
pEntry
->
index
,
pEntry
->
term
);
ret
=
-
1
;
goto
_out
;
}
pBuf
->
commitIndex
=
index
;
...
...
@@ -487,6 +490,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
pBuf
->
startIndex
=
index
+
1
;
}
ret
=
0
;
_out:
// mark as restored if needed
if
(
!
pNode
->
restoreFinish
&&
pBuf
->
commitIndex
>=
pNode
->
commitIndex
)
{
...
...
@@ -505,7 +509,7 @@ _out:
return
ret
;
}
int32_t
syncLogRe
setLogReplMgr
(
SSyncLogReplMgr
*
pMgr
)
{
int32_t
syncLogRe
plMgrReset
(
SSyncLogReplMgr
*
pMgr
)
{
ASSERT
(
pMgr
->
startIndex
>=
0
);
for
(
SyncIndex
index
=
pMgr
->
startIndex
;
index
<
pMgr
->
endIndex
;
index
++
)
{
memset
(
&
pMgr
->
states
[
index
%
pMgr
->
size
],
0
,
sizeof
(
pMgr
->
states
[
0
]));
...
...
@@ -601,7 +605,7 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
return
0
;
}
(
void
)
syncLogRe
setLogReplMgr
(
pMgr
);
(
void
)
syncLogRe
plMgrReset
(
pMgr
);
}
// send match index
...
...
@@ -633,7 +637,7 @@ int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pN
if
(
pMsg
->
startTime
!=
0
&&
pMsg
->
startTime
!=
pMgr
->
peerStartTime
)
{
sInfo
(
"vgId:%d, reset sync log repl mgr in heartbeat. start time:%"
PRId64
", old start time:%"
PRId64
""
,
pNode
->
vgId
,
pMsg
->
startTime
,
pMgr
->
peerStartTime
);
syncLogRe
setLogReplMgr
(
pMgr
);
syncLogRe
plMgrReset
(
pMgr
);
pMgr
->
peerStartTime
=
pMsg
->
startTime
;
}
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
...
...
@@ -647,7 +651,7 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sync
sInfo
(
"vgId:%d, reset sync log repl mgr in append entries reply. start time:%"
PRId64
", old start time:%"
PRId64
""
,
pNode
->
vgId
,
pMsg
->
startTime
,
pMgr
->
peerStartTime
);
syncLogRe
setLogReplMgr
(
pMgr
);
syncLogRe
plMgrReset
(
pMgr
);
pMgr
->
peerStartTime
=
pMsg
->
startTime
;
}
...
...
@@ -861,7 +865,7 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
// reset repl mgr
for
(
int
i
=
0
;
i
<
pNode
->
replicaNum
;
i
++
)
{
SSyncLogReplMgr
*
pMgr
=
pNode
->
logReplMgrs
[
i
];
syncLogRe
setLogReplMgr
(
pMgr
);
syncLogRe
plMgrReset
(
pMgr
);
}
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
0
;
...
...
@@ -884,14 +888,6 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
return
pEntry
;
}
bool
syncLogReplMgrValidate
(
SSyncLogReplMgr
*
pMgr
)
{
ASSERT
(
pMgr
->
startIndex
<=
pMgr
->
endIndex
);
for
(
SyncIndex
index
=
pMgr
->
startIndex
;
index
<
pMgr
->
endIndex
;
index
++
)
{
ASSERT
(
pMgr
->
states
[(
index
+
pMgr
->
size
)
%
pMgr
->
size
].
barrier
==
false
||
index
+
1
==
pMgr
->
endIndex
);
}
return
true
;
}
int32_t
syncLogBufferReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
)
{
SSyncRaftEntry
*
pEntry
=
NULL
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
363cbc89
...
...
@@ -58,7 +58,6 @@ static int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeade
static
int32_t
syncDoLeaderTransfer
(
SSyncNode
*
ths
,
SRpcMsg
*
pRpcMsg
,
SSyncRaftEntry
*
pEntry
);
static
ESyncStrategy
syncNodeStrategy
(
SSyncNode
*
pSyncNode
);
static
SyncIndex
syncNodeGetSnapshotConfigIndex
(
SSyncNode
*
pSyncNode
,
SyncIndex
snapshotLastApplyIndex
);
int64_t
syncOpen
(
SSyncInfo
*
pSyncInfo
)
{
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
...
...
source/libs/transport/src/tmsgcb.c
浏览文件 @
363cbc89
...
...
@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#include "tmsgcb.h"
#include "taoserror.h"
#include "transLog.h"
#include "trpc.h"
static
SMsgCb
defaultMsgCb
;
...
...
@@ -23,9 +24,7 @@ static SMsgCb defaultMsgCb;
void
tmsgSetDefault
(
const
SMsgCb
*
msgcb
)
{
defaultMsgCb
=
*
msgcb
;
}
int32_t
tmsgPutToQueue
(
const
SMsgCb
*
msgcb
,
EQueueType
qtype
,
SRpcMsg
*
pMsg
)
{
if
(
msgcb
==
NULL
)
{
return
-
1
;
}
ASSERT
(
msgcb
!=
NULL
);
int32_t
code
=
(
*
msgcb
->
putToQueueFp
)(
msgcb
->
mgmt
,
qtype
,
pMsg
);
if
(
code
!=
0
)
{
rpcFreeCont
(
pMsg
->
pCont
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录