Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e0946761
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e0946761
编写于
1月 07, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
1月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9680 from taosdata/feature/dnode3
test for create mnode
上级
7e2076e4
9320f30d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
275 addition
and
381 deletion
+275
-381
source/dnode/mgmt/impl/src/dndMnode.c
source/dnode/mgmt/impl/src/dndMnode.c
+1
-1
source/dnode/mgmt/impl/test/mnode/dmnode.cpp
source/dnode/mgmt/impl/test/mnode/dmnode.cpp
+41
-108
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+85
-113
source/dnode/mnode/impl/test/mnode/CMakeLists.txt
source/dnode/mnode/impl/test/mnode/CMakeLists.txt
+4
-4
source/dnode/mnode/impl/test/mnode/mnode.cpp
source/dnode/mnode/impl/test/mnode/mnode.cpp
+144
-155
未找到文件。
source/dnode/mgmt/impl/src/dndMnode.c
浏览文件 @
e0946761
...
...
@@ -502,7 +502,7 @@ int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
}
SMnode
*
pMnode
=
dndAcquireMnode
(
pDnode
);
if
(
pMnode
!
=
NULL
)
{
if
(
pMnode
=
=
NULL
)
{
terrno
=
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
;
dError
(
"failed to drop mnode since %s"
,
terrstr
());
return
-
1
;
...
...
source/dnode/mgmt/impl/test/mnode/
q
mnode.cpp
→
source/dnode/mgmt/impl/test/mnode/
d
mnode.cpp
浏览文件 @
e0946761
...
...
@@ -13,20 +13,10 @@
class
DndTestMnode
:
public
::
testing
::
Test
{
protected:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_mnode"
,
9113
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9113"
;
server2
.
Start
(
"/tmp/dnode_test_mnode2"
,
fqdn
,
9114
,
firstEp
);
}
static
void
TearDownTestSuite
()
{
server2
.
Stop
();
test
.
Cleanup
();
}
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_mnode"
,
9113
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
Testbase
test
;
static
TestServer
server2
;
public:
void
SetUp
()
override
{}
...
...
@@ -34,24 +24,6 @@ class DndTestMnode : public ::testing::Test {
};
Testbase
DndTestMnode
::
test
;
TestServer
DndTestMnode
::
server2
;
TEST_F
(
DndTestMnode
,
01
_Create_Dnode
)
{
int32_t
contLen
=
sizeof
(
SCreateDnodeReq
);
SCreateDnodeReq
*
pReq
=
(
SCreateDnodeReq
*
)
rpcMallocCont
(
contLen
);
strcpy
(
pReq
->
fqdn
,
"localhost"
);
pReq
->
port
=
htonl
(
9114
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_DNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
taosMsleep
(
1300
);
test
.
SendShowMetaReq
(
TSDB_MGMT_TABLE_DNODE
,
""
);
test
.
SendShowRetrieveReq
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
TEST_F
(
DndTestMnode
,
01
_Create_Mnode
)
{
{
...
...
@@ -101,100 +73,55 @@ TEST_F(DndTestMnode, 01_Create_Mnode) {
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED
);
}
// {
// int32_t contLen = sizeof(SDCreateMnodeReq);
// SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
// pReq->dnodeId = htonl(1);
// pReq->replica = 2;
// pReq->replicas[0].id = htonl(1);
// pReq->replicas[0].port = htonl(9113);
// pReq->replicas[0].id = htonl(1);
// pReq->replicas[0].port = htonl(9113);
// strcpy(pReq->replicas[0].fqdn, "localhost");
// SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, 0);
// }
// {
// int32_t contLen = sizeof(SDCreateMnodeReq);
// SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
// pReq->dnodeId = htonl(1);
// SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
// }
// test.Restart();
// {
// int32_t contLen = sizeof(SDCreateMnodeReq);
// SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
// pReq->dnodeId = htonl(1);
// SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
// }
}
#if 0
TEST_F
(
DndTestMnode
,
02
_Alter_Mnode
)
{
{
int32_t contLen = sizeof(SD
Create
MnodeReq);
{
int32_t
contLen
=
sizeof
(
SD
Alter
MnodeReq
);
SD
CreateMnodeReq* pReq = (SDCreate
MnodeReq*)rpcMallocCont(contLen);
SD
AlterMnodeReq
*
pReq
=
(
SDAlter
MnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
pReq
->
replica
=
1
;
pReq
->
replicas
[
0
].
id
=
htonl
(
1
);
pReq
->
replicas
[
0
].
port
=
htonl
(
9113
);
strcpy
(
pReq
->
replicas
[
0
].
fqdn
,
"localhost"
);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_ALTER_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ(pRsp->code,
0
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_INVALID_OPTION
);
}
{
int32_t contLen = sizeof(SD
Create
MnodeReq);
int32_t
contLen
=
sizeof
(
SD
Alter
MnodeReq
);
SD
CreateMnodeReq* pReq = (SDCreate
MnodeReq*)rpcMallocCont(contLen);
SD
AlterMnodeReq
*
pReq
=
(
SDAlter
MnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
pReq
->
replica
=
1
;
pReq
->
replicas
[
0
].
id
=
htonl
(
2
);
pReq
->
replicas
[
0
].
port
=
htonl
(
9113
);
strcpy
(
pReq
->
replicas
[
0
].
fqdn
,
"localhost"
);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_
CREATE
_MNODE, pReq, contLen);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_
ALTER
_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_
ALREADY_DEPLOYED
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_
INVALID_OPTION
);
}
test.Restart();
{
int32_t contLen = sizeof(SD
Create
MnodeReq);
int32_t
contLen
=
sizeof
(
SD
Alter
MnodeReq
);
SD
CreateMnodeReq* pReq = (SDCreate
MnodeReq*)rpcMallocCont(contLen);
SD
AlterMnodeReq
*
pReq
=
(
SDAlter
MnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
pReq
->
replica
=
1
;
pReq
->
replicas
[
0
].
id
=
htonl
(
1
);
pReq
->
replicas
[
0
].
port
=
htonl
(
9113
);
strcpy
(
pReq
->
replicas
[
0
].
fqdn
,
"localhost"
);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_
CREATE
_MNODE, pReq, contLen);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_
ALTER
_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ(pRsp->code,
TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
}
}
TEST_F
(
DndTestMnode
,
03
_Drop_Mnode
)
{
{
int32_t
contLen
=
sizeof
(
SDDropMnodeReq
);
...
...
@@ -204,7 +131,7 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_DROP_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_I
D_INVALID
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_I
NVALID_OPTION
);
}
{
...
...
@@ -229,28 +156,34 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
);
}
test.Restart();
{
int32_t contLen = sizeof(SD
Drop
MnodeReq);
int32_t
contLen
=
sizeof
(
SD
Alter
MnodeReq
);
SD
DropMnodeReq* pReq = (SDDrop
MnodeReq*)rpcMallocCont(contLen);
SD
AlterMnodeReq
*
pReq
=
(
SDAlter
MnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
pReq
->
replica
=
1
;
pReq
->
replicas
[
0
].
id
=
htonl
(
1
);
pReq
->
replicas
[
0
].
port
=
htonl
(
9113
);
strcpy
(
pReq
->
replicas
[
0
].
fqdn
,
"localhost"
);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_
DROP
_MNODE, pReq, contLen);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_
ALTER
_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
);
}
{
int32_t
contLen
=
sizeof
(
SDCreateMnodeReq
);
SDCreateMnodeReq
*
pReq
=
(
SDCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
pReq
->
replica
=
2
;
pReq
->
replicas
[
0
].
id
=
htonl
(
1
);
pReq
->
replicas
[
0
].
port
=
htonl
(
9113
);
strcpy
(
pReq
->
replicas
[
0
].
fqdn
,
"localhost"
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_DND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
}
}
#endif
\ No newline at end of file
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
e0946761
...
...
@@ -27,14 +27,14 @@ static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj);
static
SSdbRow
*
mndMnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndMnodeActionInsert
(
SSdb
*
pSdb
,
SMnodeObj
*
pObj
);
static
int32_t
mndMnodeActionDelete
(
SSdb
*
pSdb
,
SMnodeObj
*
pObj
);
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
pOld
Mnode
,
SMnodeObj
*
pNewMnode
);
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
p
Msg
);
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
p
Msg
);
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
p
Msg
);
static
int32_t
mndProcessAlterMnodeRsp
(
SMnodeMsg
*
p
Msg
);
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
p
Msg
);
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
p
Msg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
p
Msg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
pOld
,
SMnodeObj
*
pNew
);
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
p
Req
);
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
p
Req
);
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
p
Rsp
);
static
int32_t
mndProcessAlterMnodeRsp
(
SMnodeMsg
*
p
Rsp
);
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
p
Rsp
);
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
p
Req
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
p
Req
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextMnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitMnode
(
SMnode
*
pMnode
)
{
...
...
@@ -65,7 +65,7 @@ void mndCleanupMnode(SMnode *pMnode) {}
static
SMnodeObj
*
mndAcquireMnode
(
SMnode
*
pMnode
,
int32_t
mnodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SMnodeObj
*
pObj
=
sdbAcquire
(
pSdb
,
SDB_MNODE
,
&
mnodeId
);
if
(
pObj
==
NULL
)
{
if
(
pObj
==
NULL
&&
terrno
==
TSDB_CODE_SDB_OBJ_NOT_THERE
)
{
terrno
=
TSDB_CODE_MND_MNODE_NOT_EXIST
;
}
return
pObj
;
...
...
@@ -207,9 +207,9 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
return
0
;
}
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
pOld
Mnode
,
SMnodeObj
*
pNewMnode
)
{
mTrace
(
"mnode:%d, perform update action, old_row:%p new_row:%p"
,
pOld
Mnode
->
id
,
pOldMnode
,
pNewMnode
);
pOld
Mnode
->
updateTime
=
pNewMnode
->
updateTime
;
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
pOld
,
SMnodeObj
*
pNew
)
{
mTrace
(
"mnode:%d, perform update action, old_row:%p new_row:%p"
,
pOld
->
id
,
pOld
,
pNew
);
pOld
->
updateTime
=
pNew
->
updateTime
;
return
0
;
}
...
...
@@ -277,13 +277,13 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
SDCreateMnodeReq
create
Msg
=
{
0
};
SDCreateMnodeReq
create
Req
=
{
0
};
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
if
(
pIter
==
NULL
)
break
;
SReplica
*
pReplica
=
&
create
Msg
.
replicas
[
numOfReplicas
];
SReplica
*
pReplica
=
&
create
Req
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pMObj
->
id
);
pReplica
->
port
=
htons
(
pMObj
->
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
...
...
@@ -292,13 +292,13 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
sdbRelease
(
pSdb
,
pMObj
);
}
SReplica
*
pReplica
=
&
create
Msg
.
replicas
[
numOfReplicas
];
SReplica
*
pReplica
=
&
create
Req
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pDnode
->
id
);
pReplica
->
port
=
htons
(
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
numOfReplicas
++
;
create
Msg
.
replica
=
numOfReplicas
;
create
Req
.
replica
=
numOfReplicas
;
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
...
...
@@ -307,22 +307,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
STransAction
action
=
{
0
};
SDAlterMnodeReq
*
p
Msg
=
malloc
(
sizeof
(
SDAlterMnodeReq
));
if
(
p
Msg
==
NULL
)
{
SDAlterMnodeReq
*
p
Req
=
malloc
(
sizeof
(
SDAlterMnodeReq
));
if
(
p
Req
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
memcpy
(
p
Msg
,
&
createMsg
,
sizeof
(
SDAlterMnodeReq
));
memcpy
(
p
Req
,
&
createReq
,
sizeof
(
SDAlterMnodeReq
));
p
Msg
->
dnodeId
=
htonl
(
pMObj
->
id
);
p
Req
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
p
Msg
;
action
.
pCont
=
p
Req
;
action
.
contLen
=
sizeof
(
SDAlterMnodeReq
);
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
action
.
acceptableCode
=
TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
p
Msg
);
free
(
p
Req
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
...
...
@@ -335,17 +336,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
SDCreateMnodeReq
*
p
Msg
=
malloc
(
sizeof
(
SDCreateMnodeReq
));
if
(
p
Msg
==
NULL
)
return
-
1
;
memcpy
(
p
Msg
,
&
createMsg
,
sizeof
(
SDAlterMnodeReq
));
p
Msg
->
dnodeId
=
htonl
(
pObj
->
id
);
SDCreateMnodeReq
*
p
Req
=
malloc
(
sizeof
(
SDCreateMnodeReq
));
if
(
p
Req
==
NULL
)
return
-
1
;
memcpy
(
p
Req
,
&
createReq
,
sizeof
(
SDAlterMnodeReq
));
p
Req
->
dnodeId
=
htonl
(
pObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
p
Msg
;
action
.
pCont
=
p
Req
;
action
.
contLen
=
sizeof
(
SDCreateMnodeReq
);
action
.
msgType
=
TDMT_DND_CREATE_MNODE
;
action
.
acceptableCode
=
TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
p
Msg
);
free
(
p
Req
);
return
-
1
;
}
}
...
...
@@ -353,39 +355,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
return
0
;
}
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
SMCreateMnodeReq
*
pCreate
)
{
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pReq
,
SDnodeObj
*
pDnode
,
SMCreateMnodeReq
*
pCreate
)
{
int32_t
code
=
-
1
;
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
pDnode
->
id
;
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"mnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
mDebug
(
"trans:%d, used to create mnode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
CREATE_MNODE_OVER
;
if
(
mndSetCreateMnodeRedoLogs
(
pMnode
,
pTrans
,
&
mnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
if
(
mndSetCreateMnodeCommitLogs
(
pMnode
,
pTrans
,
&
mnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
if
(
mndSetCreateMnodeRedoActions
(
pMnode
,
pTrans
,
pDnode
,
&
mnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
mDebug
(
"trans:%d, used to create mnode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
if
(
mndSetCreateMnodeRedoLogs
(
pMnode
,
pTrans
,
&
mnodeObj
)
!=
0
)
goto
CREATE_MNODE_OVER
;
if
(
mndSetCreateMnodeCommitLogs
(
pMnode
,
pTrans
,
&
mnodeObj
)
!=
0
)
goto
CREATE_MNODE_OVER
;
if
(
mndSetCreateMnodeRedoActions
(
pMnode
,
pTrans
,
pDnode
,
&
mnodeObj
)
!=
0
)
goto
CREATE_MNODE_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_MNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
CREATE_MNODE_OVER
;
code
=
0
;
...
...
@@ -394,9 +380,9 @@ CREATE_MNODE_OVER:
return
code
;
}
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
p
Msg
)
{
SMnode
*
pMnode
=
p
Msg
->
pMnode
;
SMCreateMnodeReq
*
pCreate
=
p
Msg
->
rpcMsg
.
pCont
;
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
p
Req
)
{
SMnode
*
pMnode
=
p
Req
->
pMnode
;
SMCreateMnodeReq
*
pCreate
=
p
Req
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
...
...
@@ -408,6 +394,9 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
mError
(
"mnode:%d, mnode already exist"
,
pObj
->
id
);
terrno
=
TSDB_CODE_MND_MNODE_ALREADY_EXIST
;
return
-
1
;
}
else
if
(
terrno
!=
TSDB_CODE_MND_MNODE_NOT_EXIST
)
{
mError
(
"qnode:%d, failed to create mnode since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
...
...
@@ -417,7 +406,7 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
return
-
1
;
}
int32_t
code
=
mndCreateMnode
(
pMnode
,
p
Msg
,
pDnode
,
pCreate
);
int32_t
code
=
mndCreateMnode
(
pMnode
,
p
Req
,
pDnode
,
pCreate
);
mndReleaseDnode
(
pMnode
,
pDnode
);
if
(
code
!=
0
)
{
...
...
@@ -449,14 +438,14 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
SDAlterMnodeReq
alter
Msg
=
{
0
};
SDAlterMnodeReq
alter
Req
=
{
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
=
&
alter
Msg
.
replicas
[
numOfReplicas
];
SReplica
*
pReplica
=
&
alter
Req
.
replicas
[
numOfReplicas
];
pReplica
->
id
=
htonl
(
pMObj
->
id
);
pReplica
->
port
=
htons
(
pMObj
->
pDnode
->
port
);
memcpy
(
pReplica
->
fqdn
,
pMObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
...
...
@@ -466,7 +455,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
sdbRelease
(
pSdb
,
pMObj
);
}
alter
Msg
.
replica
=
numOfReplicas
;
alter
Req
.
replica
=
numOfReplicas
;
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
...
...
@@ -475,22 +464,23 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
if
(
pMObj
->
id
!=
pObj
->
id
)
{
STransAction
action
=
{
0
};
SDAlterMnodeReq
*
p
Msg
=
malloc
(
sizeof
(
SDAlterMnodeReq
));
if
(
p
Msg
==
NULL
)
{
SDAlterMnodeReq
*
p
Req
=
malloc
(
sizeof
(
SDAlterMnodeReq
));
if
(
p
Req
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
}
memcpy
(
p
Msg
,
&
alterMsg
,
sizeof
(
SDAlterMnodeReq
));
memcpy
(
p
Req
,
&
alterReq
,
sizeof
(
SDAlterMnodeReq
));
p
Msg
->
dnodeId
=
htonl
(
pMObj
->
id
);
p
Req
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
p
Msg
;
action
.
pCont
=
p
Req
;
action
.
contLen
=
sizeof
(
SDAlterMnodeReq
);
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
action
.
acceptableCode
=
TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
p
Msg
);
free
(
p
Req
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
...
...
@@ -504,19 +494,20 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
SDDropMnodeReq
*
p
Msg
=
malloc
(
sizeof
(
SDDropMnodeReq
));
if
(
p
Msg
==
NULL
)
{
SDDropMnodeReq
*
p
Req
=
malloc
(
sizeof
(
SDDropMnodeReq
));
if
(
p
Req
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
p
Msg
->
dnodeId
=
htonl
(
pObj
->
id
);
p
Req
->
dnodeId
=
htonl
(
pObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
p
Msg
;
action
.
pCont
=
p
Req
;
action
.
contLen
=
sizeof
(
SDDropMnodeReq
);
action
.
msgType
=
TDMT_DND_DROP_MNODE
;
action
.
acceptableCode
=
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
p
Msg
);
free
(
p
Req
);
return
-
1
;
}
}
...
...
@@ -524,35 +515,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
return
0
;
}
static
int32_t
mndDropMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
p
Msg
,
SMnodeObj
*
pObj
)
{
static
int32_t
mndDropMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
p
Req
,
SMnodeObj
*
pObj
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"mnode:%d, failed to drop since %s"
,
pObj
->
id
,
terrstr
());
goto
DROP_MNODE_OVER
;
}
mDebug
(
"trans:%d, used to drop mnode:%d"
,
pTrans
->
id
,
pObj
->
id
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
DROP_MNODE_OVER
;
if
(
mndSetDropMnodeRedoLogs
(
pMnode
,
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_MNODE_OVER
;
}
if
(
mndSetDropMnodeCommitLogs
(
pMnode
,
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_MNODE_OVER
;
}
if
(
mndSetDropMnodeRedoActions
(
pMnode
,
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_MNODE_OVER
;
}
mDebug
(
"trans:%d, used to drop mnode:%d"
,
pTrans
->
id
,
pObj
->
id
);
if
(
mnd
TransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
())
;
goto
DROP_MNODE_OVER
;
}
if
(
mnd
SetDropMnodeRedoLogs
(
pMnode
,
pTrans
,
pObj
)
!=
0
)
goto
DROP_MNODE_OVER
;
if
(
mndSetDropMnodeCommitLogs
(
pMnode
,
pTrans
,
pObj
)
!=
0
)
goto
DROP_MNODE_OVER
;
if
(
mndSetDropMnodeRedoActions
(
pMnode
,
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
goto
DROP_MNODE_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
DROP_MNODE_OVER
;
code
=
0
;
...
...
@@ -561,9 +535,9 @@ DROP_MNODE_OVER:
return
code
;
}
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
p
Msg
)
{
SMnode
*
pMnode
=
p
Msg
->
pMnode
;
SMDropMnodeReq
*
pDrop
=
p
Msg
->
rpcMsg
.
pCont
;
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
p
Req
)
{
SMnode
*
pMnode
=
p
Req
->
pMnode
;
SMDropMnodeReq
*
pDrop
=
p
Req
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"mnode:%d, start to drop"
,
pDrop
->
dnodeId
);
...
...
@@ -577,12 +551,10 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
SMnodeObj
*
pObj
=
mndAcquireMnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pObj
==
NULL
)
{
mError
(
"mnode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropMnode
(
pMnode
,
pMsg
,
pObj
);
int32_t
code
=
mndDropMnode
(
pMnode
,
pReq
,
pObj
);
if
(
code
!=
0
)
{
mError
(
"mnode:%d, failed to drop since %s"
,
pMnode
->
dnodeId
,
terrstr
());
return
-
1
;
...
...
@@ -592,23 +564,23 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
p
Msg
)
{
mndTransProcessRsp
(
p
Msg
);
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
p
Rsp
)
{
mndTransProcessRsp
(
p
Rsp
);
return
0
;
}
static
int32_t
mndProcessAlterMnodeRsp
(
SMnodeMsg
*
p
Msg
)
{
mndTransProcessRsp
(
p
Msg
);
static
int32_t
mndProcessAlterMnodeRsp
(
SMnodeMsg
*
p
Rsp
)
{
mndTransProcessRsp
(
p
Rsp
);
return
0
;
}
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
p
Msg
)
{
mndTransProcessRsp
(
p
Msg
);
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
p
Rsp
)
{
mndTransProcessRsp
(
p
Rsp
);
return
0
;
}
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
p
Msg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
p
Msg
->
pMnode
;
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
p
Req
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
p
Req
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
...
...
@@ -660,8 +632,8 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
return
0
;
}
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
p
Msg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
p
Msg
->
pMnode
;
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
p
Req
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
p
Req
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
...
...
source/dnode/mnode/impl/test/mnode/CMakeLists.txt
浏览文件 @
e0946761
...
...
@@ -5,7 +5,7 @@ target_link_libraries(
PUBLIC sut
)
#
add_test(
#
NAME mnode_test_mnode
#
COMMAND mnode_test_mnode
#
)
add_test
(
NAME mnode_test_mnode
COMMAND mnode_test_mnode
)
source/dnode/mnode/impl/test/mnode/mnode.cpp
浏览文件 @
e0946761
...
...
@@ -18,37 +18,25 @@ class MndTestMnode : public ::testing::Test {
public:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/mnode_test_mnode1"
,
90
31
);
test
.
Init
(
"/tmp/mnode_test_mnode1"
,
90
28
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:90
31
"
;
const
char
*
firstEp
=
"localhost:90
28
"
;
server2
.
Start
(
"/tmp/mnode_test_mnode2"
,
fqdn
,
9032
,
firstEp
);
server3
.
Start
(
"/tmp/mnode_test_mnode3"
,
fqdn
,
9033
,
firstEp
);
server4
.
Start
(
"/tmp/mnode_test_mnode4"
,
fqdn
,
9034
,
firstEp
);
server5
.
Start
(
"/tmp/mnode_test_mnode5"
,
fqdn
,
9035
,
firstEp
);
server2
.
Start
(
"/tmp/mnode_test_mnode2"
,
fqdn
,
9029
,
firstEp
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
server2
.
Stop
();
server3
.
Stop
();
server4
.
Stop
();
server5
.
Stop
();
test
.
Cleanup
();
}
static
Testbase
test
;
static
TestServer
server2
;
static
TestServer
server3
;
static
TestServer
server4
;
static
TestServer
server5
;
};
Testbase
MndTestMnode
::
test
;
TestServer
MndTestMnode
::
server2
;
TestServer
MndTestMnode
::
server3
;
TestServer
MndTestMnode
::
server4
;
TestServer
MndTestMnode
::
server5
;
TEST_F
(
MndTestMnode
,
01
_ShowDnode
)
{
test
.
SendShowMetaReq
(
TSDB_MGMT_TABLE_MNODE
,
""
);
...
...
@@ -64,7 +52,7 @@ TEST_F(MndTestMnode, 01_ShowDnode) {
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:90
31
"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:90
28
"
,
TSDB_EP_LEN
);
CheckBinary
(
"master"
,
12
);
CheckInt64
(
0
);
CheckTimestamp
();
...
...
@@ -103,7 +91,7 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
SCreateDnodeReq
*
pReq
=
(
SCreateDnodeReq
*
)
rpcMallocCont
(
contLen
);
strcpy
(
pReq
->
fqdn
,
"localhost"
);
pReq
->
port
=
htonl
(
90
32
);
pReq
->
port
=
htonl
(
90
29
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_DNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
...
...
@@ -132,8 +120,8 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
CheckInt16
(
1
);
CheckInt16
(
2
);
CheckBinary
(
"localhost:90
31
"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:90
32
"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:90
28
"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:90
29
"
,
TSDB_EP_LEN
);
CheckBinary
(
"master"
,
12
);
CheckBinary
(
"slave"
,
12
);
CheckInt64
(
0
);
...
...
@@ -158,144 +146,145 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:90
31
"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:90
28
"
,
TSDB_EP_LEN
);
CheckBinary
(
"master"
,
12
);
CheckInt64
(
0
);
CheckTimestamp
();
}
{
// drop mnode
int32_t
contLen
=
sizeof
(
SMDropMnodeReq
);
SMDropMnodeReq
*
pReq
=
(
SMDropMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_MND_MNODE_NOT_EXIST
);
}
}
TEST_F
(
MndTestMnode
,
03
_Create_Mnode_Rollback
)
{
{
// send message first, then dnode2 crash, result is returned, and rollback is started
int32_t
contLen
=
sizeof
(
SMCreateMnodeReq
);
SMCreateMnodeReq
*
pReq
=
(
SMCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
server2
.
Stop
();
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_RPC_NETWORK_UNAVAIL
);
}
{
// continue send message, mnode is creating
int32_t
contLen
=
sizeof
(
SMCreateMnodeReq
);
SMCreateMnodeReq
*
pReq
=
(
SMCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_SDB_OBJ_CREATING
);
}
{
// continue send message, mnode is creating
int32_t
contLen
=
sizeof
(
SMDropMnodeReq
);
SMDropMnodeReq
*
pReq
=
(
SMDropMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_SDB_OBJ_CREATING
);
}
{
// server start, wait until the rollback finished
server2
.
DoStart
();
taosMsleep
(
1000
);
int32_t
retry
=
0
;
int32_t
retryMax
=
20
;
for
(
retry
=
0
;
retry
<
retryMax
;
retry
++
)
{
int32_t
contLen
=
sizeof
(
SMCreateMnodeReq
);
SMCreateMnodeReq
*
pReq
=
(
SMCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
if
(
pRsp
->
code
==
TSDB_CODE_MND_MNODE_ALREADY_EXIST
)
break
;
taosMsleep
(
1000
);
}
ASSERT_NE
(
retry
,
retryMax
);
}
}
// {
// int32_t contLen = sizeof(SDropDnodeReq);
// SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
// pReq->dnodeId = htonl(2);
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, 0);
// }
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7);
// test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 1);
// CheckInt16(1);
// CheckBinary("localhost:9031", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckBinary("", 24);
// {
// int32_t contLen = sizeof(SCreateDnodeReq);
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9033");
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, 0);
// }
// {
// int32_t contLen = sizeof(SCreateDnodeReq);
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9034");
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, 0);
// }
// {
// int32_t contLen = sizeof(SCreateDnodeReq);
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9035");
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pRsp->code, 0);
// }
// taosMsleep(1300);
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7);
// test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 4);
// CheckInt16(1);
// CheckInt16(3);
// CheckInt16(4);
// CheckInt16(5);
// CheckBinary("localhost:9031", TSDB_EP_LEN);
// CheckBinary("localhost:9033", TSDB_EP_LEN);
// CheckBinary("localhost:9034", TSDB_EP_LEN);
// CheckBinary("localhost:9035", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// // restart
// uInfo("stop all server");
// test.Restart();
// server2.Restart();
// server3.Restart();
// server4.Restart();
// server5.Restart();
// taosMsleep(1300);
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7);
// test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 4);
// CheckInt16(1);
// CheckInt16(3);
// CheckInt16(4);
// CheckInt16(5);
// CheckBinary("localhost:9031", TSDB_EP_LEN);
// CheckBinary("localhost:9033", TSDB_EP_LEN);
// CheckBinary("localhost:9034", TSDB_EP_LEN);
// CheckBinary("localhost:9035", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// }
TEST_F
(
MndTestMnode
,
04
_Drop_Mnode_Rollback
)
{
{
// send message first, then dnode2 crash, result is returned, and rollback is started
int32_t
contLen
=
sizeof
(
SMDropMnodeReq
);
SMDropMnodeReq
*
pReq
=
(
SMDropMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
server2
.
Stop
();
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_RPC_NETWORK_UNAVAIL
);
}
{
// continue send message, mnode is dropping
int32_t
contLen
=
sizeof
(
SMCreateMnodeReq
);
SMCreateMnodeReq
*
pReq
=
(
SMCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_SDB_OBJ_DROPPING
);
}
{
// continue send message, mnode is dropping
int32_t
contLen
=
sizeof
(
SMDropMnodeReq
);
SMDropMnodeReq
*
pReq
=
(
SMDropMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
TSDB_CODE_SDB_OBJ_DROPPING
);
}
{
// server start, wait until the rollback finished
server2
.
DoStart
();
taosMsleep
(
1000
);
int32_t
retry
=
0
;
int32_t
retryMax
=
20
;
for
(
retry
=
0
;
retry
<
retryMax
;
retry
++
)
{
int32_t
contLen
=
sizeof
(
SMCreateMnodeReq
);
SMCreateMnodeReq
*
pReq
=
(
SMCreateMnodeReq
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
if
(
pRsp
->
code
==
0
)
break
;
taosMsleep
(
1000
);
}
ASSERT_NE
(
retry
,
retryMax
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录