Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5335c084
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看板
提交
5335c084
编写于
12月 23, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-10431 refact drop mnode msg
上级
ad0995c2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
154 addition
and
86 deletion
+154
-86
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+154
-86
未找到文件。
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
5335c084
...
...
@@ -202,52 +202,6 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
}
}
static
SCreateMnodeInMsg
*
mndBuildCreateMnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SCreateMnodeInMsg
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateMnodeInMsg
));
if
(
pCreate
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pCreate
->
dnodeId
=
htonl
(
pObj
->
id
);
int32_t
numOfReplicas
=
0
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
numOfReplicas
<
TSDB_MAX_REPLICA
-
1
)
{
SMnodeObj
*
pObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pObj
);
if
(
pIter
==
NULL
)
break
;
if
(
pObj
->
pDnode
==
NULL
)
break
;
SReplica
*
pReplica
=
&
pCreate
->
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pObj
->
id
);
pReplica
->
port
=
htons
(
pObj
->
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
numOfReplicas
++
;
}
numOfReplicas
++
;
SReplica
*
pReplica
=
&
pCreate
->
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pObj
->
id
);
pReplica
->
port
=
htons
(
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
return
pCreate
;
}
static
SDropMnodeInMsg
*
mndBuildDropMnodeMsg
(
SMnode
*
pMnode
,
SMnodeObj
*
pObj
)
{
SDropMnodeInMsg
*
pDrop
=
calloc
(
1
,
sizeof
(
SDropMnodeInMsg
));
if
(
pDrop
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pDrop
->
dnodeId
=
htonl
(
pObj
->
id
);
return
pDrop
;
}
static
int32_t
mndSetCreateMnodeRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndMnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
...
...
@@ -272,17 +226,73 @@ static int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnod
return
0
;
}
static
int32_t
mndSetCreateMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
static
int32_t
mndSetCreateMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
SCreateMnodeInMsg
createMsg
=
{
0
};
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
SReplica
*
pReplica
=
&
createMsg
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pMObj
->
id
);
pReplica
->
port
=
htons
(
pMObj
->
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
numOfReplicas
++
;
sdbRelease
(
pSdb
,
pMObj
);
}
SReplica
*
pReplica
=
&
createMsg
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pDnode
->
id
);
pReplica
->
port
=
htons
(
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
numOfReplicas
++
;
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
STransAction
action
=
{
0
};
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pObj
->
id
);
if
(
pDnode
==
NULL
)
return
-
1
;
SAlterMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SAlterMnodeInMsg
));
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
SAlterMnodeInMsg
));
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SAlterMnodeInMsg
);
action
.
msgType
=
TSDB_MSG_TYPE_ALTER_MNODE_IN
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
sdbRelease
(
pSdb
,
pMObj
);
}
{
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
SCreateMnodeInMsg
*
pMsg
=
mndBuildCreateMnodeMsg
(
pMnode
,
pDnode
,
pObj
);
SCreateMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SCreateMnodeInMsg
)
);
if
(
pMsg
==
NULL
)
return
-
1
;
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
SAlterMnodeInMsg
));
pMsg
->
dnodeId
=
htonl
(
pObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SCreateMnodeInMsg
);
action
.
msgType
=
TSDB_MSG_TYPE_CREATE_MNODE_IN
;
...
...
@@ -290,11 +300,12 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SMno
free
(
pMsg
);
return
-
1
;
}
}
return
0
;
}
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateMnodeMsg
*
pCreate
)
{
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
S
DnodeObj
*
pDnode
,
S
CreateMnodeMsg
*
pCreate
)
{
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_MNODE
);
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
...
...
@@ -318,7 +329,7 @@ static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateMnodeMsg *
goto
CREATE_MNODE_OVER
;
}
if
(
mndSetCreateMnodeRedoActions
(
pMnode
,
pTrans
,
&
mnodeObj
)
!=
0
)
{
if
(
mndSetCreateMnodeRedoActions
(
pMnode
,
pTrans
,
pDnode
,
&
mnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
...
...
@@ -343,22 +354,23 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
mDebug
(
"mnode:%d, start to create"
,
pCreate
->
dnodeId
);
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"mnode:%d, dnode not exist"
,
pDnode
->
id
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
mndReleaseDnode
(
pMnode
,
pDnode
);
SMnodeObj
*
pObj
=
mndAcquireMnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pObj
!=
NULL
)
{
mndReleaseMnode
(
pMnode
,
pObj
);
mError
(
"mnode:%d, mnode already exist"
,
pObj
->
id
);
terrno
=
TSDB_CODE_MND_MNODE_ALREADY_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateMnode
(
pMnode
,
pMsg
,
pCreate
);
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"mnode:%d, dnode not exist"
,
pDnode
->
id
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateMnode
(
pMnode
,
pMsg
,
pDnode
,
pCreate
);
mndReleaseDnode
(
pMnode
,
pDnode
);
if
(
code
!=
0
)
{
mError
(
"mnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
...
...
@@ -384,24 +396,80 @@ static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeO
return
0
;
}
static
int32_t
mndSetDropMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMnodeObj
*
pObj
)
{
static
int32_t
mndSetDropMnodeRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SMnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
SAlterMnodeInMsg
alterMsg
=
{
0
};
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
if
(
pMObj
->
id
!=
pObj
->
id
)
{
SReplica
*
pReplica
=
&
alterMsg
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pMObj
->
id
);
pReplica
->
port
=
htons
(
pMObj
->
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
numOfReplicas
++
;
}
sdbRelease
(
pSdb
,
pMObj
);
}
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
if
(
pMObj
->
id
!=
pObj
->
id
)
{
STransAction
action
=
{
0
};
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pObj
->
id
);
if
(
pDnode
==
NULL
)
return
-
1
;
SAlterMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SAlterMnodeInMsg
));
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
memcpy
(
pMsg
,
&
alterMsg
,
sizeof
(
SAlterMnodeInMsg
));
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SAlterMnodeInMsg
);
action
.
msgType
=
TSDB_MSG_TYPE_ALTER_MNODE_IN
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
}
sdbRelease
(
pSdb
,
pMObj
);
}
{
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
SDropMnodeInMsg
*
pMsg
=
mndBuildDropMnodeMsg
(
pMnode
,
pObj
);
if
(
pMsg
==
NULL
)
return
-
1
;
SDropMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SDropMnodeInMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDropMnodeInMsg
);
action
.
msgType
=
TSDB_MSG_TYPE_CREATE
_MNODE_IN
;
action
.
msgType
=
TSDB_MSG_TYPE_DROP
_MNODE_IN
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
}
return
0
;
}
...
...
@@ -426,7 +494,7 @@ static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pObj) {
goto
DROP_MNODE_OVER
;
}
if
(
mndSet
CreateMnodeRedoActions
(
pMnode
,
pTrans
,
pObj
)
!=
0
)
{
if
(
mndSet
DropMnodeRedoActions
(
pMnode
,
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_MNODE_OVER
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录