Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
24b599f1
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
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看板
提交
24b599f1
编写于
11月 12, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10645][raft]<feature>add restore process
上级
fb01dd56
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
91 addition
and
14 deletion
+91
-14
source/libs/sync/inc/sync_raft_progress.h
source/libs/sync/inc/sync_raft_progress.h
+1
-1
source/libs/sync/inc/sync_raft_quorum_joint.h
source/libs/sync/inc/sync_raft_quorum_joint.h
+8
-0
source/libs/sync/inc/sync_raft_restore.h
source/libs/sync/inc/sync_raft_restore.h
+9
-2
source/libs/sync/src/sync_raft_config_change.c
source/libs/sync/src/sync_raft_config_change.c
+59
-1
source/libs/sync/src/sync_raft_progress.c
source/libs/sync/src/sync_raft_progress.c
+1
-1
source/libs/sync/src/sync_raft_restore.c
source/libs/sync/src/sync_raft_restore.c
+13
-9
未找到文件。
source/libs/sync/inc/sync_raft_progress.h
浏览文件 @
24b599f1
...
@@ -214,7 +214,7 @@ bool syncRaftProgressIsUptodate(SSyncRaft* pRaft, SSyncRaftProgress* progress);
...
@@ -214,7 +214,7 @@ bool syncRaftProgressIsUptodate(SSyncRaft* pRaft, SSyncRaftProgress* progress);
void
syncRaftProgressBecomeSnapshot
(
SSyncRaftProgress
*
progress
,
SyncIndex
snapshotIndex
);
void
syncRaftProgressBecomeSnapshot
(
SSyncRaftProgress
*
progress
,
SyncIndex
snapshotIndex
);
void
syncRaft
ProgressCopy
(
const
SSyncRaftProgress
*
from
,
SSyncRaftProgress
*
to
);
void
syncRaft
CopyProgress
(
const
SSyncRaftProgress
*
from
,
SSyncRaftProgress
*
to
);
void
syncRaftProgressMapCopy
(
const
SSyncRaftProgressMap
*
from
,
SSyncRaftProgressMap
*
to
);
void
syncRaftProgressMapCopy
(
const
SSyncRaftProgressMap
*
from
,
SSyncRaftProgressMap
*
to
);
...
...
source/libs/sync/inc/sync_raft_quorum_joint.h
浏览文件 @
24b599f1
...
@@ -55,4 +55,12 @@ static FORCE_INLINE bool syncRaftJointConfigInIncoming(const SSyncRaftQuorumJoin
...
@@ -55,4 +55,12 @@ static FORCE_INLINE bool syncRaftJointConfigInIncoming(const SSyncRaftQuorumJoin
return
syncRaftJointConfigInCluster
(
&
config
->
incoming
,
id
);
return
syncRaftJointConfigInCluster
(
&
config
->
incoming
,
id
);
}
}
static
FORCE_INLINE
const
SSyncCluster
*
syncRaftJointConfigIncoming
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
return
&
config
->
incoming
;
}
static
FORCE_INLINE
const
SSyncCluster
*
syncRaftJointConfigOutgoing
(
const
SSyncRaftQuorumJointConfig
*
config
)
{
return
&
config
->
outgoing
;
}
#endif
/* _TD_LIBS_SYNC_RAFT_QUORUM_JOINT_H */
#endif
/* _TD_LIBS_SYNC_RAFT_QUORUM_JOINT_H */
source/libs/sync/inc/sync_raft_restore.h
浏览文件 @
24b599f1
...
@@ -19,7 +19,14 @@
...
@@ -19,7 +19,14 @@
#include "sync_type.h"
#include "sync_type.h"
#include "sync_raft_proto.h"
#include "sync_raft_proto.h"
int
syncRaftRestoreConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncConfigState
*
cs
,
// Restore takes a Changer (which must represent an empty configuration), and
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
);
// runs a sequence of changes enacting the configuration described in the
// ConfState.
//
// TODO(tbg) it's silly that this takes a Changer. Unravel this by making sure
// the Changer only needs a ProgressMap (not a whole Tracker) at which point
// this can just take LastIndex and MaxInflight directly instead and cook up
// the results from that alone.
int
syncRaftRestoreConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncConfigState
*
cs
);
#endif
/* TD_SYNC_RAFT_RESTORE_H */
#endif
/* TD_SYNC_RAFT_RESTORE_H */
source/libs/sync/src/sync_raft_config_change.c
浏览文件 @
24b599f1
...
@@ -25,6 +25,7 @@ static int checkInvariants(SSyncRaftProgressTrackerConfig* config, SSyncRaftProg
...
@@ -25,6 +25,7 @@ static int checkInvariants(SSyncRaftProgressTrackerConfig* config, SSyncRaftProg
static
bool
hasJointConfig
(
const
SSyncRaftProgressTrackerConfig
*
config
);
static
bool
hasJointConfig
(
const
SSyncRaftProgressTrackerConfig
*
config
);
static
int
applyConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncRaftProgressTrackerConfig
*
config
,
static
int
applyConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncRaftProgressTrackerConfig
*
config
,
const
SSyncRaftProgressMap
*
progressMap
,
const
SSyncConfChangeSingleArray
*
css
);
const
SSyncRaftProgressMap
*
progressMap
,
const
SSyncConfChangeSingleArray
*
css
);
static
int
symDiff
(
const
SSyncCluster
*
l
,
const
SSyncCluster
*
r
);
// Simple carries out a series of configuration changes that (in aggregate)
// Simple carries out a series of configuration changes that (in aggregate)
// mutates the incoming majority config Voters[0] by at most one. This method
// mutates the incoming majority config Voters[0] by at most one. This method
...
@@ -49,9 +50,34 @@ int syncRaftChangerSimpleConfig(SSyncRaftChanger* changer, const SSyncConfChange
...
@@ -49,9 +50,34 @@ int syncRaftChangerSimpleConfig(SSyncRaftChanger* changer, const SSyncConfChange
return
ret
;
return
ret
;
}
}
int
n
=
symDiff
(
syncRaftJointConfigIncoming
(
&
changer
->
tracker
->
config
.
voters
),
syncRaftJointConfigIncoming
(
&
config
->
voters
));
if
(
n
>
1
)
{
syncError
(
"more than one voter changed without entering joint config"
);
return
-
1
;
}
return
checkAndReturn
(
config
,
progressMap
);
return
checkAndReturn
(
config
,
progressMap
);
}
}
// EnterJoint verifies that the outgoing (=right) majority config of the joint
// config is empty and initializes it with a copy of the incoming (=left)
// majority config. That is, it transitions from
//
// (1 2 3)&&()
// to
// (1 2 3)&&(1 2 3).
//
// The supplied changes are then applied to the incoming majority config,
// resulting in a joint configuration that in terms of the Raft thesis[1]
// (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
,
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
)
{
}
// checkAndCopy copies the tracker's config and progress map (deeply enough for
// checkAndCopy copies the tracker's config and progress map (deeply enough for
// the purposes of the Changer) and returns those copies. It returns an error
// the purposes of the Changer) and returns those copies. It returns an error
// if checkInvariants does.
// if checkInvariants does.
...
@@ -63,7 +89,7 @@ static int checkAndCopy(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfi
...
@@ -63,7 +89,7 @@ static int checkAndCopy(SSyncRaftChanger* changer, SSyncRaftProgressTrackerConfi
if
(
progress
->
id
==
SYNC_NON_NODE_ID
)
{
if
(
progress
->
id
==
SYNC_NON_NODE_ID
)
{
continue
;
continue
;
}
}
syncRaft
ProgressCopy
(
progress
,
&
(
progressMap
->
progress
[
i
]));
syncRaft
CopyProgress
(
progress
,
&
(
progressMap
->
progress
[
i
]));
}
}
return
checkAndReturn
(
config
,
progressMap
);
return
checkAndReturn
(
config
,
progressMap
);
}
}
...
@@ -151,4 +177,36 @@ static int applyConfig(SSyncRaftChanger* changer, const SSyncRaftProgressTracker
...
@@ -151,4 +177,36 @@ static int applyConfig(SSyncRaftChanger* changer, const SSyncRaftProgressTracker
}
}
return
0
;
return
0
;
}
// 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
SSyncCluster
*
l
,
const
SSyncCluster
*
r
)
{
int
n
;
int
i
;
int
j0
,
j1
;
const
SSyncCluster
*
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
SSyncCluster
**
pp
=
pairs
[
i
];
const
SSyncCluster
*
p0
=
pp
[
0
];
const
SSyncCluster
*
p1
=
pp
[
1
];
for
(
j0
=
0
;
j0
<
p0
->
replica
;
++
j0
)
{
SyncNodeId
id
=
p0
->
nodeInfo
[
j0
].
nodeId
;
if
(
id
==
SYNC_NON_NODE_ID
)
{
continue
;
}
for
(
j1
=
0
;
j1
<
p1
->
replica
;
++
j1
)
{
if
(
p1
->
nodeInfo
[
j1
].
nodeId
!=
SYNC_NON_NODE_ID
&&
p1
->
nodeInfo
[
j1
].
nodeId
!=
id
)
{
n
+=
1
;
}
}
}
}
return
n
;
}
}
\ No newline at end of file
source/libs/sync/src/sync_raft_progress.c
浏览文件 @
24b599f1
...
@@ -149,7 +149,7 @@ void syncRaftProgressBecomeSnapshot(SSyncRaftProgress* progress, SyncIndex snaps
...
@@ -149,7 +149,7 @@ void syncRaftProgressBecomeSnapshot(SSyncRaftProgress* progress, SyncIndex snaps
progress
->
pendingSnapshotIndex
=
snapshotIndex
;
progress
->
pendingSnapshotIndex
=
snapshotIndex
;
}
}
void
syncRaft
ProgressCopy
(
const
SSyncRaftProgress
*
progress
,
SSyncRaftProgress
*
out
)
{
void
syncRaft
CopyProgress
(
const
SSyncRaftProgress
*
progress
,
SSyncRaftProgress
*
out
)
{
}
}
...
...
source/libs/sync/src/sync_raft_restore.c
浏览文件 @
24b599f1
...
@@ -19,11 +19,21 @@
...
@@ -19,11 +19,21 @@
static
int
toConfChangeSingle
(
const
SSyncConfigState
*
cs
,
SSyncConfChangeSingleArray
*
out
,
SSyncConfChangeSingleArray
*
in
);
static
int
toConfChangeSingle
(
const
SSyncConfigState
*
cs
,
SSyncConfChangeSingleArray
*
out
,
SSyncConfChangeSingleArray
*
in
);
int
syncRaftRestoreConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncConfigState
*
cs
,
// Restore takes a Changer (which must represent an empty configuration), and
SSyncRaftProgressTrackerConfig
*
config
,
SSyncRaftProgressMap
*
progressMap
)
{
// runs a sequence of changes enacting the configuration described in the
// ConfState.
//
// TODO(tbg) it's silly that this takes a Changer. Unravel this by making sure
// the Changer only needs a ProgressMap (not a whole Tracker) at which point
// this can just take LastIndex and MaxInflight directly instead and cook up
// the results from that alone.
int
syncRaftRestoreConfig
(
SSyncRaftChanger
*
changer
,
const
SSyncConfigState
*
cs
)
{
SSyncConfChangeSingleArray
outgoing
;
SSyncConfChangeSingleArray
outgoing
;
SSyncConfChangeSingleArray
incoming
;
SSyncConfChangeSingleArray
incoming
;
SSyncConfChangeSingleArray
css
;
SSyncConfChangeSingleArray
css
;
SSyncRaftProgressTracker
*
tracker
=
changer
->
tracker
;
SSyncRaftProgressTrackerConfig
*
config
=
&
tracker
->
config
;
SSyncRaftProgressMap
*
progressMap
=
&
tracker
->
progressMap
;
int
i
,
ret
;
int
i
,
ret
;
ret
=
toConfChangeSingle
(
cs
,
&
outgoing
,
&
incoming
);
ret
=
toConfChangeSingle
(
cs
,
&
outgoing
,
&
incoming
);
...
@@ -38,12 +48,10 @@ int syncRaftRestoreConfig(SSyncRaftChanger* changer, const SSyncConfigState* cs,
...
@@ -38,12 +48,10 @@ int syncRaftRestoreConfig(SSyncRaftChanger* changer, const SSyncConfigState* cs,
.
n
=
1
,
.
n
=
1
,
.
changes
=
&
incoming
.
changes
[
i
],
.
changes
=
&
incoming
.
changes
[
i
],
};
};
ret
=
syncRaftChangerSimpleConfig
(
changer
,
&
css
,
config
,
progressMap
);
ret
=
syncRaftChangerSimpleConfig
(
changer
,
&
css
,
&
config
,
&
progressMap
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
goto
out
;
goto
out
;
}
}
syncRaftCloneTrackerConfig
(
config
,
&
changer
->
tracker
->
config
);
syncRaftProgressMapCopy
(
progressMap
,
&
changer
->
tracker
->
progressMap
);
}
}
}
else
{
}
else
{
// The ConfState describes a joint configuration.
// The ConfState describes a joint configuration.
...
@@ -60,16 +68,12 @@ int syncRaftRestoreConfig(SSyncRaftChanger* changer, const SSyncConfigState* cs,
...
@@ -60,16 +68,12 @@ int syncRaftRestoreConfig(SSyncRaftChanger* changer, const SSyncConfigState* cs,
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
goto
out
;
goto
out
;
}
}
syncRaftCloneTrackerConfig
(
config
,
&
changer
->
tracker
->
config
);
syncRaftProgressMapCopy
(
progressMap
,
&
changer
->
tracker
->
progressMap
);
}
}
ret
=
syncRaftChangerEnterJoint
(
changer
,
&
incoming
,
config
,
progressMap
);
ret
=
syncRaftChangerEnterJoint
(
changer
,
&
incoming
,
config
,
progressMap
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
goto
out
;
goto
out
;
}
}
syncRaftCloneTrackerConfig
(
config
,
&
changer
->
tracker
->
config
);
syncRaftProgressMapCopy
(
progressMap
,
&
changer
->
tracker
->
progressMap
);
}
}
out:
out:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录