From 3efe621526c2b94367108a0ff72e6fb128dfbdfc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 17:44:47 +0800 Subject: [PATCH 01/26] integration with wal module --- include/dnode/mnode/sdb/sdb.h | 13 ++++++++-- source/dnode/mnode/impl/CMakeLists.txt | 1 + source/dnode/mnode/impl/inc/mndInt.h | 3 +++ source/dnode/mnode/impl/src/mndSync.c | 34 +++++++++++++++++++++++++- source/dnode/mnode/sdb/inc/sdbInt.h | 1 + source/dnode/mnode/sdb/src/sdb.c | 5 ++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 9373e258be..fa10d46878 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -260,7 +260,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2 * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The number of rows in the table + * @return int32_t The number of rows in the table */ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); @@ -269,10 +269,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The max id of the table + * @return int32_t The max id of the table */ int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type); +/** + * @brief Update the version of sdb + * + * @param pSdb The sdb object. + * @param val The update value of the version. + * @return int32_t The current version of sdb + */ +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val); + SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); void sdbFreeRaw(SSdbRaw *pRaw); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 98c604e520..6768651922 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -8,6 +8,7 @@ target_include_directories( target_link_libraries( mnode PRIVATE sdb + PRIVATE wal PRIVATE transport PRIVATE cjson PRIVATE sync diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 15ff65a8fc..5c8d409d90 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -17,11 +17,13 @@ #define _TD_MND_INT_H_ #include "mndDef.h" + #include "sdb.h" #include "tcache.h" #include "tep.h" #include "tqueue.h" #include "ttime.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -65,6 +67,7 @@ typedef struct { typedef struct { int32_t errCode; sem_t syncSem; + SWal *pWal; SSyncNode *pSyncNode; ESyncState state; } SSyncMgmt; diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 6a2fca836f..d3d4ef33e9 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -20,6 +20,21 @@ int32_t mndInitSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; tsem_init(&pMgmt->syncSem, 0, 0); + char path[PATH_MAX] = {0}; + snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); + SWalCfg cfg = {.vgId = 1, + .fsyncPeriod = 0, + .rollPeriod = -1, + .segSize = -1, + .retentionPeriod = 0, + .retentionSize = 0, + .level = TAOS_WAL_FSYNC}; + pMgmt->pWal = walOpen(path, &cfg); + if (pMgmt->pWal == NULL) { + mError("failed to open wal in %s since %s", path, terrstr()); + return -1; + } + pMgmt->state = TAOS_SYNC_STATE_LEADER; pMgmt->pSyncNode = NULL; return 0; @@ -27,7 +42,11 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - tsem_destroy(&pMgmt->syncSem); + if (pMgmt->pWal != NULL) { + walClose(pMgmt->pWal); + pMgmt->pWal = NULL; + tsem_destroy(&pMgmt->syncSem); + } } static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { @@ -41,6 +60,19 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync } int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + + int64_t ver = sdbUpdateVer(pSdb, 1); + if (walWrite(pWal, ver, 1, pRaw, sdbGetRawTotalSize(pRaw)) < 0) { + sdbUpdateVer(pSdb, -1); + mError("failed to write raw:%p since %s, ver:%" PRId64, pRaw, terrstr(), ver); + return -1; + } + + mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + walFsync(pWal, true); + #if 1 return 0; #else diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 070aa56944..98c822cae8 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -59,6 +59,7 @@ typedef struct SSdb { char *tmpDir; int64_t lastCommitVer; int64_t curVer; + int64_t tableVer[SDB_MAX]; int32_t maxId[SDB_MAX]; EKeyType keyTypes[SDB_MAX]; SHashObj *hashObjs[SDB_MAX]; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 97bc0ecbdb..7df5052d6e 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -159,3 +159,8 @@ static int32_t sdbCreateDir(SSdb *pSdb) { return 0; } + +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { + pSdb->curVer += val; + return val; +} \ No newline at end of file From ab9366215590a2ce5139525e9558bc3ee877df81 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 17:54:54 +0800 Subject: [PATCH 02/26] Move the location of the test cases --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 -- source/dnode/mnode/impl/CMakeLists.txt | 6 +++++- source/dnode/mnode/impl/test/CMakeLists.txt | 4 ++++ source/dnode/{mgmt => mnode}/impl/test/acct/CMakeLists.txt | 0 source/dnode/{mgmt => mnode}/impl/test/acct/acct.cpp | 0 source/dnode/mnode/impl/test/mnodeTests.cpp | 0 source/dnode/{mgmt => mnode}/impl/test/user/CMakeLists.txt | 0 source/dnode/{mgmt => mnode}/impl/test/user/user.cpp | 0 8 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 source/dnode/mnode/impl/test/CMakeLists.txt rename source/dnode/{mgmt => mnode}/impl/test/acct/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/acct/acct.cpp (100%) delete mode 100644 source/dnode/mnode/impl/test/mnodeTests.cpp rename source/dnode/{mgmt => mnode}/impl/test/user/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/user/user.cpp (100%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index b0596bed08..b36cdbd690 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,6 +1,5 @@ enable_testing() -add_subdirectory(acct) # add_subdirectory(auth) # add_subdirectory(balance) add_subdirectory(cluster) @@ -17,7 +16,6 @@ add_subdirectory(stb) # add_subdirectory(sync) # add_subdirectory(telem) # add_subdirectory(trans) -add_subdirectory(user) add_subdirectory(vgroup) add_subdirectory(sut) diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 6768651922..adbef3b55f 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -12,4 +12,8 @@ target_link_libraries( PRIVATE transport PRIVATE cjson PRIVATE sync -) \ No newline at end of file +) + +if(${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt new file mode 100644 index 0000000000..fa7b45f988 --- /dev/null +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -0,0 +1,4 @@ +enable_testing() + +add_subdirectory(acct) +add_subdirectory(user) diff --git a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/acct/CMakeLists.txt rename to source/dnode/mnode/impl/test/acct/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp similarity index 100% rename from source/dnode/mgmt/impl/test/acct/acct.cpp rename to source/dnode/mnode/impl/test/acct/acct.cpp diff --git a/source/dnode/mnode/impl/test/mnodeTests.cpp b/source/dnode/mnode/impl/test/mnodeTests.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/source/dnode/mgmt/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/user/CMakeLists.txt rename to source/dnode/mnode/impl/test/user/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp similarity index 100% rename from source/dnode/mgmt/impl/test/user/user.cpp rename to source/dnode/mnode/impl/test/user/user.cpp From 0e8c226085bc8acb0154a52ff623c586014007f2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 18:19:30 +0800 Subject: [PATCH 03/26] the starting version of wal is 0 --- source/dnode/mnode/impl/test/acct/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/acct/acct.cpp | 4 ++-- source/dnode/mnode/impl/test/user/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/user/user.cpp | 4 ++-- source/dnode/mnode/sdb/src/sdb.c | 4 +++- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt index a06becd127..8c8bf54bc4 100644 --- a/source/dnode/mnode/impl/test/acct/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. ACCT_SRC) -add_executable(dnode_test_acct ${ACCT_SRC}) +add_executable(mnode_test_acct ${ACCT_SRC}) target_link_libraries( - dnode_test_acct + mnode_test_acct PUBLIC sut ) add_test( - NAME dnode_test_acct - COMMAND dnode_test_acct + NAME mnode_test_acct + COMMAND mnode_test_acct ) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index be0ad4ab0f..934a2d96b4 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,7 +1,7 @@ /** * @file acct.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module acct-msg tests + * @brief MNODE module acct-msg tests * @version 0.1 * @date 2021-12-15 * @@ -13,7 +13,7 @@ class DndTestAcct : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; diff --git a/source/dnode/mnode/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt index 5068660eba..c6aeef7221 100644 --- a/source/dnode/mnode/impl/test/user/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/user/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. USER_SRC) -add_executable(dnode_test_user ${USER_SRC}) +add_executable(mnode_test_user ${USER_SRC}) target_link_libraries( - dnode_test_user + mnode_test_user PUBLIC sut ) add_test( - NAME dnode_test_user - COMMAND dnode_test_user + NAME mnode_test_user + COMMAND mnode_test_user ) diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index aa160304c8..00153e778c 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,7 +1,7 @@ /** * @file user.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module user-msg tests + * @brief MNODE module user-msg tests * @version 0.1 * @date 2021-12-15 * @@ -13,7 +13,7 @@ class DndTestUser : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 7df5052d6e..fb6ac7bb37 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -51,6 +51,8 @@ SSdb *sdbInit(SSdbOpt *pOption) { taosInitRWLatch(&pSdb->locks[i]); } + pSdb->curVer = -1; + pSdb->lastCommitVer = -1; pSdb->pMnode = pOption->pMnode; mDebug("sdb init successfully"); return pSdb; @@ -162,5 +164,5 @@ static int32_t sdbCreateDir(SSdb *pSdb) { int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { pSdb->curVer += val; - return val; + return pSdb->curVer; } \ No newline at end of file From 5ac3398f3add7d99a2c5b6f82dc0cb93eee2fdf9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:36:31 +0800 Subject: [PATCH 04/26] Mnode intergate with wal module --- include/dnode/mnode/sdb/sdb.h | 8 ++ include/util/taoserror.h | 1 + source/dnode/mnode/impl/src/mndSync.c | 103 +++++++++++++++++++++++--- source/dnode/mnode/sdb/inc/sdbInt.h | 2 - source/libs/wal/inc/walInt.h | 2 + source/libs/wal/src/walRead.c | 2 + source/util/src/terror.c | 1 + 7 files changed, 106 insertions(+), 13 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index fa10d46878..48c8df5ba0 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -188,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb); */ int32_t sdbReadFile(SSdb *pSdb); +/** + * @brief Write sdb file. + * + * @param pSdb The sdb object. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t sdbWriteFile(SSdb *pSdb); + /** * @brief Parse and write raw data to sdb, then free the pRaw object * diff --git a/include/util/taoserror.h b/include/util/taoserror.h index ae36ac7216..2dcc74213c 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -160,6 +160,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339) #define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A) #define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B) +#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C) // mnode-dnode #define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index d3d4ef33e9..3f5bb77855 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -15,10 +15,10 @@ #define _DEFAULT_SOURCE #include "mndSync.h" +#include "mndTrans.h" -int32_t mndInitSync(SMnode *pMnode) { +static int32_t mndInitWal(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - tsem_init(&pMgmt->syncSem, 0, 0); char path[PATH_MAX] = {0}; snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); @@ -26,12 +26,95 @@ int32_t mndInitSync(SMnode *pMnode) { .fsyncPeriod = 0, .rollPeriod = -1, .segSize = -1, - .retentionPeriod = 0, - .retentionSize = 0, + .retentionPeriod = -1, + .retentionSize = -1, .level = TAOS_WAL_FSYNC}; pMgmt->pWal = walOpen(path, &cfg); - if (pMgmt->pWal == NULL) { - mError("failed to open wal in %s since %s", path, terrstr()); + if (pMgmt->pWal == NULL) return -1; + + return 0; +} + +static void mndCloseWal(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + + if (pMgmt->pWal != NULL) { + walClose(pMgmt->pWal); + pMgmt->pWal = NULL; + } +} + +static int32_t mndRestoreWal(SMnode *pMnode) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + int64_t lastSdbVer = sdbUpdateVer(pSdb, 0); + int32_t code = -1; + + SWalReadHandle *pHandle = walOpenReadHandle(pWal); + if (pHandle == NULL) return -1; + + int64_t start = walGetFirstVer(pWal); + int64_t end = walGetLastVer(pWal); + start = MAX(lastSdbVer, start); + + for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { + if (walReadWithHandle(pHandle, ver) < 0) { + mError("failed to read with wal handle since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + SWalHead *pHead = pHandle->pHead; + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + if (sdbVer + 1 != ver) { + terrno = TSDB_CODE_SDB_INVALID_WAl_VER; + mError("failed to write wal to sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); + goto WAL_RESTORE_OVER; + } + + if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) { + mError("failed to write wal to sdb since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + sdbUpdateVer(pSdb, 1); + } + + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + if (sdbVer != lastSdbVer) { + if (walBeginSnapshot(pWal, sdbVer) < 0) { + goto WAL_RESTORE_OVER; + } + + if (sdbVer != lastSdbVer) { + mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + if (sdbWriteFile(pSdb) != 0) { + goto WAL_RESTORE_OVER; + } + } + + if (walEndSnapshot(pWal) < 0) { + goto WAL_RESTORE_OVER; + } + } + + code = 0; + +WAL_RESTORE_OVER: + walCloseReadHandle(pHandle); + return 0; +} + +int32_t mndInitSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_init(&pMgmt->syncSem, 0, 0); + + if (mndInitWal(pMnode) < 0) { + mError("failed to open wal since %s", terrstr()); + return -1; + } + + if (mndRestoreWal(pMnode) < 0) { + mError("failed to restore wal since %s", terrstr()); return -1; } @@ -42,11 +125,8 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - if (pMgmt->pWal != NULL) { - walClose(pMgmt->pWal); - pMgmt->pWal = NULL; - tsem_destroy(&pMgmt->syncSem); - } + tsem_destroy(&pMgmt->syncSem); + mndCloseWal(pMnode); } static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { @@ -71,6 +151,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { } mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + walCommit(pWal, ver); walFsync(pWal, true); #if 1 diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 98c822cae8..25db988a0c 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -72,8 +72,6 @@ typedef struct SSdb { SdbDecodeFp decodeFps[SDB_MAX]; } SSdb; -int32_t sdbWriteFile(SSdb *pSdb); - const char *sdbTableName(ESdbType type); void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 1579cad7b6..871c95193f 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -20,6 +20,8 @@ #include "tchecksum.h" #include "wal.h" +#include "taoserror.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index c80fb4eed8..b5a30e4397 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -19,8 +19,10 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { SWalReadHandle *pRead = malloc(sizeof(SWalReadHandle)); if (pRead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + pRead->pWal = pWal; pRead->readIdxTfd = -1; pRead->readLogTfd = -1; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9fa5b3198b..e821f1f803 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -170,6 +170,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_STATUS_TYPE, "Invalid status type") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_VER, "Invalid raw data version") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_LEN, "Invalid raw data len") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_CONTENT, "Invalid raw data content") +TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_WAl_VER, "Invalid wal version") // mnode-dnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "Dnode already exists") From 99e53317ce03583c3acbbc056c25276c4bd32d90 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:41:45 +0800 Subject: [PATCH 05/26] minor changes --- source/dnode/mnode/impl/src/mndSync.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 3f5bb77855..7c8a8cdb96 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -37,7 +37,6 @@ static int32_t mndInitWal(SMnode *pMnode) { static void mndCloseWal(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - if (pMgmt->pWal != NULL) { walClose(pMgmt->pWal); pMgmt->pWal = NULL; @@ -59,7 +58,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { - mError("failed to read with wal handle since %s, ver:%" PRId64, terrstr(), ver); + mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; } @@ -67,12 +66,12 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t sdbVer = sdbUpdateVer(pSdb, 0); if (sdbVer + 1 != ver) { terrno = TSDB_CODE_SDB_INVALID_WAl_VER; - mError("failed to write wal to sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); + mError("failed to read wal from sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); goto WAL_RESTORE_OVER; } if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) { - mError("failed to write wal to sdb since %s, ver:%" PRId64, terrstr(), ver); + mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; } @@ -85,11 +84,9 @@ static int32_t mndRestoreWal(SMnode *pMnode) { goto WAL_RESTORE_OVER; } - if (sdbVer != lastSdbVer) { - mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); - if (sdbWriteFile(pSdb) != 0) { - goto WAL_RESTORE_OVER; - } + mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + if (sdbWriteFile(pSdb) != 0) { + goto WAL_RESTORE_OVER; } if (walEndSnapshot(pWal) < 0) { @@ -101,7 +98,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { WAL_RESTORE_OVER: walCloseReadHandle(pHandle); - return 0; + return code; } int32_t mndInitSync(SMnode *pMnode) { From efb3d812b183e7831717045ad158a036cd4b2f68 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 11:23:54 +0800 Subject: [PATCH 06/26] add commit version to sdb --- include/dnode/mnode/sdb/sdb.h | 37 ++++---- source/dnode/mnode/sdb/inc/sdbInt.h | 5 +- source/dnode/mnode/sdb/src/sdb.c | 11 ++- source/dnode/mnode/sdb/src/sdbFile.c | 128 +++++++++++++++++++++++++-- source/dnode/mnode/sdb/src/sdbHash.c | 37 ++++---- 5 files changed, 171 insertions(+), 47 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 48c8df5ba0..497da71c13 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -102,25 +102,24 @@ typedef enum { } ESdbStatus; typedef enum { - SDB_START = 0, - SDB_TRANS = 1, - SDB_CLUSTER = 2, - SDB_MNODE = 3, - SDB_QNODE = 4, - SDB_SNODE = 5, - SDB_BNODE = 6, - SDB_DNODE = 7, - SDB_USER = 8, - SDB_AUTH = 9, - SDB_ACCT = 10, - SDB_CONSUMER = 11, - SDB_CGROUP = 12, - SDB_TOPIC = 13, - SDB_VGROUP = 14, - SDB_STB = 15, - SDB_DB = 16, - SDB_FUNC = 17, - SDB_MAX = 18 + SDB_TRANS = 0, + SDB_CLUSTER = 1, + SDB_MNODE = 2, + SDB_QNODE = 3, + SDB_SNODE = 4, + SDB_BNODE = 5, + SDB_DNODE = 6, + SDB_USER = 7, + SDB_AUTH = 8, + SDB_ACCT = 9, + SDB_CONSUMER = 10, + SDB_CGROUP = 11, + SDB_TOPIC = 12, + SDB_VGROUP = 13, + SDB_STB = 14, + SDB_DB = 15, + SDB_FUNC = 16, + SDB_MAX = 17 } ESdbType; typedef struct SSdb SSdb; diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 25db988a0c..c99dff57e1 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -17,11 +17,12 @@ #define _TD_SDB_INT_H_ #include "os.h" + #include "sdb.h" -#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" +#include "tmsg.h" #ifdef __cplusplus extern "C" { @@ -60,7 +61,7 @@ typedef struct SSdb { int64_t lastCommitVer; int64_t curVer; int64_t tableVer[SDB_MAX]; - int32_t maxId[SDB_MAX]; + int64_t maxId[SDB_MAX]; EKeyType keyTypes[SDB_MAX]; SHashObj *hashObjs[SDB_MAX]; SRWLatch locks[SDB_MAX]; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index fb6ac7bb37..0671434218 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -49,6 +49,9 @@ SSdb *sdbInit(SSdbOpt *pOption) { for (ESdbType i = 0; i < SDB_MAX; ++i) { taosInitRWLatch(&pSdb->locks[i]); + pSdb->maxId[i] = 0; + pSdb->tableVer[i] = -1; + pSdb->keyTypes[i] = SDB_KEY_INT32; } pSdb->curVer = -1; @@ -61,10 +64,10 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - // if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); - sdbWriteFile(pSdb); - // } + if (pSdb->curVer != pSdb->lastCommitVer) { + mDebug("write sdb file for curVer:% " PRId64 " and lastCommitVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + sdbWriteFile(pSdb); + } if (pSdb->currDir != NULL) { tfree(pSdb->currDir); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 5a03b3409e..c5306478f2 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -17,10 +17,13 @@ #include "sdbInt.h" #include "tchecksum.h" +#define SDB_TABLE_SIZE 24 +#define SDB_RESERVE_SIZE 512 + static int32_t sdbRunDeployFp(SSdb *pSdb) { mDebug("start to deploy sdb"); - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbDeployFp fp = pSdb->deployFps[i]; if (fp == NULL) continue; @@ -34,6 +37,100 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) { return 0; } +static int32_t sdbReadFileHead(SSdb *pSdb, FileFd fd) { + int32_t ret = taosReadFile(fd, &pSdb->curVer, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + ret = taosReadFile(fd, &maxId, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->maxId[i] = maxId; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + ret = taosReadFile(fd, &ver, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->tableVer[i] = ver; + } + } + + char reserve[SDB_RESERVE_SIZE] = {0}; + ret = taosWriteFile(fd, reserve, sizeof(reserve)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(reserve)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + return 0; +} + +static int32_t sdbWriteFileHead(SSdb *pSdb, FileFd fd) { + if (taosWriteFile(fd, &pSdb->curVer, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + if (i < SDB_MAX) { + maxId = pSdb->maxId[i]; + } + if (taosWriteFile(fd, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + if (i < SDB_MAX) { + ver = pSdb->tableVer[i]; + } + if (taosWriteFile(fd, &ver, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + char reserve[512] = {0}; + if (taosWriteFile(fd, reserve, sizeof(reserve)) != sizeof(reserve)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + int32_t sdbReadFile(SSdb *pSdb) { int64_t offset = 0; int32_t code = 0; @@ -43,7 +140,7 @@ int32_t sdbReadFile(SSdb *pSdb) { SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed read file since %s", terrstr()); + mError("failed read file since %s", terrstr()); return -1; } @@ -58,6 +155,14 @@ int32_t sdbReadFile(SSdb *pSdb) { return 0; } + if (sdbReadFileHead(pSdb, fd) != 0) { + mError("failed to read file:%s head since %s", file, terrstr()); + pSdb->curVer = -1; + free(pRaw); + taosCloseFile(fd); + return -1; + } + while (1) { readLen = sizeof(SSdbRaw); ret = taosReadFile(fd, pRaw, readLen); @@ -104,6 +209,8 @@ int32_t sdbReadFile(SSdb *pSdb) { } code = 0; + pSdb->lastCommitVer = pSdb->curVer; + mError("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); PARSE_SDB_DATA_ERROR: taosCloseFile(fd); @@ -130,11 +237,17 @@ int32_t sdbWriteFile(SSdb *pSdb) { return -1; } - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + if (sdbWriteFileHead(pSdb, fd) != 0) { + mError("failed to write file:%s head since %s", tmpfile, terrstr()); + taosCloseFile(fd); + return -1; + } + + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; - mTrace("sdb write %s, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); + mTrace("write %s to file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); SHashObj *hash = pSdb->hashObjs[i]; SRWLatch *pLock = &pSdb->locks[i]; @@ -155,7 +268,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { pRaw->status = pRow->status; int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen; if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -163,7 +276,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -201,7 +314,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { if (code != 0) { mError("failed to write file:%s since %s", curfile, tstrerror(code)); } else { - mDebug("write file:%s successfully", curfile); + pSdb->lastCommitVer = pSdb->curVer; + mDebug("write file:%s successfully, ver:%" PRId64, curfile, pSdb->lastCommitVer); } terrno = code; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 597484dad1..4b11ec3e76 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -38,6 +38,10 @@ const char *sdbTableName(ESdbType type) { return "auth"; case SDB_ACCT: return "acct"; + case SDB_CONSUMER: + return "consumer"; + case SDB_CGROUP: + return "cgroup"; case SDB_TOPIC: return "topic"; case SDB_VGROUP: @@ -70,7 +74,7 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { } static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { - if (type >= SDB_MAX || type <= SDB_START) { + if (type >= SDB_MAX || type < 0) { terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE; return NULL; } @@ -100,8 +104,6 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) { } static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -126,10 +128,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosWUnLockLatch(pLock); - if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { - pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); - } - + int32_t code = 0; SdbInsertFp insertFp = pSdb->insertFps[pRow->type]; if (insertFp != NULL) { code = (*insertFp)(pSdb, pRow->pObj); @@ -143,12 +142,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * } } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT64) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + pSdb->tableVer[pRow->type]++; + return 0; } static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pNewRow->type]; taosRLockLatch(pLock); @@ -157,23 +162,24 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosRUnLockLatch(pLock); return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize); } - SSdbRow *pOldRow = *ppOldRow; + SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; taosRUnLockLatch(pLock); + int32_t code = 0; SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type]; if (updateFp != NULL) { code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj); } sdbFreeRow(pSdb, pNewRow); + + pSdb->tableVer[pOldRow->type]++; return code; } static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -190,9 +196,10 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); - // sdbRelease(pSdb, pOldRow->pObj); + pSdb->tableVer[pOldRow->type]++; sdbFreeRow(pSdb, pRow); - return code; + // sdbRelease(pSdb, pOldRow->pObj); + return 0; } int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) { @@ -277,7 +284,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); - if (pRow->type >= SDB_MAX || pRow->type <= SDB_START) return; + if (pRow->type >= SDB_MAX ) return; SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); From 81e7ff450e73b5635ee49f1448dd25fe3ef70d85 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 13:40:47 +0800 Subject: [PATCH 07/26] minor changes --- source/dnode/mnode/impl/src/mndSync.c | 16 ++++++++-------- source/dnode/mnode/sdb/src/sdbFile.c | 6 +++--- source/libs/wal/src/walWrite.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 7c8a8cdb96..49eaa45156 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -54,7 +54,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t start = walGetFirstVer(pWal); int64_t end = walGetLastVer(pWal); - start = MAX(lastSdbVer, start); + start = MAX(lastSdbVer + 1, start); for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { @@ -79,19 +79,19 @@ static int32_t mndRestoreWal(SMnode *pMnode) { } int64_t sdbVer = sdbUpdateVer(pSdb, 0); - if (sdbVer != lastSdbVer) { - if (walBeginSnapshot(pWal, sdbVer) < 0) { - goto WAL_RESTORE_OVER; - } + if (walBeginSnapshot(pWal, sdbVer) < 0) { + goto WAL_RESTORE_OVER; + } + if (sdbVer != lastSdbVer) { mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); if (sdbWriteFile(pSdb) != 0) { goto WAL_RESTORE_OVER; } + } - if (walEndSnapshot(pWal) < 0) { - goto WAL_RESTORE_OVER; - } + if (walEndSnapshot(pWal) < 0) { + goto WAL_RESTORE_OVER; } code = 0; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index c5306478f2..cc36b8ec13 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -81,7 +81,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, FileFd fd) { } char reserve[SDB_RESERVE_SIZE] = {0}; - ret = taosWriteFile(fd, reserve, sizeof(reserve)); + ret = taosReadFile(fd, reserve, sizeof(reserve)); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -122,7 +122,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, FileFd fd) { } } - char reserve[512] = {0}; + char reserve[SDB_RESERVE_SIZE] = {0}; if (taosWriteFile(fd, reserve, sizeof(reserve)) != sizeof(reserve)) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -210,7 +210,7 @@ int32_t sdbReadFile(SSdb *pSdb) { code = 0; pSdb->lastCommitVer = pSdb->curVer; - mError("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); + mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); PARSE_SDB_DATA_ERROR: taosCloseFile(fd); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index c8ffd9d07d..05750d6446 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -148,7 +148,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { int32_t walEndSnapshot(SWal *pWal) { int64_t ver = pWal->vers.verInSnapshotting; - if (ver == -1) return -1; + if (ver == -1) return 0; pWal->vers.snapshotVer = ver; int ts = taosGetTimestampSec(); From 1826b3035f1adb64f722da7f9530cbbd9edf225f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:55:10 -0800 Subject: [PATCH 08/26] minor changes --- tests/script/general/table/basic1.sim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/script/general/table/basic1.sim b/tests/script/general/table/basic1.sim index f2341a84ce..298f663822 100644 --- a/tests/script/general/table/basic1.sim +++ b/tests/script/general/table/basic1.sim @@ -46,7 +46,6 @@ print =============== create child table sql create table c1 using st tags(1) sql create table c2 using st tags(2) -return sql show tables if $rows != 2 then return -1 @@ -56,6 +55,8 @@ print $data00 $data01 $data02 print $data10 $data11 $data22 print $data20 $data11 $data22 +return + print =============== insert data sql insert into c1 values(now+1s, 1) sql insert into c1 values(now+2s, 2) From 4079bd2b5536d117b585b72e59ecb88d75566e67 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:14:12 +0800 Subject: [PATCH 09/26] refactor code --- source/libs/index/src/index.c | 21 +++---- source/libs/index/src/index_cache.c | 2 +- .../index/src/index_fst_counting_writer.c | 4 +- source/libs/index/src/index_tfile.c | 56 ++++++++++--------- source/libs/index/test/indexTests.cc | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0657c68458..691e564c68 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,16 +74,15 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); if (sIdx->tindex == NULL) { goto END; } + sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; - sIdx->path = calloc(1, strlen(path) + 1); - memcpy(sIdx->path, path, strlen(path)); + sIdx->path = tstrdup(path); pthread_mutex_init(&sIdx->mtx, NULL); - *index = sIdx; - return 0; #endif + END: if (sIdx != NULL) { indexClose(sIdx); } @@ -310,18 +309,14 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // Get col info IndexCache* cache = NULL; - pthread_mutex_lock(&sIdx->mtx); char buf[128] = {0}; ICacheKey key = {.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); + pthread_mutex_lock(&sIdx->mtx); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); - if (pCache == NULL) { - pthread_mutex_unlock(&sIdx->mtx); - return -1; - } - cache = *pCache; + cache = (pCache == NULL) ? NULL : *pCache; pthread_mutex_unlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); @@ -329,7 +324,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result STermValueType s = kTypeValue; if (0 == indexCacheSearch(cache, query, *result, &s)) { if (s == kTypeDeletion) { - indexInfo("col: %s already drop by other opera", term->colName); + indexInfo("col: %s already drop by", term->colName); // coloum already drop by other oper, no need to query tindex return 0; } else { @@ -504,17 +499,15 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); + if (reader == NULL) { goto END; } - char buf[128] = {0}; TFileHeader* header = &reader->header; ICacheKey key = { .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; pthread_mutex_lock(&sIdx->mtx); - IndexTFile* ifile = (IndexTFile*)sIdx->tindex; tfileCachePut(ifile->cache, &key, reader); - pthread_mutex_unlock(&sIdx->mtx); return ret; END: diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index e95de9286e..a4993257b3 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -261,7 +261,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { return -1; } + if (cache == NULL) { return 0; } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 0f29da1c27..c3e1aab381 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -18,7 +18,7 @@ #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { - if (ctx->offset + len > ctx->limit) { return -1; } + // if (ctx->offset + len > ctx->limit) { return -1; } if (ctx->type == TFile) { assert(len == tfWrite(ctx->file.fd, buf, len)); @@ -111,8 +111,8 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { free(ctx->mem.buf); } else { + // ctx->flush(ctx); tfClose(ctx->file.fd); - ctx->flush(ctx); if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index d4d13ddf19..b32226775d 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -67,29 +67,18 @@ TFileCache* tfileCacheCreate(const char* path) { for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - // refactor later, use colname and version info - char colName[256] = {0}; - if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { - indexInfo("try parse invalid file: %s, skip it", file); - continue; - } - - char fullName[256] = {0}; - sprintf(fullName, "%s/%s", path, file); - - WriterCtx* wc = writerCtxCreate(TFile, fullName, true, 1024 * 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); if (wc == NULL) { indexError("failed to open index:%s", file); goto End; } - char buf[128] = {0}; TFileReader* reader = tfileReaderCreate(wc); + if (reader == NULL) { goto End; } TFileHeader* header = &reader->header; - ICacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; + + char buf[128] = {0}; + ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); assert(sz < sizeof(buf)); @@ -256,7 +245,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // sort by coltype and write to tindex if (order == false) { __compar_fn_t fn; - int8_t colType = tw->header.colType; + + int8_t colType = tw->header.colType; if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { fn = tfileStrCompare; } else { @@ -351,10 +341,16 @@ void tfileWriterDestroy(TFileWriter* tw) { } IndexTFile* indexTFileCreate(const char* path) { - IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); - if (tfile == NULL) { return NULL; } + TFileCache* cache = tfileCacheCreate(path); + if (cache == NULL) { return NULL; } - tfile->cache = tfileCacheCreate(path); + IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); + if (tfile == NULL) { + tfileCacheDestroy(cache); + return NULL; + } + + tfile->cache = cache; return tfile; } void indexTFileDestroy(IndexTFile* tfile) { @@ -366,6 +362,7 @@ void indexTFileDestroy(IndexTFile* tfile) { int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; if (tfile == NULL) { return ret; } + IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; @@ -545,7 +542,6 @@ static int tfileReaderLoadHeader(TFileReader* reader) { int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); if (nread == -1) { - // indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { @@ -566,7 +562,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s ", nread, reader->header.fstOffset, ctx->file.buf); + indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); @@ -613,15 +610,20 @@ void tfileReaderUnRef(TFileReader* reader) { static SArray* tfileGetFileList(const char* path) { SArray* files = taosArrayInit(4, sizeof(void*)); + char buf[128] = {0}; + uint64_t suid; + uint32_t version; + DIR* dir = opendir(path); if (NULL == dir) { return NULL; } - struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type && DT_DIR) { continue; } - size_t len = strlen(entry->d_name); - char* buf = calloc(1, len + 1); - memcpy(buf, entry->d_name, len); + char* file = entry->d_name; + if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } + + size_t len = strlen(path) + 1 + strlen(file) + 1; + char* buf = calloc(1, len); + sprintf(buf, "%s/%s", path, file); taosArrayPush(files, &buf); } closedir(dir); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 77b6e02f18..b33b5b7632 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -848,7 +848,7 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 50 * 10000); + index->WriteMultiMillonData("tag2", "Test", 10 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From c94f30e3838106d50423bd8c64eb901ca6675313 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 23:20:29 -0800 Subject: [PATCH 10/26] add some logs --- source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mndShow.c | 2 +- source/dnode/mnode/impl/src/mndSync.c | 16 ++++++++----- source/dnode/mnode/impl/src/mndTrans.c | 14 +++++++---- source/dnode/mnode/impl/src/mnode.c | 28 +++++++++++----------- source/dnode/mnode/sdb/src/sdb.c | 4 ++-- source/dnode/mnode/sdb/src/sdbFile.c | 1 + source/dnode/mnode/sdb/src/sdbHash.c | 32 +++++++++++++++++++++----- 8 files changed, 64 insertions(+), 35 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d110969025..1d78359015 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -354,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) { } if (pStatus->dnodeId == 0) { - mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); + mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { if (pStatus->clusterId != pMnode->clusterId) { if (pDnode != NULL) { diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index c156c87123..125c250614 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -152,7 +152,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { } int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 49eaa45156..19fb89454e 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -52,11 +52,12 @@ static int32_t mndRestoreWal(SMnode *pMnode) { SWalReadHandle *pHandle = walOpenReadHandle(pWal); if (pHandle == NULL) return -1; - int64_t start = walGetFirstVer(pWal); - int64_t end = walGetLastVer(pWal); - start = MAX(lastSdbVer + 1, start); + int64_t first = walGetFirstVer(pWal); + int64_t last = walGetLastVer(pWal); + mDebug("restore sdb wal start, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last); - for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { + first = MAX(lastSdbVer + 1, first); + for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; @@ -76,15 +77,18 @@ static int32_t mndRestoreWal(SMnode *pMnode) { } sdbUpdateVer(pSdb, 1); + mDebug("wal:%" PRId64 ", is restored", ver); } int64_t sdbVer = sdbUpdateVer(pSdb, 0); + mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer); + if (walBeginSnapshot(pWal, sdbVer) < 0) { goto WAL_RESTORE_OVER; } if (sdbVer != lastSdbVer) { - mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer); if (sdbWriteFile(pSdb) != 0) { goto WAL_RESTORE_OVER; } @@ -147,7 +151,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { return -1; } - mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + mTrace("raw:%p, write to wal, ver:%" PRId64, pRaw, ver); walCommit(pWal, ver); walFsync(pWal, true); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 5062048d6d..bf472a504c 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -169,7 +169,7 @@ TRANS_ENCODE_OVER: return NULL; } - mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos); + mTrace("trans:%d, encode to raw:%p, row:%p len:%d", pTrans->id, pRaw, pTrans, dataPos); return pRaw; } @@ -226,6 +226,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -235,6 +236,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -243,6 +245,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < commitLogNum; ++i) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -284,13 +288,13 @@ TRANS_DECODE_OVER: return NULL; } - mTrace("trans:%d, decode from raw:%p, data:%p", pTrans->id, pRaw, pTrans); + mTrace("trans:%d, decode from raw:%p, row:%p", pTrans->id, pRaw, pTrans); return pRow; } static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { pTrans->stage = TRN_STAGE_PREPARE; - mTrace("trans:%d, perform insert action, data:%p", pTrans->id, pTrans); + mTrace("trans:%d, perform insert action, row:%p", pTrans->id, pTrans); return 0; } @@ -303,13 +307,13 @@ static void mndTransDropData(STrans *pTrans) { } static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { - mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); + mTrace("trans:%d, perform delete action, row:%p", pTrans->id, pTrans); mndTransDropData(pTrans); return 0; } static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) { - mTrace("trans:%d, perform update action, data:%p", pOldTrans->id, pOldTrans); + mTrace("trans:%d, perform update action, old_row:%p new_row:%p", pOldTrans->id, pOldTrans, pNewTrans); pOldTrans->stage = pNewTrans->stage; return 0; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 3a55961d4a..abc86a7d35 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -185,7 +185,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { for (int32_t s = pos; s >= 0; s--) { SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, s); - mDebug("step:%s will cleanup", pStep->name); + mDebug("%s will cleanup", pStep->name); if (pStep->cleanupFp != NULL) { (*pStep->cleanupFp)(pMnode); } @@ -204,12 +204,12 @@ static int32_t mndExecSteps(SMnode *pMnode) { if ((*pStep->initFp)(pMnode) != 0) { int32_t code = terrno; - mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); + mError("%s exec failed since %s, start to cleanup", pStep->name, terrstr()); mndCleanupSteps(pMnode, pos); terrno = code; return -1; } else { - mDebug("step:%s is initialized", pStep->name); + mDebug("%s is initialized", pStep->name); } } @@ -357,7 +357,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); return NULL; } @@ -365,7 +365,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { taosFreeQitem(pMsg); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); + 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); @@ -374,12 +374,12 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { pMsg->rpcMsg = *pRpcMsg; pMsg->createdTime = taosGetTimestampSec(); - mTrace("msg:%p, app:%p is created, RPC:%p", pMsg, pRpcMsg->ahandle, pRpcMsg->handle); + mTrace("msg:%p, is created, app:%p RPC:%p user:%s", pMsg, pRpcMsg->ahandle, pRpcMsg->handle, pMsg->user); return pMsg; } void mndCleanupMsg(SMnodeMsg *pMsg) { - mTrace("msg:%p, app:%p is destroyed, RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); + mTrace("msg:%p, is destroyed, app:%p RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); rpcFreeCont(pMsg->rpcMsg.pCont); pMsg->rpcMsg.pCont = NULL; taosFreeQitem(pMsg); @@ -397,37 +397,37 @@ void mndProcessMsg(SMnodeMsg *pMsg) { void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); - mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType)); + mTrace("msg:%p, type:%s will be processed, app:%p", pMsg, TMSG_INFO(msgType), ahandle); if (isReq && !mndIsMaster(pMnode)) { code = TSDB_CODE_APP_NOT_READY; - mDebug("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mDebug("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } if (isReq && pMsg->rpcMsg.pCont == NULL) { code = TSDB_CODE_MND_INVALID_MSG_LEN; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(msgType)]; if (fp == NULL) { code = TSDB_CODE_MSG_NOT_PROCESSED; - mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle); + mError("msg:%p, failed to process since no msg handle, app:%p", pMsg, ahandle); goto PROCESS_RPC_END; } code = (*fp)(pMsg); if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mTrace("msg:%p, app:%p in progressing", pMsg, ahandle); + mTrace("msg:%p, in progress, app:%p", pMsg, ahandle); return; } else if (code != 0) { code = terrno; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } else { - mTrace("msg:%p, app:%p is processed", pMsg, ahandle); + mTrace("msg:%p, is processed, app:%p", pMsg, ahandle); } PROCESS_RPC_END: diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 0671434218..ef5bb6f16f 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -65,7 +65,7 @@ void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastCommitVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + mDebug("write sdb file for current ver:%" PRId64 " != last commit ver:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); sdbWriteFile(pSdb); } @@ -138,7 +138,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { pSdb->maxId[sdbType] = 0; pSdb->hashObjs[sdbType] = hash; taosInitRWLatch(&pSdb->locks[sdbType]); - mDebug("sdb table:%d is initialized", sdbType); + mDebug("sdb table:%s is initialized", sdbTableName(sdbType)); return 0; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index cc36b8ec13..970fdc2061 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -146,6 +146,7 @@ int32_t sdbReadFile(SSdb *pSdb) { char file[PATH_MAX] = {0}; snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); + mDebug("start to read file:%s", file); FileFd fd = taosOpenFileRead(file); if (fd <= 0) { diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 4b11ec3e76..733075757f 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -57,18 +57,35 @@ const char *sdbTableName(ESdbType type) { } } +static const char *sdbStatusStr(ESdbStatus status) { + switch (status) { + case SDB_STATUS_CREATING: + return "creating"; + case SDB_STATUS_UPDATING: + return "updating"; + case SDB_STATUS_DROPPING: + return "dropping"; + case SDB_STATUS_READY: + return "ready"; + case SDB_STATUS_DROPPED: + return "dropped"; + default: + return "undefine"; + } +} + void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { EKeyType keyType = pSdb->keyTypes[pRow->type]; if (keyType == SDB_KEY_BINARY) { - mTrace("%s:%s, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper, - pRow->pObj); + mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, + oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT32) { - mTrace("%s:%d, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper, - pRow->pObj); + mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT64) { - mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, - pRow->refCount, oper, pRow->pObj); + mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else { } } @@ -165,6 +182,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "updateRow"); taosRUnLockLatch(pLock); int32_t code = 0; @@ -193,6 +211,8 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "deleteRow"); + taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); From 1ddd99b6fc5330850bddd4925a8d09c7b0fe5ca0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 07:39:08 +0000 Subject: [PATCH 11/26] fix problem --- source/dnode/vnode/impl/src/vnodeQuery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index cbc4d75e8b..5f850f0112 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -86,7 +86,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (pTbCfg->type == META_SUPER_TABLE) { nTagCols = pTbCfg->stbCfg.nTagCols; pTagSchema = pTbCfg->stbCfg.pTagSchema; - } else if (pTbCfg->type == META_SUPER_TABLE) { + } else if (pTbCfg->type == META_CHILD_TABLE) { nTagCols = pStbCfg->stbCfg.nTagCols; pTagSchema = pStbCfg->stbCfg.pTagSchema; } else { From 4bdac1fdbf987faf2be31ff78620934b35966d00 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:59:54 +0800 Subject: [PATCH 12/26] optimize tfile --- source/libs/index/src/index.c | 2 +- source/libs/index/src/index_cache.c | 2 +- source/libs/index/src/index_tfile.c | 11 ++++++----- source/libs/index/test/indexTests.cc | 12 +++++------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 691e564c68..44d3066589 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -397,7 +397,7 @@ static void indexDestroyTempResult(SArray* result) { } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { if (sIdx == NULL) { return -1; } - indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index a4993257b3..517cb1640d 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,7 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 5 * 10000 +#define MEM_TERM_LIMIT 10 * 10000 // ref index_cache.h:22 //#define CACHE_KEY_LEN(p) \ // (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index b32226775d..753dbe87b1 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -264,7 +264,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - // taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL); + taosArraySort(v->tableId, tfileUidCompare); + taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -545,8 +546,8 @@ static int tfileReaderLoadHeader(TFileReader* reader) { indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { - indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), - errno, reader->ctx->file.fd, reader->ctx->file.buf); + indexInfo("actual Read: %d, to read: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), + reader->ctx->file.fd, reader->ctx->file.buf); } // assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); @@ -562,8 +563,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, - ctx->file.size); + indexInfo("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index b33b5b7632..c3d6e5541f 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -701,7 +701,8 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << std::endl; + std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } int sz = taosArrayGetSize(result); @@ -834,11 +835,8 @@ static void write_and_search(IndexObj* idx) { std::string colName("tag1"), colVal("Hello"); int target = idx->SearchOne("tag1", "Hello"); - std::cout << "search: " << target << std::endl; target = idx->SearchOne("tag2", "Test"); - std::cout << "search: " << target << std::endl; - - idx->PutOne(colName, colVal); + // idx->PutOne(colName, colVal); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { std::string path = "/tmp/cache_and_tfile"; @@ -847,8 +845,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); - index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 10 * 10000); + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From eb9a70975ae47bc227e246300358ffb4db6b88b6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 4 Jan 2022 16:13:46 +0800 Subject: [PATCH 13/26] feature/qnode --- source/libs/qcom/src/querymsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index f24b191db3..507650159f 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -247,8 +247,8 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { pOut->metaNum = 2; if (pMetaMsg->dbFname[0]) { - snprintf(pOut->ctbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); - snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); + snprintf(pOut->ctbFname, sizeof(pOut->ctbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, sizeof(pOut->tbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); } else { memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); From a94487ab34050b800a09be6104059f457087e2a3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 08:29:05 +0000 Subject: [PATCH 14/26] fix invalid read --- source/dnode/vnode/meta/src/metaBDBImpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index b8ad7ab235..ae6693f973 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -382,8 +382,8 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *pSKey // Second key is the first tag void *pTagVal = tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId); - pDbt[1].data = varDataVal(pTagVal); - pDbt[1].size = varDataLen(pTagVal); + pDbt[1].data = pTagVal; + pDbt[1].size = sizeof(int32_t); // Set index key memset(pSKey, 0, sizeof(*pSKey)); From c426ae83836191a36931041fa0b146d30ad1852f Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 03:32:48 -0500 Subject: [PATCH 15/26] TD-12696 bug fix for insert --- source/libs/parser/inc/dataBlockMgt.h | 2 +- source/libs/parser/src/insertParser.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/inc/dataBlockMgt.h b/source/libs/parser/inc/dataBlockMgt.h index 69dad4d9f4..cd84222c65 100644 --- a/source/libs/parser/inc/dataBlockMgt.h +++ b/source/libs/parser/inc/dataBlockMgt.h @@ -126,7 +126,7 @@ static FORCE_INLINE void getMemRowAppendInfo(SSchema *pSchema, uint8_t memRowTyp int32_t idx, int32_t *toffset) { int32_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { - schemaIdx = spd->boundedColumns[idx]; + schemaIdx = spd->boundedColumns[idx] - 1; if (isDataRowT(memRowType)) { *toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart } else { diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index c0ba4f40b4..cde426fb9a 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -425,7 +425,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i]]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From e5155adcacfe766176d2d2c9fd36f6716693d877 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:05:33 -0500 Subject: [PATCH 16/26] TD-12696 bug fix for insert --- source/libs/parser/src/insertParser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index cde426fb9a..c63e854051 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -106,6 +106,7 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { SVgroupInfo vg; CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); + pCxt->pTableMeta->vgId = vg.vgId; // todo remove return TSDB_CODE_SUCCESS; } @@ -425,7 +426,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From b15ea75b996d2705ea7f90a44ed98e212cfeb998 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:16:32 -0500 Subject: [PATCH 17/26] TD-12696 bug fix for insert --- source/client/src/clientImpl.c | 5 ++++- source/client/src/clientMain.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 71fd8462af..a4750309e8 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -203,7 +203,10 @@ int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { - return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); + SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; + int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res); + pRequest->affectedRows = res.numOfRows; + return res.code; } return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e5f3eba5c2..2b875b3eb5 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -262,6 +262,8 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } -int taos_affected_rows(TAOS_RES *res) { return 1; } +int taos_affected_rows(TAOS_RES *res) { + return ((SRequestObj*)res)->affectedRows; +} int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } From dcb0de0b5cf7d86ec0f40ab4b4c4deb6e9db2e93 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 01:17:25 -0800 Subject: [PATCH 18/26] test cases for trans --- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 + source/dnode/mgmt/impl/test/sut/inc/server.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 10 ++- source/dnode/mnode/impl/test/CMakeLists.txt | 1 + source/dnode/mnode/impl/test/acct/acct.cpp | 6 +- .../mnode/impl/test/trans/CMakeLists.txt | 11 +++ source/dnode/mnode/impl/test/trans/trans.cpp | 86 +++++++++++++++++++ source/dnode/mnode/impl/test/user/user.cpp | 8 +- source/dnode/mnode/sdb/src/sdbFile.c | 2 +- 9 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 source/dnode/mnode/impl/test/trans/CMakeLists.txt create mode 100644 source/dnode/mnode/impl/test/trans/trans.cpp diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index 41382fbab5..24278a73f7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -37,6 +37,8 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); + void ServerStop(); + void ServerStart(); SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); private: diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h index aa7b37f221..5f9e4846a7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/server.h +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -21,10 +21,10 @@ class TestServer { bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); void Stop(); void Restart(); + bool DoStart(); private: SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); - bool DoStart(); private: SDnode* pDnode; diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 429d5a6976..e1b6664e9f 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -16,13 +16,13 @@ #include "base.h" void Testbase::InitLog(const char* path) { - dDebugFlag = 207; + dDebugFlag = 0; vDebugFlag = 0; - mDebugFlag = 207; + mDebugFlag = 143; cDebugFlag = 0; jniDebugFlag = 0; tmrDebugFlag = 0; - uDebugFlag = 143; + uDebugFlag = 0; rpcDebugFlag = 0; qDebugFlag = 0; wDebugFlag = 0; @@ -60,6 +60,10 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } +void Testbase::ServerStop() { server.Stop(); } + +void Testbase::ServerStart() { server.DoStart(); } + SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index fa7b45f988..dfac7a76c9 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -2,3 +2,4 @@ enable_testing() add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(trans) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 934a2d96b4..5f105d99f3 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,11 +1,11 @@ /** * @file acct.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module acct-msg tests - * @version 0.1 + * @brief MNODE module acct tests + * @version 1.0 * @date 2021-12-15 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ diff --git a/source/dnode/mnode/impl/test/trans/CMakeLists.txt b/source/dnode/mnode/impl/test/trans/CMakeLists.txt new file mode 100644 index 0000000000..d7c9756794 --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. TRANS_SRC) +add_executable(mnode_test_trans ${TRANS_SRC}) +target_link_libraries( + mnode_test_trans + PUBLIC sut +) + +add_test( + NAME mnode_test_trans + COMMAND mnode_test_trans +) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp new file mode 100644 index 0000000000..1400ad897f --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -0,0 +1,86 @@ +/** + * @file user.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module trans tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "base.h" +#include "os.h" + +class DndTestTrans : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } + static void TearDownTestSuite() { test.Cleanup(); } + static void KillThenRestartServer() { + char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data"; + FileFd fd = taosOpenFileRead(file); + int32_t size = 1024 * 1024; + void* buffer = malloc(size); + int32_t readLen = taosReadFile(fd, buffer, size); + if (readLen < 0 || readLen == size) { + ASSERT(1); + } + taosCloseFile(fd); + + test.ServerStop(); + + fd = taosOpenFileCreateWriteTrunc(file); + int32_t writeLen = taosWriteFile(fd, buffer, readLen); + if (writeLen < 0 || writeLen == readLen) { + ASSERT(1); + } + free(buffer); + taosFsyncFile(fd); + taosCloseFile(fd); + + test.ServerStart(); + } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestTrans::test; + +TEST_F(DndTestTrans, 01_CreateUser_Crash) { + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + KillThenRestartServer(); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("u2", TSDB_USER_LEN); + // CheckBinary("super", 10); + // CheckBinary("normal", 10); + // CheckTimestamp(); + // CheckTimestamp(); + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("root", TSDB_USER_LEN); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ad2e38e0a4..536150ccfd 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,8 +1,8 @@ /** * @file user.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module user-msg tests - * @version 0.1 + * @brief MNODE module user tests + * @version 1.0 * @date 2021-12-15 * * @copyright Copyright (c) 2021 @@ -13,7 +13,7 @@ class DndTestUser : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; @@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) { EXPECT_EQ(test.GetShowRows(), 1); } -TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { +TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserMsg); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 970fdc2061..1f6d6cbda8 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -231,7 +231,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { mDebug("start to write file:%s", curfile); - FileFd fd = taosOpenFileCreateWrite(tmpfile); + FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile); if (fd <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr()); From 5f70d7b241908fc6e4fd9ffda468c955c111d47c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 01:39:48 -0800 Subject: [PATCH 19/26] minor changes --- source/dnode/mnode/impl/test/trans/trans.cpp | 18 +++++++++--------- source/dnode/mnode/sdb/src/sdb.c | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 1400ad897f..1be38b3289 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -1,5 +1,5 @@ /** - * @file user.cpp + * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests * @version 1.0 @@ -75,12 +75,12 @@ TEST_F(DndTestTrans, 01_CreateUser_Crash) { test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 2); - // CheckBinary("root", TSDB_USER_LEN); - // CheckBinary("u2", TSDB_USER_LEN); - // CheckBinary("super", 10); - // CheckBinary("normal", 10); - // CheckTimestamp(); - // CheckTimestamp(); - // CheckBinary("root", TSDB_USER_LEN); - // CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index ef5bb6f16f..39b5bb4d5b 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -64,8 +64,9 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for current ver:%" PRId64 " != last commit ver:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + if (pSdb->curVer > pSdb->lastCommitVer) { + mDebug("write sdb file for current ver:%" PRId64 " larger than last commit ver:%" PRId64, pSdb->curVer, + pSdb->lastCommitVer); sdbWriteFile(pSdb); } From bcad6bb52840f782fd37a6f5fd6adf20c810de00 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 03:44:44 -0800 Subject: [PATCH 20/26] restore from wal --- include/dnode/bnode/bnode.h | 12 ++--- include/dnode/mnode/mnode.h | 14 +++--- include/dnode/qnode/qnode.h | 12 ++--- include/dnode/snode/snode.h | 12 ++--- include/util/taoserror.h | 2 +- source/dnode/bnode/inc/bndInt.h | 6 +-- source/dnode/mgmt/impl/inc/dndDnode.h | 4 +- source/dnode/mgmt/impl/inc/dndTransport.h | 4 +- source/dnode/mgmt/impl/src/dndBnode.c | 6 +-- source/dnode/mgmt/impl/src/dndDnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndMnode.c | 12 +++-- source/dnode/mgmt/impl/src/dndQnode.c | 6 +-- source/dnode/mgmt/impl/src/dndSnode.c | 6 +-- source/dnode/mgmt/impl/src/dndTransport.c | 17 ++++--- source/dnode/mgmt/impl/src/dnode.c | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 15 ++++--- source/dnode/mnode/impl/inc/mndTrans.h | 1 + source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mndSync.c | 2 + source/dnode/mnode/impl/src/mndTrans.c | 25 ++++++----- source/dnode/mnode/impl/src/mnode.c | 47 +++++++++++--------- source/dnode/mnode/impl/test/trans/trans.cpp | 6 +-- source/dnode/qnode/inc/qndInt.h | 6 +-- source/dnode/snode/inc/sndInt.h | 6 +-- source/libs/transport/src/rpcMain.c | 2 +- source/util/src/terror.c | 2 +- 26 files changed, 130 insertions(+), 107 deletions(-) diff --git a/include/dnode/bnode/bnode.h b/include/dnode/bnode/bnode.h index 23cc3ca617..3cc26861ab 100644 --- a/include/dnode/bnode/bnode.h +++ b/include/dnode/bnode/bnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SBnode SBnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SBnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnodeOpt; /* ------------------------ SBnode ------------------------ */ diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index a288e3e630..de4b4e4e89 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -24,9 +24,10 @@ extern "C" { typedef struct SDnode SDnode; typedef struct SMnode SMnode; typedef struct SMnodeMsg SMnodeMsg; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct SMnodeLoad { int64_t numOfDnode; @@ -62,9 +63,10 @@ typedef struct { SReplica replicas[TSDB_MAX_REPLICA]; SMnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + PutReqToMWriteQFp putReqToMWriteQFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SMnodeOpt; /* ------------------------ SMnode ------------------------ */ diff --git a/include/dnode/qnode/qnode.h b/include/dnode/qnode/qnode.h index 8084175a90..554c57a045 100644 --- a/include/dnode/qnode/qnode.h +++ b/include/dnode/qnode/qnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SQnode SQnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfStartTask; @@ -47,9 +47,9 @@ typedef struct { int64_t clusterId; SQnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnodeOpt; /* ------------------------ SQnode ------------------------ */ diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 4913d2572f..43d3dd9b4b 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SSnode SSnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SSnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnodeOpt; /* ------------------------ SSnode ------------------------ */ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 2dcc74213c..0305404937 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -253,7 +253,7 @@ int32_t* taosGetErrno(); // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) -#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401) +#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401) #define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402) #define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410) #define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411) diff --git a/source/dnode/bnode/inc/bndInt.h b/source/dnode/bnode/inc/bndInt.h index d44c520a26..cddb1e50f1 100644 --- a/source/dnode/bnode/inc/bndInt.h +++ b/source/dnode/bnode/inc/bndInt.h @@ -33,9 +33,9 @@ typedef struct SBnode { int32_t dnodeId; int64_t clusterId; SBnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnode; #ifdef __cplusplus diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index a2015913a7..69c2aa1fbf 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); -void dndSendStatusMsg(SDnode *pDnode); +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg); +void dndSendStatusReq(SDnode *pDnode); void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/impl/inc/dndTransport.h b/source/dnode/mgmt/impl/inc/dndTransport.h index 312da69fa2..42fb379fc1 100644 --- a/source/dnode/mgmt/impl/inc/dndTransport.h +++ b/source/dnode/mgmt/impl/inc/dndTransport.h @@ -23,8 +23,8 @@ extern "C" { int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index c12d449517..dfe4eda145 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) { static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 30b069f349..f5f9bbf1b8 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { taosRUnLockLatch(&pMgmt->latch); } -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { tmsg_t msgType = pMsg->msgType; SEpSet epSet = {0}; @@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { return 0; } -void dndSendStatusMsg(SDnode *pDnode) { +void dndSendStatusReq(SDnode *pDnode) { int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); SStatusMsg *pStatus = rpcMallocCont(contLen); @@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) { pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); - dndSendMsgToMnode(pDnode, &rpcMsg); + dndSendReqToMnode(pDnode, &rpcMsg); } static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { @@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) { taosMsleep(ms); if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) { - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); } } } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 577cb0c3b0..a8bf26f133 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -19,6 +19,7 @@ #include "dndTransport.h" #include "dndWorker.h" +static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg); static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg); static SMnode *dndAcquireMnode(SDnode *pDnode) { @@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { return true; } +static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) { + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg); +} + static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; + pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 1f3d6ee371..e73a0cb0d8 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) { static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index ab4ca191a9..070fc8663e 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -179,9 +179,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) { static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index bb16ef0b77..cf0f561609 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; @@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) { dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); - SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING}; + SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_OFFLINE}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); return; @@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) { dInfo("dnode-transport is cleaned up"); } -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { STransMgmt *pMgmt = &pDnode->tmgmt; - if (pMgmt->clientRpc == NULL) return; + if (pMgmt->clientRpc == NULL) { + terrno = TSDB_CODE_DND_OFFLINE; + return -1; + } + rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL); + return 0; } -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) { +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dndSendMsgToDnode(pDnode, &epSet, pMsg); + return dndSendReqToDnode(pDnode, &epSet, pMsg); } diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 88a96dadc4..33cec5ff47 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -213,7 +213,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { } dndSetStat(pDnode, DND_STAT_RUNNING); - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); dndReportStartup(pDnode, "TDengine", "initialized successfully"); dInfo("TDengine is initialized successfully, pDnode:%p", pDnode); diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 5c8d409d90..89fb2e3189 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -91,15 +91,16 @@ typedef struct SMnode { STelemMgmt telemMgmt; SSyncMgmt syncMgmt; MndMsgFp msgFp[TDMT_MAX]; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; + PutReqToMWriteQFp putReqToMWriteQFp; } SMnode; -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); -void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg); +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); uint64_t mndGenerateUid(char *name, int32_t len) ; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 201fcde1a9..bd053d91b6 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -45,6 +45,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); void mndTransProcessRsp(SMnodeMsg *pMsg); +void mndTransPullup(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1d78359015..2cca70b04e 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -557,7 +557,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) { .ahandle = pMsg->rpcMsg.ahandle}; mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config); - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + mndSendReqToDnode(pMnode, &epSet, &rpcMsg); return 0; } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 19fb89454e..bf1697fb19 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -83,6 +83,8 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t sdbVer = sdbUpdateVer(pSdb, 0); mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer); + mndTransPullup(pMnode); + if (walBeginSnapshot(pWal, sdbVer) < 0) { goto WAL_RESTORE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index bf472a504c..ee4a49ffdc 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -52,7 +52,6 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); static void mndTransExecute(SMnode *pMnode, STrans *pTrans); static void mndTransSendRpcRsp(STrans *pTrans); static int32_t mndProcessTransMsg(SMnodeMsg *pMsg); -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg); int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, @@ -64,7 +63,6 @@ int32_t mndInitTrans(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndTransActionDelete}; mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransMsg); - mndSetMsgHandle(pMnode, TDMT_MND_TRANS_RSP, mndProcessTransRsp); return sdbSetTable(pMnode->pSdb, table); } @@ -615,12 +613,15 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr } memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen); - pAction->msgSent = 1; - pAction->msgReceived = 0; - pAction->errCode = 0; - - mDebug("trans:%d, action:%d is sent", pTrans->id, action); - mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg); + if (mndSendReqToDnode(pMnode, &pAction->epSet, &rpcMsg) == 0) { + mDebug("trans:%d, action:%d is sent", pTrans->id, action); + pAction->msgSent = 1; + pAction->msgReceived = 0; + pAction->errCode = 0; + } else { + mDebug("trans:%d, action:%d not sent since %s", pTrans->id, action, terrstr()); + return -1; + } } return 0; @@ -885,7 +886,11 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + mndTransPullup(pMsg->pMnode); + return 0; +} + +void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; void *pIter = NULL; @@ -897,5 +902,3 @@ static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { sdbRelease(pMnode->pSdb, pTrans); } } - -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg) { return 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 abc86a7d35..0653a0f5d4 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -34,21 +34,27 @@ #include "mndUser.h" #include "mndVgroup.h" -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { - (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); } -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) { - (*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToMnodeFp)(pMnode->pDnode, pMsg); } -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) { - (*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendRedirectRspFp != NULL) { + (*pMnode->sendRedirectRspFp)(pMnode->pDnode, pMsg); } } @@ -56,11 +62,8 @@ static void mndTransReExecute(void *param, void *tmrId) { SMnode *pMnode = param; if (mndIsMaster(pMnode)) { STransMsg *pMsg = rpcMallocCont(sizeof(STransMsg)); - SEpSet epSet = {.inUse = 0, .numOfEps = 1}; - epSet.port[0] = pMnode->replicas[pMnode->selfIndex].port; - memcpy(epSet.fqdn[0], pMnode->replicas[pMnode->selfIndex].fqdn, TSDB_FQDN_LEN); - SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; + pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg); } taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer); @@ -76,7 +79,7 @@ static int32_t mndInitTimer(SMnode *pMnode) { return -1; } - if (taosTmrReset(mndTransReExecute, 1000, pMnode, pMnode->timer, &pMnode->transTimer)) { + if (taosTmrReset(mndTransReExecute, 6000, pMnode, pMnode->timer, &pMnode->transTimer)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -223,9 +226,10 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->pDnode = pOption->pDnode; - pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; - pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; - pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; + pMnode->putReqToMWriteQFp = pOption->putReqToMWriteQFp; + pMnode->sendReqToDnodeFp = pOption->sendReqToDnodeFp; + pMnode->sendReqToMnodeFp = pOption->sendReqToMnodeFp; + pMnode->sendRedirectRspFp = pOption->sendRedirectRspFp; pMnode->cfg.sver = pOption->cfg.sver; pMnode->cfg.enableTelem = pOption->cfg.enableTelem; pMnode->cfg.statusInterval = pOption->cfg.statusInterval; @@ -236,8 +240,9 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->cfg.gitinfo = strdup(pOption->cfg.gitinfo); pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo); - if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) { + if (pMnode->sendReqToDnodeFp == NULL || pMnode->sendReqToMnodeFp == NULL || pMnode->sendRedirectRspFp == NULL || + pMnode->putReqToMWriteQFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 || + pMnode->cfg.statusInterval < 1) { terrno = TSDB_CODE_MND_INVALID_OPTIONS; return -1; } @@ -433,7 +438,7 @@ void mndProcessMsg(SMnodeMsg *pMsg) { PROCESS_RPC_END: if (isReq) { if (code == TSDB_CODE_APP_NOT_READY) { - mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); + mndSendRedirectRsp(pMnode, &pMsg->rpcMsg); } else if (code != 0) { SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code}; rpcSendResponse(&rpcRsp); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 1be38b3289..d2bf92ad13 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -2,7 +2,7 @@ * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests - * @version 1.0 + * @version 0.1 * @date 2022-01-04 * * @copyright Copyright (c) 2022 @@ -75,10 +75,10 @@ TEST_F(DndTestTrans, 01_CreateUser_Crash) { test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 2); + CheckBinary("u1", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("super", 10); CheckBinary("normal", 10); + CheckBinary("super", 10); CheckTimestamp(); CheckTimestamp(); CheckBinary("root", TSDB_USER_LEN); diff --git a/source/dnode/qnode/inc/qndInt.h b/source/dnode/qnode/inc/qndInt.h index e9f1229a9d..529c407efa 100644 --- a/source/dnode/qnode/inc/qndInt.h +++ b/source/dnode/qnode/inc/qndInt.h @@ -32,9 +32,9 @@ typedef struct SQnode { int32_t dnodeId; int64_t clusterId; SQnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnode; #ifdef __cplusplus diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 8827c92eef..3b41c7f4b1 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -32,9 +32,9 @@ typedef struct SSnode { int32_t dnodeId; int64_t clusterId; SSnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnode; #ifdef __cplusplus diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 310944e9b6..242bdb1558 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -1195,7 +1195,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead, SRpcReqConte } rpcSendReqToServer(pRpc, pContext); rpcFreeCont(rpcMsg.pCont); - } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_EXITING) { + } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_OFFLINE) { pContext->code = pHead->code; rpcProcessConnError(pContext, NULL); rpcFreeCont(rpcMsg.pCont); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index e821f1f803..0bf56dbaaf 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -253,7 +253,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_EXIST, "Transaction not exis // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_DND_EXITING, "Dnode is exiting") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_OFFLINE, "Dnode is offline") TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, "Invalid message length") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_READ_FILE_ERROR, "Read dnode.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR, "Write dnode.json error") From 821b9ea4d3ff7f173b2514f93249abb2eda59185 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:04:23 -0800 Subject: [PATCH 21/26] minor changes --- include/common/tmsg.h | 6 +- source/dnode/mnode/impl/src/mndAcct.c | 36 ++++++------ source/dnode/mnode/impl/src/mndUser.c | 42 +++++++------- source/dnode/mnode/impl/test/acct/acct.cpp | 12 ++-- source/dnode/mnode/impl/test/trans/trans.cpp | 4 +- source/dnode/mnode/impl/test/user/user.cpp | 60 ++++++++++---------- source/libs/parser/inc/astToMsg.h | 6 +- source/libs/parser/src/astToMsg.c | 16 +++--- src/client/src/tscServer.c | 12 ++-- 9 files changed, 97 insertions(+), 97 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 19897ecb24..ac26e4f074 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -345,18 +345,18 @@ typedef struct { int32_t maxStreams; int32_t accessState; // Configured only by command int64_t maxStorage; // In unit of GB -} SCreateAcctMsg, SAlterAcctMsg; +} SCreateAcctReq, SAlterAcctReq; typedef struct { char user[TSDB_USER_LEN]; -} SDropUserMsg, SDropAcctMsg; +} SDropUserReq, SDropAcctReq; typedef struct { int8_t type; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; int8_t superUser; // denote if it is a super user or not -} SCreateUserMsg, SAlterUserMsg; +} SCreateUserReq, SAlterUserReq; typedef struct { int32_t contLen; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 2847d19bea..0cf940b987 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -25,10 +25,10 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct); static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw); static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct); -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct); -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew); +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg); +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg); int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, @@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndAcctActionUpdate, .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq); return sdbSetTable(pMnode->pSdb, table); } @@ -176,29 +176,29 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; } -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) { - mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOldAcct->acct, pOldAcct, pNewAcct); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) { + mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOld->acct, pOld, pNew); - pOldAcct->updateTime = pNewAcct->updateTime; - pOldAcct->status = pNewAcct->status; - memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctCfg)); + pOld->updateTime = pNew->updateTime; + pOld->status = pNew->status; + memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg)); return 0; } -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 6311d3e8da..3ffb979ed1 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -28,11 +28,11 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser); static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw); static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser); -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser); +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew); static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg); -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg); +static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg); +static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg); static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); @@ -47,9 +47,9 @@ int32_t mndInitUser(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); @@ -192,10 +192,10 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { return 0; } -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) { - mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOldUser->user, pOldUser, pNewUser); - memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN); - pOldUser->updateTime = pNewUser->updateTime; +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) { + mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOld->user, pOld, pNew); + memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN); + pOld->updateTime = pNew->updateTime; return 0; } @@ -247,9 +247,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, return 0; } -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; + SCreateUserReq *pCreate = pMsg->rpcMsg.pCont; mDebug("user:%s, start to create", pCreate->user); @@ -291,15 +291,15 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) { +static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pMsg) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("user:%s, failed to update since %s", pOldUser->user, terrstr()); + mError("user:%s, failed to update since %s", pOld->user, terrstr()); return -1; } - mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user); + mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user); - SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser); + SSdbRaw *pRedoRaw = mndUserActionEncode(pNew); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); @@ -317,9 +317,9 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewU return 0; } -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; + SAlterUserReq *pAlter = pMsg->rpcMsg.pCont; mDebug("user:%s, start to alter", pAlter->user); @@ -394,9 +394,9 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { return 0; } -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SDropUserMsg *pDrop = pMsg->rpcMsg.pCont; + SDropUserReq *pDrop = pMsg->rpcMsg.pCont; mDebug("user:%s, start to drop", pDrop->user); diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 5f105d99f3..f517b26596 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -26,9 +26,9 @@ class DndTestAcct : public ::testing::Test { Testbase DndTestAcct::test; TEST_F(DndTestAcct, 01_CreateAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); + int32_t contLen = sizeof(SCreateAcctReq); - SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); + SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -36,9 +36,9 @@ TEST_F(DndTestAcct, 01_CreateAcct) { } TEST_F(DndTestAcct, 02_AlterAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); + int32_t contLen = sizeof(SCreateAcctReq); - SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); + SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -46,9 +46,9 @@ TEST_F(DndTestAcct, 02_AlterAcct) { } TEST_F(DndTestAcct, 03_DropAcct) { - int32_t contLen = sizeof(SDropAcctMsg); + int32_t contLen = sizeof(SDropAcctReq); - SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); + SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index d2bf92ad13..19bba13345 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -52,9 +52,9 @@ Testbase DndTestTrans::test; TEST_F(DndTestTrans, 01_CreateUser_Crash) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 536150ccfd..5ccb079633 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -45,9 +45,9 @@ TEST_F(DndTestUser, 01_ShowUser) { TEST_F(DndTestUser, 02_Create_User) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); @@ -57,9 +57,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); @@ -69,9 +69,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "root"); strcpy(pReq->pass, "1"); @@ -81,9 +81,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); @@ -101,9 +101,9 @@ TEST_F(DndTestUser, 02_Create_User) { TEST_F(DndTestUser, 03_Alter_User) { { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); @@ -113,9 +113,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); @@ -125,9 +125,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u4"); strcpy(pReq->pass, "1"); @@ -137,9 +137,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "1"); @@ -151,9 +151,9 @@ TEST_F(DndTestUser, 03_Alter_User) { TEST_F(DndTestUser, 04_Drop_User) { { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -162,9 +162,9 @@ TEST_F(DndTestUser, 04_Drop_User) { } { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u4"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -173,9 +173,9 @@ TEST_F(DndTestUser, 04_Drop_User) { } { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -192,9 +192,9 @@ TEST_F(DndTestUser, 04_Drop_User) { TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); @@ -204,9 +204,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); @@ -235,9 +235,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); @@ -266,9 +266,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index ba33767a05..30919d25dd 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -5,9 +5,9 @@ #include "tmsg.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 792c0db266..ab8c9b8094 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -2,8 +2,8 @@ #include "astGenerator.h" #include "parserUtil.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateUserMsg* pMsg = (SCreateUserMsg*)calloc(1, sizeof(SCreateUserMsg)); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateUserReq* pMsg = (SCreateUserReq*)calloc(1, sizeof(SCreateUserReq)); if (pMsg == NULL) { // tscError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -25,8 +25,8 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in return pMsg; } -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateAcctMsg *pCreateMsg = (SCreateAcctMsg *) calloc(1, sizeof(SCreateAcctMsg)); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateAcctReq *pCreateMsg = (SCreateAcctReq *) calloc(1, sizeof(SCreateAcctReq)); if (pCreateMsg == NULL) { qError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -64,24 +64,24 @@ SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in } } - *outputLen = sizeof(SCreateAcctMsg); + *outputLen = sizeof(SCreateAcctReq); return pCreateMsg; } -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); if (pName->n >= TSDB_USER_LEN) { return NULL; } - SDropUserMsg* pMsg = calloc(1, sizeof(SDropUserMsg)); + SDropUserReq* pMsg = calloc(1, sizeof(SDropUserReq)); if (pMsg == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } strncpy(pMsg->user, pName->z, pName->n); - *msgLen = sizeof(SDropUserMsg); + *msgLen = sizeof(SDropUserReq); return pMsg; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 42799927e6..48127147f8 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1210,13 +1210,13 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateAcctMsg); + pCmd->payloadLen = sizeof(SCreateAcctReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateAcctMsg *pAlterMsg = (SCreateAcctMsg *)pCmd->payload; + SCreateAcctReq *pAlterMsg = (SCreateAcctReq *)pCmd->payload; SStrToken *pName = &pInfo->pMiscInfo->user.user; SStrToken *pPwd = &pInfo->pMiscInfo->user.passwd; @@ -1255,14 +1255,14 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateUserMsg); + pCmd->payloadLen = sizeof(SCreateUserReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateUserMsg *pAlterMsg = (SCreateUserMsg *)pCmd->payload; + SCreateUserReq *pAlterMsg = (SCreateUserReq *)pCmd->payload; SUserInfo *pUser = &pInfo->pMiscInfo->user; strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n); @@ -1369,7 +1369,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char user[TSDB_USER_LEN] = {0}; tstrncpy(user, pCmd->payload, TSDB_USER_LEN); - pCmd->payloadLen = sizeof(SDropUserMsg); + pCmd->payloadLen = sizeof(SDropUserReq); pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TDMT_MND_DROP_USER:TDMT_MND_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1377,7 +1377,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SDropUserMsg *pDropMsg = (SDropUserMsg *)pCmd->payload; + SDropUserReq *pDropMsg = (SDropUserReq *)pCmd->payload; tstrncpy(pDropMsg->user, user, tListLen(user)); return TSDB_CODE_SUCCESS; From 0526051edd43778bbd14c34ead72aa0aaa1c65d5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:18:09 -0800 Subject: [PATCH 22/26] minor changes --- source/dnode/mgmt/impl/test/CMakeLists.txt | 3 --- source/dnode/mnode/impl/test/CMakeLists.txt | 6 ++++- source/dnode/mnode/impl/test/acct/acct.cpp | 2 +- .../impl/test/bnode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/bnode/bnode.cpp | 26 +++++++++---------- .../impl/test/qnode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/qnode/qnode.cpp | 26 +++++++++---------- .../impl/test/snode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/snode/snode.cpp | 26 +++++++++---------- source/dnode/mnode/impl/test/trans/trans.cpp | 2 +- source/dnode/mnode/impl/test/user/user.cpp | 4 +-- 11 files changed, 48 insertions(+), 47 deletions(-) rename source/dnode/{mgmt => mnode}/impl/test/bnode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/bnode/bnode.cpp (87%) rename source/dnode/{mgmt => mnode}/impl/test/qnode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/qnode/qnode.cpp (87%) rename source/dnode/{mgmt => mnode}/impl/test/snode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/snode/snode.cpp (87%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index b36cdbd690..1896a605cd 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -7,9 +7,6 @@ add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) add_subdirectory(mnode) -add_subdirectory(qnode) -add_subdirectory(snode) -add_subdirectory(bnode) add_subdirectory(profile) add_subdirectory(show) add_subdirectory(stb) diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index dfac7a76c9..075ff38bc6 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -1,5 +1,9 @@ enable_testing() -add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(acct) add_subdirectory(trans) +add_subdirectory(qnode) +add_subdirectory(snode) +add_subdirectory(bnode) + diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index f517b26596..5a7df55c4c 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -3,7 +3,7 @@ * @author slguan (slguan@taosdata.com) * @brief MNODE module acct tests * @version 1.0 - * @date 2021-12-15 + * @date 2022-01-04 * * @copyright Copyright (c) 2022 * diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/bnode/CMakeLists.txt rename to source/dnode/mnode/impl/test/bnode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/bnode/bnode.cpp rename to source/dnode/mnode/impl/test/bnode/bnode.cpp index b1a85522c4..eee61cbf4e 100644 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file bnode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestBnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_bnode1", 9068); + test.Init("/tmp/mnode_test_bnode1", 9018); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9068"; + const char* firstEp = "localhost:9018"; - server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); + server2.Start("/tmp/mnode_test_bnode2", fqdn, 9019, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9069); + pReq->port = htonl(9019); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckBinary("localhost:9069", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); + CheckBinary("localhost:9019", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/qnode/CMakeLists.txt rename to source/dnode/mnode/impl/test/qnode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/qnode/qnode.cpp rename to source/dnode/mnode/impl/test/qnode/qnode.cpp index 40464de816..6e71eb51eb 100644 --- a/source/dnode/mgmt/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file qnode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestQnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_qnode1", 9064); + test.Init("/tmp/mnode_test_qnode1", 9014); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9064"; + const char* firstEp = "localhost:9014"; - server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp); + server2.Start("/tmp/mnode_test_qnode2", fqdn, 9015, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9065); + pReq->port = htonl(9015); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9064", TSDB_EP_LEN); - CheckBinary("localhost:9065", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); + CheckBinary("localhost:9015", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mnode/impl/test/snode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/snode/CMakeLists.txt rename to source/dnode/mnode/impl/test/snode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/snode/snode.cpp rename to source/dnode/mnode/impl/test/snode/snode.cpp index a14a575beb..4c32edc152 100644 --- a/source/dnode/mgmt/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file snode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module snode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestSnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_snode1", 9066); + test.Init("/tmp/mnode_test_snode1", 9016); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9066"; + const char* firstEp = "localhost:9016"; - server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp); + server2.Start("/tmp/mnode_test_snode2", fqdn, 9017, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestSnode, 04_Create_Snode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9067); + pReq->port = htonl(9017); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestSnode, 04_Create_Snode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9066", TSDB_EP_LEN); - CheckBinary("localhost:9067", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); + CheckBinary("localhost:9017", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestSnode, 04_Create_Snode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 19bba13345..ca7a8a0981 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -2,7 +2,7 @@ * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests - * @version 0.1 + * @version 1.0 * @date 2022-01-04 * * @copyright Copyright (c) 2022 diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 5ccb079633..ce8fd1b166 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -3,9 +3,9 @@ * @author slguan (slguan@taosdata.com) * @brief MNODE module user tests * @version 1.0 - * @date 2021-12-15 + * @date 2022-01-04 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ From dfd724a81c1d443a0e96701b3155352ac4390e0c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:19:06 -0800 Subject: [PATCH 23/26] minor changes --- source/dnode/mnode/impl/test/bnode/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/qnode/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/snode/CMakeLists.txt | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt index ea769a701c..b58b1a856b 100644 --- a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. STEST_SRC) -add_executable(dnode_test_bnode ${STEST_SRC}) +add_executable(mnode_test_bnode ${STEST_SRC}) target_link_libraries( - dnode_test_bnode + mnode_test_bnode PUBLIC sut ) add_test( - NAME dnode_test_bnode - COMMAND dnode_test_bnode + NAME mnode_test_bnode + COMMAND mnode_test_bnode ) diff --git a/source/dnode/mnode/impl/test/qnode/CMakeLists.txt b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt index 2edb6de8b8..77ac39e409 100644 --- a/source/dnode/mnode/impl/test/qnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. QTEST_SRC) -add_executable(dnode_test_qnode ${QTEST_SRC}) +add_executable(mnode_test_qnode ${QTEST_SRC}) target_link_libraries( - dnode_test_qnode + mnode_test_qnode PUBLIC sut ) add_test( - NAME dnode_test_qnode - COMMAND dnode_test_qnode + NAME mnode_test_qnode + COMMAND mnode_test_qnode ) diff --git a/source/dnode/mnode/impl/test/snode/CMakeLists.txt b/source/dnode/mnode/impl/test/snode/CMakeLists.txt index 180b1ec163..44a5f35f94 100644 --- a/source/dnode/mnode/impl/test/snode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/snode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. STEST_SRC) -add_executable(dnode_test_snode ${STEST_SRC}) +add_executable(mnode_test_snode ${STEST_SRC}) target_link_libraries( - dnode_test_snode + mnode_test_snode PUBLIC sut ) add_test( - NAME dnode_test_snode - COMMAND dnode_test_snode + NAME mnode_test_snode + COMMAND mnode_test_snode ) From 7974143dc7b3fa4aa09b107aaa79e0ed8a8fbef2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:36:54 -0800 Subject: [PATCH 24/26] minor changes --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 + source/dnode/mgmt/impl/test/bnode/bnode.cpp | 154 ++++++++++++++++++ .../dnode/mgmt/impl/test/cluster/cluster.cpp | 2 +- source/dnode/mgmt/impl/test/db/db.cpp | 2 +- source/dnode/mgmt/impl/test/dnode/dnode.cpp | 2 +- source/dnode/mgmt/impl/test/mnode/mnode.cpp | 2 +- .../dnode/mgmt/impl/test/profile/profile.cpp | 2 +- .../dnode/mgmt/impl/test/qnode/CMakeLists.txt | 11 ++ source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 26 +++ source/dnode/mgmt/impl/test/show/show.cpp | 2 +- source/dnode/mgmt/impl/test/stb/stb.cpp | 2 +- .../mgmt/impl/test/sut/inc/{base.h => sut.h} | 0 .../dnode/mgmt/impl/test/sut/src/client.cpp | 2 +- .../dnode/mgmt/impl/test/sut/src/server.cpp | 2 +- .../impl/test/sut/src/{base.cpp => sut.cpp} | 2 +- source/dnode/mgmt/impl/test/vgroup/vgroup.cpp | 2 +- source/dnode/mnode/impl/test/acct/acct.cpp | 14 +- source/dnode/mnode/impl/test/bnode/bnode.cpp | 16 +- source/dnode/mnode/impl/test/qnode/qnode.cpp | 16 +- source/dnode/mnode/impl/test/snode/snode.cpp | 16 +- source/dnode/mnode/impl/test/trans/trans.cpp | 8 +- source/dnode/mnode/impl/test/user/user.cpp | 16 +- 22 files changed, 247 insertions(+), 54 deletions(-) create mode 100644 source/dnode/mgmt/impl/test/bnode/bnode.cpp create mode 100644 source/dnode/mgmt/impl/test/qnode/CMakeLists.txt create mode 100644 source/dnode/mgmt/impl/test/qnode/dqnode.cpp rename source/dnode/mgmt/impl/test/sut/inc/{base.h => sut.h} (100%) rename source/dnode/mgmt/impl/test/sut/src/{base.cpp => sut.cpp} (99%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index 1896a605cd..6e6015b5f4 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,5 +1,7 @@ enable_testing() +add_subdirectory(qnode) + # add_subdirectory(auth) # add_subdirectory(balance) add_subdirectory(cluster) diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp new file mode 100644 index 0000000000..b06fd1bbca --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/bnode.cpp @@ -0,0 +1,154 @@ +/** + * @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(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)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(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)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(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)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(SMDropBnodeMsg); + + SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)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/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp index 7734826789..7d9bff7b23 100644 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ b/source/dnode/mgmt/impl/test/cluster/cluster.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestCluster : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 7ba19677fd..a78b8388c6 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDb : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index 54d7e73be6..9041098d71 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDnode : public ::testing::Test { public: diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp index e9b1ef45bd..3d4844c3f6 100644 --- a/source/dnode/mgmt/impl/test/mnode/mnode.cpp +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestMnode : public ::testing::Test { public: diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 87e6bfde74..77122d1bb9 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestProfile : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt new file mode 100644 index 0000000000..2536001231 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. DQTEST_SRC) +add_executable(dnode_test_qnode ${DQTEST_SRC}) +target_link_libraries( + dnode_test_qnode + PUBLIC sut +) + +add_test( + NAME dnode_test_qnode + COMMAND dnode_test_qnode +) diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp new file mode 100644 index 0000000000..8678e098f4 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -0,0 +1,26 @@ +/** + * @file dqnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestQnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestQnode::test; diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp index a0df0f2921..8622672758 100644 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ b/source/dnode/mgmt/impl/test/show/show.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestShow : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index dca0f48516..40af751e33 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestStb : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/sut.h similarity index 100% rename from source/dnode/mgmt/impl/test/sut/inc/base.h rename to source/dnode/mgmt/impl/test/sut/inc/sut.h diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index 13429cec28..086ba7bb0f 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; diff --git a/source/dnode/mgmt/impl/test/sut/src/server.cpp b/source/dnode/mgmt/impl/test/sut/src/server.cpp index 8ac5f62144..fb2974294c 100644 --- a/source/dnode/mgmt/impl/test/sut/src/server.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/server.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void* serverLoop(void* param) { while (1) { diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp similarity index 99% rename from source/dnode/mgmt/impl/test/sut/src/base.cpp rename to source/dnode/mgmt/impl/test/sut/src/sut.cpp index e1b6664e9f..46ced254c6 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void Testbase::InitLog(const char* path) { dDebugFlag = 0; diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index 718fbea50d..15a0c8087c 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestVgroup : public ::testing::Test { protected: diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 5a7df55c4c..906a066f74 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestAcct : public ::testing::Test { +class MndTestAcct : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); } static void TearDownTestSuite() { test.Cleanup(); } @@ -23,9 +23,9 @@ class DndTestAcct : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestAcct::test; +Testbase MndTestAcct::test; -TEST_F(DndTestAcct, 01_CreateAcct) { +TEST_F(MndTestAcct, 01_Create_Acct) { int32_t contLen = sizeof(SCreateAcctReq); SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen); @@ -35,7 +35,7 @@ TEST_F(DndTestAcct, 01_CreateAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 02_AlterAcct) { +TEST_F(MndTestAcct, 02_Alter_Acct) { int32_t contLen = sizeof(SCreateAcctReq); SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen); @@ -45,7 +45,7 @@ TEST_F(DndTestAcct, 02_AlterAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 03_DropAcct) { +TEST_F(MndTestAcct, 03_Drop_Acct) { int32_t contLen = sizeof(SDropAcctReq); SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen); @@ -55,7 +55,7 @@ TEST_F(DndTestAcct, 03_DropAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 04_ShowAcct) { +TEST_F(MndTestAcct, 04_Show_Acct) { int32_t contLen = sizeof(SShowMsg); SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index eee61cbf4e..2d44249f77 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestBnode : public ::testing::Test { +class MndTestBnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestBnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestBnode::test; -TestServer DndTestBnode::server2; +Testbase MndTestBnode::test; +TestServer MndTestBnode::server2; -TEST_F(DndTestBnode, 01_ShowBnode) { +TEST_F(MndTestBnode, 01_Show_Bnode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); CHECK_META("show bnodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestBnode, 01_ShowBnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { +TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateBnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { } } -TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { +TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateBnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { } } -TEST_F(DndTestBnode, 04_Create_Bnode) { +TEST_F(MndTestBnode, 04_Create_Bnode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index 6e71eb51eb..ca768db56c 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestQnode : public ::testing::Test { +class MndTestQnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestQnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestQnode::test; -TestServer DndTestQnode::server2; +Testbase MndTestQnode::test; +TestServer MndTestQnode::server2; -TEST_F(DndTestQnode, 01_ShowQnode) { +TEST_F(MndTestQnode, 01_Show_Qnode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestQnode, 01_ShowQnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { } } -TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { } } -TEST_F(DndTestQnode, 04_Create_Qnode) { +TEST_F(MndTestQnode, 04_Create_Qnode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index 4c32edc152..7816de6ab9 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestSnode : public ::testing::Test { +class MndTestSnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestSnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestSnode::test; -TestServer DndTestSnode::server2; +Testbase MndTestSnode::test; +TestServer MndTestSnode::server2; -TEST_F(DndTestSnode, 01_ShowSnode) { +TEST_F(MndTestSnode, 01_Show_Snode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); CHECK_META("show snodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestSnode, 01_ShowSnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { +TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateSnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { } } -TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { +TEST_F(MndTestSnode, 03_Create_Snode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateSnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { } } -TEST_F(DndTestSnode, 04_Create_Snode) { +TEST_F(MndTestSnode, 04_Create_Snode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index ca7a8a0981..97a8bd2caf 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -9,10 +9,10 @@ * */ -#include "base.h" +#include "sut.h" #include "os.h" -class DndTestTrans : public ::testing::Test { +class MndTestTrans : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } static void TearDownTestSuite() { test.Cleanup(); } @@ -48,9 +48,9 @@ class DndTestTrans : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestTrans::test; +Testbase MndTestTrans::test; -TEST_F(DndTestTrans, 01_CreateUser_Crash) { +TEST_F(MndTestTrans, 01_Create_User_Crash) { { int32_t contLen = sizeof(SCreateUserReq); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ce8fd1b166..76954db213 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestUser : public ::testing::Test { +class MndTestUser : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } static void TearDownTestSuite() { test.Cleanup(); } @@ -23,9 +23,9 @@ class DndTestUser : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestUser::test; +Testbase MndTestUser::test; -TEST_F(DndTestUser, 01_ShowUser) { +TEST_F(MndTestUser, 01_Show_User) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); @@ -43,7 +43,7 @@ TEST_F(DndTestUser, 01_ShowUser) { CheckBinary("root", TSDB_USER_LEN); } -TEST_F(DndTestUser, 02_Create_User) { +TEST_F(MndTestUser, 02_Create_User) { { int32_t contLen = sizeof(SCreateUserReq); @@ -99,7 +99,7 @@ TEST_F(DndTestUser, 02_Create_User) { EXPECT_EQ(test.GetShowRows(), 2); } -TEST_F(DndTestUser, 03_Alter_User) { +TEST_F(MndTestUser, 03_Alter_User) { { int32_t contLen = sizeof(SAlterUserReq); @@ -149,7 +149,7 @@ TEST_F(DndTestUser, 03_Alter_User) { } } -TEST_F(DndTestUser, 04_Drop_User) { +TEST_F(MndTestUser, 04_Drop_User) { { int32_t contLen = sizeof(SDropUserReq); @@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) { EXPECT_EQ(test.GetShowRows(), 1); } -TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { +TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserReq); From 268c3343d589bce88b5996ffdf2de422bba66f6a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:42:03 -0800 Subject: [PATCH 25/26] minor changes --- include/common/tmsg.h | 6 +-- source/dnode/mgmt/impl/src/dndBnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndQnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndSnode.c | 8 ++-- source/dnode/mgmt/impl/test/bnode/bnode.cpp | 16 ++++---- source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 41 ++++++++++++++++++++ source/dnode/mnode/impl/src/mndBnode.c | 14 +++---- source/dnode/mnode/impl/src/mndQnode.c | 14 +++---- source/dnode/mnode/impl/src/mndSnode.c | 14 +++---- source/dnode/mnode/impl/test/bnode/bnode.cpp | 16 ++++---- source/dnode/mnode/impl/test/qnode/qnode.cpp | 16 ++++---- source/dnode/mnode/impl/test/snode/snode.cpp | 16 ++++---- 12 files changed, 109 insertions(+), 68 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ac26e4f074..affab8903c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -851,15 +851,15 @@ typedef struct { typedef struct { int32_t dnodeId; -} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg; +} SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq; typedef struct { int32_t dnodeId; -} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg; +} SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq; typedef struct { int32_t dnodeId; -} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg; +} SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq; typedef struct { int32_t dnodeId; diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index dfe4eda145..da3295b5d7 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -256,7 +256,7 @@ static int32_t dndDropBnode(SDnode *pDnode) { } int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateBnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -268,7 +268,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropBnodeMsg *pMsg = pRpcMsg->pCont; + SDDropBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index e73a0cb0d8..642c17b661 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -261,7 +261,7 @@ static int32_t dndDropQnode(SDnode *pDnode) { } int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateQnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -273,7 +273,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropQnodeMsg *pMsg = pRpcMsg->pCont; + SDDropQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index 070fc8663e..a295a2d481 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -256,7 +256,7 @@ static int32_t dndDropSnode(SDnode *pDnode) { } int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateSnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -268,7 +268,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropSnodeMsg *pMsg = pRpcMsg->pCont; + SDDropSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp index b06fd1bbca..7777d60550 100644 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ b/source/dnode/mgmt/impl/test/bnode/bnode.cpp @@ -52,9 +52,9 @@ TEST_F(DndTestBnode, 01_ShowBnode) { TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { { // create bnode - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { { // drop bnode - int32_t contLen = sizeof(SMDropBnodeMsg); + int32_t contLen = sizeof(SMDropBnodeReq); - SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index 8678e098f4..fa9038107e 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -24,3 +24,44 @@ class DndTestQnode : public ::testing::Test { }; Testbase DndTestQnode::test; + +TEST_F(DndTestQnode, 04_Drop_User) { + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + // { + // int32_t contLen = sizeof(SDropUserReq); + + // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + // strcpy(pReq->user, "u4"); + + // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + // ASSERT_NE(pMsg, nullptr); + // ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + // } + + // { + // int32_t contLen = sizeof(SDropUserReq); + + // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + // strcpy(pReq->user, "u1"); + + // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + // ASSERT_NE(pMsg, nullptr); + // ASSERT_EQ(pMsg->code, 0); + // } + + // test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + // CHECK_META("show users", 4); + + // test.SendShowRetrieveMsg(); + // EXPECT_EQ(test.GetShowRows(), 1); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index ceaebe3f6d..886784805e 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg)); + SDCreateBnodeReq *pMsg = malloc(sizeof(SDCreateBnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateBnodeMsg); + action.contLen = sizeof(SDCreateBnodeReq); action.msgType = TDMT_DND_CREATE_BNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { +static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { SBnodeObj bnodeObj = {0}; bnodeObj.id = pDnode->id; bnodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_BNODE_OVER: static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateBnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg)); + SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropBnodeMsg); + action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_BNODE_OVER: static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropBnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("bnode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index a0c4ff8218..ea4cfa41c8 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg)); + SDCreateQnodeReq *pMsg = malloc(sizeof(SDCreateQnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateQnodeMsg); + action.contLen = sizeof(SDCreateQnodeReq); action.msgType = TDMT_DND_CREATE_QNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) { +static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { SQnodeObj qnodeObj = {0}; qnodeObj.id = pDnode->id; qnodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_QNODE_OVER: static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateQnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg)); + SDDropQnodeReq *pMsg = malloc(sizeof(SDDropQnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropQnodeMsg); + action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_QNODE_OVER: static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropQnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("qnode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index ac03e1659c..3ab1ad4eaf 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg)); + SDCreateSnodeReq *pMsg = malloc(sizeof(SDCreateSnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateSnodeMsg); + action.contLen = sizeof(SDCreateSnodeReq); action.msgType = TDMT_DND_CREATE_SNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) { +static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { SSnodeObj snodeObj = {0}; snodeObj.id = pDnode->id; snodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_SNODE_OVER: static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateSnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg)); + SDDropSnodeReq *pMsg = malloc(sizeof(SDDropSnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropSnodeMsg); + action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_SNODE_OVER: static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropSnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("snode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index 2d44249f77..fa06d9ac69 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestBnode, 01_Show_Bnode) { TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { { // create bnode - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { { // drop bnode - int32_t contLen = sizeof(SMDropBnodeMsg); + int32_t contLen = sizeof(SMDropBnodeReq); - SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index ca768db56c..f5dfc35188 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestQnode, 01_Show_Qnode) { TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { { // create qnode - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { { // drop qnode - int32_t contLen = sizeof(SMDropQnodeMsg); + int32_t contLen = sizeof(SMDropQnodeReq); - SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen); + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index 7816de6ab9..4819bc556c 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestSnode, 01_Show_Snode) { TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { TEST_F(MndTestSnode, 03_Create_Snode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestSnode, 04_Create_Snode) { { // create snode - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestSnode, 04_Create_Snode) { { // drop snode - int32_t contLen = sizeof(SMDropSnodeMsg); + int32_t contLen = sizeof(SMDropSnodeReq); - SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen); + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); From c5decfec282e426fc198c30119b0da0d71580b02 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 05:31:49 -0800 Subject: [PATCH 26/26] test for dqnode --- source/dnode/mgmt/impl/src/dndBnode.c | 18 ++++-- source/dnode/mgmt/impl/src/dndQnode.c | 20 +++++-- source/dnode/mgmt/impl/src/dndSnode.c | 21 +++++-- source/dnode/mgmt/impl/src/dnode.c | 24 ++++++++ source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 59 +++++++++++--------- 5 files changed, 103 insertions(+), 39 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index da3295b5d7..1b2e56edfe 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pBnode = pMgmt->pBnode; } else { @@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { static int32_t dndOpenBnode(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; - SBnodeOpt option = {0}; + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode != NULL) { + dndReleaseBnode(pDnode, pBnode); + terrno = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; + dError("failed to create bnode since %s", terrstr()); + return -1; + } + + SBnodeOpt option = {0}; dndBuildBnodeOption(pDnode, &option); - SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option); + pBnode = bndOpen(pDnode->dir.bnode, &option); if (pBnode == NULL) { dError("failed to open bnode since %s", terrstr()); return -1; @@ -261,6 +269,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to create bnode since %s", terrstr()); return -1; } else { return dndOpenBnode(pDnode); @@ -273,6 +282,7 @@ int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to drop bnode since %s", terrstr()); return -1; } else { return dndDropBnode(pDnode); diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 642c17b661..7dd3e168ce 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pQnode = pMgmt->pQnode; } else { @@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { static int32_t dndOpenQnode(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; - SQnodeOpt option = {0}; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode != NULL) { + dndReleaseQnode(pDnode, pQnode); + terrno = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; + dError("failed to create qnode since %s", terrstr()); + return -1; + } + + SQnodeOpt option = {0}; dndBuildQnodeOption(pDnode, &option); - SQnode *pQnode = qndOpen(&option); + pQnode = qndOpen(&option); if (pQnode == NULL) { dError("failed to open qnode since %s", terrstr()); return -1; @@ -266,6 +275,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to create qnode since %s", terrstr()); return -1; } else { return dndOpenQnode(pDnode); @@ -278,6 +288,7 @@ int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to drop qnode since %s", terrstr()); return -1; } else { return dndDropQnode(pDnode); @@ -293,6 +304,7 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pQnode != NULL) { code = qndProcessMsg(pQnode, pMsg, &pRsp); } + dndReleaseQnode(pDnode, pQnode); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index a295a2d481..567c7dcdb0 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pSnode = pMgmt->pSnode; } else { @@ -170,9 +170,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); - } + } dndCleanupWorker(&pMgmt->writeWorker); } @@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { static int32_t dndOpenSnode(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; - SSnodeOpt option = {0}; + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode != NULL) { + dndReleaseSnode(pDnode, pSnode); + terrno = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; + dError("failed to create snode since %s", terrstr()); + return -1; + } + + SSnodeOpt option = {0}; dndBuildSnodeOption(pDnode, &option); - SSnode *pSnode = sndOpen(pDnode->dir.snode, &option); + pSnode = sndOpen(pDnode->dir.snode, &option); if (pSnode == NULL) { dError("failed to open snode since %s", terrstr()); return -1; @@ -261,6 +269,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to create snode since %s", terrstr()); return -1; } else { return dndOpenSnode(pDnode); @@ -273,6 +282,7 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to drop snode since %s", terrstr()); return -1; } else { return dndDropSnode(pDnode); @@ -288,6 +298,7 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pSnode != NULL) { code = sndProcessMsg(pSnode, pMsg, &pRsp); } + dndReleaseSnode(pDnode, pSnode); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 33cec5ff47..ef5c15743c 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -14,8 +14,11 @@ */ #define _DEFAULT_SOURCE +#include "dndBnode.h" #include "dndDnode.h" #include "dndMnode.h" +#include "dndQnode.h" +#include "dndSnode.h" #include "dndTransport.h" #include "dndVnodes.h" #include "sync.h" @@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) { return NULL; } + if (dndInitQnode(pDnode) != 0) { + dError("failed to init qnode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitSnode(pDnode) != 0) { + dError("failed to init snode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitBnode(pDnode) != 0) { + dError("failed to init bnode"); + dndCleanup(pDnode); + return NULL; + } + if (dndInitMnode(pDnode) != 0) { dError("failed to init mnode"); dndCleanup(pDnode); @@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) { dndSetStat(pDnode, DND_STAT_STOPPED); dndCleanupTrans(pDnode); dndCleanupMnode(pDnode); + dndCleanupBnode(pDnode); + dndCleanupSnode(pDnode); + dndCleanupQnode(pDnode); dndCleanupVnodes(pDnode); dndCleanupDnode(pDnode); vnodeClear(); diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index fa9038107e..7c8b502a58 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -25,43 +25,50 @@ class DndTestQnode : public ::testing::Test { Testbase DndTestQnode::test; -TEST_F(DndTestQnode, 04_Drop_User) { +TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { { - int32_t contLen = sizeof(SDropUserReq); + int32_t contLen = sizeof(SDCreateQnodeReq); - SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - strcpy(pReq->user, ""); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); } - // { - // int32_t contLen = sizeof(SDropUserReq); + { + int32_t contLen = sizeof(SDCreateQnodeReq); - // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - // strcpy(pReq->user, "u4"); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); - // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - // ASSERT_NE(pMsg, nullptr); - // ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); - // } + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } - // { - // int32_t contLen = sizeof(SDropUserReq); + { + int32_t contLen = sizeof(SDCreateQnodeReq); - // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - // strcpy(pReq->user, "u1"); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); - // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - // ASSERT_NE(pMsg, nullptr); - // ASSERT_EQ(pMsg->code, 0); - // } + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } - // test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - // CHECK_META("show users", 4); + test.Restart(); - // test.SendShowRetrieveMsg(); - // EXPECT_EQ(test.GetShowRows(), 1); + { + 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, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } } \ No newline at end of file