Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
437b6843
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看板
提交
437b6843
编写于
11月 24, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into 3.0
上级
1d294497
c02d71f3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
14 deletion
+64
-14
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-1
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+13
-4
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+3
-0
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+46
-9
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
437b6843
...
...
@@ -232,7 +232,7 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, S
int32_t
syncNodeSendMsgByInfo
(
const
SNodeInfo
*
nodeInfo
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
);
SyncIndex
syncMinMatchIndex
(
SSyncNode
*
pSyncNode
);
int32_t
syncCacheEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
,
LRUHandle
**
h
);
bool
syncNodeHeartbeatTimeout
(
SSyncNode
*
pSyncNode
);
bool
syncNodeHeartbeat
Reply
Timeout
(
SSyncNode
*
pSyncNode
);
// raft state change --------------
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
);
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
437b6843
...
...
@@ -124,6 +124,7 @@ typedef struct SyncHeartbeat {
SyncIndex
commitIndex
;
SyncTerm
privateTerm
;
SyncTerm
minMatchIndex
;
int64_t
timeStamp
;
}
SyncHeartbeat
;
typedef
struct
SyncHeartbeatReply
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
437b6843
...
...
@@ -640,7 +640,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
}
// heartbeat timeout
if
(
syncNodeHeartbeatTimeout
(
pSyncNode
))
{
if
(
syncNodeHeartbeat
Reply
Timeout
(
pSyncNode
))
{
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
sNError
(
pSyncNode
,
"failed to sync propose since hearbeat timeout, type:%s, last:%"
PRId64
", cmt:%"
PRId64
,
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeGetLastIndex
(
pSyncNode
),
pSyncNode
->
commitIndex
);
...
...
@@ -2039,6 +2039,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
pSyncMsg
->
commitIndex
=
pSyncNode
->
commitIndex
;
pSyncMsg
->
minMatchIndex
=
syncMinMatchIndex
(
pSyncNode
);
pSyncMsg
->
privateTerm
=
0
;
pSyncMsg
->
timeStamp
=
taosGetTimestampMs
();
// send msg
syncNodeSendHeartbeat
(
pSyncNode
,
&
pSyncMsg
->
destId
,
&
rpcMsg
);
...
...
@@ -2094,7 +2095,7 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHand
return
code
;
}
bool
syncNodeHeartbeatTimeout
(
SSyncNode
*
pSyncNode
)
{
bool
syncNodeHeartbeat
Reply
Timeout
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
replicaNum
==
1
)
{
return
false
;
}
...
...
@@ -2148,7 +2149,11 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
int32_t
syncNodeOnHeartbeat
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
SyncHeartbeat
*
pMsg
=
pRpcMsg
->
pCont
;
syncLogRecvHeartbeat
(
ths
,
pMsg
,
""
);
int64_t
tsMs
=
taosGetTimestampMs
();
char
buf
[
128
];
snprintf
(
buf
,
sizeof
(
buf
),
"recv local time:%"
PRId64
,
tsMs
);
syncLogRecvHeartbeat
(
ths
,
pMsg
,
buf
);
SRpcMsg
rpcMsg
=
{
0
};
(
void
)
syncBuildHeartbeatReply
(
&
rpcMsg
,
ths
->
vgId
);
...
...
@@ -2161,6 +2166,8 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
pMsgReply
->
timeStamp
=
taosGetTimestampMs
();
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
syncIndexMgrSetRecvTime
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
tsMs
);
syncNodeResetElectTimer
(
ths
);
ths
->
minMatchIndex
=
pMsg
->
minMatchIndex
;
...
...
@@ -2220,9 +2227,11 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
int32_t
syncNodeOnHeartbeatReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
SyncHeartbeatReply
*
pMsg
=
pRpcMsg
->
pCont
;
syncLogRecvHeartbeatReply
(
ths
,
pMsg
,
""
);
int64_t
tsMs
=
taosGetTimestampMs
();
char
buf
[
128
];
snprintf
(
buf
,
sizeof
(
buf
),
"recv local time:%"
PRId64
,
tsMs
);
syncLogRecvHeartbeatReply
(
ths
,
pMsg
,
buf
);
// update last reply time, make decision whether the other node is alive or not
syncIndexMgrSetRecvTime
(
ths
->
pMatchIndex
,
&
pMsg
->
srcId
,
tsMs
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
437b6843
...
...
@@ -213,9 +213,11 @@ int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcM
}
int32_t
syncNodeHeartbeatPeers
(
SSyncNode
*
pSyncNode
)
{
int64_t
ts
=
taosGetTimestampMs
();
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SRpcMsg
rpcMsg
=
{
0
};
if
(
syncBuildHeartbeat
(
&
rpcMsg
,
pSyncNode
->
vgId
)
!=
0
)
{
sError
(
"vgId:%d, build sync-heartbeat error"
,
pSyncNode
->
vgId
);
continue
;
}
...
...
@@ -226,6 +228,7 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
pSyncMsg
->
commitIndex
=
pSyncNode
->
commitIndex
;
pSyncMsg
->
minMatchIndex
=
syncMinMatchIndex
(
pSyncNode
);
pSyncMsg
->
privateTerm
=
0
;
pSyncMsg
->
timeStamp
=
ts
;
// send msg
syncNodeSendHeartbeat
(
pSyncNode
,
&
pSyncMsg
->
destId
,
&
rpcMsg
);
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
437b6843
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "syncUtil.h"
#include "syncIndexMgr.h"
#include "syncMessage.h"
#include "syncRaftCfg.h"
#include "syncRaftStore.h"
...
...
@@ -175,6 +176,36 @@ void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
}
}
// for leader
static
void
syncHearbeatReplyTime2Str
(
SSyncNode
*
pSyncNode
,
char
*
buf
,
int32_t
bufLen
)
{
int32_t
len
=
5
;
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
int64_t
tsMs
=
syncIndexMgrGetRecvTime
(
pSyncNode
->
pMatchIndex
,
&
(
pSyncNode
->
replicasId
[
i
]));
if
(
i
<
pSyncNode
->
replicaNum
-
1
)
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
","
,
i
,
tsMs
);
}
else
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
"}"
,
i
,
tsMs
);
}
}
}
// for follower
static
void
syncHearbeatTime2Str
(
SSyncNode
*
pSyncNode
,
char
*
buf
,
int32_t
bufLen
)
{
int32_t
len
=
4
;
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
int64_t
tsMs
=
syncIndexMgrGetRecvTime
(
pSyncNode
->
pNextIndex
,
&
(
pSyncNode
->
replicasId
[
i
]));
if
(
i
<
pSyncNode
->
replicaNum
-
1
)
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
","
,
i
,
tsMs
);
}
else
{
len
+=
snprintf
(
buf
+
len
,
bufLen
-
len
,
"%d:%"
PRId64
"}"
,
i
,
tsMs
);
}
}
}
static
void
syncPeerState2Str
(
SSyncNode
*
pSyncNode
,
char
*
buf
,
int32_t
bufLen
)
{
int32_t
len
=
1
;
...
...
@@ -221,6 +252,12 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
char
peerStr
[
1024
]
=
"{"
;
syncPeerState2Str
(
pNode
,
peerStr
,
sizeof
(
peerStr
));
char
hbrTimeStr
[
256
]
=
"hbr:{"
;
syncHearbeatReplyTime2Str
(
pNode
,
hbrTimeStr
,
sizeof
(
hbrTimeStr
));
char
hbTimeStr
[
256
]
=
"hb:{"
;
syncHearbeatTime2Str
(
pNode
,
hbTimeStr
,
sizeof
(
hbTimeStr
));
int32_t
quorum
=
syncNodeDynamicQuorum
(
pNode
);
char
eventLog
[
512
];
// {0};
...
...
@@ -243,12 +280,13 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
"%s"
", tm:%"
PRIu64
", cmt:%"
PRId64
", fst:%"
PRId64
", lst:%"
PRId64
", min:%"
PRId64
", snap:%"
PRId64
", snap-tm:%"
PRIu64
", sby:%d, aq:%d, snaping:%"
PRId64
", r-num:%d, lcfg:%"
PRId64
", chging:%d, rsto:%d, dquorum:%d, elt:%"
PRId64
", hb:%"
PRId64
", %s, %s"
,
", chging:%d, rsto:%d, dquorum:%d, elt:%"
PRId64
", hb:%"
PRId64
", %s, %s
, %s, %s
"
,
pNode
->
vgId
,
syncStr
(
pNode
->
state
),
eventLog
,
currentTerm
,
pNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
pNode
->
minMatchIndex
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
pNode
->
pRaftCfg
->
isStandBy
,
aqItems
,
pNode
->
snapshottingIndex
,
pNode
->
replicaNum
,
pNode
->
pRaftCfg
->
lastConfigIndex
,
pNode
->
changing
,
pNode
->
restoreFinish
,
quorum
,
pNode
->
electTimerLogicClock
,
pNode
->
heartbeatTimerLogicClockUser
,
peerStr
,
cfgStr
);
pNode
->
electTimerLogicClock
,
pNode
->
heartbeatTimerLogicClockUser
,
peerStr
,
cfgStr
,
hbTimeStr
,
hbrTimeStr
);
}
}
...
...
@@ -395,9 +433,8 @@ 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:%"
PRId64
", cmt:%"
PRId64
", min-match:%"
PRId64
", pterm:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
privateTerm
,
s
);
"send sync-heartbeat to %s:%d {term:%"
PRId64
", cmt:%"
PRId64
", min-match:%"
PRId64
", ts:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
timeStamp
,
s
);
}
void
syncLogRecvHeartbeat
(
SSyncNode
*
pSyncNode
,
const
SyncHeartbeat
*
pMsg
,
const
char
*
s
)
{
...
...
@@ -406,9 +443,9 @@ 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:%"
PRId64
", cmt:%"
PRId64
", min-match:%"
PRId64
",
pterm
:%"
PRId64
"recv sync-heartbeat from %s:%d {term:%"
PRId64
", cmt:%"
PRId64
", min-match:%"
PRId64
",
ts
:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
privateTerm
,
s
);
host
,
port
,
pMsg
->
term
,
pMsg
->
commitIndex
,
pMsg
->
minMatchIndex
,
pMsg
->
timeStamp
,
s
);
}
void
syncLogSendHeartbeatReply
(
SSyncNode
*
pSyncNode
,
const
SyncHeartbeatReply
*
pMsg
,
const
char
*
s
)
{
...
...
@@ -416,8 +453,8 @@ 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:%"
PRId64
",
pterm
:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
s
);
sNTrace
(
pSyncNode
,
"send sync-heartbeat-reply from %s:%d {term:%"
PRId64
",
ts
:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
timeStamp
,
s
);
}
void
syncLogRecvHeartbeatReply
(
SSyncNode
*
pSyncNode
,
const
SyncHeartbeatReply
*
pMsg
,
const
char
*
s
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录