diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 7dd3e168ce892d243a555dbb9a5bc2d5bbc66a2f..845ea8bf9a14b5492ce1233f1aa74fd8cfce1d47 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -306,14 +306,16 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { } dndReleaseQnode(pDnode, pQnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index 567c7dcdb09c4ab81e50151c26fb627507706c28..7f234629cb1f80e4c9d5d258def74b3da1134ae4 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -300,14 +300,16 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { } dndReleaseSnode(pDnode, pSnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index 6e6015b5f41d30fbeb0c61fcd98f63eeb608998c..da043f8fe264e2d6cf877bafa716cc205cca141c 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,6 +1,8 @@ enable_testing() add_subdirectory(qnode) +add_subdirectory(bnode) +add_subdirectory(snode) # add_subdirectory(auth) # add_subdirectory(balance) diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..22edc9b257f961e84debcfef3eebb21cfe3d07aa --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. BQTEST_SRC) +add_executable(dnode_test_bnode ${BQTEST_SRC}) +target_link_libraries( + dnode_test_bnode + PUBLIC sut +) + +add_test( + NAME dnode_test_bnode + COMMAND dnode_test_bnode +) diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp deleted file mode 100644 index 7777d60550c58c526efc7944d2ca130458653b31..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file dnode.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "sut.h" - -class DndTestBnode : public ::testing::Test { - public: - void SetUp() override {} - void TearDown() override {} - - public: - static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_bnode1", 9068); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9068"; - - server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); - taosMsleep(300); - } - - static void TearDownTestSuite() { - server2.Stop(); - test.Cleanup(); - } - - static Testbase test; - static TestServer server2; -}; - -Testbase DndTestBnode::test; -TestServer DndTestBnode::server2; - -TEST_F(DndTestBnode, 01_ShowBnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(1); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} - -TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); - } -} - -TEST_F(DndTestBnode, 04_Create_Bnode) { - { - // create dnode - int32_t contLen = sizeof(SCreateDnodeMsg); - - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9069); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - } - - { - // create bnode - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckBinary("localhost:9069", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); - } - - { - // drop bnode - int32_t contLen = sizeof(SMDropBnodeReq); - - SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/bnode/dbnode.cpp b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd8c13c4bdc70d8e8ef265069979c792243ebd80 --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dbnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestBnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestBnode::test; + +TEST_F(DndTestBnode, 01_Create_Bnode) { + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestBnode, 01_Drop_Bnode) { + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index 7c8b502a58c0e762c9cd7b4927f28134475710c6..48de6e03ebea8b04663d39c24404ed4e4c0e669e 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -25,7 +25,7 @@ class DndTestQnode : public ::testing::Test { Testbase DndTestQnode::test; -TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { +TEST_F(DndTestQnode, 01_Create_Qnode) { { int32_t contLen = sizeof(SDCreateQnodeReq); @@ -71,4 +71,63 @@ TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); } +} + +TEST_F(DndTestQnode, 01_Drop_Qnode) { + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c163d1999a209b21fc138795b84be0fd8b42c09 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. SQTEST_SRC) +add_executable(dnode_test_snode ${SQTEST_SRC}) +target_link_libraries( + dnode_test_snode + PUBLIC sut +) + +add_test( + NAME dnode_test_snode + COMMAND dnode_test_snode +) diff --git a/source/dnode/mgmt/impl/test/snode/dsnode.cpp b/source/dnode/mgmt/impl/test/snode/dsnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ec624b942087d931fd7a9190ae9c1580db3ce17 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/dsnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dsnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module snode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestSnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestSnode::test; + +TEST_F(DndTestSnode, 01_Create_Snode) { + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestSnode, 01_Drop_Snode) { + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 0653a0f5d4500662cf88db675a3fe780c7fe72b3..7c740df06dfe1d1fd1a1f4a8d42df438dbe4fa4d 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -366,14 +366,16 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { return NULL; } - SRpcConnInfo connInfo = {0}; - if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { - taosFreeQitem(pMsg); - terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); - return NULL; + if (pRpcMsg->msgType != TDMT_MND_TRANS) { + SRpcConnInfo connInfo = {0}; + if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { + taosFreeQitem(pMsg); + terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); + return NULL; + } + memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); } - memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); pMsg->pMnode = pMnode; pMsg->rpcMsg = *pRpcMsg; diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index f5dfc3518807c0962277afffac1e8e3bff5256d7..3fdd5315a492c37a8632219800c8a8c7013e97dc 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -50,7 +50,18 @@ TEST_F(MndTestQnode, 01_Show_Qnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 02_Create_Qnode) { + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + { int32_t contLen = sizeof(SMCreateQnodeReq); @@ -63,11 +74,6 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -75,14 +81,12 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } -} -TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeReq); SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); + pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 49317e7038d4c99a2ebbcea787425bafc7745d89..d58ea63c4fe44d000a14fd0d9fe9f9e16945ff37 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -423,6 +423,8 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t } void rpcSendResponse(const SRpcMsg *pRsp) { + if (pRsp->handle == NULL) return; + int msgLen = 0; SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcMsg rpcMsg = *pRsp;