From b42cb82b1c3d2171dd1ebae72f883050a5739a27 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 22 Dec 2021 13:43:32 +0800 Subject: [PATCH 01/36] refact --- source/dnode/vnode/impl/inc/vnodeMemAllocator.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h index bdafbf31a7..eb821a4b6c 100644 --- a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h +++ b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h @@ -22,17 +22,14 @@ extern "C" { #endif -typedef struct SVArenaNode SVArenaNode; -typedef struct SVMemAllocator SVMemAllocator; - -struct SVArenaNode { +typedef struct SVArenaNode { TD_SLIST_NODE(SVArenaNode); uint64_t size; // current node size void * ptr; char data[]; -}; +} SVArenaNode; -struct SVMemAllocator { +typedef struct SVMemAllocator { T_REF_DECLARE() TD_DLIST_NODE(SVMemAllocator); uint64_t capacity; @@ -40,7 +37,7 @@ struct SVMemAllocator { uint64_t lsize; SVArenaNode *pNode; TD_SLIST(SVArenaNode) nlist; -}; +} SVMemAllocator; SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); void vmaDestroy(SVMemAllocator *pVMA); From a39ec185dc4716a1db5d5612f32b0d1359498531 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 23 Dec 2021 16:10:46 +0800 Subject: [PATCH 02/36] [td-11818] enable some unittest cases. --- source/client/test/clientTests.cpp | 184 ++++++++++++++--------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 7a1e8ca0c3..2938d0180a 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -49,101 +49,101 @@ int main(int argc, char** argv) { TEST(testCase, driverInit_Test) { taos_init(); } -// TEST(testCase, connect_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// taos_close(pConn); -//} -// -// TEST(testCase, create_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + TEST(testCase, connect_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, create_account_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + taos_close(pConn); +} + + TEST(testCase, create_user_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + + TEST(testCase, create_account_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + + TEST(testCase, drop_account_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + + TEST(testCase, show_user_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, drop_account_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + + TAOS_RES* pRes = taos_query(pConn, "show users"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} + + TEST(testCase, drop_user_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop user abc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + + TEST(testCase, show_db_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, show_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show users"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} -// -// TEST(testCase, drop_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, show_db_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show databases"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} + + TAOS_RES* pRes = taos_query(pConn, "show databases"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} TEST(testCase, create_db_Test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); From 4426e88098566b8ffaadb7f75960b6d7f9b768b1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 23 Dec 2021 18:24:24 -0800 Subject: [PATCH 03/36] minor changes --- source/dnode/mgmt/impl/test/db/db.cpp | 73 ++++++++++++++------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 378f46aa4d..823f58e3a8 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -162,51 +162,52 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("ms", 3); // precision CheckInt8(0); // update - // restart - test.Restart(); + // // restart + // test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + // test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + // CHECK_META("show databases", 17); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); + // test.SendShowRetrieveMsg(); + // EXPECT_EQ(test.GetShowRows(), 1); - CheckBinary("d1", TSDB_DB_NAME_LEN - 1); - CheckTimestamp(); - CheckInt16(2); // vgroups - CheckInt16(1); // replica - CheckInt16(2); // quorum - CheckInt16(10); // days - CheckBinary("300,400,500", 24); // days - CheckInt32(16); // cache - CheckInt32(12); // blocks - CheckInt32(100); // minrows - CheckInt32(4096); // maxrows - CheckInt8(2); // wallevel - CheckInt32(4000); // fsync - CheckInt8(2); // comp - CheckInt8(1); // cachelast - CheckBinary("ms", 3); // precision - CheckInt8(0); // update + // CheckBinary("d1", TSDB_DB_NAME_LEN - 1); + // CheckTimestamp(); + // CheckInt16(2); // vgroups + // CheckInt16(1); // replica + // CheckInt16(2); // quorum + // CheckInt16(10); // days + // CheckBinary("300,400,500", 24); // days + // CheckInt32(16); // cache + // CheckInt32(12); // blocks + // CheckInt32(100); // minrows + // CheckInt32(4096); // maxrows + // CheckInt8(2); // wallevel + // CheckInt32(4000); // fsync + // CheckInt8(2); // comp + // CheckInt8(1); // cachelast + // CheckBinary("ms", 3); // precision + // CheckInt8(0); // update - { - int32_t contLen = sizeof(SDropDbMsg); + // { + // int32_t contLen = sizeof(SDropDbMsg); - SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); - strcpy(pReq->db, "1.d1"); + // SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); + // strcpy(pReq->db, "1.d1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - } + // SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); + // ASSERT_NE(pMsg, nullptr); + // ASSERT_EQ(pMsg->code, 0); + // } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + // test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + // CHECK_META("show databases", 17); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); + // test.SendShowRetrieveMsg(); + // EXPECT_EQ(test.GetShowRows(), 0); } +#if 0 TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { { int32_t contLen = sizeof(SCreateDbMsg); @@ -298,3 +299,5 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { } } } + +#endif \ No newline at end of file From a698284093c7cf603b2ac2d3939854f2ff81412b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 23 Dec 2021 18:27:59 -0800 Subject: [PATCH 04/36] minor changes --- source/dnode/mgmt/impl/test/db/db.cpp | 73 +++++++++++++-------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 823f58e3a8..378f46aa4d 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -162,52 +162,51 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("ms", 3); // precision CheckInt8(0); // update - // // restart - // test.Restart(); + // restart + test.Restart(); - // test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - // CHECK_META("show databases", 17); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); - // test.SendShowRetrieveMsg(); - // EXPECT_EQ(test.GetShowRows(), 1); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); - // CheckBinary("d1", TSDB_DB_NAME_LEN - 1); - // CheckTimestamp(); - // CheckInt16(2); // vgroups - // CheckInt16(1); // replica - // CheckInt16(2); // quorum - // CheckInt16(10); // days - // CheckBinary("300,400,500", 24); // days - // CheckInt32(16); // cache - // CheckInt32(12); // blocks - // CheckInt32(100); // minrows - // CheckInt32(4096); // maxrows - // CheckInt8(2); // wallevel - // CheckInt32(4000); // fsync - // CheckInt8(2); // comp - // CheckInt8(1); // cachelast - // CheckBinary("ms", 3); // precision - // CheckInt8(0); // update + CheckBinary("d1", TSDB_DB_NAME_LEN - 1); + CheckTimestamp(); + CheckInt16(2); // vgroups + CheckInt16(1); // replica + CheckInt16(2); // quorum + CheckInt16(10); // days + CheckBinary("300,400,500", 24); // days + CheckInt32(16); // cache + CheckInt32(12); // blocks + CheckInt32(100); // minrows + CheckInt32(4096); // maxrows + CheckInt8(2); // wallevel + CheckInt32(4000); // fsync + CheckInt8(2); // comp + CheckInt8(1); // cachelast + CheckBinary("ms", 3); // precision + CheckInt8(0); // update - // { - // int32_t contLen = sizeof(SDropDbMsg); + { + int32_t contLen = sizeof(SDropDbMsg); - // SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); - // strcpy(pReq->db, "1.d1"); + SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); + strcpy(pReq->db, "1.d1"); - // SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); - // ASSERT_NE(pMsg, nullptr); - // ASSERT_EQ(pMsg->code, 0); - // } + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } - // test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - // CHECK_META("show databases", 17); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); - // test.SendShowRetrieveMsg(); - // EXPECT_EQ(test.GetShowRows(), 0); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); } -#if 0 TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { { int32_t contLen = sizeof(SCreateDbMsg); @@ -299,5 +298,3 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { } } } - -#endif \ No newline at end of file From 067116330bfb66c156f9f68ef6f17fcfec0e8574 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 24 Dec 2021 10:54:15 +0800 Subject: [PATCH 05/36] [td-11818] merge 3.0 and fix a bug. --- source/client/src/clientImpl.c | 18 +++++++++++++----- source/client/src/clientMsgHandler.c | 6 +++--- source/libs/parser/src/astValidate.c | 2 -- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 992d93f39b..f00e7bd578 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -113,6 +113,13 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst); } +static bool supportedQueryType(int32_t type) { + return (type == TSDB_MSG_TYPE_CREATE_USER || type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_DROP_USER || + type == TSDB_MSG_TYPE_DROP_ACCT || type == TSDB_MSG_TYPE_CREATE_DB || type == TSDB_MSG_TYPE_CREATE_ACCT || + type == TSDB_MSG_TYPE_CREATE_TABLE || type == TSDB_MSG_TYPE_CREATE_STB || type == TSDB_MSG_TYPE_USE_DB || + type == TSDB_MSG_TYPE_DROP_DB || type == TSDB_MSG_TYPE_DROP_STB); +} + TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { STscObj *pTscObj = (STscObj *)taos; if (sqlLen > (size_t) tsMaxSQLStringLen) { @@ -145,16 +152,17 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr); SParseContext cxt = { - .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)}, - .pSql = pRequest->sqlstr, + .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)}, + .pSql = pRequest->sqlstr, .sqlLen = sqlLen, - .pMsg = pRequest->msgBuf, + .pMsg = pRequest->msgBuf, .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE }; + SQueryNode* pQuery = NULL; int32_t code = qParseQuerySql(&cxt, &pQuery); if (qIsDclQuery(pQuery)) { - SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; + SDclStmtInfo* pDcl = (SDclStmtInfo*) pQuery; pRequest->type = pDcl->msgType; pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = pDcl->pMsg, .len = pDcl->msgLen}; @@ -215,7 +223,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet) { pEpSet->version = 0; - // init mgmt ip set + // init mnode ip set SEpSet *mgmtEpSet = &(pEpSet->epSet); mgmtEpSet->numOfEps = 0; mgmtEpSet->inUse = 0; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 2fc5e84bff..548ea3d725 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -110,9 +110,9 @@ SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest) { assert(pRequest != NULL); SRequestMsgBody body = { .requestObjRefId = pRequest->self, - .msgInfo = pRequest->body.requestMsg, - .msgType = pRequest->type, - .requestId = pRequest->requestId, + .msgInfo = pRequest->body.requestMsg, + .msgType = pRequest->type, + .requestId = pRequest->requestId, }; return body; } diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index 5d64323332..cd11607326 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -4457,8 +4457,6 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm return TSDB_CODE_TSC_INVALID_OPERATION; } - strncpy(pCreateMsg->db, token.z, token.n); - pDcl->pMsg = (char*)pCreateMsg; pDcl->msgLen = sizeof(SCreateDbMsg); pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB)? TSDB_MSG_TYPE_CREATE_DB:TSDB_MSG_TYPE_ALTER_DB; From b54291201eded090dc3763eb4c421bef648ab49d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 23 Dec 2021 19:27:36 -0800 Subject: [PATCH 06/36] add test case --- source/dnode/mgmt/impl/test/db/db.cpp | 42 +++++++++++++++------------ source/dnode/mnode/impl/src/mndDb.c | 10 +++++++ tests/script/general/db/basic1.sim | 4 +-- tests/script/jenkins/basic.txt | 4 +++ 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 378f46aa4d..79a7477cea 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -27,24 +27,25 @@ Testbase DndTestDb::test; TEST_F(DndTestDb, 01_ShowDb) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups"); - CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); - CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); - CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "days"); - CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); - CHECK_SCHEMA(7, TSDB_DATA_TYPE_INT, 4, "cache"); - CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "blocks"); - CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "minrows"); - CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "maxrows"); - CHECK_SCHEMA(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); - CHECK_SCHEMA(12, TSDB_DATA_TYPE_INT, 4, "fsync"); - CHECK_SCHEMA(13, TSDB_DATA_TYPE_TINYINT, 1, "comp"); - CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); - CHECK_SCHEMA(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); - CHECK_SCHEMA(16, TSDB_DATA_TYPE_TINYINT, 1, "update"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "ntables"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_SMALLINT, 2, "days"); + CHECK_SCHEMA(7, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); + CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "cache"); + CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "blocks"); + CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "minrows"); + CHECK_SCHEMA(11, TSDB_DATA_TYPE_INT, 4, "maxrows"); + CHECK_SCHEMA(12, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); + CHECK_SCHEMA(13, TSDB_DATA_TYPE_INT, 4, "fsync"); + CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "comp"); + CHECK_SCHEMA(15, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); + CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); + CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update"); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 0); @@ -82,13 +83,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); // ntables CheckInt16(1); // replica CheckInt16(1); // quorum CheckInt16(10); // days @@ -147,6 +149,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); CheckInt16(1); // replica CheckInt16(2); // quorum CheckInt16(10); // days @@ -166,7 +169,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { test.Restart(); test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -174,6 +177,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); CheckInt16(1); // replica CheckInt16(2); // quorum CheckInt16(10); // days @@ -201,7 +205,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 0); @@ -239,7 +243,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index dd474d85f3..7c12714a46 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -876,6 +876,12 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe pSchema[cols].bytes = htonl(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "ntables"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 2; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; strcpy(pSchema[cols].name, "replica"); @@ -1017,6 +1023,10 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 *(int16_t *)pWrite = pDb->cfg.numOfVgroups; cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = 0; // todo + cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int16_t *)pWrite = pDb->cfg.replications; cols++; diff --git a/tests/script/general/db/basic1.sim b/tests/script/general/db/basic1.sim index 9ec1aabe98..dc62c33842 100644 --- a/tests/script/general/db/basic1.sim +++ b/tests/script/general/db/basic1.sim @@ -15,7 +15,7 @@ if $data00 != d1 then return -1 endi -if $data02 != 0 then +if $data02 != 2 then return -1 endi @@ -51,7 +51,7 @@ if $data00 != d4 then return -1 endi -if $data02 != 0 then +if $data02 != 2 then return -1 endi diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2408faefa0..1cc15f731d 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -1,7 +1,11 @@ #======================b1-start=============== +# ---- user ./test.sh -f general/user/basic1.sim +# ---- db +./test.sh -f general/db/basic1.sim + #======================b1-end=============== From 70742ba4d91e4175319de0efea09c703c88f90e2 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Thu, 23 Dec 2021 20:28:08 +0800 Subject: [PATCH 07/36] add mndtopic --- include/common/taosmsg.h | 43 ++ include/common/tname.h | 4 + include/dnode/mnode/sdb/sdb.h | 13 +- include/util/taoserror.h | 10 + include/util/tdef.h | 2 + source/dnode/mnode/impl/inc/mndDef.h | 15 + source/dnode/mnode/impl/inc/mndStb.h | 3 + source/dnode/mnode/impl/inc/mndTopic.h | 35 + source/dnode/mnode/impl/src/mndStb.c | 12 +- source/dnode/mnode/impl/src/mndTopic.c | 858 +++++++++++++++++++++++++ 10 files changed, 989 insertions(+), 6 deletions(-) create mode 100644 source/dnode/mnode/impl/inc/mndTopic.h create mode 100644 source/dnode/mnode/impl/src/mndTopic.c diff --git a/include/common/taosmsg.h b/include/common/taosmsg.h index cf5c5c5637..ac8725efdf 100644 --- a/include/common/taosmsg.h +++ b/include/common/taosmsg.h @@ -83,6 +83,10 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW_RETRIEVE, "retrieve" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TOPIC, "create-topic" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TOPIC, "alter-topic" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TOPIC, "drop-topic" ) + // message from client to qnode // message from client to dnode TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) @@ -96,6 +100,11 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-internal" ) + +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TOPIC_IN, "create-topic-internal" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TOPIC_IN, "alter-topic-internal" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TOPIC_IN, "drop-topic-internal" ) + // message from mnode to mnode // message from mnode to qnode // message from mnode to dnode @@ -1140,6 +1149,40 @@ typedef struct SSchedulerCancelMsg { uint64_t taskId; } SSchedulerCancelMsg; +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + int8_t igExists; + void* executor; + char* sql; +} SCreateTopicMsg; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igNotExists; +} SDropTopicMsg; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t alterType; + SSchema schema; +} SAlterTopicMsg; + +typedef struct { + SMsgHead head; + char name[TSDB_TABLE_FNAME_LEN]; + uint64_t tuid; + int32_t sverson; + int32_t execLen; + char* executor; + int32_t sqlLen; + char* sql; +} SCreateTopicInternalMsg; + +typedef struct { + SMsgHead head; + char name[TSDB_TABLE_FNAME_LEN]; + uint64_t tuid; +} SDropTopicInternalMsg; #pragma pack(pop) diff --git a/include/common/tname.h b/include/common/tname.h index de9e309b55..3ac7f8b27b 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -16,18 +16,22 @@ #ifndef TDENGINE_TNAME_H #define TDENGINE_TNAME_H +#include "tdef.h" + #define TSDB_DB_NAME_T 1 #define TSDB_TABLE_NAME_T 2 #define T_NAME_ACCT 0x1u #define T_NAME_DB 0x2u #define T_NAME_TABLE 0x4u +#define T_NAME_TOPIC 0x8u typedef struct SName { uint8_t type; //db_name_t, table_name_t int32_t acctId; char dbname[TSDB_DB_NAME_LEN]; char tname[TSDB_TABLE_NAME_LEN]; + char topicName[TSDB_TOPIC_NAME_LEN]; } SName; int32_t tNameExtractFullName(const SName* name, char* dst); diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 51d7ca7202..0f648b5150 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -16,6 +16,8 @@ #ifndef _TD_SDB_H_ #define _TD_SDB_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif @@ -159,11 +161,12 @@ typedef enum { SDB_USER = 5, SDB_AUTH = 6, SDB_ACCT = 7, - SDB_VGROUP = 8, - SDB_STB = 9, - SDB_DB = 10, - SDB_FUNC = 11, - SDB_MAX = 12 + SDB_TOPIC = 8, + SDB_VGROUP = 9, + SDB_STB = 10, + SDB_DB = 11, + SDB_FUNC = 12, + SDB_MAX = 13 } ESdbType; typedef struct SSdb SSdb; diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 7e8df3add2..bef1189d07 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -220,6 +220,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_COLUMN_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA) #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB) #define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03AC) +#define TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03AD) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) @@ -234,6 +235,15 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_TRANS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D0) #define TSDB_CODE_MND_TRANS_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D1) +// mnode-topic +#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0) +#define TSDB_CODE_MND_TOPIC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E1) +#define TSDB_CODE_MND_TOO_MANY_TOPICS TAOS_DEF_ERROR_CODE(0, 0x03E2) +#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E3) +#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E4) +#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E5) +#define TSDB_CODE_MND_NAME_CONFLICT_WITH_STB TAOS_DEF_ERROR_CODE(0, 0x03E6) + // 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) diff --git a/include/util/tdef.h b/include/util/tdef.h index f3f3643268..64a169b4f1 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -163,6 +163,7 @@ do { \ #define TSDB_NODE_NAME_LEN 64 #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string +#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string #define TSDB_DB_NAME_LEN 65 #define TSDB_FULL_DB_NAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN) @@ -175,6 +176,7 @@ do { \ #define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TABLE_FNAME_LEN (TSDB_FULL_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) +#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN #define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index da54920574..e3097c8b09 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -285,6 +285,21 @@ typedef struct { char payload[]; } SShowObj; +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_FULL_DB_NAME_LEN]; + int64_t createTime; + int64_t updateTime; + uint64_t uid; + uint64_t dbUid; + int32_t version; + SRWLatch lock; + int32_t execLen; + void* executor; + int32_t sqlLen; + char* sql; +} STopicObj; + typedef struct SMnodeMsg { char user[TSDB_USER_LEN]; char db[TSDB_FULL_DB_NAME_LEN]; diff --git a/source/dnode/mnode/impl/inc/mndStb.h b/source/dnode/mnode/impl/inc/mndStb.h index 58cae73c7f..48847dc6a3 100644 --- a/source/dnode/mnode/impl/inc/mndStb.h +++ b/source/dnode/mnode/impl/inc/mndStb.h @@ -25,6 +25,9 @@ extern "C" { int32_t mndInitStb(SMnode *pMnode); void mndCleanupStb(SMnode *pMnode); +SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName); +void mndReleaseStb(SMnode *pMnode, SStbObj *pStb); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h new file mode 100644 index 0000000000..aa431a36c9 --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndTopic.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_MND_STB_H_ +#define _TD_MND_STB_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitTopic(SMnode *pMnode); +void mndCleanupTopic(SMnode *pMnode); + +SStbObj *mndAcquireTopic(SMnode *pMnode, char *topicName); +void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_STB_H_*/ diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index a51312a2a9..d99e4d095e 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -484,6 +484,16 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { } } + //topic should have different name with stb + SStbObj *pTopic = mndAcquireStb(pMnode, pCreate->name); + if (pTopic != NULL) { + sdbRelease(pMnode->pSdb, pTopic); + terrno = TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC; + mError("stb:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + sdbRelease(pMnode->pSdb, pTopic); + SDbObj *pDb = mndAcquireDbByStb(pMnode, pCreate->name); if (pDb == NULL) { terrno = TSDB_CODE_MND_DB_NOT_SELECTED; @@ -891,4 +901,4 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c new file mode 100644 index 0000000000..6d5ff96419 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -0,0 +1,858 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "mndStb.h" +#include "mndDb.h" +#include "mndDnode.h" +#include "mndMnode.h" +#include "mndShow.h" +#include "mndTrans.h" +#include "mndUser.h" +#include "mndVgroup.h" +#include "tname.h" + +#define TSDB_TOPIC_VER_NUMBER 1 +#define TSDB_TOPIC_RESERVE_SIZE 64 + +static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic); +static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw); +static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic); +static int32_t mndTopicActionDelete(SSdb *pSdb, STopicObj *pTopic); +static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pTopic, STopicObj *pNewTopic); +static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg); +static int32_t mndProcessAlterTopicMsg(SMnodeMsg *pMsg); +static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg); +static int32_t mndProcessCreateTopicInRsp(SMnodeMsg *pMsg); +static int32_t mndProcessAlterTopicInRsp(SMnodeMsg *pMsg); +static int32_t mndProcessDropTopicInRsp(SMnodeMsg *pMsg); +static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg); +static int32_t mndGetTopicMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveTopic(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter); + +int32_t mndInitTopic(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_TOPIC, + .keyType = SDB_KEY_BINARY, + .encodeFp = (SdbEncodeFp)mndTopicActionEncode, + .decodeFp = (SdbDecodeFp)mndTopicActionDecode, + .insertFp = (SdbInsertFp)mndTopicActionInsert, + .updateFp = (SdbUpdateFp)mndTopicActionUpdate, + .deleteFp = (SdbDeleteFp)mndTopicActionDelete}; + + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC, mndProcessCreateTopicMsg); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_TOPIC, mndProcessAlterTopicMsg); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_TOPIC, mndProcessDropTopicMsg); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC_IN_RSP, mndProcessCreateTopicInRsp); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_TOPIC_IN_RSP, mndProcessAlterTopicInRsp); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_TOPIC_IN_RSP, mndProcessDropTopicInRsp); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessTopicMetaMsg); + + /*mndAddShowMetaHandle(pMnode, TSDB_MGMT_TOPIC, mndGetTopicMeta);*/ + /*mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TOPIC, mndRetrieveTopic);*/ + /*mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TOPIC, mndCancelGetNextTopic);*/ + + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC, mndProcessCreateTopicMsg); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC_IN_RSP, mndProcessCreateTopicInRsp); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupTopic(SMnode *pMnode) {} + +static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { + int32_t size = sizeof(STopicObj) + TSDB_TOPIC_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, TSDB_TOPIC_VER_NUMBER, size); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); + SDB_SET_BINARY(pRaw, dataPos, pTopic->db, TSDB_FULL_DB_NAME_LEN); + SDB_SET_INT64(pRaw, dataPos, pTopic->createTime); + SDB_SET_INT64(pRaw, dataPos, pTopic->updateTime); + SDB_SET_INT64(pRaw, dataPos, pTopic->uid); + SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid); + SDB_SET_INT32(pRaw, dataPos, pTopic->version); + SDB_SET_INT32(pRaw, dataPos, pTopic->execLen); + SDB_SET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen); + SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen); + SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen); + + SDB_SET_RESERVE(pRaw, dataPos, TSDB_TOPIC_RESERVE_SIZE); + SDB_SET_DATALEN(pRaw, dataPos); + + return pRaw; +} + +static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != TSDB_TOPIC_VER_NUMBER) { + mError("failed to decode stable since %s", terrstr()); + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + return NULL; + } + + int32_t size = sizeof(STopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); + STopicObj *pTopic = sdbGetRowObj(pRow); + if (pTopic == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->db, TSDB_FULL_DB_NAME_LEN); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->createTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->updateTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->uid); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->dbUid); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->version); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->execLen); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->executor, pTopic->execLen); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->sqlLen); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->sql, pTopic->sqlLen); + + SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_TOPIC_RESERVE_SIZE); + + return pRow; +} + +static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic) { + mTrace("topic:%s, perform insert action", pTopic->name); + return 0; +} + +static int32_t mndTopicActionDelete(SSdb *pSdb, STopicObj *pTopic) { + mTrace("topic:%s, perform delete action", pTopic->name); + return 0; +} + +static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj *pNewTopic) { + mTrace("topic:%s, perform update action", pOldTopic->name); + atomic_exchange_32(&pOldTopic->updateTime, pNewTopic->updateTime); + atomic_exchange_32(&pOldTopic->version, pNewTopic->version); + + taosWLockLatch(&pOldTopic->lock); +#if 0 + + pOldTopic->numOfColumns = pNewTopic->numOfColumns; + pOldTopic->numOfTags = pNewTopic->numOfTags; + int32_t totalCols = pNewTopic->numOfTags + pNewTopic->numOfColumns; + int32_t totalSize = totalCols * sizeof(SSchema); + + if (pOldTopic->numOfTags + pOldTopic->numOfColumns < totalCols) { + void *pSchema = malloc(totalSize); + if (pSchema != NULL) { + free(pOldTopic->pSchema); + pOldTopic->pSchema = pSchema; + } + } + + memcpy(pOldTopic->pSchema, pNewTopic->pSchema, totalSize); + +#endif + taosWUnLockLatch(&pOldTopic->lock); + return 0; +} + +STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName) { + SSdb *pSdb = pMnode->pSdb; + STopicObj *pTopic = sdbAcquire(pSdb, SDB_TOPIC, topicName); + if (pTopic == NULL) { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + } + return pTopic; +} + +void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pTopic); +} + +static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) { + SName name = {0}; + tNameFromString(&name, topicName, T_NAME_ACCT | T_NAME_DB | T_NAME_TOPIC); + + char db[TSDB_TABLE_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, db); + + return mndAcquireDb(pMnode, db); +} + +static SCreateTopicInternalMsg *mndBuildCreateTopicMsg(SMnode *pMnode, SVgObj *pVgroup, STopicObj *pTopic) { + int32_t totalCols = 0; + int32_t contLen = sizeof(SCreateTopicInternalMsg) + pTopic->execLen + pTopic->sqlLen; + + SCreateTopicInternalMsg *pCreate = calloc(1, contLen); + if (pCreate == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pCreate->head.contLen = htonl(contLen); + pCreate->head.vgId = htonl(pVgroup->vgId); + memcpy(pCreate->name, pTopic->name, TSDB_TABLE_FNAME_LEN); + pCreate->tuid = htobe64(pTopic->uid); + pCreate->sverson = htonl(pTopic->version); + + pCreate->sql = malloc(pTopic->sqlLen); + if(pCreate->sql == NULL) { + free(pCreate); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + memcpy(pCreate->sql, pTopic->sql, pTopic->sqlLen); + + pCreate->executor = malloc(pTopic->execLen); + if(pCreate->executor == NULL) { + free(pCreate); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + memcpy(pCreate->executor, pTopic->executor, pTopic->execLen); + + return pCreate; +} + +static SDropTopicInternalMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, STopicObj *pTopic) { + int32_t contLen = sizeof(SDropTopicInternalMsg); + + SDropTopicInternalMsg *pDrop = calloc(1, contLen); + if (pDrop == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pDrop->head.contLen = htonl(contLen); + pDrop->head.vgId = htonl(pVgroup->vgId); + memcpy(pDrop->name, pTopic->name, TSDB_TABLE_FNAME_LEN); + pDrop->tuid = htobe64(pTopic->uid); + + return pDrop; +} + +static int32_t mndCheckCreateTopicMsg(SCreateTopicMsg *pCreate) { + //deserialize and other stuff + return 0; +} + +static int32_t mndSetCreateTopicRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, STopicObj *pTopic) { + SSdbRaw *pRedoRaw = mndTopicActionEncode(pTopic); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateTopicUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, STopicObj *pTopic) { + SSdbRaw *pUndoRaw = mndTopicActionEncode(pTopic); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateTopicCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, STopicObj *pTopic) { + SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateTopicRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, STopicObj *pTopic) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pDb->uid) continue; + + SCreateTopicInternalMsg *pMsg = mndBuildCreateTopicMsg(pMnode, pVgroup, pTopic); + if (pMsg == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + action.pCont = pMsg; + action.contLen = htonl(pMsg->head.contLen); + action.msgType = TSDB_MSG_TYPE_CREATE_TOPIC_IN; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndSetCreateTopicUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, STopicObj *pTopic) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pDb->uid) continue; + + SDropTopicInternalMsg *pMsg = mndBuildDropTopicMsg(pMnode, pVgroup, pTopic); + if (pMsg == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + action.pCont = pMsg; + action.contLen = sizeof(SDropTopicInternalMsg); + action.msgType = TSDB_MSG_TYPE_DROP_TOPIC_IN; + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pMsg); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCreateTopicMsg *pCreate, SDbObj *pDb) { + STopicObj topicObj = {0}; + tstrncpy(topicObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); + tstrncpy(topicObj.db, pDb->name, TSDB_FULL_DB_NAME_LEN); + topicObj.createTime = taosGetTimestampMs(); + topicObj.updateTime = topicObj.createTime; + topicObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); + topicObj.dbUid = pDb->uid; + topicObj.version = 1; + +#if 0 + int32_t totalCols = topicObj.numOfColumns + topicObj.numOfTags; + int32_t totalSize = totalCols * sizeof(SSchema); + topicObj.sql = malloc(totalSize); + if (topicObj.sql == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + memcpy(topicObj.sql, pCreate->sql, totalSize); +#endif + + int32_t code = 0; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + if (pTrans == NULL) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name); + + if (mndSetCreateTopicRedoLogs(pMnode, pTrans, pDb, &topicObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto CREATE_TOPIC_OVER; + } + + if (mndSetCreateTopicUndoLogs(pMnode, pTrans, pDb, &topicObj) != 0) { + mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); + goto CREATE_TOPIC_OVER; + } + + if (mndSetCreateTopicCommitLogs(pMnode, pTrans, pDb, &topicObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto CREATE_TOPIC_OVER; + } + + if (mndSetCreateTopicRedoActions(pMnode, pTrans, pDb, &topicObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_TOPIC_OVER; + } + + if (mndSetCreateTopicUndoActions(pMnode, pTrans, pDb, &topicObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_TOPIC_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + code = 0; + +CREATE_TOPIC_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SCreateTopicMsg *pCreate = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to create", pCreate->name); + + if (mndCheckCreateTopicMsg(pCreate) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + STopicObj *pTopic = mndAcquireTopic(pMnode, pCreate->name); + if (pTopic != NULL) { + sdbRelease(pMnode->pSdb, pTopic); + if (pCreate->igExists) { + mDebug("topic:%s, already exist, ignore exist is set", pCreate->name); + return 0; + } else { + terrno = TSDB_CODE_MND_TOPIC_ALREADY_EXIST; + mError("db:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + } + + //topic should have different name with stb + SStbObj *pStb = mndAcquireStb(pMnode, pCreate->name); + if (pStb != NULL) { + sdbRelease(pMnode->pSdb, pStb); + terrno = TSDB_CODE_MND_NAME_CONFLICT_WITH_STB; + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + sdbRelease(pMnode->pSdb, pStb); + + SDbObj *pDb = mndAcquireDbByTopic(pMnode, pCreate->name); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + int32_t code = mndCreateTopic(pMnode, pMsg, pCreate, pDb); + mndReleaseDb(pMnode, pDb); + + if (code != 0) { + terrno = code; + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndCheckAlterTopicMsg(SAlterTopicMsg *pAlter) { + SSchema *pSchema = &pAlter->schema; + pSchema->colId = htonl(pSchema->colId); + pSchema->bytes = htonl(pSchema->bytes); + + if (pSchema->type <= 0) { + terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + return -1; + } + if (pSchema->colId < 0 || pSchema->colId >= (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS)) { + terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + return -1; + } + if (pSchema->bytes <= 0) { + terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + return -1; + } + if (pSchema->name[0] == 0) { + terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + return -1; + } + + return 0; +} + +static int32_t mndUpdateTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pOldTopic, STopicObj *pNewTopic) { return 0; } + +static int32_t mndProcessAlterTopicMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SAlterTopicMsg *pAlter = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to alter", pAlter->name); + + if (mndCheckAlterTopicMsg(pAlter) != 0) { + mError("topic:%s, failed to alter since %s", pAlter->name, terrstr()); + return -1; + } + + STopicObj *pTopic = mndAcquireTopic(pMnode, pAlter->name); + if (pTopic == NULL) { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + mError("topic:%s, failed to alter since %s", pAlter->name, terrstr()); + return -1; + } + + STopicObj topicObj = {0}; + memcpy(&topicObj, pTopic, sizeof(STopicObj)); + + int32_t code = mndUpdateTopic(pMnode, pMsg, pTopic, &topicObj); + mndReleaseTopic(pMnode, pTopic); + + if (code != 0) { + mError("topic:%s, failed to alter since %s", pAlter->name, tstrerror(code)); + return code; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessAlterTopicInRsp(SMnodeMsg *pMsg) { + mndTransHandleActionRsp(pMsg); + return 0; +} + +static int32_t mndSetDropTopicRedoLogs(SMnode *pMnode, STrans *pTrans, STopicObj *pTopic) { + SSdbRaw *pRedoRaw = mndTopicActionEncode(pTopic); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + + return 0; +} + +static int32_t mndSetDropTopicUndoLogs(SMnode *pMnode, STrans *pTrans, STopicObj *pTopic) { + SSdbRaw *pUndoRaw = mndTopicActionEncode(pTopic); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1; + + return 0; +} + +static int32_t mndSetDropTopicCommitLogs(SMnode *pMnode, STrans *pTrans, STopicObj *pTopic) { + SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + + return 0; +} + +static int32_t mndSetDropTopicRedoActions(SMnode *pMnode, STrans *pTrans, STopicObj *pTopic) { return 0; } + +static int32_t mndSetDropTopicUndoActions(SMnode *pMnode, STrans *pTrans, STopicObj *pTopic) { return 0; } + +static int32_t mndDropTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pTopic) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + if (pTrans == NULL) { + mError("topic:%s, failed to drop since %s", pTopic->name, terrstr()); + return -1; + } + mDebug("trans:%d, used to drop topic:%s", pTrans->id, pTopic->name); + + if (mndSetDropTopicRedoLogs(pMnode, pTrans, pTopic) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + if (mndSetDropTopicUndoLogs(pMnode, pTrans, pTopic) != 0) { + mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + if (mndSetDropTopicCommitLogs(pMnode, pTrans, pTopic) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + if (mndSetDropTopicRedoActions(pMnode, pTrans, pTopic) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + if (mndSetDropTopicUndoActions(pMnode, pTrans, pTopic) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto DROP_TOPIC_OVER; + } + + code = 0; + +DROP_TOPIC_OVER: + mndTransDrop(pTrans); + return 0; +} + +static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SDropTopicMsg *pDrop = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to drop", pDrop->name); + + STopicObj *pTopic = mndAcquireTopic(pMnode, pDrop->name); + if (pTopic == NULL) { + if (pDrop->igNotExists) { + mDebug("topic:%s, not exist, ignore not exist is set", pDrop->name); + return 0; + } else { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + mError("topic:%s, failed to drop since %s", pDrop->name, terrstr()); + return -1; + } + } + + int32_t code = mndDropTopic(pMnode, pMsg, pTopic); + mndReleaseTopic(pMnode, pTopic); + + if (code != 0) { + terrno = code; + mError("topic:%s, failed to drop since %s", pDrop->name, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessDropTopicInRsp(SMnodeMsg *pMsg) { + mndTransHandleActionRsp(pMsg); + return 0; +} + +static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to retrieve meta", pInfo->tableFname); + + SDbObj *pDb = mndAcquireDbByTopic(pMnode, pInfo->tableFname); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + mError("topic:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + STopicObj *pTopic = mndAcquireTopic(pMnode, pInfo->tableFname); + if (pTopic == NULL) { + mndReleaseDb(pMnode, pDb); + terrno = TSDB_CODE_MND_INVALID_TOPIC; + mError("topic:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } +#if 0 + + taosRLockLatch(&pTopic->lock); + int32_t totalCols = pTopic->numOfColumns + pTopic->numOfTags; + int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema); + + STableMetaMsg *pMeta = rpcMallocCont(contLen); + if (pMeta == NULL) { + taosRUnLockLatch(&pTopic->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseTopic(pMnode, pTopic); + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("topic:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + memcpy(pMeta->topicFname, pTopic->name, TSDB_TABLE_FNAME_LEN); + pMeta->numOfTags = htonl(pTopic->numOfTags); + pMeta->numOfColumns = htonl(pTopic->numOfColumns); + pMeta->precision = pDb->cfg.precision; + pMeta->tableType = TSDB_SUPER_TABLE; + pMeta->update = pDb->cfg.update; + pMeta->sversion = htonl(pTopic->version); + pMeta->tuid = htonl(pTopic->uid); + + for (int32_t i = 0; i < totalCols; ++i) { + SSchema *pSchema = &pMeta->pSchema[i]; + SSchema *pSrcSchema = &pTopic->pSchema[i]; + memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); + pSchema->type = pSrcSchema->type; + pSchema->colId = htonl(pSrcSchema->colId); + pSchema->bytes = htonl(pSrcSchema->bytes); + } + taosRUnLockLatch(&pTopic->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseTopic(pMnode, pTopic); + + pMsg->pCont = pMeta; + pMsg->contLen = contLen; + + mDebug("topic:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pTopic->numOfColumns, pTopic->numOfTags); +#endif + return 0; +} + +static int32_t mndProcessCreateTopicInRsp(SMnodeMsg* pMsg) { + mndTransHandleActionRsp(pMsg); + return 0; +} + +static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTopics) { + SSdb *pSdb = pMnode->pSdb; + + SDbObj *pDb = mndAcquireDb(pMnode, dbName); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + return -1; + } + + int32_t numOfTopics = 0; + void *pIter = NULL; + while (1) { + STopicObj *pTopic = NULL; + pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic); + if (pIter == NULL) break; + + if (strcmp(pTopic->db, dbName) == 0) { + numOfTopics++; + } + + sdbRelease(pSdb, pTopic); + } + + *pNumOfTopics = numOfTopics; + return 0; +} + +static int32_t mndGetTopicMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + if (mndGetNumOfTopics(pMnode, pShow->db, &pShow->numOfRows) != 0) { + return -1; + } + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "name"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "columns"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "tags"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = sdbGetSize(pSdb, SDB_TOPIC); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static void mndExtractTableName(char *tableId, char *name) { + int pos = -1; + int num = 0; + for (pos = 0; tableId[pos] != 0; ++pos) { + if (tableId[pos] == '.') num++; + if (num == 2) break; + } + + if (num == 2) { + strcpy(name, tableId + pos + 1); + } +} + +static int32_t mndRetrieveTopic(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + STopicObj *pTopic = NULL; + int32_t cols = 0; + char *pWrite; + char prefix[64] = {0}; + + tstrncpy(prefix, pShow->db, 64); + strcat(prefix, TS_PATH_DELIMITER); + int32_t prefixLen = (int32_t)strlen(prefix); + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_TOPIC, pShow->pIter, (void **)&pTopic); + if (pShow->pIter == NULL) break; + + if (strncmp(pTopic->name, prefix, prefixLen) != 0) { + sdbRelease(pSdb, pTopic); + continue; + } + + cols = 0; + + char topicName[TSDB_TABLE_NAME_LEN] = {0}; + tstrncpy(topicName, pTopic->name + prefixLen, TSDB_TABLE_NAME_LEN); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, topicName); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pTopic->createTime; + cols++; + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pTopic->numOfColumns;*/ + /*cols++;*/ + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pTopic->numOfTags;*/ + /*cols++;*/ + + numOfRows++; + sdbRelease(pSdb, pTopic); + } + + pShow->numOfReads += numOfRows; + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + return numOfRows; +} + +static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} From 7d8c04ed1e8f86060a865f801b5f2e2b3fb83b5a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 23 Dec 2021 22:08:21 -0800 Subject: [PATCH 08/36] fix bug in transaction --- source/dnode/mgmt/impl/src/dndVnodes.c | 1 + source/dnode/mnode/impl/src/mndDb.c | 160 ++++++++++++++++++------ source/dnode/mnode/impl/src/mndTrans.c | 3 +- source/dnode/mnode/impl/src/mndVgroup.c | 12 +- source/dnode/mnode/sdb/src/sdbHash.c | 1 + tests/script/general/db/basic1.sim | 1 - tests/script/general/table/basic1.sim | 32 ++--- 7 files changed, 146 insertions(+), 64 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index 598d6e47be..028596c041 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -829,6 +829,7 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; rpcSendResponse(pRsp); free(pRsp); } else { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 7c12714a46..d7e8768f65 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -541,6 +541,15 @@ static int32_t mndSetDbCfgFromAlterDbMsg(SDbObj *pDb, SAlterDbMsg *pAlter) { } static int32_t mndSetUpdateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { + SSdbRaw *pRedoRaw = mndDbActionEncode(pOldDb); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_UPDATING) != 0) return -1; + + return 0; +} + +static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { SSdbRaw *pRedoRaw = mndDbActionEncode(pNewDb); if (pRedoRaw == NULL) return -1; if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; @@ -549,24 +558,57 @@ static int32_t mndSetUpdateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pO return 0; } -static int32_t mndSetUpdateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { - SSdbRaw *pUndoRaw = mndDbActionEncode(pOldDb); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1; +static int32_t mndBuildUpdateVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + STransAction action = {0}; + SVnodeGid *pVgid = pVgroup->vnodeGid + vn; + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + SAlterVnodeMsg *pMsg = (SAlterVnodeMsg *)mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup); + if (pMsg == NULL) return -1; + + action.pCont = pMsg; + action.contLen = sizeof(SAlterVnodeMsg); + action.msgType = TSDB_MSG_TYPE_ALTER_VNODE_IN; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } return 0; } -static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } +static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; -static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; -static int32_t mndSetUpdateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } + if (pVgroup->dbUid == pNewDb->uid) { + if (mndBuildUpdateVgroupAction(pMnode, pTrans, pNewDb, pVgroup) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + } + + sdbRelease(pSdb, pVgroup); + } + + return 0; +} static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbObj *pNewDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); if (pTrans == NULL) { mError("db:%s, failed to update since %s", pOldDb->name, terrstr()); return terrno; @@ -579,11 +621,6 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO goto UPDATE_DB_OVER; } - if (mndSetUpdateDbUndoLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) { - mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); - goto UPDATE_DB_OVER; - } - if (mndSetUpdateDbCommitLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) { mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); goto UPDATE_DB_OVER; @@ -594,11 +631,6 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO goto UPDATE_DB_OVER; } - if (mndSetUpdateDbUndoActions(pMnode, pTrans, pOldDb, pNewDb) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto UPDATE_DB_OVER; - } - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); goto UPDATE_DB_OVER; @@ -660,31 +692,87 @@ static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) return 0; } -static int32_t mndSetDropDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { - SSdbRaw *pUndoRaw = mndDbActionEncode(pDb); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1; - - return 0; -} - static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { SSdbRaw *pCommitRaw = mndDbActionEncode(pDb); if (pCommitRaw == NULL) return -1; if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + if (pVgroup->dbUid == pDb->uid) { + SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); + if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED); + } + + sdbRelease(pSdb, pVgroup); + } + return 0; } -static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } +static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + STransAction action = {0}; + SVnodeGid * pVgid = pVgroup->vnodeGid + vn; -static int32_t mndSetDropDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup); + if (pMsg == NULL) return -1; + + action.pCont = pMsg; + action.contLen = sizeof(SCreateVnodeMsg); + action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } + + return 0; +} + +static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + if (pVgroup->dbUid == pDb->uid) { + if (mndBuildDropVgroupAction(pMnode, pTrans, pDb, pVgroup) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + } + + sdbRelease(pSdb, pVgroup); + } + + return 0; +} static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); if (pTrans == NULL) { mError("db:%s, failed to drop since %s", pDb->name, terrstr()); return -1; @@ -697,11 +785,6 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { goto DROP_DB_OVER; } - if (mndSetDropDbUndoLogs(pMnode, pTrans, pDb) != 0) { - mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); - goto DROP_DB_OVER; - } - if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) { mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); goto DROP_DB_OVER; @@ -712,11 +795,6 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { goto DROP_DB_OVER; } - if (mndSetDropDbUndoActions(pMnode, pTrans, pDb) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_DB_OVER; - } - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); goto DROP_DB_OVER; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 53e3bc5203..eca49cf2d0 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -696,7 +696,8 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA for (int32_t action = 0; action < numOfActions; ++action) { STransAction *pAction = taosArrayGet(pArray, action); if (pAction == NULL) continue; - if (pAction->msgReceived && pAction->errCode == 0) continue; + if (pAction->msgSent && !pAction->msgReceived) continue; + if (pAction->msgSent && pAction->msgReceived && pAction->errCode == 0) continue; int64_t signature = pTrans->id; signature = (signature << 32); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index c65436efcb..92bcbb7394 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -337,8 +337,16 @@ static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) { return 0; } -static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { return 0; } -static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { return 0; } +static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { + mndTransHandleActionRsp(pMsg); + return 0; +} + +static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { + mndTransHandleActionRsp(pMsg); + return 0; +} + static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; } static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 1c8b82fd92..0c311b86b6 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -199,6 +199,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { SSdbRow *pRow = *ppRow; switch (pRow->status) { case SDB_STATUS_READY: + case SDB_STATUS_UPDATING: atomic_add_fetch_32(&pRow->refCount, 1); pRet = pRow->pObj; break; diff --git a/tests/script/general/db/basic1.sim b/tests/script/general/db/basic1.sim index dc62c33842..666a9dfd9e 100644 --- a/tests/script/general/db/basic1.sim +++ b/tests/script/general/db/basic1.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 sql connect print =============== create database diff --git a/tests/script/general/table/basic1.sim b/tests/script/general/table/basic1.sim index c26c3c33e4..ded8d79a3f 100644 --- a/tests/script/general/table/basic1.sim +++ b/tests/script/general/table/basic1.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 sql connect print =============== create database @@ -13,29 +12,24 @@ endi print $data00 $data01 $data02 -print =============== create normal table -sql create table d1.n1 (ts timestamp, i int) -sql show d1.tables -if $rows != 1 then - return -1 -endi - -print $data00 $data01 $data02 +sql use d1 print =============== create super table -sql create table d1.st (ts timestamp, i int) tags (j int) -sql show d1.stables +sql create table st (ts timestamp, i int) tags (j int) +sql show stables if $rows != 1 then return -1 endi print $data00 $data01 $data02 +return + print =============== create child table -sql create table d1.c1 using d1.st tags(1) -sql create table d1.c2 using d1.st tags(2) -sql show d1.tables -if $rows != 3 then +sql create table c1 using st tags(1) +sql create table c2 using st tags(2) +sql show tables +if $rows != 2 then return -1 endi @@ -44,12 +38,12 @@ print $data10 $data11 $data22 print $data20 $data11 $data22 print =============== insert data -sql insert into d1.n1 values(now+1s, 1) -sql insert into d1.n1 values(now+2s, 2) -sql insert into d1.n1 values(now+3s, 3) +sql insert into c1 values(now+1s, 1) +sql insert into c1 values(now+2s, 2) +sql insert into c1 values(now+3s, 3) print =============== query data -sql select * from d1.n1 +sql select * from c1 if $rows != 3 then return -1 endi From 23a1204a28ac445c15e0fc48bcd09242649d820b Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 24 Dec 2021 14:37:06 +0800 Subject: [PATCH 09/36] fix topic init --- source/dnode/mnode/impl/inc/mndTopic.h | 8 ++++---- source/dnode/mnode/impl/src/mnode.c | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h index aa431a36c9..62d213b8a2 100644 --- a/source/dnode/mnode/impl/inc/mndTopic.h +++ b/source/dnode/mnode/impl/inc/mndTopic.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MND_STB_H_ -#define _TD_MND_STB_H_ +#ifndef _TD_MND_TOPIC_H_ +#define _TD_MND_TOPIC_H_ #include "mndInt.h" @@ -25,11 +25,11 @@ extern "C" { int32_t mndInitTopic(SMnode *pMnode); void mndCleanupTopic(SMnode *pMnode); -SStbObj *mndAcquireTopic(SMnode *pMnode, char *topicName); +STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName); void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic); #ifdef __cplusplus } #endif -#endif /*_TD_MND_STB_H_*/ +#endif /*_TD_MND_TOPIC_H_*/ diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index a62a0a9296..b334936a44 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -27,6 +27,7 @@ #include "mndStb.h" #include "mndSync.h" #include "mndTelem.h" +#include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -132,6 +133,7 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; if (pMnode->clusterId <= 0) { if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; @@ -227,7 +229,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { } return 0; -} +} SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { mDebug("start to open mnode in %s", path); @@ -442,4 +444,4 @@ uint64_t mndGenerateUid(char *name, int32_t len) { int32_t hashval = MurmurHash3_32(name, len); uint64_t x = (us & 0x000000FFFFFFFFFF) << 24; return x + ((hashval & ((1ul << 16) - 1ul)) << 8) + (taosRand() & ((1ul << 8) - 1ul)); -} \ No newline at end of file +} From e7ea350872a16f60bf7a605e7d2d12b29e332920 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 24 Dec 2021 01:39:46 -0500 Subject: [PATCH 10/36] TD-12506 implement taos_query_l --- include/libs/parser/parser.h | 4 +- include/libs/planner/planner.h | 2 +- source/client/CMakeLists.txt | 2 +- source/client/inc/clientInt.h | 1 + source/client/src/clientImpl.c | 195 +++++++++++++--------- source/libs/parser/src/parser.c | 6 +- source/libs/planner/src/planner.c | 2 +- source/libs/planner/test/phyPlanTests.cpp | 2 +- 8 files changed, 127 insertions(+), 87 deletions(-) diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 7834bc6913..f2f3fcd49b 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -44,7 +44,9 @@ typedef struct SParseContext { */ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); -bool qIsDclQuery(const SQueryNode* pQuery); +bool qIsDdlQuery(const SQueryNode* pQuery); + +void qDestoryQuery(SQueryNode* pQuery); /** * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index d4469be5e3..146d01faa7 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -139,7 +139,7 @@ struct SQueryNode; /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index c78bf02cbd..ad6a93415c 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( taos INTERFACE api - PRIVATE os util common transport parser catalog function qcom + PRIVATE os util common transport parser planner catalog scheduler function qcom ) ADD_SUBDIRECTORY(test) \ No newline at end of file diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index a34250ccab..e68b989b50 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -121,6 +121,7 @@ typedef struct SRequestObj { STscObj *pTscObj; SQueryExecMetric metric; char *sqlstr; // sql string + int32_t sqlLen; SRequestSendRecvBody body; int64_t self; char *msgBuf; diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 992d93f39b..3236d1308a 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -9,6 +9,17 @@ #include "tpagedfile.h" #include "tref.h" #include "parser.h" +#include "planner.h" +#include "scheduler.h" + +#define CHECK_CODE_GOTO(expr, lable) \ + do { \ + int32_t code = expr; \ + if (TSDB_CODE_SUCCESS != code) { \ + terrno = code; \ + goto lable; \ + } \ + } while (0) static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet); static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody); @@ -113,6 +124,94 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst); } +int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj** pRequest) { + *pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT); + if (*pRequest == NULL) { + tscError("failed to malloc sqlObj"); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + (*pRequest)->sqlstr = malloc(sqlLen + 1); + if ((*pRequest)->sqlstr == NULL) { + tscError("0x%"PRIx64" failed to prepare sql string buffer", (*pRequest)->self); + (*pRequest)->msgBuf = strdup("failed to prepare sql string buffer"); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen); + (*pRequest)->sqlstr[sqlLen] = 0; + (*pRequest)->sqlLen = sqlLen; + + tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr); + return TSDB_CODE_SUCCESS; +} + +int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) { + SParseContext cxt = { + .ctx = {.requestId = pRequest->requestId, .acctId = pRequest->pTscObj->acctId, .db = getConnectionDB(pRequest->pTscObj)}, + .pSql = pRequest->sqlstr, + .sqlLen = pRequest->sqlLen, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE + }; + int32_t code = qParseQuerySql(&cxt, pQuery); + tfree(cxt.ctx.db); + return code; +} + +int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { + SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; + pRequest->type = pDcl->msgType; + pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = pDcl->pMsg, .len = pDcl->msgLen}; + + SRequestMsgBody body = buildRequestMsgImpl(pRequest); + SEpSet* pEpSet = &pRequest->pTscObj->pAppInfo->mgmtEp.epSet; + + if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) { + struct SCatalog* pCatalog = NULL; + + char buf[12] = {0}; + sprintf(buf, "%d", pRequest->pTscObj->pAppInfo->clusterId); + int32_t code = catalogGetHandle(buf, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + SCreateTableMsg* pMsg = body.msgInfo.pMsg; + + SName t = {0}; + tNameFromString(&t, pMsg->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE); + + char db[TSDB_DB_NAME_LEN + TS_PATH_DELIMITER_LEN + TSDB_ACCT_ID_LEN] = {0}; + tNameGetFullDbName(&t, db); + + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCatalog, pRequest->pTscObj->pTransporter, pEpSet, db, tNameGetTableName(&t), &info); + + int64_t transporterId = 0; + SEpSet ep = {0}; + ep.inUse = info.inUse; + ep.numOfEps = info.numOfEps; + for(int32_t i = 0; i < ep.numOfEps; ++i) { + ep.port[i] = info.epAddr[i].port; + tstrncpy(ep.fqdn[i], info.epAddr[i].fqdn, tListLen(ep.fqdn[i])); + } + + sendMsgToServer(pRequest->pTscObj->pTransporter, &ep, &body, &transporterId); + } else { + int64_t transporterId = 0; + sendMsgToServer(pRequest->pTscObj->pTransporter, pEpSet, &body, &transporterId); + } + + tsem_wait(&pRequest->body.rspSem); + destroyRequestMsgBody(&body); + return TSDB_CODE_SUCCESS; +} + +int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { + return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); +} + TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { STscObj *pTscObj = (STscObj *)taos; if (sqlLen > (size_t) tsMaxSQLStringLen) { @@ -123,92 +222,26 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { nPrintTsc("%s", sql) - SRequestObj* pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT); - if (pRequest == NULL) { - tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - return NULL; - } - - pRequest->sqlstr = malloc(sqlLen + 1); - if (pRequest->sqlstr == NULL) { - tscError("0x%"PRIx64" failed to prepare sql string buffer", pRequest->self); - - pRequest->msgBuf = strdup("failed to prepare sql string buffer"); - terrno = pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - return pRequest; - } - - strntolower(pRequest->sqlstr, sql, (int32_t)sqlLen); - pRequest->sqlstr[sqlLen] = 0; - - tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr); - - SParseContext cxt = { - .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)}, - .pSql = pRequest->sqlstr, - .sqlLen = sqlLen, - .pMsg = pRequest->msgBuf, - .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE - }; + SRequestObj* pRequest = NULL; SQueryNode* pQuery = NULL; - int32_t code = qParseQuerySql(&cxt, &pQuery); - if (qIsDclQuery(pQuery)) { - SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; - pRequest->type = pDcl->msgType; - pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = pDcl->pMsg, .len = pDcl->msgLen}; + SQueryDag* pDag = NULL; + void* pJob = NULL; - SRequestMsgBody body = buildRequestMsgImpl(pRequest); - SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; - - if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) { - struct SCatalog* pCatalog = NULL; - - char buf[12] = {0}; - sprintf(buf, "%d", pTscObj->pAppInfo->clusterId); - code = catalogGetHandle(buf, &pCatalog); - if (code != 0) { - pRequest->code = code; - return pRequest; - } - - SCreateTableMsg* pMsg = body.msgInfo.pMsg; - - SName t = {0}; - tNameFromString(&t, pMsg->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE); - - char db[TSDB_DB_NAME_LEN + TS_PATH_DELIMITER_LEN + TSDB_ACCT_ID_LEN] = {0}; - tNameGetFullDbName(&t, db); - - SVgroupInfo info = {0}; - catalogGetTableHashVgroup(pCatalog, pTscObj->pTransporter, pEpSet, db, tNameGetTableName(&t), &info); - - int64_t transporterId = 0; - SEpSet ep = {0}; - ep.inUse = info.inUse; - ep.numOfEps = info.numOfEps; - for(int32_t i = 0; i < ep.numOfEps; ++i) { - ep.port[i] = info.epAddr[i].port; - tstrncpy(ep.fqdn[i], info.epAddr[i].fqdn, tListLen(ep.fqdn[i])); - } - - sendMsgToServer(pTscObj->pTransporter, &ep, &body, &transporterId); - } else { - int64_t transporterId = 0; - sendMsgToServer(pTscObj->pTransporter, pEpSet, &body, &transporterId); - } - - tsem_wait(&pRequest->body.rspSem); - destroyRequestMsgBody(&body); + CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); + CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return); + if (qIsDdlQuery(pQuery)) { + CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return); + goto _return; } + CHECK_CODE_GOTO(qCreateQueryDag(pQuery, &pDag), _return); + CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return); - tfree(cxt.ctx.db); - - if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - return pRequest; +_return: + qDestoryQuery(pQuery); + qDestroyQueryDag(pDag); + if (NULL != pRequest) { + pRequest->code = terrno; } - return pRequest; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 9922642df3..0f77135ec1 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -31,7 +31,7 @@ bool isInsertSql(const char* pStr, size_t length) { } while (1); } -bool qIsDclQuery(const SQueryNode* pQuery) { +bool qIsDdlQuery(const SQueryNode* pQuery) { return TSDB_SQL_INSERT != pQuery->type && TSDB_SQL_SELECT != pQuery->type; } @@ -227,3 +227,7 @@ void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) { taosArrayDestroy(pMetaReq->pTableName); taosArrayDestroy(pMetaReq->pUdf); } + +void qDestoryQuery(SQueryNode* pQuery) { + // todo +} diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index e8523249e4..6381771400 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -24,7 +24,7 @@ void qDestroyQueryDag(struct SQueryDag* pDag) { // todo } -int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SEpSet* pEpSet, struct SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) { SQueryPlanNode* logicPlan; int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index f14fd50e03..d0f6fd5adf 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -60,7 +60,7 @@ protected: return code; } SQueryDag* dag = nullptr; - code = qCreateQueryDag(query, nullptr, &dag); + code = qCreateQueryDag(query, &dag); dag_.reset(dag); return code; } From 4f099bbc9f8000147578ecdfa05cfa170c47690d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 23 Dec 2021 22:55:40 -0800 Subject: [PATCH 11/36] minor changes --- source/dnode/mnode/impl/src/mndDb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index d7e8768f65..d5e2115c7e 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -550,10 +550,10 @@ static int32_t mndSetUpdateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pO } static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { - SSdbRaw *pRedoRaw = mndDbActionEncode(pNewDb); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1; + SSdbRaw *pCommitRaw = mndDbActionEncode(pNewDb); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; return 0; } From 9acdf1e9758ed293f549f3c70a6a17b8a88dc9fe Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:00:51 +0800 Subject: [PATCH 12/36] take a commit --- include/common/common.h | 2 +- include/common/tep.h | 2 +- include/common/{taosmsg.h => tmsg.h} | 254 +++++------------- include/common/tmsgdef.h | 141 ++++++++++ include/common/ttime.h | 2 +- include/dnode/vnode/tq/tq.h | 2 +- include/libs/catalog/catalog.h | 2 +- include/libs/planner/planner.h | 2 +- include/libs/qcom/query.h | 4 +- include/libs/transport/trpc.h | 2 +- source/client/inc/clientInt.h | 4 +- source/client/src/clientEnv.c | 2 +- source/client/src/clientImpl.c | 22 +- source/client/src/clientMain.c | 2 +- source/client/src/clientMsgHandler.c | 22 +- source/common/src/taosmsg.c | 14 +- source/common/src/tname.c | 2 +- source/common/test/CMakeLists.txt | 10 + source/common/test/tmsgTest.cpp | 11 + source/dnode/mgmt/impl/inc/dndInt.h | 4 +- source/dnode/mgmt/impl/src/dndDnode.c | 18 +- source/dnode/mgmt/impl/src/dndMnode.c | 6 +- source/dnode/mgmt/impl/src/dndTransport.c | 182 ++++++------- source/dnode/mgmt/impl/src/dndVnodes.c | 12 +- source/dnode/mgmt/impl/test/acct/acct.cpp | 8 +- source/dnode/mgmt/impl/test/db/db.cpp | 10 +- source/dnode/mgmt/impl/test/dnode/dnode.cpp | 12 +- source/dnode/mgmt/impl/test/mnode/mnode.cpp | 18 +- .../dnode/mgmt/impl/test/profile/profile.cpp | 20 +- source/dnode/mgmt/impl/test/show/show.cpp | 6 +- source/dnode/mgmt/impl/test/stb/stb.cpp | 8 +- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 4 +- .../dnode/mgmt/impl/test/sut/src/client.cpp | 2 +- source/dnode/mgmt/impl/test/user/user.cpp | 8 +- source/dnode/mgmt/impl/test/vgroup/vgroup.cpp | 8 +- source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/dnode/mnode/impl/src/mndAcct.c | 6 +- source/dnode/mnode/impl/src/mndDb.c | 16 +- source/dnode/mnode/impl/src/mndDnode.c | 12 +- source/dnode/mnode/impl/src/mndFunc.c | 6 +- source/dnode/mnode/impl/src/mndMnode.c | 18 +- source/dnode/mnode/impl/src/mndProfile.c | 8 +- source/dnode/mnode/impl/src/mndShow.c | 4 +- source/dnode/mnode/impl/src/mndStb.c | 18 +- source/dnode/mnode/impl/src/mndTrans.c | 4 +- source/dnode/mnode/impl/src/mndUser.c | 6 +- source/dnode/mnode/impl/src/mndVgroup.c | 10 +- source/dnode/mnode/impl/src/mnode.c | 4 +- source/dnode/mnode/sdb/inc/sdbInt.h | 2 +- source/dnode/vnode/impl/src/vnodeRequest.c | 6 +- source/dnode/vnode/impl/src/vnodeWrite.c | 12 +- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 14 +- source/dnode/vnode/tsdb/inc/tsdbDef.h | 2 +- source/dnode/vnode/tsdb/src/tsdbHealth.c | 2 +- source/libs/catalog/src/catalog.c | 12 +- source/libs/catalog/test/catalogTests.cpp | 2 +- source/libs/executor/src/executil.c | 2 +- source/libs/executor/src/executorimpl.c | 2 +- source/libs/function/inc/texpr.h | 2 +- source/libs/function/src/taggfunction.c | 2 +- source/libs/function/src/texpr.c | 2 +- source/libs/function/src/tfill.c | 2 +- source/libs/function/src/thistogram.c | 2 +- source/libs/parser/inc/astToMsg.h | 2 +- source/libs/parser/src/astValidate.c | 18 +- source/libs/parser/src/dataBlockMgt.c | 2 +- source/libs/parser/src/parserUtil.c | 4 +- source/libs/planner/inc/plannerInt.h | 2 +- source/libs/qcom/src/queryUtil.c | 2 +- source/libs/qcom/src/querymsg.c | 14 +- source/libs/qcom/test/queryTest.cpp | 2 +- source/libs/qworker/src/qworker.c | 2 +- source/libs/scheduler/src/scheduler.c | 28 +- source/libs/transport/src/rpcMain.c | 44 +-- source/util/test/skiplistTest.cpp | 2 +- src/client/inc/tscGlobalmerge.h | 2 +- src/client/inc/tsclient.h | 2 +- src/client/src/tscLocal.c | 2 +- src/client/src/tscPrepare.c | 2 +- src/client/src/tscProfile.c | 2 +- src/client/src/tscSQLParser.c | 2 +- src/client/src/tscServer.c | 64 ++--- src/client/src/tscStream.c | 2 +- src/client/src/tscSystem.c | 2 +- src/client/src/tscUtil.c | 4 +- src/cq/src/cqMain.c | 4 +- src/cq/test/cqtest.c | 2 +- src/inc/tsdb.h | 2 +- src/kit/taosdump/taosdump.c | 2 +- src/query/inc/qExtbuffer.h | 2 +- src/query/inc/qSqlparser.h | 2 +- src/query/src/qAggMain.c | 2 +- src/query/src/qExecutor.c | 2 +- src/query/src/qExtbuffer.c | 2 +- src/query/src/qFill.c | 2 +- src/query/src/qFilterfunc.c | 2 +- src/query/src/qHistogram.c | 2 +- src/query/src/qSqlParser.c | 2 +- src/query/src/qTableMeta.c | 2 +- src/query/src/queryMain.c | 2 +- src/query/tests/astTest.cpp | 2 +- tools/shell/src/backup/tnettest.c | 10 +- 104 files changed, 662 insertions(+), 600 deletions(-) rename include/common/{taosmsg.h => tmsg.h} (72%) create mode 100644 include/common/tmsgdef.h create mode 100644 source/common/test/tmsgTest.cpp diff --git a/include/common/common.h b/include/common/common.h index 1c3a0e22f7..0ae06e5a7f 100644 --- a/include/common/common.h +++ b/include/common/common.h @@ -17,7 +17,7 @@ #define TDENGINE_COMMON_H #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tvariant.h" //typedef struct STimeWindow { diff --git a/include/common/tep.h b/include/common/tep.h index 2addc11e5a..aad5cc81d4 100644 --- a/include/common/tep.h +++ b/include/common/tep.h @@ -2,7 +2,7 @@ #define TDENGINE_TEP_H #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" typedef struct SCorEpSet { int32_t version; diff --git a/include/common/taosmsg.h b/include/common/tmsg.h similarity index 72% rename from include/common/taosmsg.h rename to include/common/tmsg.h index f0b2d0f08b..66a77839d4 100644 --- a/include/common/taosmsg.h +++ b/include/common/tmsg.h @@ -24,125 +24,30 @@ extern "C" { #include "taoserror.h" #include "tdataformat.h" -// message type +#define TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" -#ifdef TAOS_MESSAGE_C -#define TAOS_DEFINE_MESSAGE_TYPE( name, msg ) msg, msg "-rsp", -char *taosMsg[] = { - "null", -#else -#define TAOS_DEFINE_MESSAGE_TYPE( name, msg ) name, name##_RSP, -enum { - TSDB_MESSAGE_NULL = 0, -#endif +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#define TD_MSG_SEG_CODE_ +#include "tmsgdef.h" -// message from client to vnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SUBMIT, "submit" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_QUERY, "query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_FETCH, "fetch" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TABLE, "create-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TABLE, "drop-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TABLE, "alter-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_UPDATE_TAG_VAL, "update-tag-val" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLE_META, "table-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLES_META, "tables-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET_CUR, "mq-set-cur" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RES_READY, "res-ready" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TASKS_STATUS, "tasks-status" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CANCEL_TASK, "cancel-task" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TASK, "drop-task" ) +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" -// message from client to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_ACCT, "alter-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_ACCT, "drop-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_USER, "create-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_USER, "alter-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_USER, "drop-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DNODE, "create-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE, "config-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DNODE, "drop-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE, "create-mnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE, "drop-mnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DB, "create-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_USE_DB, "use-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_DB, "alter-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_DB, "sync-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_DB, "compact-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_FUNCTION, "create-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RETRIEVE_FUNCTION, "retrieve-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_FUNCTION, "drop-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_VGROUP_LIST, "vgroup-list" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW_RETRIEVE, "retrieve" ) -// message from client to qnode -// message from client to dnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) +extern char *tMsgInfo[]; +extern int tMsgDict[]; -// message from vnode to vnode -// message from vnode to mnode -// message from vnode to qnode -// message from vnode to dnode - -// message from mnode to vnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-internal" ) -// message from mnode to mnode -// message from mnode to qnode -// message from mnode to dnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_MNODE_IN, "alter-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE_IN, "drop-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE_IN, "config-dnode-internal" ) - -// message from qnode to vnode -// message from qnode to mnode -// message from qnode to qnode -// message from qnode to dnode - -// message from dnode to vnode -// message from dnode to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STATUS, "status" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_GRANT, "grant" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH, "auth" ) -// message from dnode to qnode -// message from dnode to dnode - -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY0, "dummy0" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY1, "dummy1" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY2, "dummy2" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY3, "dummy3" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY4, "dummy4" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY5, "dummy5" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY6, "dummy6" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY7, "dummy7" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY8, "dummy8" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY9, "dummy9" ) - -#ifndef TAOS_MESSAGE_C - TSDB_MSG_TYPE_MAX // 147 -#endif - -}; +#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) +#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) +#define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] // IE type #define TSDB_IE_TYPE_SEC 1 @@ -178,48 +83,46 @@ typedef enum _mgmt_table { TSDB_MGMT_TABLE_MAX, } EShowType; -#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1 -#define TSDB_ALTER_TABLE_DROP_TAG_COLUMN 2 +#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1 +#define TSDB_ALTER_TABLE_DROP_TAG_COLUMN 2 #define TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN 3 -#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 +#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 -#define TSDB_ALTER_TABLE_ADD_COLUMN 5 -#define TSDB_ALTER_TABLE_DROP_COLUMN 6 -#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7 +#define TSDB_ALTER_TABLE_ADD_COLUMN 5 +#define TSDB_ALTER_TABLE_DROP_COLUMN 6 +#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7 #define TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN 8 -#define TSDB_FILL_NONE 0 -#define TSDB_FILL_NULL 1 -#define TSDB_FILL_SET_VALUE 2 -#define TSDB_FILL_LINEAR 3 -#define TSDB_FILL_PREV 4 -#define TSDB_FILL_NEXT 5 +#define TSDB_FILL_NONE 0 +#define TSDB_FILL_NULL 1 +#define TSDB_FILL_SET_VALUE 2 +#define TSDB_FILL_LINEAR 3 +#define TSDB_FILL_PREV 4 +#define TSDB_FILL_NEXT 5 -#define TSDB_ALTER_USER_PASSWD 0x1 +#define TSDB_ALTER_USER_PASSWD 0x1 #define TSDB_ALTER_USER_PRIVILEGES 0x2 -#define TSDB_KILL_MSG_LEN 30 +#define TSDB_KILL_MSG_LEN 30 -#define TSDB_VN_READ_ACCCESS ((char)0x1) -#define TSDB_VN_WRITE_ACCCESS ((char)0x2) +#define TSDB_VN_READ_ACCCESS ((char)0x1) +#define TSDB_VN_WRITE_ACCCESS ((char)0x2) #define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS) -#define TSDB_COL_NORMAL 0x0u // the normal column of the table -#define TSDB_COL_TAG 0x1u // the tag column type -#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column -#define TSDB_COL_TMP 0x4u // internal column generated by the previous operators -#define TSDB_COL_NULL 0x8u // the column filter NULL or not +#define TSDB_COL_NORMAL 0x0u // the normal column of the table +#define TSDB_COL_TAG 0x1u // the tag column type +#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column +#define TSDB_COL_TMP 0x4u // internal column generated by the previous operators +#define TSDB_COL_NULL 0x8u // the column filter NULL or not -#define TSDB_COL_IS_TAG(f) (((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0) -#define TSDB_COL_IS_NORMAL_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL) -#define TSDB_COL_IS_UD_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC) -#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0) - -extern char *taosMsg[]; +#define TSDB_COL_IS_TAG(f) (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0) +#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL) +#define TSDB_COL_IS_UD_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC) +#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0) typedef struct SBuildTableMetaInput { int32_t vgId; - char *tableFullName; + char * tableFullName; } SBuildTableMetaInput; typedef struct SBuildUseDBInput { @@ -227,7 +130,6 @@ typedef struct SBuildUseDBInput { int32_t vgVersion; } SBuildUseDBInput; - #pragma pack(push, 1) // null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta @@ -312,7 +214,7 @@ typedef struct { char data[]; } SMDCreateTableMsg; -//typedef struct { +// typedef struct { // int32_t len; // one create table message // char tableName[TSDB_TABLE_FNAME_LEN]; // int16_t numOfColumns; @@ -442,7 +344,7 @@ 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 + int8_t superUser; // denote if it is a super user or not int32_t reserve[8]; } SCreateUserMsg, SAlterUserMsg; @@ -578,8 +480,8 @@ typedef struct { int32_t sqlstrLen; // sql query string int32_t prevResultLen; // previous result length int32_t numOfOperator; - int32_t tableScanOperator;// table scan operator. -1 means no scan operator - int32_t udfNum; // number of udf function + int32_t tableScanOperator; // table scan operator. -1 means no scan operator + int32_t udfNum; // number of udf function int32_t udfContentOffset; int32_t udfContentLen; SColumnInfo tableCols[]; @@ -882,7 +784,7 @@ typedef struct SMultiTableMeta { typedef struct { int32_t dataLen; char name[TSDB_TABLE_FNAME_LEN]; - char *data; + char * data; } STagData; typedef struct { @@ -917,7 +819,7 @@ typedef struct SShowRsp { } SShowRsp; typedef struct { - char ep[TSDB_EP_LEN]; // end point, hostname:port + char ep[TSDB_EP_LEN]; // end point, hostname:port } SCreateDnodeMsg; typedef struct { @@ -1019,35 +921,27 @@ typedef struct { // mq related typedef struct { - } SMqConnectReq; typedef struct { - } SMqConnectRsp; typedef struct { - } SMqDisconnectReq; typedef struct { - } SMqDisconnectRsp; typedef struct { - } SMqAckReq; typedef struct { - } SMqAckRsp; typedef struct { - } SMqResetReq; typedef struct { - } SMqResetRsp; // mq related end @@ -1104,17 +998,17 @@ typedef struct { } SUpdateTagValRsp; typedef struct SSubQueryMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; - uint32_t contentLen; - char msg[]; + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; + uint32_t contentLen; + char msg[]; } SSubQueryMsg; typedef struct SResReadyMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; } SResReadyMsg; typedef struct SResReadyRsp { @@ -1122,19 +1016,19 @@ typedef struct SResReadyRsp { } SResReadyRsp; typedef struct SResFetchMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; } SResFetchMsg; typedef struct SSchTasksStatusMsg { - uint64_t schedulerId; + uint64_t schedulerId; } SSchTasksStatusMsg; typedef struct STaskStatus { - uint64_t queryId; - uint64_t taskId; - int8_t status; + uint64_t queryId; + uint64_t taskId; + int8_t status; } STaskStatus; typedef struct SSchedulerStatusRsp { @@ -1142,11 +1036,10 @@ typedef struct SSchedulerStatusRsp { STaskStatus status[]; } SSchedulerStatusRsp; - typedef struct STaskCancelMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; } STaskCancelMsg; typedef struct STaskCancelRsp { @@ -1154,16 +1047,15 @@ typedef struct STaskCancelRsp { } STaskCancelRsp; typedef struct STaskDropMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; } STaskDropMsg; typedef struct STaskDropRsp { int32_t code; } STaskDropRsp; - #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h new file mode 100644 index 0000000000..eb23d7b2af --- /dev/null +++ b/include/common/tmsgdef.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#if 0 +#undef TD_MSG_INFO_ +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_SEG_CODE_ +#endif + +#if defined(TD_MSG_INFO_) + +#define TD_NEW_MSG_SEG(TYPE) "null", +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) MSG, MSG "-rsp", + +char *tMsgInfo[] = { + +#elif defined(TD_MSG_NUMBER_) + +#define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE##_NUM, TYPE##_RSP_NUM, + +enum { + +#elif defined(TD_MSG_DICT_) + +#define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) + +int tMsgDict[] = { + +#elif defined(TD_MSG_SEG_CODE_) + +#define TD_NEW_MSG_SEG(TYPE) TYPE##_SEG_CODE, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) + +enum { + +#else + +#define TD_NEW_MSG_SEG(TYPE) TYPE = ((TYPE##_SEG_CODE) << 8), +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE, TYPE##_RSP, + +enum { +#endif + // Requests handled by DNODE + TD_NEW_MSG_SEG(TDMT_DND_MSG) + TD_DEF_MSG_TYPE(TDMT_DND_NETWORK_TEST, "dnode-nettest", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "dnode-create-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_VNODE, "dnode-alter-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "dnode-drop-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_AUTH_VNODE, "dnode-auth-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_SYNC_VNODE, "dnode-sync-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_COMPACT_VNODE, "dnode-compact-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE, "dnode-alter-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_MNODE, "dnode-drop-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CONFIG_DNODE, "dnode-config-dnode", NULL, NULL) + + // Requests handled by MNODE + TD_NEW_MSG_SEG(TDMT_MND_MSG) + TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "mnode-connect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TABLE, "mnode-create-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_TABLE, "mnode-drop-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "mnode-create-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_ACCT, "mnode-alter-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_ACCT, "mnode-drop-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "mnode-create-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "mnode-alter-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "mnode-drop-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "mnode-create-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "mnode-drop-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "mnode-create-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "mnode-drop-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "mnode-use-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "mnode-alter-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "mnode-sync-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "mnode-compact-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNCTION, "mnode-create-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNCTION, "mnode-retrieve-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNCTION, "mnode-drop-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL) + TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_STATUS, "mnode-status", NULL, NULL) + TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_GRANT, "mnode-grant", NULL, NULL) + TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_AUTH, "mnode-auth", NULL, NULL) + + // Requests handled by VNODE + TD_NEW_MSG_SEG(TDMT_VND_MSG) + TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "vnode-submit", SSubmitReq, SSubmitRsp) + TD_DEF_MSG_TYPE(TDMT_VND_QUERY, "vnode-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_FETCH, "vnode-fetch", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TABLE, "vnode-alter-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "vnode-update-tag-val", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_DISCONNECT, "vnode-mq-disconnect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CUR, "vnode-mq-set-cur", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_RES_READY, "vnode-res-ready", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TASKS_STATUS, "vnode-tasks-status", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TASK, "vnode-drop-task", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL) + + // Requests handled by QNODE + TD_NEW_MSG_SEG(TDMT_QND_MSG) + + // Requests handled by SNODE + TD_NEW_MSG_SEG(TDMT_SND_MSG) + +#if defined(TD_MSG_NUMBER_) + TDMT_MAX +#endif +}; \ No newline at end of file diff --git a/include/common/ttime.h b/include/common/ttime.h index ed6496aca6..e22e1d6c4e 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -21,7 +21,7 @@ extern "C" { #endif #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y') diff --git a/include/dnode/vnode/tq/tq.h b/include/dnode/vnode/tq/tq.h index f5d5cc9a16..b6cb96a57b 100644 --- a/include/dnode/vnode/tq/tq.h +++ b/include/dnode/vnode/tq/tq.h @@ -20,7 +20,7 @@ #include "mallocator.h" #include "os.h" #include "taoserror.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlist.h" #include "trpc.h" #include "ttimer.h" diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 592c5f707c..60c688d95b 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -26,7 +26,7 @@ extern "C" { #include "taosdef.h" #include "transport.h" #include "common.h" -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" struct SCatalog; diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index d4469be5e3..a4c9522094 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -20,7 +20,7 @@ extern "C" { #endif -#include "taosmsg.h" +#include "tmsg.h" #define QUERY_TYPE_MERGE 1 #define QUERY_TYPE_PARTIAL 2 diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 877cfb130c..abb13dfe71 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -112,8 +112,8 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code); SSchema* tGetTbnameColumnSchema(); void initQueryModuleMsgHandle(); -extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); -extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize); +extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); +extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize); #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) #define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 2afd9d48b7..976c0b8bb4 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -22,7 +22,7 @@ extern "C" { #include #include #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #define TAOS_CONN_SERVER 0 #define TAOS_CONN_CLIENT 1 diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index a34250ccab..f73876313a 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -22,7 +22,7 @@ extern "C" { #include "taos.h" #include "common.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tdef.h" #include "tep.h" #include "thash.h" @@ -140,7 +140,7 @@ extern int32_t tscReqRef; extern int32_t tscConnRef; SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest); -extern int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); +extern int (*handleRequestRspFp[TDMT_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); int taos_init(); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index b54f7fedd7..2cb367aaaa 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -18,7 +18,7 @@ #include "clientLog.h" #include "os.h" #include "query.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcache.h" #include "tconfig.h" #include "tglobal.h" diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index f00e7bd578..e88b9b8b84 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -114,10 +114,10 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, } static bool supportedQueryType(int32_t type) { - return (type == TSDB_MSG_TYPE_CREATE_USER || type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_DROP_USER || - type == TSDB_MSG_TYPE_DROP_ACCT || type == TSDB_MSG_TYPE_CREATE_DB || type == TSDB_MSG_TYPE_CREATE_ACCT || - type == TSDB_MSG_TYPE_CREATE_TABLE || type == TSDB_MSG_TYPE_CREATE_STB || type == TSDB_MSG_TYPE_USE_DB || - type == TSDB_MSG_TYPE_DROP_DB || type == TSDB_MSG_TYPE_DROP_STB); + return (type == TDMT_MND_CREATE_USER || type == TDMT_MND_SHOW || type == TDMT_MND_DROP_USER || + type == TDMT_MND_DROP_ACCT || type == TDMT_MND_CREATE_DB || type == TDMT_MND_CREATE_ACCT || + type == TDMT_MND_CREATE_TABLE || type == TDMT_MND_CREATE_STB || type == TDMT_MND_USE_DB || + type == TDMT_MND_DROP_DB || type == TDMT_MND_DROP_STB); } TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { @@ -169,7 +169,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { SRequestMsgBody body = buildRequestMsgImpl(pRequest); SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; - if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) { + if (pDcl->msgType == TDMT_MND_CREATE_TABLE) { struct SCatalog* pCatalog = NULL; char buf[12] = {0}; @@ -263,7 +263,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con return pTscObj; } - SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_MSG_TYPE_CONNECT); + SRequestObj *pRequest = createRequest(pTscObj, fp, param, TDMT_MND_CONNECT); if (pRequest == NULL) { destroyTscObj(pTscObj); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -295,7 +295,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con } static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT; + pMsgBody->msgType = TDMT_MND_CONNECT; pMsgBody->msgInfo.len = sizeof(SConnectMsg); pMsgBody->requestObjRefId = pRequest->self; @@ -327,7 +327,7 @@ static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody) { int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId) { char *pMsg = rpcMallocCont(pBody->msgInfo.len); if (NULL == pMsg) { - tscError("0x%"PRIx64" msg:%s malloc failed", pBody->requestId, taosMsg[pBody->msgType]); + tscError("0x%"PRIx64" msg:%s malloc failed", pBody->requestId, TMSG_INFO(pBody->msgType)); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return -1; } @@ -372,7 +372,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { * The actual inserted number of points is the first number. */ if (pMsg->code == TSDB_CODE_SUCCESS) { - tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType], + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start); if (handleRequestRspFp[pRequest->type]) { char *p = malloc(pMsg->contLen); @@ -385,7 +385,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { } } } else { - tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, taosMsg[pMsg->msgType], + tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start); } @@ -427,7 +427,7 @@ void* doFetchRow(SRequestObj* pRequest) { SReqResultInfo* pResultInfo = &pRequest->body.resInfo; if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) { - pRequest->type = TSDB_MSG_TYPE_SHOW_RETRIEVE; + pRequest->type = TDMT_MND_SHOW_RETRIEVE; SRequestMsgBody body = buildRequestMsgImpl(pRequest); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index f50765d37a..f521e109c8 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2,7 +2,7 @@ #include "clientInt.h" #include "clientLog.h" #include "query.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tref.h" #include "trpc.h" diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 548ea3d725..1f737b33d2 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -21,10 +21,10 @@ #include "tmsgtype.h" #include "trpc.h" -int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); +int (*handleRequestRspFp[TDMT_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT; + pMsgBody->msgType = TDMT_MND_CONNECT; pMsgBody->msgInfo.len = sizeof(SConnectMsg); pMsgBody->requestObjRefId = pRequest->self; @@ -87,7 +87,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { } static int32_t buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; + pMsgBody->msgType = TDMT_MND_SHOW_RETRIEVE; pMsgBody->msgInfo.len = sizeof(SRetrieveTableMsg); pMsgBody->requestObjRefId = pRequest->self; @@ -102,7 +102,7 @@ static int32_t buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMs } SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest) { - if (pRequest->type == TSDB_MSG_TYPE_SHOW_RETRIEVE) { + if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { SRequestMsgBody body = {0}; buildRetrieveMnodeMsg(pRequest, &body); return body; @@ -273,11 +273,11 @@ void initMsgHandleFp() { tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; #endif - handleRequestRspFp[TSDB_MSG_TYPE_CONNECT] = processConnectRsp; - handleRequestRspFp[TSDB_MSG_TYPE_SHOW] = processShowRsp; - handleRequestRspFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = processRetrieveMnodeRsp; - handleRequestRspFp[TSDB_MSG_TYPE_CREATE_DB] = processCreateDbRsp; - handleRequestRspFp[TSDB_MSG_TYPE_USE_DB] = processUseDbRsp; - handleRequestRspFp[TSDB_MSG_TYPE_CREATE_TABLE] = processCreateTableRsp; - handleRequestRspFp[TSDB_MSG_TYPE_DROP_DB] = processDropDbRsp; + handleRequestRspFp[TDMT_MND_CONNECT] = processConnectRsp; + handleRequestRspFp[TDMT_MND_SHOW] = processShowRsp; + handleRequestRspFp[TDMT_MND_SHOW_RETRIEVE] = processRetrieveMnodeRsp; + handleRequestRspFp[TDMT_MND_CREATE_DB] = processCreateDbRsp; + handleRequestRspFp[TDMT_MND_USE_DB] = processUseDbRsp; + handleRequestRspFp[TDMT_MND_CREATE_TABLE] = processCreateTableRsp; + handleRequestRspFp[TDMT_MND_DROP_DB] = processDropDbRsp; } \ No newline at end of file diff --git a/source/common/src/taosmsg.c b/source/common/src/taosmsg.c index b35e3f1478..a7f285046c 100644 --- a/source/common/src/taosmsg.c +++ b/source/common/src/taosmsg.c @@ -13,8 +13,16 @@ * along with this program. If not, see . */ -#define TAOS_MESSAGE_C - -#include "taosmsg.h" +#include "tmsg.h" +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#define TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" +#undef TD_MSG_NUMBER_ +#undef TD_MSG_INFO_ +#define TD_MSG_DICT_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" \ No newline at end of file diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 9661016483..e24c8f7a81 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -2,7 +2,7 @@ #include "tutil.h" #include "tname.h" -#include "taosmsg.h" +#include "tmsg.h" #define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T) diff --git a/source/common/test/CMakeLists.txt b/source/common/test/CMakeLists.txt index f4c849780d..ee2e55533e 100644 --- a/source/common/test/CMakeLists.txt +++ b/source/common/test/CMakeLists.txt @@ -16,3 +16,13 @@ TARGET_INCLUDE_DIRECTORIES( PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/common/" PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/common/inc" ) + +# tmsg test +add_executable(tmsgTest "") +target_sources(tmsgTest + PRIVATE + "tmsgTest.cpp" + "../src/taosmsg.c" +) +target_include_directories(tmsgTest PUBLIC "${CMAKE_SOURCE_DIR}/include/common/") +target_link_libraries(tmsgTest PUBLIC os util gtest gtest_main) \ No newline at end of file diff --git a/source/common/test/tmsgTest.cpp b/source/common/test/tmsgTest.cpp new file mode 100644 index 0000000000..ca33d24a8c --- /dev/null +++ b/source/common/test/tmsgTest.cpp @@ -0,0 +1,11 @@ +#include + +#include "gtest/gtest.h" + +#include "tmsg.h" + +TEST(td_msg_test, simple_msg_test) { + // std::cout << TMSG_INFO(TDMT_VND_DROP_TABLE) << std::endl; + // std::cout << TMSG_INFO(TDMT_MND_DROP_SUPER_TABLE) << std::endl; + // std::cout << TMSG_INFO(TDMT_MND_CREATE_SUPER_TABLE) << std::endl; +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index d8acda530d..8973574d23 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -22,7 +22,7 @@ extern "C" { #include "cJSON.h" #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" @@ -105,7 +105,7 @@ typedef struct { typedef struct { void *serverRpc; void *clientRpc; - DndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; + DndMsgFp msgFp[TDMT_MAX]; } STransMgmt; typedef struct SDnode { diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 9e2d4d4c9b..df82855c36 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -68,7 +68,7 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dDebug("RPC %p, msg:%s is redirected, num:%d inUse:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse); + dDebug("RPC %p, msg:%s is redirected, num:%d inUse:%d", pMsg->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]); if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) { @@ -369,7 +369,7 @@ void dndSendStatusMsg(SDnode *pDnode) { dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); - SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_STATUS}; + SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS}; pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); @@ -556,14 +556,14 @@ void dndCleanupDnode(SDnode *pDnode) { void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { switch (pMsg->msgType) { - case TSDB_MSG_TYPE_NETWORK_TEST: + case TDMT_DND_NETWORK_TEST: dndProcessStartupReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_CONFIG_DNODE_IN: + case TDMT_DND_CONFIG_DNODE: dndProcessConfigDnodeReq(pDnode, pMsg); break; default: - dError("RPC %p, dnode req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); + dError("RPC %p, dnode req:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType)); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; rpcSendResponse(&rspMsg); } @@ -574,17 +574,17 @@ void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { switch (pMsg->msgType) { - case TSDB_MSG_TYPE_STATUS_RSP: + case TDMT_MND_STATUS_RSP: dndProcessStatusRsp(pDnode, pMsg, pEpSet); break; - case TSDB_MSG_TYPE_AUTH_RSP: + case TDMT_MND_AUTH_RSP: dndProcessAuthRsp(pDnode, pMsg, pEpSet); break; - case TSDB_MSG_TYPE_GRANT_RSP: + case TDMT_MND_GRANT_RSP: dndProcessGrantRsp(pDnode, pMsg, pEpSet); break; default: - dError("RPC %p, dnode rsp:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); + dError("RPC %p, dnode rsp:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType)); } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index c4d69c4626..c62c05fe2f 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -552,13 +552,13 @@ static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { int32_t code = 0; switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_MNODE_IN: + case TDMT_DND_CREATE_MNODE: code = dndProcessCreateMnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_ALTER_MNODE_IN: + case TDMT_DND_ALTER_MNODE: code = dndProcessAlterMnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_DROP_MNODE_IN: + case TDMT_DND_DROP_MNODE: code = dndProcessDropMnodeReq(pDnode, pMsg); break; default: diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index 3d797eba8f..ac00e1e4f2 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -31,97 +31,97 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { // msg from client to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_SUBMIT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_FETCH] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_SET_CUR] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_RES_READY] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TASKS_STATUS] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CANCEL_TASK] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TASK] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TDMT_VND_SUBMIT] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_QUERY] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TDMT_VND_FETCH] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TDMT_MND_CREATE_TABLE] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_TABLE] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_ALTER_TABLE] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_TABLE_META] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_VND_TABLES_META] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TDMT_VND_MQ_QUERY] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TDMT_VND_MQ_CONSUME] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TDMT_VND_MQ_CONNECT] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_MQ_SET_CUR] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_RES_READY] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TDMT_VND_TASKS_STATUS] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TDMT_VND_CANCEL_TASK] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TDMT_VND_DROP_TASK] = dndProcessVnodeFetchMsg; // msg from client to mnode - pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_USE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_RETRIEVE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_VGROUP_LIST] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SHOW] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_CONNECT] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_CREATE_ACCT] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_ALTER_ACCT] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_ACCT] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_USER] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_ALTER_USER] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_USER] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_DNODE] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CONFIG_DNODE] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_DNODE] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_MNODE] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_MNODE] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_USE_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_ALTER_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_SYNC_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_COMPACT_DB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_FUNCTION] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_RETRIEVE_FUNCTION] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_FUNCTION] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_CREATE_STB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_ALTER_STB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_DROP_STB] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_VGROUP_LIST] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_KILL_QUERY] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_KILL_CONN] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_HEARTBEAT] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_SHOW] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_SHOW_RETRIEVE] = dndProcessMnodeReadMsg; // message from client to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dndProcessDnodeReq; + pMgmt->msgFp[TDMT_DND_NETWORK_TEST] = dndProcessDnodeReq; // message from mnode to vnode - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_CREATE_STB] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_CREATE_STB_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_ALTER_STB] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_ALTER_STB_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_DROP_STB] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TDMT_VND_DROP_STB_RSP] = dndProcessMnodeWriteMsg; // message from mnode to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = dndProcessDnodeReq; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_CREATE_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_CREATE_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_ALTER_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_ALTER_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_DROP_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_DROP_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_SYNC_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_SYNC_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_AUTH_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_AUTH_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_COMPACT_VNODE] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_COMPACT_VNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_CREATE_MNODE] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_CREATE_MNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_ALTER_MNODE] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_ALTER_MNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_DROP_MNODE] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TDMT_DND_DROP_MNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_DND_CONFIG_DNODE] = dndProcessDnodeReq; + pMgmt->msgFp[TDMT_DND_CONFIG_DNODE_RSP] = dndProcessMnodeWriteMsg; // message from dnode to mnode - pMgmt->msgFp[TSDB_MSG_TYPE_GRANT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TSDB_MSG_TYPE_STATUS] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dndProcessDnodeRsp; + pMgmt->msgFp[TDMT_MND_GRANT] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_GRANT_RSP] = dndProcessDnodeRsp; + pMgmt->msgFp[TDMT_MND_STATUS] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TDMT_MND_STATUS_RSP] = dndProcessDnodeRsp; + pMgmt->msgFp[TDMT_MND_AUTH] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TDMT_MND_AUTH_RSP] = dndProcessDnodeRsp; } static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { @@ -132,7 +132,7 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) { if (pMsg == NULL || pMsg->pCont == NULL) return; - dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]); + dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); return; } @@ -140,9 +140,9 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { DndMsgFp fp = pMgmt->msgFp[msgType]; if (fp != NULL) { (*fp)(pDnode, pMsg, pEpSet); - dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, taosMsg[msgType], pMsg->code & 0XFFFF); + dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); } else { - dError("RPC %p, rsp:%s not processed", pMsg->handle, taosMsg[msgType]); + dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); } } @@ -187,20 +187,20 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { STransMgmt *pMgmt = &pDnode->tmgmt; int32_t msgType = pMsg->msgType; - if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { + if (msgType == TDMT_DND_NETWORK_TEST) { dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pMsg->handle, pMsg->ahandle, pMsg->code); dndProcessDnodeReq(pDnode, pMsg, pEpSet); return; } if (dndGetStat(pDnode) == DND_STAT_STOPPED) { - dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + 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}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); return; } else if (dndGetStat(pDnode) != DND_STAT_RUNNING) { - dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); @@ -208,7 +208,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { } if (pMsg->pCont == NULL) { - dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN}; rpcSendResponse(&rspMsg); return; @@ -216,10 +216,10 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { DndMsgFp fp = pMgmt->msgFp[msgType]; if (fp != NULL) { - dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); (*fp)(pDnode, pMsg, pEpSet); } else { - dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); @@ -281,7 +281,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); tstrncpy(pMsg->user, user, TSDB_USER_LEN); - SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TSDB_MSG_TYPE_AUTH}; + SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TDMT_MND_AUTH}; SRpcMsg rpcRsp = {0}; dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index 598d6e47be..05fb28e256 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -773,22 +773,22 @@ static void dndProcessVnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { int32_t code = 0; switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_VNODE_IN: + case TDMT_DND_CREATE_VNODE: code = dndProcessCreateVnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_ALTER_VNODE_IN: + case TDMT_DND_ALTER_VNODE: code = dndProcessAlterVnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_DROP_VNODE_IN: + case TDMT_DND_DROP_VNODE: code = dndProcessDropVnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_AUTH_VNODE_IN: + case TDMT_DND_AUTH_VNODE: code = dndProcessAuthVnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_SYNC_VNODE_IN: + case TDMT_DND_SYNC_VNODE: code = dndProcessSyncVnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_COMPACT_VNODE_IN: + case TDMT_DND_COMPACT_VNODE: code = dndProcessCompactVnodeReq(pDnode, pMsg); break; default: diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mgmt/impl/test/acct/acct.cpp index 69ddae675d..be0ad4ab0f 100644 --- a/source/dnode/mgmt/impl/test/acct/acct.cpp +++ b/source/dnode/mgmt/impl/test/acct/acct.cpp @@ -30,7 +30,7 @@ TEST_F(DndTestAcct, 01_CreateAcct) { SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -40,7 +40,7 @@ TEST_F(DndTestAcct, 02_AlterAcct) { SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -50,7 +50,7 @@ TEST_F(DndTestAcct, 03_DropAcct) { SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -61,7 +61,7 @@ TEST_F(DndTestAcct, 04_ShowAcct) { SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); pReq->type = TSDB_MGMT_TABLE_ACCT; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 79a7477cea..5c67c10817 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -77,7 +77,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -138,7 +138,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->quorum = 2; pReq->cacheLastRow = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -199,7 +199,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -237,7 +237,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -256,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { strcpy(pReq->db, "1.d2"); pReq->vgVersion = htonl(-1); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_USE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_USE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index c9708ec1cf..4009a83cd0 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -81,7 +81,7 @@ TEST_F(DndTestDnode, 02_ConfigDnode) { pReq->dnodeId = htonl(1); strcpy(pReq->config, "ddebugflag 131"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONFIG_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -93,7 +93,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->ep, "localhost:9042"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -126,7 +126,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -150,7 +150,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->ep, "localhost:9043"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -161,7 +161,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->ep, "localhost:9044"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -172,7 +172,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->ep, "localhost:9045"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp index 6724c85500..0d89542288 100644 --- a/source/dnode/mgmt/impl/test/mnode/mnode.cpp +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -77,7 +77,7 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) { SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_MNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); } @@ -90,7 +90,7 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) { SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_MNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } @@ -104,7 +104,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->ep, "localhost:9062"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -121,7 +121,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_MNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -148,7 +148,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SDropMnodeMsg* pReq = (SDropMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_MNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -169,7 +169,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); // pReq->dnodeId = htonl(2); -// SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen); +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); // ASSERT_NE(pMsg, nullptr); // ASSERT_EQ(pMsg->code, 0); // } @@ -193,7 +193,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9063"); -// SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // ASSERT_NE(pMsg, nullptr); // ASSERT_EQ(pMsg->code, 0); // } @@ -204,7 +204,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9064"); -// SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // ASSERT_NE(pMsg, nullptr); // ASSERT_EQ(pMsg->code, 0); // } @@ -215,7 +215,7 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9065"); -// SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // ASSERT_NE(pMsg, nullptr); // ASSERT_EQ(pMsg->code, 0); // } diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 2e82d4d1aa..081f9e7ef5 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -35,7 +35,7 @@ TEST_F(DndTestProfile, 01_ConnectMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -67,7 +67,7 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, "invalid_db"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB); ASSERT_EQ(pMsg->contLen, 0); @@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -138,7 +138,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -153,7 +153,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION); ASSERT_EQ(pMsg->contLen, 0); @@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -198,7 +198,7 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } @@ -211,7 +211,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->connId = htonl(connId); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->contLen, 0); @@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -261,7 +261,7 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { pReq->connId = htonl(2345); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp index bec681cb8f..a0df0f2921 100644 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ b/source/dnode/mgmt/impl/test/show/show.cpp @@ -32,7 +32,7 @@ TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { pReq->type = TSDB_MGMT_TABLE_MAX; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } @@ -44,7 +44,7 @@ TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { pReq->type = TSDB_MGMT_TABLE_START; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } @@ -57,7 +57,7 @@ TEST_F(DndTestShow, 02_ShowMsg_Conn) { strcpy(pReq->app, "dnode_test_show"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index 992ebaf902..e67a3ea8cf 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -51,7 +51,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -106,7 +106,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { strcpy(pSchema->name, "tag3"); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_STB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -133,7 +133,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen); strcpy(pReq->tableFname, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_TABLE_META, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_VND_TABLE_META, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -192,7 +192,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen); strcpy(pReq->name, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_STB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index b0de6f5c0c..7b62b0299d 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -20,7 +20,7 @@ #include "os.h" #include "dnode.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tconfig.h" #include "tdataformat.h" #include "tglobal.h" diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 59e99b1e1d..76d742d751 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -75,7 +75,7 @@ void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { pShow->type = showType; strcpy(pShow->db, db); - SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW, pShow, contLen); + SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen); SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; ASSERT(pShowRsp != nullptr); @@ -124,7 +124,7 @@ void Testbase::SendShowRetrieveMsg() { pRetrieve->showId = htonl(showId); pRetrieve->free = 0; - SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW_RETRIEVE, pRetrieve, contLen); + SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index fce3da1507..13429cec28 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -18,7 +18,7 @@ static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; client->SetRpcRsp(pMsg); - uInfo("response:%s from dnode, code:0x%x", taosMsg[pMsg->msgType], pMsg->code); + uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code); tsem_post(client->GetSem()); } diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp index a1810e7ada..aa160304c8 100644 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ b/source/dnode/mgmt/impl/test/user/user.cpp @@ -51,7 +51,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -63,7 +63,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -94,7 +94,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -124,7 +124,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index c534fcbabe..718fbea50d 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -60,7 +60,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -100,7 +100,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -119,9 +119,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pReq; rpcMsg.contLen = sizeof(SDropVnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + rpcMsg.msgType = TDMT_DND_DROP_VNODE; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index a0404d5bcc..fe01daa1a7 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -20,7 +20,7 @@ #include "cJSON.h" #include "sync.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "tlog.h" #include "trpc.h" diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index ba72d95537..5c78289102 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -77,7 +77,7 @@ typedef struct SMnode { SShowMgmt showMgmt; SProfileMgmt profileMgmt; STelemMgmt telemMgmt; - MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; + MndMsgFp msgFp[TDMT_MAX]; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 4c2706f481..767f628306 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndAcctActionUpdate, .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_ACCT, mndProcessCreateAcctMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_ACCT, mndProcessAlterAcctMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_ACCT, mndProcessDropAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); return sdbSetTable(pMnode->pSdb, table); } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 7c12714a46..306ebce599 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -48,12 +48,12 @@ int32_t mndInitDb(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndDbActionUpdate, .deleteFp = (SdbDeleteFp)mndDbActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_DB, mndProcessCreateDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_DB, mndProcessAlterDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_DB, mndProcessDropDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_USE_DB, mndProcessUseDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SYNC_DB, mndProcessSyncDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_COMPACT_DB, mndProcessCompactDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DB, mndProcessCreateDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_DB, mndProcessAlterDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_DB, mndProcessDropDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SYNC_DB, mndProcessSyncDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_DB, mndGetDbMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs); @@ -311,7 +311,7 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.pCont = pMsg; action.contLen = sizeof(SCreateVnodeMsg); - action.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN; + action.msgType = TDMT_DND_CREATE_VNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; @@ -340,7 +340,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.pCont = pMsg; action.contLen = sizeof(SDropVnodeMsg); - action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + action.msgType = TDMT_DND_DROP_VNODE; if (mndTransAppendUndoAction(pTrans, &action) != 0) { free(pMsg); return -1; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 9751771773..f13bbed247 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -73,11 +73,11 @@ int32_t mndInitDnode(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndDnodeActionUpdate, .deleteFp = (SdbDeleteFp)mndDnodeActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_DNODE, mndProcessCreateDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_DNODE, mndProcessDropDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONFIG_DNODE, mndProcessConfigDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP, mndProcessConfigDnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_STATUS, mndProcessStatusMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp); + mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndGetConfigMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndRetrieveConfigs); @@ -527,7 +527,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) { pCfgDnode->dnodeId = htonl(pCfg->dnodeId); memcpy(pCfgDnode->config, pCfg->config, TSDB_DNODE_CONFIG_LEN); - SRpcMsg rpcMsg = {.msgType = TSDB_MSG_TYPE_CONFIG_DNODE_IN, + SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pCfgDnode, .contLen = sizeof(SCfgDnodeMsg), .ahandle = pMsg->rpcMsg.ahandle}; diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index a513c9d57d..7e9d4ebeab 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -44,9 +44,9 @@ int32_t mndInitFunc(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndFuncActionUpdate, .deleteFp = (SdbDeleteFp)mndFuncActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_FUNCTION, mndProcessCreateFuncMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_FUNCTION, mndProcessDropFuncMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_RETRIEVE_FUNCTION, mndProcessRetrieveFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_FUNCTION, mndProcessCreateFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_FUNCTION, mndProcessDropFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_RETRIEVE_FUNCTION, mndProcessRetrieveFuncMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndGetFuncMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndRetrieveFuncs); diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index a019c0dc55..9f76060063 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -47,11 +47,11 @@ int32_t mndInitMnode(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndMnodeActionUpdate, .deleteFp = (SdbDeleteFp)mndMnodeActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_MNODE, mndProcessCreateMnodeReq); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_MNODE, mndProcessDropMnodeReq); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP, mndProcessCreateMnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_MNODE_IN_RSP, mndProcessAlterMnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_MNODE_IN_RSP, mndProcessDropMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_MNODE, mndProcessCreateMnodeReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_MNODE_RSP, mndProcessCreateMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE_RSP, mndProcessAlterMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndProcessDropMnodeRsp); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndGetMnodeMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes); @@ -293,7 +293,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno action.epSet = mndGetDnodeEpset(pMObj->pDnode); action.pCont = pMsg; action.contLen = sizeof(SAlterMnodeInMsg); - action.msgType = TSDB_MSG_TYPE_ALTER_MNODE_IN; + action.msgType = TDMT_DND_ALTER_MNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -317,7 +317,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; action.contLen = sizeof(SCreateMnodeInMsg); - action.msgType = TSDB_MSG_TYPE_CREATE_MNODE_IN; + action.msgType = TDMT_DND_CREATE_MNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; @@ -461,7 +461,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode action.epSet = mndGetDnodeEpset(pMObj->pDnode); action.pCont = pMsg; action.contLen = sizeof(SAlterMnodeInMsg); - action.msgType = TSDB_MSG_TYPE_ALTER_MNODE_IN; + action.msgType = TDMT_DND_ALTER_MNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -488,7 +488,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; action.contLen = sizeof(SDropMnodeInMsg); - action.msgType = TSDB_MSG_TYPE_DROP_MNODE_IN; + action.msgType = TDMT_DND_DROP_MNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index a4b73e0f3f..833be3884c 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -68,10 +68,10 @@ int32_t mndInitProfile(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_HEARTBEAT, mndProcessHeartBeatMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONNECT, mndProcessConnectMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_QUERY, mndProcessKillQueryMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_CONN, mndProcessKillConnectionMsg); + mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CONNECT, mndProcessConnectMsg); + mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryMsg); + mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnectionMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndGetConnsMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 41f09e85a9..4e22a07460 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -36,8 +36,8 @@ int32_t mndInitShow(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SHOW, mndProcessShowMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SHOW_RETRIEVE, mndProcessRetrieveMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveMsg); return 0; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index a51312a2a9..5aec40766b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -52,13 +52,13 @@ int32_t mndInitStb(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndStbActionUpdate, .deleteFp = (SdbDeleteFp)mndStbActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB, mndProcessCreateStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB, mndProcessAlterStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB, mndProcessDropStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB_IN_RSP, mndProcessCreateStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB_IN_RSP, mndProcessAlterStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB_IN_RSP, mndProcessDropStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessStbMetaMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessCreateStbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessAlterStbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessDropStbMsg); + mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndProcessCreateStbInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndProcessAlterStbInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndProcessDropStbInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_TABLE_META, mndProcessStbMetaMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STB, mndGetStbMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STB, mndRetrieveStb); @@ -345,7 +345,7 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; action.contLen = htonl(pMsg->head.contLen); - action.msgType = TSDB_MSG_TYPE_CREATE_STB_IN; + action.msgType = TDMT_VND_CREATE_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); @@ -380,7 +380,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; action.contLen = sizeof(SDropStbInternalMsg); - action.msgType = TSDB_MSG_TYPE_DROP_STB_IN; + action.msgType = TDMT_VND_DROP_STB; if (mndTransAppendUndoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 53e3bc5203..b6781c5b21 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -466,13 +466,13 @@ static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) { int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction) { int32_t code = mndTransAppendAction(pTrans->redoActions, pAction); - mTrace("trans:%d, msg:%s append to redo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code); + mTrace("trans:%d, msg:%s append to redo actions, code:0x%x", pTrans->id, TMSG_INFO(pAction->msgType), code); return code; } int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction) { int32_t code = mndTransAppendAction(pTrans->undoActions, pAction); - mTrace("trans:%d, msg:%s append to undo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code); + mTrace("trans:%d, msg:%s append to undo actions, code:0x%x", pTrans->id, TMSG_INFO(pAction->msgType), code); return code; } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index c96e6a80db..9b5eca6d39 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -47,9 +47,9 @@ int32_t mndInitUser(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_USER, mndProcessAlterUserMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_USER, mndProcessDropUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index c65436efcb..463bb0ddb6 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -51,11 +51,11 @@ int32_t mndInitVgroup(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndVgroupActionDelete, .deleteFp = (SdbDeleteFp)mndVgroupActionUpdate}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP, mndProcessCreateVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP, mndProcessAlterVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_VNODE_IN_RSP, mndProcessDropVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP, mndProcessSyncVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP, mndProcessCompactVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_VNODE_RSP, mndProcessCreateVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_ALTER_VNODE_RSP, mndProcessAlterVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_VNODE_RSP, mndProcessDropVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_SYNC_VNODE_RSP, mndProcessSyncVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_COMPACT_VNODE_RSP, mndProcessCompactVnodeRsp); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndGetVgroupMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndRetrieveVgroups); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index a62a0a9296..91572399ad 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -376,7 +376,7 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) { void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); - mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, taosMsg[msgType]); + mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType)); if (isReq && !mndIsMaster(pMnode)) { code = TSDB_CODE_APP_NOT_READY; @@ -424,7 +424,7 @@ PROCESS_RPC_END: } void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { - if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) { + if (msgType >= 0 && msgType < TDMT_MAX) { pMnode->msgFp[msgType] = fp; } } diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 7e2e2602a8..00f6d231d6 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -18,7 +18,7 @@ #include "os.h" #include "sdb.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 249bde4e56..545d89ebb7 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -23,10 +23,10 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { tsize += taosEncodeFixedU64(buf, pReq->ver); switch (type) { - case TSDB_MSG_TYPE_CREATE_TABLE: + case TDMT_MND_CREATE_TABLE: tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq)); break; - case TSDB_MSG_TYPE_SUBMIT: + case TDMT_VND_SUBMIT: /* code */ break; default: @@ -40,7 +40,7 @@ void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { buf = taosDecodeFixedU64(buf, &(pReq->ver)); switch (type) { - case TSDB_MSG_TYPE_CREATE_TABLE: + case TDMT_MND_CREATE_TABLE: buf = vnodeParseCreateTableReq(buf, &(pReq->ctReq)); break; diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 5ec03f1fd3..b278197935 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -17,7 +17,7 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) { switch (pMsg->msgType) { - case TSDB_MSG_TYPE_MQ_SET_CUR: + case TDMT_VND_MQ_SET_CUR: if (tqSetCursor(pVnode->pTq, pMsg->pCont) < 0) { // TODO: handle error } @@ -70,21 +70,21 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType); switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_STB_IN: - case TSDB_MSG_TYPE_CREATE_TABLE: + case TDMT_VND_CREATE_STB: + case TDMT_MND_CREATE_TABLE: if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) { // TODO: handle error } // TODO: maybe need to clear the requst struct break; - case TSDB_MSG_TYPE_DROP_STB_IN: - case TSDB_MSG_TYPE_DROP_TABLE: + case TDMT_VND_DROP_STB: + case TDMT_MND_DROP_TABLE: if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { // TODO: handle error } break; - case TSDB_MSG_TYPE_SUBMIT: + case TDMT_VND_SUBMIT: if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) { // TODO: handle error } diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index aa9fc741d9..13d703f0be 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -84,14 +84,14 @@ static void vtBuildCreateStbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) { SVnodeReq vCreateSTbReq; vnodeSetCreateStbReq(&vCreateSTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); - zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + zs = vnodeBuildReq(NULL, &vCreateSTbReq, TDMT_MND_CREATE_TABLE); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); - pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pMsg->msgType = TDMT_MND_CREATE_TABLE; pMsg->contLen = zs; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); pBuf = pMsg->pCont; - vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateSTbReq, TDMT_MND_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateSTbReq); tdFreeSchema(pSchema); @@ -108,14 +108,14 @@ static void vtBuildCreateCtbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) { SVnodeReq vCreateCTbReq; vnodeSetCreateCtbReq(&vCreateCTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pTag); - tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + tz = vnodeBuildReq(NULL, &vCreateCTbReq, TDMT_MND_CREATE_TABLE); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); - pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pMsg->msgType = TDMT_MND_CREATE_TABLE; pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); void *pBuf = pMsg->pCont; - vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateCTbReq, TDMT_MND_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateCTbReq); free(pTag); @@ -133,7 +133,7 @@ static void vtBuildSubmitReq(SRpcMsg **ppMsg) { int tz = 1024; // TODO pMsg = (SRpcMsg *)malloc(sizeof(*pMsg) + tz); - pMsg->msgType = TSDB_MSG_TYPE_SUBMIT; + pMsg->msgType = TDMT_VND_SUBMIT; pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); diff --git a/source/dnode/vnode/tsdb/inc/tsdbDef.h b/source/dnode/vnode/tsdb/inc/tsdbDef.h index b1375c9477..ded28727e4 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbDef.h +++ b/source/dnode/vnode/tsdb/inc/tsdbDef.h @@ -17,7 +17,7 @@ #define _TD_TSDB_DEF_H_ #include "mallocator.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlist.h" #include "thash.h" #include "tskiplist.h" diff --git a/source/dnode/vnode/tsdb/src/tsdbHealth.c b/source/dnode/vnode/tsdb/src/tsdbHealth.c index 8198c48033..4205f3e90f 100644 --- a/source/dnode/vnode/tsdb/src/tsdbHealth.c +++ b/source/dnode/vnode/tsdb/src/tsdbHealth.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "query.h" #include "tglobal.h" diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index bc7a8b8aff..7ca2822332 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -49,7 +49,7 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; - CTG_ERR_RET(queryBuildMsg[TSDB_MSG_TYPE_USE_DB](input, &msg, 0, &msgLen)); + CTG_ERR_RET(queryBuildMsg[TDMT_MND_USE_DB](input, &msg, 0, &msgLen)); char *pMsg = rpcMallocCont(msgLen); if (NULL == pMsg) { @@ -63,7 +63,7 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp tfree(msg); SRpcMsg rpcMsg = { - .msgType = TSDB_MSG_TYPE_USE_DB, + .msgType = TDMT_MND_USE_DB, .pCont = pMsg, .contLen = msgLen, }; @@ -76,7 +76,7 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp CTG_ERR_RET(rpcRsp.code); } - CTG_ERR_RET(queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB](out, rpcRsp.pCont, rpcRsp.contLen)); + CTG_ERR_RET(queryProcessMsgRsp[TDMT_MND_USE_DB](out, rpcRsp.pCont, rpcRsp.contLen)); return TSDB_CODE_SUCCESS; } @@ -161,10 +161,10 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; - CTG_ERR_RET(queryBuildMsg[TSDB_MSG_TYPE_TABLE_META](&bInput, &msg, 0, &msgLen)); + CTG_ERR_RET(queryBuildMsg[TDMT_VND_TABLE_META](&bInput, &msg, 0, &msgLen)); SRpcMsg rpcMsg = { - .msgType = TSDB_MSG_TYPE_TABLE_META, + .msgType = TDMT_VND_TABLE_META, .pCont = msg, .contLen = msgLen, }; @@ -181,7 +181,7 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE CTG_ERR_RET(rpcRsp.code); } - CTG_ERR_RET(queryProcessMsgRsp[TSDB_MSG_TYPE_TABLE_META](output, rpcRsp.pCont, rpcRsp.contLen)); + CTG_ERR_RET(queryProcessMsgRsp[TDMT_VND_TABLE_META](output, rpcRsp.pCont, rpcRsp.contLen)); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 22b5b7adc4..aa5a8e2b3e 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -79,7 +79,7 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pReq; rpcMsg.contLen = sizeof(SCreateDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB; + rpcMsg.msgType = TDMT_MND_CREATE_DB; SRpcMsg rpcRsp = {0}; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 1f7795e06f..ac91f906c7 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "executil.h" diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f37c7727f7..2e1c1f3f6e 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -14,7 +14,7 @@ */ #include #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "ttime.h" diff --git a/source/libs/function/inc/texpr.h b/source/libs/function/inc/texpr.h index 4ef0a7ab21..eb4ab1b6e3 100644 --- a/source/libs/function/inc/texpr.h +++ b/source/libs/function/inc/texpr.h @@ -22,7 +22,7 @@ extern "C" { #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "taosdef.h" #include "tskiplist.h" #include "function.h" diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c index 00f59e8b87..3af4a8fe57 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -16,7 +16,7 @@ #include "tscalarfunction.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "thash.h" #include "ttypes.h" diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c index 70a7e9973f..aa3e6ba0f0 100644 --- a/source/libs/function/src/texpr.c +++ b/source/libs/function/src/texpr.c @@ -18,7 +18,7 @@ #include "exception.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tbuffer.h" #include "tcompare.h" diff --git a/source/libs/function/src/tfill.c b/source/libs/function/src/tfill.c index 9575416a03..db1bb3e7b8 100644 --- a/source/libs/function/src/tfill.c +++ b/source/libs/function/src/tfill.c @@ -17,7 +17,7 @@ #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "ttypes.h" #include "tfill.h" diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index 23238ebab7..2229ac8561 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -16,7 +16,7 @@ #include "thistogram.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" /** diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index c0c3c8386b..73790b89f7 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -2,7 +2,7 @@ #define TDENGINE_ASTTOMSG_H #include "parserInt.h" -#include "taosmsg.h" +#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); diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index cd11607326..c515705f75 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -4358,7 +4358,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm } pDcl->pMsg = (char*)buildUserManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER)? TSDB_MSG_TYPE_CREATE_USER:TSDB_MSG_TYPE_ALTER_USER; + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER)? TDMT_MND_CREATE_USER:TDMT_MND_ALTER_USER; break; } @@ -4395,20 +4395,20 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm } pDcl->pMsg = (char*)buildAcctManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT)? TSDB_MSG_TYPE_CREATE_ACCT:TSDB_MSG_TYPE_ALTER_ACCT; + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT)? TDMT_MND_CREATE_ACCT:TDMT_MND_ALTER_ACCT; break; } case TSDB_SQL_DROP_ACCT: case TSDB_SQL_DROP_USER: { pDcl->pMsg = (char*)buildDropUserMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT)? TSDB_MSG_TYPE_DROP_ACCT:TSDB_MSG_TYPE_DROP_USER; + pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT)? TDMT_MND_DROP_ACCT:TDMT_MND_DROP_USER; break; } case TSDB_SQL_SHOW: { code = setShowInfo(&pInfo->pMiscInfo->showOpt, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, pMsgBuf); - pDcl->msgType = TSDB_MSG_TYPE_SHOW; + pDcl->msgType = TDMT_MND_SHOW; break; } @@ -4431,7 +4431,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm pDcl->pMsg = (char*)pUseDbMsg; pDcl->msgLen = sizeof(SUseDbMsg); - pDcl->msgType = TSDB_MSG_TYPE_USE_DB; + pDcl->msgType = TDMT_MND_USE_DB; break; } @@ -4459,7 +4459,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm pDcl->pMsg = (char*)pCreateMsg; pDcl->msgLen = sizeof(SCreateDbMsg); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB)? TSDB_MSG_TYPE_CREATE_DB:TSDB_MSG_TYPE_ALTER_DB; + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB)? TDMT_MND_CREATE_DB:TDMT_MND_ALTER_DB; break; } @@ -4481,7 +4481,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T); - pDcl->msgType = TSDB_MSG_TYPE_DROP_DB; + pDcl->msgType = TDMT_MND_DROP_DB; pDcl->msgLen = sizeof(SDropDbMsg); pDcl->pMsg = (char*)pDropDbMsg; return TSDB_CODE_SUCCESS; @@ -4495,7 +4495,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm return code; } pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); - pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE)? TSDB_MSG_TYPE_CREATE_TABLE:TSDB_MSG_TYPE_CREATE_STB; + pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE)? TDMT_MND_CREATE_TABLE:TDMT_MND_CREATE_STB; } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { // if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { // return code; @@ -4515,7 +4515,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm return terrno; } - pDcl->msgType = TSDB_MSG_TYPE_DROP_STB; + pDcl->msgType = TDMT_MND_DROP_STB; return TSDB_CODE_SUCCESS; break; } diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index 2f3d5aab77..b315ea613f 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -18,7 +18,7 @@ #include "catalog.h" #include "parserUtil.h" #include "queryInfoUtil.h" -#include "taosmsg.h" +#include "tmsg.h" #define IS_RAW_PAYLOAD(t) \ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index 307062ef15..8133ee62f7 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -14,7 +14,7 @@ */ -#include "taosmsg.h" +#include "tmsg.h" #include "parser.h" #include "taoserror.h" #include "tutil.h" @@ -1825,7 +1825,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt SSqlCmd *pCmd = &pSql->cmd; pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + pCmd->msgType = TDMT_VND_TABLES_META; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)pNameList; diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index ed29839905..35c6d59ffe 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -24,7 +24,7 @@ extern "C" { #include "tarray.h" #include "planner.h" #include "parser.h" -#include "taosmsg.h" +#include "tmsg.h" #define QNODE_TAGSCAN 1 #define QNODE_TABLESCAN 2 diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 829f426c9d..05132e610c 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -1,5 +1,5 @@ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #include "tglobal.h" #include "tsched.h" diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index eb5527f076..9507b93222 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -13,13 +13,13 @@ * along with this program. If not, see . */ -#include "taosmsg.h" +#include "tmsg.h" #include "queryInt.h" #include "query.h" -int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen) = {0}; +int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen) = {0}; -int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize) = {0}; +int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize) = {0}; int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int32_t *msgLen) { if (NULL == input || NULL == msg || NULL == msgLen) { @@ -264,11 +264,11 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { void initQueryModuleMsgHandle() { - queryBuildMsg[TSDB_MSG_TYPE_TABLE_META] = queryBuildTableMetaReqMsg; - queryBuildMsg[TSDB_MSG_TYPE_USE_DB] = queryBuildUseDbMsg; + queryBuildMsg[TDMT_VND_TABLE_META] = queryBuildTableMetaReqMsg; + queryBuildMsg[TDMT_MND_USE_DB] = queryBuildUseDbMsg; - queryProcessMsgRsp[TSDB_MSG_TYPE_TABLE_META] = queryProcessTableMetaRsp; - queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB] = queryProcessUseDBRsp; + queryProcessMsgRsp[TDMT_VND_TABLE_META] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TDMT_MND_USE_DB] = queryProcessUseDBRsp; } diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp index d2aedff8fd..ddf89c6272 100644 --- a/source/libs/qcom/test/queryTest.cpp +++ b/source/libs/qcom/test/queryTest.cpp @@ -15,7 +15,7 @@ #include #include -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #pragma GCC diagnostic ignored "-Wwrite-strings" diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 37d3e655c2..994b46c5c4 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1,4 +1,4 @@ -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #include "qworker.h" #include "qworkerInt.h" diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 4185b3176c..876a4ff4ae 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -14,7 +14,7 @@ */ #include "schedulerInt.h" -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #include "catalog.h" @@ -310,7 +310,7 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { void *msg = NULL; switch (msgType) { - case TSDB_MSG_TYPE_SUBMIT: { + case TDMT_VND_SUBMIT: { if (NULL == task->msg || task->msgLen <= 0) { qError("submit msg is NULL"); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); @@ -320,7 +320,7 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { msg = task->msg; break; } - case TSDB_MSG_TYPE_QUERY: { + case TDMT_VND_QUERY: { if (NULL == task->msg) { qError("query msg is NULL"); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); @@ -342,7 +342,7 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { memcpy(pMsg->msg, task->msg, task->msgLen); break; } - case TSDB_MSG_TYPE_RES_READY: { + case TDMT_VND_RES_READY: { msgSize = sizeof(SResReadyMsg); msg = calloc(1, msgSize); if (NULL == msg) { @@ -356,7 +356,7 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { pMsg->taskId = htobe64(task->taskId); break; } - case TSDB_MSG_TYPE_FETCH: { + case TDMT_VND_FETCH: { msgSize = sizeof(SResFetchMsg); msg = calloc(1, msgSize); if (NULL == msg) { @@ -370,7 +370,7 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { pMsg->taskId = htobe64(task->taskId); break; } - case TSDB_MSG_TYPE_DROP_TASK:{ + case TDMT_VND_DROP_TASK:{ msgSize = sizeof(STaskDropMsg); msg = calloc(1, msgSize); if (NULL == msg) { @@ -413,7 +413,7 @@ int32_t schFetchFromRemote(SQueryJob *job) { return TSDB_CODE_SUCCESS; } - SCH_ERR_JRET(schAsyncSendMsg(job, NULL, TSDB_MSG_TYPE_FETCH)); + SCH_ERR_JRET(schAsyncSendMsg(job, NULL, TDMT_VND_FETCH)); return TSDB_CODE_SUCCESS; @@ -564,17 +564,17 @@ int32_t schHandleRspMsg(SQueryJob *job, SQueryTask *task, int32_t msgType, int32 int32_t code = 0; switch (msgType) { - case TSDB_MSG_TYPE_QUERY: + case TDMT_VND_QUERY: if (rspCode != TSDB_CODE_SUCCESS) { SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); } else { - code = schAsyncSendMsg(job, task, TSDB_MSG_TYPE_RES_READY); + code = schAsyncSendMsg(job, task, TDMT_VND_RES_READY); if (code) { goto _task_error; } } break; - case TSDB_MSG_TYPE_RES_READY: + case TDMT_VND_RES_READY: if (rspCode != TSDB_CODE_SUCCESS) { SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); } else { @@ -584,7 +584,7 @@ int32_t schHandleRspMsg(SQueryJob *job, SQueryTask *task, int32_t msgType, int32 } } break; - case TSDB_MSG_TYPE_FETCH: + case TDMT_VND_FETCH: SCH_ERR_JRET(rspCode); SCH_ERR_JRET(schProcessOnDataFetched(job)); break; @@ -619,7 +619,7 @@ int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) { SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TSDB_MSG_TYPE_SUBMIT : TSDB_MSG_TYPE_QUERY; + int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TDMT_VND_SUBMIT : TDMT_VND_QUERY; SCH_ERR_RET(schAsyncSendMsg(job, task, msgType)); @@ -647,7 +647,7 @@ void schDropJobAllTasks(SQueryJob *job) { while (pIter) { SQueryTask *task = *(SQueryTask **)pIter; - schAsyncSendMsg(job, task, TSDB_MSG_TYPE_DROP_TASK); + schAsyncSendMsg(job, task, TDMT_VND_DROP_TASK); pIter = taosHashIterate(job->succTasks, pIter); } @@ -656,7 +656,7 @@ void schDropJobAllTasks(SQueryJob *job) { while (pIter) { SQueryTask *task = *(SQueryTask **)pIter; - schAsyncSendMsg(job, task, TSDB_MSG_TYPE_DROP_TASK); + schAsyncSendMsg(job, task, TDMT_VND_DROP_TASK); pIter = taosHashIterate(job->succTasks, pIter); } diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 2f710f3efd..71304fcca8 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -23,7 +23,7 @@ #include "tref.h" #include "taoserror.h" #include "tglobal.h" -#include "taosmsg.h" +#include "tmsg.h" #include "trpc.h" #include "thash.h" #include "rpcLog.h" @@ -410,10 +410,10 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t // connection type is application specific. // for TDengine, all the query, show commands shall have TCP connection char type = pMsg->msgType; - if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_SHOW_RETRIEVE - || type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_VGROUP_LIST - || type == TSDB_MSG_TYPE_TABLES_META || type == TSDB_MSG_TYPE_TABLE_META - || type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_STATUS || type == TSDB_MSG_TYPE_ALTER_TABLE) + if (type == TDMT_VND_QUERY || type == TDMT_MND_SHOW_RETRIEVE + || type == TDMT_VND_FETCH || type == TDMT_MND_VGROUP_LIST + || type == TDMT_VND_TABLES_META || type == TDMT_VND_TABLE_META + || type == TDMT_MND_SHOW || type == TDMT_MND_STATUS || type == TDMT_VND_ALTER_TABLE) pContext->connType = RPC_CONN_TCPC; pContext->rid = taosAddRef(tsRpcRefId, pContext); @@ -837,16 +837,16 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->inTranId == pHead->tranId) { if (pConn->inType == pHead->msgType) { if (pHead->code == 0) { - tDebug("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]); + tDebug("%s, %s is retransmitted", pConn->info, TMSG_INFO(pHead->msgType)); rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); } else { // do nothing, it is heart beat from client } } else if (pConn->inType == 0) { - tDebug("%s, %s is already processed, tranId:%d", pConn->info, taosMsg[pHead->msgType], pConn->inTranId); + tDebug("%s, %s is already processed, tranId:%d", pConn->info, TMSG_INFO(pHead->msgType), pConn->inTranId); rpcSendMsgToPeer(pConn, pConn->pRspMsg, pConn->rspMsgLen); // resend the response } else { - tDebug("%s, mismatched message %s and tranId", pConn->info, taosMsg[pHead->msgType]); + tDebug("%s, mismatched message %s and tranId", pConn->info, TMSG_INFO(pHead->msgType)); } // do not reply any message @@ -957,19 +957,19 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv, SRpcReqCont sid = htonl(pHead->destId); *ppContext = NULL; - if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) { + if (pHead->msgType >= TDMT_MAX || pHead->msgType <= 0) { tDebug("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL; } if (sid < 0 || sid >= pRpc->sessions) { tDebug("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid, - pRpc->sessions, taosMsg[pHead->msgType]); + pRpc->sessions, TMSG_INFO(pHead->msgType)); terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL; } if (rpcIsReq(pHead->msgType) && htonl(pHead->msgVer) != tsVersion >> 8) { - tDebug("%s sid:%d, invalid client version:%x/%x %s", pRpc->label, sid, htonl(pHead->msgVer), tsVersion, taosMsg[pHead->msgType]); + tDebug("%s sid:%d, invalid client version:%x/%x %s", pRpc->label, sid, htonl(pHead->msgVer), tsVersion, TMSG_INFO(pHead->msgType)); terrno = TSDB_CODE_RPC_INVALID_VERSION; return NULL; } @@ -1094,9 +1094,9 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { SRpcReqContext *pContext; pConn = rpcProcessMsgHead(pRpc, pRecv, &pContext); - if (pHead->msgType >= 1 && pHead->msgType < TSDB_MSG_TYPE_MAX) { + if (pHead->msgType >= 1 && pHead->msgType < TDMT_MAX) { tDebug("%s %p %p, %s received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, - pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType], pRecv->ip, pRecv->port, terrno, pRecv->msgLen, + pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), pRecv->ip, pRecv->port, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); } else { tDebug("%s %p %p, %d received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, @@ -1112,10 +1112,10 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE) { rpcCloseConn(pConn); } - if (pHead->msgType + 1 > 1 && pHead->msgType+1 < TSDB_MSG_TYPE_MAX) { - tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType+1], code); + if (pHead->msgType + 1 > 1 && pHead->msgType+1 < TDMT_MAX) { + tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType+1), code); } else { - tError("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType], code); + tError("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), code); } } } else { // msg is passed to app only parsing is ok @@ -1343,12 +1343,12 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) { if ( rpcIsReq(pHead->msgType)) { tDebug("%s, %s is sent to %s:%hu, len:%d sig:0x%08x:0x%08x:%d", - pConn->info, taosMsg[pHead->msgType], pConn->peerFqdn, pConn->peerPort, + pConn->info, TMSG_INFO(pHead->msgType), pConn->peerFqdn, pConn->peerPort, msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } else { if (pHead->code == 0) pConn->secured = 1; // for success response, set link as secured tDebug("%s, %s is sent to 0x%x:%hu, code:0x%x len:%d sig:0x%08x:0x%08x:%d", - pConn->info, taosMsg[pHead->msgType], pConn->peerIp, pConn->peerPort, + pConn->info, TMSG_INFO(pHead->msgType), pConn->peerIp, pConn->peerPort, htonl(pHead->code), msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } @@ -1373,7 +1373,7 @@ static void rpcProcessConnError(void *param, void *id) { tDebug("%s %p, connection error happens", pRpc->label, pContext->ahandle); - if (pContext->numOfTry >= pContext->epSet.numOfEps || pContext->msgType == TSDB_MSG_TYPE_FETCH) { + if (pContext->numOfTry >= pContext->epSet.numOfEps || pContext->msgType == TDMT_VND_FETCH) { rpcMsg.msgType = pContext->msgType+1; rpcMsg.ahandle = pContext->ahandle; rpcMsg.code = pContext->code; @@ -1396,17 +1396,17 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) { rpcLockConn(pConn); if (pConn->outType && pConn->user[0]) { - tDebug("%s, expected %s is not received", pConn->info, taosMsg[(int)pConn->outType + 1]); + tDebug("%s, expected %s is not received", pConn->info, TMSG_INFO((int)pConn->outType + 1)); pConn->pTimer = NULL; pConn->retry++; if (pConn->retry < 4) { - tDebug("%s, re-send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort); + tDebug("%s, re-send msg:%s to %s:%hu", pConn->info, TMSG_INFO(pConn->outType), pConn->peerFqdn, pConn->peerPort); rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); } else { // close the connection - tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort); + tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, TMSG_INFO(pConn->outType), pConn->peerFqdn, pConn->peerPort); if (pConn->pContext) { pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; pConn->pContext->pConn = NULL; diff --git a/source/util/test/skiplistTest.cpp b/source/util/test/skiplistTest.cpp index df4c5af5e2..f2e696b0e5 100644 --- a/source/util/test/skiplistTest.cpp +++ b/source/util/test/skiplistTest.cpp @@ -5,7 +5,7 @@ #include #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tskiplist.h" #include "tutil.h" diff --git a/src/client/inc/tscGlobalmerge.h b/src/client/inc/tscGlobalmerge.h index a462d78ff0..7aa16f843f 100644 --- a/src/client/inc/tscGlobalmerge.h +++ b/src/client/inc/tscGlobalmerge.h @@ -22,7 +22,7 @@ extern "C" { #include "qExtbuffer.h" #include "qFill.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" #include "qExecutor.h" diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 653c7770ef..7dc9c0e28b 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -25,7 +25,7 @@ extern "C" { #include "../../../include/client/taos.h" #include "qAggMain.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tcache.h" #include "tglobal.h" diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index dcfb2d6a87..31e60ff279 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "../../../include/client/taos.h" #include "qTableMeta.h" diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 17742d71e1..ab582ec249 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -15,7 +15,7 @@ #include "os.h" #include "../../../include/client/taos.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tscLog.h" #include "tscSubquery.h" #include "tscUtil.h" diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index a9f65b84ce..e4b1602661 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -18,7 +18,7 @@ #include "tsclient.h" #include "tsocket.h" #include "ttimer.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcq.h" #include "../../../include/client/taos.h" diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4fc78d73e4..eb3f8be25a 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -28,7 +28,7 @@ #include "qTableMeta.h" #include "qUtil.h" #include "regex.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "texpr.h" #include "tfilter.h" diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7a754ee698..42799927e6 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -313,7 +313,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { char *pMsg = rpcMallocCont(pCmd->payloadLen); if (NULL == pMsg) { - tscError("0x%"PRIx64" msg:%s malloc failed", pSql->self, taosMsg[pSql->cmd.msgType]); + tscError("0x%"PRIx64" msg:%s malloc failed", pSql->self, TMSG_INFO(pSql->cmd.msgType)); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -489,7 +489,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { * There is not response callback function for submit response. * The actual inserted number of points is the first number. */ - if (rpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT_RSP && pRes->pRsp != NULL) { + if (rpcMsg->msgType == TDMT_VND_SUBMIT_RSP && pRes->pRsp != NULL) { SShellSubmitRspMsg *pMsg = (SShellSubmitRspMsg*)pRes->pRsp; pMsg->code = htonl(pMsg->code); pMsg->numOfRows = htonl(pMsg->numOfRows); @@ -639,7 +639,7 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg); - pSql->cmd.msgType = TSDB_MSG_TYPE_FETCH; + pSql->cmd.msgType = TDMT_VND_FETCH; pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); @@ -651,7 +651,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; // pSql->cmd.payloadLen is set during copying data into payload - pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; + pSql->cmd.msgType = TDMT_VND_SUBMIT; SNewVgroupInfo vgroupInfo = {0}; taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo); @@ -1150,7 +1150,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tscDebug("0x%"PRIx64" msg built success, len:%d bytes", pSql->self, msgLen); pCmd->payloadLen = msgLen; - pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY; + pSql->cmd.msgType = TDMT_VND_QUERY; pQueryMsg->head.contLen = htonl(msgLen); assert(msgLen + minMsgSize() <= (int32_t)pCmd->allocSize); @@ -1166,7 +1166,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCreateDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg *)pCmd->payload; @@ -1182,7 +1182,7 @@ int32_t tscBuildCreateFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; SCreateFuncMsg *pCreateFuncMsg = (SCreateFuncMsg *)pCmd->payload; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_FUNCTION; + pCmd->msgType = TDMT_MND_CREATE_FUNCTION; pCmd->payloadLen = sizeof(SCreateFuncMsg) + htonl(pCreateFuncMsg->codeLen); @@ -1203,7 +1203,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SStrToken* t0 = taosArrayGet(pInfo->pMiscInfo->a, 0); strncpy(pCreate->ep, t0->z, t0->n); - pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; + pCmd->msgType = TDMT_MND_CREATE_DNODE; return TSDB_CODE_SUCCESS; } @@ -1249,7 +1249,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } } - pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT; + pCmd->msgType = TDMT_MND_CREATE_ACCT; return TSDB_CODE_SUCCESS; } @@ -1277,9 +1277,9 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; + pCmd->msgType = TDMT_MND_ALTER_USER; } else { - pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; + pCmd->msgType = TDMT_MND_CREATE_USER; } return TSDB_CODE_SUCCESS; @@ -1288,7 +1288,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCfgDnodeMsg); - pCmd->msgType = TSDB_MSG_TYPE_CONFIG_DNODE; + pCmd->msgType = TDMT_MND_CONFIG_DNODE; return TSDB_CODE_SUCCESS; } @@ -1310,14 +1310,14 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_DROP_DB : TSDB_MSG_TYPE_DROP_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_DROP_DB : TSDB_MSG_TYPE_DROP_TP; return TSDB_CODE_SUCCESS; } int32_t tscBuildDropFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_DROP_FUNCTION; + pCmd->msgType = TDMT_MND_DROP_FUNCTION; pCmd->payloadLen = sizeof(SDropFuncMsg); @@ -1340,7 +1340,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropTableMsg->supertable = (pInfo->pMiscInfo->tableType == TSDB_SUPER_TABLE)? 1:0; pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; + pCmd->msgType = TDMT_MND_DROP_TABLE; return TSDB_CODE_SUCCESS; } @@ -1358,7 +1358,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SDropDnodeMsg * pDrop = (SDropDnodeMsg *)pCmd->payload; tstrncpy(pDrop->ep, dnodeEp, tListLen(pDrop->ep)); - pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; + pCmd->msgType = TDMT_MND_DROP_DNODE; return TSDB_CODE_SUCCESS; } @@ -1370,7 +1370,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tstrncpy(user, pCmd->payload, TSDB_USER_LEN); pCmd->payloadLen = sizeof(SDropUserMsg); - pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TSDB_MSG_TYPE_DROP_USER:TSDB_MSG_TYPE_DROP_ACCT; + pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TDMT_MND_DROP_USER:TDMT_MND_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1395,7 +1395,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SUseDbMsg *pUseDbMsg = (SUseDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pUseDbMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_USE_DB; + pCmd->msgType = TDMT_MND_USE_DB; return TSDB_CODE_SUCCESS; } @@ -1412,14 +1412,14 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { SSyncDbMsg *pSyncMsg = (SSyncDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pSyncMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_SYNC_DB; + pCmd->msgType = TDMT_MND_SYNC_DB; return TSDB_CODE_SUCCESS; } int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW; + pCmd->msgType = TDMT_MND_SHOW; pCmd->payloadLen = sizeof(SShowMsg) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1473,10 +1473,10 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { switch (pCmd->command) { case TSDB_SQL_KILL_QUERY: - pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; + pCmd->msgType = TDMT_MND_KILL_QUERY; break; case TSDB_SQL_KILL_CONNECTION: - pCmd->msgType = TSDB_MSG_TYPE_KILL_CONN; + pCmd->msgType = TDMT_MND_KILL_CONN; break; case TSDB_SQL_KILL_STREAM: pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; @@ -1592,7 +1592,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); pCreateTableMsg->contLen = htonl(msgLen); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pCmd->msgType = TDMT_MND_CREATE_TABLE; assert(msgLen + minMsgSize() <= size); return TSDB_CODE_SUCCESS; @@ -1645,7 +1645,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pAlterTableMsg); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; + pCmd->msgType = TDMT_VND_ALTER_TABLE; assert(msgLen + minMsgSize() <= size); @@ -1654,7 +1654,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { SSqlCmd* pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_UPDATE_TAG_VAL; + pCmd->msgType = TDMT_VND_UPDATE_TAG_VAL; SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload; pCmd->payloadLen = htonl(pUpdateMsg->head.contLen); @@ -1674,7 +1674,7 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SAlterDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg* )pCmd->payload; pAlterDbMsg->dbType = -1; @@ -1741,7 +1741,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; + pCmd->msgType = TDMT_MND_SHOW_RETRIEVE; pCmd->payloadLen = sizeof(SRetrieveTableMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1861,7 +1861,7 @@ int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STscObj *pObj = pSql->pTscObj; SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CONNECT; + pCmd->msgType = TDMT_MND_CONNECT; pCmd->payloadLen = sizeof(SConnectMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1898,7 +1898,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildMultiTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + pCmd->msgType = TDMT_VND_TABLES_META; assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize); tscDebug("0x%"PRIx64" build load multi-tablemeta msg completed, numOfTables:%d, msg size:%d", pSql->self, pCmd->count, @@ -1996,7 +1996,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pthread_mutex_unlock(&pObj->mutex); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_HEARTBEAT; + pCmd->msgType = TDMT_MND_HEARTBEAT; return TSDB_CODE_SUCCESS; } @@ -2838,7 +2838,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn } pNew->cmd.payloadLen = (int32_t)(pMsg - (char*)pInfoMsg); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLE_META; + pNew->cmd.msgType = TDMT_VND_TABLE_META; } int32_t code = tscBuildAndSendRequest(pNew, NULL); @@ -2913,7 +2913,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg } pNew->cmd.payloadLen = (int32_t) ((start - pInfo->tableNames) + sizeof(SMultiTableInfoMsg)); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLES_META; + pNew->cmd.msgType = TDMT_VND_TABLES_META; registerSqlObj(pNew); tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, udf:%d, msg size:%d", pSql->self, diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9f2b79e891..c8a305e804 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tscLog.h" #include "tscUtil.h" #include "tsched.h" diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index badc97ba35..897a629d57 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tconfig.h" #include "tglobal.h" #include "tnote.h" diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 986ce41a9c..b7d88f94ca 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -16,7 +16,7 @@ #include "tscUtil.h" #include "hash.h" #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "texpr.h" #include "tkey.h" #include "tmd5.h" @@ -5011,7 +5011,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt SSqlCmd *pCmd = &pSql->cmd; pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + pCmd->msgType = TDMT_VND_TABLES_META; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)pNameList; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index d2558e4650..d610ed605f 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -22,7 +22,7 @@ #include "../../../include/client/taos.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcq.h" #include "tdataformat.h" #include "tglobal.h" @@ -520,7 +520,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { pMsg->length = pMsg->header.contLen; pMsg->numOfBlocks = htonl(1); - pHead->msgType = TSDB_MSG_TYPE_SUBMIT; + pHead->msgType = TDMT_VND_SUBMIT; pHead->version = 0; // write into vnode write queue diff --git a/src/cq/test/cqtest.c b/src/cq/test/cqtest.c index b1153397ba..ee52152ad8 100644 --- a/src/cq/test/cqtest.c +++ b/src/cq/test/cqtest.c @@ -16,7 +16,7 @@ //#define _DEFAULT_SOURCE #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tlog.h" #include "tcq.h" diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 089e30ac37..65c8a45d00 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -20,7 +20,7 @@ #include #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tdataformat.h" #include "tname.h" diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 3d59dfff4e..8e01920004 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -20,7 +20,7 @@ #include "../../../include/client/taos.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tsclient.h" #include "tsdb.h" diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index d4a9ed0cbc..1238348237 100644 --- a/src/query/inc/qExtbuffer.h +++ b/src/query/inc/qExtbuffer.h @@ -20,7 +20,7 @@ extern "C" { #endif #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tutil.h" diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 0c60319f39..ecb5c664aa 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -21,7 +21,7 @@ extern "C" { #endif #include "../../../include/client/taos.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tstrbuild.h" #include "ttoken.h" #include "tvariant.h" diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 037b60343e..d57532ac8f 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -15,7 +15,7 @@ #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "texpr.h" #include "ttype.h" #include "tsdb.h" diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 85f961b829..be1bfb8143 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -14,7 +14,7 @@ */ #include "os.h" #include "qFill.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "exception.h" diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index 35cd7eeac2..35e95a6845 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -19,7 +19,7 @@ #include "qExecutor.h" #include "queryLog.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "tulog.h" diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index cdcc164152..47ea63eeb0 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -17,7 +17,7 @@ #include "qAggMain.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "ttype.h" #include "qFill.h" diff --git a/src/query/src/qFilterfunc.c b/src/query/src/qFilterfunc.c index 1c1ec21d65..6ad7a6ef63 100644 --- a/src/query/src/qFilterfunc.c +++ b/src/query/src/qFilterfunc.c @@ -17,7 +17,7 @@ #include "os.h" #include "qExecutor.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "ttype.h" diff --git a/src/query/src/qHistogram.c b/src/query/src/qHistogram.c index 5fa35d0ee5..b406c0f703 100644 --- a/src/query/src/qHistogram.c +++ b/src/query/src/qHistogram.c @@ -16,7 +16,7 @@ #include "qHistogram.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" /** diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index cca7bc6148..b4ad30b291 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -16,7 +16,7 @@ #include "qSqlparser.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tmsgtype.h" #include "tstrbuild.h" #include "ttoken.h" diff --git a/src/query/src/qTableMeta.c b/src/query/src/qTableMeta.c index f687b8aa1f..4e8954ed6f 100644 --- a/src/query/src/qTableMeta.c +++ b/src/query/src/qTableMeta.c @@ -1,6 +1,6 @@ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "qTableMeta.h" #include "ttokendef.h" #include "taosdef.h" diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 1460fbdc0f..3bf031ebd5 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcache.h" #include "tglobal.h" diff --git a/src/query/tests/astTest.cpp b/src/query/tests/astTest.cpp index 75a703ac1f..b7df749983 100644 --- a/src/query/tests/astTest.cpp +++ b/src/query/tests/astTest.cpp @@ -4,7 +4,7 @@ #include #include "texpr.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tsdb.h" #include "tskiplist.h" diff --git a/tools/shell/src/backup/tnettest.c b/tools/shell/src/backup/tnettest.c index c8a6b36fc7..d6904ddc04 100644 --- a/tools/shell/src/backup/tnettest.c +++ b/tools/shell/src/backup/tnettest.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "taoserror.h" #include "tulog.h" #include "tglobal.h" @@ -358,7 +358,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p epSet.port[0] = port; strcpy(epSet.fqdn[0], serverFqdn); - reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; + reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pktLen); reqMsg.contLen = pktLen; reqMsg.code = 0; @@ -368,7 +368,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); - if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) { + if ((rspMsg.code != 0) || (rspMsg.msgType != TDMT_DND_NETWORK_TEST + 1)) { uDebug("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); return rspMsg.code; } @@ -602,7 +602,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, epSet.port[0] = port; strcpy(epSet.fqdn[0], host); - reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; + reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pkgLen); reqMsg.contLen = pkgLen; reqMsg.code = 0; @@ -613,7 +613,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); int code = 0; - if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) { + if ((rspMsg.code != 0) || (rspMsg.msgType != TDMT_DND_NETWORK_TEST + 1)) { uError("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); code = -1; }else{ From 5eabe9102c38bb14839886b2037a730631b7abfb Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:31:14 +0800 Subject: [PATCH 13/36] make compile --- include/common/tmsgdef.h | 12 +++++++++--- source/dnode/mnode/impl/src/mndDb.c | 4 ++-- source/dnode/mnode/impl/src/mndTopic.c | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index eb23d7b2af..0f8b97b519 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -103,9 +103,12 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL) - TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_STATUS, "mnode-status", NULL, NULL) - TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_GRANT, "mnode-grant", NULL, NULL) - TD_DEF_MSG_TYPE(TSDB_MSG_TYPE_AUTH, "mnode-auth", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL) // Requests handled by VNODE TD_NEW_MSG_SEG(TDMT_VND_MSG) @@ -128,6 +131,9 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL) // Requests handled by QNODE TD_NEW_MSG_SEG(TDMT_QND_MSG) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 1ed11cf834..ac9de7eab8 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -573,7 +573,7 @@ static int32_t mndBuildUpdateVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj action.pCont = pMsg; action.contLen = sizeof(SAlterVnodeMsg); - action.msgType = TSDB_MSG_TYPE_ALTER_VNODE_IN; + action.msgType = TDMT_DND_ALTER_VNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; @@ -737,7 +737,7 @@ static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj * action.pCont = pMsg; action.contLen = sizeof(SCreateVnodeMsg); - action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + action.msgType = TDMT_DND_DROP_VNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 653c3c65fb..5b45aea2e6 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -52,20 +52,20 @@ int32_t mndInitTopic(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndTopicActionUpdate, .deleteFp = (SdbDeleteFp)mndTopicActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC, mndProcessCreateTopicMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_TOPIC, mndProcessAlterTopicMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_TOPIC, mndProcessDropTopicMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC_IN_RSP, mndProcessCreateTopicInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_TOPIC_IN_RSP, mndProcessAlterTopicInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_TOPIC_IN_RSP, mndProcessDropTopicInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessTopicMetaMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TOPIC, mndProcessCreateTopicMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_TOPIC, mndProcessAlterTopicMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicMsg); + mndSetMsgHandle(pMnode, TDMT_VND_CREATE_TOPIC_RSP, mndProcessCreateTopicInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_ALTER_TOPIC_RSP, mndProcessAlterTopicInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndProcessDropTopicInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_TABLE_META, mndProcessTopicMetaMsg); /*mndAddShowMetaHandle(pMnode, TSDB_MGMT_TOPIC, mndGetTopicMeta);*/ /*mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TOPIC, mndRetrieveTopic);*/ /*mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TOPIC, mndCancelGetNextTopic);*/ - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC, mndProcessCreateTopicMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_TOPIC_IN_RSP, mndProcessCreateTopicInRsp); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TOPIC, mndProcessCreateTopicMsg); + mndSetMsgHandle(pMnode, TDMT_VND_CREATE_TOPIC_RSP, mndProcessCreateTopicInRsp); return sdbSetTable(pMnode->pSdb, table); } @@ -297,7 +297,7 @@ static int32_t mndSetCreateTopicRedoActions(SMnode *pMnode, STrans *pTrans, SDbO action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; action.contLen = htonl(pMsg->head.contLen); - action.msgType = TSDB_MSG_TYPE_CREATE_TOPIC_IN; + action.msgType = TDMT_VND_CREATE_TOPIC; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); @@ -332,7 +332,7 @@ static int32_t mndSetCreateTopicUndoActions(SMnode *pMnode, STrans *pTrans, SDbO action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; action.contLen = sizeof(SDropTopicInternalMsg); - action.msgType = TSDB_MSG_TYPE_DROP_TOPIC_IN; + action.msgType = TDMT_VND_DROP_TOPIC; if (mndTransAppendUndoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); From cc41b9d3124609129dfc0fe57465458e1d10307a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:40:15 +0800 Subject: [PATCH 14/36] change msg type def --- include/common/tmsg.h | 10 +++--- include/libs/transport/trpc.h | 68 +++++++++++++++++------------------ 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 4136585241..6dda3b195e 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -42,13 +42,15 @@ extern "C" { #undef TD_MSG_SEG_CODE_ #include "tmsgdef.h" -extern char *tMsgInfo[]; +extern char* tMsgInfo[]; extern int tMsgDict[]; #define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) #define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) #define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] +typedef uint16_t tmsg_t; + // IE type #define TSDB_IE_TYPE_SEC 1 #define TSDB_IE_TYPE_META 2 @@ -122,7 +124,7 @@ typedef enum _mgmt_table { typedef struct SBuildTableMetaInput { int32_t vgId; - char * tableFullName; + char* tableFullName; } SBuildTableMetaInput; typedef struct SBuildUseDBInput { @@ -395,7 +397,7 @@ typedef struct SColumnFilterList { int16_t numOfFilters; union { int64_t placeholder; - SColumnFilterInfo *filterInfo; + SColumnFilterInfo* filterInfo; }; } SColumnFilterList; /* @@ -784,7 +786,7 @@ typedef struct SMultiTableMeta { typedef struct { int32_t dataLen; char name[TSDB_TABLE_FNAME_LEN]; - char * data; + char* data; } STagData; typedef struct { diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 976c0b8bb4..b88d45fbd6 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -24,41 +24,41 @@ extern "C" { #include "taosdef.h" #include "tmsg.h" -#define TAOS_CONN_SERVER 0 -#define TAOS_CONN_CLIENT 1 +#define TAOS_CONN_SERVER 0 +#define TAOS_CONN_CLIENT 1 extern int tsRpcHeadSize; typedef struct SRpcConnInfo { - uint32_t clientIp; - uint16_t clientPort; - uint32_t serverIp; - char user[TSDB_USER_LEN]; + uint32_t clientIp; + uint16_t clientPort; + uint32_t serverIp; + char user[TSDB_USER_LEN]; } SRpcConnInfo; typedef struct SRpcMsg { - uint8_t msgType; - void *pCont; + tmsg_t msgType; + void * pCont; int contLen; int32_t code; - void *handle; // rpc handle returned to app - void *ahandle; // app handle set by client + void * handle; // rpc handle returned to app + void * ahandle; // app handle set by client } SRpcMsg; typedef struct SRpcInit { - uint16_t localPort; // local port - char *label; // for debug purpose - int numOfThreads; // number of threads to handle connections - int sessions; // number of sessions allowed - int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS - int idleTime; // milliseconds, 0 means idle timer is disabled + uint16_t localPort; // local port + char * label; // for debug purpose + int numOfThreads; // number of threads to handle connections + int sessions; // number of sessions allowed + int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS + int idleTime; // milliseconds, 0 means idle timer is disabled // the following is for client app ecurity only - char *user; // user name - char spi; // security parameter index - char encrypt; // encrypt algorithm - char *secret; // key for authentication - char *ckey; // ciphering key + char *user; // user name + char spi; // security parameter index + char encrypt; // encrypt algorithm + char *secret; // key for authentication + char *ckey; // ciphering key // call back to process incoming msg, code shall be ignored by server app void (*cfp)(void *parent, SRpcMsg *, SEpSet *); @@ -70,19 +70,19 @@ typedef struct SRpcInit { } SRpcInit; int32_t rpcInit(); -void rpcCleanup(); -void *rpcOpen(const SRpcInit *pRpc); -void rpcClose(void *); -void *rpcMallocCont(int contLen); -void rpcFreeCont(void *pCont); -void *rpcReallocCont(void *ptr, int contLen); -void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); -void rpcSendResponse(const SRpcMsg *pMsg); -void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet); -int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); -void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); -int rpcReportProgress(void *pConn, char *pCont, int contLen); -void rpcCancelRequest(int64_t rid); +void rpcCleanup(); +void * rpcOpen(const SRpcInit *pRpc); +void rpcClose(void *); +void * rpcMallocCont(int contLen); +void rpcFreeCont(void *pCont); +void * rpcReallocCont(void *ptr, int contLen); +void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); +void rpcSendResponse(const SRpcMsg *pMsg); +void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet); +int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); +void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +int rpcReportProgress(void *pConn, char *pCont, int contLen); +void rpcCancelRequest(int64_t rid); #ifdef __cplusplus } From 846d9194cf3a4aa0315d587b87d4ef2cee8ec85c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:46:15 +0800 Subject: [PATCH 15/36] get rid of compile warnning --- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index 7b62b0299d..fef7ad9d43 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -37,7 +37,7 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); - SRpcMsg* SendMsg(int8_t msgType, void* pCont, int32_t contLen); + SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); private: void InitLog(const char* path); diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 76d742d751..f3fe8cfa86 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -60,7 +60,7 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } -SRpcMsg* Testbase::SendMsg(int8_t msgType, void* pCont, int32_t contLen) { +SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; rpcMsg.contLen = contLen; From be6c080acf5f49cba1793ffb44fa91df818c3582 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:50:05 +0800 Subject: [PATCH 16/36] get rid of compile warning --- include/common/tmsgdef.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 0f8b97b519..05373cda97 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -22,6 +22,8 @@ #if defined(TD_MSG_INFO_) +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE #define TD_NEW_MSG_SEG(TYPE) "null", #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) MSG, MSG "-rsp", @@ -29,6 +31,8 @@ char *tMsgInfo[] = { #elif defined(TD_MSG_NUMBER_) +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE #define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE##_NUM, TYPE##_RSP_NUM, @@ -36,6 +40,8 @@ enum { #elif defined(TD_MSG_DICT_) +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE #define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) @@ -43,6 +49,8 @@ int tMsgDict[] = { #elif defined(TD_MSG_SEG_CODE_) +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE #define TD_NEW_MSG_SEG(TYPE) TYPE##_SEG_CODE, #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) @@ -50,6 +58,8 @@ enum { #else +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE #define TD_NEW_MSG_SEG(TYPE) TYPE = ((TYPE##_SEG_CODE) << 8), #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE, TYPE##_RSP, From a4a38e2256473ebf0403c189774c8c20777b2d20 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:50:41 +0800 Subject: [PATCH 17/36] just a rename --- source/common/src/{taosmsg.c => tmsg.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/common/src/{taosmsg.c => tmsg.c} (100%) diff --git a/source/common/src/taosmsg.c b/source/common/src/tmsg.c similarity index 100% rename from source/common/src/taosmsg.c rename to source/common/src/tmsg.c From 3721da020d997c699bce98a598643c6feaea50e6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:53:05 +0800 Subject: [PATCH 18/36] get rid of compile warning --- include/dnode/vnode/vnode.h | 4 ++-- source/dnode/vnode/impl/src/vnodeRequest.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index e708d7b545..812f313e71 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -246,8 +246,8 @@ static FORCE_INLINE void vnodeSetCreateNtbReq(SVnodeReq *pReq, char *name, uint3 pReq->ctReq.ntbCfg.pSchema = pSchema; } -int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); -void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, tmsg_t type); +void *vnodeParseReq(void *buf, SVnodeReq *pReq, tmsg_t type); /* ------------------------ FOR COMPILE ------------------------ */ diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 545d89ebb7..efbba6352f 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -18,7 +18,7 @@ static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); -int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, tmsg_t type) { int tsize = 0; tsize += taosEncodeFixedU64(buf, pReq->ver); @@ -36,7 +36,7 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { return tsize; } -void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { +void *vnodeParseReq(void *buf, SVnodeReq *pReq, tmsg_t type) { buf = taosDecodeFixedU64(buf, &(pReq->ver)); switch (type) { From 75ac5b00a5d56c555015b4c3585cf4183b8e004f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 24 Dec 2021 15:55:06 +0800 Subject: [PATCH 19/36] make compile --- source/common/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/test/CMakeLists.txt b/source/common/test/CMakeLists.txt index ee2e55533e..03ca95ff64 100644 --- a/source/common/test/CMakeLists.txt +++ b/source/common/test/CMakeLists.txt @@ -22,7 +22,7 @@ add_executable(tmsgTest "") target_sources(tmsgTest PRIVATE "tmsgTest.cpp" - "../src/taosmsg.c" + "../src/tmsg.c" ) target_include_directories(tmsgTest PUBLIC "${CMAKE_SOURCE_DIR}/include/common/") target_link_libraries(tmsgTest PUBLIC os util gtest gtest_main) \ No newline at end of file From b98c6f7e042227d7073ac89a84d3e191bc7128a8 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 24 Dec 2021 04:14:29 -0500 Subject: [PATCH 20/36] TD-12506 merge 3.0 --- source/client/src/clientImpl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index fbe0b8e6fc..da401ebcc6 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -227,6 +227,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { SQueryDag* pDag = NULL; void* pJob = NULL; + terrno = TSDB_CODE_SUCCESS; CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return); if (qIsDdlQuery(pQuery)) { From 9f3ef6cd7947070fb49a131f75fe77d3cb7f387d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 24 Dec 2021 01:35:39 -0800 Subject: [PATCH 21/36] adjust rpc code after change msgtype from int8 to int16 --- include/common/tmsg.h | 1 + source/dnode/mgmt/impl/src/dndDnode.c | 4 +- source/dnode/mgmt/impl/src/dndTransport.c | 170 +++++++++++----------- source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/dnode/mnode/impl/inc/mndTrans.h | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 8 +- source/dnode/mnode/impl/src/mnode.c | 13 +- source/libs/transport/inc/rpcHead.h | 2 +- source/libs/transport/src/rpcMain.c | 20 +-- 9 files changed, 112 insertions(+), 110 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 6dda3b195e..2c5f7346ca 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -48,6 +48,7 @@ extern int tMsgDict[]; #define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) #define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) #define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] +#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)) typedef uint16_t tmsg_t; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index df82855c36..6b5aeb078a 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -63,7 +63,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { } void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { - int32_t msgType = pMsg->msgType; + tmsg_t msgType = pMsg->msgType; SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); @@ -369,7 +369,7 @@ void dndSendStatusMsg(SDnode *pDnode) { dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); - SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS}; + SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = 9527}; pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index ac00e1e4f2..b8ebe3f884 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -31,104 +31,104 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { // msg from client to dnode - pMgmt->msgFp[TDMT_VND_SUBMIT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TDMT_VND_FETCH] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TDMT_MND_CREATE_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_ALTER_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_TABLE_META] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_VND_TABLES_META] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TDMT_VND_MQ_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TDMT_VND_MQ_CONSUME] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TDMT_VND_MQ_CONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_MQ_SET_CUR] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_RES_READY] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TDMT_VND_TASKS_STATUS] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TDMT_VND_CANCEL_TASK] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TDMT_VND_DROP_TASK] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SUBMIT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_QUERY)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_QUERY)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONSUME)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONNECT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_DISCONNECT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CUR)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_RES_READY)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TASKS_STATUS)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CANCEL_TASK)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TASK)] = dndProcessVnodeFetchMsg; // msg from client to mnode - pMgmt->msgFp[TDMT_MND_CONNECT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_MND_CREATE_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_ALTER_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_ALTER_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CONFIG_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_USE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_ALTER_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_SYNC_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_COMPACT_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_RETRIEVE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_CREATE_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_ALTER_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_DROP_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_VGROUP_LIST] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_MND_KILL_QUERY] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_KILL_CONN] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_HEARTBEAT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_MND_SHOW] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_MND_SHOW_RETRIEVE] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONNECT)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONFIG_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_MNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_MNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_USE_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SYNC_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_COMPACT_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_VGROUP_LIST)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_KILL_QUERY)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_KILL_CONN)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_HEARTBEAT)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; // message from client to dnode - pMgmt->msgFp[TDMT_DND_NETWORK_TEST] = dndProcessDnodeReq; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_NETWORK_TEST)] = dndProcessDnodeReq; // message from mnode to vnode - pMgmt->msgFp[TDMT_VND_CREATE_STB] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_CREATE_STB_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_ALTER_STB] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_ALTER_STB_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_DROP_STB] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TDMT_VND_DROP_STB_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_STB_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_STB_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_STB_RSP)] = dndProcessMnodeWriteMsg; // message from mnode to dnode - pMgmt->msgFp[TDMT_DND_CREATE_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_CREATE_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_ALTER_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_ALTER_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_DROP_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_DROP_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_SYNC_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_SYNC_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_AUTH_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_AUTH_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_COMPACT_VNODE] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_COMPACT_VNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_CREATE_MNODE] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_CREATE_MNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_ALTER_MNODE] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_ALTER_MNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_DROP_MNODE] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TDMT_DND_DROP_MNODE_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_DND_CONFIG_DNODE] = dndProcessDnodeReq; - pMgmt->msgFp[TDMT_DND_CONFIG_DNODE_RSP] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_SYNC_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_SYNC_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_AUTH_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_AUTH_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_COMPACT_VNODE)] = dndProcessVnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_COMPACT_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_MNODE)] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE)] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE)] = dndProcessMnodeMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CONFIG_DNODE)] = dndProcessDnodeReq; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CONFIG_DNODE_RSP)] = dndProcessMnodeWriteMsg; // message from dnode to mnode - pMgmt->msgFp[TDMT_MND_GRANT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_GRANT_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TDMT_MND_STATUS] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TDMT_MND_STATUS_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TDMT_MND_AUTH] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TDMT_MND_AUTH_RSP] = dndProcessDnodeRsp; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessDnodeRsp; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessDnodeRsp; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH_RSP)] = dndProcessDnodeRsp; } static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnode *pDnode = parent; STransMgmt *pMgmt = &pDnode->tmgmt; - int32_t msgType = pMsg->msgType; + tmsg_t msgType = pMsg->msgType; if (dndGetStat(pDnode) == DND_STAT_STOPPED) { if (pMsg == NULL || pMsg->pCont == NULL) return; @@ -137,7 +137,7 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { return; } - DndMsgFp fp = pMgmt->msgFp[msgType]; + DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { (*fp)(pDnode, pMsg, pEpSet); dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); @@ -186,7 +186,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnode *pDnode = param; STransMgmt *pMgmt = &pDnode->tmgmt; - int32_t msgType = pMsg->msgType; + tmsg_t msgType = pMsg->msgType; if (msgType == TDMT_DND_NETWORK_TEST) { dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pMsg->handle, pMsg->ahandle, pMsg->code); dndProcessDnodeReq(pDnode, pMsg, pEpSet); @@ -214,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { return; } - DndMsgFp fp = pMgmt->msgFp[msgType]; + DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); (*fp)(pDnode, pMsg, pEpSet); diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 5c78289102..ba8746c009 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -87,7 +87,7 @@ typedef struct 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, int32_t msgType, MndMsgFp fp); +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 a8d37ba655..a424c315f9 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -24,7 +24,7 @@ extern "C" { typedef struct { SEpSet epSet; - int8_t msgType; + tmsg_t msgType; int8_t msgSent; int8_t msgReceived; int32_t errCode; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1c0a9ad071..354d456cc4 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -132,7 +132,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { for (int32_t i = 0; i < redoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->redoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT8(pRaw, dataPos, pAction->msgType) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType) SDB_SET_INT32(pRaw, dataPos, pAction->contLen) SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen); } @@ -140,7 +140,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { for (int32_t i = 0; i < undoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->undoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT8(pRaw, dataPos, pAction->msgType) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType) SDB_SET_INT32(pRaw, dataPos, pAction->contLen) SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen); } @@ -243,7 +243,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < redoActionNum; ++i) { STransAction action = {0}; SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType) + SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) action.pCont = malloc(action.contLen); if (action.pCont == NULL) { @@ -262,7 +262,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < undoActionNum; ++i) { STransAction action = {0}; SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType) + SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) action.pCont = malloc(action.contLen); if (action.pCont == NULL) { diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 0199b0c583..26b1c71a10 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -374,7 +374,7 @@ void mndSendRsp(SMnodeMsg *pMsg, int32_t code) { static void mndProcessRpcMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; int32_t code = 0; - int32_t msgType = pMsg->rpcMsg.msgType; + tmsg_t msgType = pMsg->rpcMsg.msgType; void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); @@ -392,10 +392,10 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) { goto PROCESS_RPC_END; } - MndMsgFp fp = pMnode->msgFp[msgType]; + 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 not handle", pMsg, ahandle); + mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle); goto PROCESS_RPC_END; } @@ -425,9 +425,10 @@ PROCESS_RPC_END: } } -void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { - if (msgType >= 0 && msgType < TDMT_MAX) { - pMnode->msgFp[msgType] = fp; +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) { + tmsg_t type = TMSG_INDEX(msgType); + if (type >= 0 && type < TDMT_MAX) { + pMnode->msgFp[type] = fp; } } diff --git a/source/libs/transport/inc/rpcHead.h b/source/libs/transport/inc/rpcHead.h index 5b401ac54b..6e98bbd563 100644 --- a/source/libs/transport/inc/rpcHead.h +++ b/source/libs/transport/inc/rpcHead.h @@ -52,7 +52,7 @@ typedef struct { char user[TSDB_UNI_LEN]; // user ID uint16_t port; // for UDP only, port may be changed char empty[1]; // reserved - uint8_t msgType; // message type + uint16_t msgType; // message type int32_t msgLen; // message length including the header iteslf uint32_t msgVer; int32_t code; // code in response message diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 71304fcca8..a9098b5053 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -74,7 +74,7 @@ typedef struct { SEpSet epSet; // ip list provided by app void *ahandle; // handle provided by app struct SRpcConn *pConn; // pConn allocated - char msgType; // message type + tmsg_t msgType; // message type uint8_t *pCont; // content provided by app int32_t contLen; // content length int32_t code; // error code @@ -108,8 +108,8 @@ typedef struct SRpcConn { uint16_t tranId; // outgoing transcation ID, for build message uint16_t outTranId; // outgoing transcation ID uint16_t inTranId; // transcation ID for incoming msg - uint8_t outType; // message type for outgoing request - uint8_t inType; // message type for incoming request + tmsg_t outType; // message type for outgoing request + tmsg_t inType; // message type for incoming request void *chandle; // handle passed by TCP/UDP connection layer void *ahandle; // handle provided by upper app layter int retry; // number of retry for sending request @@ -409,7 +409,7 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t // connection type is application specific. // for TDengine, all the query, show commands shall have TCP connection - char type = pMsg->msgType; + tmsg_t type = pMsg->msgType; if (type == TDMT_VND_QUERY || type == TDMT_MND_SHOW_RETRIEVE || type == TDMT_VND_FETCH || type == TDMT_MND_VGROUP_LIST || type == TDMT_VND_TABLES_META || type == TDMT_VND_TABLE_META @@ -957,7 +957,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv, SRpcReqCont sid = htonl(pHead->destId); *ppContext = NULL; - if (pHead->msgType >= TDMT_MAX || pHead->msgType <= 0) { + if (TMSG_INDEX(pHead->msgType) >= TDMT_MAX || TMSG_INDEX(pHead->msgType) <= 0) { tDebug("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL; } @@ -1094,7 +1094,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { SRpcReqContext *pContext; pConn = rpcProcessMsgHead(pRpc, pRecv, &pContext); - if (pHead->msgType >= 1 && pHead->msgType < TDMT_MAX) { + if (TMSG_INDEX(pHead->msgType) >= 1 && TMSG_INDEX(pHead->msgType) < TDMT_MAX) { tDebug("%s %p %p, %s received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), pRecv->ip, pRecv->port, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); @@ -1112,11 +1112,11 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE) { rpcCloseConn(pConn); } - if (pHead->msgType + 1 > 1 && pHead->msgType+1 < TDMT_MAX) { + if (TMSG_INDEX(pHead->msgType) + 1 > 1 && TMSG_INDEX(pHead->msgType) + 1 < TDMT_MAX) { tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType+1), code); } else { tError("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), code); - } + } } } else { // msg is passed to app only parsing is ok rpcProcessIncomingMsg(pConn, pHead, pContext); @@ -1262,7 +1262,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) { memset(msg, 0, sizeof(SRpcHead)); pReplyHead->version = pRecvHead->version; - pReplyHead->msgType = (char)(pRecvHead->msgType + 1); + pReplyHead->msgType = (tmsg_t)(pRecvHead->msgType + 1); pReplyHead->spi = 0; pReplyHead->encrypt = pRecvHead->encrypt; pReplyHead->tranId = pRecvHead->tranId; @@ -1292,7 +1292,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) { SRpcHead *pHead = rpcHeadFromCont(pContext->pCont); char *msg = (char *)pHead; int msgLen = rpcMsgLenFromCont(pContext->contLen); - char msgType = pContext->msgType; + tmsg_t msgType = pContext->msgType; pContext->numOfTry++; SRpcConn *pConn = rpcSetupConnToServer(pContext); From 3813df6c2eb00182580826579d87fb644054d881 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 24 Dec 2021 04:38:49 -0500 Subject: [PATCH 22/36] TD-12506 merge 3.0 --- source/client/src/clientImpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index da401ebcc6..a508962325 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -240,7 +240,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { _return: qDestoryQuery(pQuery); qDestroyQueryDag(pDag); - if (NULL != pRequest) { + if (NULL != pRequest && TSDB_CODE_SUCCESS != terrno) { pRequest->code = terrno; } return pRequest; From 7ca0a88ee274d25ecf6e5dadacf82b9569fe659e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 24 Dec 2021 23:55:15 +0800 Subject: [PATCH 23/36] add skiplist add --- source/libs/index/test/indexTests.cc | 364 +++++++++++++++++++++------ 1 file changed, 286 insertions(+), 78 deletions(-) diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 6c6f45bd11..de82350aad 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -16,10 +16,12 @@ #include #include "index.h" #include "indexInt.h" +#include "index_cache.h" #include "index_fst.h" #include "index_fst_counting_writer.h" #include "index_fst_util.h" #include "index_tfile.h" +#include "tskiplist.h" #include "tutil.h" using namespace std; class FstWriter { @@ -110,58 +112,6 @@ class FstReadMemory { size_t _size; }; -// TEST(IndexTest, index_create_test) { -// SIndexOpts *opts = indexOptsCreate(); -// SIndex *index = indexOpen(opts, "./test"); -// if (index == NULL) { -// std::cout << "index open failed" << std::endl; -// } -// -// -// // write -// for (int i = 0; i < 100000; i++) { -// SIndexMultiTerm* terms = indexMultiTermCreate(); -// std::string val = "field"; -// -// indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size()); -// -// val.append(std::to_string(i)); -// indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size()); -// -// val.insert(0, std::to_string(i)); -// indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size()); -// -// val.append("const"); -// indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size()); -// -// -// indexPut(index, terms, i); -// indexMultiTermDestroy(terms); -// } -// -// -// // query -// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST); -// -// indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX); -// indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM); -// -// SArray *result = (SArray *)taosArrayInit(10, sizeof(int)); -// indexSearch(index, multiQuery, result); -// -// std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl; -// for (int i = 0; i < taosArrayGetSize(result); i++) { -// int *v = (int *)taosArrayGet(result, i); -// std::cout << "value --->" << *v << std::endl; -// } -// // add more test case -// indexMultiTermQueryDestroy(multiQuery); -// -// indexOptsDestroy(opts); -// indexClose(index); -// // -//} - #define L 100 #define M 100 #define N 100 @@ -421,6 +371,7 @@ class TFileObj { int colId_; }; + class IndexTFileEnv : public ::testing::Test { protected: virtual void SetUp() { @@ -428,22 +379,6 @@ class IndexTFileEnv : public ::testing::Test { taosMkDir(dir.c_str()); tfInit(); fObj = new TFileObj(dir, colName); - - // std::string colName("voltage"); - // header.suid = 1; - // header.version = 1; - // memcpy(header.colName, colName.c_str(), colName.size()); - // header.colType = TSDB_DATA_TYPE_BINARY; - - // std::string path(dir); - // int colId = 2; - // char buf[64] = {0}; - // sprintf(buf, "%" PRIu64 "-%d-%d.tindex", header.suid, colId, header.version); - // path.append("/").append(buf); - - // ctx = writerCtxCreate(TFile, path.c_str(), false, 64 * 1024 * 1024); - - // twrite = tfileWriterCreate(ctx, &header); } virtual void TearDown() { @@ -460,16 +395,8 @@ class IndexTFileEnv : public ::testing::Test { int coldId = 2; int version = 1; int colType = TSDB_DATA_TYPE_BINARY; - - // WriterCtx* ctx = NULL; - // TFileHeader header; - // TFileWriter* twrite = NULL; }; -// static TFileWriter* genTFileWriter(const char* path, TFileHeader* header) { -// char buf[128] = {0}; -// WriterCtx* ctx = writerCtxCreate(TFile, path, false, ) -//} static TFileValue* genTFileValue(const char* val) { TFileValue* tv = (TFileValue*)calloc(1, sizeof(TFileValue)); int32_t vlen = strlen(val) + 1; @@ -492,7 +419,7 @@ static void destroyTFileValue(void* val) { TEST_F(IndexTFileEnv, test_tfile_write) { TFileValue* v1 = genTFileValue("c"); - TFileValue* v2 = genTFileValue("a"); + TFileValue* v2 = genTFileValue("ab"); TFileValue* v3 = genTFileValue("b"); TFileValue* v4 = genTFileValue("d"); @@ -510,7 +437,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) { taosArrayDestroy(data); std::string colName("voltage"); - std::string colVal("b"); + std::string colVal("ab"); SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; @@ -521,3 +448,284 @@ TEST_F(IndexTFileEnv, test_tfile_write) { // tfileWriterDestroy(twrite); } +class CacheObj { + public: + CacheObj() { + // TODO + cache = indexCacheCreate(); + } + int Put(SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid) { + int ret = indexCachePut(cache, term, colId, version, uid); + if (ret != 0) { + // + std::cout << "failed to put into cache: " << ret << std::endl; + } + return ret; + } + int Get(SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s) { + int ret = indexCacheSearch(cache, query, colId, version, result, s); + if (ret != 0) { + // + std::cout << "failed to get from cache:" << ret << std::endl; + } + return ret; + } + ~CacheObj() { + // TODO + indexCacheDestroy(cache); + } + + private: + IndexCache* cache = NULL; +}; + +class IndexCacheEnv : public ::testing::Test { + protected: + virtual void SetUp() { + // TODO + coj = new CacheObj(); + } + virtual void TearDown() { + delete coj; + // formate + } + CacheObj* coj; +}; + +TEST_F(IndexCacheEnv, cache_test) { + int count = 10; + + int16_t colId = 1; + int32_t version = 10; + uint64_t suid = 100; + std::string colName("voltage"); + std::string colVal("My God"); + for (size_t i = 0; i < count; i++) { + colVal += ('a' + i); + SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version, suid); + version++; + } + + // coj->Get(); +} + +typedef struct CTerm { + char buf[16]; + char version[8]; + int val; + int other; +} CTerm; +CTerm* cTermCreate(const char* str, const char* version, int val) { + CTerm* tm = (CTerm*)calloc(1, sizeof(CTerm)); + memcpy(tm->buf, str, strlen(str)); + memcpy(tm->version, version, strlen(version)); + tm->val = val; + tm->other = -100; + return tm; +} +int termCompar(const void* a, const void* b) { + printf("a: %s \t b: %s\n", (char*)a, (char*)b); + int ret = strncmp((char*)a, (char*)b, 16); + if (ret == 0) { + // + return strncmp((char*)a + 16, (char*)b + 16, 8); + } + return ret; +} + +int SerialTermTo(char* buf, CTerm* term) { + char* p = buf; + memcpy(buf, term->buf, sizeof(term->buf)); + buf += sizeof(term->buf); + + // memcpy(buf, term->version, sizeof(term->version)); + // buf += sizeof(term->version); + return buf - p; +} +static char* getTermKey(const void* pData) { + CTerm* p = (CTerm*)pData; + return (char*)p->buf; +} +#define MAX_TERM_KEY_LEN 128 +class SkiplistObj { + public: + // max_key_len: + // + SkiplistObj() { + slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, termCompar, SL_ALLOW_DUP_KEY, getTermKey); + } + int Put(CTerm* term, uint64_t suid) { + char buf[MAX_TERM_KEY_LEN] = {0}; + int sz = SerialTermTo(buf, term); + + char* pBuf = (char*)calloc(1, sz + sizeof(suid)); + + memcpy(pBuf, buf, sz); + memcpy(pBuf + sz, &suid, sizeof(suid)); + // int32_t level, headsize; + // tSkipListNewNodeInfo(slt, &level, &headsize); + + // SSkipListNode* node = (SSkipListNode*)calloc(1, headsize + strlen(buf) + sizeof(suid)); + // node->level = level; + // char* d = (char*)SL_GET_NODE_DATA(node); + // memcpy(d, buf, strlen(buf)); + // memcpy(d + strlen(buf), &suid, sizeof(suid)); + SSkipListNode* node = tSkipListPut(slt, pBuf); + tSkipListPrint(slt, 1); + free(pBuf); + return 0; + } + + int Get(int key, char* buf, int version) { + // CTerm term; + // term.key = key; + //// term.version = version; + // memcpy(term.buf, buf, strlen(buf)); + + // char tbuf[128] = {0}; + // SerialTermTo(tbuf, &term); + + // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + // SSkipListNode* node = tSkipListIterGet(iter); + // CTerm* ct = (CTerm*)SL_GET_NODE_DATA(node); + // printf("key: %d\t, version: %d\t, buf: %s\n", ct->key, ct->version, ct->buf); + // while (iter) { + // assert(tSkipListIterNext(iter) == true); + // SSkipListNode* node = tSkipListIterGet(iter); + // // ugly formate + // CTerm* t = (CTerm*)SL_GET_NODE_KEY(slt, node); + // printf("key: %d\t, version: %d\t, buf: %s\n", t->key, t->version, t->buf); + //} + return 0; + } + ~SkiplistObj() { + // TODO + // indexCacheDestroy(cache); + } + + private: + SSkipList* slt; +}; + +typedef struct KV { + int32_t k; + int32_t v; +} KV; +int kvCompare(const void* a, const void* b) { + int32_t av = *(int32_t*)a; + int32_t bv = *(int32_t*)b; + return av - bv; +} +char* getKVkey(const void* a) { + return (char*)(&(((KV*)a)->v)); + // KV* kv = (KV*)a; +} +int testKV() { + SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, kvCompare, SL_DISCARD_DUP_KEY, getKVkey); + { + KV t = {.k = 1, .v = 5}; + tSkipListPut(slt, (void*)&t); + } + { + KV t = {.k = 2, .v = 3}; + tSkipListPut(slt, (void*)&t); + } + + KV value = {.k = 4, .v = 5}; + char* key = getKVkey(&value); + // const char* key = "Hello"; + SArray* arr = tSkipListGet(slt, (SSkipListKey)&key); + for (size_t i = 0; i < taosArrayGetSize(arr); i++) { + SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); + int32_t* ct = (int32_t*)SL_GET_NODE_KEY(slt, node); + + printf("Get key: %d\n", *ct); + // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + } + return 1; +} + +int testComplicate() { + SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, termCompar, SL_ALLOW_DUP_KEY, getTermKey); + { + CTerm* tm = cTermCreate("val", "v1", 10); + tSkipListPut(slt, (char*)tm); + } + { + CTerm* tm = cTermCreate("val1", "v2", 2); + tSkipListPut(slt, (char*)tm); + } + { + CTerm* tm = cTermCreate("val3", "v3", -1); + tSkipListPut(slt, (char*)tm); + } + { + CTerm* tm = cTermCreate("val3", "v4", 2); + tSkipListPut(slt, (char*)tm); + } + { + CTerm* tm = cTermCreate("val3", "v5", -1); + char* key = getTermKey(tm); + SArray* arr = tSkipListGet(slt, (SSkipListKey)key); + for (size_t i = 0; i < taosArrayGetSize(arr); i++) { + SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); + CTerm* ct = (CTerm*)SL_GET_NODE_KEY(slt, node); + printf("other; %d\tbuf: %s\t, version: %s, val: %d\n", ct->other, ct->buf, ct->version, ct->val); + // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + } + free(tm); + taosArrayDestroy(arr); + } + return 1; +} +int strCompare(const void* a, const void* b) { + const char* sa = (char*)a; + const char* sb = (char*)b; + return strcmp(sa, sb); +} +void testString() { + SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, strCompare, SL_ALLOW_DUP_KEY, getTermKey); + { + tSkipListPut(slt, (void*)"Hello"); + tSkipListPut(slt, (void*)"World"); + tSkipListPut(slt, (void*)"YI"); + } + + const char* key = "YI"; + SArray* arr = tSkipListGet(slt, (SSkipListKey)key); + for (size_t i = 0; i < taosArrayGetSize(arr); i++) { + SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); + char* ct = (char*)SL_GET_NODE_KEY(slt, node); + printf("Get key: %s\n", ct); + // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + } +} +// class IndexSkip : public ::testing::Test { +// protected: +// virtual void SetUp() { +// // TODO +// sObj = new SkiplistObj(); +// } +// virtual void TearDown() { +// delete sObj; +// // formate +// } +// SkiplistObj* sObj; +//}; + +// TEST_F(IndexSkip, skip_test) { +// std::string val("Hello"); +// std::string minVal = val; +// for (size_t i = 0; i < 10; i++) { +// CTerm* t = (CTerm*)calloc(1, sizeof(CTerm)); +// t->key = 1; +// t->version = i; +// +// val[val.size() - 1] = 'a' + i; +// memcpy(t->buf, val.c_str(), val.size()); +// sObj->Put(t, 10); +// free(t); +// } +// sObj->Get(1, (char*)(minVal.c_str()), 1000000); +//} From a724e85b495911cbb02c25c6edf9f79526887a11 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 24 Dec 2021 23:56:53 +0800 Subject: [PATCH 24/36] add skiplist test --- source/libs/index/test/indexTests.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index de82350aad..18ad37de1f 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -578,6 +578,7 @@ class SkiplistObj { } int Get(int key, char* buf, int version) { + // TODO // CTerm term; // term.key = key; //// term.version = version; From 856104c4f3714affcd67286fafca5e2b0bdc625c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 25 Dec 2021 13:27:37 +0800 Subject: [PATCH 25/36] minor changes --- source/dnode/mnode/impl/inc/mndTopic.h | 2 +- source/dnode/mnode/impl/src/mndFunc.c | 2 +- source/dnode/mnode/impl/src/mndStb.c | 4 +- source/dnode/mnode/impl/src/mndTopic.c | 56 ++++++------ source/dnode/mnode/impl/src/mndTrans.c | 115 +++++++++---------------- 5 files changed, 73 insertions(+), 106 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h index 62d213b8a2..d092f47d4b 100644 --- a/source/dnode/mnode/impl/inc/mndTopic.h +++ b/source/dnode/mnode/impl/inc/mndTopic.h @@ -26,7 +26,7 @@ int32_t mndInitTopic(SMnode *pMnode); void mndCleanupTopic(SMnode *pMnode); STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName); -void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic); +void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 7e9d4ebeab..c6209c949f 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -441,7 +441,7 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le } if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { - int32_t bytes = len > 0 ? (int)(len - VARSTR_HEADER_SIZE) : len; + int32_t bytes = len > 0 ? (int32_t)(len - VARSTR_HEADER_SIZE) : len; snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes / 4 : bytes); buf[buflen - 1] = 0; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 8b62c2f02d..411f68e7e1 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -834,8 +834,8 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM } static void mndExtractTableName(char *tableId, char *name) { - int pos = -1; - int num = 0; + int32_t pos = -1; + int32_t num = 0; for (pos = 0; tableId[pos] != 0; ++pos) { if (tableId[pos] == '.') num++; if (num == 2) break; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 5b45aea2e6..648ebb14fc 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -14,18 +14,18 @@ */ #define _DEFAULT_SOURCE -#include "mndStb.h" #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" #include "mndShow.h" +#include "mndStb.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" #include "tname.h" -#define TSDB_TOPIC_VER_NUMBER 1 -#define TSDB_TOPIC_RESERVE_SIZE 64 +#define MND_TOPIC_VER_NUMBER 1 +#define MND_TOPIC_RESERVE_SIZE 64 static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic); static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw); @@ -73,8 +73,8 @@ int32_t mndInitTopic(SMnode *pMnode) { void mndCleanupTopic(SMnode *pMnode) {} static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { - int32_t size = sizeof(STopicObj) + TSDB_TOPIC_RESERVE_SIZE; - SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, TSDB_TOPIC_VER_NUMBER, size); + int32_t size = sizeof(STopicObj) + MND_TOPIC_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); if (pRaw == NULL) return NULL; int32_t dataPos = 0; @@ -90,7 +90,7 @@ static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen); SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen); - SDB_SET_RESERVE(pRaw, dataPos, TSDB_TOPIC_RESERVE_SIZE); + SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE); SDB_SET_DATALEN(pRaw, dataPos); return pRaw; @@ -100,14 +100,14 @@ static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; - if (sver != TSDB_TOPIC_VER_NUMBER) { - mError("failed to decode stable since %s", terrstr()); + if (sver != MND_TOPIC_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode topic since %s", terrstr()); return NULL; } - int32_t size = sizeof(STopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); - SSdbRow *pRow = sdbAllocRow(size); + int32_t size = sizeof(STopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); STopicObj *pTopic = sdbGetRowObj(pRow); if (pTopic == NULL) return NULL; @@ -124,7 +124,7 @@ static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->sqlLen); SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->sql, pTopic->sqlLen); - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_TOPIC_RESERVE_SIZE); + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TOPIC_RESERVE_SIZE); return pRow; } @@ -168,7 +168,7 @@ static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj } STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName) { - SSdb *pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; STopicObj *pTopic = sdbAcquire(pSdb, SDB_TOPIC, topicName); if (pTopic == NULL) { terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; @@ -208,7 +208,7 @@ static SCreateTopicInternalMsg *mndBuildCreateTopicMsg(SMnode *pMnode, SVgObj *p pCreate->sverson = htonl(pTopic->version); pCreate->sql = malloc(pTopic->sqlLen); - if(pCreate->sql == NULL) { + if (pCreate->sql == NULL) { free(pCreate); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -216,7 +216,7 @@ static SCreateTopicInternalMsg *mndBuildCreateTopicMsg(SMnode *pMnode, SVgObj *p memcpy(pCreate->sql, pTopic->sql, pTopic->sqlLen); pCreate->executor = malloc(pTopic->execLen); - if(pCreate->executor == NULL) { + if (pCreate->executor == NULL) { free(pCreate); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -244,7 +244,7 @@ static SDropTopicInternalMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgro } static int32_t mndCheckCreateTopicMsg(SCreateTopicMsg *pCreate) { - //deserialize and other stuff + // deserialize and other stuff return 0; } @@ -413,7 +413,7 @@ CREATE_TOPIC_OVER: } static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SCreateTopicMsg *pCreate = pMsg->rpcMsg.pCont; mDebug("topic:%s, start to create", pCreate->name); @@ -436,7 +436,7 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { } } - //topic should have different name with stb + // topic should have different name with stb SStbObj *pStb = mndAcquireStb(pMnode, pCreate->name); if (pStb != NULL) { sdbRelease(pMnode->pSdb, pStb); @@ -492,7 +492,7 @@ static int32_t mndCheckAlterTopicMsg(SAlterTopicMsg *pAlter) { static int32_t mndUpdateTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pOldTopic, STopicObj *pNewTopic) { return 0; } static int32_t mndProcessAlterTopicMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SAlterTopicMsg *pAlter = pMsg->rpcMsg.pCont; mDebug("topic:%s, start to alter", pAlter->name); @@ -606,7 +606,7 @@ DROP_TOPIC_OVER: } static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SDropTopicMsg *pDrop = pMsg->rpcMsg.pCont; mDebug("topic:%s, start to drop", pDrop->name); @@ -705,7 +705,7 @@ static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg) { return 0; } -static int32_t mndProcessCreateTopicInRsp(SMnodeMsg* pMsg) { +static int32_t mndProcessCreateTopicInRsp(SMnodeMsg *pMsg) { mndTransHandleActionRsp(pMsg); return 0; } @@ -788,8 +788,8 @@ static int32_t mndGetTopicMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * } static void mndExtractTableName(char *tableId, char *name) { - int pos = -1; - int num = 0; + int32_t pos = -1; + int32_t num = 0; for (pos = 0; tableId[pos] != 0; ++pos) { if (tableId[pos] == '.') num++; if (num == 2) break; @@ -801,13 +801,13 @@ static void mndExtractTableName(char *tableId, char *name) { } static int32_t mndRetrieveTopic(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; - SSdb *pSdb = pMnode->pSdb; - int32_t numOfRows = 0; + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; STopicObj *pTopic = NULL; - int32_t cols = 0; - char *pWrite; - char prefix[64] = {0}; + int32_t cols = 0; + char *pWrite; + char prefix[64] = {0}; tstrncpy(prefix, pShow->db, 64); strcat(prefix, TS_PATH_DELIMITER); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 354d456cc4..966ee3c4b9 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -17,9 +17,9 @@ #include "mndTrans.h" #include "mndSync.h" -#define TSDB_TRANS_VER_NUMBER 1 -#define TSDB_TRN_ARRAY_SIZE 8 -#define TSDB_TRN_RESERVE_SIZE 64 +#define MND_TRANS_VER_NUMBER 1 +#define MND_TRANS_ARRAY_SIZE 8 +#define MND_TRANS_RESERVE_SIZE 64 static SSdbRaw *mndTransActionEncode(STrans *pTrans); static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw); @@ -61,7 +61,7 @@ int32_t mndInitTrans(SMnode *pMnode) { void mndCleanupTrans(SMnode *pMnode) {} static SSdbRaw *mndTransActionEncode(STrans *pTrans) { - int32_t rawDataLen = sizeof(STrans) + TSDB_TRN_RESERVE_SIZE; + int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE; int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs); @@ -93,7 +93,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { rawDataLen += (sizeof(STransAction) + pAction->contLen); } - SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER_NUMBER, rawDataLen); + SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, MND_TRANS_VER_NUMBER, rawDataLen); if (pRaw == NULL) { mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr()); return NULL; @@ -145,7 +145,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen); } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_TRN_RESERVE_SIZE) + SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE) SDB_SET_DATALEN(pRaw, dataPos); mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos); return pRaw; @@ -155,12 +155,9 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { int32_t code = 0; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) { - mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr()); - return NULL; - } + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; - if (sver != TSDB_TRANS_VER_NUMBER) { + if (sver != MND_TRANS_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; mError("failed to get check soft ver from raw:%p since %s", pRaw, terrstr()); return NULL; @@ -173,11 +170,11 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { return NULL; } - pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); - pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); + pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); + pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || pTrans->redoActions == NULL || pTrans->undoActions == NULL) { @@ -278,7 +275,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { } } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_TRN_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TRANS_RESERVE_SIZE) TRANS_DECODE_OVER: if (code != 0) { @@ -370,11 +367,11 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; pTrans->rpcHandle = rpcHandle; - pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); - pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); + pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); + pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || pTrans->redoActions == NULL || pTrans->undoActions == NULL) { @@ -504,7 +501,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { STrans *pNewTrans = mndAcquireTrans(pMnode, pTrans->id); if (pNewTrans == NULL) { - mError("trans:%d, failed to ready from sdb since %s", pTrans->id, terrstr()); + mError("trans:%d, failed to read from sdb since %s", pTrans->id, terrstr()); return -1; } @@ -526,19 +523,17 @@ int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) { if (taosArrayGetSize(pTrans->commitLogs) != 0) { mTrace("trans:%d, sync to other nodes", pTrans->id); - int32_t code = mndSyncPropose(pMnode, pRaw); - if (code != 0) { + if (mndSyncPropose(pMnode, pRaw) != 0) { mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); sdbFreeRaw(pRaw); return -1; } - mTrace("trans:%d, sync finished", pTrans->id); - code = sdbWrite(pMnode->pSdb, pRaw); - if (code != 0) { - mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); - return -1; - } + } + + if (sdbWrite(pMnode->pSdb, pRaw) != 0) { + mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); + return -1; } mDebug("trans:%d, commit finished", pTrans->id); @@ -614,7 +609,7 @@ void mndTransHandleActionRsp(SMnodeMsg *pMsg) { } int32_t actionNum = taosArrayGetSize(pTrans->redoActions); - if (action < 0 || action > actionNum) { + if (action < 0 || action >= actionNum) { mError("trans:%d, invalid action:%d", transId, action); goto HANDLE_ACTION_RSP_OVER; } @@ -636,6 +631,8 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) { SSdb *pSdb = pMnode->pSdb; int32_t arraySize = taosArrayGetSize(pArray); + if (arraySize == 0) return 0; + for (int32_t i = 0; i < arraySize; ++i) { SSdbRaw *pRaw = taosArrayGetP(pArray, i); int32_t code = sdbWriteNotFree(pSdb, pRaw); @@ -648,45 +645,15 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) { } static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->redoLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->redoLogs); - if (code != 0) { - mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute redo logs finished", pTrans->id) - } - } - - return code; + return mndTransExecuteLogs(pMnode, pTrans->redoLogs); } static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->undoLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->undoLogs); - if (code != 0) { - mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute undo logs finished", pTrans->id) - } - } - - return code; + return mndTransExecuteLogs(pMnode, pTrans->undoLogs); } static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->commitLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->commitLogs); - if (code != 0) { - mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute commit logs finished", pTrans->id) - } - } - - return code; + return mndTransExecuteLogs(pMnode, pTrans->commitLogs); } static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) { @@ -719,25 +686,25 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg); } - int32_t numOfReceivedMsgs = 0; - int32_t errorCode = 0; + int32_t numOfReceived = 0; + int32_t errCode = 0; for (int32_t action = 0; action < numOfActions; ++action) { STransAction *pAction = taosArrayGet(pArray, action); if (pAction == NULL) continue; if (pAction->msgSent && pAction->msgReceived) { - numOfReceivedMsgs++; + numOfReceived++; if (pAction->errCode != 0) { - errorCode = pAction->errCode; + errCode = pAction->errCode; } } } - if (numOfReceivedMsgs == numOfActions) { - mDebug("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errorCode); - terrno = errorCode; - return errorCode; + if (numOfReceived == numOfActions) { + mDebug("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errCode); + terrno = errCode; + return errCode; } else { - mDebug("trans:%d, %d of %d actions executed, code:0x%x", pTrans->id, numOfReceivedMsgs, numOfActions, errorCode); + mDebug("trans:%d, %d of %d actions executed, code:0x%x", pTrans->id, numOfReceived, numOfActions, errCode); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } } From 1f70617b371141758ae0bcd776104d4f359613da Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 25 Dec 2021 14:09:23 +0800 Subject: [PATCH 26/36] add ahandle to topic --- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/inc/mndTrans.h | 2 +- source/dnode/mnode/impl/src/mndDb.c | 6 +++--- source/dnode/mnode/impl/src/mndDnode.c | 4 ++-- source/dnode/mnode/impl/src/mndFunc.c | 4 ++-- source/dnode/mnode/impl/src/mndMnode.c | 4 ++-- source/dnode/mnode/impl/src/mndStb.c | 4 ++-- source/dnode/mnode/impl/src/mndTopic.c | 4 ++-- source/dnode/mnode/impl/src/mndTrans.c | 22 +++++++++------------- source/dnode/mnode/impl/src/mndUser.c | 6 +++--- 10 files changed, 27 insertions(+), 30 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 927b1e2e16..b21dc0841c 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -96,6 +96,7 @@ typedef struct { ETrnStage stage; ETrnPolicy policy; void *rpcHandle; + void *rpcAHandle; SArray *redoLogs; SArray *undoLogs; SArray *commitLogs; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index a424c315f9..2d57179f1c 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -35,7 +35,7 @@ typedef struct { int32_t mndInitTrans(SMnode *pMnode); void mndCleanupTrans(SMnode *pMnode); -STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle); +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg); void mndTransDrop(STrans *pTrans); int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw); int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 82aea79edb..6eb94eccf2 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -400,7 +400,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat } int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to create since %s", pCreate->db, terrstr()); goto CREATE_DB_OVER; @@ -608,7 +608,7 @@ static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbObj *pNewDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to update since %s", pOldDb->name, terrstr()); return terrno; @@ -772,7 +772,7 @@ static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *p static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to drop since %s", pDb->name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index f13bbed247..80c9f9544e 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -396,7 +396,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg * return terrno; } - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("dnode:%s, failed to create since %s", pCreate->ep, terrstr()); return -1; @@ -452,7 +452,7 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) { } static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index c6209c949f..638d984c69 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -147,7 +147,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncMsg *pC pFunc->pCode = pFunc->pData + pCreate->commentSize; memcpy(pFunc->pCode, pCreate->pCont + pCreate->commentSize, pFunc->codeSize); - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { free(pFunc); mError("func:%s, failed to create since %s", pCreate->name, terrstr()); @@ -195,7 +195,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncMsg *pC } static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pMsg, SFuncObj *pFunc) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("func:%s, failed to drop since %s", pFunc->name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 9f76060063..8f57a18a1d 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -334,7 +334,7 @@ static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode mnodeObj.updateTime = mnodeObj.createdTime; int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("mnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); goto CREATE_MNODE_OVER; @@ -500,7 +500,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("mnode:%d, failed to drop since %s", pObj->id, terrstr()); goto DROP_MNODE_OVER; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 411f68e7e1..0f577c3c3b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -415,7 +415,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre memcpy(stbObj.pSchema, pCreate->pSchema, totalSize); int32_t code = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("stb:%s, failed to create since %s", pCreate->name, terrstr()); return -1; @@ -614,7 +614,7 @@ static int32_t mndSetDropStbUndoActions(SMnode *pMnode, STrans *pTrans, SStbObj static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("stb:%s, failed to drop since %s", pStb->name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 648ebb14fc..04f6907918 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -367,7 +367,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCreateTopicMsg * #endif int32_t code = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; @@ -561,7 +561,7 @@ static int32_t mndSetDropTopicUndoActions(SMnode *pMnode, STrans *pTrans, STopic static int32_t mndDropTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pTopic) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to drop since %s", pTopic->name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 966ee3c4b9..2432e31b9e 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -27,7 +27,6 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans); static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOldTrans); static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans); -static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle); static void mndTransSendRpcRsp(STrans *pTrans, int32_t code); static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw); static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction); @@ -355,7 +354,7 @@ char *mndTransPolicyStr(ETrnPolicy policy) { } } -STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) { STrans *pTrans = calloc(1, sizeof(STrans)); if (pTrans == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -366,7 +365,8 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS); pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; - pTrans->rpcHandle = rpcHandle; + pTrans->rpcHandle = pMsg->handle; + pTrans->rpcAHandle = pMsg->ahandle; pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); @@ -413,11 +413,6 @@ void mndTransDrop(STrans *pTrans) { tfree(pTrans); } -static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) { - pTrans->rpcHandle = rpcHandle; - mTrace("trans:%d, set rpc handle:%p", pTrans->id, rpcHandle); -} - static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) { if (pArray == NULL || pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -506,6 +501,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { } pNewTrans->rpcHandle = pTrans->rpcHandle; + pNewTrans->rpcAHandle = pTrans->rpcAHandle; mndTransExecute(pMnode, pNewTrans); mndReleaseTrans(pMnode, pNewTrans); return 0; @@ -571,10 +567,11 @@ int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { static void mndTransSendRpcRsp(STrans *pTrans, int32_t code) { if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; - mDebug("trans:%d, send rpc rsp, RPC:%p code:0x%x", pTrans->id, pTrans->rpcHandle, code & 0xFFFF); + mDebug("trans:%d, send rpc rsp, RPC:%p ahandle:%p code:0x%x", pTrans->id, pTrans->rpcHandle, pTrans->rpcAHandle, + code & 0xFFFF); if (pTrans->rpcHandle != NULL) { - SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = code}; + SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = code, .ahandle = pTrans->rpcAHandle}; rpcSendResponse(&rspMsg); } } @@ -739,7 +736,6 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) { mDebug("trans:%d, stage from execute to commit", pTrans->id); } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { mDebug("trans:%d, stage keep on execute since %s", pTrans->id, tstrerror(code)); - return code; } else { if (pTrans->policy == TRN_POLICY_ROLLBACK) { pTrans->stage = TRN_STAGE_ROLLBACK; @@ -790,9 +786,9 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } break; case TRN_STAGE_ROLLBACK: - code = mndTransPerformRollbackStage(pMnode, pTrans); + code = mndTransRollback(pMnode, pTrans); if (code == 0) { - code = mndTransRollback(pMnode, pTrans); + mndTransPerformRollbackStage(pMnode, pTrans); } break; default: diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 9b5eca6d39..0926cf0c48 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -197,7 +197,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, userObj.updateTime = userObj.createdTime; userObj.superUser = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to create since %s", user, terrstr()); return -1; @@ -267,7 +267,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { } static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to update since %s", pOldUser->user, terrstr()); return -1; @@ -342,7 +342,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { } static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to drop since %s", pUser->user, terrstr()); return -1; From a60e9e40ed4ec23a9692331c5dfafc1219ac6268 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 14:35:39 +0800 Subject: [PATCH 27/36] more --- include/common/taosdef.h | 42 +++++------ include/common/tmsg.h | 126 ++++++++++++++++++++++++++++++++ include/common/tmsgdef.h | 2 +- include/dnode/vnode/meta/meta.h | 1 - include/util/tcoding.h | 11 +++ 5 files changed, 158 insertions(+), 24 deletions(-) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 9b2bb89793..da58f98e4c 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -20,36 +20,38 @@ extern "C" { #endif -#include "tdef.h" #include "taos.h" +#include "tdef.h" -#define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX}) -#define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN}) +typedef uint64_t tb_uid_t; + +#define TSWINDOW_INITIALIZER ((STimeWindow){INT64_MIN, INT64_MAX}) +#define TSWINDOW_DESC_INITIALIZER ((STimeWindow){INT64_MAX, INT64_MIN}) #define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) typedef enum { - TAOS_QTYPE_RPC = 1, - TAOS_QTYPE_FWD = 2, - TAOS_QTYPE_WAL = 3, - TAOS_QTYPE_CQ = 4, + TAOS_QTYPE_RPC = 1, + TAOS_QTYPE_FWD = 2, + TAOS_QTYPE_WAL = 3, + TAOS_QTYPE_CQ = 4, TAOS_QTYPE_QUERY = 5 } EQType; typedef enum { - TSDB_SUPER_TABLE = 1, // super table - TSDB_CHILD_TABLE = 2, // table created from super table - TSDB_NORMAL_TABLE = 3, // ordinary table - TSDB_STREAM_TABLE = 4, // table created from stream computing - TSDB_TEMP_TABLE = 5, // temp table created by nest query - TSDB_TABLE_MAX = 6 + TSDB_SUPER_TABLE = 1, // super table + TSDB_CHILD_TABLE = 2, // table created from super table + TSDB_NORMAL_TABLE = 3, // ordinary table + TSDB_STREAM_TABLE = 4, // table created from stream computing + TSDB_TEMP_TABLE = 5, // temp table created by nest query + TSDB_TABLE_MAX = 6 } ETableType; typedef enum { - TSDB_MOD_MNODE = 1, - TSDB_MOD_HTTP = 2, + TSDB_MOD_MNODE = 1, + TSDB_MOD_HTTP = 2, TSDB_MOD_MONITOR = 3, - TSDB_MOD_MQTT = 4, - TSDB_MOD_MAX = 5 + TSDB_MOD_MQTT = 4, + TSDB_MOD_MAX = 5 } EModuleType; typedef enum { @@ -64,11 +66,7 @@ typedef enum { TSDB_CHECK_ITEM_MAX } ECheckItemType; -typedef enum { - TD_ROW_DISCARD_UPDATE = 0, - TD_ROW_OVERWRITE_UPDATE = 1, - TD_ROW_PARTIAL_UPDATE = 2 -} TDUpdateConfig; +typedef enum { TD_ROW_DISCARD_UPDATE = 0, TD_ROW_OVERWRITE_UPDATE = 1, TD_ROW_PARTIAL_UPDATE = 2 } TDUpdateConfig; extern char *qtypeStr[]; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2c5f7346ca..92b453bc1f 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -22,6 +22,7 @@ extern "C" { #include "taosdef.h" #include "taoserror.h" +#include "tcoding.h" #include "tdataformat.h" #define TD_MSG_NUMBER_ @@ -1096,6 +1097,131 @@ typedef struct { uint64_t tuid; } SDropTopicInternalMsg; +typedef struct SVCreateTbReq { + uint64_t ver; // use a general definition + char* name; + uint32_t ttl; + uint32_t keep; +#define TD_SUPER_TABLE 0 +#define TD_CHILD_TABLE 1 +#define TD_NORMAL_TABLE 2 + uint8_t type; + union { + struct { + tb_uid_t suid; + uint32_t nCols; + SSchema* pSchema; + uint32_t nTagCols; + SSchema* pTagSchema; + } stbCfg; + struct { + tb_uid_t suid; + SKVRow pTag; + } ctbCfg; + struct { + uint32_t nCols; + SSchema* pSchema; + } ntbCfg; + }; +} SVCreateTbReq; + +static FORCE_INLINE int tSerializeSVCreateTbReq(void** buf, const SVCreateTbReq* pReq) { + int tlen = 0; + + tlen += taosEncodeFixedU64(buf, pReq->ver); + tlen += taosEncodeString(buf, pReq->name); + tlen += taosEncodeFixedU32(buf, pReq->ttl); + tlen += taosEncodeFixedU32(buf, pReq->keep); + tlen += taosEncodeFixedU8(buf, pReq->type); + + switch (pReq->type) { + case TD_SUPER_TABLE: + tlen += taosEncodeFixedU64(buf, pReq->stbCfg.suid); + tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols); + for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name); + } + tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols); + for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); + } + break; + case TD_CHILD_TABLE: + tlen += taosEncodeFixedU64(buf, pReq->ctbCfg.suid); + tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag); + break; + case TD_NORMAL_TABLE: + tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols); + for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); + } + break; + default: + ASSERT(0); + } + + return tlen; +} + +static FORCE_INLINE void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq) { + buf = taosDecodeFixedU64(buf, &(pReq->ver)); + buf = taosDecodeString(buf, &(pReq->name)); + buf = taosDecodeFixedU32(buf, &(pReq->ttl)); + buf = taosDecodeFixedU32(buf, &(pReq->keep)); + buf = taosDecodeFixedU8(buf, &(pReq->type)); + + switch (pReq->type) { + case TD_SUPER_TABLE: + buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid)); + buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols)); + pReq->stbCfg.pSchema = (SSchema*)malloc(pReq->stbCfg.nCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type)); + buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId)); + buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes)); + buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name); + } + buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols); + pReq->stbCfg.pTagSchema = (SSchema*)malloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); + buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); + buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); + } + break; + case TD_CHILD_TABLE: + buf = taosDecodeFixedU64(buf, &pReq->ctbCfg.suid); + buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag); + break; + case TD_NORMAL_TABLE: + buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols); + pReq->ntbCfg.pSchema = (SSchema*)malloc(pReq->ntbCfg.nCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type); + buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); + buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); + } + break; + default: + ASSERT(0); + } + + return buf; +} +typedef struct SVCreateTbRsp { +} SVCreateTbRsp; + #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 05373cda97..15b5b9da28 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -138,7 +138,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_TASKS_STATUS, "vnode-tasks-status", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_TASK, "vnode-drop-task", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-super-table", SVCreateTbReq, SVCreateTbRsp) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 113a970548..3d618862b6 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -25,7 +25,6 @@ extern "C" { #endif // Types exported -typedef uint64_t tb_uid_t; typedef struct SMeta SMeta; #define META_SUPER_TABLE 0 diff --git a/include/util/tcoding.h b/include/util/tcoding.h index a2c91c5dbe..6e6a91130c 100644 --- a/include/util/tcoding.h +++ b/include/util/tcoding.h @@ -357,6 +357,17 @@ static FORCE_INLINE void *taosDecodeString(void *buf, char **value) { return POINTER_SHIFT(buf, size); } +static FORCE_INLINE void *taosDecodeStringTo(void *buf, char *value) { + uint64_t size = 0; + + buf = taosDecodeVariantU64(buf, &size); + memcpy(value, buf, (size_t)size); + + value[size] = '\0'; + + return POINTER_SHIFT(buf, size); +} + #ifdef __cplusplus } #endif From b10cff8b3521f90d8dffd41339b851c1898069ad Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 25 Dec 2021 14:40:43 +0800 Subject: [PATCH 28/36] framework integrated with sync --- include/dnode/mnode/mnode.h | 10 ----- source/dnode/mgmt/impl/inc/dndInt.h | 1 - source/dnode/mgmt/impl/src/dndDnode.c | 2 +- source/dnode/mgmt/impl/src/dndMnode.c | 56 -------------------------- source/dnode/mnode/impl/inc/mndInt.h | 9 ++++- source/dnode/mnode/impl/src/mndSync.c | 56 +++++++++++++++++++------- source/dnode/mnode/impl/src/mndTrans.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 6 +-- 8 files changed, 53 insertions(+), 89 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index f4a6f7a4c9..09d1f8c013 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -27,7 +27,6 @@ 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 (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg); typedef struct SMnodeLoad { int64_t numOfDnode; @@ -63,7 +62,6 @@ typedef struct { SReplica replicas[TSDB_MAX_REPLICA]; SMnodeCfg cfg; SDnode *pDnode; - PutMsgToMnodeQFp putMsgToApplyMsgFp; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; @@ -172,14 +170,6 @@ void mndProcessWriteMsg(SMnodeMsg *pMsg); */ void mndProcessSyncMsg(SMnodeMsg *pMsg); -/** - * @brief Process the apply request. - * - * @param pMsg The request msg. - * @return int32_t 0 for success, -1 for failure. - */ -void mndProcessApplyMsg(SMnodeMsg *pMsg); - #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index 8973574d23..6f1357e9c1 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -80,7 +80,6 @@ typedef struct { SRWLatch latch; taos_queue pReadQ; taos_queue pWriteQ; - taos_queue pApplyQ; taos_queue pSyncQ; taos_queue pMgmtQ; SWorkerPool mgmtPool; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 6b5aeb078a..af86e59518 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -369,7 +369,7 @@ void dndSendStatusMsg(SDnode *pDnode) { dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); - SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = 9527}; + SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527}; pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index c62c05fe2f..8fbb473af1 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -28,18 +28,15 @@ static void dndCleanupMnodeSyncWorker(SDnode *pDnode); static void dndCleanupMnodeMgmtWorker(SDnode *pDnode); static int32_t dndAllocMnodeReadQueue(SDnode *pDnode); static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode); -static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode); static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode); static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode); static void dndFreeMnodeReadQueue(SDnode *pDnode); static void dndFreeMnodeWriteQueue(SDnode *pDnode); -static void dndFreeMnodeApplyQueue(SDnode *pDnode); static void dndFreeMnodeSyncQueue(SDnode *pDnode); static void dndFreeMnodeMgmtQueue(SDnode *pDnode); static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg); static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg); -static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg); static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg); static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg); static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg); @@ -47,7 +44,6 @@ void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEp void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg); static int32_t dndStartMnodeWorker(SDnode *pDnode); static void dndStopMnodeWorker(SDnode *pDnode); @@ -271,11 +267,6 @@ static int32_t dndStartMnodeWorker(SDnode *pDnode) { return -1; } - if (dndAllocMnodeApplyQueue(pDnode) != 0) { - dError("failed to alloc mnode apply queue since %s", terrstr()); - return -1; - } - if (dndAllocMnodeSyncQueue(pDnode) != 0) { dError("failed to alloc mnode sync queue since %s", terrstr()); return -1; @@ -293,7 +284,6 @@ static void dndStopMnodeWorker(SDnode *pDnode) { while (pMgmt->refCount > 1) taosMsleep(10); while (!taosQueueEmpty(pMgmt->pReadQ)) taosMsleep(10); - while (!taosQueueEmpty(pMgmt->pApplyQ)) taosMsleep(10); while (!taosQueueEmpty(pMgmt->pWriteQ)) taosMsleep(10); while (!taosQueueEmpty(pMgmt->pSyncQ)) taosMsleep(10); @@ -303,7 +293,6 @@ static void dndStopMnodeWorker(SDnode *pDnode) { dndFreeMnodeReadQueue(pDnode); dndFreeMnodeWriteQueue(pDnode); - dndFreeMnodeApplyQueue(pDnode); dndFreeMnodeSyncQueue(pDnode); } @@ -328,7 +317,6 @@ static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendRedirectMsgFp = dndSendRedirectMsg; - pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; @@ -604,20 +592,6 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { mndCleanupMsg(pMsg); } -static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode != NULL) { - mndProcessApplyMsg(pMsg); - dndReleaseMnode(pDnode, pMnode); - } else { - mndSendRsp(pMsg, terrno); - } - - mndCleanupMsg(pMsg); -} - static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; @@ -712,19 +686,6 @@ void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { dndReleaseMnode(pDnode, pMnode); } -static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode == NULL) { - return -1; - } - - int32_t code = taosWriteQitem(pMgmt->pApplyQ, pMsg); - dndReleaseMnode(pDnode, pMnode); - return code; -} - static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue); @@ -817,23 +778,6 @@ static void dndFreeMnodeWriteQueue(SDnode *pDnode) { pMgmt->pWriteQ = NULL; } -static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue); - if (pMgmt->pApplyQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dndFreeMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pApplyQ); - pMgmt->pApplyQ = NULL; -} - static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; SWorkerPool *pPool = &pMgmt->writePool; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index ba8746c009..a9932ce048 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -61,6 +61,13 @@ typedef struct { char email[TSDB_FQDN_LEN]; } STelemMgmt; +typedef struct { + int32_t errCode; + sem_t syncSem; + SSyncNode *pSyncNode; + ESyncState state; +} SSyncMgmt; + typedef struct SMnode { int32_t dnodeId; int32_t clusterId; @@ -77,11 +84,11 @@ typedef struct SMnode { SShowMgmt showMgmt; SProfileMgmt profileMgmt; STelemMgmt telemMgmt; + SSyncMgmt syncMgmt; MndMsgFp msgFp[TDMT_MAX]; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; - PutMsgToMnodeQFp putMsgToApplyMsgFp; } SMnode; void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 5e9165f898..6a2fca836f 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -14,26 +14,54 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "mndInt.h" -#include "mndTrans.h" +#include "mndSync.h" -int32_t mndInitSync(SMnode *pMnode) { return 0; } -void mndCleanupSync(SMnode *pMnode) {} +int32_t mndInitSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_init(&pMgmt->syncSem, 0, 0); + + pMgmt->state = TAOS_SYNC_STATE_LEADER; + pMgmt->pSyncNode = NULL; + return 0; +} + +void mndCleanupSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_destroy(&pMgmt->syncSem); +} + +static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { + SMnode *pMnode = pData; + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + + pMgmt->errCode = 0; + tsem_post(&pMgmt->syncSem); + + return 0; +} int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { - int32_t code = 0; +#if 1 + return 0; +#else + if (pMnode->replica == 1) return 0; - // int32_t len = sdbGetRawTotalSize(pRaw); - // SSdbRaw *pReceived = calloc(1, len); - // memcpy(pReceived, pRaw, len); - // mDebug("trans:%d, data:%p recv from sync, code:0x%x pMsg:%p", pMsg->id, pReceived, code & 0xFFFF, pMsg); + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + pMgmt->errCode = 0; - // mndTransApply(pMnode, pReceived, code); - return code; + SSyncBuffer buf = {.data = pRaw, .len = sdbGetRawTotalSize(pRaw)}; + + bool isWeak = false; + int32_t code = syncPropose(pMgmt->pSyncNode, &buf, pMnode, isWeak); + + if (code != 0) return code; + + tsem_wait(&pMgmt->syncSem); + return pMgmt->errCode; +#endif } bool mndIsMaster(SMnode *pMnode) { - // pMnode->role = TAOS_SYNC_STATE_LEADER; - return true; + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + return pMgmt->state == TAOS_SYNC_STATE_LEADER; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 2432e31b9e..f63d14e711 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -746,7 +746,7 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) { } } - return 0; + return code; } static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) { diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 26b1c71a10..27668a585a 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -202,7 +202,6 @@ 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->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; @@ -217,8 +216,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo); if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 || - pMnode->cfg.statusInterval < 1) { + pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) { terrno = TSDB_CODE_MND_INVALID_OPTIONS; return -1; } @@ -438,8 +436,6 @@ void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } -void mndProcessApplyMsg(SMnodeMsg *pMsg) {} - uint64_t mndGenerateUid(char *name, int32_t len) { int64_t us = taosGetTimestampUs(); int32_t hashval = MurmurHash3_32(name, len); From 67cc6839b266f4bd5c6a0a4fd3164118154e5a7d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 15:04:48 +0800 Subject: [PATCH 29/36] more --- source/dnode/mnode/impl/src/mndStb.c | 70 ++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 8b62c2f02d..3981219636 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -177,7 +177,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb } SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName); if (pStb == NULL) { terrno = TSDB_CODE_MND_STB_NOT_EXIST; @@ -200,7 +200,36 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { return mndAcquireDb(pMnode, db); } -static SCreateStbInternalMsg *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) { +static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *contLen) { + SVCreateTbReq req; + void * buf; + int bsize; + + req.ver = 0; + req.name = pStb->name; + req.ttl = 0; + req.keep = 0; + req.type = TD_SUPER_TABLE; + req.stbCfg.suid = pStb->uid; + req.stbCfg.nCols = pStb->numOfColumns; + req.stbCfg.pSchema = pStb->pSchema; + req.stbCfg.nTagCols = pStb->numOfTags; + req.stbCfg.pTagSchema = pStb->pSchema + pStb->numOfColumns; + + bsize = tSerializeSVCreateTbReq(NULL, &req); + buf = malloc(bsize); + if (buf == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + void *pBuf = buf; + tSerializeSVCreateTbReq(&pBuf, &req); + + *contLen = bsize; + return buf; + +#if 0 int32_t totalCols = pStb->numOfTags + pStb->numOfColumns; int32_t contLen = totalCols * sizeof(SSchema) + sizeof(SCreateStbInternalMsg); @@ -226,8 +255,8 @@ static SCreateStbInternalMsg *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgro pSchema->bytes = htonl(pSchema->bytes); pSchema->colId = htonl(pSchema->colId); } - - return pCreate; + return pCreate; +#endif } static SDropStbInternalMsg *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) { @@ -324,16 +353,17 @@ static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void *pIter = NULL; + void * pIter = NULL; + int contLen; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; if (pVgroup->dbUid != pDb->uid) continue; - SCreateStbInternalMsg *pMsg = mndBuildCreateStbMsg(pMnode, pVgroup, pStb); + void *pMsg = mndBuildCreateStbMsg(pMnode, pVgroup, pStb, &contLen); if (pMsg == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); @@ -344,7 +374,7 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; - action.contLen = htonl(pMsg->head.contLen); + action.contLen = htonl(contLen); action.msgType = TDMT_VND_CREATE_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -359,9 +389,9 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void *pIter = NULL; + void * pIter = NULL; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); @@ -461,7 +491,7 @@ CREATE_STB_OVER: } static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SCreateStbMsg *pCreate = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to create", pCreate->name); @@ -484,7 +514,7 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { } } - //topic should have different name with stb + // topic should have different name with stb SStbObj *pTopic = mndAcquireStb(pMnode, pCreate->name); if (pTopic != NULL) { sdbRelease(pMnode->pSdb, pTopic); @@ -545,7 +575,7 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) { static int32_t mndUpdateStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pOldStb, SStbObj *pNewStb) { return 0; } static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SAlterStbMsg *pAlter = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to alter", pAlter->name); @@ -659,7 +689,7 @@ DROP_STB_OVER: } static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SDropStbMsg *pDrop = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to drop", pDrop->name); @@ -694,7 +724,7 @@ static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { } static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to retrieve meta", pInfo->tableFname); @@ -766,7 +796,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs } int32_t numOfStbs = 0; - void *pIter = NULL; + void * pIter = NULL; while (1) { SStbObj *pStb = NULL; pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb); @@ -785,7 +815,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { SMnode *pMnode = pMsg->pMnode; - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; if (mndGetNumOfStbs(pMnode, pShow->db, &pShow->numOfRows) != 0) { return -1; @@ -847,12 +877,12 @@ static void mndExtractTableName(char *tableId, char *name) { } static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; - SSdb *pSdb = pMnode->pSdb; + SMnode * pMnode = pMsg->pMnode; + SSdb * pSdb = pMnode->pSdb; int32_t numOfRows = 0; SStbObj *pStb = NULL; int32_t cols = 0; - char *pWrite; + char * pWrite; char prefix[64] = {0}; tstrncpy(prefix, pShow->db, 64); From 05baf88df8bedf1bafb70f533ded77f0492941bd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 15:50:12 +0800 Subject: [PATCH 30/36] more --- source/dnode/mgmt/impl/src/dndVnodes.c | 4 ++-- source/dnode/mnode/impl/src/mndStb.c | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index 351fc20784..bfefee7c78 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -822,12 +822,12 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t assert(ptr != NULL); } - vnodeProcessWMsgs(pVnode->pImpl, pArray); + // vnodeProcessWMsgs(pVnode->pImpl, pArray); for (size_t i = 0; i < numOfMsgs; i++) { SRpcMsg *pRsp = NULL; SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); - int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); + int32_t code = 0; //vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; rpcSendResponse(pRsp); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3981219636..7105ed486e 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -200,10 +200,12 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { return mndAcquireDb(pMnode, db); } -static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *contLen) { +static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) { +#if 0 SVCreateTbReq req; void * buf; int bsize; + SMsgHead * pMsgHead; req.ver = 0; req.name = pStb->name; @@ -217,19 +219,24 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb req.stbCfg.pTagSchema = pStb->pSchema + pStb->numOfColumns; bsize = tSerializeSVCreateTbReq(NULL, &req); - buf = malloc(bsize); + buf = malloc(sizeof(SMsgHead) + bsize); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - void *pBuf = buf; + pMsgHead = (SMsgHead *)buf; + + pMsgHead->contLen = htonl(sizeof(SMsgHead) + bsize); + pMsgHead->vgId = htonl(pVgroup->vgId); + + void *pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tSerializeSVCreateTbReq(&pBuf, &req); - *contLen = bsize; + *pContLen = sizeof(SMsgHead) + bsize; return buf; -#if 0 +#else int32_t totalCols = pStb->numOfTags + pStb->numOfColumns; int32_t contLen = totalCols * sizeof(SSchema) + sizeof(SCreateStbInternalMsg); @@ -255,7 +262,9 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb pSchema->bytes = htonl(pSchema->bytes); pSchema->colId = htonl(pSchema->colId); } - return pCreate; + + *pContLen = contLen; + return pCreate; #endif } From be06f24c46df4fd5f4f1f23593db22d4dc2a7533 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 25 Dec 2021 16:05:18 +0800 Subject: [PATCH 31/36] minor changes --- source/dnode/mgmt/impl/src/dndVnodes.c | 4 ++-- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/src/mndStb.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index 351fc20784..00b7883d5b 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -822,12 +822,12 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t assert(ptr != NULL); } - vnodeProcessWMsgs(pVnode->pImpl, pArray); + //vnodeProcessWMsgs(pVnode->pImpl, pArray); for (size_t i = 0; i < numOfMsgs; i++) { SRpcMsg *pRsp = NULL; SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); - int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); + int32_t code = 0; //vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; rpcSendResponse(pRsp); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index b21dc0841c..c6fb0cce1d 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -95,6 +95,7 @@ typedef struct { int32_t id; ETrnStage stage; ETrnPolicy policy; + int32_t retryTimes; void *rpcHandle; void *rpcAHandle; SArray *redoLogs; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index e5acb6024e..9421f1b20d 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -374,7 +374,7 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; - action.contLen = htonl(contLen); + action.contLen = contLen; action.msgType = TDMT_VND_CREATE_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index f63d14e711..1697936a26 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -39,7 +39,7 @@ static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans); +static void mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans); static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans); static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans); static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans); @@ -714,7 +714,7 @@ static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) { return mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions); } -static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) { +static void mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) { int32_t code = mndTransExecuteRedoLogs(pMnode, pTrans); if (code == 0) { @@ -724,8 +724,6 @@ static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) { pTrans->stage = TRN_STAGE_ROLLBACK; mError("trans:%d, stage from prepare to rollback since %s", pTrans->id, terrstr()); } - - return 0; } static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) { @@ -742,6 +740,7 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) { mError("trans:%d, stage from execute to rollback since %s", pTrans->id, terrstr()); } else { pTrans->stage = TRN_STAGE_EXECUTE; + pTrans->retryTimes++; mError("trans:%d, stage keep on execute since %s", pTrans->id, terrstr()); } } @@ -762,6 +761,7 @@ static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { mDebug("trans:%d, rollbacked", pTrans->id); } else { pTrans->stage = TRN_STAGE_ROLLBACK; + pTrans->retryTimes++; mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr()); } @@ -774,7 +774,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { while (code == 0) { switch (pTrans->stage) { case TRN_STAGE_PREPARE: - code = mndTransPerformPrepareStage(pMnode, pTrans); + mndTransPerformPrepareStage(pMnode, pTrans); break; case TRN_STAGE_EXECUTE: code = mndTransPerformExecuteStage(pMnode, pTrans); From a927ca8bc43577c61e1fa0fb50f3d9c7678ed467 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 25 Dec 2021 16:11:57 +0800 Subject: [PATCH 32/36] minor changes --- source/dnode/mnode/impl/src/mndTrans.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1697936a26..0b714c34ae 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -660,8 +660,9 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA for (int32_t action = 0; action < numOfActions; ++action) { STransAction *pAction = taosArrayGet(pArray, action); if (pAction == NULL) continue; - if (pAction->msgSent && !pAction->msgReceived) continue; - if (pAction->msgSent && pAction->msgReceived && pAction->errCode == 0) continue; + // if (pAction->msgSent && !pAction->msgReceived) continue; + // if (pAction->msgSent && pAction->msgReceived && pAction->errCode == 0) continue; + if (pAction->msgSent) continue; int64_t signature = pTrans->id; signature = (signature << 32); From 435de712adee52644421a7c0ad6825658dfac4a1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 16:25:57 +0800 Subject: [PATCH 33/36] more --- source/dnode/mgmt/impl/src/dndVnodes.c | 4 ++-- source/dnode/mnode/impl/src/mndStb.c | 2 +- source/dnode/vnode/impl/src/vnodeWrite.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index bfefee7c78..351fc20784 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -822,12 +822,12 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t assert(ptr != NULL); } - // vnodeProcessWMsgs(pVnode->pImpl, pArray); + vnodeProcessWMsgs(pVnode->pImpl, pArray); for (size_t i = 0; i < numOfMsgs; i++) { SRpcMsg *pRsp = NULL; SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); - int32_t code = 0; //vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); + int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; rpcSendResponse(pRsp); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 71215c55da..24d88068bf 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -201,7 +201,7 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { } static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) { -#if 0 +#if 1 SVCreateTbReq req; void * buf; int bsize; diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index b278197935..5b48a9f274 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -34,7 +34,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); // ser request version - void * pBuf = pMsg->pCont; + void * pBuf = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int64_t ver = pVnode->state.processed++; taosEncodeFixedU64(&pBuf, ver); From fea6562a299973197b75ef63a7f8131db59e8377 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 16:54:28 +0800 Subject: [PATCH 34/36] more --- include/dnode/vnode/meta/meta.h | 35 ++---------------------- source/dnode/vnode/impl/CMakeLists.txt | 2 +- source/dnode/vnode/impl/src/vnodeWrite.c | 14 +++++----- source/dnode/vnode/meta/inc/metaTbCfg.h | 8 +++--- source/dnode/vnode/meta/src/metaTable.c | 2 +- source/dnode/vnode/meta/src/metaTbCfg.c | 2 +- 6 files changed, 16 insertions(+), 47 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 3d618862b6..d9f5a3ff09 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -19,6 +19,7 @@ #include "mallocator.h" #include "os.h" #include "trow.h" +#include "tmsg.h" #ifdef __cplusplus extern "C" { @@ -36,39 +37,7 @@ typedef struct SMetaCfg { uint64_t lruSize; } SMetaCfg; -typedef struct STbCfg { - /// name of the table - char *name; - /// time to live of the table - uint32_t ttl; - /// keep time of this table - uint32_t keep; - /// type of table - uint8_t type; - union { - /// super table configurations - struct { - /// super table UID - tb_uid_t suid; - /// row schema - STSchema *pSchema; - /// tag schema - STSchema *pTagSchema; - } stbCfg; - - /// normal table configuration - struct { - /// row schema - STSchema *pSchema; - } ntbCfg; - /// child table configuration - struct { - /// super table UID - tb_uid_t suid; - SKVRow pTag; - } ctbCfg; - }; -} STbCfg; +typedef SVCreateTbReq STbCfg; // SMeta operations SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); diff --git a/source/dnode/vnode/impl/CMakeLists.txt b/source/dnode/vnode/impl/CMakeLists.txt index 9e892bc4c4..944a4276db 100644 --- a/source/dnode/vnode/impl/CMakeLists.txt +++ b/source/dnode/vnode/impl/CMakeLists.txt @@ -20,5 +20,5 @@ target_link_libraries( # test if(${BUILD_TEST}) - add_subdirectory(test) +# add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 5b48a9f274..18a808f955 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -51,8 +51,9 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { } int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - SVnodeReq vReq; - void * ptr = vnodeMalloc(pVnode, pMsg->contLen); + SVnodeReq vReq; + SVCreateTbReq vCreateTbReq; + void * ptr = vnodeMalloc(pVnode, pMsg->contLen); if (ptr == NULL) { // TODO: handle error } @@ -62,17 +63,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // todo: change the interface here uint64_t ver; - taosDecodeFixedU64(pMsg->pCont, &ver); + taosDecodeFixedU64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) { // TODO: handle error } - vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType); - switch (pMsg->msgType) { case TDMT_VND_CREATE_STB: - case TDMT_MND_CREATE_TABLE: - if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) { + tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq); + if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { // TODO: handle error } @@ -90,6 +89,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } break; default: + ASSERT(0); break; } diff --git a/source/dnode/vnode/meta/inc/metaTbCfg.h b/source/dnode/vnode/meta/inc/metaTbCfg.h index 68c609d6b4..b4ee095967 100644 --- a/source/dnode/vnode/meta/inc/metaTbCfg.h +++ b/source/dnode/vnode/meta/inc/metaTbCfg.h @@ -22,11 +22,11 @@ extern "C" { #endif -#define META_SUPER_TABLE 0 -#define META_CHILD_TABLE 1 -#define META_NORMAL_TABLE 2 +#define META_SUPER_TABLE TD_SUPER_TABLE +#define META_CHILD_TABLE TD_CHILD_TABLE +#define META_NORMAL_TABLE TD_NORMAL_TABLE -int metaValidateTbOptions(SMeta *pMeta, const STbCfg *); +int metaValidateTbCfg(SMeta *pMeta, const STbCfg *); size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize); #ifdef __cplusplus diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index fc0f19302f..1398639f39 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -17,7 +17,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { // Validate the tbOptions - if (metaValidateTbOptions(pMeta, pTbCfg) < 0) { + if (metaValidateTbCfg(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } diff --git a/source/dnode/vnode/meta/src/metaTbCfg.c b/source/dnode/vnode/meta/src/metaTbCfg.c index da181a68fc..6f8a537966 100644 --- a/source/dnode/vnode/meta/src/metaTbCfg.c +++ b/source/dnode/vnode/meta/src/metaTbCfg.c @@ -16,7 +16,7 @@ #include "metaDef.h" #include "tcoding.h" -int metaValidateTbOptions(SMeta *pMeta, const STbCfg *pTbOptions) { +int metaValidateTbCfg(SMeta *pMeta, const STbCfg *pTbOptions) { // TODO return 0; } From 9ab51149d14b4a3c8000d1f6d69dff869b157190 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 25 Dec 2021 17:32:25 +0800 Subject: [PATCH 35/36] more --- source/dnode/vnode/meta/src/metaBDBImpl.c | 42 ++++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 3c1ccc72dc..735d33ac15 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -125,11 +125,11 @@ void metaCloseDB(SMeta *pMeta) { } int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { - tb_uid_t uid; - char buf[512]; - void * pBuf; - DBT key, value; - STSchema *pSchema = NULL; + tb_uid_t uid; + char buf[512]; + void * pBuf; + DBT key, value; + SSchema *pSchema = NULL; if (pTbCfg->type == META_SUPER_TABLE) { uid = pTbCfg->stbCfg.suid; @@ -156,9 +156,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { } // save schema + uint32_t ncols; if (pTbCfg->type == META_SUPER_TABLE) { + ncols = pTbCfg->stbCfg.nCols; pSchema = pTbCfg->stbCfg.pSchema; } else if (pTbCfg->type == META_NORMAL_TABLE) { + ncols = pTbCfg->ntbCfg.nCols; pSchema = pTbCfg->ntbCfg.pSchema; } @@ -166,12 +169,18 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { pBuf = buf; memset(&key, 0, sizeof(key)); memset(&value, 0, sizeof(key)); - SSchemaKey schemaKey = {uid, schemaVersion(pSchema)}; + SSchemaKey schemaKey = {uid, 0 /*TODO*/}; key.data = &schemaKey; key.size = sizeof(schemaKey); - tdEncodeSchema(&pBuf, pSchema); + taosEncodeFixedU32(&pBuf, ncols); + for (size_t i = 0; i < ncols; i++) { + taosEncodeFixedI8(&pBuf, pSchema[i].type); + taosEncodeFixedI32(&pBuf, pSchema[i].colId); + taosEncodeFixedI32(&pBuf, pSchema[i].bytes); + taosEncodeString(&pBuf, pSchema[i].name); + } value.data = buf; value.size = POINTER_DISTANCE(pBuf, buf); @@ -367,7 +376,15 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) { tsize += taosEncodeFixedU8(buf, pTbCfg->type); if (pTbCfg->type == META_SUPER_TABLE) { - tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema); + tsize += taosEncodeVariantU32(buf, pTbCfg->stbCfg.nTagCols); + for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { + tsize += taosEncodeFixedI8(buf, pTbCfg->stbCfg.pSchema[i].type); + tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].colId); + tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].bytes); + tsize += taosEncodeString(buf, pTbCfg->stbCfg.pSchema[i].name); + } + + // tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema); } else if (pTbCfg->type == META_CHILD_TABLE) { tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid); tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag); @@ -386,7 +403,14 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { buf = taosDecodeFixedU8(buf, &(pTbCfg->type)); if (pTbCfg->type == META_SUPER_TABLE) { - buf = tdDecodeSchema(buf, &(pTbCfg->stbCfg.pTagSchema)); + buf = taosDecodeVariantU32(buf, pTbCfg->stbCfg.nTagCols); + pTbCfg->stbCfg.pTagSchema = (SSchema *)malloc(sizeof(SSchema) * pTbCfg->stbCfg.nTagCols); + for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { + buf = taosDecodeFixedI8(buf, &pTbCfg->stbCfg.pSchema[i].type); + buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].bytes); + buf = taosDecodeStringTo(buf, pTbCfg->stbCfg.pSchema[i].name); + } } else if (pTbCfg->type == META_CHILD_TABLE) { buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid)); buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag)); From 0365c67b81af64cffb9056d15397046acbd7ad66 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 25 Dec 2021 19:16:05 +0800 Subject: [PATCH 36/36] Combine the search results of cache and tfile And Update cache code --- source/libs/index/inc/index_cache.h | 12 + source/libs/index/src/index.c | 4 +- source/libs/index/src/index_cache.c | 201 +++++++++------ source/libs/index/src/index_tfile.c | 4 +- source/libs/index/test/indexTests.cc | 370 ++++++++------------------- 5 files changed, 247 insertions(+), 344 deletions(-) diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/index_cache.h index fb4f478ae9..692edcc064 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/index_cache.h @@ -37,6 +37,17 @@ typedef struct IndexCache { SSkipList* skiplist; } IndexCache; +typedef struct CacheTerm { + // key + int32_t colId; + int32_t nColVal; + char* colVal; + int32_t version; + // value + uint64_t uid; + int8_t colType; + SIndexOperOnColumn operaType; +} CacheTerm; // IndexCache* indexCacheCreate(); @@ -47,6 +58,7 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version, // int indexCacheGet(void *cache, uint64_t *rst); int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s); +void indexCacheDebug(IndexCache* cache); #ifdef __cplusplus } #endif diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index f0546afaf5..1c65dd03d5 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -41,7 +41,7 @@ static pthread_once_t isInit = PTHREAD_ONCE_INIT; static void indexInit(); static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result); -static int indexFlushCacheToTindex(SIndex* sIdx); +static int indexFlushCacheTFile(SIndex* sIdx); static void indexInterResultsDestroy(SArray* results); static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType, SArray* finalResult); @@ -353,7 +353,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType } return 0; } -static int indexFlushCacheToTindex(SIndex* sIdx) { +static int indexFlushCacheTFile(SIndex* sIdx) { if (sIdx == NULL) { return -1; } indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index bb6a5e048a..9c92203088 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,81 +20,88 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later // 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) + sizeof(p->operType)) +//#define CACHE_KEY_LEN(p) \ +// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + sizeof(p->operType)) -static char* getIndexKey(const void* pData) { - return NULL; +static void cacheTermDestroy(CacheTerm* ct) { + if (ct == NULL) { return; } + + free(ct->colVal); + free(ct); } +static char* getIndexKey(const void* pData) { + CacheTerm* p = (CacheTerm*)pData; + return (char*)p; +} + static int32_t compareKey(const void* l, const void* r) { - char* lp = (char*)l; - char* rp = (char*)r; + CacheTerm* lt = (CacheTerm*)l; + CacheTerm* rt = (CacheTerm*)r; - // skip total len, not compare - int32_t ll, rl; // len - memcpy(&ll, lp, sizeof(int32_t)); - memcpy(&rl, rp, sizeof(int32_t)); - lp += sizeof(int32_t); - rp += sizeof(int32_t); + // compare colId + if (lt->colId != rt->colId) { return lt->colId - rt->colId; } - // compare field id - int16_t lf, rf; // field id - memcpy(&lf, lp, sizeof(lf)); - memcpy(&rf, rp, sizeof(rf)); - if (lf != rf) { return lf < rf ? -1 : 1; } - lp += sizeof(lf); - rp += sizeof(rf); - - // compare field type - int8_t lft, rft; - memcpy(&lft, lp, sizeof(lft)); - memcpy(&rft, rp, sizeof(rft)); - lp += sizeof(lft); - rp += sizeof(rft); - assert(rft == rft); - - // skip value len - int32_t lfl, rfl; - memcpy(&lfl, lp, sizeof(lfl)); - memcpy(&rfl, rp, sizeof(rfl)); - lp += sizeof(lfl); - rp += sizeof(rfl); - - // compare value - int32_t i, j; - for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) { - if (lp[i] == rp[j]) { + // compare colVal + int i, j; + for (i = 0, j = 0; i < lt->nColVal && j < rt->nColVal; i++, j++) { + if (lt->colVal[i] == rt->colVal[j]) { continue; } else { - return lp[i] < rp[j] ? -1 : 1; + return lt->colVal[i] < rt->colVal[j] ? -1 : 1; } } - if (i < lfl) { + if (i < lt->nColVal) { return 1; - } else if (j < rfl) { + } else if (j < rt->nColVal) { return -1; } - lp += lfl; - rp += rfl; + // compare version - // skip uid - uint64_t lu, ru; - memcpy(&lu, lp, sizeof(lu)); - memcpy(&ru, rp, sizeof(ru)); - lp += sizeof(lu); - rp += sizeof(ru); + return rt->version - lt->version; - // compare version, desc order - int32_t lv, rv; - memcpy(&lv, lp, sizeof(lv)); - memcpy(&rv, rp, sizeof(rv)); - if (lv != rv) { return lv > rv ? -1 : 1; } + // char* lp = (char*)l; + // char* rp = (char*)r; - lp += sizeof(lv); - rp += sizeof(rv); - // not care item type + //// compare col id + // int16_t lf, rf; // cold id + // memcpy(&lf, lp, sizeof(lf)); + // memcpy(&rf, rp, sizeof(rf)); + // if (lf != rf) { return lf < rf ? -1 : 1; } - return 0; + // lp += sizeof(lf); + // rp += sizeof(rf); + + //// skip value len + // int32_t lfl, rfl; + // memcpy(&lfl, lp, sizeof(lfl)); + // memcpy(&rfl, rp, sizeof(rfl)); + // lp += sizeof(lfl); + // rp += sizeof(rfl); + + //// compare value + // int32_t i, j; + // for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) { + // if (lp[i] == rp[j]) { + // continue; + // } else { + // return lp[i] < rp[j] ? -1 : 1; + // } + //} + // if (i < lfl) { + // return 1; + //} else if (j < rfl) { + // return -1; + //} + // lp += lfl; + // rp += rfl; + + //// compare version, desc order + // int32_t lv, rv; + // memcpy(&lv, lp, sizeof(lv)); + // memcpy(&rv, rp, sizeof(rv)); + // if (lv != rv) { return lv < rv ? 1 : -1; } + + // return 0; } IndexCache* indexCacheCreate() { IndexCache* cache = calloc(1, sizeof(IndexCache)); @@ -106,6 +113,18 @@ IndexCache* indexCacheCreate() { tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey); return cache; } +void indexCacheDebug(IndexCache* cache) { + SSkipListIterator* iter = tSkipListCreateIter(cache->skiplist); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); + if (ct != NULL) { + // TODO, add more debug info + indexInfo("{colId:%d, colVal: %s, version: %d} \t", ct->colId, ct->colVal, ct->version); + } + } + tSkipListDestroyIter(iter); +} void indexCacheDestroy(void* cache) { IndexCache* pCache = cache; @@ -119,24 +138,20 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version, IndexCache* pCache = cache; // encode data - int32_t total = CACHE_KEY_LEN(term); + CacheTerm* ct = calloc(1, sizeof(CacheTerm)); + if (cache == NULL) { return -1; } + // set up key + ct->colId = colId; + ct->colType = term->colType; + ct->nColVal = term->nColVal; + ct->colVal = (char*)calloc(1, sizeof(char) * (ct->nColVal + 1)); + memcpy(ct->colVal, term->colVal, ct->nColVal); + ct->version = version; - char* buf = calloc(1, total); - char* p = buf; + ct->uid = uid; + ct->operaType = term->operType; - SERIALIZE_VAR_TO_BUF(p, total, int32_t); - SERIALIZE_VAR_TO_BUF(p, colId, int16_t); - - SERIALIZE_MEM_TO_BUF(p, term, colType); - SERIALIZE_MEM_TO_BUF(p, term, nColVal); - SERIALIZE_STR_MEM_TO_BUF(p, term, colVal, term->nColVal); - - SERIALIZE_VAR_TO_BUF(p, version, int32_t); - SERIALIZE_VAR_TO_BUF(p, uid, uint64_t); - - SERIALIZE_MEM_TO_BUF(p, term, operType); - - tSkipListPut(pCache->skiplist, (void*)buf); + tSkipListPut(pCache->skiplist, (char*)ct); return 0; // encode end } @@ -150,8 +165,39 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t SIndexTerm* term = query->term; EIndexQueryType qtype = query->qType; - int32_t keyLen = CACHE_KEY_LEN(term); - char* buf = calloc(1, keyLen); + CacheTerm* ct = calloc(1, sizeof(CacheTerm)); + if (ct == NULL) { return -1; } + ct->colId = colId; + ct->nColVal = term->nColVal; + ct->colVal = calloc(1, sizeof(char) * (ct->nColVal + 1)); + memcpy(ct->colVal, term->colVal, ct->nColVal); + ct->version = version; + + char* key = getIndexKey(ct); + // TODO handle multi situation later, and refactor + SSkipListIterator* iter = tSkipListCreateIterFromVal(pCache->skiplist, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + if (node != NULL) { + CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); + if (c->operaType == ADD_VALUE || qtype == QUERY_TERM) { + if (c->nColVal == ct->nColVal && strncmp(c->colVal, ct->colVal, c->nColVal) == 0) { + taosArrayPush(result, &c->uid); + *s = kTypeValue; + } else { + break; + } + } else if (c->operaType == DEL_VALUE) { + // table is del, not need + *s = kTypeDeletion; + break; + } + } + } + tSkipListDestroyIter(iter); + cacheTermDestroy(ct); + // int32_t keyLen = CACHE_KEY_LEN(term); + // char* buf = calloc(1, keyLen); if (qtype == QUERY_TERM) { // } else if (qtype == QUERY_PREFIX) { @@ -161,6 +207,5 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t } else if (qtype == QUERY_REGEX) { // } - return 0; } diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 9afc29457d..003ae86c6a 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -462,7 +462,9 @@ static int tfileCompare(const void* a, const void* b) { size_t aLen = strlen(aName); size_t bLen = strlen(bName); - return strncmp(aName, bName, aLen > bLen ? aLen : bLen); + int ret = strncmp(aName, bName, aLen > bLen ? aLen : bLen); + if (ret == 0) { return ret; } + return ret < 0 ? -1 : 1; } // tfile name suid-colId-version.tindex static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version) { diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 18ad37de1f..bed2b82daa 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -24,6 +24,22 @@ #include "tskiplist.h" #include "tutil.h" using namespace std; +class DebugInfo { + public: + DebugInfo(const char* str) : info(str) { + std::cout << "------------" << info << "\t" + << "begin" + << "-------------" << std::endl; + } + ~DebugInfo() { + std::cout << "-----------" << info << "\t" + << "end" + << "--------------" << std::endl; + } + + private: + std::string info; +}; class FstWriter { public: FstWriter() { @@ -133,7 +149,6 @@ int Performance_fstWriteRecords(FstWriter* b) { } return L * M * N; } - void Performance_fstReadRecords(FstReadMemory* m) { std::string str("aa"); for (int i = 0; i < M; i++) { @@ -168,7 +183,6 @@ void checkFstPerf() { Performance_fstReadRecords(m); delete m; } - void checkFstPrefixSearch() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); @@ -246,7 +260,6 @@ void validateFst() { } delete m; } - class IndexEnv : public ::testing::Test { protected: virtual void SetUp() { @@ -265,44 +278,51 @@ class IndexEnv : public ::testing::Test { SIndex* index; }; -// TEST_F(IndexEnv, testPut) { -// // single index column -// { -// std::string colName("tag1"), colVal("Hello world"); -// SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), -// colVal.size()); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); -// -// for (size_t i = 0; i < 100; i++) { -// int tableId = i; -// int ret = indexPut(index, terms, tableId); -// assert(ret == 0); -// } -// indexMultiTermDestroy(terms); -// } -// // multi index column -// { +/// TEST_F(IndexEnv, testPut) { +// / // single index column +// / { +// / std::string colName("tag1"), colVal("Hello world"); +// / SIndexTerm* term = +// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), / colVal.size()); // SIndexMultiTerm* terms = indexMultiTermCreate(); -// { -// std::string colName("tag1"), colVal("Hello world"); -// SIndexTerm* term = -// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); -// indexMultiTermAdd(terms, term); +// indexMultiTermAdd(terms, term); +// / / for (size_t i = 0; i < 100; i++) { +// / int tableId = i; +// / int ret = indexPut(index, terms, tableId); +// / assert(ret == 0); +// / // } -// { -// std::string colName("tag2"), colVal("Hello world"); -// SIndexTerm* term = -// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); -// indexMultiTermAdd(terms, term); -// } -// -// for (int i = 0; i < 100; i++) { -// int tableId = i; -// int ret = indexPut(index, terms, tableId); -// assert(ret == 0); -// } -// indexMultiTermDestroy(terms); +// / indexMultiTermDestroy(terms); +// / // } -// // +// / // multi index column +// / { +// / SIndexMultiTerm* terms = indexMultiTermCreate(); +// / { +// / std::string colName("tag1"), colVal("Hello world"); +// / SIndexTerm* term = +// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); +// / indexMultiTermAdd(terms, term); +// / +// } +// / { +// / std::string colName("tag2"), colVal("Hello world"); +// / SIndexTerm* term = +// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); +// / indexMultiTermAdd(terms, term); +// / +// } +// / / for (int i = 0; i < 100; i++) { +// / int tableId = i; +// / int ret = indexPut(index, terms, tableId); +// / assert(ret == 0); +// / +// } +// / indexMultiTermDestroy(terms); +// / +// } +// / // +// / //} class TFileObj { @@ -416,7 +436,6 @@ static void destroyTFileValue(void* val) { taosArrayDestroy(tv->tableId); free(tv); } - TEST_F(IndexTFileEnv, test_tfile_write) { TFileValue* v1 = genTFileValue("c"); TFileValue* v2 = genTFileValue("ab"); @@ -492,241 +511,66 @@ class IndexCacheEnv : public ::testing::Test { CacheObj* coj; }; -TEST_F(IndexCacheEnv, cache_test) { - int count = 10; - - int16_t colId = 1; - int32_t version = 10; - uint64_t suid = 100; - std::string colName("voltage"); - std::string colVal("My God"); - for (size_t i = 0; i < count; i++) { - colVal += ('a' + i); - SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); - coj->Put(term, colId, version, suid); - version++; - } - - // coj->Get(); -} - -typedef struct CTerm { - char buf[16]; - char version[8]; - int val; - int other; -} CTerm; -CTerm* cTermCreate(const char* str, const char* version, int val) { - CTerm* tm = (CTerm*)calloc(1, sizeof(CTerm)); - memcpy(tm->buf, str, strlen(str)); - memcpy(tm->version, version, strlen(version)); - tm->val = val; - tm->other = -100; - return tm; -} -int termCompar(const void* a, const void* b) { - printf("a: %s \t b: %s\n", (char*)a, (char*)b); - int ret = strncmp((char*)a, (char*)b, 16); - if (ret == 0) { - // - return strncmp((char*)a + 16, (char*)b + 16, 8); - } - return ret; -} - -int SerialTermTo(char* buf, CTerm* term) { - char* p = buf; - memcpy(buf, term->buf, sizeof(term->buf)); - buf += sizeof(term->buf); - - // memcpy(buf, term->version, sizeof(term->version)); - // buf += sizeof(term->version); - return buf - p; -} -static char* getTermKey(const void* pData) { - CTerm* p = (CTerm*)pData; - return (char*)p->buf; -} #define MAX_TERM_KEY_LEN 128 -class SkiplistObj { - public: - // max_key_len: - // - SkiplistObj() { - slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, termCompar, SL_ALLOW_DUP_KEY, getTermKey); - } - int Put(CTerm* term, uint64_t suid) { - char buf[MAX_TERM_KEY_LEN] = {0}; - int sz = SerialTermTo(buf, term); +TEST_F(IndexCacheEnv, cache_test) { + int version = 0; + int16_t colId = 0; - char* pBuf = (char*)calloc(1, sz + sizeof(suid)); - - memcpy(pBuf, buf, sz); - memcpy(pBuf + sz, &suid, sizeof(suid)); - // int32_t level, headsize; - // tSkipListNewNodeInfo(slt, &level, &headsize); - - // SSkipListNode* node = (SSkipListNode*)calloc(1, headsize + strlen(buf) + sizeof(suid)); - // node->level = level; - // char* d = (char*)SL_GET_NODE_DATA(node); - // memcpy(d, buf, strlen(buf)); - // memcpy(d + strlen(buf), &suid, sizeof(suid)); - SSkipListNode* node = tSkipListPut(slt, pBuf); - tSkipListPrint(slt, 1); - free(pBuf); - return 0; - } - - int Get(int key, char* buf, int version) { - // TODO - // CTerm term; - // term.key = key; - //// term.version = version; - // memcpy(term.buf, buf, strlen(buf)); - - // char tbuf[128] = {0}; - // SerialTermTo(tbuf, &term); - - // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); - // SSkipListNode* node = tSkipListIterGet(iter); - // CTerm* ct = (CTerm*)SL_GET_NODE_DATA(node); - // printf("key: %d\t, version: %d\t, buf: %s\n", ct->key, ct->version, ct->buf); - // while (iter) { - // assert(tSkipListIterNext(iter) == true); - // SSkipListNode* node = tSkipListIterGet(iter); - // // ugly formate - // CTerm* t = (CTerm*)SL_GET_NODE_KEY(slt, node); - // printf("key: %d\t, version: %d\t, buf: %s\n", t->key, t->version, t->buf); - //} - return 0; - } - ~SkiplistObj() { - // TODO - // indexCacheDestroy(cache); - } - - private: - SSkipList* slt; -}; - -typedef struct KV { - int32_t k; - int32_t v; -} KV; -int kvCompare(const void* a, const void* b) { - int32_t av = *(int32_t*)a; - int32_t bv = *(int32_t*)b; - return av - bv; -} -char* getKVkey(const void* a) { - return (char*)(&(((KV*)a)->v)); - // KV* kv = (KV*)a; -} -int testKV() { - SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, kvCompare, SL_DISCARD_DUP_KEY, getKVkey); + uint64_t suid = 0; + std::string colName("voltage"); { - KV t = {.k = 1, .v = 5}; - tSkipListPut(slt, (void*)&t); + std::string colVal("v1"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); } { - KV t = {.k = 2, .v = 3}; - tSkipListPut(slt, (void*)&t); + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v2"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); } - KV value = {.k = 4, .v = 5}; - char* key = getKVkey(&value); - // const char* key = "Hello"; - SArray* arr = tSkipListGet(slt, (SSkipListKey)&key); - for (size_t i = 0; i < taosArrayGetSize(arr); i++) { - SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); - int32_t* ct = (int32_t*)SL_GET_NODE_KEY(slt, node); - - printf("Get key: %d\n", *ct); - // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); - } - return 1; -} - -int testComplicate() { - SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, termCompar, SL_ALLOW_DUP_KEY, getTermKey); { - CTerm* tm = cTermCreate("val", "v1", 10); - tSkipListPut(slt, (char*)tm); - } - { - CTerm* tm = cTermCreate("val1", "v2", 2); - tSkipListPut(slt, (char*)tm); - } - { - CTerm* tm = cTermCreate("val3", "v3", -1); - tSkipListPut(slt, (char*)tm); - } - { - CTerm* tm = cTermCreate("val3", "v4", 2); - tSkipListPut(slt, (char*)tm); - } - { - CTerm* tm = cTermCreate("val3", "v5", -1); - char* key = getTermKey(tm); - SArray* arr = tSkipListGet(slt, (SSkipListKey)key); - for (size_t i = 0; i < taosArrayGetSize(arr); i++) { - SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); - CTerm* ct = (CTerm*)SL_GET_NODE_KEY(slt, node); - printf("other; %d\tbuf: %s\t, version: %s, val: %d\n", ct->other, ct->buf, ct->version, ct->val); - // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + std::string colVal("v4"); + for (size_t i = 0; i < 100; i++) { + colVal[colVal.size() - 1] = 'a' + i; + SIndexTerm* term = + indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); } - free(tm); - taosArrayDestroy(arr); } - return 1; -} -int strCompare(const void* a, const void* b) { - const char* sa = (char*)a; - const char* sb = (char*)b; - return strcmp(sa, sb); -} -void testString() { - SSkipList* slt = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_TERM_KEY_LEN, strCompare, SL_ALLOW_DUP_KEY, getTermKey); { - tSkipListPut(slt, (void*)"Hello"); - tSkipListPut(slt, (void*)"World"); - tSkipListPut(slt, (void*)"YI"); - } + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; + SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); + STermValueType valType; - const char* key = "YI"; - SArray* arr = tSkipListGet(slt, (SSkipListKey)key); - for (size_t i = 0; i < taosArrayGetSize(arr); i++) { - SSkipListNode* node = (SSkipListNode*)taosArrayGetP(arr, i); - char* ct = (char*)SL_GET_NODE_KEY(slt, node); - printf("Get key: %s\n", ct); - // SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + coj->Get(&query, colId, 10000, ret, &valType); + assert(taosArrayGetSize(ret) == 3); + } + { + std::string colVal("v2"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); + SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; + SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); + STermValueType valType; + + coj->Get(&query, colId, 10000, ret, &valType); + assert(taosArrayGetSize(ret) == 1); } } -// class IndexSkip : public ::testing::Test { -// protected: -// virtual void SetUp() { -// // TODO -// sObj = new SkiplistObj(); -// } -// virtual void TearDown() { -// delete sObj; -// // formate -// } -// SkiplistObj* sObj; -//}; - -// TEST_F(IndexSkip, skip_test) { -// std::string val("Hello"); -// std::string minVal = val; -// for (size_t i = 0; i < 10; i++) { -// CTerm* t = (CTerm*)calloc(1, sizeof(CTerm)); -// t->key = 1; -// t->version = i; -// -// val[val.size() - 1] = 'a' + i; -// memcpy(t->buf, val.c_str(), val.size()); -// sObj->Put(t, 10); -// free(t); -// } -// sObj->Get(1, (char*)(minVal.c_str()), 1000000); -//}