Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1d874657
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
1d874657
编写于
11月 17, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>add node map
上级
0c65b848
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
39 addition
and
25 deletion
+39
-25
source/libs/sync/inc/sync_raft_progress_tracker.h
source/libs/sync/inc/sync_raft_progress_tracker.h
+5
-2
source/libs/sync/inc/sync_raft_quorum_joint.h
source/libs/sync/inc/sync_raft_quorum_joint.h
+2
-1
source/libs/sync/inc/sync_raft_quorum_majority.h
source/libs/sync/inc/sync_raft_quorum_majority.h
+2
-1
source/libs/sync/inc/sync_type.h
source/libs/sync/inc/sync_type.h
+0
-3
source/libs/sync/src/sync.c
source/libs/sync/src/sync.c
+3
-3
source/libs/sync/src/sync_raft_election.c
source/libs/sync/src/sync_raft_election.c
+6
-1
source/libs/sync/src/sync_raft_impl.c
source/libs/sync/src/sync_raft_impl.c
+1
-1
source/libs/sync/src/sync_raft_progress_tracker.c
source/libs/sync/src/sync_raft_progress_tracker.c
+10
-7
source/libs/sync/src/sync_raft_quorum_joint.c
source/libs/sync/src/sync_raft_quorum_joint.c
+3
-3
source/libs/sync/src/sync_raft_quorum_majority.c
source/libs/sync/src/sync_raft_quorum_majority.c
+7
-3
未找到文件。
source/libs/sync/inc/sync_raft_progress_tracker.h
浏览文件 @
1d874657
...
...
@@ -21,6 +21,7 @@
#include "sync_raft_quorum_joint.h"
#include "sync_raft_progress.h"
#include "sync_raft_proto.h"
#include "thash.h"
struct
SSyncRaftProgressTrackerConfig
{
SSyncRaftQuorumJointConfig
voters
;
...
...
@@ -83,7 +84,9 @@ struct SSyncRaftProgressTracker {
SSyncRaftProgressMap
progressMap
;
ESyncRaftVoteType
votes
[
TSDB_MAX_REPLICA
];
// nodeid -> ESyncRaftVoteType map
SHashObj
*
votesMap
;
int
maxInflightMsgs
;
};
...
...
@@ -98,7 +101,7 @@ void syncRaftProgressVisit(SSyncRaftProgressTracker*, visitProgressFp visit, voi
* syncRaftRecordVote records that the node with the given id voted for this Raft
* instance if v == true (and declined it otherwise).
**/
void
syncRaftRecordVote
(
SSyncRaftProgressTracker
*
tracker
,
int
i
,
bool
grant
);
void
syncRaftRecordVote
(
SSyncRaftProgressTracker
*
tracker
,
SyncNodeId
id
,
bool
grant
);
void
syncRaftCloneTrackerConfig
(
const
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressTrackerConfig
*
result
);
...
...
source/libs/sync/inc/sync_raft_quorum_joint.h
浏览文件 @
1d874657
...
...
@@ -20,6 +20,7 @@
#include "sync.h"
#include "sync_type.h"
#include "sync_raft_node_map.h"
#include "thash.h"
/**
* SSyncRaftQuorumJointConfig is a configuration of two groups of (possibly overlapping)
...
...
@@ -35,7 +36,7 @@ typedef struct SSyncRaftQuorumJointConfig {
* a result indicating whether the vote is pending, lost, or won. A joint quorum
* requires both majority quorums to vote in favor.
**/
ESyncRaftVoteType
syncRaftVoteResult
(
SSyncRaftQuorumJointConfig
*
config
,
const
ESyncRaftVoteType
*
votes
);
ESyncRaftVoteType
syncRaftVoteResult
(
SSyncRaftQuorumJointConfig
*
config
,
SHashObj
*
votesMap
);
static
FORCE_INLINE
bool
syncRaftJointConfigInOutgoing
(
const
SSyncRaftQuorumJointConfig
*
config
,
SyncNodeId
id
)
{
return
syncRaftIsInNodeMap
(
&
config
->
outgoing
,
id
);
...
...
source/libs/sync/inc/sync_raft_quorum_majority.h
浏览文件 @
1d874657
...
...
@@ -19,6 +19,7 @@
#include "sync.h"
#include "sync_type.h"
#include "sync_raft_quorum.h"
#include "thash.h"
/**
* syncRaftMajorityVoteResult takes a mapping of voters to yes/no (true/false) votes and returns
...
...
@@ -26,6 +27,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
(
SSyncRaftNodeMap
*
config
,
const
ESyncRaftVoteType
*
votes
);
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSyncRaftNodeMap
*
config
,
SHashObj
*
votesMap
);
#endif
/* _TD_LIBS_SYNC_RAFT_QUORUM_MAJORITY_H */
source/libs/sync/inc/sync_type.h
浏览文件 @
1d874657
...
...
@@ -77,9 +77,6 @@ typedef enum {
}
ESyncRaftElectionType
;
typedef
enum
{
// the init vote resp status
SYNC_RAFT_VOTE_RESP_UNKNOWN
=
0
,
// grant the vote request
SYNC_RAFT_VOTE_RESP_GRANT
=
1
,
...
...
source/libs/sync/src/sync.c
浏览文件 @
1d874657
...
...
@@ -99,7 +99,7 @@ void syncCleanUp() {
SSyncNode
*
syncStart
(
const
SSyncInfo
*
pInfo
)
{
pthread_mutex_lock
(
&
gSyncManager
->
mutex
);
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
pInfo
->
vgId
,
sizeof
(
SyncGroupId
));
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
pInfo
->
vgId
,
sizeof
(
SyncGroupId
*
));
if
(
ppNode
!=
NULL
)
{
syncInfo
(
"vgroup %d already exist"
,
pInfo
->
vgId
);
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
...
...
@@ -140,7 +140,7 @@ SSyncNode* syncStart(const SSyncInfo* pInfo) {
void
syncStop
(
const
SSyncNode
*
pNode
)
{
pthread_mutex_lock
(
&
gSyncManager
->
mutex
);
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
pNode
->
vgId
,
sizeof
(
SyncGroupId
));
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
pNode
->
vgId
,
sizeof
(
SyncGroupId
*
));
if
(
ppNode
==
NULL
)
{
syncInfo
(
"vgroup %d not exist"
,
pNode
->
vgId
);
pthread_mutex_unlock
(
&
gSyncManager
->
mutex
);
...
...
@@ -288,7 +288,7 @@ static void *syncWorkerMain(void *argv) {
static
void
syncNodeTick
(
void
*
param
,
void
*
tmrId
)
{
SyncGroupId
vgId
=
(
SyncGroupId
)
param
;
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
vgId
,
sizeof
(
SyncGroupId
));
SSyncNode
**
ppNode
=
taosHashGet
(
gSyncManager
->
vgroupTable
,
&
vgId
,
sizeof
(
SyncGroupId
*
));
if
(
ppNode
==
NULL
)
{
return
;
}
...
...
source/libs/sync/src/sync_raft_election.c
浏览文件 @
1d874657
...
...
@@ -95,6 +95,11 @@ static void campaign(SSyncRaft* pRaft, ESyncRaftElectionType cType) {
continue
;
}
SNodeInfo
*
pNode
=
syncRaftGetNodeById
(
pRaft
,
nodeId
);
if
(
pNode
==
NULL
)
{
continue
;
}
SSyncMessage
*
pMsg
=
syncNewVoteMsg
(
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
term
,
cType
,
lastIndex
,
lastTerm
);
if
(
pMsg
==
NULL
)
{
...
...
@@ -105,6 +110,6 @@ static void campaign(SSyncRaft* pRaft, ESyncRaftElectionType cType) {
pRaft
->
selfGroupId
,
pRaft
->
selfId
,
lastTerm
,
lastIndex
,
nodeId
,
pRaft
->
term
);
//pRaft->io.send(pMsg, &(pRaft->cluster.nodeInfo[i])
);
pRaft
->
io
.
send
(
pMsg
,
pNode
);
}
}
\ No newline at end of file
source/libs/sync/src/sync_raft_impl.c
浏览文件 @
1d874657
...
...
@@ -200,7 +200,7 @@ void syncRaftBroadcastAppend(SSyncRaft* pRaft) {
}
SNodeInfo
*
syncRaftGetNodeById
(
SSyncRaft
*
pRaft
,
SyncNodeId
id
)
{
SNodeInfo
**
ppNode
=
taosHashGet
(
pRaft
->
nodeInfoMap
,
&
id
,
sizeof
(
S
NodeInfo
));
SNodeInfo
**
ppNode
=
taosHashGet
(
pRaft
->
nodeInfoMap
,
&
id
,
sizeof
(
S
yncNodeId
*
));
if
(
ppNode
!=
NULL
)
{
return
*
ppNode
;
}
...
...
source/libs/sync/src/sync_raft_progress_tracker.c
浏览文件 @
1d874657
...
...
@@ -26,7 +26,7 @@ SSyncRaftProgressTracker* syncRaftOpenProgressTracker() {
}
void
syncRaftResetVotes
(
SSyncRaftProgressTracker
*
tracker
)
{
memset
(
tracker
->
votes
,
SYNC_RAFT_VOTE_RESP_UNKNOWN
,
sizeof
(
ESyncRaftVoteType
)
*
TSDB_MAX_REPLICA
);
taosHashClear
(
tracker
->
votesMap
);
}
void
syncRaftProgressVisit
(
SSyncRaftProgressTracker
*
tracker
,
visitProgressFp
visit
,
void
*
arg
)
{
...
...
@@ -37,12 +37,14 @@ void syncRaftProgressVisit(SSyncRaftProgressTracker* tracker, visitProgressFp vi
}
}
void
syncRaftRecordVote
(
SSyncRaftProgressTracker
*
tracker
,
int
i
,
bool
grant
)
{
if
(
tracker
->
votes
[
i
]
!=
SYNC_RAFT_VOTE_RESP_UNKNOWN
)
{
void
syncRaftRecordVote
(
SSyncRaftProgressTracker
*
tracker
,
SyncNodeId
id
,
bool
grant
)
{
ESyncRaftVoteType
*
pType
=
taosHashGet
(
tracker
->
votesMap
,
&
id
,
sizeof
(
SyncNodeId
*
));
if
(
pType
!=
NULL
)
{
return
;
}
tracker
->
votes
[
i
]
=
grant
?
SYNC_RAFT_VOTE_RESP_GRANT
:
SYNC_RAFT_VOTE_RESP_REJECT
;
ESyncRaftVoteType
type
=
grant
?
SYNC_RAFT_VOTE_RESP_GRANT
:
SYNC_RAFT_VOTE_RESP_REJECT
;
taosHashPut
(
tracker
->
votesMap
,
&
id
,
sizeof
(
SyncNodeId
),
&
type
,
sizeof
(
ESyncRaftVoteType
*
));
}
void
syncRaftCloneTrackerConfig
(
const
SSyncRaftProgressTrackerConfig
*
from
,
SSyncRaftProgressTrackerConfig
*
to
)
{
...
...
@@ -68,11 +70,12 @@ ESyncRaftVoteResult syncRaftTallyVotes(SSyncRaftProgressTracker* tracker, int* r
continue
;
}
if
(
tracker
->
votes
[
i
]
==
SYNC_RAFT_VOTE_RESP_UNKNOWN
)
{
ESyncRaftVoteType
*
pType
=
taosHashGet
(
tracker
->
votesMap
,
&
progress
->
id
,
sizeof
(
SyncNodeId
*
));
if
(
pType
==
NULL
)
{
continue
;
}
if
(
tracker
->
votes
[
i
]
==
SYNC_RAFT_VOTE_RESP_GRANT
)
{
if
(
*
pType
==
SYNC_RAFT_VOTE_RESP_GRANT
)
{
g
++
;
}
else
{
r
++
;
...
...
@@ -81,7 +84,7 @@ ESyncRaftVoteResult syncRaftTallyVotes(SSyncRaftProgressTracker* tracker, int* r
if
(
rejected
)
*
rejected
=
r
;
if
(
granted
)
*
granted
=
g
;
return
syncRaftVoteResult
(
&
(
tracker
->
config
.
voters
),
tracker
->
votes
);
return
syncRaftVoteResult
(
&
(
tracker
->
config
.
voters
),
tracker
->
votes
Map
);
}
void
syncRaftConfigState
(
const
SSyncRaftProgressTracker
*
tracker
,
SSyncConfigState
*
cs
)
{
...
...
source/libs/sync/src/sync_raft_quorum_joint.c
浏览文件 @
1d874657
...
...
@@ -23,9 +23,9 @@
* a result indicating whether the vote is pending, lost, or won. A joint quorum
* requires both majority quorums to vote in favor.
**/
ESyncRaftVoteType
syncRaftVoteResult
(
SSyncRaftQuorumJointConfig
*
config
,
const
ESyncRaftVoteType
*
votes
)
{
ESyncRaftVoteResult
r1
=
syncRaftMajorityVoteResult
(
&
(
config
->
incoming
),
votes
);
ESyncRaftVoteResult
r2
=
syncRaftMajorityVoteResult
(
&
(
config
->
outgoing
),
votes
);
ESyncRaftVoteType
syncRaftVoteResult
(
SSyncRaftQuorumJointConfig
*
config
,
SHashObj
*
votesMap
)
{
ESyncRaftVoteResult
r1
=
syncRaftMajorityVoteResult
(
&
(
config
->
incoming
),
votes
Map
);
ESyncRaftVoteResult
r2
=
syncRaftMajorityVoteResult
(
&
(
config
->
outgoing
),
votes
Map
);
if
(
r1
==
r2
)
{
// If they agree, return the agreed state.
...
...
source/libs/sync/src/sync_raft_quorum_majority.c
浏览文件 @
1d874657
...
...
@@ -23,7 +23,7 @@
* yes/no has been reached), won (a quorum of yes has been reached), or lost (a
* quorum of no has been reached).
**/
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSyncRaftNodeMap
*
config
,
const
ESyncRaftVoteType
*
votes
)
{
ESyncRaftVoteResult
syncRaftMajorityVoteResult
(
SSyncRaftNodeMap
*
config
,
SHashObj
*
votesMap
)
{
if
(
config
->
replica
==
0
)
{
return
SYNC_RAFT_VOTE_WON
;
}
...
...
@@ -34,9 +34,13 @@ ESyncRaftVoteResult syncRaftMajorityVoteResult(SSyncRaftNodeMap* config, const E
continue
;
}
if
(
votes
[
i
]
==
SYNC_RAFT_VOTE_RESP_UNKNOWN
)
{
const
ESyncRaftVoteType
*
pType
=
taosHashGet
(
votesMap
,
&
config
->
nodeId
[
i
],
sizeof
(
SyncNodeId
*
));
if
(
pType
==
NULL
)
{
missing
+=
1
;
}
else
if
(
votes
[
i
]
==
SYNC_RAFT_VOTE_RESP_GRANT
)
{
continue
;
}
if
(
*
pType
==
SYNC_RAFT_VOTE_RESP_GRANT
)
{
g
+=
1
;
}
else
{
r
+=
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录