Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
25219949
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
25219949
编写于
11月 15, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>refactor sync interface
上级
83a40a7f
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
43 addition
and
15 deletion
+43
-15
source/libs/sync/inc/sync_raft_config_change.h
source/libs/sync/inc/sync_raft_config_change.h
+1
-1
source/libs/sync/inc/sync_raft_restore.h
source/libs/sync/inc/sync_raft_restore.h
+1
-1
source/libs/sync/src/raft.c
source/libs/sync/src/raft.c
+20
-2
source/libs/sync/src/sync_raft_config_change.c
source/libs/sync/src/sync_raft_config_change.c
+19
-9
source/libs/sync/src/sync_raft_restore.c
source/libs/sync/src/sync_raft_restore.c
+2
-2
未找到文件。
source/libs/sync/inc/sync_raft_config_change.h
浏览文件 @
25219949
...
...
@@ -36,7 +36,7 @@ typedef int (*configChangeFp)(SSyncRaftChanger* changer, const SSyncConfChangeSi
int
syncRaftChangerSimpleConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncConfChangeSingleArray
*
css
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
);
int
syncRaftChangerEnterJoint
(
SSyncRaftChanger
*
changer
,
const
SSyncConfChangeSingleArray
*
css
,
int
syncRaftChangerEnterJoint
(
SSyncRaftChanger
*
changer
,
bool
autoLeave
,
const
SSyncConfChangeSingleArray
*
css
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
);
#endif
/* TD_SYNC_RAFT_CONFIG_CHANGE_H */
source/libs/sync/inc/sync_raft_restore.h
浏览文件 @
25219949
...
...
@@ -19,7 +19,7 @@
#include "sync_type.h"
#include "sync_raft_proto.h"
//
Restore
takes a Changer (which must represent an empty configuration), and
//
syncRaftRestoreConfig
takes a Changer (which must represent an empty configuration), and
// runs a sequence of changes enacting the configuration described in the
// ConfState.
//
...
...
source/libs/sync/src/raft.c
浏览文件 @
25219949
...
...
@@ -22,6 +22,9 @@
#define RAFT_READ_LOG_MAX_NUM 100
static
int
deserializeServerStateFromBuffer
(
SSyncServerState
*
server
,
const
char
*
buffer
,
int
n
);
static
int
deserializeClusterConfigFromBuffer
(
SSyncClusterConfig
*
cluster
,
const
char
*
buffer
,
int
n
);
static
bool
preHandleMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
static
bool
preHandleNewTermMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
static
bool
preHandleOldTermMessage
(
SSyncRaft
*
pRaft
,
const
SSyncMessage
*
pMsg
);
...
...
@@ -35,6 +38,8 @@ int32_t syncRaftStart(SSyncRaft* pRaft, const SSyncInfo* pInfo) {
SyncIndex
initIndex
=
pInfo
->
snapshotIndex
;
SSyncBuffer
buffer
[
RAFT_READ_LOG_MAX_NUM
];
int
nBuf
,
limit
,
i
;
char
*
buf
;
int
n
;
memset
(
pRaft
,
0
,
sizeof
(
SSyncRaft
));
...
...
@@ -57,10 +62,15 @@ int32_t syncRaftStart(SSyncRaft* pRaft, const SSyncInfo* pInfo) {
return
-
1
;
}
// read server state
if
(
stateManager
->
readServerState
(
stateManager
,
&
serverState
)
!=
0
)
{
if
(
stateManager
->
readServerState
(
stateManager
,
&
buf
,
&
n
)
!=
0
)
{
syncError
(
"readServerState for vgid %d fail"
,
pInfo
->
vgId
);
return
-
1
;
}
if
(
deserializeServerStateFromBuffer
(
&
serverState
,
buf
,
n
)
!=
0
)
{
syncError
(
"deserializeServerStateFromBuffer for vgid %d fail"
,
pInfo
->
vgId
);
return
-
1
;
}
assert
(
initIndex
<=
serverState
.
commitIndex
);
// restore fsm state from snapshot index + 1 until commitIndex
...
...
@@ -119,6 +129,14 @@ int32_t syncRaftTick(SSyncRaft* pRaft) {
return
0
;
}
static
int
deserializeServerStateFromBuffer
(
SSyncServerState
*
server
,
const
char
*
buffer
,
int
n
)
{
return
0
;
}
static
int
deserializeClusterConfigFromBuffer
(
SSyncClusterConfig
*
cluster
,
const
char
*
buffer
,
int
n
)
{
return
0
;
}
/**
* 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
浏览文件 @
25219949
...
...
@@ -17,6 +17,7 @@
#include "sync_raft_config_change.h"
#include "sync_raft_progress.h"
#include "sync_raft_progress_tracker.h"
#include "sync_raft_quorum_joint.h"
static
int
checkAndCopy
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
);
static
int
checkAndReturn
(
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
);
...
...
@@ -38,7 +39,7 @@ static void makeVoter(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfig*
SSyncRaftProgressMap
*
progressMap
,
SyncNodeId
id
);
static
void
makeLearner
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
,
SyncNodeId
id
);
static
void
remove
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
static
void
remove
NodeId
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
,
SyncNodeId
id
);
// syncRaftChangerSimpleConfig carries out a series of configuration changes that (in aggregate)
// mutates the incoming majority config Voters[0] by at most one. This method
...
...
@@ -87,7 +88,7 @@ int syncRaftChangerSimpleConfig(SSyncRaftChanger* changer, const SSyncConfChange
// (Section 4.3) corresponds to `C_{new,old}`.
//
// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf
int
syncRaftChangerEnterJoint
(
SSyncRaftChanger
*
changer
,
const
SSyncConfChangeSingleArray
*
css
,
int
syncRaftChangerEnterJoint
(
SSyncRaftChanger
*
changer
,
bool
autoLeave
,
const
SSyncConfChangeSingleArray
*
css
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
)
{
int
ret
;
...
...
@@ -108,9 +109,18 @@ int syncRaftChangerEnterJoint(SSyncRaftChanger* changer, const SSyncConfChangeSi
}
// Clear the outgoing config.
syncRaftJointConfigClearOutgoing
(
config
);
syncRaftJointConfigClearOutgoing
(
&
config
->
voters
);
// Copy incoming to outgoing.
memcpy
(
&
config
->
voters
.
outgoing
,
&
config
->
voters
.
incoming
,
sizeof
(
SSyncCluster
));
ret
=
applyConfig
(
changer
,
config
,
progressMap
,
css
);
if
(
ret
!=
0
)
{
return
ret
;
}
config
->
autoLeave
=
autoLeave
;
return
checkAndReturn
(
config
,
progressMap
);
}
// checkAndCopy copies the tracker's config and progress map (deeply enough for
...
...
@@ -210,7 +220,7 @@ static int applyConfig(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfig
makeLearner
(
changer
,
config
,
progressMap
,
cs
->
nodeId
);
break
;
case
SYNC_RAFT_Conf_RemoveNode
:
remove
(
changer
,
config
,
progressMap
,
cs
->
nodeId
);
remove
NodeId
(
changer
,
config
,
progressMap
,
cs
->
nodeId
);
break
;
case
SYNC_RAFT_Conf_UpdateNode
:
break
;
...
...
@@ -309,7 +319,7 @@ static void makeVoter(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfig*
progress
->
isLearner
=
false
;
nilAwareDelete
(
&
config
->
learners
,
id
);
nilAwareDelete
(
&
config
->
learnersNext
,
id
);
syncRaftJointConfigAddToIncoming
(
config
,
id
);
syncRaftJointConfigAddToIncoming
(
&
config
->
voters
,
id
);
}
// makeLearner makes the given ID a learner or stages it to be a learner once
...
...
@@ -339,7 +349,7 @@ static void makeLearner(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfi
return
;
}
// Remove any existing voter in the incoming config...
remove
(
changer
,
config
,
progressMap
,
id
);
remove
NodeId
(
changer
,
config
,
progressMap
,
id
);
// ... but save the Progress.
syncRaftAddToProgressMap
(
progressMap
,
id
);
...
...
@@ -358,8 +368,8 @@ static void makeLearner(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfi
}
}
// remove this peer as a voter or learner from the incoming config.
static
void
remove
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
// remove
NodeId
this peer as a voter or learner from the incoming config.
static
void
remove
NodeId
(
SSyncRaftChanger
*
changer
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
,
SyncNodeId
id
)
{
int
i
=
syncRaftFindProgressIndexByNodeId
(
progressMap
,
id
);
if
(
i
==
-
1
)
{
...
...
source/libs/sync/src/sync_raft_restore.c
浏览文件 @
25219949
...
...
@@ -19,7 +19,7 @@
static
int
toConfChangeSingle
(
const
SSyncConfigState
*
cs
,
SSyncConfChangeSingleArray
*
out
,
SSyncConfChangeSingleArray
*
in
);
//
Restore
takes a Changer (which must represent an empty configuration), and
//
syncRaftRestoreConfig
takes a Changer (which must represent an empty configuration), and
// runs a sequence of changes enacting the configuration described in the
// ConfState.
//
...
...
@@ -70,7 +70,7 @@ int syncRaftRestoreConfig(SSyncRaftChanger* changer, const SSyncConfigState* cs)
}
}
ret
=
syncRaftChangerEnterJoint
(
changer
,
&
incoming
,
config
,
progressMap
);
ret
=
syncRaftChangerEnterJoint
(
changer
,
cs
->
autoLeave
,
&
incoming
,
config
,
progressMap
);
if
(
ret
!=
0
)
{
goto
out
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录