Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fdad1087
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看板
提交
fdad1087
编写于
11月 09, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into fix/TD-20052
上级
f2fd8474
35bacc2f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
101 addition
and
58 deletion
+101
-58
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+19
-3
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+19
-2
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+2
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+39
-39
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+12
-4
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
+9
-9
未找到文件。
include/libs/sync/sync.h
浏览文件 @
fdad1087
...
...
@@ -139,6 +139,7 @@ typedef struct SSyncFSM {
void
(
*
FpReConfigCb
)(
const
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
const
SReConfigCbMeta
*
pMeta
);
void
(
*
FpLeaderTransferCb
)(
const
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
const
SFsmCbMeta
*
pMeta
);
bool
(
*
FpApplyQueueEmptyCb
)(
const
struct
SSyncFSM
*
pFsm
);
int32_t
(
*
FpApplyQueueItems
)(
const
struct
SSyncFSM
*
pFsm
);
void
(
*
FpBecomeLeaderCb
)(
const
struct
SSyncFSM
*
pFsm
);
void
(
*
FpBecomeFollowerCb
)(
const
struct
SSyncFSM
*
pFsm
);
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
fdad1087
...
...
@@ -205,8 +205,23 @@ static void mndBecomeLeader(const SSyncFSM *pFsm) {
static
bool
mndApplyQueueEmpty
(
const
SSyncFSM
*
pFsm
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pMnode
->
msgCb
,
1
,
APPLY_QUEUE
);
return
(
itemSize
==
0
);
if
(
pMnode
!=
NULL
&&
pMnode
->
msgCb
.
qsizeFp
!=
NULL
)
{
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pMnode
->
msgCb
,
1
,
APPLY_QUEUE
);
return
(
itemSize
==
0
);
}
else
{
return
true
;
}
}
static
int32_t
mndApplyQueueItems
(
const
SSyncFSM
*
pFsm
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
if
(
pMnode
!=
NULL
&&
pMnode
->
msgCb
.
qsizeFp
!=
NULL
)
{
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pMnode
->
msgCb
,
1
,
APPLY_QUEUE
);
return
itemSize
;
}
else
{
return
-
1
;
}
}
SSyncFSM
*
mndSyncMakeFsm
(
SMnode
*
pMnode
)
{
...
...
@@ -218,6 +233,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
pFsm
->
FpRestoreFinishCb
=
mndRestoreFinish
;
pFsm
->
FpLeaderTransferCb
=
NULL
;
pFsm
->
FpApplyQueueEmptyCb
=
mndApplyQueueEmpty
;
pFsm
->
FpApplyQueueItems
=
mndApplyQueueItems
;
pFsm
->
FpReConfigCb
=
NULL
;
pFsm
->
FpBecomeLeaderCb
=
mndBecomeLeader
;
pFsm
->
FpBecomeFollowerCb
=
mndBecomeFollower
;
...
...
@@ -291,7 +307,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
SRpcMsg
req
=
{.
msgType
=
TDMT_MND_APPLY_MSG
,
.
contLen
=
sdbGetRawTotalSize
(
pRaw
)};
if
(
req
.
contLen
<=
0
)
return
-
1
;
req
.
pCont
=
rpcMallocCont
(
req
.
contLen
);
if
(
req
.
pCont
==
NULL
)
return
-
1
;
memcpy
(
req
.
pCont
,
pRaw
,
req
.
contLen
);
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
fdad1087
...
...
@@ -438,8 +438,24 @@ static void vnodeBecomeLeader(const SSyncFSM *pFsm) {
static
bool
vnodeApplyQueueEmpty
(
const
SSyncFSM
*
pFsm
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pVnode
->
msgCb
,
pVnode
->
config
.
vgId
,
APPLY_QUEUE
);
return
(
itemSize
==
0
);
if
(
pVnode
!=
NULL
&&
pVnode
->
msgCb
.
qsizeFp
!=
NULL
)
{
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pVnode
->
msgCb
,
pVnode
->
config
.
vgId
,
APPLY_QUEUE
);
return
(
itemSize
==
0
);
}
else
{
return
true
;
}
}
static
int32_t
vnodeApplyQueueItems
(
const
SSyncFSM
*
pFsm
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
if
(
pVnode
!=
NULL
&&
pVnode
->
msgCb
.
qsizeFp
!=
NULL
)
{
int32_t
itemSize
=
tmsgGetQueueSize
(
&
pVnode
->
msgCb
,
pVnode
->
config
.
vgId
,
APPLY_QUEUE
);
return
itemSize
;
}
else
{
return
-
1
;
}
}
static
SSyncFSM
*
vnodeSyncMakeFsm
(
SVnode
*
pVnode
)
{
...
...
@@ -452,6 +468,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
pFsm
->
FpRestoreFinishCb
=
vnodeRestoreFinish
;
pFsm
->
FpLeaderTransferCb
=
NULL
;
pFsm
->
FpApplyQueueEmptyCb
=
vnodeApplyQueueEmpty
;
pFsm
->
FpApplyQueueItems
=
vnodeApplyQueueItems
;
pFsm
->
FpBecomeLeaderCb
=
vnodeBecomeLeader
;
pFsm
->
FpBecomeFollowerCb
=
vnodeBecomeFollower
;
pFsm
->
FpReConfigCb
=
NULL
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
fdad1087
...
...
@@ -246,7 +246,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
}
else
{
// error
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"ignore, get local entry error, append-index:%"
PRId64
,
appendIndex
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"ignore, get local entry error, append-index:%"
PRId64
" err:%d"
,
appendIndex
,
terrno
);
syncLogRecvAppendEntries
(
ths
,
pMsg
,
logBuf
);
syncEntryDestory
(
pLocalEntry
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
fdad1087
...
...
@@ -1388,7 +1388,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
((
pSyncNode
->
replicasId
)[
i
].
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"snapshot sender reset for: %"
PRI
u
64
", newIndex:%d, %s:%d, %p"
,
sNTrace
(
pSyncNode
,
"snapshot sender reset for: %"
PRI
d
64
", newIndex:%d, %s:%d, %p"
,
(
pSyncNode
->
replicasId
)[
i
].
addr
,
i
,
host
,
port
,
oldSenders
[
j
]);
(
pSyncNode
->
senders
)[
i
]
=
oldSenders
[
j
];
...
...
@@ -1457,7 +1457,7 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
if
(
term
>
pSyncNode
->
pRaftStore
->
currentTerm
)
{
raftStoreSetTerm
(
pSyncNode
->
pRaftStore
,
term
);
char
tmpBuf
[
64
];
snprintf
(
tmpBuf
,
sizeof
(
tmpBuf
),
"update term to %"
PRI
u
64
,
term
);
snprintf
(
tmpBuf
,
sizeof
(
tmpBuf
),
"update term to %"
PRI
d
64
,
term
);
syncNodeBecomeFollower
(
pSyncNode
,
tmpBuf
);
raftStoreClearVote
(
pSyncNode
->
pRaftStore
);
}
...
...
@@ -1471,20 +1471,20 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
void
syncNodeStepDown
(
SSyncNode
*
pSyncNode
,
SyncTerm
newTerm
)
{
if
(
pSyncNode
->
pRaftStore
->
currentTerm
>
newTerm
)
{
sNTrace
(
pSyncNode
,
"step down, ignore, new-term:%"
PRI
u64
", current-term:%"
PRIu
64
,
newTerm
,
sNTrace
(
pSyncNode
,
"step down, ignore, new-term:%"
PRI
d64
", current-term:%"
PRId
64
,
newTerm
,
pSyncNode
->
pRaftStore
->
currentTerm
);
return
;
}
do
{
sNTrace
(
pSyncNode
,
"step down, new-term:%"
PRI
u64
", current-term:%"
PRIu
64
,
newTerm
,
sNTrace
(
pSyncNode
,
"step down, new-term:%"
PRI
d64
", current-term:%"
PRId
64
,
newTerm
,
pSyncNode
->
pRaftStore
->
currentTerm
);
}
while
(
0
);
if
(
pSyncNode
->
pRaftStore
->
currentTerm
<
newTerm
)
{
raftStoreSetTerm
(
pSyncNode
->
pRaftStore
,
newTerm
);
char
tmpBuf
[
64
];
snprintf
(
tmpBuf
,
sizeof
(
tmpBuf
),
"step down, update term to %"
PRI
u
64
,
newTerm
);
snprintf
(
tmpBuf
,
sizeof
(
tmpBuf
),
"step down, update term to %"
PRI
d
64
,
newTerm
);
syncNodeBecomeFollower
(
pSyncNode
,
tmpBuf
);
raftStoreClearVote
(
pSyncNode
->
pRaftStore
);
...
...
@@ -1803,7 +1803,7 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
}
}
sNError
(
pSyncNode
,
"sync node get pre term error, index:%"
PRId64
", snap-index:%"
PRId64
", snap-term:%"
PRI
u
64
,
sNError
(
pSyncNode
,
"sync node get pre term error, index:%"
PRId64
", snap-index:%"
PRId64
", snap-term:%"
PRI
d
64
,
index
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
);
return
SYNC_TERM_INVALID
;
}
...
...
@@ -1844,7 +1844,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
}
}
else
{
sTrace
(
"==syncNodeEqPingTimer== pingTimerLogicClock:%"
PRI
u64
", pingTimerLogicClockUser:%"
PRIu
64
,
sTrace
(
"==syncNodeEqPingTimer== pingTimerLogicClock:%"
PRI
d64
", pingTimerLogicClockUser:%"
PRId
64
,
pSyncNode
->
pingTimerLogicClock
,
pSyncNode
->
pingTimerLogicClockUser
);
}
}
...
...
@@ -1866,7 +1866,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
taosMemoryFree
(
pElectTimer
);
return
;
}
sNTrace
(
pSyncNode
,
"eq elect timer lc:%"
PRI
u
64
,
pSyncMsg
->
logicClock
);
sNTrace
(
pSyncNode
,
"eq elect timer lc:%"
PRI
d
64
,
pSyncMsg
->
logicClock
);
}
else
{
sTrace
(
"syncNodeEqElectTimer syncEqMsg is NULL"
);
}
...
...
@@ -1919,7 +1919,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
sError
(
"sync env is stop, syncNodeEqHeartbeatTimer"
);
}
}
else
{
sTrace
(
"==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%"
PRI
u64
", heartbeatTimerLogicClockUser:%"
PRIu
64
sTrace
(
"==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%"
PRI
d64
", heartbeatTimerLogicClockUser:%"
PRId
64
""
,
pSyncNode
->
heartbeatTimerLogicClock
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
}
...
...
@@ -1981,7 +1981,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
}
}
else
{
sTrace
(
"==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%"
PRI
u64
", msgLogicClock:%"
PRIu
64
""
,
timerLogicClock
,
sTrace
(
"==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%"
PRI
d64
", msgLogicClock:%"
PRId
64
""
,
timerLogicClock
,
msgLogicClock
);
}
}
...
...
@@ -2111,7 +2111,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
sError
(
"vgId:%d, sync enqueue fc-commit msg error, code:%d"
,
ths
->
vgId
,
code
);
rpcFreeCont
(
rpcMsgLocalCmd
.
pCont
);
}
else
{
sTrace
(
"vgId:%d, sync enqueue fc-commit msg, fc-index:
%"
PRIu
64
,
ths
->
vgId
,
pSyncMsg
->
fcIndex
);
sTrace
(
"vgId:%d, sync enqueue fc-commit msg, fc-index:
%"
PRId
64
,
ths
->
vgId
,
pSyncMsg
->
fcIndex
);
}
}
}
...
...
@@ -2132,7 +2132,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
sError
(
"vgId:%d, sync enqueue step-down msg error, code:%d"
,
ths
->
vgId
,
code
);
rpcFreeCont
(
rpcMsgLocalCmd
.
pCont
);
}
else
{
sTrace
(
"vgId:%d, sync enqueue step-down msg, new-term: %"
PRI
u
64
,
ths
->
vgId
,
pSyncMsg
->
sdNewTerm
);
sTrace
(
"vgId:%d, sync enqueue step-down msg, new-term: %"
PRI
d
64
,
ths
->
vgId
,
pSyncMsg
->
sdNewTerm
);
}
}
...
...
@@ -2303,7 +2303,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
}
if
(
pEntry
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
sNTrace
(
ths
,
"little term:%"
PRI
u
64
", can not do leader transfer"
,
pEntry
->
term
);
sNTrace
(
ths
,
"little term:%"
PRI
d
64
", can not do leader transfer"
,
pEntry
->
term
);
return
0
;
}
...
...
@@ -2333,7 +2333,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
int32_t
ret
=
syncNodeRestartElectTimer
(
ths
,
electMS
);
ASSERT
(
ret
==
0
);
sNTrace
(
ths
,
"maybe leader transfer to %s:%d %"
PRI
u
64
,
pSyncLeaderTransfer
->
newNodeInfo
.
nodeFqdn
,
sNTrace
(
ths
,
"maybe leader transfer to %s:%d %"
PRI
d
64
,
pSyncLeaderTransfer
->
newNodeInfo
.
nodeFqdn
,
pSyncLeaderTransfer
->
newNodeInfo
.
nodePort
,
pSyncLeaderTransfer
->
newLeaderId
.
addr
);
}
...
...
@@ -2581,7 +2581,7 @@ const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
}
void
syncLogRecvTimer
(
SSyncNode
*
pSyncNode
,
const
SyncTimeout
*
pMsg
,
const
char
*
s
)
{
sNTrace
(
pSyncNode
,
"recv sync-timer {type:%s, lc:%"
PRI
u
64
", ms:%d, data:%p}, %s"
,
sNTrace
(
pSyncNode
,
"recv sync-timer {type:%s, lc:%"
PRI
d
64
", ms:%d, data:%p}, %s"
,
syncTimerTypeStr
(
pMsg
->
timeoutType
),
pMsg
->
logicClock
,
pMsg
->
timerMS
,
pMsg
->
data
,
s
);
}
...
...
@@ -2589,7 +2589,7 @@ void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-request-vote to %s:%d {term:%"
PRI
u64
", lindex:%"
PRId64
", lterm:%"
PRIu
64
"}, %s"
,
sNTrace
(
pSyncNode
,
"send sync-request-vote to %s:%d {term:%"
PRI
d64
", lindex:%"
PRId64
", lterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
lastLogIndex
,
pMsg
->
lastLogTerm
,
s
);
}
...
...
@@ -2598,7 +2598,7 @@ void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-request-vote from %s:%d, {term:%"
PRI
u64
", lindex:%"
PRId64
", lterm:%"
PRIu
64
"}, %s"
,
sNTrace
(
pSyncNode
,
"recv sync-request-vote from %s:%d, {term:%"
PRI
d64
", lindex:%"
PRId64
", lterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
lastLogIndex
,
pMsg
->
lastLogTerm
,
s
);
}
...
...
@@ -2606,7 +2606,7 @@ void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-request-vote-reply to %s:%d {term:%"
PRI
u
64
", grant:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
sNTrace
(
pSyncNode
,
"send sync-request-vote-reply to %s:%d {term:%"
PRI
d
64
", grant:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
voteGranted
,
s
);
}
...
...
@@ -2614,7 +2614,7 @@ void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-request-vote-reply from %s:%d {term:%"
PRI
u
64
", grant:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
sNTrace
(
pSyncNode
,
"recv sync-request-vote-reply from %s:%d {term:%"
PRI
d
64
", grant:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
voteGranted
,
s
);
}
...
...
@@ -2623,8 +2623,8 @@ void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-append-entries to %s:%d, {term:%"
PRI
u64
", pre-index:%"
PRId64
", pre-term:%"
PRIu
64
", pterm:%"
PRI
u
64
", cmt:%"
PRId64
", datalen:%d}, %s"
,
"send sync-append-entries to %s:%d, {term:%"
PRI
d64
", pre-index:%"
PRId64
", pre-term:%"
PRId
64
", pterm:%"
PRI
d
64
", cmt:%"
PRId64
", datalen:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
privateTerm
,
pMsg
->
commitIndex
,
pMsg
->
dataLen
,
s
);
}
...
...
@@ -2635,8 +2635,8 @@ void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-append-entries from %s:%d {term:%"
PRI
u64
", pre-index:%"
PRIu64
", pre-term:%"
PRIu
64
", cmt:%"
PRI
u64
", pterm:%"
PRIu
64
", datalen:%d}, %s"
,
"recv sync-append-entries from %s:%d {term:%"
PRI
d64
", pre-index:%"
PRId64
", pre-term:%"
PRId
64
", cmt:%"
PRI
d64
", pterm:%"
PRId
64
", datalen:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
commitIndex
,
pMsg
->
privateTerm
,
pMsg
->
dataLen
,
s
);
}
...
...
@@ -2647,8 +2647,8 @@ void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-append-entries-batch to %s:%d, {term:%"
PRI
u64
", pre-index:%"
PRId64
", pre-term:%"
PRIu
64
", pterm:%"
PRI
u
64
", cmt:%"
PRId64
", datalen:%d, count:%d}, %s"
,
"send sync-append-entries-batch to %s:%d, {term:%"
PRI
d64
", pre-index:%"
PRId64
", pre-term:%"
PRId
64
", pterm:%"
PRI
d
64
", cmt:%"
PRId64
", datalen:%d, count:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
privateTerm
,
pMsg
->
commitIndex
,
pMsg
->
dataLen
,
pMsg
->
dataCount
,
s
);
}
...
...
@@ -2659,8 +2659,8 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-append-entries-batch from %s:%d, {term:%"
PRI
u64
", pre-index:%"
PRId64
", pre-term:%"
PRIu
64
", pterm:%"
PRI
u
64
", cmt:%"
PRId64
", datalen:%d, count:%d}, %s"
,
"recv sync-append-entries-batch from %s:%d, {term:%"
PRI
d64
", pre-index:%"
PRId64
", pre-term:%"
PRId
64
", pterm:%"
PRI
d
64
", cmt:%"
PRId64
", datalen:%d, count:%d}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
privateTerm
,
pMsg
->
commitIndex
,
pMsg
->
dataLen
,
pMsg
->
dataCount
,
s
);
}
...
...
@@ -2671,7 +2671,7 @@ void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-append-entries-reply to %s:%d, {term:%"
PRI
u64
", pterm:%"
PRIu
64
", success:%d, match:%"
PRId64
"send sync-append-entries-reply to %s:%d, {term:%"
PRI
d64
", pterm:%"
PRId
64
", success:%d, match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
pMsg
->
success
,
pMsg
->
matchIndex
,
s
);
}
...
...
@@ -2682,7 +2682,7 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-append-entries-reply from %s:%d {term:%"
PRI
u64
", pterm:%"
PRIu
64
", success:%d, match:%"
PRId64
"recv sync-append-entries-reply from %s:%d {term:%"
PRI
d64
", pterm:%"
PRId
64
", success:%d, match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
pMsg
->
success
,
pMsg
->
matchIndex
,
s
);
}
...
...
@@ -2693,7 +2693,7 @@ void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-heartbeat to %s:%d {term:%"
PRI
u64
", cmt:%"
PRId64
", min-match:%"
PRId64
", pterm:%"
PRIu
64
"send sync-heartbeat to %s:%d {term:%"
PRI
d64
", cmt:%"
PRId64
", min-match:%"
PRId64
", pterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
privateTerm
,
s
);
}
...
...
@@ -2704,7 +2704,7 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-heartbeat from %s:%d {term:%"
PRI
u64
", cmt:%"
PRId64
", min-match:%"
PRId64
", pterm:%"
PRIu
64
"recv sync-heartbeat from %s:%d {term:%"
PRI
d64
", cmt:%"
PRId64
", min-match:%"
PRId64
", pterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
privateTerm
,
s
);
}
...
...
@@ -2714,7 +2714,7 @@ void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-heartbeat-reply from %s:%d {term:%"
PRI
u64
", pterm:%"
PRIu
64
"}, %s"
,
host
,
port
,
sNTrace
(
pSyncNode
,
"send sync-heartbeat-reply from %s:%d {term:%"
PRI
d64
", pterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
s
);
}
...
...
@@ -2722,34 +2722,34 @@ void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-heartbeat-reply from %s:%d {term:%"
PRI
u64
", pterm:%"
PRIu
64
"}, %s"
,
host
,
port
,
sNTrace
(
pSyncNode
,
"recv sync-heartbeat-reply from %s:%d {term:%"
PRI
d64
", pterm:%"
PRId
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
s
);
}
void
syncLogRecvLocalCmd
(
SSyncNode
*
pSyncNode
,
const
SyncLocalCmd
*
pMsg
,
const
char
*
s
)
{
sNTrace
(
pSyncNode
,
"recv sync-local-cmd {cmd:%d-%s, sd-new-term:%"
PRI
u
64
"}, %s"
,
pMsg
->
cmd
,
syncLocalCmdGetStr
(
pMsg
->
cmd
),
pMsg
->
sdNewTerm
,
s
);
sNTrace
(
pSyncNode
,
"recv sync-local-cmd {cmd:%d-%s, sd-new-term:%"
PRI
d64
", fc-index:%"
PRId
64
"}, %s"
,
pMsg
->
cmd
,
syncLocalCmdGetStr
(
pMsg
->
cmd
),
pMsg
->
sdNewTerm
,
pMsg
->
fcIndex
,
s
);
}
void
syncLogSendSyncPreSnapshot
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshot
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-pre-snapshot to %s:%d {term:%"
PRI
u
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
s
);
sNTrace
(
pSyncNode
,
"send sync-pre-snapshot to %s:%d {term:%"
PRI
d
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
s
);
}
void
syncLogRecvSyncPreSnapshot
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshot
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-pre-snapshot from %s:%d {term:%"
PRI
u
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
s
);
sNTrace
(
pSyncNode
,
"recv sync-pre-snapshot from %s:%d {term:%"
PRI
d
64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
s
);
}
void
syncLogSendSyncPreSnapshotReply
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshotReply
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-pre-snapshot-reply to %s:%d {term:%"
PRI
u
64
", snap-start:%"
PRId64
"}, %s"
,
host
,
port
,
sNTrace
(
pSyncNode
,
"send sync-pre-snapshot-reply to %s:%d {term:%"
PRI
d
64
", snap-start:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
}
...
...
@@ -2757,7 +2757,7 @@ void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-pre-snapshot-reply from %s:%d {term:%"
PRI
u
64
", snap-start:%"
PRId64
"}, %s"
,
host
,
sNTrace
(
pSyncNode
,
"recv sync-pre-snapshot-reply from %s:%d {term:%"
PRI
d
64
", snap-start:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
fdad1087
...
...
@@ -205,7 +205,7 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
if
(
i
<
pSyncNode
->
replicaNum
-
1
)
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
" %"
PRId64
", "
,
i
,
pState
->
lastSendIndex
,
pState
->
lastSendTime
);
pState
->
lastSendTime
);
}
else
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
" %"
PRId64
"}"
,
i
,
pState
->
lastSendIndex
,
pState
->
lastSendTime
);
...
...
@@ -216,6 +216,9 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
void
syncPrintNodeLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncNode
*
pNode
,
const
char
*
format
,
...)
{
if
(
pNode
==
NULL
||
pNode
->
pRaftCfg
!=
NULL
&&
pNode
->
pRaftStore
==
NULL
||
pNode
->
pLogStore
==
NULL
)
return
;
// save error code, otherwise it will be overwritten
int32_t
errCode
=
terrno
;
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
};
if
(
pNode
->
pFsm
!=
NULL
&&
pNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
pNode
->
pFsm
->
FpGetSnapshotInfo
(
pNode
->
pFsm
,
&
snapshot
);
...
...
@@ -242,16 +245,21 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
int32_t
writeLen
=
vsnprintf
(
eventLog
,
sizeof
(
eventLog
),
format
,
argpointer
);
va_end
(
argpointer
);
int32_t
aqItems
=
pNode
->
pFsm
->
FpApplyQueueItems
(
pNode
->
pFsm
);
// restore error code
terrno
=
errCode
;
taosPrintLog
(
flags
,
level
,
dflag
,
"vgId:%d, sync %s "
"%s"
", tm:%"
PRIu64
", cmt:%"
PRId64
", fst:%"
PRId64
", lst:%"
PRId64
", min:%"
PRId64
", snap:%"
PRId64
", snap-tm:%"
PRIu64
", sby:%d,
stgy
:%d, bch:%d, r-num:%d, lcfg:%"
PRId64
", snap-tm:%"
PRIu64
", sby:%d,
aq
:%d, bch:%d, r-num:%d, lcfg:%"
PRId64
", chging:%d, rsto:%d, dquorum:%d, elt:%"
PRId64
", hb:%"
PRId64
", %s, %s"
,
pNode
->
vgId
,
syncStr
(
pNode
->
state
),
eventLog
,
pNode
->
pRaftStore
->
currentTerm
,
pNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
pNode
->
minMatchIndex
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
pNode
->
pRaftCfg
->
isStandBy
,
pNode
->
pRaftCfg
->
snapshotStrategy
,
pNode
->
pRaftCfg
->
batchSize
,
pNode
->
replicaNum
,
pNode
->
pRaftCfg
->
lastConfigIndex
,
pNode
->
changing
,
pNode
->
restoreFinish
,
quorum
,
pNode
->
pRaftCfg
->
isStandBy
,
aqItems
,
pNode
->
pRaftCfg
->
batchSize
,
pNode
->
replicaNum
,
pNode
->
pRaftCfg
->
lastConfigIndex
,
pNode
->
changing
,
pNode
->
restoreFinish
,
quorum
,
pNode
->
electTimerLogicClock
,
pNode
->
heartbeatTimerLogicClockUser
,
peerStr
,
cfgStr
);
}
...
...
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
浏览文件 @
fdad1087
...
...
@@ -104,37 +104,37 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pPingTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pPingTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"pingTimerMS"
,
pSyncNode
->
pingTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
pingTimerLogicClock
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
pingTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
pingTimerLogicClockUser
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
pingTimerLogicClockUser
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerLogicClockUser"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpPingTimerCB
);
cJSON_AddStringToObject
(
pRoot
,
"FpPingTimerCB"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
pingTimerCounter
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
pingTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"pingTimerCounter"
,
u64buf
);
// elect timer
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pElectTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pElectTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"electTimerMS"
,
pSyncNode
->
electTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
electTimerLogicClock
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
electTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"electTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpElectTimerCB
);
cJSON_AddStringToObject
(
pRoot
,
"FpElectTimerCB"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
electTimerCounter
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
electTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"electTimerCounter"
,
u64buf
);
// heartbeat timer
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pHeartbeatTimer
);
cJSON_AddStringToObject
(
pRoot
,
"pHeartbeatTimer"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"heartbeatTimerMS"
,
pSyncNode
->
heartbeatTimerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
heartbeatTimerLogicClock
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
heartbeatTimerLogicClock
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerLogicClock"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerLogicClockUser"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpHeartbeatTimerCB
);
cJSON_AddStringToObject
(
pRoot
,
"FpHeartbeatTimerCB"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u
64
,
pSyncNode
->
heartbeatTimerCounter
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d
64
,
pSyncNode
->
heartbeatTimerCounter
);
cJSON_AddStringToObject
(
pRoot
,
"heartbeatTimerCounter"
,
u64buf
);
// callback
...
...
@@ -195,7 +195,7 @@ inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
SyncIndex
logBeginIndex
=
pSyncNode
->
pLogStore
->
syncLogBeginIndex
(
pSyncNode
->
pLogStore
);
snprintf
(
s
,
len
,
"vgId:%d, sync %s, tm:%"
PRI
u
64
", cmt:%"
PRId64
", fst:%"
PRId64
", lst:%"
PRId64
", snap:%"
PRId64
"vgId:%d, sync %s, tm:%"
PRI
d
64
", cmt:%"
PRId64
", fst:%"
PRId64
", lst:%"
PRId64
", snap:%"
PRId64
", sby:%d, "
"r-num:%d, "
"lcfg:%"
PRId64
", chging:%d, rsto:%d"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录