Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ffed8636
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看板
提交
ffed8636
编写于
11月 16, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>fix compile error
上级
30321c34
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
59 addition
and
67 deletion
+59
-67
source/libs/sync/inc/sync_raft_progress_tracker.h
source/libs/sync/inc/sync_raft_progress_tracker.h
+2
-0
source/libs/sync/inc/sync_raft_quorum_joint.h
source/libs/sync/inc/sync_raft_quorum_joint.h
+5
-14
source/libs/sync/inc/sync_raft_quorum_majority.h
source/libs/sync/inc/sync_raft_quorum_majority.h
+1
-1
source/libs/sync/src/raft.c
source/libs/sync/src/raft.c
+8
-34
source/libs/sync/src/sync_raft_config_change.c
source/libs/sync/src/sync_raft_config_change.c
+9
-9
source/libs/sync/src/sync_raft_impl.c
source/libs/sync/src/sync_raft_impl.c
+14
-2
source/libs/sync/src/sync_raft_quorum_joint.c
source/libs/sync/src/sync_raft_quorum_joint.c
+18
-5
source/libs/sync/src/sync_raft_quorum_majority.c
source/libs/sync/src/sync_raft_quorum_majority.c
+2
-2
未找到文件。
source/libs/sync/inc/sync_raft_progress_tracker.h
浏览文件 @
ffed8636
...
...
@@ -112,4 +112,6 @@ ESyncRaftVoteResult syncRaftTallyVotes(SSyncRaftProgressTracker* tracker, int* r
void
syncRaftConfigState
(
const
SSyncRaftProgressTracker
*
tracker
,
SSyncConfigState
*
cs
);
bool
syncRaftIsInNodeMap
(
const
SSyncRaftNodeMap
*
nodeMap
,
SyncNodeId
nodeId
);
#endif
/* _TD_LIBS_SYNC_RAFT_PROGRESS_TRACKER_H */
source/libs/sync/inc/sync_raft_quorum_joint.h
浏览文件 @
ffed8636
...
...
@@ -36,34 +36,25 @@ typedef struct SSyncRaftQuorumJointConfig {
**/
ESyncRaftVoteType
syncRaftVoteResult
(
SSyncRaftQuorumJointConfig
*
config
,
const
ESyncRaftVoteType
*
votes
);
static
FORCE_INLINE
bool
syncRaftJointConfigInCluster
(
const
SSyncCluster
*
cluster
,
SyncNodeId
id
)
{
int
i
;
for
(
i
=
0
;
i
<
cluster
->
replica
;
++
i
)
{
if
(
cluster
->
nodeInfo
[
i
].
nodeId
==
id
)
{
return
true
;
}
}
return
false
;
}
bool
syncRaftIsInNodeMap
(
const
SSyncRaftNodeMap
*
nodeMap
,
SyncNodeId
nodeId
);
static
FORCE_INLINE
bool
syncRaftJointConfigInOutgoing
(
const
SSyncRaftQuorumJointConfig
*
config
,
SyncNodeId
id
)
{
return
syncRaft
JointConfigInCluster
(
&
config
->
outgoing
,
id
);
return
syncRaft
IsInNodeMap
(
&
config
->
outgoing
,
id
);
}
static
FORCE_INLINE
bool
syncRaftJointConfigInIncoming
(
const
SSyncRaftQuorumJointConfig
*
config
,
SyncNodeId
id
)
{
return
syncRaft
JointConfigInCluster
(
&
config
->
incoming
,
id
);
return
syncRaft
IsInNodeMap
(
&
config
->
incoming
,
id
);
}
void
syncRaftJointConfigAddToIncoming
(
SSyncRaftQuorumJointConfig
*
config
,
SyncNodeId
id
);
void
syncRaftJointConfigRemoveFromIncoming
(
SSyncRaftQuorumJointConfig
*
config
,
SyncNodeId
id
);
static
FORCE_INLINE
const
SSync
Cluster
*
syncRaftJointConfigIncoming
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
static
FORCE_INLINE
const
SSync
RaftNodeMap
*
syncRaftJointConfigIncoming
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
return
&
config
->
incoming
;
}
static
FORCE_INLINE
const
SSync
Cluster
*
syncRaftJointConfigOutgoing
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
static
FORCE_INLINE
const
SSync
RaftNodeMap
*
syncRaftJointConfigOutgoing
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
return
&
config
->
outgoing
;
}
...
...
source/libs/sync/inc/sync_raft_quorum_majority.h
浏览文件 @
ffed8636
...
...
@@ -26,6 +26,6 @@
* yes/no has been reached), won (a quorum of yes has been reached), or lost (a
* quorum of no has been reached).
**/
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSync
Cluster
*
config
,
const
ESyncRaftVoteType
*
votes
);
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSync
RaftNodeMap
*
config
,
const
ESyncRaftVoteType
*
votes
);
#endif
/* _TD_LIBS_SYNC_RAFT_QUORUM_MAJORITY_H */
source/libs/sync/src/raft.c
浏览文件 @
ffed8636
...
...
@@ -30,6 +30,8 @@ static int deserializeClusterStateFromBuffer(SSyncConfigState* cluster, const ch
static
void
switchToConfig
(
SSyncRaft
*
pRaft
,
const
SSyncRaftProgressTrackerConfig
*
config
,
const
SSyncRaftProgressMap
*
progressMap
,
SSyncConfigState
*
cs
);
static
void
abortLeaderTransfer
(
SSyncRaft
*
pRaft
);
static
bool
preHandleMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
static
bool
preHandleNewTermMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
static
bool
preHandleOldTermMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
...
...
@@ -109,38 +111,6 @@ int32_t syncRaftStart(SSyncRaft* pRaft, const SSyncInfo* pInfo) {
syncRaftBecomeFollower
(
pRaft
,
pRaft
->
term
,
SYNC_NON_NODE_ID
);
#if 0
// restore fsm state from snapshot index + 1 until commitIndex
++initIndex;
while (initIndex <= serverState.commitIndex) {
limit = MIN(RAFT_READ_LOG_MAX_NUM, serverState.commitIndex - initIndex + 1);
if (logStore->logRead(logStore, initIndex, limit, buffer, &nBuf) != 0) {
return -1;
}
assert(limit == nBuf);
for (i = 0; i < limit; ++i) {
fsm->applyLog(fsm, initIndex + i, &(buffer[i]), NULL);
free(buffer[i].data);
}
initIndex += nBuf;
}
assert(initIndex == serverState.commitIndex);
//pRaft->heartbeatTimeoutTick = 1;
syncRaftBecomeFollower(pRaft, pRaft->term, SYNC_NON_NODE_ID);
pRaft->selfIndex = pRaft->cluster.selfIndex;
#endif
syncInfo
(
"[%d:%d] restore vgid %d state: snapshot index success"
,
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
pInfo
->
vgId
);
return
0
;
...
...
@@ -242,12 +212,16 @@ static void switchToConfig(SSyncRaft* pRaft, const SSyncRaftProgressTrackerConfi
// If the the leadTransferee was removed or demoted, abort the leadership transfer.
SyncNodeId
leadTransferee
=
pRaft
->
leadTransferee
;
if
(
leadTransferee
!=
SYNC_NON_NODE_ID
)
{
if
(
leadTransferee
!=
SYNC_NON_NODE_ID
&&
!
syncRaftIsInNodeMap
(
&
pRaft
->
tracker
->
config
.
voters
,
leadTransferee
)
)
{
abortLeaderTransfer
(
pRaft
);
}
}
}
static
void
abortLeaderTransfer
(
SSyncRaft
*
pRaft
)
{
pRaft
->
leadTransferee
=
SYNC_NON_NODE_ID
;
}
/**
* pre-handle message, return true means no need to continue
* Handle the message term, which may result in our stepping down to a follower.
...
...
source/libs/sync/src/sync_raft_config_change.c
浏览文件 @
ffed8636
...
...
@@ -26,8 +26,8 @@ static int checkInvariants(SSyncRaftProgressTrackerConfig* config, SSyncRaftProg
static
bool
hasJointConfig
(
const
SSyncRaftProgressTrackerConfig
*
config
);
static
int
applyConfig
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
,
const
SSyncConfChangeSingleArray
*
css
);
static
int
symDiff
(
const
SSyncCluster
*
l
,
const
SSyncCluster
*
r
);
static
int
symDiff
(
const
SSyncRaftNodeMap
*
l
,
const
SSyncRaftNodeMap
*
r
);
static
void
initProgress
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
,
SyncNodeId
id
,
bool
isLearner
);
...
...
@@ -237,27 +237,27 @@ static int applyConfig(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfig
// symdiff returns the count of the symmetric difference between the sets of
// uint64s, i.e. len( (l - r) \union (r - l)).
static
int
symDiff
(
const
SSync
Cluster
*
l
,
const
SSyncCluster
*
r
)
{
static
int
symDiff
(
const
SSync
RaftNodeMap
*
l
,
const
SSyncRaftNodeMap
*
r
)
{
int
n
;
int
i
;
int
j0
,
j1
;
const
SSync
Cluster
*
pairs
[
2
][
2
]
=
{
const
SSync
RaftNodeMap
*
pairs
[
2
][
2
]
=
{
{
l
,
r
},
// count elems in l but not in r
{
r
,
l
},
// count elems in r but not in l
};
for
(
n
=
0
,
i
=
0
;
i
<
2
;
++
i
)
{
const
SSync
Cluster
**
pp
=
pairs
[
i
];
const
SSync
RaftNodeMap
**
pp
=
pairs
[
i
];
const
SSync
Cluster
*
p0
=
pp
[
0
];
const
SSync
Cluster
*
p1
=
pp
[
1
];
for
(
j0
=
0
;
j0
<
p0
->
replica
;
++
j0
)
{
SyncNodeId
id
=
p0
->
nodeI
nfo
[
j0
].
nodeId
;
const
SSync
RaftNodeMap
*
p0
=
pp
[
0
];
const
SSync
RaftNodeMap
*
p1
=
pp
[
1
];
for
(
j0
=
0
;
j0
<
TSDB_MAX_REPLICA
;
++
j0
)
{
SyncNodeId
id
=
p0
->
nodeI
d
[
j0
]
;
if
(
id
==
SYNC_NON_NODE_ID
)
{
continue
;
}
for
(
j1
=
0
;
j1
<
p1
->
replica
;
++
j1
)
{
if
(
p1
->
nodeI
nfo
[
j1
].
nodeId
!=
SYNC_NON_NODE_ID
&&
p1
->
nodeInfo
[
j1
].
nodeId
!=
id
)
{
if
(
p1
->
nodeI
d
[
j1
]
!=
SYNC_NON_NODE_ID
&&
p1
->
nodeId
[
j1
]
!=
id
)
{
n
+=
1
;
}
}
...
...
source/libs/sync/src/sync_raft_impl.c
浏览文件 @
ffed8636
...
...
@@ -185,8 +185,17 @@ void syncRaftLoadState(SSyncRaft* pRaft, const SSyncServerState* serverState) {
pRaft
->
voteFor
=
serverState
->
voteFor
;
}
void
syncRaftBroadcastAppend
(
SSyncRaft
*
pRaft
)
{
static
void
visitProgressSendAppend
(
int
i
,
SSyncRaftProgress
*
progress
,
void
*
arg
)
{
SSyncRaft
*
pRaft
=
(
SSyncRaft
*
)
arg
;
if
(
pRaft
->
selfId
==
progress
->
id
)
{
return
;
}
syncRaftReplicate
(
arg
,
progress
,
true
);
}
void
syncRaftBroadcastAppend
(
SSyncRaft
*
pRaft
)
{
syncRaftProgressVisit
(
pRaft
->
tracker
,
visitProgressSendAppend
,
pRaft
);
}
static
int
convertClear
(
SSyncRaft
*
pRaft
)
{
...
...
@@ -279,6 +288,7 @@ bool syncRaftMaybeCommit(SSyncRaft* pRaft) {
* trigger I/O requests for newly appended log entries or heartbeats.
**/
static
int
triggerAll
(
SSyncRaft
*
pRaft
)
{
#if 0
assert(pRaft->state == TAOS_SYNC_STATE_LEADER);
int i;
...
...
@@ -287,8 +297,10 @@ static int triggerAll(SSyncRaft* pRaft) {
continue;
}
syncRaftReplicate
(
pRaft
,
i
);
syncRaftReplicate(pRaft,
pRaft->tracker->progressMap.progress[i], true
);
}
#endif
return
0
;
}
static
void
abortLeaderTransfer
(
SSyncRaft
*
pRaft
)
{
...
...
source/libs/sync/src/sync_raft_quorum_joint.c
浏览文件 @
ffed8636
...
...
@@ -44,16 +44,16 @@ void syncRaftJointConfigAddToIncoming(SSyncRaftQuorumJointConfig* config, SyncNo
int
i
,
min
;
for
(
i
=
0
,
min
=
-
1
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
if
(
config
->
incoming
.
nodeI
nfo
[
i
].
nodeId
==
id
)
{
if
(
config
->
incoming
.
nodeI
d
[
i
]
==
id
)
{
return
;
}
if
(
min
==
-
1
&&
config
->
incoming
.
nodeI
nfo
[
i
].
nodeId
==
SYNC_NON_NODE_ID
)
{
if
(
min
==
-
1
&&
config
->
incoming
.
nodeI
d
[
i
]
==
SYNC_NON_NODE_ID
)
{
min
=
i
;
}
}
assert
(
min
!=
-
1
);
config
->
incoming
.
nodeI
nfo
[
min
].
nodeId
=
id
;
config
->
incoming
.
nodeI
d
[
min
]
=
id
;
config
->
incoming
.
replica
+=
1
;
}
...
...
@@ -61,12 +61,25 @@ void syncRaftJointConfigRemoveFromIncoming(SSyncRaftQuorumJointConfig* config, S
int
i
;
for
(
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
if
(
config
->
incoming
.
nodeI
nfo
[
i
].
nodeId
==
id
)
{
if
(
config
->
incoming
.
nodeI
d
[
i
]
==
id
)
{
config
->
incoming
.
replica
-=
1
;
config
->
incoming
.
nodeI
nfo
[
i
].
nodeId
=
SYNC_NON_NODE_ID
;
config
->
incoming
.
nodeI
d
[
i
]
=
SYNC_NON_NODE_ID
;
break
;
}
}
assert
(
config
->
incoming
.
replica
>=
0
);
}
bool
syncRaftIsInNodeMap
(
const
SSyncRaftNodeMap
*
nodeMap
,
SyncNodeId
nodeId
)
{
int
i
;
for
(
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
if
(
nodeId
==
nodeMap
->
nodeId
[
i
])
{
return
true
;
}
}
return
false
;
}
\ No newline at end of file
source/libs/sync/src/sync_raft_quorum_majority.c
浏览文件 @
ffed8636
...
...
@@ -22,14 +22,14 @@
* yes/no has been reached), won (a quorum of yes has been reached), or lost (a
* quorum of no has been reached).
**/
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSync
Cluster
*
config
,
const
ESyncRaftVoteType
*
votes
)
{
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSync
RaftNodeMap
*
config
,
const
ESyncRaftVoteType
*
votes
)
{
if
(
config
->
replica
==
0
)
{
return
SYNC_RAFT_VOTE_WON
;
}
int
i
,
g
,
r
,
missing
;
for
(
i
=
g
=
r
=
missing
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
if
(
config
->
nodeI
nfo
[
i
].
nodeId
==
SYNC_NON_NODE_ID
)
{
if
(
config
->
nodeI
d
[
i
]
==
SYNC_NON_NODE_ID
)
{
continue
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录