Merge pull request #9680 from taosdata/feature/dnode3
test for create mnode
This commit is contained in:
commit
e094676110
|
@ -502,7 +502,7 @@ int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
if (pMnode != NULL) {
|
if (pMnode == NULL) {
|
||||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||||
dError("failed to drop mnode since %s", terrstr());
|
dError("failed to drop mnode since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -13,20 +13,10 @@
|
||||||
|
|
||||||
class DndTestMnode : public ::testing::Test {
|
class DndTestMnode : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static void SetUpTestSuite() {
|
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_mnode", 9113); }
|
||||||
test.Init("/tmp/dnode_test_mnode", 9113);
|
static void TearDownTestSuite() { test.Cleanup(); }
|
||||||
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 Testbase test;
|
static Testbase test;
|
||||||
static TestServer server2;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
|
@ -34,24 +24,6 @@ class DndTestMnode : public ::testing::Test {
|
||||||
};
|
};
|
||||||
|
|
||||||
Testbase DndTestMnode::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) {
|
TEST_F(DndTestMnode, 01_Create_Mnode) {
|
||||||
{
|
{
|
||||||
|
@ -101,100 +73,55 @@ TEST_F(DndTestMnode, 01_Create_Mnode) {
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
|
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) {
|
TEST_F(DndTestMnode, 02_Alter_Mnode) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||||
|
|
||||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(2);
|
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);
|
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||||
|
|
||||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(1);
|
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_INVALID_OPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||||
|
|
||||||
|
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)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_ALTER_MNODE, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(DndTestMnode, 03_Drop_Mnode) {
|
TEST_F(DndTestMnode, 03_Drop_Mnode) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
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);
|
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -229,28 +156,34 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||||
}
|
}
|
||||||
|
|
||||||
test.Restart();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||||
|
|
||||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(1);
|
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_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||||
|
|
||||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(1);
|
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);
|
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
|
@ -27,14 +27,14 @@ static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj);
|
||||||
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw);
|
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw);
|
||||||
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj);
|
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj);
|
||||||
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj);
|
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj);
|
||||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode);
|
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew);
|
||||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg);
|
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq);
|
||||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg);
|
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq);
|
||||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg);
|
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp);
|
||||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg);
|
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pRsp);
|
||||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg);
|
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pRsp);
|
||||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
static int32_t mndGetMnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
static int32_t mndRetrieveMnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||||
static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
int32_t mndInitMnode(SMnode *pMnode) {
|
int32_t mndInitMnode(SMnode *pMnode) {
|
||||||
|
@ -65,7 +65,7 @@ void mndCleanupMnode(SMnode *pMnode) {}
|
||||||
static SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
static SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SMnodeObj *pObj = sdbAcquire(pSdb, SDB_MNODE, &mnodeId);
|
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;
|
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||||
}
|
}
|
||||||
return pObj;
|
return pObj;
|
||||||
|
@ -207,9 +207,9 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) {
|
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew) {
|
||||||
mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOldMnode->id, pOldMnode, pNewMnode);
|
mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||||
pOldMnode->updateTime = pNewMnode->updateTime;
|
pOld->updateTime = pNew->updateTime;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,13 +277,13 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t numOfReplicas = 0;
|
int32_t numOfReplicas = 0;
|
||||||
|
|
||||||
SDCreateMnodeReq createMsg = {0};
|
SDCreateMnodeReq createReq = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
SReplica *pReplica = &createMsg.replicas[numOfReplicas];
|
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||||
pReplica->id = htonl(pMObj->id);
|
pReplica->id = htonl(pMObj->id);
|
||||||
pReplica->port = htons(pMObj->pDnode->port);
|
pReplica->port = htons(pMObj->pDnode->port);
|
||||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
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);
|
sdbRelease(pSdb, pMObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
SReplica *pReplica = &createMsg.replicas[numOfReplicas];
|
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||||
pReplica->id = htonl(pDnode->id);
|
pReplica->id = htonl(pDnode->id);
|
||||||
pReplica->port = htons(pDnode->port);
|
pReplica->port = htons(pDnode->port);
|
||||||
memcpy(pReplica->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(pReplica->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
numOfReplicas++;
|
numOfReplicas++;
|
||||||
|
|
||||||
createMsg.replica = numOfReplicas;
|
createReq.replica = numOfReplicas;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
|
@ -307,22 +307,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
|
||||||
SDAlterMnodeReq *pMsg = malloc(sizeof(SDAlterMnodeReq));
|
SDAlterMnodeReq *pReq = malloc(sizeof(SDAlterMnodeReq));
|
||||||
if (pMsg == NULL) {
|
if (pReq == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeReq));
|
memcpy(pReq, &createReq, sizeof(SDAlterMnodeReq));
|
||||||
|
|
||||||
pMsg->dnodeId = htonl(pMObj->id);
|
pReq->dnodeId = htonl(pMObj->id);
|
||||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SDAlterMnodeReq);
|
action.contLen = sizeof(SDAlterMnodeReq);
|
||||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||||
|
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pReq);
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -335,17 +336,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
|
||||||
SDCreateMnodeReq *pMsg = malloc(sizeof(SDCreateMnodeReq));
|
SDCreateMnodeReq *pReq = malloc(sizeof(SDCreateMnodeReq));
|
||||||
if (pMsg == NULL) return -1;
|
if (pReq == NULL) return -1;
|
||||||
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeReq));
|
memcpy(pReq, &createReq, sizeof(SDAlterMnodeReq));
|
||||||
pMsg->dnodeId = htonl(pObj->id);
|
pReq->dnodeId = htonl(pObj->id);
|
||||||
|
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SDCreateMnodeReq);
|
action.contLen = sizeof(SDCreateMnodeReq);
|
||||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||||
|
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pReq);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,39 +355,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
return 0;
|
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};
|
SMnodeObj mnodeObj = {0};
|
||||||
mnodeObj.id = pDnode->id;
|
mnodeObj.id = pDnode->id;
|
||||||
mnodeObj.createdTime = taosGetTimestampMs();
|
mnodeObj.createdTime = taosGetTimestampMs();
|
||||||
mnodeObj.updateTime = mnodeObj.createdTime;
|
mnodeObj.updateTime = mnodeObj.createdTime;
|
||||||
|
|
||||||
int32_t code = -1;
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
if (pTrans == NULL) goto CREATE_MNODE_OVER;
|
||||||
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);
|
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 (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_MNODE_OVER;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
|
||||||
goto CREATE_MNODE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
@ -394,9 +380,9 @@ CREATE_MNODE_OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pReq->pMnode;
|
||||||
SMCreateMnodeReq *pCreate = pMsg->rpcMsg.pCont;
|
SMCreateMnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||||
|
|
||||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||||
|
|
||||||
|
@ -408,6 +394,9 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
||||||
mError("mnode:%d, mnode already exist", pObj->id);
|
mError("mnode:%d, mnode already exist", pObj->id);
|
||||||
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
||||||
return -1;
|
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);
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||||
|
@ -417,7 +406,7 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = mndCreateMnode(pMnode, pMsg, pDnode, pCreate);
|
int32_t code = mndCreateMnode(pMnode, pReq, pDnode, pCreate);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
@ -449,14 +438,14 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t numOfReplicas = 0;
|
int32_t numOfReplicas = 0;
|
||||||
|
|
||||||
SDAlterMnodeReq alterMsg = {0};
|
SDAlterMnodeReq alterReq = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
if (pMObj->id != pObj->id) {
|
if (pMObj->id != pObj->id) {
|
||||||
SReplica *pReplica = &alterMsg.replicas[numOfReplicas];
|
SReplica *pReplica = &alterReq.replicas[numOfReplicas];
|
||||||
pReplica->id = htonl(pMObj->id);
|
pReplica->id = htonl(pMObj->id);
|
||||||
pReplica->port = htons(pMObj->pDnode->port);
|
pReplica->port = htons(pMObj->pDnode->port);
|
||||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
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);
|
sdbRelease(pSdb, pMObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
alterMsg.replica = numOfReplicas;
|
alterReq.replica = numOfReplicas;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
|
@ -475,22 +464,23 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
if (pMObj->id != pObj->id) {
|
if (pMObj->id != pObj->id) {
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
|
||||||
SDAlterMnodeReq *pMsg = malloc(sizeof(SDAlterMnodeReq));
|
SDAlterMnodeReq *pReq = malloc(sizeof(SDAlterMnodeReq));
|
||||||
if (pMsg == NULL) {
|
if (pReq == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pMsg, &alterMsg, sizeof(SDAlterMnodeReq));
|
memcpy(pReq, &alterReq, sizeof(SDAlterMnodeReq));
|
||||||
|
|
||||||
pMsg->dnodeId = htonl(pMObj->id);
|
pReq->dnodeId = htonl(pMObj->id);
|
||||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SDAlterMnodeReq);
|
action.contLen = sizeof(SDAlterMnodeReq);
|
||||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||||
|
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pReq);
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -504,19 +494,20 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
|
||||||
SDDropMnodeReq *pMsg = malloc(sizeof(SDDropMnodeReq));
|
SDDropMnodeReq *pReq = malloc(sizeof(SDDropMnodeReq));
|
||||||
if (pMsg == NULL) {
|
if (pReq == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pMsg->dnodeId = htonl(pObj->id);
|
pReq->dnodeId = htonl(pObj->id);
|
||||||
|
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SDDropMnodeReq);
|
action.contLen = sizeof(SDDropMnodeReq);
|
||||||
action.msgType = TDMT_DND_DROP_MNODE;
|
action.msgType = TDMT_DND_DROP_MNODE;
|
||||||
|
action.acceptableCode = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pReq);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,35 +515,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pObj) {
|
static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pReq, SMnodeObj *pObj) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
|
||||||
if (pTrans == NULL) {
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||||
mError("mnode:%d, failed to drop since %s", pObj->id, terrstr());
|
if (pTrans == NULL) goto DROP_MNODE_OVER;
|
||||||
goto DROP_MNODE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||||
|
|
||||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) {
|
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) goto DROP_MNODE_OVER;
|
||||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) goto DROP_MNODE_OVER;
|
||||||
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;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
|
||||||
goto DROP_MNODE_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
@ -561,9 +535,9 @@ DROP_MNODE_OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pReq->pMnode;
|
||||||
SMDropMnodeReq *pDrop = pMsg->rpcMsg.pCont;
|
SMDropMnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||||
|
|
||||||
mDebug("mnode:%d, start to drop", 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);
|
SMnodeObj *pObj = mndAcquireMnode(pMnode, pDrop->dnodeId);
|
||||||
if (pObj == NULL) {
|
if (pObj == NULL) {
|
||||||
mError("mnode:%d, not exist", pDrop->dnodeId);
|
mError("mnode:%d, not exist", pDrop->dnodeId);
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = mndDropMnode(pMnode, pMsg, pObj);
|
int32_t code = mndDropMnode(pMnode, pReq, pObj);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("mnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
mError("mnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -592,23 +564,23 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg) {
|
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp) {
|
||||||
mndTransProcessRsp(pMsg);
|
mndTransProcessRsp(pRsp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg) {
|
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pRsp) {
|
||||||
mndTransProcessRsp(pMsg);
|
mndTransProcessRsp(pRsp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg) {
|
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pRsp) {
|
||||||
mndTransProcessRsp(pMsg);
|
mndTransProcessRsp(pRsp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
static int32_t mndGetMnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pReq->pMnode;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
@ -660,8 +632,8 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
static int32_t mndRetrieveMnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pReq->pMnode;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@ target_link_libraries(
|
||||||
PUBLIC sut
|
PUBLIC sut
|
||||||
)
|
)
|
||||||
|
|
||||||
#add_test(
|
add_test(
|
||||||
# NAME mnode_test_mnode
|
NAME mnode_test_mnode
|
||||||
# COMMAND mnode_test_mnode
|
COMMAND mnode_test_mnode
|
||||||
#)
|
)
|
||||||
|
|
|
@ -18,37 +18,25 @@ class MndTestMnode : public ::testing::Test {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void SetUpTestSuite() {
|
static void SetUpTestSuite() {
|
||||||
test.Init("/tmp/mnode_test_mnode1", 9031);
|
test.Init("/tmp/mnode_test_mnode1", 9028);
|
||||||
const char* fqdn = "localhost";
|
const char* fqdn = "localhost";
|
||||||
const char* firstEp = "localhost:9031";
|
const char* firstEp = "localhost:9028";
|
||||||
|
|
||||||
server2.Start("/tmp/mnode_test_mnode2", fqdn, 9032, firstEp);
|
server2.Start("/tmp/mnode_test_mnode2", fqdn, 9029, 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);
|
|
||||||
taosMsleep(300);
|
taosMsleep(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
static void TearDownTestSuite() {
|
||||||
server2.Stop();
|
server2.Stop();
|
||||||
server3.Stop();
|
|
||||||
server4.Stop();
|
|
||||||
server5.Stop();
|
|
||||||
test.Cleanup();
|
test.Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Testbase test;
|
static Testbase test;
|
||||||
static TestServer server2;
|
static TestServer server2;
|
||||||
static TestServer server3;
|
|
||||||
static TestServer server4;
|
|
||||||
static TestServer server5;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Testbase MndTestMnode::test;
|
Testbase MndTestMnode::test;
|
||||||
TestServer MndTestMnode::server2;
|
TestServer MndTestMnode::server2;
|
||||||
TestServer MndTestMnode::server3;
|
|
||||||
TestServer MndTestMnode::server4;
|
|
||||||
TestServer MndTestMnode::server5;
|
|
||||||
|
|
||||||
TEST_F(MndTestMnode, 01_ShowDnode) {
|
TEST_F(MndTestMnode, 01_ShowDnode) {
|
||||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||||
|
@ -64,7 +52,7 @@ TEST_F(MndTestMnode, 01_ShowDnode) {
|
||||||
EXPECT_EQ(test.GetShowRows(), 1);
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9031", TSDB_EP_LEN);
|
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||||
CheckBinary("master", 12);
|
CheckBinary("master", 12);
|
||||||
CheckInt64(0);
|
CheckInt64(0);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
|
@ -103,7 +91,7 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
|
||||||
|
|
||||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->fqdn, "localhost");
|
strcpy(pReq->fqdn, "localhost");
|
||||||
pReq->port = htonl(9032);
|
pReq->port = htonl(9029);
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -132,8 +120,8 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckInt16(2);
|
CheckInt16(2);
|
||||||
CheckBinary("localhost:9031", TSDB_EP_LEN);
|
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||||
CheckBinary("localhost:9032", TSDB_EP_LEN);
|
CheckBinary("localhost:9029", TSDB_EP_LEN);
|
||||||
CheckBinary("master", 12);
|
CheckBinary("master", 12);
|
||||||
CheckBinary("slave", 12);
|
CheckBinary("slave", 12);
|
||||||
CheckInt64(0);
|
CheckInt64(0);
|
||||||
|
@ -158,144 +146,145 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
|
||||||
EXPECT_EQ(test.GetShowRows(), 1);
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9031", TSDB_EP_LEN);
|
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||||
CheckBinary("master", 12);
|
CheckBinary("master", 12);
|
||||||
CheckInt64(0);
|
CheckInt64(0);
|
||||||
CheckTimestamp();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// int32_t contLen = sizeof(SDropDnodeReq);
|
|
||||||
|
|
||||||
// SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
|
TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
|
||||||
// pReq->dnodeId = htonl(2);
|
{
|
||||||
|
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||||
|
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||||
|
|
||||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||||
// ASSERT_NE(pRsp, nullptr);
|
pReq->dnodeId = htonl(2);
|
||||||
// ASSERT_EQ(pRsp->code, 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
server2.Stop();
|
||||||
// CHECK_META("show dnodes", 7);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
// test.SendShowRetrieveReq();
|
ASSERT_NE(pRsp, nullptr);
|
||||||
// EXPECT_EQ(test.GetShowRows(), 1);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||||
|
}
|
||||||
|
|
||||||
// CheckInt16(1);
|
{
|
||||||
// CheckBinary("localhost:9031", TSDB_EP_LEN);
|
// continue send message, mnode is creating
|
||||||
// CheckInt16(0);
|
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||||
// CheckInt16(1);
|
|
||||||
// CheckBinary("ready", 10);
|
|
||||||
// CheckTimestamp();
|
|
||||||
// CheckBinary("", 24);
|
|
||||||
|
|
||||||
// {
|
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||||
// int32_t contLen = sizeof(SCreateDnodeReq);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
// strcpy(pReq->ep, "localhost:9033");
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||||
|
}
|
||||||
|
|
||||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
{
|
||||||
// ASSERT_NE(pRsp, nullptr);
|
// continue send message, mnode is creating
|
||||||
// ASSERT_EQ(pRsp->code, 0);
|
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||||
// }
|
|
||||||
|
|
||||||
// {
|
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||||
// int32_t contLen = sizeof(SCreateDnodeReq);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||||
// strcpy(pReq->ep, "localhost:9034");
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||||
|
}
|
||||||
|
|
||||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
{
|
||||||
// ASSERT_NE(pRsp, nullptr);
|
// server start, wait until the rollback finished
|
||||||
// ASSERT_EQ(pRsp->code, 0);
|
server2.DoStart();
|
||||||
// }
|
taosMsleep(1000);
|
||||||
|
|
||||||
// {
|
int32_t retry = 0;
|
||||||
// int32_t contLen = sizeof(SCreateDnodeReq);
|
int32_t retryMax = 20;
|
||||||
|
|
||||||
// SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
for (retry = 0; retry < retryMax; retry++) {
|
||||||
// strcpy(pReq->ep, "localhost:9035");
|
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||||
|
|
||||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||||
// ASSERT_NE(pRsp, nullptr);
|
pReq->dnodeId = htonl(2);
|
||||||
// ASSERT_EQ(pRsp->code, 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// taosMsleep(1300);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
ASSERT_NE(pRsp, nullptr);
|
||||||
// CHECK_META("show dnodes", 7);
|
if (pRsp->code == TSDB_CODE_MND_MNODE_ALREADY_EXIST) break;
|
||||||
// test.SendShowRetrieveReq();
|
taosMsleep(1000);
|
||||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
}
|
||||||
|
|
||||||
// CheckInt16(1);
|
ASSERT_NE(retry, retryMax);
|
||||||
// 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
|
TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
|
||||||
// uInfo("stop all server");
|
{
|
||||||
// test.Restart();
|
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||||
// server2.Restart();
|
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||||
// server3.Restart();
|
|
||||||
// server4.Restart();
|
|
||||||
// server5.Restart();
|
|
||||||
|
|
||||||
// taosMsleep(1300);
|
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
pReq->dnodeId = htonl(2);
|
||||||
// CHECK_META("show dnodes", 7);
|
|
||||||
// test.SendShowRetrieveReq();
|
|
||||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
|
||||||
|
|
||||||
// CheckInt16(1);
|
server2.Stop();
|
||||||
// CheckInt16(3);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||||
// CheckInt16(4);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
// CheckInt16(5);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||||
// CheckBinary("localhost:9031", TSDB_EP_LEN);
|
}
|
||||||
// CheckBinary("localhost:9033", TSDB_EP_LEN);
|
|
||||||
// CheckBinary("localhost:9034", TSDB_EP_LEN);
|
{
|
||||||
// CheckBinary("localhost:9035", TSDB_EP_LEN);
|
// continue send message, mnode is dropping
|
||||||
// CheckInt16(0);
|
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||||
// CheckInt16(0);
|
|
||||||
// CheckInt16(0);
|
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||||
// CheckInt16(0);
|
pReq->dnodeId = htonl(2);
|
||||||
// CheckInt16(1);
|
|
||||||
// CheckInt16(1);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
// CheckInt16(1);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
// CheckInt16(1);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||||
// CheckBinary("ready", 10);
|
}
|
||||||
// CheckBinary("ready", 10);
|
|
||||||
// CheckBinary("ready", 10);
|
{
|
||||||
// CheckBinary("ready", 10);
|
// continue send message, mnode is dropping
|
||||||
// CheckTimestamp();
|
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||||
// CheckTimestamp();
|
|
||||||
// CheckTimestamp();
|
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||||
// CheckTimestamp();
|
pReq->dnodeId = htonl(2);
|
||||||
// CheckBinary("", 24);
|
|
||||||
// CheckBinary("", 24);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||||
// CheckBinary("", 24);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
// CheckBinary("", 24);
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue