Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b6c7bc3
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看板
提交
5b6c7bc3
编写于
7月 15, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add leader transfer callback
上级
e3eaddac
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
12 deletion
+75
-12
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+13
-12
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+9
-0
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+7
-0
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+5
-0
tests/script/tsim/sync/mnodeLeaderTransfer.sim
tests/script/tsim/sync/mnodeLeaderTransfer.sim
+41
-0
未找到文件。
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
5b6c7bc3
...
...
@@ -50,8 +50,8 @@ extern "C" {
// clang-format on
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
#define SYSTABLE_SCH_DB_NAME_LEN
((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
#define SYSTABLE_SCH_COL_NAME_LEN
((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
typedef
int32_t
(
*
MndMsgFp
)(
SRpcMsg
*
pMsg
);
typedef
int32_t
(
*
MndInitFp
)(
SMnode
*
pMnode
);
...
...
@@ -61,7 +61,7 @@ typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter);
typedef
struct
SQWorker
SQHandle
;
typedef
struct
{
const
char
*
name
;
const
char
*
name
;
MndInitFp
initFp
;
MndCleanupFp
cleanupFp
;
}
SMnodeStep
;
...
...
@@ -70,7 +70,7 @@ typedef struct {
int64_t
showId
;
ShowRetrieveFp
retrieveFps
[
TSDB_MGMT_TABLE_MAX
];
ShowFreeIterFp
freeIterFps
[
TSDB_MGMT_TABLE_MAX
];
SCacheObj
*
cache
;
SCacheObj
*
cache
;
}
SShowMgmt
;
typedef
struct
{
...
...
@@ -84,12 +84,13 @@ typedef struct {
}
STelemMgmt
;
typedef
struct
{
tsem_t
syncSem
;
tsem_t
syncSem
;
int64_t
sync
;
bool
standby
;
SReplica
replica
;
int32_t
errCode
;
int32_t
transId
;
int8_t
leaderTransferFinish
;
}
SSyncMgmt
;
typedef
struct
{
...
...
@@ -107,14 +108,14 @@ typedef struct SMnode {
bool
stopped
;
bool
restored
;
bool
deploy
;
char
*
path
;
char
*
path
;
int64_t
checkTime
;
SSdb
*
pSdb
;
SArray
*
pSteps
;
SQHandle
*
pQuery
;
SHashObj
*
infosMeta
;
SHashObj
*
perfsMeta
;
SWal
*
pWal
;
SSdb
*
pSdb
;
SArray
*
pSteps
;
SQHandle
*
pQuery
;
SHashObj
*
infosMeta
;
SHashObj
*
perfsMeta
;
SWal
*
pWal
;
SShowMgmt
showMgmt
;
SProfileMgmt
profileMgmt
;
STelemMgmt
telemMgmt
;
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
5b6c7bc3
...
...
@@ -367,8 +367,17 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
}
void
mndPreClose
(
SMnode
*
pMnode
)
{
mDebug
(
"vgId:1, mnode pre-close"
);
if
(
pMnode
!=
NULL
)
{
atomic_store_8
(
&
(
pMnode
->
syncMgmt
.
leaderTransferFinish
),
0
);
syncLeaderTransfer
(
pMnode
->
syncMgmt
.
sync
);
mDebug
(
"vgId:1, wait for mnode leader transfer"
);
// wait for leader transfer finish
while
(
!
atomic_load_8
(
&
(
pMnode
->
syncMgmt
.
leaderTransferFinish
)))
{
taosMsleep
(
10
);
}
mDebug
(
"vgId:1, mnode leader transfer finish"
);
}
}
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
5b6c7bc3
...
...
@@ -153,6 +153,12 @@ int32_t mndSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int
return
sdbDoWrite
(
pMnode
->
pSdb
,
pWriter
,
pBuf
,
len
);
}
void
mndLeaderTransfer
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
atomic_store_8
(
&
(
pMnode
->
syncMgmt
.
leaderTransferFinish
),
1
);
mDebug
(
"vgId:1, mnd leader transfer finish"
);
}
SSyncFSM
*
mndSyncMakeFsm
(
SMnode
*
pMnode
)
{
SSyncFSM
*
pFsm
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncFSM
));
pFsm
->
data
=
pMnode
;
...
...
@@ -160,6 +166,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
pFsm
->
FpPreCommitCb
=
NULL
;
pFsm
->
FpRollBackCb
=
NULL
;
pFsm
->
FpRestoreFinishCb
=
mndRestoreFinish
;
pFsm
->
FpLeaderTransferCb
=
mndLeaderTransfer
;
pFsm
->
FpReConfigCb
=
mndReConfig
;
pFsm
->
FpGetSnapshot
=
mndSyncGetSnapshot
;
pFsm
->
FpGetSnapshotInfo
=
mndSyncGetSnapshotInfo
;
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
5b6c7bc3
...
...
@@ -536,6 +536,10 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *
#endif
}
static
void
vnodeLeaderTransfer
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
}
static
SSyncFSM
*
vnodeSyncMakeFsm
(
SVnode
*
pVnode
)
{
SSyncFSM
*
pFsm
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncFSM
));
pFsm
->
data
=
pVnode
;
...
...
@@ -544,6 +548,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
pFsm
->
FpRollBackCb
=
vnodeSyncRollBackMsg
;
pFsm
->
FpGetSnapshotInfo
=
vnodeSyncGetSnapshot
;
pFsm
->
FpRestoreFinishCb
=
NULL
;
pFsm
->
FpLeaderTransferCb
=
vnodeLeaderTransfer
;
pFsm
->
FpReConfigCb
=
vnodeSyncReconfig
;
pFsm
->
FpSnapshotStartRead
=
vnodeSnapshotStartRead
;
pFsm
->
FpSnapshotStopRead
=
vnodeSnapshotStopRead
;
...
...
tests/script/tsim/sync/mnodeLeaderTransfer.sim
0 → 100644
浏览文件 @
5b6c7bc3
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
sql connect
print =============== show dnodes
sql show mnodes;
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data02 != leader then
return -1
endi
print =============== create dnodes
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sleep 3000
print =============== create mnode 2
sql create mnode on dnode 2
sql create mnode on dnode 3
sleep 3000
print =============== create user
sql create user user1 PASS 'user1'
sql show users
if $rows != 2 then
return -1
endi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录