From 1b9b49c95fa8d8e7eec60926687655fed80b17a1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 03:33:05 -0800 Subject: [PATCH 01/86] modify the clusterId generation method --- source/dnode/mnode/impl/src/mndCluster.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f656c27dcd..427fe55e1d 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -124,12 +124,11 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { if (code != 0) { strcpy(clusterObj.name, "tdengine2.0"); mError("failed to get name from system, set to default val %s", clusterObj.name); - } else { - mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); } - clusterObj.id = MurmurHash3_32(clusterObj.name, TSDB_CLUSTER_ID_LEN); + + clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id); - pMnode->clusterId = clusterObj.id; + mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj); if (pRaw == NULL) return -1; From 85e0f135e21541072765c497de2b8d5b961d98d4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 03:47:03 -0800 Subject: [PATCH 02/86] minor changes --- source/dnode/mnode/impl/src/mndAcct.c | 2 +- source/dnode/mnode/impl/src/mndDb.c | 2 +- source/dnode/mnode/impl/src/mndFunc.c | 2 +- source/dnode/mnode/impl/src/mndStb.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 2 +- source/dnode/mnode/impl/src/mndUser.c | 2 +- source/dnode/mnode/impl/src/mndVgroup.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 767f628306..0c1ae1bffa 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -97,8 +97,8 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_ACCT_VER_NUMBER) { - mError("failed to decode acct since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode acct since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index f9199f9eed..fe49ad99fe 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -106,8 +106,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_DB_VER_NUMBER) { - mError("failed to decode db since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode db since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 638d984c69..59d04ab4a1 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -86,8 +86,8 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != SDB_FUNC_VER) { - mError("failed to decode func since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode func since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 918f43f2bd..3454ea1884 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -105,8 +105,8 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_STB_VER_NUMBER) { - mError("failed to decode stable since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode stable since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index cf434dda39..b0d799d21b 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -168,7 +168,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { 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()); + mError("failed to decode trans since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0926cf0c48..129d1c50b1 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -115,8 +115,8 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_USER_VER_NUMBER) { - mError("failed to decode user since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode user since %s", terrstr()); return NULL; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 41de70283f..3090f1e645 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -98,8 +98,8 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_VGROUP_VER_NUMBER) { - mError("failed to decode vgroup since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode vgroup since %s", terrstr()); return NULL; } From 9c717d9c7cee7a755aaef1aaecb0785101634af8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 04:07:32 -0800 Subject: [PATCH 03/86] minor changes --- source/dnode/mnode/impl/src/mndShow.c | 38 ++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index d4b4459176..c156c87123 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -68,11 +68,11 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime); if (pShow == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to put into cache since %s", showId, terrstr()); + mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr()); return NULL; } - mTrace("show:0x%"PRIx64", is created, data:%p", showId, pShow); + mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow); return pShow; } @@ -87,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) { } } - mTrace("show:0x%d, is destroyed, data:%p", pShow->id, pShow); + mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow); } static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) { @@ -95,17 +95,17 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) { SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId)); if (pShow == NULL) { - mError("show:0x%"PRIx64", already destroyed", showId); + mError("show:0x%" PRIx64 ", already destroyed", showId); return NULL; } - mTrace("show:0x%"PRIx64", acquired from cache, data:%p", pShow->id, pShow); + mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow); return pShow; } static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { if (pShow == NULL) return; - mTrace("show:0x%"PRIx64", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); + mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); // A bug in tcache.c forceRemove = 0; @@ -146,18 +146,19 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, true); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type)); + mError("show:0x%" PRIx64 ", failed to process show-meta msg:%s since malloc rsp error", pShow->id, + mndShowStr(type)); return -1; } int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:0x%"PRIx64", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; - pMnodeMsg->pCont = pRsp; - pRsp->showId = htobe64(pShow->id); + pMnodeMsg->pCont = pRsp; + pRsp->showId = htobe64(pShow->id); mndReleaseShowObj(pShow, false); return TSDB_CODE_SUCCESS; } else { @@ -175,7 +176,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { int32_t rowsRead = 0; SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont; - int64_t showId = htobe64(pRetrieve->showId); + int64_t showId = htobe64(pRetrieve->showId); SShowObj *pShow = mndAcquireShowObj(pMnode, showId); if (pShow == NULL) { @@ -188,15 +189,16 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (retrieveFp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:0x%"PRIx64", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, + mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, pShow->numOfRows, mndShowStr(pShow->type)); if (mndCheckRetrieveFinished(pShow)) { - mDebug("show:0x%"PRIx64", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows); + mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, + pShow->numOfRows); pShow->numOfReads = pShow->numOfRows; } @@ -219,7 +221,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } @@ -228,7 +230,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead); } - mDebug("show:0x%"PRIx64", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); + mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision @@ -238,10 +240,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; - mDebug("show:0x%"PRIx64", retrieve completed", pShow->id); + mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); } else { - mDebug("show:0x%"PRIx64", retrieve not completed yet", pShow->id); + mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); mndReleaseShowObj(pShow, false); } From fded16d1db34a8e1213efbc39bd34e7a23ce9808 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 23:40:05 +0800 Subject: [PATCH 04/86] fix memory leak while drop user --- source/dnode/mnode/impl/src/mndUser.c | 22 +++++++++----- source/dnode/mnode/sdb/src/sdbHash.c | 10 +++--- source/dnode/mnode/sdb/src/sdbRow.c | 3 ++ tests/script/general/user/basic1.sim | 44 ++------------------------- 4 files changed, 25 insertions(+), 54 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0926cf0c48..0f3dfd2ee3 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -75,7 +75,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("user:%s, will be created while deploy sdb", userObj.user); + mDebug("user:%s, will be created while deploy sdb, raw:%p", userObj.user, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } @@ -107,6 +107,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE) SDB_SET_DATALEN(pRaw, dataPos); + mTrace("user:%s, encode to raw:%p, row:%p", pUser->user, pRaw, pUser); return pRaw; } @@ -133,11 +134,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser) SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE) + mTrace("user:%s, decode from raw:%p, row:%p", pUser->user, pRaw, pUser); return pRow; } static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { - mTrace("user:%s, perform insert action", pUser->user); + mTrace("user:%s, perform insert action, row:%p", pUser->user, pUser); pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->prohibitDbHash == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -158,7 +160,7 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { } static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { - mTrace("user:%s, perform delete action", pUser->user); + mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser); if (pUser->prohibitDbHash) { taosHashCleanup(pUser->prohibitDbHash); pUser->prohibitDbHash = NULL; @@ -168,7 +170,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { } static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) { - mTrace("user:%s, perform update action", pOldUser->user); + mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOldUser->user, pOldUser, pNewUser); memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN); pOldUser->updateTime = pNewUser->updateTime; return 0; @@ -242,7 +244,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user); if (pUser != NULL) { - sdbRelease(pMnode->pSdb, pUser); + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_USER_ALREADY_EXIST; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; @@ -256,7 +258,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { } int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg); - sdbRelease(pMnode->pSdb, pOperUser); + mndReleaseUser(pMnode, pOperUser); if (code != 0) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); @@ -319,6 +321,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); if (pOperUser == NULL) { + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); return -1; @@ -331,7 +334,8 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { newUser.updateTime = taosGetTimestampMs(); int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg); - sdbRelease(pMnode->pSdb, pOperUser); + mndReleaseUser(pMnode, pOperUser); + mndReleaseUser(pMnode, pUser); if (code != 0) { mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); @@ -388,13 +392,15 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); if (pOperUser == NULL) { + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); return -1; } int32_t code = mndDropUser(pMnode, pMsg, pUser); - sdbRelease(pMnode->pSdb, pOperUser); + mndReleaseUser(pMnode, pOperUser); + mndReleaseUser(pMnode, pUser); if (code != 0) { mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 0388fa99f5..23bcdb1b60 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -57,12 +57,14 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { EKeyType keyType = pSdb->keyTypes[pRow->type]; if (keyType == SDB_KEY_BINARY) { - mTrace("%s:%s, refCount:%d oper:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper); + mTrace("%s:%s, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper, + pRow->pObj); } else if (keyType == SDB_KEY_INT32) { - mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper); + mTrace("%s:%d, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper, + pRow->pObj); } else if (keyType == SDB_KEY_INT64) { - mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount, - oper); + mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj); } else { } } diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index 4c889a6d04..e51dd48dcd 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -23,6 +23,7 @@ SSdbRow *sdbAllocRow(int32_t objSize) { return NULL; } + mTrace("row:%p, is created, len:%d", pRow->pObj, objSize); return pRow; } @@ -43,5 +44,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) { } sdbPrintOper(pSdb, pRow, "freeRow"); + + mTrace("row:%p, is freed", pRow->pObj); tfree(pRow); } diff --git a/tests/script/general/user/basic1.sim b/tests/script/general/user/basic1.sim index 33c4dc96d4..0ae4ab4c57 100644 --- a/tests/script/general/user/basic1.sim +++ b/tests/script/general/user/basic1.sim @@ -1,22 +1,9 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode1 -s start -v sql connect print =============== show users -sql show users -if $rows != 1 then - return -1 -endi - -print $data00 $data01 $data02 -print $data10 $data11 $data22 -print $data20 $data11 $data22 - -sql_error show accounts; -sql_error create account a pass "a" -sql_error drop account a -sql_error drop account root print =============== create user1 sql create user user1 PASS 'user1' @@ -30,23 +17,10 @@ print $data10 $data11 $data12 print $data20 $data11 $data22 print $data30 $data31 $data32 -print =============== create user2 -sql create user user2 PASS 'user2' -sql show users -if $rows != 3 then - return -1 -endi - -print $data00 $data01 $data02 -print $data10 $data11 $data12 -print $data20 $data11 $data22 -print $data30 $data31 $data32 -print $data40 $data41 $data42 - print =============== drop user1 sql drop user user1 sql show users -if $rows != 2 then +if $rows != 1 then return -1 endi @@ -57,18 +31,4 @@ print $data30 $data31 $data32 print =============== restart taosd system sh/exec.sh -n dnode1 -s stop -sleep 1000 -system sh/exec.sh -n dnode1 -s start -print =============== show users -sql show users -if $rows != 2 then - return -1 -endi - -print $data00 $data01 $data02 -print $data10 $data11 $data22 -print $data20 $data11 $data22 -print $data30 $data31 $data32 - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From f5eb4ef6c64251b90e1a66e6ecb4dd792a76d9aa Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 23:43:29 +0800 Subject: [PATCH 05/86] minor changes --- tests/script/general/user/basic1.sim | 44 ++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/script/general/user/basic1.sim b/tests/script/general/user/basic1.sim index 0ae4ab4c57..33c4dc96d4 100644 --- a/tests/script/general/user/basic1.sim +++ b/tests/script/general/user/basic1.sim @@ -1,9 +1,22 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start -v +system sh/exec.sh -n dnode1 -s start sql connect print =============== show users +sql show users +if $rows != 1 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data22 +print $data20 $data11 $data22 + +sql_error show accounts; +sql_error create account a pass "a" +sql_error drop account a +sql_error drop account root print =============== create user1 sql create user user1 PASS 'user1' @@ -17,10 +30,23 @@ print $data10 $data11 $data12 print $data20 $data11 $data22 print $data30 $data31 $data32 +print =============== create user2 +sql create user user2 PASS 'user2' +sql show users +if $rows != 3 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data12 +print $data20 $data11 $data22 +print $data30 $data31 $data32 +print $data40 $data41 $data42 + print =============== drop user1 sql drop user user1 sql show users -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -31,4 +57,18 @@ print $data30 $data31 $data32 print =============== restart taosd system sh/exec.sh -n dnode1 -s stop +sleep 1000 +system sh/exec.sh -n dnode1 -s start +print =============== show users +sql show users +if $rows != 2 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data22 +print $data20 $data11 $data22 +print $data30 $data31 $data32 + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 96be7db9b7207f36a5dbcd32a34035078f83676e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 23:47:01 +0800 Subject: [PATCH 06/86] minor changes --- source/dnode/mnode/impl/src/mndUser.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0f3dfd2ee3..1619b8e14f 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -242,7 +242,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user); + SUserObj *pUser = mndAcquireUser(pMnode, pCreate->user); if (pUser != NULL) { mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_USER_ALREADY_EXIST; @@ -250,7 +250,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); if (pOperUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); @@ -312,14 +312,14 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pAlter->user); + SUserObj *pUser = mndAcquireUser(pMnode, pAlter->user); if (pUser == NULL) { terrno = TSDB_CODE_MND_USER_NOT_EXIST; mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); if (pOperUser == NULL) { mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; @@ -383,14 +383,14 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pDrop->user); + SUserObj *pUser = mndAcquireUser(pMnode, pDrop->user); if (pUser == NULL) { terrno = TSDB_CODE_MND_USER_NOT_EXIST; mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); if (pOperUser == NULL) { mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; From c9b8e7485f7c223e5fdc18739b0115c3382ff9fb Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 18:52:10 -0800 Subject: [PATCH 07/86] add logs --- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 4 ++-- source/dnode/mnode/impl/src/mndCluster.c | 3 ++- source/dnode/mnode/sdb/inc/sdbInt.h | 4 +++- source/dnode/mnode/sdb/src/sdbFile.c | 6 ++++++ source/dnode/mnode/sdb/src/sdbHash.c | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index fef7ad9d43..41382fbab5 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -71,7 +71,7 @@ class Testbase { const char* GetShowBinary(int32_t len); private: - int32_t showId; + int64_t showId; STableMetaMsg* pMeta; SRetrieveTableRsp* pRetrieveRsp; char* pData; diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index e14dc94d31..429d5a6976 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -79,7 +79,7 @@ void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; ASSERT(pShowRsp != nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); + pShowRsp->showId = htobe64(pShowRsp->showId); pMeta = &pShowRsp->tableMeta; pMeta->numOfTags = htonl(pMeta->numOfTags); pMeta->numOfColumns = htonl(pMeta->numOfColumns); @@ -121,7 +121,7 @@ void Testbase::SendShowRetrieveMsg() { int32_t contLen = sizeof(SRetrieveTableMsg); SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen); - pRetrieve->showId = htonl(showId); + pRetrieve->showId = htobe64(showId); pRetrieve->free = 0; SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 427fe55e1d..1c12109f38 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -33,7 +33,7 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter); int32_t mndInitCluster(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_CLUSTER, - .keyType = SDB_KEY_INT32, + .keyType = SDB_KEY_INT64, .deployFp = (SdbDeployFp)mndCreateDefaultCluster, .encodeFp = (SdbEncodeFp)mndClusterActionEncode, .decodeFp = (SdbDecodeFp)mndClusterActionDecode, @@ -128,6 +128,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id); + pMnode->clusterId = clusterObj.id; mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj); diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index da90451202..070aa56944 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -72,7 +72,9 @@ typedef struct SSdb { } SSdb; int32_t sdbWriteFile(SSdb *pSdb); -void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); + +const char *sdbTableName(ESdbType type); +void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); #ifdef __cplusplus } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 78cf0a3492..5a03b3409e 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -121,6 +121,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { char curfile[PATH_MAX] = {0}; snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); + mDebug("start to write file:%s", curfile); + FileFd fd = taosOpenFileCreateWrite(tmpfile); if (fd <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -132,6 +134,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; + mTrace("sdb write %s, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); + SHashObj *hash = pSdb->hashObjs[i]; SRWLatch *pLock = &pSdb->locks[i]; taosWLockLatch(pLock); @@ -144,6 +148,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { continue; } + sdbPrintOper(pSdb, pRow, "writeFile"); + SSdbRaw *pRaw = (*encodeFp)(pRow->pObj); if (pRaw != NULL) { pRaw->status = pRow->status; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 23bcdb1b60..597484dad1 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -static const char *sdbTableName(ESdbType type) { +const char *sdbTableName(ESdbType type) { switch (type) { case SDB_TRANS: return "trans"; From d3927b54c0b4671e5b7cef65e8146a4f6e1b7df6 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 22:22:50 -0800 Subject: [PATCH 08/86] Improve the error handling of mnode --- include/dnode/mnode/sdb/sdb.h | 129 ++++-------- source/dnode/mgmt/impl/test/db/db.cpp | 2 +- source/dnode/mnode/impl/src/mndAcct.c | 101 +++++---- source/dnode/mnode/impl/src/mndBnode.c | 111 ++++++---- source/dnode/mnode/impl/src/mndCluster.c | 73 ++++--- source/dnode/mnode/impl/src/mndConsumer.c | 81 ++++--- source/dnode/mnode/impl/src/mndDb.c | 153 ++++++++------ source/dnode/mnode/impl/src/mndDnode.c | 77 ++++--- source/dnode/mnode/impl/src/mndFunc.c | 97 +++++---- source/dnode/mnode/impl/src/mndMnode.c | 69 ++++-- source/dnode/mnode/impl/src/mndQnode.c | 67 ++++-- source/dnode/mnode/impl/src/mndSnode.c | 67 ++++-- source/dnode/mnode/impl/src/mndStb.c | 125 ++++++----- source/dnode/mnode/impl/src/mndTopic.c | 117 ++++++----- source/dnode/mnode/impl/src/mndTrans.c | 245 +++++++++++----------- source/dnode/mnode/impl/src/mndUser.c | 65 ++++-- source/dnode/mnode/impl/src/mndVgroup.c | 89 +++++--- 17 files changed, 974 insertions(+), 694 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 3ff86bea3e..9373e258be 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -22,121 +22,70 @@ extern "C" { #endif -#define SDB_GET_INT64(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int64_t); \ +#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \ + { \ + if (func(pRaw, dataPos, val) != 0) { \ + goto pos; \ + } \ + dataPos += sizeof(type); \ } -#define SDB_GET_INT32(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int32_t); \ - } - -#define SDB_GET_INT16(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int16_t); \ - } - -#define SDB_GET_INT8(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int8_t); \ - } - -#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \ +#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ { \ if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - tfree(pRow); \ - return NULL; \ + goto pos; \ } \ dataPos += valLen; \ } -#define SDB_GET_RESERVE(pRaw, pRow, dataPos, valLen) \ - { \ - char val[valLen] = {0}; \ - if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += valLen; \ +#define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t) + +#define SDB_GET_INT32(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt32, int32_t) + +#define SDB_GET_INT16(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt16, int16_t) + +#define SDB_GET_INT8(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt8, int8_t) + +#define SDB_GET_RESERVE(pRaw, dataPos, valLen, pos) \ + { \ + char val[valLen] = {0}; \ + SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ } -#define SDB_SET_INT64(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int64_t); \ +#define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \ + { \ + if (func(pRaw, dataPos, val) != 0) { \ + goto pos; \ + } \ + dataPos += sizeof(type); \ } -#define SDB_SET_INT32(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int32_t); \ - } +#define SDB_SET_INT64(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt64, int64_t) -#define SDB_SET_INT16(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt16(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int16_t); \ - } +#define SDB_SET_INT32(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt32, int32_t) -#define SDB_SET_INT8(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int8_t); \ - } +#define SDB_SET_INT16(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt16, int16_t) -#define SDB_SET_BINARY(pRaw, dataPos, val, valLen) \ +#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t) + +#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ { \ if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ + goto pos; \ } \ dataPos += valLen; \ } -#define SDB_SET_RESERVE(pRaw, dataPos, valLen) \ - { \ - char val[valLen] = {0}; \ - if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += valLen; \ +#define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \ + { \ + char val[valLen] = {0}; \ + SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ } -#define SDB_SET_DATALEN(pRaw, dataLen) \ +#define SDB_SET_DATALEN(pRaw, dataLen, pos) \ { \ if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ + goto pos; \ } \ } diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 5c67c10817..7ba19677fd 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -115,8 +115,8 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 2); - CheckInt32(1); CheckInt32(2); + CheckInt32(3); CheckInt32(0); CheckInt32(0); CheckInt16(1); diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 0c1ae1bffa..ae8ffea4ea 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -66,75 +66,100 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("acct:%s, will be created while deploy sdb", acctObj.acct); + mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto ACCT_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime) - SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime) - SDB_SET_INT32(pRaw, dataPos, pAcct->acctId) - SDB_SET_INT32(pRaw, dataPos, pAcct->status) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams) - SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, ACCT_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, ACCT_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, ACCT_ENCODE_OVER) + terrno = 0; + +ACCT_ENCODE_OVER: + if (terrno != 0) { + mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("acct:%s, encode to raw:%p, row:%p", pAcct->acct, pRaw, pAcct); return pRaw; } static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto ACCT_DECODE_OVER; if (sver != TSDB_ACCT_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode acct since %s", terrstr()); + goto ACCT_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); + if (pRow == NULL) goto ACCT_DECODE_OVER; + + SAcctObj *pAcct = sdbGetRowObj(pRow); + if (pAcct == NULL) goto ACCT_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, ACCT_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, ACCT_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_DECODE_OVER) + + terrno = 0; + +ACCT_DECODE_OVER: + if (terrno != 0) { + mError("acct:%s, failed to decode from raw:%p since %s", pAcct->acct, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); - SAcctObj *pAcct = sdbGetRowObj(pRow); - if (pAcct == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->updateTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->acctId) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->status) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxUsers) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxDbs) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxTimeSeries) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxStreams) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->cfg.maxStorage) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.accessState) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_ACCT_RESERVE_SIZE) - + mTrace("acct:%s, decode from raw:%p, row:%p", pAcct->acct, pRaw, pAcct); return pRow; } static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { - mTrace("acct:%s, perform insert action", pAcct->acct); + mTrace("acct:%s, perform insert action, row:%p", pAcct->acct, pAcct); return 0; } static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { - mTrace("acct:%s, perform delete action", pAcct->acct); + mTrace("acct:%s, perform delete action, row:%p", pAcct->acct, pAcct); return 0; } static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) { - mTrace("acct:%s, perform update action", pOldAcct->acct); + mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOldAcct->acct, pOldAcct, pNewAcct); pOldAcct->updateTime = pNewAcct->updateTime; pOldAcct->status = pNewAcct->status; diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 2d14e0f92e..ceaebe3f6d 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -58,9 +58,9 @@ int32_t mndInitBnode(SMnode *pMnode) { void mndCleanupBnode(SMnode *pMnode) {} -static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) { +static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) { SSdb *pSdb = pMnode->pSdb; - SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId); + SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &bnodeId); if (pObj == NULL) { terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; } @@ -73,47 +73,72 @@ static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) { } static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto BNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, BNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, BNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, BNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_ENCODE_OVER) + terrno = 0; + +BNODE_ENCODE_OVER: + if (terrno != 0) { + mError("bnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("bnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto BNODE_DECODE_OVER; if (sver != TSDB_BNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode snode since %s", terrstr()); + goto BNODE_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); + if (pRow == NULL) goto BNODE_DECODE_OVER; + + SBnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) goto BNODE_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &pObj->id, BNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, BNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, BNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_DECODE_OVER) + + terrno = 0; + +BNODE_DECODE_OVER: + if (terrno != 0) { + mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); - SBnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE) - + mTrace("bnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { - mTrace("snode:%d, perform insert action", pObj->id); + mTrace("bnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr()); + mError("bnode:%d, failed to perform insert action since %s", pObj->id, terrstr()); return -1; } @@ -121,7 +146,7 @@ static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { } static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { - mTrace("snode:%d, perform delete action", pObj->id); + mTrace("bnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -131,7 +156,7 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { } static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) { - mTrace("snode:%d, perform update action", pOldBnode->id); + mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOldBnode->id, pOldBnode, pNewBnode); pOldBnode->updateTime = pNewBnode->updateTime; return 0; } @@ -175,30 +200,30 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S } static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { - SBnodeObj snodeObj = {0}; - snodeObj.id = pDnode->id; - snodeObj.createdTime = taosGetTimestampMs(); - snodeObj.updateTime = snodeObj.createdTime; + SBnodeObj bnodeObj = {0}; + bnodeObj.id = pDnode->id; + bnodeObj.createdTime = taosGetTimestampMs(); + bnodeObj.updateTime = bnodeObj.createdTime; int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); goto CREATE_BNODE_OVER; } - mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); + mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId); - if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) { + if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) { mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); goto CREATE_BNODE_OVER; } - if (mndSetCreateBnodeCommitLogs(pTrans, &snodeObj) != 0) { + if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) { mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); goto CREATE_BNODE_OVER; } - if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { + if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) { mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); goto CREATE_BNODE_OVER; } @@ -221,18 +246,18 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { pCreate->dnodeId = htonl(pCreate->dnodeId); - mDebug("snode:%d, start to create", pCreate->dnodeId); + mDebug("bnode:%d, start to create", pCreate->dnodeId); SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { - mError("snode:%d, snode already exist", pObj->id); + mError("bnode:%d, bnode already exist", pObj->id); mndReleaseBnode(pMnode, pObj); return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); if (pDnode == NULL) { - mError("snode:%d, dnode not exist", pCreate->dnodeId); + mError("bnode:%d, dnode not exist", pCreate->dnodeId); terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; return -1; } @@ -241,7 +266,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { mndReleaseDnode(pMnode, pDnode); if (code != 0) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); return -1; } @@ -290,11 +315,11 @@ static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) { int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); + mError("bnode:%d, failed to drop since %s", pObj->id, terrstr()); goto DROP_BNODE_OVER; } - mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); + mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id); if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) { mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); @@ -328,24 +353,24 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); - mDebug("snode:%d, start to drop", pDrop->dnodeId); + mDebug("bnode:%d, start to drop", pDrop->dnodeId); if (pDrop->dnodeId <= 0) { terrno = TSDB_CODE_SDB_APP_ERROR; - mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); + mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("snode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("bnode:%d, not exist", pDrop->dnodeId); + terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; return -1; } int32_t code = mndDropBnode(pMnode, pMsg, pObj); if (code != 0) { - mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 1c12109f38..00cfa6b413 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -63,55 +63,80 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) { } static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, TSDB_CLUSTER_VER_NUMBE, sizeof(SClusterObj) + TSDB_CLUSTER_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto CLUSTER_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT64(pRaw, dataPos, pCluster->id); - SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime) - SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime) - SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE) + SDB_SET_INT64(pRaw, dataPos, pCluster->id, CLUSTER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, CLUSTER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, CLUSTER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_ENCODE_OVER) + terrno = 0; + +CLUSTER_ENCODE_OVER: + if (terrno != 0) { + mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("cluster:%" PRId64 ", encode to raw:%p, row:%p", pCluster->id, pRaw, pCluster); return pRaw; } static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CLUSTER_DECODE_OVER; if (sver != TSDB_CLUSTER_VER_NUMBE) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode cluster since %s", terrstr()); + goto CLUSTER_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj)); + if (pRow == NULL) goto CLUSTER_DECODE_OVER; + + SClusterObj *pCluster = sdbGetRowObj(pRow); + if (pCluster == NULL) goto CLUSTER_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT64(pRaw, dataPos, &pCluster->id, CLUSTER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, CLUSTER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, CLUSTER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_DECODE_OVER) + + terrno = 0; + +CLUSTER_DECODE_OVER: + if (terrno != 0) { + mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj)); - SClusterObj *pCluster = sdbGetRowObj(pRow); - if (pCluster == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime) - SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_CLUSTER_RESERVE_SIZE) - + mTrace("cluster:%" PRId64 ", decode from raw:%p, row:%p", pCluster->id, pRaw, pCluster); return pRow; } static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%" PRId64 ", perform insert action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform insert action, row:%p", pCluster->id, pCluster); return 0; } static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%" PRId64 ", perform delete action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform delete action, row:%p", pCluster->id, pCluster); return 0; } -static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) { - mTrace("cluster:%" PRId64 ", perform update action", pOldCluster->id); +static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) { + mTrace("cluster:%" PRId64 ", perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); return 0; } @@ -135,7 +160,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("cluster:%" PRId64 ", will be created while deploy sdb", clusterObj.id); + mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 9e7cdbf09e..32a044fe09 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -67,66 +67,87 @@ int32_t mndInitConsumer(SMnode *pMnode) { void mndCleanupConsumer(SMnode *pMnode) {} static SSdbRaw *mndConsumerActionEncode(SConsumerObj *pConsumer) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = sizeof(SConsumerObj) + MND_CONSUMER_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto CM_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN); - SDB_SET_BINARY(pRaw, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN); - SDB_SET_INT64(pRaw, dataPos, pConsumer->createTime); - SDB_SET_INT64(pRaw, dataPos, pConsumer->updateTime); - SDB_SET_INT64(pRaw, dataPos, pConsumer->uid); + SDB_SET_BINARY(pRaw, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN, CM_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN, CM_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pConsumer->createTime, CM_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pConsumer->updateTime, CM_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pConsumer->uid, CM_ENCODE_OVER) /*SDB_SET_INT64(pRaw, dataPos, pConsumer->dbUid);*/ - SDB_SET_INT32(pRaw, dataPos, pConsumer->version); + SDB_SET_INT32(pRaw, dataPos, pConsumer->version, CM_ENCODE_OVER) - SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE); - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CM_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, CM_ENCODE_OVER) +CM_ENCODE_OVER: + if (terrno != 0) { + mError("consumer:%s, failed to encode to raw:%p since %s", pConsumer->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("consumer:%s, encode to raw:%p, row:%p", pConsumer->name, pRaw, pConsumer); return pRaw; } static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CONSUME_DECODE_OVER; if (sver != MND_CONSUMER_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode consumer since %s", terrstr()); + goto CONSUME_DECODE_OVER; + } + + int32_t size = sizeof(SConsumerObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto CONSUME_DECODE_OVER; + + SConsumerObj *pConsumer = sdbGetRowObj(pRow); + if (pConsumer == NULL) goto CONSUME_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN, CONSUME_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN, CONSUME_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pConsumer->createTime, CONSUME_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pConsumer->updateTime, CONSUME_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pConsumer->uid, CONSUME_DECODE_OVER) + /*SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->dbUid);*/ + SDB_GET_INT32(pRaw, dataPos, &pConsumer->version, CONSUME_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CONSUME_DECODE_OVER) + terrno = 0; + +CONSUME_DECODE_OVER: + if (terrno != 0) { + mError("consumer:%s, failed to decode from raw:%p since %s", pConsumer->name, pRaw, terrstr()); + tfree(pRow); return NULL; } - int32_t size = sizeof(SConsumerObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); - SSdbRow *pRow = sdbAllocRow(size); - SConsumerObj *pConsumer = sdbGetRowObj(pRow); - if (pConsumer == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN); - SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN); - SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->createTime); - SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->updateTime); - SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->uid); - /*SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->dbUid);*/ - SDB_GET_INT32(pRaw, pRow, dataPos, &pConsumer->version); - - SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_CONSUMER_RESERVE_SIZE); - + mTrace("consumer:%s, decode from raw:%p, row:%p", pConsumer->name, pRaw, pConsumer); return pRow; } static int32_t mndConsumerActionInsert(SSdb *pSdb, SConsumerObj *pConsumer) { - mTrace("consumer:%s, perform insert action", pConsumer->name); + mTrace("consumer:%s, perform insert action, row:%p", pConsumer->name, pConsumer); return 0; } static int32_t mndConsumerActionDelete(SSdb *pSdb, SConsumerObj *pConsumer) { - mTrace("consumer:%s, perform delete action", pConsumer->name); + mTrace("consumer:%s, perform delete action, row:%p", pConsumer->name, pConsumer); return 0; } static int32_t mndConsumerActionUpdate(SSdb *pSdb, SConsumerObj *pOldConsumer, SConsumerObj *pNewConsumer) { - mTrace("consumer:%s, perform update action", pOldConsumer->name); + mTrace("consumer:%s, perform update action, old_row:%p new_row:%p", pOldConsumer->name, pOldConsumer, pNewConsumer); atomic_exchange_32(&pOldConsumer->updateTime, pNewConsumer->updateTime); atomic_exchange_32(&pOldConsumer->version, pNewConsumer->version); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index fe49ad99fe..410368f130 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -65,100 +65,125 @@ int32_t mndInitDb(SMnode *pMnode) { void mndCleanupDb(SMnode *pMnode) {} static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUMBER, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto DB_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN) - SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pDb->createdTime) - SDB_SET_INT64(pRaw, dataPos, pDb->updateTime) - SDB_SET_INT64(pRaw, dataPos, pDb->uid) - SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion) - SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion) - SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->createdTime, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->updateTime, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->uid, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, DB_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, DB_ENCODE_OVER) + terrno = 0; + +DB_ENCODE_OVER: + if (terrno != 0) { + mError("db:%s, failed to encode to raw:%p since %s", pDb->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("db:%s, encode to raw:%p, row:%p", pDb->name, pRaw, pDb); return pRaw; } static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DB_DECODE_OVER; if (sver != TSDB_DB_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode db since %s", terrstr()); - return NULL; + goto DB_DECODE_OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SDbObj)); - SDbObj *pDb = sdbGetRowObj(pRow); - if (pDb == NULL) return NULL; + if (pRow == NULL) goto DB_DECODE_OVER; + + SDbObj *pDb = sdbGetRowObj(pRow); + if (pDb == NULL) goto DB_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->name, TSDB_DB_FNAME_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->updateTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep0) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep1) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep2) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.minRows) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.maxRows) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.commitTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.fsyncPeriod) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.walLevel) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.precision) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.compression) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.replications) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.quorum) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.update) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.cacheLastRow) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DB_RESERVE_SIZE) + SDB_GET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->createdTime, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->updateTime, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->uid, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfgVersion, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->vgVersion, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->hashMethod, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfVgroups, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheBlockSize, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.totalBlocks, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep2, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.minRows, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.maxRows, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.commitTime, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.fsyncPeriod, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.walLevel, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.precision, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compression, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.replications, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.quorum, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.update, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, DB_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_DECODE_OVER) + terrno = 0; + +DB_DECODE_OVER: + if (terrno != 0) { + mError("db:%s, failed to decode from raw:%p since %s", pDb->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("db:%s, decode from raw:%p, row:%p", pDb->name, pRaw, pDb); return pRow; } static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb) { - mTrace("db:%s, perform insert action", pDb->name); + mTrace("db:%s, perform insert action, row:%p", pDb->name, pDb); return 0; } static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) { - mTrace("db:%s, perform delete action", pDb->name); + mTrace("db:%s, perform delete action, row:%p", pDb->name, pDb); return 0; } static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) { - mTrace("db:%s, perform update action", pOldDb->name); + mTrace("db:%s, perform update action, old_row:%p new_row:%p", pOldDb->name, pOldDb, pNewDb); pOldDb->updateTime = pNewDb->updateTime; pOldDb->cfgVersion = pNewDb->cfgVersion; pOldDb->vgVersion = pNewDb->vgVersion; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1c7f8544e9..d110969025 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -100,65 +100,90 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { if (pRaw == NULL) return -1; if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1; - mDebug("dnode:%d, will be created while deploy sdb", dnodeObj.id); + mDebug("dnode:%d, will be created while deploy sdb, raw:%p", dnodeObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto DNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pDnode->id); - SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime) - SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime) - SDB_SET_INT16(pRaw, dataPos, pDnode->port) - SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_INT32(pRaw, dataPos, pDnode->id, DNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, DNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, DNODE_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pDnode->port, DNODE_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, DNODE_ENCODE_OVER); + terrno = 0; + +DNODE_ENCODE_OVER: + if (terrno != 0) { + mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode); return pRaw; } static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER; if (sver != TSDB_DNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode dnode since %s", terrstr()); + goto DNODE_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj)); + if (pRow == NULL) goto DNODE_DECODE_OVER; + + SDnodeObj *pDnode = sdbGetRowObj(pRow); + if (pDnode == NULL) goto DNODE_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &pDnode->id, DNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, DNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, DNODE_DECODE_OVER) + SDB_GET_INT16(pRaw, dataPos, &pDnode->port, DNODE_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_DECODE_OVER) + + terrno = 0; + +DNODE_DECODE_OVER: + if (terrno != 0) { + mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj)); - SDnodeObj *pDnode = sdbGetRowObj(pRow); - if (pDnode == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pDnode->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->updateTime) - SDB_GET_INT16(pRaw, pRow, dataPos, &pDnode->port) - SDB_GET_BINARY(pRaw, pRow, dataPos, pDnode->fqdn, TSDB_FQDN_LEN) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DNODE_RESERVE_SIZE) - + mTrace("dnode:%d, decode from raw:%p, row:%p", pDnode->id, pRaw, pDnode); return pRow; } static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) { - mTrace("dnode:%d, perform insert action", pDnode->id); + mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode); pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED; snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port); return 0; } static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) { - mTrace("dnode:%d, perform delete action", pDnode->id); + mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode); return 0; } static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) { - mTrace("dnode:%d, perform update action", pOldDnode->id); + mTrace("dnode:%d, perform update action, old_row:%p new_row:%p", pOldDnode->id, pOldDnode, pNewDnode); pOldDnode->updateTime = pNewDnode->updateTime; return 0; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 59d04ab4a1..57c94fe5db 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -58,76 +58,101 @@ int32_t mndInitFunc(SMnode *pMnode) { void mndCleanupFunc(SMnode *pMnode) {} static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj); SSdbRaw *pRaw = sdbAllocRaw(SDB_FUNC, SDB_FUNC_VER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto FUNC_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime) - SDB_SET_INT8(pRaw, dataPos, pFunc->funcType) - SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType) - SDB_SET_INT8(pRaw, dataPos, pFunc->align) - SDB_SET_INT8(pRaw, dataPos, pFunc->outputType) - SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen) - SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize) - SDB_SET_INT64(pRaw, dataPos, pFunc->sigature) - SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize) - SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize) - SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize) - SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->funcType, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->align, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, FUNC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pFunc->sigature, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, FUNC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, FUNC_ENCODE_OVER); + terrno = 0; + +FUNC_ENCODE_OVER: + if (terrno != 0) { + mError("func:%s, failed to encode to raw:%p since %s", pFunc->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("func:%d, encode to raw:%p, row:%p", pFunc->name, pRaw, pFunc); return pRaw; } static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto FUNC_DECODE_OVER; if (sver != SDB_FUNC_VER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode func since %s", terrstr()); - return NULL; + goto FUNC_DECODE_OVER; } - int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN; - SSdbRow *pRow = sdbAllocRow(size); + int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN; + SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto FUNC_DECODE_OVER; + SFuncObj *pFunc = sdbGetRowObj(pRow); - if (pFunc == NULL) return NULL; + if (pFunc == NULL) goto FUNC_DECODE_OVER; char *tmp = (char *)pFunc + sizeof(SFuncObj); int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->createdTime) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->funcType) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->scriptType) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->align) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->outputType) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->outputLen) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->bufSize) - SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->sigature) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->commentSize) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->codeSize) - SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize) + SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pFunc->createdTime, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->funcType, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->scriptType, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->align, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, FUNC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pFunc->sigature, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize, FUNC_DECODE_OVER) pFunc->pComment = pFunc->pData; pFunc->pCode = (pFunc->pData + pFunc->commentSize); + terrno = 0; + +FUNC_DECODE_OVER: + if (terrno != 0) { + mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("func:%s, decode from raw:%p, row:%p", pFunc->name, pRaw, pFunc); return pRow; } static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc) { - mTrace("func:%s, perform insert action", pFunc->name); + mTrace("func:%s, perform insert action, row:%p", pFunc->name, pFunc); return 0; } static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc) { - mTrace("func:%s, perform delete action", pFunc->name); + mTrace("func:%s, perform delete action, row:%p", pFunc->name, pFunc); return 0; } static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOldFunc, SFuncObj *pNewFunc) { - mTrace("func:%s, perform update action", pOldFunc->name); + mTrace("func:%s, perform update action, old_row:%p new_row:%p", pOldFunc->name, pOldFunc, pNewFunc); return 0; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index ad3d5e1cf6..df1848f2f1 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -117,50 +117,75 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("mnode:%d, will be created while deploy sdb", mnodeObj.id); + mDebug("mnode:%d, will be created while deploy sdb, raw:%p", mnodeObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, TSDB_MNODE_VER_NUMBER, sizeof(SMnodeObj) + TSDB_MNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto MNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, MNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, MNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, MNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_ENCODE_OVER) + terrno = 0; + +MNODE_ENCODE_OVER: + if (terrno != 0) { + mError("mnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("mnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_MNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode mnode since %s", terrstr()); + goto MNODE_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj)); + if (pRow == NULL) goto MNODE_DECODE_OVER; + + SMnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) goto MNODE_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &pObj->id, MNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, MNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, MNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_DECODE_OVER) + + terrno = 0; + +MNODE_DECODE_OVER: + if (terrno != 0) { + mError("mnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj)); - SMnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_MNODE_RESERVE_SIZE) - + mTrace("mnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static void mnodeResetMnode(SMnodeObj *pObj) { pObj->role = TAOS_SYNC_STATE_FOLLOWER; } static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { - mTrace("mnode:%d, perform insert action", pObj->id); + mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -173,7 +198,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { } static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { - mTrace("mnode:%d, perform delete action", pObj->id); + mTrace("mnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -183,7 +208,7 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { } static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) { - mTrace("mnode:%d, perform update action", pOldMnode->id); + mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOldMnode->id, pOldMnode, pNewMnode); pOldMnode->updateTime = pNewMnode->updateTime; return 0; } @@ -370,7 +395,7 @@ CREATE_MNODE_OVER: } static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -537,7 +562,7 @@ DROP_MNODE_OVER: } static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 3b27764c7c..a0c4ff8218 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -73,43 +73,68 @@ static void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) { } static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, TSDB_QNODE_VER_NUMBER, sizeof(SQnodeObj) + TSDB_QNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto QNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, QNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, QNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, QNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_ENCODE_OVER) + terrno = 0; + +QNODE_ENCODE_OVER: + if (terrno != 0) { + mError("qnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("qnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto QNODE_DECODE_OVER; if (sver != TSDB_QNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode qnode since %s", terrstr()); + goto QNODE_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj)); + if (pRow == NULL) goto QNODE_DECODE_OVER; + + SQnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) goto QNODE_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &pObj->id, QNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, QNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, QNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_DECODE_OVER) + + terrno = 0; + +QNODE_DECODE_OVER: + if (terrno != 0) { + mError("qnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj)); - SQnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_QNODE_RESERVE_SIZE) - + mTrace("qnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) { - mTrace("qnode:%d, perform insert action", pObj->id); + mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -121,7 +146,7 @@ static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) { } static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { - mTrace("qnode:%d, perform delete action", pObj->id); + mTrace("qnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -131,7 +156,7 @@ static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { } static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) { - mTrace("qnode:%d, perform update action", pOldQnode->id); + mTrace("qnode:%d, perform update action, old_row:%p new_row:%p", pOldQnode->id, pOldQnode, pNewQnode); pOldQnode->updateTime = pNewQnode->updateTime; return 0; } @@ -339,7 +364,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { mError("qnode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + terrno = TSDB_CODE_MND_QNODE_NOT_EXIST; return -1; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index a4825c0e82..ac03e1659c 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -73,43 +73,68 @@ static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { } static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, TSDB_SNODE_VER_NUMBER, sizeof(SSnodeObj) + TSDB_SNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto SNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, SNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, SNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, SNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_ENCODE_OVER) + terrno = 0; + +SNODE_ENCODE_OVER: + if (terrno != 0) { + mError("snode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("snode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto SNODE_DECODE_OVER; if (sver != TSDB_SNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode snode since %s", terrstr()); + goto SNODE_DECODE_OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj)); + if (pRow == NULL) goto SNODE_DECODE_OVER; + + SSnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) goto SNODE_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &pObj->id, SNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, SNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, SNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_DECODE_OVER) + + terrno = 0; + +SNODE_DECODE_OVER: + if (terrno != 0) { + mError("snode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj)); - SSnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_SNODE_RESERVE_SIZE) - + mTrace("snode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) { - mTrace("snode:%d, perform insert action", pObj->id); + mTrace("snode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -121,7 +146,7 @@ static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) { } static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { - mTrace("snode:%d, perform delete action", pObj->id); + mTrace("snode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -131,7 +156,7 @@ static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { } static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) { - mTrace("snode:%d, perform update action", pOldSnode->id); + mTrace("snode:%d, perform update action, old_row:%p new_row:%p", pOldSnode->id, pOldSnode, pNewSnode); pOldSnode->updateTime = pNewSnode->updateTime; return 0; } @@ -339,7 +364,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { mError("snode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; return -1; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3454ea1884..8f18308374 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -70,90 +70,115 @@ int32_t mndInitStb(SMnode *pMnode) { void mndCleanupStb(SMnode *pMnode) {} static SSdbRaw *mndStbActionEncode(SStbObj *pStb) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + TSDB_STB_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto STB_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pStb->createdTime) - SDB_SET_INT64(pRaw, dataPos, pStb->updateTime) - SDB_SET_INT64(pRaw, dataPos, pStb->uid) - SDB_SET_INT64(pRaw, dataPos, pStb->dbUid) - SDB_SET_INT32(pRaw, dataPos, pStb->version) - SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns) - SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags) + SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->createdTime, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->updateTime, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->uid, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->dbUid, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->version, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; for (int32_t i = 0; i < totalCols; ++i) { SSchema *pSchema = &pStb->pSchema[i]; - SDB_SET_INT8(pRaw, dataPos, pSchema->type); - SDB_SET_INT32(pRaw, dataPos, pSchema->colId); - SDB_SET_INT32(pRaw, dataPos, pSchema->bytes); - SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN); + SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER) } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER) + terrno = 0; + +STB_ENCODE_OVER: + if (terrno != 0) { + mError("stb:%s, failed to encode to raw:%p since %s", pStb->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("stb:%s, encode to raw:%p, row:%p", pStb->name, pRaw, pStb); return pRaw; } static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto STB_DECODE_OVER; if (sver != TSDB_STB_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode stable since %s", terrstr()); - return NULL; + goto STB_DECODE_OVER; } int32_t size = sizeof(SStbObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto STB_DECODE_OVER; + SStbObj *pStb = sdbGetRowObj(pRow); - if (pStb == NULL) return NULL; + if (pStb == NULL) goto STB_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_DB_FNAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->updateTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->uid) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->dbUid) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->version) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfColumns) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfTags) + SDB_GET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->createdTime, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->updateTime, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->uid, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->dbUid, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->version, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; pStb->pSchema = calloc(totalCols, sizeof(SSchema)); for (int32_t i = 0; i < totalCols; ++i) { SSchema *pSchema = &pStb->pSchema[i]; - SDB_GET_INT8(pRaw, pRow, dataPos, &pSchema->type); - SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->colId); - SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->bytes); - SDB_GET_BINARY(pRaw, pRow, dataPos, pSchema->name, TSDB_COL_NAME_LEN); + SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER) } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_STB_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER) + terrno = 0; + +STB_DECODE_OVER: + if (terrno != 0) { + mError("stb:%s, failed to decode from raw:%p since %s", pStb->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("stb:%s, decode from raw:%p, row:%p", pStb->name, pRaw, pStb); return pRow; } static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) { - mTrace("stb:%s, perform insert action", pStb->name); + mTrace("stb:%s, perform insert action, row:%p", pStb->name, pStb); return 0; } static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) { - mTrace("stb:%s, perform delete action", pStb->name); + mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb); return 0; } static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb) { - mTrace("stb:%s, perform update action", pOldStb->name); + mTrace("stb:%s, perform update action, old_row:%p new_row:%p", pOldStb->name, pOldStb, pNewStb); atomic_exchange_32(&pOldStb->updateTime, pNewStb->updateTime); atomic_exchange_32(&pOldStb->version, pNewStb->version); @@ -177,7 +202,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; @@ -202,9 +227,9 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) { SVCreateTbReq req; - void * buf; + void *buf; int bsize; - SMsgHead * pMsgHead; + SMsgHead *pMsgHead; req.ver = 0; req.name = pStb->name; @@ -325,9 +350,9 @@ 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) { @@ -361,9 +386,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); @@ -467,7 +492,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); @@ -551,7 +576,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); @@ -665,7 +690,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); @@ -700,7 +725,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); @@ -772,7 +797,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); @@ -791,7 +816,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; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 24e32e07b4..9fb63f6f58 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -59,80 +59,105 @@ int32_t mndInitTopic(SMnode *pMnode) { void mndCleanupTopic(SMnode *pMnode) {} static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = sizeof(STopicObj) + MND_TOPIC_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto TOPIC_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); - SDB_SET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_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_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN, TOPIC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_LEN, TOPIC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTopic->createTime, TOPIC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTopic->updateTime, TOPIC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTopic->uid, TOPIC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid, TOPIC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pTopic->execLen, TOPIC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen, TOPIC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER) - SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE); - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, TOPIC_ENCODE_OVER) + terrno = 0; + +TOPIC_ENCODE_OVER: + if (terrno != 0) { + mError("topic:%s, failed to encode to raw:%p since %s", pTopic->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("topic:%s, encode to raw:%p, row:%p", pTopic->name, pRaw, pTopic); return pRaw; } static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TOPIC_DECODE_OVER; if (sver != MND_TOPIC_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode topic since %s", terrstr()); + goto TOPIC_DECODE_OVER; + } + + int32_t size = sizeof(STopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto TOPIC_DECODE_OVER; + + STopicObj *pTopic = sdbGetRowObj(pRow); + if (pTopic == NULL) goto TOPIC_DECODE_OVER; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN, TOPIC_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_LEN, TOPIC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTopic->createTime, TOPIC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTopic->updateTime, TOPIC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pTopic->execLen, TOPIC_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen, TOPIC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER) + + SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER) + + terrno = 0; + +TOPIC_DECODE_OVER: + if (terrno != 0) { + mError("topic:%s, failed to decode from raw:%p since %s", pTopic->name, pRaw, terrstr()); + tfree(pRow); 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_DB_FNAME_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, MND_TOPIC_RESERVE_SIZE); - + mTrace("topic:%s, decode from raw:%p, row:%p", pTopic->name, pRaw, pTopic); return pRow; } static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic) { - mTrace("topic:%s, perform insert action", pTopic->name); + mTrace("topic:%s, perform insert action, row:%p", pTopic->name, pTopic); return 0; } static int32_t mndTopicActionDelete(SSdb *pSdb, STopicObj *pTopic) { - mTrace("topic:%s, perform delete action", pTopic->name); + mTrace("topic:%s, perform delete action, row:%p", pTopic->name, pTopic); return 0; } static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj *pNewTopic) { - mTrace("topic:%s, perform update action", pOldTopic->name); + mTrace("topic:%s, perform update action, old_row:%p new_row:%p", pOldTopic->name, pOldTopic, pNewTopic); atomic_exchange_32(&pOldTopic->updateTime, pNewTopic->updateTime); atomic_exchange_32(&pOldTopic->version, pNewTopic->version); taosWLockLatch(&pOldTopic->lock); - - //TODO handle update + + // TODO handle update taosWUnLockLatch(&pOldTopic->lock); return 0; @@ -201,9 +226,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCMCreateTopicReq } static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - char *msgStr = pMsg->rpcMsg.pCont; - SCMCreateTopicReq* pCreate; + SMnode *pMnode = pMsg->pMnode; + char *msgStr = pMsg->rpcMsg.pCont; + SCMCreateTopicReq *pCreate; tDeserializeSCMCreateTopicReq(msgStr, pCreate); mDebug("topic:%s, start to create", pCreate->name); @@ -245,9 +270,7 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndDropTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pTopic) { - return 0; -} +static int32_t mndDropTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pTopic) { return 0; } static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index b0d799d21b..5062048d6d 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -31,6 +31,7 @@ static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw); static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction); static void mndTransDropLogs(SArray *pArray); static void mndTransDropActions(SArray *pArray); +static void mndTransDropData(STrans *pTrans); static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray); static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray); static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans); @@ -70,6 +71,8 @@ int32_t mndInitTrans(SMnode *pMnode) { void mndCleanupTrans(SMnode *pMnode) {} static SSdbRaw *mndTransActionEncode(STrans *pTrans) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE; int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); @@ -109,75 +112,95 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { } int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pTrans->id) - SDB_SET_INT8(pRaw, dataPos, pTrans->policy) - SDB_SET_INT32(pRaw, dataPos, redoLogNum) - SDB_SET_INT32(pRaw, dataPos, undoLogNum) - SDB_SET_INT32(pRaw, dataPos, commitLogNum) - SDB_SET_INT32(pRaw, dataPos, redoActionNum) - SDB_SET_INT32(pRaw, dataPos, undoActionNum) + SDB_SET_INT32(pRaw, dataPos, pTrans->id, TRANS_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->policy, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, redoLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, undoLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, commitLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, redoActionNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, undoActionNum, TRANS_ENCODE_OVER) for (int32_t i = 0; i < redoLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < undoLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < commitLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } 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_INT16(pRaw, dataPos, pAction->msgType) - SDB_SET_INT32(pRaw, dataPos, pAction->contLen) - SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen); + SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) } 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_INT16(pRaw, dataPos, pAction->msgType) - SDB_SET_INT32(pRaw, dataPos, pAction->contLen) - SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen); + SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) + } + + SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, TRANS_ENCODE_OVER) + + terrno = 0; + +TRANS_ENCODE_OVER: + if (terrno != 0) { + mError("trans:%d, failed to encode to raw:%p len:%d since %s", pTrans->id, pRaw, dataPos, terrstr()); + sdbFreeRaw(pRaw); + return NULL; } - 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; } static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { - int32_t code = 0; + terrno = TSDB_CODE_OUT_OF_MEMORY; - int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + SSdbRow *pRow = NULL; + STrans *pTrans = NULL; + char *pData = NULL; + int32_t dataLen = 0; + int8_t sver = 0; + int32_t redoLogNum = 0; + int32_t undoLogNum = 0; + int32_t commitLogNum = 0; + int32_t redoActionNum = 0; + int32_t undoActionNum = 0; + int32_t dataPos = 0; + STransAction action = {0}; + + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TRANS_DECODE_OVER; if (sver != MND_TRANS_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode trans since %s", terrstr()); - return NULL; + goto TRANS_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(STrans)); - STrans *pTrans = sdbGetRowObj(pRow); - if (pTrans == NULL) { - mError("failed to alloc trans from raw:%p since %s", pRaw, terrstr()); - return NULL; - } + pRow = sdbAllocRow(sizeof(STrans)); + if (pRow == NULL) goto TRANS_DECODE_OVER; + + pTrans = sdbGetRowObj(pRow); + if (pTrans == NULL) goto TRANS_DECODE_OVER; pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); @@ -185,112 +208,79 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { 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) { - mDebug("trans:%d, failed to create array while parsed from raw:%p", pTrans->id, pRaw); - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + if (pTrans->redoLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->undoLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->commitLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->redoActions == NULL) goto TRANS_DECODE_OVER; + if (pTrans->undoActions == NULL) goto TRANS_DECODE_OVER; - int32_t redoLogNum = 0; - int32_t undoLogNum = 0; - int32_t commitLogNum = 0; - int32_t redoActionNum = 0; - int32_t undoActionNum = 0; - - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id) - SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->policy) - SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &commitLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &redoActionNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum) + SDB_GET_INT32(pRaw, dataPos, &pTrans->id, TRANS_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, (int8_t *)&pTrans->policy, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &redoLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &undoLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &commitLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &redoActionNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &undoActionNum, TRANS_DECODE_OVER) for (int32_t i = 0; i < redoLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->redoLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < undoLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->undoLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < commitLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->commitLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < redoActionNum; ++i) { - STransAction action = {0}; - SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) - SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) + SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); + SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); - if (action.pCont == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } - SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen); - - void *ret = taosArrayPush(pTrans->redoActions, &action); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + if (action.pCont == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto TRANS_DECODE_OVER; + action.pCont = NULL; } for (int32_t i = 0; i < undoActionNum; ++i) { - STransAction action = {0}; - SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) - SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) + SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); + SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); - if (action.pCont == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } - SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen); - - void *ret = taosArrayPush(pTrans->undoActions, &action); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + if (action.pCont == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto TRANS_DECODE_OVER; + action.pCont = NULL; } - SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TRANS_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_DECODE_OVER) + + terrno = 0; TRANS_DECODE_OVER: - if (code != 0) { - mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, tstrerror(errno)); - mndTransDrop(pTrans); - terrno = code; + if (terrno != 0) { + mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr()); + mndTransDropData(pTrans); + tfree(pRow); + tfree(pData); + tfree(action.pCont); return NULL; } @@ -304,15 +294,17 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { return 0; } -static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { - mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); - +static void mndTransDropData(STrans *pTrans) { mndTransDropLogs(pTrans->redoLogs); mndTransDropLogs(pTrans->undoLogs); mndTransDropLogs(pTrans->commitLogs); mndTransDropActions(pTrans->redoActions); mndTransDropActions(pTrans->undoActions); +} +static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { + mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); + mndTransDropData(pTrans); return 0; } @@ -367,6 +359,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) { } static void mndTransDropLogs(SArray *pArray) { + if (pArray == NULL) return; for (int32_t i = 0; i < pArray->size; ++i) { SSdbRaw *pRaw = taosArrayGetP(pArray, i); sdbFreeRaw(pRaw); @@ -376,6 +369,7 @@ static void mndTransDropLogs(SArray *pArray) { } static void mndTransDropActions(SArray *pArray) { + if (pArray == NULL) return; for (int32_t i = 0; i < pArray->size; ++i) { STransAction *pAction = taosArrayGet(pArray, i); free(pAction->pCont); @@ -385,12 +379,7 @@ static void mndTransDropActions(SArray *pArray) { } void mndTransDrop(STrans *pTrans) { - mndTransDropLogs(pTrans->redoLogs); - mndTransDropLogs(pTrans->undoLogs); - mndTransDropLogs(pTrans->commitLogs); - mndTransDropActions(pTrans->redoActions); - mndTransDropActions(pTrans->undoActions); - + mndTransDropData(pTrans); mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans); tfree(pTrans); } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 8b891ddb92..6311d3e8da 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -94,45 +94,68 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) { } static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER_NUMBER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto USER_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN) - SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN) - SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) - SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) - SDB_SET_INT8(pRaw, dataPos, pUser->superUser) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, USER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, USER_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pUser->superUser, USER_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, USER_ENCODE_OVER) + + terrno = 0; + +USER_ENCODE_OVER: + if (terrno != 0) { + mError("user:%s, failed to encode to raw:%p since %s", pUser->user, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } mTrace("user:%s, encode to raw:%p, row:%p", pUser->user, pRaw, pUser); return pRaw; } static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto USER_DECODE_OVER; if (sver != TSDB_USER_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode user since %s", terrstr()); - return NULL; + goto USER_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj)); + if (pRow == NULL) goto USER_DECODE_OVER; + SUserObj *pUser = sdbGetRowObj(pRow); - if (pUser == NULL) return NULL; + if (pUser == NULL) goto USER_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_PASSWORD_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime) - SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE) + SDB_GET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, USER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, USER_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, USER_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_DECODE_OVER) + + terrno = 0; + +USER_DECODE_OVER: + if (terrno != 0) { + mError("user:%s, failed to decode from raw:%p since %s", pUser->user, pRaw, terrstr()); + tfree(pRow); + return NULL; + } mTrace("user:%s, decode from raw:%p, row:%p", pUser->user, pRaw, pUser); return pRow; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 3090f1e645..bd17c6d150 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -70,77 +70,102 @@ int32_t mndInitVgroup(SMnode *pMnode) { void mndCleanupVgroup(SMnode *pMnode) {} SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUMBER, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto VG_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId) - SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime) - SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime) - SDB_SET_INT32(pRaw, dataPos, pVgroup->version) - SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin) - SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd) - SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid) - SDB_SET_INT8(pRaw, dataPos, pVgroup->replica) + SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->version, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd, VG_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid, VG_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pVgroup->replica, VG_ENCODE_OVER) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; - SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId) + SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, VG_ENCODE_OVER) } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, VG_ENCODE_OVER) + terrno = 0; + +VG_ENCODE_OVER: + if (terrno != 0) { + mError("vgId:%d, failed to encode to raw:%p since %s", pVgroup->vgId, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("vgId:%d, encode to raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup); return pRaw; } SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto VG_DECODE_OVER; if (sver != TSDB_VGROUP_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode vgroup since %s", terrstr()); - return NULL; + goto VG_DECODE_OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SVgObj)); - SVgObj *pVgroup = sdbGetRowObj(pRow); - if (pVgroup == NULL) return NULL; + if (pRow == NULL) goto VG_DECODE_OVER; + + SVgObj *pVgroup = sdbGetRowObj(pRow); + if (pVgroup == NULL) goto VG_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->vgId) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->updateTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->version) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashBegin) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashEnd) - SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->dbUid) - SDB_GET_INT8(pRaw, pRow, dataPos, &pVgroup->replica) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->vgId, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->createdTime, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->updateTime, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->version, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashBegin, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashEnd, VG_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->dbUid, VG_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pVgroup->replica, VG_DECODE_OVER) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId) + SDB_GET_INT32(pRaw, dataPos, &pVgid->dnodeId, VG_DECODE_OVER) if (pVgroup->replica == 1) { pVgid->role = TAOS_SYNC_STATE_LEADER; } } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_DECODE_OVER) + terrno = 0; + +VG_DECODE_OVER: + if (terrno != 0) { + mError("vgId:%d, failed to decode from raw:%p since %s", pVgroup->vgId, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("vgId:%d, decode from raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup); return pRow; } static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup) { - mTrace("vgId:%d, perform insert action", pVgroup->vgId); + mTrace("vgId:%d, perform insert action, row:%p", pVgroup->vgId, pVgroup); return 0; } static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup) { - mTrace("vgId:%d, perform delete action", pVgroup->vgId); + mTrace("vgId:%d, perform delete action, row:%p", pVgroup->vgId, pVgroup); return 0; } static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNewVgroup) { - mTrace("vgId:%d, perform update action", pOldVgroup->vgId); + mTrace("vgId:%d, perform update action, old_row:%p new_row:%p", pOldVgroup->vgId, pOldVgroup, pNewVgroup); pOldVgroup->updateTime = pNewVgroup->updateTime; pOldVgroup->version = pNewVgroup->version; pOldVgroup->hashBegin = pNewVgroup->hashBegin; From fe96d9dcf4071def467782a445fa3a0e286040b2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 22:32:59 -0800 Subject: [PATCH 09/86] Add fields to acct --- source/dnode/mnode/impl/inc/mndDef.h | 6 ++++++ source/dnode/mnode/impl/src/mndAcct.c | 28 ++++++++++++++++++++++----- source/dnode/mnode/impl/src/mndFunc.c | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index e26c0c5ae7..267a3f6cf5 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -160,8 +160,14 @@ typedef struct { typedef struct { int32_t maxUsers; int32_t maxDbs; + int32_t maxStbs; + int32_t maxTbs; int32_t maxTimeSeries; int32_t maxStreams; + int32_t maxFuncs; + int32_t maxConsumers; + int32_t maxConns; + int32_t maxTopics; int64_t maxStorage; // In unit of GB int32_t accessState; // Configured only by command } SAcctCfg; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index ae8ffea4ea..2847d19bea 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -18,7 +18,7 @@ #include "mndShow.h" #define TSDB_ACCT_VER_NUMBER 1 -#define TSDB_ACCT_RESERVE_SIZE 64 +#define TSDB_ACCT_RESERVE_SIZE 128 static int32_t mndCreateDefaultAcct(SMnode *pMnode); static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct); @@ -55,10 +55,16 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { acctObj.createdTime = taosGetTimestampMs(); acctObj.updateTime = acctObj.createdTime; acctObj.acctId = 1; - acctObj.cfg = (SAcctCfg){.maxUsers = 1024, - .maxDbs = 1024, + acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX, + .maxDbs = INT32_MAX, + .maxStbs = INT32_MAX, + .maxTbs = INT32_MAX, .maxTimeSeries = INT32_MAX, - .maxStreams = 8092, + .maxStreams = INT32_MAX, + .maxFuncs = INT32_MAX, + .maxConsumers = INT32_MAX, + .maxConns = INT32_MAX, + .maxTopics = INT32_MAX, .maxStorage = INT64_MAX, .accessState = TSDB_VN_ALL_ACCCESS}; @@ -84,8 +90,14 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, ACCT_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, ACCT_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, ACCT_ENCODE_OVER) SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, ACCT_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, ACCT_ENCODE_OVER) SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_ENCODE_OVER) @@ -129,8 +141,14 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, ACCT_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, ACCT_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, ACCT_DECODE_OVER) SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, ACCT_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, ACCT_DECODE_OVER) SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_DECODE_OVER) @@ -163,7 +181,7 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNe pOldAcct->updateTime = pNewAcct->updateTime; pOldAcct->status = pNewAcct->status; - memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctInfo)); + memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctCfg)); return 0; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 57c94fe5db..f7a39ce9e5 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -89,7 +89,7 @@ FUNC_ENCODE_OVER: return NULL; } - mTrace("func:%d, encode to raw:%p, row:%p", pFunc->name, pRaw, pFunc); + mTrace("func:%s, encode to raw:%p, row:%p", pFunc->name, pRaw, pFunc); return pRaw; } From 89a0dd76c25ae0ff70b6efc75feec6972f0d8805 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 00:19:26 -0800 Subject: [PATCH 10/86] test for create table --- source/dnode/mnode/impl/src/mnode.c | 4 -- tests/CMakeLists.txt | 2 +- tests/test/c/CMakeLists.txt | 60 +++---------------- .../c/{createNormalTable.c => create_table.c} | 9 +-- tools/shell/CMakeLists.txt | 2 - 5 files changed, 14 insertions(+), 63 deletions(-) rename tests/test/c/{createNormalTable.c => create_table.c} (98%) diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index e902e13a36..3a55961d4a 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -202,8 +202,6 @@ static int32_t mndExecSteps(SMnode *pMnode) { SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos); if (pStep->initFp == NULL) continue; - // (*pMnode->reportProgress)(pStep->name, "start initialize"); - if ((*pStep->initFp)(pMnode) != 0) { int32_t code = terrno; mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); @@ -213,8 +211,6 @@ static int32_t mndExecSteps(SMnode *pMnode) { } else { mDebug("step:%s is initialized", pStep->name); } - - // (*pMnode->reportProgress)(pStep->name, "initialize completed"); } return 0; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 966eb94354..59cbbb3147 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ #ADD_SUBDIRECTORY(examples/c) ADD_SUBDIRECTORY(tsim) -#ADD_SUBDIRECTORY(test/c) +ADD_SUBDIRECTORY(test/c) #ADD_SUBDIRECTORY(comparisonTest/tdengine) diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index 2702d192d3..ebe9f96989 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -1,52 +1,8 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) -PROJECT(TDengine) - -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/tsdb/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/plugins/http/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) -INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) - -IF (TD_LINUX) - #add_executable(insertPerTable insertPerTable.c) - #target_link_libraries(insertPerTable taos_static pthread) - - #add_executable(insertPerRow insertPerRow.c) - #target_link_libraries(insertPerRow taos_static pthread) - - #add_executable(importOneRow importOneRow.c) - #target_link_libraries(importOneRow taos_static pthread) - - #add_executable(importPerTable importPerTable.c) - #target_link_libraries(importPerTable taos_static pthread) - - #add_executable(hashPerformance hashPerformance.c) - #target_link_libraries(hashPerformance taos_static tutil common pthread) - - #add_executable(createTablePerformance createTablePerformance.c) - #target_link_libraries(createTablePerformance taos_static tutil common pthread) - - #add_executable(createNormalTable createNormalTable.c) - #target_link_libraries(createNormalTable taos_static tutil common pthread) - - #add_executable(queryPerformance queryPerformance.c) - #target_link_libraries(queryPerformance taos_static tutil common pthread) - - #add_executable(httpTest httpTest.c) - #target_link_libraries(httpTest taos_static tutil common pthread mnode monitor http tsdb twal vnode cJson lz4) - - #add_executable(cacheTest cacheTest.c) - #target_link_libraries(cacheTest taos_static tutil common pthread mnode monitor http tsdb twal vnode cJson lz4) - - #add_executable(invalidTableId invalidTableId.c) - #target_link_libraries(invalidTableId taos_static tutil common pthread) - - #add_executable(hashIterator hashIterator.c) - #target_link_libraries(hashIterator taos_static tutil common pthread) -ENDIF() - +add_executable(create_table create_table.c) +target_link_libraries( + create_table + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os +) diff --git a/tests/test/c/createNormalTable.c b/tests/test/c/create_table.c similarity index 98% rename from tests/test/c/createNormalTable.c rename to tests/test/c/create_table.c index f9e4aa5a3a..d51292ae01 100644 --- a/tests/test/c/createNormalTable.c +++ b/tests/test/c/create_table.c @@ -14,13 +14,14 @@ */ #define _DEFAULT_SOURCE -#include "../../../include/client/taos.h" -#include "hash.h" #include "os.h" + +#include "taos.h" +#include "taosdef.h" #include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" +#include "thash.h" #include "tutil.h" +#include "ulog.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index def421c212..b351675e47 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -1,6 +1,4 @@ aux_source_directory(src SHELL_SRC) -list(REMOVE_ITEM SHELL_SRC src/shellWindows.c) -list(REMOVE_ITEM SHELL_SRC src/shellDarwin.c) add_executable(shell ${SHELL_SRC}) target_link_libraries( From f469521f2495cc69dbd611250f9078a70c35e17e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 01:14:54 -0800 Subject: [PATCH 11/86] test for create table --- tests/test/c/create_table.c | 142 +++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 65 deletions(-) diff --git a/tests/test/c/create_table.c b/tests/test/c/create_table.c index d51292ae01..dca7b1159c 100644 --- a/tests/test/c/create_table.c +++ b/tests/test/c/create_table.c @@ -28,35 +28,35 @@ #define NC "\033[0m" char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t numOfThreads = 30; -int32_t numOfTables = 100000; -int32_t replica = 1; -int32_t numOfColumns = 2; +char stbName[64] = "st"; +int32_t numOfThreads = 2; +int32_t numOfTables = 100; +int32_t createTable = 1; +int32_t insertData = 0; +int32_t batchNum = 1; +int32_t numOfVgroups = 2; typedef struct { int32_t tableBeginIndex; int32_t tableEndIndex; int32_t threadIndex; char dbName[32]; - char stableName[64]; + char stbName[64]; float createTableSpeed; + float insertDataSpeed; pthread_t thread; } SThreadInfo; -void shellParseArgument(int argc, char *argv[]); +void parseArgument(int argc, char *argv[]); void *threadFunc(void *param); -void createDbAndSTable(); +void createDbAndStb(); int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - if (replica != 0) { - createDbAndSTable(); - } + parseArgument(argc, argv); + createDbAndStb(); + + pPrint("%d threads are spawned to create %d tables", numOfThreads, numOfThreads); - pPrint("%d threads are spawned to create table", numOfThreads); - pthread_attr_t thattr; pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) { pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; pInfo[i].threadIndex = i; strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); + strcpy(pInfo[i].stbName, stbName); pthread_create(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i)); } @@ -83,25 +83,31 @@ int main(int argc, char *argv[]) { createTableSpeed += pInfo[i].createTableSpeed; } - pPrint("%s total speed:%.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); + float insertDataSpeed = 0; + for (int i = 0; i < numOfThreads; ++i) { + insertDataSpeed += pInfo[i].insertDataSpeed; + } + + pPrint("%s total %.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); + pPrint("%s total %.1f rows/second, threads:%d %s", GREEN, insertDataSpeed, numOfThreads, NC); pthread_attr_destroy(&thattr); free(pInfo); } -void createDbAndSTable() { +void createDbAndStb() { pPrint("start to create db and stable"); char qstr[64000]; - + TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0); if (con == NULL) { pError("failed to connect to DB, reason:%s", taos_errstr(con)); exit(1); } - sprintf(qstr, "create database if not exists %s replica %d", dbName, replica); + sprintf(qstr, "create database if not exists %s vgroups %d", dbName, numOfVgroups); TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); + int32_t code = taos_errno(pSql); if (code != 0) { pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); exit(0); @@ -122,8 +128,8 @@ void createDbAndSTable() { void *threadFunc(void *param) { SThreadInfo *pInfo = (SThreadInfo *)param; - char qstr[65000]; - int code; + char qstr[65000]; + int code; TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0); if (con == NULL) { @@ -135,49 +141,45 @@ void *threadFunc(void *param) { TAOS_RES *pSql = taos_query(con, qstr); taos_free_result(pSql); - int64_t startMs = taosGetTimestampMs(); - - if (replica != 0) { + if (createTable) { + int64_t startMs = taosGetTimestampMs(); for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table %s%d (ts timestamp, i int)", stableName, t); + sprintf(qstr, "create table %s%d (ts timestamp, i int)", stbName, t); TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); if (code != 0) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); + pError("failed to create table %s%d, reason:%s", stbName, t, tstrerror(code)); } taos_free_result(pSql); } - } else { + int64_t endMs = taosGetTimestampMs(); + int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; + float seconds = (endMs - startMs) / 1000.0; + float speed = totalTables / seconds; + pInfo->createTableSpeed = speed; + pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); + } + + if (insertData) { + int64_t startMs = taosGetTimestampMs(); for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "insert into %s%d values(now, 1)", stableName, t); + sprintf(qstr, "insert into %s%d values(now, 1)", stbName, t); TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); if (code != 0) { - if (code != TSDB_CODE_MND_INVALID_TABLE_NAME) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); - } - if (code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - exit(0); - } + pError("failed to create table %s%d, reason:%s", stbName, t, tstrerror(code)); } taos_free_result(pSql); } + int64_t endMs = taosGetTimestampMs(); + int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; + float seconds = (endMs - startMs) / 1000.0; + float speed = totalTables / seconds; + pInfo->insertDataSpeed = speed; + pPrint("thread:%d, time:%.2f sec, speed:%.1f rows/second, ", pInfo->threadIndex, seconds, speed); } - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - int64_t endMs = taosGetTimestampMs(); - int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - float seconds = (endMs - startMs) / 1000.0; - float speed = totalTables / seconds; - pInfo->createTableSpeed = speed; - - pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); taos_close(con); - return 0; } @@ -190,20 +192,24 @@ void printHelp() { printf("%s%s\n", indent, "-d"); printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName); + printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stbName); printf("%s%s\n", indent, "-t"); printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", numOfThreads); printf("%s%s\n", indent, "-n"); printf("%s%s%s%d\n", indent, indent, "numOfTables, default is ", numOfTables); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "replica, default is ", replica); - printf("%s%s\n", indent, "-columns"); - printf("%s%s%s%d\n", indent, indent, "numOfColumns, default is ", numOfColumns); - + printf("%s%s\n", indent, "-v"); + printf("%s%s%s%d\n", indent, indent, "numOfVgroups, default is ", numOfVgroups); + printf("%s%s\n", indent, "-a"); + printf("%s%s%s%d\n", indent, indent, "createTable, default is ", createTable); + printf("%s%s\n", indent, "-i"); + printf("%s%s%s%d\n", indent, indent, "insertData, default is ", insertData); + printf("%s%s\n", indent, "-b"); + printf("%s%s%s%d\n", indent, indent, "batchNum, default is ", batchNum); + exit(EXIT_SUCCESS); } -void shellParseArgument(int argc, char *argv[]) { +void parseArgument(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { printHelp(); @@ -213,26 +219,32 @@ void shellParseArgument(int argc, char *argv[]) { } else if (strcmp(argv[i], "-c") == 0) { strcpy(configDir, argv[++i]); } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); + strcpy(stbName, argv[++i]); } else if (strcmp(argv[i], "-t") == 0) { numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-n") == 0) { numOfTables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-columns") == 0) { - numOfColumns = atoi(argv[++i]); + } else if (strcmp(argv[i], "-n") == 0) { + numOfVgroups = atoi(argv[++i]); + } else if (strcmp(argv[i], "-a") == 0) { + createTable = atoi(argv[++i]); + } else if (strcmp(argv[i], "-i") == 0) { + insertData = atoi(argv[++i]); + } else if (strcmp(argv[i], "-b") == 0) { + batchNum = atoi(argv[++i]); } else { } } pPrint("%s dbName:%s %s", GREEN, dbName, NC); - pPrint("%s stableName:%s %s", GREEN, stableName, NC); + pPrint("%s stbName:%s %s", GREEN, stbName, NC); pPrint("%s configDir:%s %s", GREEN, configDir, NC); pPrint("%s numOfTables:%d %s", GREEN, numOfTables, NC); pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s numOfColumns:%d %s", GREEN, numOfColumns, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); - + pPrint("%s numOfVgroups:%d %s", GREEN, numOfVgroups, NC); + pPrint("%s createTable:%d %s", GREEN, createTable, NC); + pPrint("%s insertData:%d %s", GREEN, insertData, NC); + pPrint("%s batchNum:%d %s", GREEN, batchNum, NC); + pPrint("%s start create table performace test %s", GREEN, NC); } From 2b6f415aa662727818dc9afd825d2ebe304153cc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 01:22:46 -0800 Subject: [PATCH 12/86] remove invalid tests --- tests/test/c/cacheTest.c | 146 ---------- tests/test/c/createTablePerformance.c | 225 ---------------- tests/test/c/hashIterator.c | 72 ----- tests/test/c/hashPerformance.c | 166 ------------ tests/test/c/httpTest.c | 48 ---- tests/test/c/importOneRow.c | 182 ------------- tests/test/c/importPerTable.c | 356 ------------------------- tests/test/c/insertPerRow.c | 366 -------------------------- tests/test/c/insertPerTable.c | 357 ------------------------- tests/test/c/invalidTableId.c | 220 ---------------- tests/test/c/queryPerformance.c | 183 ------------- 11 files changed, 2321 deletions(-) delete mode 100644 tests/test/c/cacheTest.c delete mode 100644 tests/test/c/createTablePerformance.c delete mode 100644 tests/test/c/hashIterator.c delete mode 100644 tests/test/c/hashPerformance.c delete mode 100644 tests/test/c/httpTest.c delete mode 100644 tests/test/c/importOneRow.c delete mode 100644 tests/test/c/importPerTable.c delete mode 100644 tests/test/c/insertPerRow.c delete mode 100644 tests/test/c/insertPerTable.c delete mode 100644 tests/test/c/invalidTableId.c delete mode 100644 tests/test/c/queryPerformance.c diff --git a/tests/test/c/cacheTest.c b/tests/test/c/cacheTest.c deleted file mode 100644 index ce5d7d1421..0000000000 --- a/tests/test/c/cacheTest.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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 -#include "../../../include/client/taos.h" -#include "os.h" -#include "tcache.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_REFRESH_TIME_SEC 2 -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -int32_t tsKeepTimeInSec = 3; -int32_t tsNumOfRows = 1000000; -int32_t tsSizeOfRow = 64 * 1024; -void * tsCacheObj = NULL; -int32_t destroyTimes = 0; - -typedef int64_t CacheTestKey; -typedef struct CacheTestRow { - int32_t index; - void ** ppRow; - void * data; -} CacheTestRow; - -CacheTestRow *initRow(int32_t index) { - CacheTestRow *row = calloc(sizeof(CacheTestRow), 1); - row->index = index; - row->data = malloc(tsSizeOfRow * sizeof(int8_t)); - return row; -} - -void detroyRow(void *data) { - CacheTestRow *row = *(CacheTestRow **)data; - free(row->data); - free(row); - destroyTimes++; - if (destroyTimes % 50000 == 0) { - pPrint("%s ===> destroyTimes:%d %s", GREEN, destroyTimes, NC); - } -} - -void initCache() { - tsCacheObj = taosCacheInit(TSDB_DATA_TYPE_BIGINT, MAX_REFRESH_TIME_SEC, true, detroyRow, "cachetest"); -} - -void putRowInCache() { - for (int index = 0; index < tsNumOfRows; ++index) { - CacheTestRow *row = initRow(index); - uint64_t key = (uint64_t)row; - void **ppRow = taosCachePut(tsCacheObj, &key, sizeof(int64_t), &row, sizeof(int64_t), tsKeepTimeInSec * 1000); - row->ppRow = ppRow; - taosCacheRelease(tsCacheObj, (void **)&ppRow, false); - } -} - -void cleanupCache() { - taosCacheCleanup(tsCacheObj); -} - -void initGetMemory() { - osInit(); - taos_init(); -} - -float getProcMemory() { - float procMemoryUsedMB = 0; - taosGetProcMemory(&procMemoryUsedMB); - return procMemoryUsedMB; -} - -void doTest() { - initCache(); - pPrint("%s initialize procMemory %f MB %s", GREEN, getProcMemory(), NC); - - putRowInCache(); - pPrint("%s insert %d rows, procMemory %f MB %s", GREEN, tsNumOfRows, getProcMemory(), NC); - - int32_t sleepMs = (MAX_REFRESH_TIME_SEC * 3) * 1000 + tsKeepTimeInSec * 1000; - taosMsleep(sleepMs); - pPrint("%s after sleep %d ms, procMemory %f MB %s", GREEN, sleepMs, getProcMemory(), NC); - - cleanupCache(); - taosMsleep(sleepMs); - pPrint("%s after cleanup cache, procMemory %f MB %s", GREEN, getProcMemory(), NC); - - malloc_trim(0); - taosMsleep(sleepMs); - pPrint("%s after malloc_trim, procMemory %f MB %s", GREEN, getProcMemory(), NC); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of cache\n"); - - printf("%s%s\n", indent, "-k"); - printf("%s%s%s%d\n", indent, indent, "KeepTimeInSec, default is ", tsKeepTimeInSec); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%d\n", indent, indent, "NumOfRows, default is ", tsNumOfRows); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%d\n", indent, indent, "SizeOfData, default is ", tsSizeOfRow); - - exit(EXIT_SUCCESS); -} - -void parseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-k") == 0) { - tsKeepTimeInSec = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - tsNumOfRows = atoi(argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - tsSizeOfRow = atoi(argv[++i]); - } else { - } - } - - pPrint("%s KeepTimeInSec:%d %s", GREEN, tsKeepTimeInSec, NC); - pPrint("%s NumOfRows:%d %s", GREEN, tsNumOfRows, NC); - pPrint("%s SizeOfData:%d %s", GREEN, tsSizeOfRow, NC); -} - -int main(int argc, char *argv[]) { - initGetMemory(); - parseArgument(argc, argv); - doTest(); -} diff --git a/tests/test/c/createTablePerformance.c b/tests/test/c/createTablePerformance.c deleted file mode 100644 index 1a59657f1a..0000000000 --- a/tests/test/c/createTablePerformance.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t numOfThreads = 30; -int32_t numOfTables = 100000; -int32_t replica = 1; -int32_t numOfColumns = 2; -TAOS * con = NULL; - -typedef struct { - int32_t tableBeginIndex; - int32_t tableEndIndex; - int32_t threadIndex; - char dbName[32]; - char stableName[64]; - float createTableSpeed; - pthread_t thread; -} SThreadInfo; - -void shellParseArgument(int argc, char *argv[]); -void *threadFunc(void *param); -void createDbAndSTable(); - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - createDbAndSTable(); - - pPrint("%d threads are spawned to create table", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SThreadInfo *pInfo = (SThreadInfo *)calloc(numOfThreads, sizeof(SThreadInfo)); - - int32_t numOfTablesPerThread = numOfTables / numOfThreads; - numOfTables = numOfTablesPerThread * numOfThreads; - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - pPrint("%s total speed:%.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); - - pthread_attr_destroy(&thattr); - free(pInfo); - taos_close(con); -} - -void createDbAndSTable() { - pPrint("start to create db and stable"); - char qstr[64000]; - - con = taos_connect(NULL, "root", "taosdata", NULL, 0); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s replica %d", dbName, replica); - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int32_t f = 0; f < numOfColumns - 1; ++f) { - len += sprintf(qstr + len, ", f%d double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); -} - -void *threadFunc(void *param) { - SThreadInfo *pInfo = (SThreadInfo *)param; - char qstr[65000]; - int code; - - sprintf(qstr, "use %s", pInfo->dbName); - TAOS_RES *pSql = taos_query(con, qstr); - taos_free_result(pSql); - - int64_t startMs = taosGetTimestampMs(); - - for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table if not exists %s%d using %s tags(%d)", stableName, t, stableName, t); - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); - } - taos_free_result(pSql); - } - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - int64_t endMs = taosGetTimestampMs(); - int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - float seconds = (endMs - startMs) / 1000.0; - float speed = totalTables / seconds; - pInfo->createTableSpeed = speed; - - pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); - - return 0; -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance while create table\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%d\n", indent, indent, "numOfTables, default is ", numOfTables); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "replica, default is ", replica); - printf("%s%s\n", indent, "-columns"); - printf("%s%s%s%d\n", indent, indent, "numOfColumns, default is ", numOfColumns); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-columns") == 0) { - numOfColumns = atoi(argv[++i]); - } else { - } - } - - pPrint("%s dbName:%s %s", GREEN, dbName, NC); - pPrint("%s stableName:%s %s", GREEN, stableName, NC); - pPrint("%s configDir:%s %s", GREEN, configDir, NC); - pPrint("%s numOfTables:%d %s", GREEN, numOfTables, NC); - pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s numOfColumns:%d %s", GREEN, numOfColumns, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); - - pPrint("%s start create table performace test %s", GREEN, NC); -} diff --git a/tests/test/c/hashIterator.c b/tests/test/c/hashIterator.c deleted file mode 100644 index 0d3dbb64d7..0000000000 --- a/tests/test/c/hashIterator.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "tulog.h" -#include "tutil.h" - -typedef struct HashTestRow { - int32_t keySize; - char key[100]; -} HashTestRow; - -int main(int argc, char *argv[]) { - _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); - void * hashHandle = taosHashInit(100, hashFp, true, HASH_ENTRY_LOCK); - - pPrint("insert 3 rows to hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow row = {0}; - row.keySize = sprintf(row.key, "0.db.st%d", t); - - taosHashPut(hashHandle, row.key, row.keySize, &row, sizeof(HashTestRow)); - } - - pPrint("start iterator"); - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - pPrint("drop key:%s", row->key); - taosHashRemove(hashHandle, row->key, row->keySize); - - pPrint("get rows from hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow r = {0}; - r.keySize = sprintf(r.key, "0.db.st%d", t); - - void *result = taosHashGet(hashHandle, r.key, r.keySize); - pPrint("get key:%s result:%p", r.key, result); - } - - //Before getting the next iterator, the object just deleted can be obtained - row = taosHashIterate(hashHandle, row); - } - - pPrint("stop iterator"); - taosHashCancelIterate(hashHandle, row); - - pPrint("get rows from hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow r = {0}; - r.keySize = sprintf(r.key, "0.db.st%d", t); - - void *result = taosHashGet(hashHandle, r.key, r.keySize); - pPrint("get key:%s result:%p", r.key, result); - } - - return 0; -} \ No newline at end of file diff --git a/tests/test/c/hashPerformance.c b/tests/test/c/hashPerformance.c deleted file mode 100644 index 0f14fbff6a..0000000000 --- a/tests/test/c/hashPerformance.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -int32_t capacity = 128; -int32_t q1Times = 10; -int32_t q2Times = 10; -int32_t keyNum = 100000; -int32_t printInterval = 1000; -void * hashHandle; -pthread_t thread; - -typedef struct HashTestRow { - int32_t keySize; - char key[100]; -} HashTestRow; - -void shellParseArgument(int argc, char *argv[]); - -void testHashPerformance() { - int64_t initialMs = taosGetTimestampMs(); - _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); - hashHandle = taosHashInit(128, hashFp, true, HASH_NO_LOCK); - - int64_t startMs = taosGetTimestampMs(); - float seconds = (startMs - initialMs) / 1000.0; - pPrint("initial time %.2f sec", seconds); - - for (int32_t t = 1; t <= keyNum; ++t) { - HashTestRow row = {0}; - row.keySize = sprintf(row.key, "0.db.st%d", t); - - for (int32_t q = 0; q < q1Times; q++) { - taosHashGet(hashHandle, row.key, row.keySize); - } - - taosHashPut(hashHandle, row.key, row.keySize, &row, sizeof(HashTestRow)); - - for (int32_t q = 0; q < q2Times; q++) { - taosHashGet(hashHandle, row.key, row.keySize); - } - - // test iterator - { - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - taosHashGet(hashHandle, row->key, row->keySize); - row = taosHashIterate(hashHandle, row); - } - } - - if (t % printInterval == 0) { - int64_t endMs = taosGetTimestampMs(); - int64_t hashSize = taosHashGetSize(hashHandle); - float seconds = (endMs - startMs) / 1000.0; - float speed = printInterval / seconds; - pPrint("time:%.2f sec, speed:%.1f rows/second, hashSize:%ld", seconds, speed, hashSize); - startMs = endMs; - } - } - - int64_t endMs = taosGetTimestampMs(); - int64_t hashSize = taosHashGetSize(hashHandle); - seconds = (endMs - initialMs) / 1000.0; - float speed = hashSize / seconds; - - pPrint("total time:%.2f sec, avg speed:%.1f rows/second, hashSize:%ld", seconds, speed, hashSize); - taosHashCleanup(hashHandle); -} - -void *multiThreadFunc(void *param) { - for (int i = 0; i < 100; ++i) { - taosMsleep(1000); - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - taosHashGet(hashHandle, row->key, row->keySize); - row = taosHashIterate(hashHandle, row); - } - int64_t hashSize = taosHashGetSize(hashHandle); - pPrint("i:%d hashSize:%ld", i, hashSize); - } - - return NULL; -} - -void multiThreadTest() { - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - - // Start threads to write - pthread_create(&thread, &thattr, multiThreadFunc, NULL); -} - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - multiThreadTest(); - testHashPerformance(); - pthread_join(thread, NULL); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of cache\n"); - - printf("%s%s\n", indent, "-k"); - printf("%s%s%s%d\n", indent, indent, "key num, default is ", keyNum); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%d\n", indent, indent, "print interval while put into hash, default is ", printInterval); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%d\n", indent, indent, "the initial capacity of hash ", capacity); - printf("%s%s\n", indent, "-q1"); - printf("%s%s%s%d\n", indent, indent, "query times before put into hash", q1Times); - printf("%s%s\n", indent, "-q2"); - printf("%s%s%s%d\n", indent, indent, "query times after put into hash", q2Times); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-k") == 0) { - keyNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - printInterval = atoi(argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - capacity = atoi(argv[++i]); - } else if (strcmp(argv[i], "-q1") == 0) { - q1Times = atoi(argv[++i]); - } else if (strcmp(argv[i], "-q2") == 0) { - q2Times = atoi(argv[++i]); - } else { - } - } - - pPrint("%s capacity:%d %s", GREEN, capacity, NC); - pPrint("%s printInterval:%d %s", GREEN, printInterval, NC); - pPrint("%s q1Times:%d %s", GREEN, q1Times, NC); - pPrint("%s q2Times:%d %s", GREEN, q2Times, NC); - pPrint("%s keyNum:%d %s", GREEN, keyNum, NC); -} diff --git a/tests/test/c/httpTest.c b/tests/test/c/httpTest.c deleted file mode 100644 index 261546770e..0000000000 --- a/tests/test/c/httpTest.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 . - */ - -#include "os.h" -#include "os.h" -#include "tglobal.h" -#include "taoserror.h" -#include "httpSystem.h" - -void signal_handler(int signum) { - httpStopSystem(); - httpCleanUpSystem(); - exit(EXIT_SUCCESS); -} - -int main(int argc, char *argv[]) { - struct sigaction act; - act.sa_handler = signal_handler; - sigaction(SIGTERM, &act, NULL); - sigaction(SIGHUP, &act, NULL); - sigaction(SIGINT, &act, NULL); - sigaction(SIGABRT, &act, NULL); - - // Initialize the system - if (httpInitSystem() < 0) { - exit(EXIT_FAILURE); - } - - if (httpStartSystem() < 0) { - exit(EXIT_FAILURE); - } - - while (1) { - sleep(1000); - } -} diff --git a/tests/test/c/importOneRow.c b/tests/test/c/importOneRow.c deleted file mode 100644 index 510f780163..0000000000 --- a/tests/test/c/importOneRow.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -void taos_error(TAOS *taos); -void* taos_execute(void *param); - -typedef struct { - pthread_t pid; - int index; -} ThreadObj; - -int threadNum = 1; -int rowNum = 1000; -int replica = 1; - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing one row of data to all tables, write the next row\n"); - - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "Number of records to write table, default is ", rowNum); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "Number of threads to be used, default is ", threadNum); - printf("%s%s\n", indent, "-replica"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", replica); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-r") == 0) { - rowNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - threadNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-replica") == 0) { - replica = atoi(argv[++i]); - } else { - } - } - - pPrint("%s rowNum:%d %s", GREEN, rowNum, NC); - pPrint("%s threadNum:%d %s", GREEN, threadNum, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); -} - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - - taos_init(); - - ThreadObj *threads = calloc(threadNum, sizeof(ThreadObj)); - for (int i = 0; i < threadNum; ++i) { - ThreadObj * pthread = threads + i; - pthread_attr_t thattr; - pthread->index = i; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - pthread_create(&pthread->pid, &thattr, taos_execute, pthread); - } - - for (int i = 0; i < threadNum; i++) { - pthread_join(threads[i].pid, NULL); - } - - printf("all finished\n"); - - return 0; -} - -void taos_error(TAOS *con) { - fprintf(stderr, "TDengine error: %s\n", taos_errstr(con)); - taos_close(con); - exit(1); -} - -void* taos_execute(void *param) { - ThreadObj *pThread = (ThreadObj *)param; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - void *taos = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (taos == NULL) taos_error(taos); - - char sql[1024] = {0}; - sprintf(sql, "create database if not exists db replica %d", replica); - taos_query(taos, sql); - - sprintf(sql, "create table if not exists db.t%d (ts timestamp, i int, j float, k double)", pThread->index); - taos_query(taos, sql); - - int64_t timestamp = 1530374400000L; - - sprintf(sql, "insert into db.t%d values(%ld, %d, %d, %d)", pThread->index, timestamp, 0, 0, 0); - TAOS_RES *pSql = taos_query(taos, sql); - int code = taos_errno(pSql); - if (code != 0) - { - printf("error code:%d, sql:%s\n", code, sql); - taos_free_result(pSql); - taos_close(taos); - return NULL; - } - int affectrows = taos_affected_rows(taos); - if (affectrows != 1) - { - printf("affect rows:%d, sql:%s\n", affectrows, sql); - taos_free_result(pSql); - taos_close(taos); - return NULL; - } - taos_free_result(pSql); - pSql = NULL; - - - timestamp -= 1000; - - int total_affect_rows = affectrows; - - for (int i = 1; i < rowNum; ++i) { - sprintf(sql, "import into db.t%d values(%ld, %d, %d, %d)", pThread->index, timestamp, i, i, i); - - pSql = taos_query(taos, sql); - code = taos_errno(pSql); - if (code != 0) - { - printf("error code:%d, sql:%s\n", code, sql); - taos_free_result(pSql); - pSql = NULL; - taos_close(taos); - return NULL; - } - int affectrows = taos_affected_rows(taos); - if (affectrows != 1) { - printf("affect rows:%d, sql:%s\n", affectrows, sql); - taos_free_result(pSql); - pSql = NULL; - taos_close(taos); - } - - total_affect_rows += affectrows; - taos_free_result(pSql); - pSql = NULL; - - timestamp -= 1000; - } - - printf("thread:%d run finished total_affect_rows:%d\n", pThread->index, total_affect_rows); - taos_close(taos); - - return NULL; -} diff --git a/tests/test/c/importPerTable.c b/tests/test/c/importPerTable.c deleted file mode 100644 index 7aef676c97..0000000000 --- a/tests/test/c/importPerTable.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "os.h" -#include "osTime.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 1000000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 10; -int64_t numOfTablesPerThread = 100; -char dbName[32] = "db"; -char stableName[64] = "st"; -int64_t totalUs = 0; -int64_t reqNum = 0; -int64_t maxUs = 0; -int64_t minUs = 100000000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); - int64_t avgUs = totalUs / reqNum; - pError("%s totalUs:%ld, avgUs:%ld maxUs:%ld minUs:%ld reqNum:%ld %s\n", GREEN, totalUs, avgUs, maxUs, minUs, reqNum, NC); -} - -int32_t query(void *con, char *qstr) { - int64_t begin = taosGetTimestampUs(); - - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to exec sql:%s, code:%d reason:%s", qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - int64_t us = taosGetTimestampUs() - begin; - maxUs = MAX(us, maxUs); - minUs = MIN(us, minUs); - atomic_add_fetch_64(&totalUs, us); - atomic_add_fetch_64(&reqNum, 1); - if (reqNum > 100000) { - int64_t avgUs = totalUs / reqNum; - if (us > avgUs * 100) { - pError("sql:%s", qstr); - pError("%s totalUs:%ld, avgUs:%ld maxUs:%ld minUs:%ld reqNum:%ld %s\n", GREEN, totalUs, avgUs, maxUs, minUs, - reqNum, NC); - taosMsleep(1000); - exit(0); - } - } - - return code; -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS * con; - struct timeval systemTime; - int64_t st, et; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s", dbName); - if (query(con, qstr)) { - pError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); - exit(0); - } - - sprintf(qstr, "use %s", dbName); - if (query(con, qstr)) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = numOfTablesPerThread * numOfThreads; - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - if (query(con, qstr)) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - - for (int64_t t = 0; t < totalTables; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - if (query(con, qstr)) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - } - } else { - for (int64_t t = 0; t < totalTables; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - if (query(con, qstr)) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - pPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pPrint("%" PRId64 " threads are spawned to import data", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf%s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1587225600000; - int64_t interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "import into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - len += sprintf(sql + len, "(%ld", start - row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - if (query(con, qstr)) { - pError("thread:%d, failed to import table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - - // "insert into" - len = sprintf(sql, "%s", inserStr); - - // "insert into st1 values" - if (row != pInfo->rowsPerTable - 1) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - } - } - } - } - - if (len != strlen(inserStr)) { - query(con, qstr); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, import finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing all the data in one table, start the next table\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/insertPerRow.c b/tests/test/c/insertPerRow.c deleted file mode 100644 index bdf27180b2..0000000000 --- a/tests/test/c/insertPerRow.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - float createTableSpeed; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 1000000000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 10; -int64_t numOfTablesPerThread = 100; -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t cache = 1; -int32_t replica = 3; -int32_t days = 10; -int32_t interval = 1000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS_RES * pSql; - TAOS * con; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s cache %d replica %d days %d", dbName, cache, replica, days); - pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pPrint("%" PRId64 " threads are spawned to insert data", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)calloc(numOfThreads, sizeof(SInfo)); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf CreateTableSpeed:%.1f t/s %s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, createTableSpeed, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - int code; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - taos_query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - if (strcmp(stableName, "no") != 0) { - for (int64_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } else { - for (int64_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - float seconds = (et - st) / 1000.0 / 1000.0; - int64_t tables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - pInfo->createTableSpeed = (float)tables / seconds; - pPrint("thread:%d, %.1f seconds to create %ld tables, speed:%.1f", pInfo->threadIndex, seconds, tables, - pInfo->createTableSpeed); - - if (pInfo->rowsPerTable == 0) return NULL; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1430000000000; - interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "insert into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - len += sprintf(sql + len, "(%ld", start + row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - taos_free_result(pSql); - - // "insert into" - len = sprintf(sql, "%s", inserStr); - } - } - } - - if (len != strlen(inserStr)) { - TAOS_RES *pSql = taos_query(con, qstr); - taos_free_result(pSql); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing one row of data to all tables, write the next row\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - printf("%s%s\n", indent, "-replica"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", replica); - printf("%s%s\n", indent, "-cache"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", cache); - printf("%s%s\n", indent, "-days"); - printf("%s%s%s%d\n", indent, indent, "Database parameters days, default is ", days); - printf("%s%s\n", indent, "-interval"); - printf("%s%s%s%d\n", indent, indent, "Interval of each rows in ms, default is ", interval); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-replica") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-cache") == 0) { - cache = atoi(argv[++i]); - } else if (strcmp(argv[i], "-days") == 0) { - days = atoi(argv[++i]); - } else if (strcmp(argv[i], "-interval") == 0) { - interval = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%scache:%" PRId32 "%s", GREEN, cache, NC); - pPrint("%stables:%" PRId32 "%s", GREEN, replica, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/insertPerTable.c b/tests/test/c/insertPerTable.c deleted file mode 100644 index ac3c06f0f3..0000000000 --- a/tests/test/c/insertPerTable.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 10000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 1; -int64_t numOfTablesPerThread = 1; -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t cache = 16; -int32_t tables = 5000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS_RES * pSql; - TAOS * con; - struct timeval systemTime; - int64_t st, et; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s cache %d maxtables %d", dbName, cache, tables); - pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = numOfTablesPerThread * numOfThreads; - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - for (int64_t t = 0; t < totalTables; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } else { - for (int64_t t = 0; t < totalTables; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - float seconds = (et - st) / 1000.0 / 1000.0; - pPrint("%.1f seconds to create %ld tables, speed:%.1f", seconds, totalTables, totalTables / seconds); - taos_close(con); -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - if (rowsPerTable <= 0) { - pPrint("not insert data for rowsPerTable is :%" PRId64, rowsPerTable); - exit(0); - } else { - pPrint("%" PRId64 " threads are spawned to insert data", numOfThreads); - } - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf%s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - taos_query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1430000000000; - int64_t interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "insert into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - len += sprintf(sql + len, "(%ld", start + row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - taos_free_result(pSql); - - // "insert into" - len = sprintf(sql, "%s", inserStr); - - // "insert into st1 values" - if (row != pInfo->rowsPerTable - 1) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - } - } - } - } - - if (len != strlen(inserStr)) { - taos_query(con, qstr); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing all the data in one table, start the next table\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - printf("%s%s\n", indent, "-tables"); - printf("%s%s%s%d\n", indent, indent, "Database parameters tables, default is ", tables); - printf("%s%s\n", indent, "-cache"); - printf("%s%s%s%d\n", indent, indent, "Database parameters cache, default is ", cache); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-tables") == 0) { - tables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-cache") == 0) { - cache = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%scache:%" PRId32 "%s", GREEN, cache, NC); - pPrint("%stables:%" PRId32 "%s", GREEN, tables, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/invalidTableId.c b/tests/test/c/invalidTableId.c deleted file mode 100644 index 286d0f1291..0000000000 --- a/tests/test/c/invalidTableId.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -#define MAX_DB_NUM 100 -void * con; -char dbNames[MAX_DB_NUM][48]; -int32_t dbNum = 0; -void parseArgument(int argc, char *argv[]); -void connDb(); -void getDbNames(); -void printDbNames(); -void queryTables(char *dbName); -void checkTables(char *dbName); - -int main(int argc, char *argv[]) { - parseArgument(argc, argv); - taos_init(); - connDb(); - getDbNames(); - printDbNames(); - for (int dbIndex = 0; dbIndex < dbNum; ++dbIndex) { - queryTables((char*)(dbNames[dbIndex])); - checkTables((char*)(dbNames[dbIndex])); - } - - pPrint("all %d database is checked", dbNum); -} - -void connDb() { - con = taos_connect(NULL, "root", "taosdata", NULL, 0); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(0); - } -} - -void getDbNames() { - if (dbNum != 0) return; - - char * qstr = "show databases"; - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - exit(0); - } - - TAOS_ROW row; - int num_fields = taos_num_fields(result); - if (num_fields <= 0) return; - while ((row = taos_fetch_row(result))) { - char * dbName = (char*)dbNames[dbNum]; - int32_t *length = taos_fetch_lengths(result); - int len = length[0]; - memcpy(dbName, (char *)row[0], len); - dbName[len] = 0; - dbNum++; - } - - taos_free_result(result); -} - -void printDbNames() { - for (int dbIndex = 0; dbIndex < dbNum; ++dbIndex) { - pPrint("db:%d %s", dbIndex, dbNames[dbIndex]); - } -} - -void queryTables(char *dbName) { - char qstr[1024]; - char fileName[1024]; - char ts[35] = {0}; - int32_t precision = 1000; - - sprintf(qstr, "show %s.tables", dbName); - sprintf(fileName, "%s_tables.txt", dbName); - - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - exit(0); - } - - FILE *fp = fopen(fileName, "w"); - if (!fp) return; - - TAOS_ROW row; - int32_t rows = 0; - while ((row = taos_fetch_row(result))) { - char tableName[256] = {0}; - int32_t *length = taos_fetch_lengths(result); - int len = length[0]; - memcpy(tableName, (char *)row[0], len); - tableName[len] = 0; - - int64_t t = *((int64_t *)row[1]); - time_t tt = t / 1000; - struct tm *ptm = localtime(&tt); - int32_t tl = (int32_t)strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm); - snprintf(ts + tl, 5, ".%03ld", t % precision); - - // fprintf(fp, "%s %s\n", tableName, ts); - fprintf(fp, "%s.%s\n", dbName, tableName); - rows++; - } - - taos_free_result(result); - fclose(fp); - pPrint("db:%s has %d tables, write to %s", dbName, rows, fileName); -} - -void checkTables(char *dbName) { - char qstr[1024]; - char fileName1[1024]; - char fileName2[1024]; - - sprintf(qstr, "show %s.tables", dbName); - sprintf(fileName1, "%s_tables.txt", dbName); - sprintf(fileName2, "%s_count.txt", dbName); - - FILE *fp1 = fopen(fileName1, "r"); - if (!fp1) return; - - FILE *fp2 = fopen(fileName2, "w"); - if (!fp2) return; - - int32_t successRows = 0; - int32_t failedRows = 0; - char tbName[256]; - while (!feof(fp1)) { - int size = fscanf(fp1, "%s", tbName); - if (size <= 0) { - break; - } - - sprintf(qstr, "select count(*) from %s", tbName); - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - fprintf(fp2, "%s failed to exec sql:%s, code:0x%x reason:%s", tbName, qstr, code & 0XFFFF, tstrerror(code)); - taos_free_result(result); - failedRows++; - continue; - } - - TAOS_ROW row; - int64_t count = 0; - while ((row = taos_fetch_row(result))) { - count = *((int64_t *)row[0]); - } - fprintf(fp2, "%s %" PRId64 "\n", tbName, count); - - successRows++; - if (successRows % 1000 == 0) { - pPrint("query %d tables", successRows); - } - taos_free_result(result); - } - - fclose(fp1); - fclose(fp2); - pPrint("db:%s query tables, success:%d failed:%d write to %s", dbName, successRows, failedRows, fileName2); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to checkTables\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be checked, default is ", "all"); - - exit(EXIT_SUCCESS); -} - -void parseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbNames[0], argv[++i]); - dbNum++; - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else { - } - } - - pPrint("%s configDir:%s %s", GREEN, configDir, NC); - pPrint("%s start to checkTables %s", GREEN, NC); -} diff --git a/tests/test/c/queryPerformance.c b/tests/test/c/queryPerformance.c deleted file mode 100644 index afe5cd0ccb..0000000000 --- a/tests/test/c/queryPerformance.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t startTimeMs; - int64_t endTimeMs; - int threadIndex; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void shellParseArgument(int argc, char *argv[]); -void queryData(); - -int numOfThreads = 10; -int useGlobalConn = 1; -int requestPerThread = 10000; -char requestSql[10240] = "show dnodes"; -TAOS *globalConn; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - queryData(); -} - -void queryData() { - struct timeval systemTime; - int64_t st, et; - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - if (useGlobalConn) { - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - globalConn = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (globalConn == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(globalConn)); - exit(1); - } - } - - pPrint("%d threads are spawned to query", numOfThreads); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].threadIndex = i; - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double totalTimeMs = (et - st) / 1000.0; - - int totalReq = requestPerThread * numOfThreads; - float rspTime = totalTimeMs / requestPerThread; - float qps = totalReq / (totalTimeMs / 1000); - - pPrint("%s threads:%d, totalTime %.1fms totalReq:%d qps:%.1f rspTime:%.3fms %s", GREEN, numOfThreads, totalTimeMs, - totalReq, qps, rspTime, NC); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - if (useGlobalConn) { - pPrint("thread:%d, start to run use global connection", pInfo->threadIndex); - con = globalConn; - } else { - pPrint("thread:%d, start to run, and create new conn", pInfo->threadIndex); - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - } - - for (int i = 0; i < requestPerThread; ++i) { - void *tres = taos_query(con, requestSql); - - TAOS_ROW row = taos_fetch_row(tres); - if (row == NULL) { - taos_free_result(tres); - exit(0); - } - - do { - row = taos_fetch_row(tres); - } while (row != NULL); - - taos_free_result(tres); - } - return NULL; -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the query performance of TDengine\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The sql to be executed, default is ", requestSql); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "Request per thread, default is ", requestPerThread); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-g"); - printf("%s%s%s%d\n", indent, indent, "Whether to share connections between threads, default is ", useGlobalConn); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(requestSql, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - requestPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-g") == 0) { - useGlobalConn = atoi(argv[++i]); - } else { - } - } - - pPrint("%s sql:%s %s", GREEN, requestSql, NC); - pPrint("%s requestPerThread:%d %s", GREEN, requestPerThread, NC); - pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s useGlobalConn:%d %s", GREEN, useGlobalConn, NC); - pPrint("%s start to run %s", GREEN, NC); -} From 5bc490d2aeb67ffdbbad5d668f9b8dc07c9cb461 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 31 Dec 2021 04:30:37 -0500 Subject: [PATCH 13/86] TD-12506 SSubplan struct modify --- include/libs/planner/planner.h | 3 ++- include/libs/qcom/query.h | 7 +++++++ include/libs/scheduler/scheduler.h | 7 ------- source/libs/planner/src/physicalPlan.c | 24 ++++++++++++------------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 3ca923b0aa..f1a9447e9c 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -20,6 +20,7 @@ extern "C" { #endif +#include "query.h" #include "tmsg.h" #include "tarray.h" @@ -122,7 +123,7 @@ typedef struct SSubplan { SSubplanId id; // unique id of the subplan int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY int32_t level; // the execution level of current subplan, starting from 0. - SEpSet execEpSet; // for the scan/modify subplan, the optional execution node + SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node SArray *pChildern; // the datasource subplan,from which to fetch the result SArray *pParents; // the data destination subplan, get data from current subplan SPhyNode *pNode; // physical plan of current subplan diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 4d5b1a8bd3..4bfb774435 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -111,6 +111,13 @@ typedef struct SMsgSendInfo { SDataBuf msgInfo; } SMsgSendInfo; +typedef struct SQueryNodeAddr{ + int32_t nodeId; //vgId or qnodeId + int8_t inUse; + int8_t numOfEps; + SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; +} SQueryNodeAddr; + bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); int32_t initTaskQueue(); diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index d6cac976d4..b2ba7acebf 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -50,13 +50,6 @@ typedef struct SQueryProfileSummary { uint64_t resultSize; // generated result size in Kb. } SQueryProfileSummary; -typedef struct SQueryNodeAddr{ - int32_t nodeId; //vgId or qnodeId - int8_t inUse; - int8_t numOfEps; - SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; -} SQueryNodeAddr; - typedef struct SQueryResult { int32_t code; uint64_t numOfRows; diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 97c9cec7c7..22a1beaa35 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -211,22 +211,22 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { return subplan; } -static void vgroupInfoToEpSet(const SVgroupInfo* vg, SEpSet* epSet) { - epSet->inUse = 0; // todo - epSet->numOfEps = vg->numOfEps; +static void vgroupInfoToEpSet(const SVgroupInfo* vg, SQueryNodeAddr* execNode) { + execNode->nodeId = vg->vgId; + execNode->inUse = 0; // todo + execNode->numOfEps = vg->numOfEps; for (int8_t i = 0; i < vg->numOfEps; ++i) { - epSet->port[i] = vg->epAddr[i].port; - strcpy(epSet->fqdn[i], vg->epAddr[i].fqdn); + execNode->epAddr[i] = vg->epAddr[i]; } return; } -static void vgroupMsgToEpSet(const SVgroupMsg* vg, SEpSet* epSet) { - epSet->inUse = 0; // todo - epSet->numOfEps = vg->numOfEps; +static void vgroupMsgToEpSet(const SVgroupMsg* vg, SQueryNodeAddr* execNode) { + execNode->nodeId = vg->vgId; + execNode->inUse = 0; // todo + execNode->numOfEps = vg->numOfEps; for (int8_t i = 0; i < vg->numOfEps; ++i) { - epSet->port[i] = vg->epAddr[i].port; - strcpy(epSet->fqdn[i], vg->epAddr[i].fqdn); + execNode->epAddr[i] = vg->epAddr[i]; } return; } @@ -236,7 +236,7 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod for (int32_t i = 0; i < pTable->pMeta->vgroupList->numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_SCAN); - vgroupMsgToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execEpSet); + vgroupMsgToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execNode); subplan->pNode = createMultiTableScanNode(pPlanNode, pTable); subplan->pDataSink = createDataDispatcher(pCxt, pPlanNode); RECOVERY_CURRENT_SUBPLAN(pCxt); @@ -297,7 +297,7 @@ static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); - vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); + vgroupInfoToEpSet(&blocks->vg, &subplan->execNode); subplan->pNode = NULL; subplan->pDataSink = createDataInserter(pCxt, blocks); subplan->type = QUERY_TYPE_MODIFY; From 65acb7dfe2c3906a0ee42cdbef0f2e76f3db9bf4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 01:34:13 -0800 Subject: [PATCH 14/86] test for create table --- tests/test/c/create_table.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test/c/create_table.c b/tests/test/c/create_table.c index dca7b1159c..96c7f87392 100644 --- a/tests/test/c/create_table.c +++ b/tests/test/c/create_table.c @@ -30,7 +30,7 @@ char dbName[32] = "db"; char stbName[64] = "st"; int32_t numOfThreads = 2; -int32_t numOfTables = 100; +int32_t numOfTables = 10000; int32_t createTable = 1; int32_t insertData = 0; int32_t batchNum = 1; @@ -123,6 +123,15 @@ void createDbAndStb() { } taos_free_result(pSql); + sprintf(qstr, "create table %s (ts timestamp, i int) tags (j int)", stbName); + pSql = taos_query(con, qstr); + code = taos_errno(pSql); + if (code != 0) { + pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + exit(0); + } + taos_free_result(pSql); + taos_close(con); } @@ -144,11 +153,11 @@ void *threadFunc(void *param) { if (createTable) { int64_t startMs = taosGetTimestampMs(); for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table %s%d (ts timestamp, i int)", stbName, t); + sprintf(qstr, "create table t%d using %s tags(%d)", t, stbName, t); TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); if (code != 0) { - pError("failed to create table %s%d, reason:%s", stbName, t, tstrerror(code)); + pError("failed to create table t%d, reason:%s", t, tstrerror(code)); } taos_free_result(pSql); } From 97df31ebad2192258ac8b3fce15b1927bed1b314 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 02:40:49 -0800 Subject: [PATCH 15/86] unitest for create user --- include/common/tmsg.h | 55 ++++---- source/dnode/mgmt/impl/src/dndTransport.c | 2 +- source/dnode/mgmt/impl/test/user/user.cpp | 149 +++++++++++++++++++++- 3 files changed, 172 insertions(+), 34 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 17a4d4ad2c..479fd3c4e8 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -354,9 +354,9 @@ typedef struct SEpSet { } SEpSet; static FORCE_INLINE int taosEncodeSEpSet(void** buf, const SEpSet* pEp) { - if(buf == NULL) return sizeof(SEpSet); + if (buf == NULL) return sizeof(SEpSet); memcpy(buf, pEp, sizeof(SEpSet)); - //TODO: endian conversion + // TODO: endian conversion return sizeof(SEpSet); } @@ -370,7 +370,7 @@ typedef struct { int64_t clusterId; int32_t connId; int8_t superUser; - int8_t reserved[5]; + int8_t align[3]; SEpSet epSet; } SConnectRsp; @@ -383,20 +383,17 @@ typedef struct { int32_t maxStreams; int32_t accessState; // Configured only by command int64_t maxStorage; // In unit of GB - int32_t reserve[8]; } SCreateAcctMsg, SAlterAcctMsg; typedef struct { - char user[TSDB_USER_LEN]; - int32_t reserve[8]; + char user[TSDB_USER_LEN]; } SDropUserMsg, SDropAcctMsg; 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 - int32_t reserve[8]; + int8_t type; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + int8_t superUser; // denote if it is a super user or not } SCreateUserMsg, SAlterUserMsg; typedef struct { @@ -585,7 +582,6 @@ typedef struct { int8_t update; int8_t cacheLastRow; int8_t ignoreExist; - int32_t reserve[8]; } SCreateDbMsg; typedef struct { @@ -598,29 +594,24 @@ typedef struct { int8_t walLevel; int8_t quorum; int8_t cacheLastRow; - int32_t reserve[8]; } SAlterDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int8_t ignoreNotExists; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; + int8_t ignoreNotExists; } SDropDbMsg; typedef struct { char db[TSDB_TABLE_FNAME_LEN]; int32_t vgVersion; - int32_t reserve[8]; } SUseDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SSyncDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SCompactDbMsg; typedef struct { @@ -676,7 +667,7 @@ typedef struct { typedef struct { int32_t vgId; int8_t role; - int8_t reserved[3]; + int8_t align[3]; int64_t totalStorage; int64_t compStorage; int64_t pointsWritten; @@ -713,7 +704,7 @@ typedef struct { typedef struct { int32_t id; int8_t isMnode; - int8_t reserved; + int8_t align; uint16_t port; char fqdn[TSDB_FQDN_LEN]; } SDnodeEp; @@ -947,7 +938,7 @@ typedef struct { int32_t totalDnodes; int32_t onlineDnodes; int8_t killConnection; - int8_t reserved[3]; + int8_t align[3]; SEpSet epSet; } SHeartBeatRsp; @@ -975,7 +966,7 @@ typedef struct { typedef struct { int8_t finished; - int8_t reserved1[7]; + int8_t align[7]; char name[TSDB_STEP_NAME_LEN]; char desc[TSDB_STEP_DESC_LEN]; } SStartupMsg; @@ -1118,10 +1109,10 @@ typedef struct STaskDropRsp { } STaskDropRsp; typedef struct { - int8_t igExists; - char* name; - char* physicalPlan; - char* logicalPlan; + int8_t igExists; + char* name; + char* physicalPlan; + char* logicalPlan; } SCMCreateTopicReq; static FORCE_INLINE int tSerializeSCMCreateTopicReq(void** buf, const SCMCreateTopicReq* pReq) { @@ -1157,8 +1148,8 @@ static FORCE_INLINE void* tDeserializeSCMCreateTopicRsp(void* buf, SCMCreateTopi } typedef struct { - char* topicName; - char* consumerGroup; + char* topicName; + char* consumerGroup; int64_t consumerId; } SCMSubscribeReq; @@ -1179,7 +1170,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq typedef struct { int32_t vgId; - SEpSet pEpSet; + SEpSet pEpSet; } SCMSubscribeRsp; static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) { diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index e5be16937b..eaa611e6c8 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -160,8 +160,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { + dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); (*fp)(pDnode, pMsg, pEpSet); - 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, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp index aa160304c8..aecce0bdc9 100644 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ b/source/dnode/mgmt/impl/test/user/user.cpp @@ -43,6 +43,153 @@ TEST_F(DndTestUser, 01_ShowUser) { CheckBinary("root", TSDB_USER_LEN); } +TEST_F(DndTestUser, 02_Create_User) { + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "root"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_ALREADY_EXIST); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); +} + +TEST_F(DndTestUser, 03_Alter_User) { + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} + +TEST_F(DndTestUser, 04_Drop_User) { + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); +} + TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserMsg); @@ -161,4 +308,4 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { CheckTimestamp(); CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); -} +} \ No newline at end of file From d74b91afb94776f90db99feff8cb13d9f347a7f7 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 19:31:35 +0800 Subject: [PATCH 16/86] feature/qnode --- include/common/tmsg.h | 3 + source/libs/scheduler/inc/schedulerInt.h | 24 +++---- source/libs/scheduler/src/scheduler.c | 79 ++++++++++++++++++------ 3 files changed, 77 insertions(+), 29 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 10aba94656..7f3a73f96e 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1090,6 +1090,7 @@ typedef struct SResFetchMsg { } SResFetchMsg; typedef struct SSchTasksStatusMsg { + SMsgHead header; uint64_t sId; } SSchTasksStatusMsg; @@ -1105,6 +1106,7 @@ typedef struct SSchedulerStatusRsp { } SSchedulerStatusRsp; typedef struct STaskCancelMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; @@ -1115,6 +1117,7 @@ typedef struct STaskCancelRsp { } STaskCancelRsp; typedef struct STaskDropMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 2770f7e21a..fa4ae0d152 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -60,17 +60,19 @@ typedef struct SSchLevel { typedef struct SSchTask { - uint64_t taskId; // task id - SSchLevel *level; // level - SSubplan *plan; // subplan - char *msg; // operator tree - int32_t msgLen; // msg length - int8_t status; // task status - SEpAddr execAddr; // task actual executed node address - SQueryProfileSummary summary; // task execution summary - int32_t childReady; // child task ready number - SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* - SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* + uint64_t taskId; // task id + SSchLevel *level; // level + SSubplan *plan; // subplan + char *msg; // operator tree + int32_t msgLen; // msg length + int8_t status; // task status + SQueryNodeAddr execAddr; // task actual executed node address + int8_t condidateIdx; // current try condidation index + SArray *condidateAddrs; // condidate node addresses, element is SQueryNodeAddr + SQueryProfileSummary summary; // task execution summary + int32_t childReady; // child task ready number + SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* + SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* } SSchTask; typedef struct SSchJobAttr { diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 20eb94c2ff..090c7b6fa7 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -215,28 +215,49 @@ _return: SCH_RET(code); } -int32_t schSetTaskExecEpSet(SSchJob *job, SEpSet *epSet) { - if (epSet->numOfEps >= SCH_MAX_CONDIDATE_EP_NUM) { +int32_t schSetTaskCondidateAddrs(SSchJob *job, SSchTask *task) { + if (task->condidateAddrs) { return TSDB_CODE_SUCCESS; } - int32_t nodeNum = taosArrayGetSize(job->nodeList); - - for (int32_t i = 0; i < nodeNum && epSet->numOfEps < tListLen(epSet->port); ++i) { - SEpAddr *addr = taosArrayGet(job->nodeList, i); - - strncpy(epSet->fqdn[epSet->numOfEps], addr->fqdn, sizeof(addr->fqdn)); - epSet->port[epSet->numOfEps] = addr->port; - - ++epSet->numOfEps; + task->condidateIdx = 0; + task->condidateAddrs = taosArrayInit(SCH_MAX_CONDIDATE_EP_NUM, sizeof(SQueryNodeAddr)); + if (NULL == task->condidateAddrs) { + qError("taosArrayInit failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - for (int32_t i = 0; i < job->dataSrcEps.numOfEps && epSet->numOfEps < tListLen(epSet->port); ++i) { + if (task->plan->execNode.numOfEps > 0) { + if (NULL == taosArrayPush(task->condidateAddrs, &task->plan->execNode)) { + qError("taosArrayPush failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + return TSDB_CODE_SUCCESS; + } + + int32_t addNum = 0; + int32_t nodeNum = taosArrayGetSize(job->nodeList); + + for (int32_t i = 0; i < nodeNum && addNum < SCH_MAX_CONDIDATE_EP_NUM; ++i) { + SQueryNodeAddr *naddr = taosArrayGet(job->nodeList, i); + + if (NULL == taosArrayPush(task->condidateAddrs, &task->plan->execNode)) { + qError("taosArrayPush failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + ++addNum; + } + +/* + for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CONDIDATE_EP_NUM; ++i) { strncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i])); epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i]; ++epSet->numOfEps; } +*/ return TSDB_CODE_SUCCESS; } @@ -394,12 +415,14 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { return TSDB_CODE_SUCCESS; } +/* if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CONDIDATE_EP_NUM) { strncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn)); job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port; ++job->dataSrcEps.numOfEps; } +*/ for (int32_t i = 0; i < parentNum; ++i) { SSchTask *par = *(SSchTask **)taosArrayGet(task->parents, i); @@ -633,6 +656,16 @@ _return: SCH_RET(code); } +void schConvertAddrToEpSet(SQueryNodeAddr *addr, SEpSet *epSet) { + epSet->inUse = addr->inUse; + epSet->numOfEps = addr->numOfEps; + + for (int8_t i = 0; i < epSet->numOfEps; ++i) { + strncpy(epSet->fqdn[i], addr->epAddr[i].fqdn, sizeof(addr->epAddr[i].fqdn)); + epSet->port[i] = addr->epAddr[i].port; + } +} + int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { uint32_t msgSize = 0; @@ -665,6 +698,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { SSubQueryMsg *pMsg = msg; + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -681,6 +715,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } SResReadyMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -698,6 +734,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } SResFetchMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -712,6 +750,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } STaskDropMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -723,7 +763,12 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { break; } - SCH_ERR_JRET(schAsyncSendMsg(job->transport, &task->plan->execEpSet, job->queryId, task->taskId, msgType, msg, msgSize)); + SEpSet epSet; + SQueryNodeAddr *addr = taosArrayGet(task->condidateAddrs, task->condidateIdx); + + schConvertAddrToEpSet(addr, &epSet); + + SCH_ERR_JRET(schAsyncSendMsg(job->transport, &epSet, job->queryId, task->taskId, msgType, msg, msgSize)); return TSDB_CODE_SUCCESS; @@ -737,12 +782,10 @@ _return: int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SSubplan *plan = task->plan; SCH_ERR_RET(qSubPlanToString(plan, &task->msg, &task->msgLen)); - if (plan->execEpSet.numOfEps <= 0) { - SCH_ERR_RET(schSetTaskExecEpSet(job, &plan->execEpSet)); - } + SCH_ERR_RET(schSetTaskCondidateAddrs(job, task)); - if (plan->execEpSet.numOfEps <= 0) { - SCH_TASK_ERR_LOG("invalid execEpSet num:%d", plan->execEpSet.numOfEps); + if (NULL == task->condidateAddrs || taosArrayGetSize(task->condidateAddrs) <= 0) { + SCH_TASK_ERR_LOG("no valid condidate node for task:%"PRIx64, task->taskId); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } From 5326356375a0ea7278bd3eefd63803f2d6712c3a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 2 Jan 2022 23:24:22 +0800 Subject: [PATCH 17/86] [td-11818] create multiple tables. --- include/libs/planner/planner.h | 7 +- source/client/src/clientMain.c | 4 +- source/client/test/clientTests.cpp | 6 +- source/libs/parser/inc/sql.y | 2 +- source/libs/parser/src/astGenerator.c | 2 +- source/libs/parser/src/dCDAstProcess.c | 10 +- source/libs/parser/src/sql.c | 2033 ++++++++--------- source/libs/planner/inc/plannerInt.h | 5 + source/libs/planner/src/logicPlan.c | 18 +- source/libs/planner/src/physicalPlan.c | 30 +- source/libs/planner/src/physicalPlanJson.c | 5 +- source/libs/planner/src/planner.c | 3 + source/libs/scheduler/src/scheduler.c | 26 +- source/libs/scheduler/test/schedulerTests.cpp | 10 +- 14 files changed, 1094 insertions(+), 1067 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 3ca923b0aa..5ad53703c7 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -119,11 +119,12 @@ typedef struct SSubplanId { } SSubplanId; typedef struct SSubplan { - SSubplanId id; // unique id of the subplan + SSubplanId id; // unique id of the subplan int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY - int32_t level; // the execution level of current subplan, starting from 0. + int32_t msgType; // message type for subplan, used to denote the send message type to vnode. + int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner. SEpSet execEpSet; // for the scan/modify subplan, the optional execution node - SArray *pChildern; // the datasource subplan,from which to fetch the result + SArray *pChildren; // the datasource subplan,from which to fetch the result SArray *pParents; // the data destination subplan, get data from current subplan SPhyNode *pNode; // physical plan of current subplan SDataSink *pDataSink; // data of the subplan flow into the datasink diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 894b810d7b..e7c44d9f28 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -140,7 +140,9 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { SRequestObj *pRequest = (SRequestObj *) pRes; if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS) { + pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || + taos_num_fields(pRes) == 0) { return NULL; } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 7a87acfc36..a3116fecea 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -279,7 +279,7 @@ TEST(testCase, connect_Test) { // taos_free_result(pRes); // taos_close(pConn); //} -// + //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // // assert(pConn != NULL); @@ -470,9 +470,9 @@ TEST(testCase, create_multiple_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 789f5a98e2..c6e1c004e3 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -392,7 +392,7 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { %type create_stable_args{SCreateTableSql*} create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. { A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); + setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_STABLE); V.n += Z.n; setCreatedTableName(pInfo, &V, &U); diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 9122b0df96..3f45012405 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -785,7 +785,7 @@ void destroySqlInfo(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->funcs); if (pInfo->type == TSDB_SQL_SELECT) { destroyAllSqlNode(&pInfo->sub); - } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) { + } else if (pInfo->type == TSDB_SQL_CREATE_STABLE) { pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo); } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeItem); diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 76e26c159b..6b42a93b73 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -761,8 +761,9 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c break; } - case TSDB_SQL_CREATE_TABLE: { + case TSDB_SQL_CREATE_STABLE: { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + assert(pCreateTable->type != TSQL_CREATE_CTABLE); if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { @@ -772,13 +773,6 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; - } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { - if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen)) != - TSDB_CODE_SUCCESS) { - goto _error; - } - - pDcl->msgType = TDMT_VND_CREATE_TABLE; } else if (pCreateTable->type == TSQL_CREATE_STREAM) { // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { // return code; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index f7f56510da..d265031a81 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -131,16 +131,16 @@ typedef union { #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 #define YYNSTATE 366 -#define YYNRULE 303 +#define YYNRULE 302 #define YYNTOKEN 191 #define YY_MAX_SHIFT 365 -#define YY_MIN_SHIFTREDUCE 587 -#define YY_MAX_SHIFTREDUCE 889 -#define YY_ERROR_ACTION 890 -#define YY_ACCEPT_ACTION 891 -#define YY_NO_ACTION 892 -#define YY_MIN_REDUCE 893 -#define YY_MAX_REDUCE 1195 +#define YY_MIN_SHIFTREDUCE 586 +#define YY_MAX_SHIFTREDUCE 887 +#define YY_ERROR_ACTION 888 +#define YY_ACCEPT_ACTION 889 +#define YY_NO_ACTION 890 +#define YY_MIN_REDUCE 891 +#define YY_MAX_REDUCE 1192 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -206,168 +206,167 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (782) +#define YY_ACTTAB_COUNT (777) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 249, 638, 364, 230, 162, 639, 248, 55, 56, 638, - /* 10 */ 59, 60, 1031, 639, 252, 49, 48, 47, 94, 58, - /* 20 */ 323, 63, 61, 64, 62, 674, 1080, 891, 365, 54, - /* 30 */ 53, 206, 82, 52, 51, 50, 253, 55, 56, 638, - /* 40 */ 59, 60, 1171, 639, 252, 49, 48, 47, 21, 58, - /* 50 */ 323, 63, 61, 64, 62, 1017, 203, 1015, 1016, 54, - /* 60 */ 53, 206, 1018, 52, 51, 50, 1019, 206, 1020, 1021, - /* 70 */ 832, 835, 1172, 55, 56, 1070, 59, 60, 1172, 1118, - /* 80 */ 252, 49, 48, 47, 81, 58, 323, 63, 61, 64, - /* 90 */ 62, 321, 319, 274, 1077, 54, 53, 206, 638, 52, - /* 100 */ 51, 50, 639, 55, 57, 353, 59, 60, 1172, 826, - /* 110 */ 252, 49, 48, 47, 155, 58, 323, 63, 61, 64, - /* 120 */ 62, 42, 319, 359, 358, 54, 53, 162, 357, 52, - /* 130 */ 51, 50, 356, 87, 355, 354, 162, 162, 588, 589, - /* 140 */ 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, - /* 150 */ 600, 601, 153, 56, 231, 59, 60, 236, 1057, 252, - /* 160 */ 49, 48, 47, 87, 58, 323, 63, 61, 64, 62, - /* 170 */ 772, 43, 32, 86, 54, 53, 255, 204, 52, 51, - /* 180 */ 50, 309, 209, 280, 279, 59, 60, 941, 839, 252, - /* 190 */ 49, 48, 47, 188, 58, 323, 63, 61, 64, 62, - /* 200 */ 294, 43, 92, 242, 54, 53, 300, 1045, 52, 51, - /* 210 */ 50, 1119, 93, 292, 42, 317, 359, 358, 316, 315, - /* 220 */ 314, 357, 313, 312, 311, 356, 310, 355, 354, 99, - /* 230 */ 22, 1010, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, - /* 240 */ 1006, 1007, 1008, 1009, 1011, 1012, 1013, 215, 251, 841, - /* 250 */ 830, 833, 836, 256, 216, 254, 776, 331, 330, 250, - /* 260 */ 137, 136, 135, 217, 1033, 266, 719, 328, 87, 251, - /* 270 */ 841, 830, 833, 836, 270, 269, 228, 229, 831, 834, - /* 280 */ 324, 4, 63, 61, 64, 62, 755, 752, 753, 754, - /* 290 */ 54, 53, 343, 342, 52, 51, 50, 228, 229, 747, - /* 300 */ 744, 745, 746, 52, 51, 50, 43, 3, 39, 178, - /* 310 */ 152, 150, 149, 257, 258, 105, 77, 101, 108, 1039, - /* 320 */ 96, 791, 792, 260, 36, 65, 244, 245, 273, 36, - /* 330 */ 79, 197, 195, 193, 36, 305, 210, 224, 192, 141, - /* 340 */ 140, 139, 138, 36, 36, 36, 65, 122, 116, 126, - /* 350 */ 36, 211, 1028, 1029, 33, 1032, 131, 134, 125, 638, - /* 360 */ 36, 842, 837, 639, 243, 128, 36, 232, 838, 54, - /* 370 */ 53, 1042, 240, 52, 51, 50, 1042, 241, 36, 36, - /* 380 */ 36, 1042, 842, 837, 1166, 261, 332, 333, 334, 838, - /* 390 */ 1042, 1042, 1042, 335, 176, 12, 840, 1042, 756, 757, - /* 400 */ 262, 95, 259, 339, 338, 337, 171, 1042, 363, 362, - /* 410 */ 146, 748, 749, 1041, 246, 80, 808, 1070, 1045, 1070, - /* 420 */ 261, 340, 341, 345, 282, 1042, 1042, 1042, 124, 177, - /* 430 */ 98, 261, 952, 942, 769, 233, 27, 234, 188, 188, - /* 440 */ 1043, 275, 353, 360, 979, 84, 85, 788, 1030, 798, - /* 450 */ 799, 71, 74, 729, 297, 731, 299, 37, 325, 7, - /* 460 */ 742, 743, 730, 157, 828, 66, 24, 740, 741, 37, - /* 470 */ 37, 67, 97, 864, 807, 760, 761, 843, 67, 637, - /* 480 */ 14, 78, 13, 70, 70, 115, 1165, 114, 16, 23, - /* 490 */ 15, 75, 72, 23, 1111, 23, 829, 758, 759, 133, - /* 500 */ 132, 18, 121, 17, 120, 20, 1164, 19, 1129, 226, - /* 510 */ 322, 227, 207, 1056, 718, 208, 212, 205, 213, 214, - /* 520 */ 1044, 219, 1072, 220, 1191, 221, 218, 202, 1128, 1183, - /* 530 */ 238, 1125, 1124, 239, 344, 271, 154, 44, 172, 1079, - /* 540 */ 151, 1110, 1090, 1087, 1088, 1071, 277, 1092, 1040, 156, - /* 550 */ 1068, 281, 235, 283, 31, 161, 285, 165, 288, 173, - /* 560 */ 163, 168, 787, 845, 164, 276, 1038, 174, 166, 169, - /* 570 */ 167, 291, 175, 956, 302, 303, 304, 76, 307, 308, - /* 580 */ 200, 40, 320, 951, 950, 329, 1190, 112, 73, 1189, - /* 590 */ 1186, 179, 46, 336, 295, 1182, 118, 287, 1181, 1178, - /* 600 */ 180, 976, 41, 38, 201, 939, 127, 937, 129, 130, - /* 610 */ 935, 934, 263, 190, 191, 931, 930, 929, 928, 293, - /* 620 */ 927, 926, 925, 194, 196, 922, 920, 918, 916, 198, - /* 630 */ 913, 199, 909, 289, 284, 83, 88, 45, 286, 1112, - /* 640 */ 306, 123, 346, 225, 247, 347, 301, 348, 349, 351, - /* 650 */ 222, 223, 350, 352, 361, 955, 954, 106, 889, 264, - /* 660 */ 265, 888, 267, 268, 887, 870, 933, 869, 272, 183, - /* 670 */ 182, 977, 932, 181, 142, 184, 185, 187, 186, 143, - /* 680 */ 144, 924, 978, 923, 2, 70, 145, 915, 914, 296, - /* 690 */ 8, 28, 1, 763, 278, 170, 789, 89, 158, 160, - /* 700 */ 800, 159, 237, 794, 90, 29, 796, 91, 290, 9, - /* 710 */ 30, 10, 11, 25, 26, 298, 100, 34, 98, 103, - /* 720 */ 652, 102, 690, 35, 104, 687, 685, 684, 683, 681, - /* 730 */ 680, 679, 676, 642, 326, 327, 107, 111, 109, 318, - /* 740 */ 113, 110, 5, 68, 844, 846, 6, 69, 721, 37, - /* 750 */ 117, 119, 720, 717, 668, 666, 658, 664, 660, 662, - /* 760 */ 656, 654, 689, 688, 686, 682, 678, 677, 189, 640, - /* 770 */ 893, 605, 892, 892, 892, 892, 892, 892, 892, 892, - /* 780 */ 147, 148, + /* 0 */ 249, 637, 637, 1077, 83, 717, 248, 55, 56, 88, + /* 10 */ 59, 60, 364, 230, 252, 49, 48, 47, 78, 58, + /* 20 */ 323, 63, 61, 64, 62, 236, 1054, 889, 365, 54, + /* 30 */ 53, 343, 342, 52, 51, 50, 253, 55, 56, 242, + /* 40 */ 59, 60, 1027, 1042, 252, 49, 48, 47, 104, 58, + /* 50 */ 323, 63, 61, 64, 62, 1014, 637, 1012, 1013, 54, + /* 60 */ 53, 206, 1015, 52, 51, 50, 1016, 206, 1017, 1018, + /* 70 */ 121, 1074, 1169, 55, 56, 1067, 59, 60, 1169, 27, + /* 80 */ 252, 49, 48, 47, 89, 58, 323, 63, 61, 64, + /* 90 */ 62, 206, 39, 274, 246, 54, 53, 206, 1042, 52, + /* 100 */ 51, 50, 1168, 55, 57, 1030, 59, 60, 1169, 824, + /* 110 */ 252, 49, 48, 47, 80, 58, 323, 63, 61, 64, + /* 120 */ 62, 294, 637, 81, 159, 54, 53, 91, 319, 52, + /* 130 */ 51, 50, 104, 1067, 56, 232, 59, 60, 353, 1039, + /* 140 */ 252, 49, 48, 47, 261, 58, 323, 63, 61, 64, + /* 150 */ 62, 233, 43, 124, 79, 54, 53, 80, 39, 52, + /* 160 */ 51, 50, 587, 588, 589, 590, 591, 592, 593, 594, + /* 170 */ 595, 596, 597, 598, 599, 600, 199, 309, 231, 59, + /* 180 */ 60, 939, 1067, 252, 49, 48, 47, 158, 58, 323, + /* 190 */ 63, 61, 64, 62, 353, 43, 280, 279, 54, 53, + /* 200 */ 234, 240, 52, 51, 50, 1039, 14, 1116, 13, 292, + /* 210 */ 42, 317, 359, 358, 316, 315, 314, 357, 313, 312, + /* 220 */ 311, 356, 310, 355, 354, 1007, 995, 996, 997, 998, + /* 230 */ 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1008, 1009, + /* 240 */ 1010, 266, 12, 22, 63, 61, 64, 62, 84, 21, + /* 250 */ 270, 269, 54, 53, 789, 790, 52, 51, 50, 946, + /* 260 */ 215, 113, 251, 839, 828, 831, 834, 216, 753, 750, + /* 270 */ 751, 752, 672, 175, 174, 172, 217, 119, 261, 282, + /* 280 */ 328, 80, 251, 839, 828, 831, 834, 127, 116, 203, + /* 290 */ 228, 229, 255, 39, 324, 257, 258, 745, 742, 743, + /* 300 */ 744, 204, 39, 1036, 3, 32, 131, 261, 209, 260, + /* 310 */ 228, 229, 129, 85, 123, 133, 1040, 39, 39, 43, + /* 320 */ 1025, 1026, 30, 1029, 244, 245, 189, 186, 183, 52, + /* 330 */ 51, 50, 305, 181, 179, 178, 177, 176, 319, 65, + /* 340 */ 1038, 273, 637, 86, 42, 241, 359, 358, 243, 1039, + /* 350 */ 224, 357, 770, 830, 833, 356, 39, 355, 354, 65, + /* 360 */ 332, 333, 54, 53, 1039, 1039, 52, 51, 50, 256, + /* 370 */ 39, 254, 39, 331, 330, 840, 835, 104, 39, 39, + /* 380 */ 754, 755, 836, 149, 142, 162, 262, 39, 259, 806, + /* 390 */ 338, 337, 167, 170, 160, 840, 835, 829, 832, 334, + /* 400 */ 104, 164, 836, 1039, 826, 363, 362, 190, 767, 746, + /* 410 */ 747, 92, 949, 335, 940, 339, 93, 1039, 158, 1039, + /* 420 */ 158, 340, 341, 71, 321, 1039, 1039, 198, 195, 193, + /* 430 */ 345, 360, 976, 7, 1039, 275, 827, 786, 774, 796, + /* 440 */ 797, 74, 727, 297, 729, 299, 325, 805, 35, 70, + /* 450 */ 210, 40, 1115, 97, 70, 66, 24, 728, 40, 40, + /* 460 */ 67, 117, 740, 741, 72, 738, 739, 862, 841, 250, + /* 470 */ 636, 837, 140, 67, 139, 82, 16, 18, 15, 17, + /* 480 */ 75, 211, 300, 23, 23, 77, 23, 758, 759, 169, + /* 490 */ 168, 4, 756, 757, 147, 20, 146, 19, 1163, 1162, + /* 500 */ 1161, 226, 227, 207, 208, 212, 1053, 1041, 205, 1126, + /* 510 */ 213, 214, 219, 220, 221, 838, 218, 202, 716, 1188, + /* 520 */ 1180, 1125, 1069, 238, 1122, 1121, 239, 44, 1068, 344, + /* 530 */ 277, 114, 322, 1108, 1107, 196, 271, 785, 1037, 276, + /* 540 */ 1065, 87, 1076, 1087, 281, 235, 73, 90, 1084, 1085, + /* 550 */ 76, 843, 283, 1089, 295, 46, 105, 106, 94, 107, + /* 560 */ 293, 95, 101, 108, 285, 291, 288, 286, 109, 1109, + /* 570 */ 289, 110, 287, 111, 284, 112, 29, 45, 225, 115, + /* 580 */ 1035, 306, 150, 247, 118, 952, 346, 120, 301, 953, + /* 590 */ 302, 303, 304, 974, 307, 308, 200, 347, 348, 38, + /* 600 */ 320, 349, 948, 951, 947, 130, 329, 350, 1187, 351, + /* 610 */ 352, 361, 137, 1186, 1183, 887, 141, 222, 336, 1179, + /* 620 */ 152, 144, 1178, 265, 1175, 886, 148, 223, 973, 268, + /* 630 */ 885, 868, 867, 70, 296, 8, 28, 41, 31, 761, + /* 640 */ 278, 96, 153, 201, 937, 151, 154, 156, 157, 155, + /* 650 */ 163, 935, 165, 1, 166, 933, 264, 932, 263, 171, + /* 660 */ 267, 975, 931, 930, 173, 929, 928, 927, 926, 925, + /* 670 */ 924, 272, 923, 787, 180, 184, 98, 182, 922, 798, + /* 680 */ 185, 921, 99, 188, 187, 920, 918, 792, 100, 916, + /* 690 */ 914, 102, 194, 913, 911, 912, 197, 907, 794, 2, + /* 700 */ 237, 103, 290, 9, 33, 34, 10, 11, 25, 298, + /* 710 */ 26, 122, 119, 36, 126, 125, 650, 688, 37, 128, + /* 720 */ 685, 683, 682, 681, 679, 678, 677, 674, 640, 132, + /* 730 */ 5, 134, 135, 842, 318, 844, 6, 326, 327, 68, + /* 740 */ 136, 40, 69, 719, 718, 138, 143, 145, 715, 666, + /* 750 */ 664, 656, 662, 658, 660, 654, 652, 687, 686, 684, + /* 760 */ 680, 676, 675, 161, 604, 638, 891, 890, 890, 890, + /* 770 */ 890, 890, 890, 890, 890, 191, 192, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 200, 1, 194, 195, 194, 5, 200, 7, 8, 1, - /* 10 */ 10, 11, 0, 5, 14, 15, 16, 17, 245, 19, - /* 20 */ 20, 21, 22, 23, 24, 3, 194, 192, 193, 29, - /* 30 */ 30, 261, 259, 33, 34, 35, 200, 7, 8, 1, - /* 40 */ 10, 11, 272, 5, 14, 15, 16, 17, 261, 19, - /* 50 */ 20, 21, 22, 23, 24, 216, 261, 218, 219, 29, + /* 0 */ 200, 1, 1, 194, 245, 3, 200, 7, 8, 201, + /* 10 */ 10, 11, 194, 195, 14, 15, 16, 17, 259, 19, + /* 20 */ 20, 21, 22, 23, 24, 243, 244, 192, 193, 29, + /* 30 */ 30, 29, 30, 33, 34, 35, 200, 7, 8, 238, + /* 40 */ 10, 11, 234, 242, 14, 15, 16, 17, 194, 19, + /* 50 */ 20, 21, 22, 23, 24, 216, 1, 218, 219, 29, /* 60 */ 30, 261, 223, 33, 34, 35, 227, 261, 229, 230, - /* 70 */ 3, 4, 272, 7, 8, 240, 10, 11, 272, 269, + /* 70 */ 201, 262, 272, 7, 8, 240, 10, 11, 272, 78, /* 80 */ 14, 15, 16, 17, 84, 19, 20, 21, 22, 23, - /* 90 */ 24, 83, 80, 258, 262, 29, 30, 261, 1, 33, - /* 100 */ 34, 35, 5, 7, 8, 88, 10, 11, 272, 79, - /* 110 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, - /* 120 */ 24, 96, 80, 98, 99, 29, 30, 194, 103, 33, - /* 130 */ 34, 35, 107, 78, 109, 110, 194, 194, 41, 42, - /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - /* 150 */ 53, 54, 55, 8, 57, 10, 11, 243, 244, 14, - /* 160 */ 15, 16, 17, 78, 19, 20, 21, 22, 23, 24, - /* 170 */ 33, 116, 78, 118, 29, 30, 64, 261, 33, 34, - /* 180 */ 35, 63, 261, 263, 264, 10, 11, 199, 121, 14, - /* 190 */ 15, 16, 17, 205, 19, 20, 21, 22, 23, 24, - /* 200 */ 267, 116, 269, 238, 29, 30, 112, 242, 33, 34, - /* 210 */ 35, 269, 269, 271, 96, 97, 98, 99, 100, 101, - /* 220 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, - /* 230 */ 40, 216, 217, 218, 219, 220, 221, 222, 223, 224, - /* 240 */ 225, 226, 227, 228, 229, 230, 231, 57, 1, 2, - /* 250 */ 3, 4, 5, 141, 64, 143, 119, 145, 146, 56, - /* 260 */ 70, 71, 72, 73, 236, 139, 3, 77, 78, 1, - /* 270 */ 2, 3, 4, 5, 148, 149, 29, 30, 3, 4, - /* 280 */ 33, 78, 21, 22, 23, 24, 2, 3, 4, 5, - /* 290 */ 29, 30, 29, 30, 33, 34, 35, 29, 30, 2, - /* 300 */ 3, 4, 5, 33, 34, 35, 116, 58, 59, 60, - /* 310 */ 58, 59, 60, 29, 30, 66, 67, 68, 69, 194, - /* 320 */ 201, 122, 123, 64, 194, 78, 29, 30, 138, 194, - /* 330 */ 140, 58, 59, 60, 194, 86, 261, 147, 65, 66, - /* 340 */ 67, 68, 69, 194, 194, 194, 78, 58, 59, 60, - /* 350 */ 194, 261, 233, 234, 235, 236, 67, 68, 69, 1, - /* 360 */ 194, 114, 115, 5, 239, 76, 194, 237, 121, 29, - /* 370 */ 30, 241, 237, 33, 34, 35, 241, 237, 194, 194, - /* 380 */ 194, 241, 114, 115, 261, 194, 237, 237, 237, 121, - /* 390 */ 241, 241, 241, 237, 203, 78, 121, 241, 114, 115, - /* 400 */ 141, 84, 143, 237, 145, 146, 248, 241, 61, 62, - /* 410 */ 63, 114, 115, 241, 238, 201, 72, 240, 242, 240, - /* 420 */ 194, 237, 237, 237, 266, 241, 241, 241, 74, 203, - /* 430 */ 113, 194, 199, 199, 95, 258, 78, 258, 205, 205, - /* 440 */ 203, 79, 88, 214, 215, 79, 79, 79, 234, 79, - /* 450 */ 79, 95, 95, 79, 79, 79, 79, 95, 9, 120, - /* 460 */ 3, 4, 79, 95, 1, 95, 95, 3, 4, 95, - /* 470 */ 95, 95, 95, 79, 130, 3, 4, 79, 95, 79, - /* 480 */ 142, 78, 144, 117, 117, 142, 261, 144, 142, 95, - /* 490 */ 144, 134, 136, 95, 270, 95, 33, 3, 4, 74, - /* 500 */ 75, 142, 142, 144, 144, 142, 261, 144, 232, 261, - /* 510 */ 194, 261, 261, 244, 111, 261, 261, 261, 261, 261, - /* 520 */ 242, 261, 240, 261, 244, 261, 261, 261, 232, 244, - /* 530 */ 232, 232, 232, 232, 232, 194, 194, 260, 246, 194, - /* 540 */ 56, 270, 194, 194, 194, 240, 240, 194, 240, 194, - /* 550 */ 257, 265, 265, 265, 247, 194, 265, 254, 194, 194, - /* 560 */ 256, 251, 121, 114, 255, 196, 194, 194, 253, 250, - /* 570 */ 252, 126, 194, 194, 194, 194, 194, 133, 194, 194, - /* 580 */ 194, 194, 194, 194, 194, 194, 194, 194, 135, 194, - /* 590 */ 194, 194, 132, 194, 128, 194, 194, 124, 194, 194, - /* 600 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 610 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 131, - /* 620 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 630 */ 194, 194, 194, 125, 127, 196, 196, 137, 196, 196, - /* 640 */ 87, 94, 93, 196, 196, 47, 196, 90, 92, 91, - /* 650 */ 196, 196, 51, 89, 80, 204, 204, 201, 3, 150, - /* 660 */ 3, 3, 150, 3, 3, 98, 196, 97, 139, 207, - /* 670 */ 211, 213, 196, 212, 197, 210, 208, 206, 209, 197, - /* 680 */ 197, 196, 215, 196, 198, 117, 197, 196, 196, 112, - /* 690 */ 78, 78, 202, 79, 95, 249, 79, 95, 78, 95, - /* 700 */ 79, 78, 1, 79, 78, 95, 79, 78, 78, 129, - /* 710 */ 95, 129, 78, 78, 78, 112, 74, 85, 113, 66, - /* 720 */ 3, 84, 3, 85, 84, 5, 3, 3, 3, 3, - /* 730 */ 3, 3, 3, 81, 20, 55, 74, 144, 82, 9, - /* 740 */ 144, 82, 78, 10, 79, 114, 78, 10, 3, 95, - /* 750 */ 144, 144, 3, 79, 3, 3, 3, 3, 3, 3, - /* 760 */ 3, 3, 3, 3, 3, 3, 3, 3, 95, 81, - /* 770 */ 0, 56, 273, 273, 273, 273, 273, 273, 273, 273, - /* 780 */ 15, 15, 273, 273, 273, 273, 273, 273, 273, 273, + /* 90 */ 24, 261, 194, 258, 238, 29, 30, 261, 242, 33, + /* 100 */ 34, 35, 272, 7, 8, 236, 10, 11, 272, 79, + /* 110 */ 14, 15, 16, 17, 78, 19, 20, 21, 22, 23, + /* 120 */ 24, 267, 1, 269, 74, 29, 30, 194, 80, 33, + /* 130 */ 34, 35, 194, 240, 8, 237, 10, 11, 88, 241, + /* 140 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, + /* 150 */ 24, 258, 116, 203, 118, 29, 30, 78, 194, 33, + /* 160 */ 34, 35, 41, 42, 43, 44, 45, 46, 47, 48, + /* 170 */ 49, 50, 51, 52, 53, 54, 55, 63, 57, 10, + /* 180 */ 11, 199, 240, 14, 15, 16, 17, 205, 19, 20, + /* 190 */ 21, 22, 23, 24, 88, 116, 263, 264, 29, 30, + /* 200 */ 258, 237, 33, 34, 35, 241, 142, 269, 144, 271, + /* 210 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + /* 220 */ 106, 107, 108, 109, 110, 216, 217, 218, 219, 220, + /* 230 */ 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + /* 240 */ 231, 139, 78, 40, 21, 22, 23, 24, 84, 261, + /* 250 */ 148, 149, 29, 30, 122, 123, 33, 34, 35, 1, + /* 260 */ 57, 248, 1, 2, 3, 4, 5, 64, 2, 3, + /* 270 */ 4, 5, 3, 70, 71, 72, 73, 113, 194, 266, + /* 280 */ 77, 78, 1, 2, 3, 4, 5, 203, 201, 261, + /* 290 */ 29, 30, 64, 194, 33, 29, 30, 2, 3, 4, + /* 300 */ 5, 261, 194, 194, 58, 59, 60, 194, 261, 64, + /* 310 */ 29, 30, 66, 67, 68, 69, 203, 194, 194, 116, + /* 320 */ 233, 234, 235, 236, 29, 30, 58, 59, 60, 33, + /* 330 */ 34, 35, 86, 65, 66, 67, 68, 69, 80, 78, + /* 340 */ 241, 138, 1, 140, 96, 237, 98, 99, 239, 241, + /* 350 */ 147, 103, 33, 3, 4, 107, 194, 109, 110, 78, + /* 360 */ 237, 237, 29, 30, 241, 241, 33, 34, 35, 141, + /* 370 */ 194, 143, 194, 145, 146, 114, 115, 194, 194, 194, + /* 380 */ 114, 115, 121, 58, 59, 60, 141, 194, 143, 72, + /* 390 */ 145, 146, 67, 68, 69, 114, 115, 3, 4, 237, + /* 400 */ 194, 76, 121, 241, 1, 61, 62, 63, 95, 114, + /* 410 */ 115, 79, 199, 237, 199, 237, 79, 241, 205, 241, + /* 420 */ 205, 237, 237, 95, 83, 241, 241, 58, 59, 60, + /* 430 */ 237, 214, 215, 120, 241, 79, 33, 79, 119, 79, + /* 440 */ 79, 95, 79, 79, 79, 79, 9, 130, 78, 117, + /* 450 */ 261, 95, 269, 95, 117, 95, 95, 79, 95, 95, + /* 460 */ 95, 95, 3, 4, 136, 3, 4, 79, 79, 56, + /* 470 */ 79, 121, 142, 95, 144, 269, 142, 142, 144, 144, + /* 480 */ 134, 261, 112, 95, 95, 78, 95, 3, 4, 74, + /* 490 */ 75, 78, 3, 4, 142, 142, 144, 144, 261, 261, + /* 500 */ 261, 261, 261, 261, 261, 261, 244, 242, 261, 232, + /* 510 */ 261, 261, 261, 261, 261, 121, 261, 261, 111, 244, + /* 520 */ 244, 232, 240, 232, 232, 232, 232, 260, 240, 232, + /* 530 */ 240, 246, 194, 270, 270, 56, 194, 121, 240, 196, + /* 540 */ 257, 194, 194, 194, 265, 265, 135, 196, 194, 194, + /* 550 */ 133, 114, 265, 194, 128, 132, 256, 255, 196, 254, + /* 560 */ 131, 194, 194, 253, 265, 126, 194, 196, 252, 196, + /* 570 */ 125, 251, 124, 250, 127, 249, 247, 137, 196, 194, + /* 580 */ 194, 87, 94, 196, 194, 204, 93, 194, 196, 194, + /* 590 */ 194, 194, 194, 213, 194, 194, 194, 47, 90, 194, + /* 600 */ 194, 92, 194, 204, 194, 201, 194, 51, 194, 91, + /* 610 */ 89, 80, 194, 194, 194, 3, 194, 196, 194, 194, + /* 620 */ 211, 194, 194, 3, 194, 3, 194, 196, 194, 3, + /* 630 */ 3, 98, 97, 117, 112, 78, 78, 194, 194, 79, + /* 640 */ 95, 95, 207, 194, 194, 212, 210, 209, 206, 208, + /* 650 */ 194, 194, 194, 202, 194, 194, 150, 194, 194, 194, + /* 660 */ 150, 215, 196, 196, 194, 194, 194, 194, 194, 194, + /* 670 */ 194, 139, 194, 79, 197, 194, 78, 197, 196, 79, + /* 680 */ 197, 196, 78, 197, 194, 194, 194, 79, 95, 194, + /* 690 */ 194, 78, 194, 196, 194, 196, 194, 194, 79, 198, + /* 700 */ 1, 78, 78, 129, 95, 95, 129, 78, 78, 112, + /* 710 */ 78, 74, 113, 85, 66, 84, 3, 3, 85, 84, + /* 720 */ 5, 3, 3, 3, 3, 3, 3, 3, 81, 74, + /* 730 */ 78, 82, 82, 79, 9, 114, 78, 20, 55, 10, + /* 740 */ 144, 95, 10, 3, 3, 144, 144, 144, 79, 3, + /* 750 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 760 */ 3, 3, 3, 95, 56, 81, 0, 273, 273, 273, + /* 770 */ 273, 273, 273, 273, 273, 15, 15, 273, 273, 273, + /* 780 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 790 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 800 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 810 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, @@ -385,115 +384,114 @@ static const YYCODETYPE yy_lookahead[] = { /* 930 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 940 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 950 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 970 */ 273, 273, 273, + /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, }; #define YY_SHIFT_COUNT (365) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (770) +#define YY_SHIFT_MAX (766) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 190, 118, 25, 42, 247, 268, 268, 358, 38, 38, - /* 10 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 20 */ 38, 0, 97, 268, 284, 297, 297, 85, 85, 38, - /* 30 */ 38, 199, 38, 12, 38, 38, 38, 38, 354, 42, - /* 40 */ 17, 17, 22, 782, 268, 268, 268, 268, 268, 268, - /* 50 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 60 */ 268, 268, 268, 268, 268, 268, 284, 297, 284, 284, - /* 70 */ 55, 263, 263, 263, 263, 263, 263, 8, 263, 38, - /* 80 */ 38, 38, 137, 38, 38, 38, 85, 85, 38, 38, - /* 90 */ 38, 38, 344, 344, 339, 85, 38, 38, 38, 38, - /* 100 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 110 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 120 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 130 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 140 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 150 */ 38, 38, 38, 38, 484, 484, 484, 441, 441, 441, - /* 160 */ 441, 484, 484, 444, 453, 466, 460, 488, 445, 508, - /* 170 */ 473, 507, 500, 484, 484, 484, 553, 553, 42, 484, - /* 180 */ 484, 547, 549, 598, 557, 556, 601, 558, 564, 22, - /* 190 */ 484, 484, 574, 574, 484, 574, 484, 574, 484, 484, - /* 200 */ 782, 782, 30, 66, 66, 96, 66, 145, 175, 261, - /* 210 */ 261, 261, 261, 261, 261, 249, 273, 289, 340, 340, - /* 220 */ 340, 340, 112, 259, 126, 317, 270, 270, 67, 275, - /* 230 */ 347, 252, 362, 366, 367, 368, 370, 371, 356, 357, - /* 240 */ 374, 375, 376, 377, 457, 464, 383, 94, 394, 398, - /* 250 */ 463, 203, 449, 400, 338, 343, 346, 472, 494, 359, - /* 260 */ 360, 403, 363, 425, 655, 509, 657, 658, 512, 660, - /* 270 */ 661, 567, 570, 529, 568, 577, 612, 614, 613, 599, - /* 280 */ 602, 617, 620, 621, 623, 624, 604, 626, 627, 629, - /* 290 */ 701, 630, 610, 580, 615, 582, 634, 577, 635, 603, - /* 300 */ 636, 605, 642, 632, 637, 653, 717, 638, 640, 719, - /* 310 */ 720, 723, 724, 725, 726, 727, 728, 729, 652, 730, - /* 320 */ 662, 656, 659, 664, 665, 631, 668, 714, 680, 733, - /* 330 */ 593, 596, 654, 654, 654, 654, 737, 606, 607, 654, - /* 340 */ 654, 654, 745, 749, 674, 654, 751, 752, 753, 754, - /* 350 */ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, - /* 360 */ 673, 688, 765, 766, 715, 770, + /* 0 */ 203, 114, 248, 48, 261, 281, 281, 1, 55, 55, + /* 10 */ 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + /* 20 */ 55, 0, 121, 281, 266, 295, 295, 79, 79, 132, + /* 30 */ 258, 50, 48, 55, 55, 55, 55, 55, 106, 55, + /* 40 */ 55, 106, 269, 777, 281, 281, 281, 281, 281, 281, + /* 50 */ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, + /* 60 */ 281, 281, 281, 281, 281, 281, 266, 295, 266, 266, + /* 70 */ 36, 2, 2, 2, 2, 2, 2, 2, 319, 79, + /* 80 */ 79, 317, 317, 313, 79, 341, 55, 479, 55, 55, + /* 90 */ 55, 479, 55, 55, 55, 479, 55, 416, 416, 416, + /* 100 */ 416, 479, 55, 55, 479, 417, 411, 426, 423, 429, + /* 110 */ 439, 445, 448, 447, 440, 479, 55, 55, 479, 55, + /* 120 */ 479, 55, 55, 55, 494, 55, 55, 494, 55, 55, + /* 130 */ 55, 48, 55, 55, 55, 55, 55, 55, 55, 55, + /* 140 */ 55, 479, 55, 55, 55, 55, 55, 55, 479, 55, + /* 150 */ 55, 488, 493, 550, 508, 509, 556, 518, 521, 55, + /* 160 */ 55, 269, 55, 55, 55, 55, 55, 55, 55, 55, + /* 170 */ 55, 479, 55, 479, 55, 55, 55, 55, 55, 55, + /* 180 */ 55, 531, 55, 531, 479, 55, 531, 479, 55, 531, + /* 190 */ 55, 55, 55, 55, 479, 55, 55, 479, 55, 55, + /* 200 */ 777, 777, 30, 66, 66, 96, 66, 126, 169, 223, + /* 210 */ 223, 223, 223, 223, 223, 246, 268, 325, 333, 333, + /* 220 */ 333, 333, 228, 245, 102, 164, 296, 296, 350, 394, + /* 230 */ 344, 369, 356, 332, 337, 358, 360, 361, 328, 346, + /* 240 */ 363, 364, 365, 366, 459, 462, 378, 370, 388, 389, + /* 250 */ 403, 413, 437, 391, 64, 330, 334, 484, 489, 335, + /* 260 */ 352, 407, 353, 415, 612, 506, 620, 622, 510, 626, + /* 270 */ 627, 533, 535, 532, 516, 522, 557, 560, 558, 545, + /* 280 */ 546, 594, 598, 600, 604, 608, 593, 613, 619, 623, + /* 290 */ 699, 624, 609, 574, 610, 577, 629, 522, 630, 597, + /* 300 */ 632, 599, 637, 628, 631, 648, 713, 633, 635, 714, + /* 310 */ 715, 718, 719, 720, 721, 722, 723, 724, 647, 725, + /* 320 */ 655, 649, 650, 652, 654, 621, 658, 717, 683, 729, + /* 330 */ 596, 601, 646, 646, 646, 646, 732, 602, 603, 646, + /* 340 */ 646, 646, 740, 741, 669, 646, 746, 747, 748, 749, + /* 350 */ 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, + /* 360 */ 668, 684, 760, 761, 708, 766, }; #define YY_REDUCE_COUNT (201) -#define YY_REDUCE_MIN (-230) -#define YY_REDUCE_MAX (492) +#define YY_REDUCE_MIN (-241) +#define YY_REDUCE_MAX (503) static const short yy_reduce_ofst[] = { - /* 0 */ -165, 15, -161, 119, -200, -194, -164, -80, 130, -58, - /* 10 */ -67, 135, 140, 149, 150, 151, 156, 166, 184, 185, - /* 20 */ 186, -168, -192, -230, -86, -35, 176, 177, 179, -190, - /* 30 */ -57, 158, 125, 28, 191, 226, 237, 172, -12, 214, - /* 40 */ 233, 234, 229, -227, -213, -205, -84, -79, 75, 90, - /* 50 */ 123, 225, 245, 248, 250, 251, 254, 255, 256, 257, - /* 60 */ 258, 260, 262, 264, 265, 266, 269, 278, 280, 285, - /* 70 */ 282, 276, 296, 298, 299, 300, 301, 316, 302, 341, - /* 80 */ 342, 345, 277, 348, 349, 350, 305, 306, 353, 355, - /* 90 */ 361, 364, 224, 271, 292, 308, 365, 372, 373, 378, - /* 100 */ 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, - /* 110 */ 390, 391, 392, 393, 395, 396, 397, 399, 401, 402, - /* 120 */ 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - /* 130 */ 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - /* 140 */ 424, 426, 427, 428, 429, 430, 431, 432, 433, 434, - /* 150 */ 435, 436, 437, 438, 369, 439, 440, 286, 287, 288, - /* 160 */ 291, 442, 443, 293, 304, 309, 303, 315, 318, 310, - /* 170 */ 319, 446, 307, 447, 448, 450, 451, 452, 456, 454, - /* 180 */ 455, 458, 461, 459, 462, 465, 468, 469, 471, 467, - /* 190 */ 470, 476, 477, 482, 485, 483, 487, 489, 491, 492, - /* 200 */ 490, 486, + /* 0 */ -165, 9, -161, 87, -200, -194, -164, -67, -102, -62, + /* 10 */ -146, -36, 108, 123, 124, 162, 176, 178, 184, 185, + /* 20 */ 193, -191, -182, -170, -218, -199, -144, -107, -58, 13, + /* 30 */ -131, -18, -192, 183, 206, 109, -50, 84, 213, 113, + /* 40 */ 99, 215, 217, -241, -12, 28, 40, 47, 189, 220, + /* 50 */ 237, 238, 239, 240, 241, 242, 243, 244, 247, 249, + /* 60 */ 250, 251, 252, 253, 255, 256, 262, 265, 275, 276, + /* 70 */ 282, 277, 289, 291, 292, 293, 294, 297, 267, 288, + /* 80 */ 290, 263, 264, 285, 298, 338, 342, 343, 347, 348, + /* 90 */ 349, 351, 354, 355, 359, 362, 367, 279, 280, 287, + /* 100 */ 299, 371, 368, 372, 373, 283, 300, 302, 305, 310, + /* 110 */ 316, 320, 323, 326, 329, 382, 385, 386, 387, 390, + /* 120 */ 392, 393, 395, 396, 381, 397, 398, 399, 400, 401, + /* 130 */ 402, 404, 405, 406, 408, 410, 412, 414, 418, 419, + /* 140 */ 420, 421, 422, 424, 425, 427, 428, 430, 431, 432, + /* 150 */ 434, 380, 433, 409, 435, 436, 441, 438, 442, 443, + /* 160 */ 444, 446, 449, 450, 456, 457, 458, 460, 461, 463, + /* 170 */ 464, 466, 465, 467, 470, 471, 472, 473, 474, 475, + /* 180 */ 476, 477, 478, 480, 482, 481, 483, 485, 490, 486, + /* 190 */ 491, 492, 495, 496, 497, 498, 500, 499, 502, 503, + /* 200 */ 451, 501, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 890, 953, 940, 949, 1174, 1174, 1174, 890, 890, 890, - /* 10 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 20 */ 890, 1081, 910, 1174, 890, 890, 890, 890, 890, 890, - /* 30 */ 890, 1096, 890, 949, 890, 890, 890, 890, 959, 949, - /* 40 */ 959, 959, 890, 1076, 890, 890, 890, 890, 890, 890, - /* 50 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 60 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 70 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 80 */ 890, 890, 1083, 1089, 1086, 890, 890, 890, 1091, 890, - /* 90 */ 890, 890, 1115, 1115, 1074, 890, 890, 890, 890, 890, - /* 100 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 110 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 120 */ 890, 890, 890, 890, 890, 890, 890, 938, 890, 936, - /* 130 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 140 */ 890, 890, 890, 890, 890, 890, 921, 890, 890, 890, - /* 150 */ 890, 890, 890, 908, 912, 912, 912, 890, 890, 890, - /* 160 */ 890, 912, 912, 1122, 1126, 1108, 1120, 1116, 1103, 1101, - /* 170 */ 1099, 1107, 1130, 912, 912, 912, 957, 957, 949, 912, - /* 180 */ 912, 975, 973, 971, 963, 969, 965, 967, 961, 890, - /* 190 */ 912, 912, 947, 947, 912, 947, 912, 947, 912, 912, - /* 200 */ 997, 1014, 890, 1131, 1121, 890, 1173, 1161, 1160, 1169, - /* 210 */ 1168, 1167, 1159, 1158, 1157, 890, 890, 890, 1153, 1156, - /* 220 */ 1155, 1154, 890, 890, 890, 890, 1163, 1162, 890, 890, - /* 230 */ 890, 890, 890, 890, 890, 890, 890, 890, 1127, 1123, - /* 240 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 250 */ 890, 1133, 890, 890, 890, 890, 890, 890, 890, 890, - /* 260 */ 890, 1022, 890, 890, 890, 890, 890, 890, 890, 890, - /* 270 */ 890, 890, 890, 890, 1073, 890, 890, 890, 890, 1085, - /* 280 */ 1084, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 290 */ 890, 890, 1117, 890, 1109, 890, 890, 1034, 890, 890, - /* 300 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 310 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 320 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 330 */ 890, 890, 1192, 1187, 1188, 1185, 890, 890, 890, 1184, - /* 340 */ 1179, 1180, 890, 890, 890, 1177, 890, 890, 890, 890, - /* 350 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 360 */ 981, 890, 919, 917, 890, 890, + /* 0 */ 888, 950, 938, 946, 1171, 1171, 1171, 888, 888, 888, + /* 10 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 20 */ 888, 1078, 908, 1171, 888, 888, 888, 888, 888, 1093, + /* 30 */ 1028, 956, 946, 888, 888, 888, 888, 888, 956, 888, + /* 40 */ 888, 956, 888, 1073, 888, 888, 888, 888, 888, 888, + /* 50 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 60 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 70 */ 888, 888, 888, 888, 888, 888, 888, 888, 1080, 888, + /* 80 */ 888, 1112, 1112, 1071, 888, 888, 888, 910, 888, 888, + /* 90 */ 1086, 910, 1083, 888, 1088, 910, 888, 888, 888, 888, + /* 100 */ 888, 910, 888, 888, 910, 1119, 1123, 1105, 1117, 1113, + /* 110 */ 1100, 1098, 1096, 1104, 1127, 910, 888, 888, 910, 888, + /* 120 */ 910, 888, 888, 888, 954, 888, 888, 954, 888, 888, + /* 130 */ 888, 946, 888, 888, 888, 888, 888, 888, 888, 888, + /* 140 */ 888, 910, 888, 888, 888, 888, 888, 888, 910, 888, + /* 150 */ 888, 972, 970, 968, 960, 966, 962, 964, 958, 888, + /* 160 */ 888, 888, 888, 936, 888, 934, 888, 888, 888, 888, + /* 170 */ 888, 910, 888, 910, 888, 888, 888, 888, 888, 888, + /* 180 */ 888, 944, 888, 944, 910, 888, 944, 910, 888, 944, + /* 190 */ 919, 888, 888, 888, 910, 888, 888, 910, 888, 906, + /* 200 */ 994, 1011, 888, 1128, 1118, 888, 1170, 1158, 1157, 1166, + /* 210 */ 1165, 1164, 1156, 1155, 1154, 888, 888, 888, 1150, 1153, + /* 220 */ 1152, 1151, 888, 888, 888, 888, 1160, 1159, 888, 888, + /* 230 */ 888, 888, 888, 888, 888, 888, 888, 888, 1124, 1120, + /* 240 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 250 */ 888, 1130, 888, 888, 888, 888, 888, 888, 888, 888, + /* 260 */ 888, 1019, 888, 888, 888, 888, 888, 888, 888, 888, + /* 270 */ 888, 888, 888, 888, 1070, 888, 888, 888, 888, 1082, + /* 280 */ 1081, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 290 */ 888, 888, 1114, 888, 1106, 888, 888, 1031, 888, 888, + /* 300 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 310 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 320 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 330 */ 888, 888, 1189, 1184, 1185, 1182, 888, 888, 888, 1181, + /* 340 */ 1176, 1177, 888, 888, 888, 1174, 888, 888, 888, 888, + /* 350 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 360 */ 978, 888, 917, 915, 888, 888, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1122,257 +1120,256 @@ static const char *const yyRuleName[] = { /* 49 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", /* 50 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", /* 51 */ "ids ::= ID", - /* 52 */ "ids ::= STRING", - /* 53 */ "ifexists ::= IF EXISTS", - /* 54 */ "ifexists ::=", - /* 55 */ "ifnotexists ::= IF NOT EXISTS", - /* 56 */ "ifnotexists ::=", - /* 57 */ "cmd ::= CREATE DNODE ids PORT ids", - /* 58 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", - /* 59 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 60 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 61 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 62 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 63 */ "cmd ::= CREATE USER ids PASS ids", - /* 64 */ "bufsize ::=", - /* 65 */ "bufsize ::= BUFSIZE INTEGER", - /* 66 */ "pps ::=", - /* 67 */ "pps ::= PPS INTEGER", - /* 68 */ "tseries ::=", - /* 69 */ "tseries ::= TSERIES INTEGER", - /* 70 */ "dbs ::=", - /* 71 */ "dbs ::= DBS INTEGER", - /* 72 */ "streams ::=", - /* 73 */ "streams ::= STREAMS INTEGER", - /* 74 */ "storage ::=", - /* 75 */ "storage ::= STORAGE INTEGER", - /* 76 */ "qtime ::=", - /* 77 */ "qtime ::= QTIME INTEGER", - /* 78 */ "users ::=", - /* 79 */ "users ::= USERS INTEGER", - /* 80 */ "conns ::=", - /* 81 */ "conns ::= CONNS INTEGER", - /* 82 */ "state ::=", - /* 83 */ "state ::= STATE ids", - /* 84 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 85 */ "intitemlist ::= intitemlist COMMA intitem", - /* 86 */ "intitemlist ::= intitem", - /* 87 */ "intitem ::= INTEGER", - /* 88 */ "keep ::= KEEP intitemlist", - /* 89 */ "cache ::= CACHE INTEGER", - /* 90 */ "replica ::= REPLICA INTEGER", - /* 91 */ "quorum ::= QUORUM INTEGER", - /* 92 */ "days ::= DAYS INTEGER", - /* 93 */ "minrows ::= MINROWS INTEGER", - /* 94 */ "maxrows ::= MAXROWS INTEGER", - /* 95 */ "blocks ::= BLOCKS INTEGER", - /* 96 */ "ctime ::= CTIME INTEGER", - /* 97 */ "wal ::= WAL INTEGER", - /* 98 */ "fsync ::= FSYNC INTEGER", - /* 99 */ "comp ::= COMP INTEGER", - /* 100 */ "prec ::= PRECISION STRING", - /* 101 */ "update ::= UPDATE INTEGER", - /* 102 */ "cachelast ::= CACHELAST INTEGER", - /* 103 */ "vgroups ::= VGROUPS INTEGER", - /* 104 */ "db_optr ::=", - /* 105 */ "db_optr ::= db_optr cache", - /* 106 */ "db_optr ::= db_optr replica", - /* 107 */ "db_optr ::= db_optr quorum", - /* 108 */ "db_optr ::= db_optr days", - /* 109 */ "db_optr ::= db_optr minrows", - /* 110 */ "db_optr ::= db_optr maxrows", - /* 111 */ "db_optr ::= db_optr blocks", - /* 112 */ "db_optr ::= db_optr ctime", - /* 113 */ "db_optr ::= db_optr wal", - /* 114 */ "db_optr ::= db_optr fsync", - /* 115 */ "db_optr ::= db_optr comp", - /* 116 */ "db_optr ::= db_optr prec", - /* 117 */ "db_optr ::= db_optr keep", - /* 118 */ "db_optr ::= db_optr update", - /* 119 */ "db_optr ::= db_optr cachelast", - /* 120 */ "db_optr ::= db_optr vgroups", - /* 121 */ "alter_db_optr ::=", - /* 122 */ "alter_db_optr ::= alter_db_optr replica", - /* 123 */ "alter_db_optr ::= alter_db_optr quorum", - /* 124 */ "alter_db_optr ::= alter_db_optr keep", - /* 125 */ "alter_db_optr ::= alter_db_optr blocks", - /* 126 */ "alter_db_optr ::= alter_db_optr comp", - /* 127 */ "alter_db_optr ::= alter_db_optr update", - /* 128 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 129 */ "typename ::= ids", - /* 130 */ "typename ::= ids LP signed RP", - /* 131 */ "typename ::= ids UNSIGNED", - /* 132 */ "signed ::= INTEGER", - /* 133 */ "signed ::= PLUS INTEGER", - /* 134 */ "signed ::= MINUS INTEGER", - /* 135 */ "cmd ::= CREATE TABLE create_table_args", - /* 136 */ "cmd ::= CREATE TABLE create_stable_args", - /* 137 */ "cmd ::= CREATE STABLE create_stable_args", - /* 138 */ "cmd ::= CREATE TABLE create_table_list", - /* 139 */ "create_table_list ::= create_from_stable", - /* 140 */ "create_table_list ::= create_table_list create_from_stable", - /* 141 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 142 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", - /* 144 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", - /* 145 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 146 */ "tagNamelist ::= ids", - /* 147 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 148 */ "columnlist ::= columnlist COMMA column", - /* 149 */ "columnlist ::= column", - /* 150 */ "column ::= ids typename", - /* 151 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", - /* 152 */ "tagitemlist1 ::= tagitem1", - /* 153 */ "tagitem1 ::= MINUS INTEGER", - /* 154 */ "tagitem1 ::= MINUS FLOAT", - /* 155 */ "tagitem1 ::= PLUS INTEGER", - /* 156 */ "tagitem1 ::= PLUS FLOAT", - /* 157 */ "tagitem1 ::= INTEGER", - /* 158 */ "tagitem1 ::= FLOAT", - /* 159 */ "tagitem1 ::= STRING", - /* 160 */ "tagitem1 ::= BOOL", - /* 161 */ "tagitem1 ::= NULL", - /* 162 */ "tagitem1 ::= NOW", - /* 163 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 164 */ "tagitemlist ::= tagitem", - /* 165 */ "tagitem ::= INTEGER", - /* 166 */ "tagitem ::= FLOAT", - /* 167 */ "tagitem ::= STRING", - /* 168 */ "tagitem ::= BOOL", - /* 169 */ "tagitem ::= NULL", - /* 170 */ "tagitem ::= NOW", - /* 171 */ "tagitem ::= MINUS INTEGER", - /* 172 */ "tagitem ::= MINUS FLOAT", - /* 173 */ "tagitem ::= PLUS INTEGER", - /* 174 */ "tagitem ::= PLUS FLOAT", - /* 175 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", - /* 176 */ "select ::= LP select RP", - /* 177 */ "union ::= select", - /* 178 */ "union ::= union UNION ALL select", - /* 179 */ "union ::= union UNION select", - /* 180 */ "cmd ::= union", - /* 181 */ "select ::= SELECT selcollist", - /* 182 */ "sclp ::= selcollist COMMA", - /* 183 */ "sclp ::=", - /* 184 */ "selcollist ::= sclp distinct expr as", - /* 185 */ "selcollist ::= sclp STAR", - /* 186 */ "as ::= AS ids", - /* 187 */ "as ::= ids", - /* 188 */ "as ::=", - /* 189 */ "distinct ::= DISTINCT", - /* 190 */ "distinct ::=", - /* 191 */ "from ::= FROM tablelist", - /* 192 */ "from ::= FROM sub", - /* 193 */ "sub ::= LP union RP", - /* 194 */ "sub ::= LP union RP ids", - /* 195 */ "sub ::= sub COMMA LP union RP ids", - /* 196 */ "tablelist ::= ids cpxName", - /* 197 */ "tablelist ::= ids cpxName ids", - /* 198 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 199 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 200 */ "tmvar ::= VARIABLE", - /* 201 */ "interval_option ::= intervalKey LP tmvar RP", - /* 202 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 203 */ "interval_option ::=", - /* 204 */ "intervalKey ::= INTERVAL", - /* 205 */ "intervalKey ::= EVERY", - /* 206 */ "session_option ::=", - /* 207 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 208 */ "windowstate_option ::=", - /* 209 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 210 */ "fill_opt ::=", - /* 211 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 212 */ "fill_opt ::= FILL LP ID RP", - /* 213 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 214 */ "sliding_opt ::=", - /* 215 */ "orderby_opt ::=", - /* 216 */ "orderby_opt ::= ORDER BY sortlist", - /* 217 */ "sortlist ::= sortlist COMMA item sortorder", - /* 218 */ "sortlist ::= item sortorder", - /* 219 */ "item ::= ids cpxName", - /* 220 */ "sortorder ::= ASC", - /* 221 */ "sortorder ::= DESC", - /* 222 */ "sortorder ::=", - /* 223 */ "groupby_opt ::=", - /* 224 */ "groupby_opt ::= GROUP BY grouplist", - /* 225 */ "grouplist ::= grouplist COMMA item", - /* 226 */ "grouplist ::= item", - /* 227 */ "having_opt ::=", - /* 228 */ "having_opt ::= HAVING expr", - /* 229 */ "limit_opt ::=", - /* 230 */ "limit_opt ::= LIMIT signed", - /* 231 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 232 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 233 */ "slimit_opt ::=", - /* 234 */ "slimit_opt ::= SLIMIT signed", - /* 235 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 236 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 237 */ "where_opt ::=", - /* 238 */ "where_opt ::= WHERE expr", - /* 239 */ "expr ::= LP expr RP", - /* 240 */ "expr ::= ID", - /* 241 */ "expr ::= ID DOT ID", - /* 242 */ "expr ::= ID DOT STAR", - /* 243 */ "expr ::= INTEGER", - /* 244 */ "expr ::= MINUS INTEGER", - /* 245 */ "expr ::= PLUS INTEGER", - /* 246 */ "expr ::= FLOAT", - /* 247 */ "expr ::= MINUS FLOAT", - /* 248 */ "expr ::= PLUS FLOAT", - /* 249 */ "expr ::= STRING", - /* 250 */ "expr ::= NOW", - /* 251 */ "expr ::= VARIABLE", - /* 252 */ "expr ::= PLUS VARIABLE", - /* 253 */ "expr ::= MINUS VARIABLE", - /* 254 */ "expr ::= BOOL", - /* 255 */ "expr ::= NULL", - /* 256 */ "expr ::= ID LP exprlist RP", - /* 257 */ "expr ::= ID LP STAR RP", - /* 258 */ "expr ::= expr IS NULL", - /* 259 */ "expr ::= expr IS NOT NULL", - /* 260 */ "expr ::= expr LT expr", - /* 261 */ "expr ::= expr GT expr", - /* 262 */ "expr ::= expr LE expr", - /* 263 */ "expr ::= expr GE expr", - /* 264 */ "expr ::= expr NE expr", - /* 265 */ "expr ::= expr EQ expr", - /* 266 */ "expr ::= expr BETWEEN expr AND expr", - /* 267 */ "expr ::= expr AND expr", - /* 268 */ "expr ::= expr OR expr", - /* 269 */ "expr ::= expr PLUS expr", - /* 270 */ "expr ::= expr MINUS expr", - /* 271 */ "expr ::= expr STAR expr", - /* 272 */ "expr ::= expr SLASH expr", - /* 273 */ "expr ::= expr REM expr", - /* 274 */ "expr ::= expr LIKE expr", - /* 275 */ "expr ::= expr MATCH expr", - /* 276 */ "expr ::= expr NMATCH expr", - /* 277 */ "expr ::= expr IN LP exprlist RP", - /* 278 */ "exprlist ::= exprlist COMMA expritem", - /* 279 */ "exprlist ::= expritem", - /* 280 */ "expritem ::= expr", - /* 281 */ "expritem ::=", - /* 282 */ "cmd ::= RESET QUERY CACHE", - /* 283 */ "cmd ::= SYNCDB ids REPLICA", - /* 284 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 285 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 286 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 287 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 288 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 289 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 290 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 291 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 292 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 293 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 294 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 295 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 296 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 297 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 298 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 299 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 300 */ "cmd ::= KILL CONNECTION INTEGER", - /* 301 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 302 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 52 */ "ifexists ::= IF EXISTS", + /* 53 */ "ifexists ::=", + /* 54 */ "ifnotexists ::= IF NOT EXISTS", + /* 55 */ "ifnotexists ::=", + /* 56 */ "cmd ::= CREATE DNODE ids PORT ids", + /* 57 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", + /* 58 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", + /* 59 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", + /* 60 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 61 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 62 */ "cmd ::= CREATE USER ids PASS ids", + /* 63 */ "bufsize ::=", + /* 64 */ "bufsize ::= BUFSIZE INTEGER", + /* 65 */ "pps ::=", + /* 66 */ "pps ::= PPS INTEGER", + /* 67 */ "tseries ::=", + /* 68 */ "tseries ::= TSERIES INTEGER", + /* 69 */ "dbs ::=", + /* 70 */ "dbs ::= DBS INTEGER", + /* 71 */ "streams ::=", + /* 72 */ "streams ::= STREAMS INTEGER", + /* 73 */ "storage ::=", + /* 74 */ "storage ::= STORAGE INTEGER", + /* 75 */ "qtime ::=", + /* 76 */ "qtime ::= QTIME INTEGER", + /* 77 */ "users ::=", + /* 78 */ "users ::= USERS INTEGER", + /* 79 */ "conns ::=", + /* 80 */ "conns ::= CONNS INTEGER", + /* 81 */ "state ::=", + /* 82 */ "state ::= STATE ids", + /* 83 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", + /* 84 */ "intitemlist ::= intitemlist COMMA intitem", + /* 85 */ "intitemlist ::= intitem", + /* 86 */ "intitem ::= INTEGER", + /* 87 */ "keep ::= KEEP intitemlist", + /* 88 */ "cache ::= CACHE INTEGER", + /* 89 */ "replica ::= REPLICA INTEGER", + /* 90 */ "quorum ::= QUORUM INTEGER", + /* 91 */ "days ::= DAYS INTEGER", + /* 92 */ "minrows ::= MINROWS INTEGER", + /* 93 */ "maxrows ::= MAXROWS INTEGER", + /* 94 */ "blocks ::= BLOCKS INTEGER", + /* 95 */ "ctime ::= CTIME INTEGER", + /* 96 */ "wal ::= WAL INTEGER", + /* 97 */ "fsync ::= FSYNC INTEGER", + /* 98 */ "comp ::= COMP INTEGER", + /* 99 */ "prec ::= PRECISION STRING", + /* 100 */ "update ::= UPDATE INTEGER", + /* 101 */ "cachelast ::= CACHELAST INTEGER", + /* 102 */ "vgroups ::= VGROUPS INTEGER", + /* 103 */ "db_optr ::=", + /* 104 */ "db_optr ::= db_optr cache", + /* 105 */ "db_optr ::= db_optr replica", + /* 106 */ "db_optr ::= db_optr quorum", + /* 107 */ "db_optr ::= db_optr days", + /* 108 */ "db_optr ::= db_optr minrows", + /* 109 */ "db_optr ::= db_optr maxrows", + /* 110 */ "db_optr ::= db_optr blocks", + /* 111 */ "db_optr ::= db_optr ctime", + /* 112 */ "db_optr ::= db_optr wal", + /* 113 */ "db_optr ::= db_optr fsync", + /* 114 */ "db_optr ::= db_optr comp", + /* 115 */ "db_optr ::= db_optr prec", + /* 116 */ "db_optr ::= db_optr keep", + /* 117 */ "db_optr ::= db_optr update", + /* 118 */ "db_optr ::= db_optr cachelast", + /* 119 */ "db_optr ::= db_optr vgroups", + /* 120 */ "alter_db_optr ::=", + /* 121 */ "alter_db_optr ::= alter_db_optr replica", + /* 122 */ "alter_db_optr ::= alter_db_optr quorum", + /* 123 */ "alter_db_optr ::= alter_db_optr keep", + /* 124 */ "alter_db_optr ::= alter_db_optr blocks", + /* 125 */ "alter_db_optr ::= alter_db_optr comp", + /* 126 */ "alter_db_optr ::= alter_db_optr update", + /* 127 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 128 */ "typename ::= ids", + /* 129 */ "typename ::= ids LP signed RP", + /* 130 */ "typename ::= ids UNSIGNED", + /* 131 */ "signed ::= INTEGER", + /* 132 */ "signed ::= PLUS INTEGER", + /* 133 */ "signed ::= MINUS INTEGER", + /* 134 */ "cmd ::= CREATE TABLE create_table_args", + /* 135 */ "cmd ::= CREATE TABLE create_stable_args", + /* 136 */ "cmd ::= CREATE STABLE create_stable_args", + /* 137 */ "cmd ::= CREATE TABLE create_table_list", + /* 138 */ "create_table_list ::= create_from_stable", + /* 139 */ "create_table_list ::= create_table_list create_from_stable", + /* 140 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 141 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 142 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", + /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", + /* 144 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 145 */ "tagNamelist ::= ids", + /* 146 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 147 */ "columnlist ::= columnlist COMMA column", + /* 148 */ "columnlist ::= column", + /* 149 */ "column ::= ids typename", + /* 150 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", + /* 151 */ "tagitemlist1 ::= tagitem1", + /* 152 */ "tagitem1 ::= MINUS INTEGER", + /* 153 */ "tagitem1 ::= MINUS FLOAT", + /* 154 */ "tagitem1 ::= PLUS INTEGER", + /* 155 */ "tagitem1 ::= PLUS FLOAT", + /* 156 */ "tagitem1 ::= INTEGER", + /* 157 */ "tagitem1 ::= FLOAT", + /* 158 */ "tagitem1 ::= STRING", + /* 159 */ "tagitem1 ::= BOOL", + /* 160 */ "tagitem1 ::= NULL", + /* 161 */ "tagitem1 ::= NOW", + /* 162 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 163 */ "tagitemlist ::= tagitem", + /* 164 */ "tagitem ::= INTEGER", + /* 165 */ "tagitem ::= FLOAT", + /* 166 */ "tagitem ::= STRING", + /* 167 */ "tagitem ::= BOOL", + /* 168 */ "tagitem ::= NULL", + /* 169 */ "tagitem ::= NOW", + /* 170 */ "tagitem ::= MINUS INTEGER", + /* 171 */ "tagitem ::= MINUS FLOAT", + /* 172 */ "tagitem ::= PLUS INTEGER", + /* 173 */ "tagitem ::= PLUS FLOAT", + /* 174 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 175 */ "select ::= LP select RP", + /* 176 */ "union ::= select", + /* 177 */ "union ::= union UNION ALL select", + /* 178 */ "union ::= union UNION select", + /* 179 */ "cmd ::= union", + /* 180 */ "select ::= SELECT selcollist", + /* 181 */ "sclp ::= selcollist COMMA", + /* 182 */ "sclp ::=", + /* 183 */ "selcollist ::= sclp distinct expr as", + /* 184 */ "selcollist ::= sclp STAR", + /* 185 */ "as ::= AS ids", + /* 186 */ "as ::= ids", + /* 187 */ "as ::=", + /* 188 */ "distinct ::= DISTINCT", + /* 189 */ "distinct ::=", + /* 190 */ "from ::= FROM tablelist", + /* 191 */ "from ::= FROM sub", + /* 192 */ "sub ::= LP union RP", + /* 193 */ "sub ::= LP union RP ids", + /* 194 */ "sub ::= sub COMMA LP union RP ids", + /* 195 */ "tablelist ::= ids cpxName", + /* 196 */ "tablelist ::= ids cpxName ids", + /* 197 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 198 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 199 */ "tmvar ::= VARIABLE", + /* 200 */ "interval_option ::= intervalKey LP tmvar RP", + /* 201 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 202 */ "interval_option ::=", + /* 203 */ "intervalKey ::= INTERVAL", + /* 204 */ "intervalKey ::= EVERY", + /* 205 */ "session_option ::=", + /* 206 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 207 */ "windowstate_option ::=", + /* 208 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 209 */ "fill_opt ::=", + /* 210 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 211 */ "fill_opt ::= FILL LP ID RP", + /* 212 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 213 */ "sliding_opt ::=", + /* 214 */ "orderby_opt ::=", + /* 215 */ "orderby_opt ::= ORDER BY sortlist", + /* 216 */ "sortlist ::= sortlist COMMA item sortorder", + /* 217 */ "sortlist ::= item sortorder", + /* 218 */ "item ::= ids cpxName", + /* 219 */ "sortorder ::= ASC", + /* 220 */ "sortorder ::= DESC", + /* 221 */ "sortorder ::=", + /* 222 */ "groupby_opt ::=", + /* 223 */ "groupby_opt ::= GROUP BY grouplist", + /* 224 */ "grouplist ::= grouplist COMMA item", + /* 225 */ "grouplist ::= item", + /* 226 */ "having_opt ::=", + /* 227 */ "having_opt ::= HAVING expr", + /* 228 */ "limit_opt ::=", + /* 229 */ "limit_opt ::= LIMIT signed", + /* 230 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 231 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 232 */ "slimit_opt ::=", + /* 233 */ "slimit_opt ::= SLIMIT signed", + /* 234 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 235 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 236 */ "where_opt ::=", + /* 237 */ "where_opt ::= WHERE expr", + /* 238 */ "expr ::= LP expr RP", + /* 239 */ "expr ::= ID", + /* 240 */ "expr ::= ID DOT ID", + /* 241 */ "expr ::= ID DOT STAR", + /* 242 */ "expr ::= INTEGER", + /* 243 */ "expr ::= MINUS INTEGER", + /* 244 */ "expr ::= PLUS INTEGER", + /* 245 */ "expr ::= FLOAT", + /* 246 */ "expr ::= MINUS FLOAT", + /* 247 */ "expr ::= PLUS FLOAT", + /* 248 */ "expr ::= STRING", + /* 249 */ "expr ::= NOW", + /* 250 */ "expr ::= VARIABLE", + /* 251 */ "expr ::= PLUS VARIABLE", + /* 252 */ "expr ::= MINUS VARIABLE", + /* 253 */ "expr ::= BOOL", + /* 254 */ "expr ::= NULL", + /* 255 */ "expr ::= ID LP exprlist RP", + /* 256 */ "expr ::= ID LP STAR RP", + /* 257 */ "expr ::= expr IS NULL", + /* 258 */ "expr ::= expr IS NOT NULL", + /* 259 */ "expr ::= expr LT expr", + /* 260 */ "expr ::= expr GT expr", + /* 261 */ "expr ::= expr LE expr", + /* 262 */ "expr ::= expr GE expr", + /* 263 */ "expr ::= expr NE expr", + /* 264 */ "expr ::= expr EQ expr", + /* 265 */ "expr ::= expr BETWEEN expr AND expr", + /* 266 */ "expr ::= expr AND expr", + /* 267 */ "expr ::= expr OR expr", + /* 268 */ "expr ::= expr PLUS expr", + /* 269 */ "expr ::= expr MINUS expr", + /* 270 */ "expr ::= expr STAR expr", + /* 271 */ "expr ::= expr SLASH expr", + /* 272 */ "expr ::= expr REM expr", + /* 273 */ "expr ::= expr LIKE expr", + /* 274 */ "expr ::= expr MATCH expr", + /* 275 */ "expr ::= expr NMATCH expr", + /* 276 */ "expr ::= expr IN LP exprlist RP", + /* 277 */ "exprlist ::= exprlist COMMA expritem", + /* 278 */ "exprlist ::= expritem", + /* 279 */ "expritem ::= expr", + /* 280 */ "expritem ::=", + /* 281 */ "cmd ::= RESET QUERY CACHE", + /* 282 */ "cmd ::= SYNCDB ids REPLICA", + /* 283 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 284 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 285 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 286 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 287 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 288 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 289 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 290 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 291 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 292 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 293 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 294 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 295 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 296 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 297 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 298 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 299 */ "cmd ::= KILL CONNECTION INTEGER", + /* 300 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 301 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1893,257 +1890,256 @@ static const struct { { 193, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ { 193, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ { 194, -1 }, /* (51) ids ::= ID */ - { 194, -1 }, /* (52) ids ::= STRING */ - { 197, -2 }, /* (53) ifexists ::= IF EXISTS */ - { 197, 0 }, /* (54) ifexists ::= */ - { 201, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ - { 201, 0 }, /* (56) ifnotexists ::= */ - { 193, -5 }, /* (57) cmd ::= CREATE DNODE ids PORT ids */ - { 193, -5 }, /* (58) cmd ::= CREATE DNODE IPTOKEN PORT ids */ - { 193, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 193, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 193, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ - { 204, 0 }, /* (64) bufsize ::= */ - { 204, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ - { 205, 0 }, /* (66) pps ::= */ - { 205, -2 }, /* (67) pps ::= PPS INTEGER */ - { 206, 0 }, /* (68) tseries ::= */ - { 206, -2 }, /* (69) tseries ::= TSERIES INTEGER */ - { 207, 0 }, /* (70) dbs ::= */ - { 207, -2 }, /* (71) dbs ::= DBS INTEGER */ - { 208, 0 }, /* (72) streams ::= */ - { 208, -2 }, /* (73) streams ::= STREAMS INTEGER */ - { 209, 0 }, /* (74) storage ::= */ - { 209, -2 }, /* (75) storage ::= STORAGE INTEGER */ - { 210, 0 }, /* (76) qtime ::= */ - { 210, -2 }, /* (77) qtime ::= QTIME INTEGER */ - { 211, 0 }, /* (78) users ::= */ - { 211, -2 }, /* (79) users ::= USERS INTEGER */ - { 212, 0 }, /* (80) conns ::= */ - { 212, -2 }, /* (81) conns ::= CONNS INTEGER */ - { 213, 0 }, /* (82) state ::= */ - { 213, -2 }, /* (83) state ::= STATE ids */ - { 199, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 214, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ - { 214, -1 }, /* (86) intitemlist ::= intitem */ - { 215, -1 }, /* (87) intitem ::= INTEGER */ - { 216, -2 }, /* (88) keep ::= KEEP intitemlist */ - { 217, -2 }, /* (89) cache ::= CACHE INTEGER */ - { 218, -2 }, /* (90) replica ::= REPLICA INTEGER */ - { 219, -2 }, /* (91) quorum ::= QUORUM INTEGER */ - { 220, -2 }, /* (92) days ::= DAYS INTEGER */ - { 221, -2 }, /* (93) minrows ::= MINROWS INTEGER */ - { 222, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ - { 223, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ - { 224, -2 }, /* (96) ctime ::= CTIME INTEGER */ - { 225, -2 }, /* (97) wal ::= WAL INTEGER */ - { 226, -2 }, /* (98) fsync ::= FSYNC INTEGER */ - { 227, -2 }, /* (99) comp ::= COMP INTEGER */ - { 228, -2 }, /* (100) prec ::= PRECISION STRING */ - { 229, -2 }, /* (101) update ::= UPDATE INTEGER */ - { 230, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ - { 231, -2 }, /* (103) vgroups ::= VGROUPS INTEGER */ - { 202, 0 }, /* (104) db_optr ::= */ - { 202, -2 }, /* (105) db_optr ::= db_optr cache */ - { 202, -2 }, /* (106) db_optr ::= db_optr replica */ - { 202, -2 }, /* (107) db_optr ::= db_optr quorum */ - { 202, -2 }, /* (108) db_optr ::= db_optr days */ - { 202, -2 }, /* (109) db_optr ::= db_optr minrows */ - { 202, -2 }, /* (110) db_optr ::= db_optr maxrows */ - { 202, -2 }, /* (111) db_optr ::= db_optr blocks */ - { 202, -2 }, /* (112) db_optr ::= db_optr ctime */ - { 202, -2 }, /* (113) db_optr ::= db_optr wal */ - { 202, -2 }, /* (114) db_optr ::= db_optr fsync */ - { 202, -2 }, /* (115) db_optr ::= db_optr comp */ - { 202, -2 }, /* (116) db_optr ::= db_optr prec */ - { 202, -2 }, /* (117) db_optr ::= db_optr keep */ - { 202, -2 }, /* (118) db_optr ::= db_optr update */ - { 202, -2 }, /* (119) db_optr ::= db_optr cachelast */ - { 202, -2 }, /* (120) db_optr ::= db_optr vgroups */ - { 198, 0 }, /* (121) alter_db_optr ::= */ - { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr replica */ - { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr quorum */ - { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr keep */ - { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr blocks */ - { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr comp */ - { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr update */ - { 198, -2 }, /* (128) alter_db_optr ::= alter_db_optr cachelast */ - { 203, -1 }, /* (129) typename ::= ids */ - { 203, -4 }, /* (130) typename ::= ids LP signed RP */ - { 203, -2 }, /* (131) typename ::= ids UNSIGNED */ - { 232, -1 }, /* (132) signed ::= INTEGER */ - { 232, -2 }, /* (133) signed ::= PLUS INTEGER */ - { 232, -2 }, /* (134) signed ::= MINUS INTEGER */ - { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_table_args */ - { 193, -3 }, /* (136) cmd ::= CREATE TABLE create_stable_args */ - { 193, -3 }, /* (137) cmd ::= CREATE STABLE create_stable_args */ - { 193, -3 }, /* (138) cmd ::= CREATE TABLE create_table_list */ - { 235, -1 }, /* (139) create_table_list ::= create_from_stable */ - { 235, -2 }, /* (140) create_table_list ::= create_table_list create_from_stable */ - { 233, -6 }, /* (141) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 234, -10 }, /* (142) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 236, -10 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ - { 236, -13 }, /* (144) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ - { 239, -3 }, /* (145) tagNamelist ::= tagNamelist COMMA ids */ - { 239, -1 }, /* (146) tagNamelist ::= ids */ - { 233, -5 }, /* (147) create_table_args ::= ifnotexists ids cpxName AS select */ - { 237, -3 }, /* (148) columnlist ::= columnlist COMMA column */ - { 237, -1 }, /* (149) columnlist ::= column */ - { 241, -2 }, /* (150) column ::= ids typename */ - { 238, -3 }, /* (151) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ - { 238, -1 }, /* (152) tagitemlist1 ::= tagitem1 */ - { 242, -2 }, /* (153) tagitem1 ::= MINUS INTEGER */ - { 242, -2 }, /* (154) tagitem1 ::= MINUS FLOAT */ - { 242, -2 }, /* (155) tagitem1 ::= PLUS INTEGER */ - { 242, -2 }, /* (156) tagitem1 ::= PLUS FLOAT */ - { 242, -1 }, /* (157) tagitem1 ::= INTEGER */ - { 242, -1 }, /* (158) tagitem1 ::= FLOAT */ - { 242, -1 }, /* (159) tagitem1 ::= STRING */ - { 242, -1 }, /* (160) tagitem1 ::= BOOL */ - { 242, -1 }, /* (161) tagitem1 ::= NULL */ - { 242, -1 }, /* (162) tagitem1 ::= NOW */ - { 243, -3 }, /* (163) tagitemlist ::= tagitemlist COMMA tagitem */ - { 243, -1 }, /* (164) tagitemlist ::= tagitem */ - { 244, -1 }, /* (165) tagitem ::= INTEGER */ - { 244, -1 }, /* (166) tagitem ::= FLOAT */ - { 244, -1 }, /* (167) tagitem ::= STRING */ - { 244, -1 }, /* (168) tagitem ::= BOOL */ - { 244, -1 }, /* (169) tagitem ::= NULL */ - { 244, -1 }, /* (170) tagitem ::= NOW */ - { 244, -2 }, /* (171) tagitem ::= MINUS INTEGER */ - { 244, -2 }, /* (172) tagitem ::= MINUS FLOAT */ - { 244, -2 }, /* (173) tagitem ::= PLUS INTEGER */ - { 244, -2 }, /* (174) tagitem ::= PLUS FLOAT */ - { 240, -14 }, /* (175) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 240, -3 }, /* (176) select ::= LP select RP */ - { 258, -1 }, /* (177) union ::= select */ - { 258, -4 }, /* (178) union ::= union UNION ALL select */ - { 258, -3 }, /* (179) union ::= union UNION select */ - { 193, -1 }, /* (180) cmd ::= union */ - { 240, -2 }, /* (181) select ::= SELECT selcollist */ - { 259, -2 }, /* (182) sclp ::= selcollist COMMA */ - { 259, 0 }, /* (183) sclp ::= */ - { 245, -4 }, /* (184) selcollist ::= sclp distinct expr as */ - { 245, -2 }, /* (185) selcollist ::= sclp STAR */ - { 262, -2 }, /* (186) as ::= AS ids */ - { 262, -1 }, /* (187) as ::= ids */ - { 262, 0 }, /* (188) as ::= */ - { 260, -1 }, /* (189) distinct ::= DISTINCT */ - { 260, 0 }, /* (190) distinct ::= */ - { 246, -2 }, /* (191) from ::= FROM tablelist */ - { 246, -2 }, /* (192) from ::= FROM sub */ - { 264, -3 }, /* (193) sub ::= LP union RP */ - { 264, -4 }, /* (194) sub ::= LP union RP ids */ - { 264, -6 }, /* (195) sub ::= sub COMMA LP union RP ids */ - { 263, -2 }, /* (196) tablelist ::= ids cpxName */ - { 263, -3 }, /* (197) tablelist ::= ids cpxName ids */ - { 263, -4 }, /* (198) tablelist ::= tablelist COMMA ids cpxName */ - { 263, -5 }, /* (199) tablelist ::= tablelist COMMA ids cpxName ids */ - { 265, -1 }, /* (200) tmvar ::= VARIABLE */ - { 248, -4 }, /* (201) interval_option ::= intervalKey LP tmvar RP */ - { 248, -6 }, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 248, 0 }, /* (203) interval_option ::= */ - { 266, -1 }, /* (204) intervalKey ::= INTERVAL */ - { 266, -1 }, /* (205) intervalKey ::= EVERY */ - { 250, 0 }, /* (206) session_option ::= */ - { 250, -7 }, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 251, 0 }, /* (208) windowstate_option ::= */ - { 251, -4 }, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 252, 0 }, /* (210) fill_opt ::= */ - { 252, -6 }, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 252, -4 }, /* (212) fill_opt ::= FILL LP ID RP */ - { 249, -4 }, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ - { 249, 0 }, /* (214) sliding_opt ::= */ - { 255, 0 }, /* (215) orderby_opt ::= */ - { 255, -3 }, /* (216) orderby_opt ::= ORDER BY sortlist */ - { 267, -4 }, /* (217) sortlist ::= sortlist COMMA item sortorder */ - { 267, -2 }, /* (218) sortlist ::= item sortorder */ - { 269, -2 }, /* (219) item ::= ids cpxName */ - { 270, -1 }, /* (220) sortorder ::= ASC */ - { 270, -1 }, /* (221) sortorder ::= DESC */ - { 270, 0 }, /* (222) sortorder ::= */ - { 253, 0 }, /* (223) groupby_opt ::= */ - { 253, -3 }, /* (224) groupby_opt ::= GROUP BY grouplist */ - { 271, -3 }, /* (225) grouplist ::= grouplist COMMA item */ - { 271, -1 }, /* (226) grouplist ::= item */ - { 254, 0 }, /* (227) having_opt ::= */ - { 254, -2 }, /* (228) having_opt ::= HAVING expr */ - { 257, 0 }, /* (229) limit_opt ::= */ - { 257, -2 }, /* (230) limit_opt ::= LIMIT signed */ - { 257, -4 }, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ - { 257, -4 }, /* (232) limit_opt ::= LIMIT signed COMMA signed */ - { 256, 0 }, /* (233) slimit_opt ::= */ - { 256, -2 }, /* (234) slimit_opt ::= SLIMIT signed */ - { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 256, -4 }, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ - { 247, 0 }, /* (237) where_opt ::= */ - { 247, -2 }, /* (238) where_opt ::= WHERE expr */ - { 261, -3 }, /* (239) expr ::= LP expr RP */ - { 261, -1 }, /* (240) expr ::= ID */ - { 261, -3 }, /* (241) expr ::= ID DOT ID */ - { 261, -3 }, /* (242) expr ::= ID DOT STAR */ - { 261, -1 }, /* (243) expr ::= INTEGER */ - { 261, -2 }, /* (244) expr ::= MINUS INTEGER */ - { 261, -2 }, /* (245) expr ::= PLUS INTEGER */ - { 261, -1 }, /* (246) expr ::= FLOAT */ - { 261, -2 }, /* (247) expr ::= MINUS FLOAT */ - { 261, -2 }, /* (248) expr ::= PLUS FLOAT */ - { 261, -1 }, /* (249) expr ::= STRING */ - { 261, -1 }, /* (250) expr ::= NOW */ - { 261, -1 }, /* (251) expr ::= VARIABLE */ - { 261, -2 }, /* (252) expr ::= PLUS VARIABLE */ - { 261, -2 }, /* (253) expr ::= MINUS VARIABLE */ - { 261, -1 }, /* (254) expr ::= BOOL */ - { 261, -1 }, /* (255) expr ::= NULL */ - { 261, -4 }, /* (256) expr ::= ID LP exprlist RP */ - { 261, -4 }, /* (257) expr ::= ID LP STAR RP */ - { 261, -3 }, /* (258) expr ::= expr IS NULL */ - { 261, -4 }, /* (259) expr ::= expr IS NOT NULL */ - { 261, -3 }, /* (260) expr ::= expr LT expr */ - { 261, -3 }, /* (261) expr ::= expr GT expr */ - { 261, -3 }, /* (262) expr ::= expr LE expr */ - { 261, -3 }, /* (263) expr ::= expr GE expr */ - { 261, -3 }, /* (264) expr ::= expr NE expr */ - { 261, -3 }, /* (265) expr ::= expr EQ expr */ - { 261, -5 }, /* (266) expr ::= expr BETWEEN expr AND expr */ - { 261, -3 }, /* (267) expr ::= expr AND expr */ - { 261, -3 }, /* (268) expr ::= expr OR expr */ - { 261, -3 }, /* (269) expr ::= expr PLUS expr */ - { 261, -3 }, /* (270) expr ::= expr MINUS expr */ - { 261, -3 }, /* (271) expr ::= expr STAR expr */ - { 261, -3 }, /* (272) expr ::= expr SLASH expr */ - { 261, -3 }, /* (273) expr ::= expr REM expr */ - { 261, -3 }, /* (274) expr ::= expr LIKE expr */ - { 261, -3 }, /* (275) expr ::= expr MATCH expr */ - { 261, -3 }, /* (276) expr ::= expr NMATCH expr */ - { 261, -5 }, /* (277) expr ::= expr IN LP exprlist RP */ - { 200, -3 }, /* (278) exprlist ::= exprlist COMMA expritem */ - { 200, -1 }, /* (279) exprlist ::= expritem */ - { 272, -1 }, /* (280) expritem ::= expr */ - { 272, 0 }, /* (281) expritem ::= */ - { 193, -3 }, /* (282) cmd ::= RESET QUERY CACHE */ - { 193, -3 }, /* (283) cmd ::= SYNCDB ids REPLICA */ - { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 193, -3 }, /* (300) cmd ::= KILL CONNECTION INTEGER */ - { 193, -5 }, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 193, -5 }, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 197, -2 }, /* (52) ifexists ::= IF EXISTS */ + { 197, 0 }, /* (53) ifexists ::= */ + { 201, -3 }, /* (54) ifnotexists ::= IF NOT EXISTS */ + { 201, 0 }, /* (55) ifnotexists ::= */ + { 193, -5 }, /* (56) cmd ::= CREATE DNODE ids PORT ids */ + { 193, -5 }, /* (57) cmd ::= CREATE DNODE IPTOKEN PORT ids */ + { 193, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 193, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 193, -8 }, /* (60) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -9 }, /* (61) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -5 }, /* (62) cmd ::= CREATE USER ids PASS ids */ + { 204, 0 }, /* (63) bufsize ::= */ + { 204, -2 }, /* (64) bufsize ::= BUFSIZE INTEGER */ + { 205, 0 }, /* (65) pps ::= */ + { 205, -2 }, /* (66) pps ::= PPS INTEGER */ + { 206, 0 }, /* (67) tseries ::= */ + { 206, -2 }, /* (68) tseries ::= TSERIES INTEGER */ + { 207, 0 }, /* (69) dbs ::= */ + { 207, -2 }, /* (70) dbs ::= DBS INTEGER */ + { 208, 0 }, /* (71) streams ::= */ + { 208, -2 }, /* (72) streams ::= STREAMS INTEGER */ + { 209, 0 }, /* (73) storage ::= */ + { 209, -2 }, /* (74) storage ::= STORAGE INTEGER */ + { 210, 0 }, /* (75) qtime ::= */ + { 210, -2 }, /* (76) qtime ::= QTIME INTEGER */ + { 211, 0 }, /* (77) users ::= */ + { 211, -2 }, /* (78) users ::= USERS INTEGER */ + { 212, 0 }, /* (79) conns ::= */ + { 212, -2 }, /* (80) conns ::= CONNS INTEGER */ + { 213, 0 }, /* (81) state ::= */ + { 213, -2 }, /* (82) state ::= STATE ids */ + { 199, -9 }, /* (83) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 214, -3 }, /* (84) intitemlist ::= intitemlist COMMA intitem */ + { 214, -1 }, /* (85) intitemlist ::= intitem */ + { 215, -1 }, /* (86) intitem ::= INTEGER */ + { 216, -2 }, /* (87) keep ::= KEEP intitemlist */ + { 217, -2 }, /* (88) cache ::= CACHE INTEGER */ + { 218, -2 }, /* (89) replica ::= REPLICA INTEGER */ + { 219, -2 }, /* (90) quorum ::= QUORUM INTEGER */ + { 220, -2 }, /* (91) days ::= DAYS INTEGER */ + { 221, -2 }, /* (92) minrows ::= MINROWS INTEGER */ + { 222, -2 }, /* (93) maxrows ::= MAXROWS INTEGER */ + { 223, -2 }, /* (94) blocks ::= BLOCKS INTEGER */ + { 224, -2 }, /* (95) ctime ::= CTIME INTEGER */ + { 225, -2 }, /* (96) wal ::= WAL INTEGER */ + { 226, -2 }, /* (97) fsync ::= FSYNC INTEGER */ + { 227, -2 }, /* (98) comp ::= COMP INTEGER */ + { 228, -2 }, /* (99) prec ::= PRECISION STRING */ + { 229, -2 }, /* (100) update ::= UPDATE INTEGER */ + { 230, -2 }, /* (101) cachelast ::= CACHELAST INTEGER */ + { 231, -2 }, /* (102) vgroups ::= VGROUPS INTEGER */ + { 202, 0 }, /* (103) db_optr ::= */ + { 202, -2 }, /* (104) db_optr ::= db_optr cache */ + { 202, -2 }, /* (105) db_optr ::= db_optr replica */ + { 202, -2 }, /* (106) db_optr ::= db_optr quorum */ + { 202, -2 }, /* (107) db_optr ::= db_optr days */ + { 202, -2 }, /* (108) db_optr ::= db_optr minrows */ + { 202, -2 }, /* (109) db_optr ::= db_optr maxrows */ + { 202, -2 }, /* (110) db_optr ::= db_optr blocks */ + { 202, -2 }, /* (111) db_optr ::= db_optr ctime */ + { 202, -2 }, /* (112) db_optr ::= db_optr wal */ + { 202, -2 }, /* (113) db_optr ::= db_optr fsync */ + { 202, -2 }, /* (114) db_optr ::= db_optr comp */ + { 202, -2 }, /* (115) db_optr ::= db_optr prec */ + { 202, -2 }, /* (116) db_optr ::= db_optr keep */ + { 202, -2 }, /* (117) db_optr ::= db_optr update */ + { 202, -2 }, /* (118) db_optr ::= db_optr cachelast */ + { 202, -2 }, /* (119) db_optr ::= db_optr vgroups */ + { 198, 0 }, /* (120) alter_db_optr ::= */ + { 198, -2 }, /* (121) alter_db_optr ::= alter_db_optr replica */ + { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr quorum */ + { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr keep */ + { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr blocks */ + { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr comp */ + { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr update */ + { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr cachelast */ + { 203, -1 }, /* (128) typename ::= ids */ + { 203, -4 }, /* (129) typename ::= ids LP signed RP */ + { 203, -2 }, /* (130) typename ::= ids UNSIGNED */ + { 232, -1 }, /* (131) signed ::= INTEGER */ + { 232, -2 }, /* (132) signed ::= PLUS INTEGER */ + { 232, -2 }, /* (133) signed ::= MINUS INTEGER */ + { 193, -3 }, /* (134) cmd ::= CREATE TABLE create_table_args */ + { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_stable_args */ + { 193, -3 }, /* (136) cmd ::= CREATE STABLE create_stable_args */ + { 193, -3 }, /* (137) cmd ::= CREATE TABLE create_table_list */ + { 235, -1 }, /* (138) create_table_list ::= create_from_stable */ + { 235, -2 }, /* (139) create_table_list ::= create_table_list create_from_stable */ + { 233, -6 }, /* (140) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 234, -10 }, /* (141) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 236, -10 }, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + { 236, -13 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + { 239, -3 }, /* (144) tagNamelist ::= tagNamelist COMMA ids */ + { 239, -1 }, /* (145) tagNamelist ::= ids */ + { 233, -5 }, /* (146) create_table_args ::= ifnotexists ids cpxName AS select */ + { 237, -3 }, /* (147) columnlist ::= columnlist COMMA column */ + { 237, -1 }, /* (148) columnlist ::= column */ + { 241, -2 }, /* (149) column ::= ids typename */ + { 238, -3 }, /* (150) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + { 238, -1 }, /* (151) tagitemlist1 ::= tagitem1 */ + { 242, -2 }, /* (152) tagitem1 ::= MINUS INTEGER */ + { 242, -2 }, /* (153) tagitem1 ::= MINUS FLOAT */ + { 242, -2 }, /* (154) tagitem1 ::= PLUS INTEGER */ + { 242, -2 }, /* (155) tagitem1 ::= PLUS FLOAT */ + { 242, -1 }, /* (156) tagitem1 ::= INTEGER */ + { 242, -1 }, /* (157) tagitem1 ::= FLOAT */ + { 242, -1 }, /* (158) tagitem1 ::= STRING */ + { 242, -1 }, /* (159) tagitem1 ::= BOOL */ + { 242, -1 }, /* (160) tagitem1 ::= NULL */ + { 242, -1 }, /* (161) tagitem1 ::= NOW */ + { 243, -3 }, /* (162) tagitemlist ::= tagitemlist COMMA tagitem */ + { 243, -1 }, /* (163) tagitemlist ::= tagitem */ + { 244, -1 }, /* (164) tagitem ::= INTEGER */ + { 244, -1 }, /* (165) tagitem ::= FLOAT */ + { 244, -1 }, /* (166) tagitem ::= STRING */ + { 244, -1 }, /* (167) tagitem ::= BOOL */ + { 244, -1 }, /* (168) tagitem ::= NULL */ + { 244, -1 }, /* (169) tagitem ::= NOW */ + { 244, -2 }, /* (170) tagitem ::= MINUS INTEGER */ + { 244, -2 }, /* (171) tagitem ::= MINUS FLOAT */ + { 244, -2 }, /* (172) tagitem ::= PLUS INTEGER */ + { 244, -2 }, /* (173) tagitem ::= PLUS FLOAT */ + { 240, -14 }, /* (174) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + { 240, -3 }, /* (175) select ::= LP select RP */ + { 258, -1 }, /* (176) union ::= select */ + { 258, -4 }, /* (177) union ::= union UNION ALL select */ + { 258, -3 }, /* (178) union ::= union UNION select */ + { 193, -1 }, /* (179) cmd ::= union */ + { 240, -2 }, /* (180) select ::= SELECT selcollist */ + { 259, -2 }, /* (181) sclp ::= selcollist COMMA */ + { 259, 0 }, /* (182) sclp ::= */ + { 245, -4 }, /* (183) selcollist ::= sclp distinct expr as */ + { 245, -2 }, /* (184) selcollist ::= sclp STAR */ + { 262, -2 }, /* (185) as ::= AS ids */ + { 262, -1 }, /* (186) as ::= ids */ + { 262, 0 }, /* (187) as ::= */ + { 260, -1 }, /* (188) distinct ::= DISTINCT */ + { 260, 0 }, /* (189) distinct ::= */ + { 246, -2 }, /* (190) from ::= FROM tablelist */ + { 246, -2 }, /* (191) from ::= FROM sub */ + { 264, -3 }, /* (192) sub ::= LP union RP */ + { 264, -4 }, /* (193) sub ::= LP union RP ids */ + { 264, -6 }, /* (194) sub ::= sub COMMA LP union RP ids */ + { 263, -2 }, /* (195) tablelist ::= ids cpxName */ + { 263, -3 }, /* (196) tablelist ::= ids cpxName ids */ + { 263, -4 }, /* (197) tablelist ::= tablelist COMMA ids cpxName */ + { 263, -5 }, /* (198) tablelist ::= tablelist COMMA ids cpxName ids */ + { 265, -1 }, /* (199) tmvar ::= VARIABLE */ + { 248, -4 }, /* (200) interval_option ::= intervalKey LP tmvar RP */ + { 248, -6 }, /* (201) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + { 248, 0 }, /* (202) interval_option ::= */ + { 266, -1 }, /* (203) intervalKey ::= INTERVAL */ + { 266, -1 }, /* (204) intervalKey ::= EVERY */ + { 250, 0 }, /* (205) session_option ::= */ + { 250, -7 }, /* (206) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 251, 0 }, /* (207) windowstate_option ::= */ + { 251, -4 }, /* (208) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 252, 0 }, /* (209) fill_opt ::= */ + { 252, -6 }, /* (210) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 252, -4 }, /* (211) fill_opt ::= FILL LP ID RP */ + { 249, -4 }, /* (212) sliding_opt ::= SLIDING LP tmvar RP */ + { 249, 0 }, /* (213) sliding_opt ::= */ + { 255, 0 }, /* (214) orderby_opt ::= */ + { 255, -3 }, /* (215) orderby_opt ::= ORDER BY sortlist */ + { 267, -4 }, /* (216) sortlist ::= sortlist COMMA item sortorder */ + { 267, -2 }, /* (217) sortlist ::= item sortorder */ + { 269, -2 }, /* (218) item ::= ids cpxName */ + { 270, -1 }, /* (219) sortorder ::= ASC */ + { 270, -1 }, /* (220) sortorder ::= DESC */ + { 270, 0 }, /* (221) sortorder ::= */ + { 253, 0 }, /* (222) groupby_opt ::= */ + { 253, -3 }, /* (223) groupby_opt ::= GROUP BY grouplist */ + { 271, -3 }, /* (224) grouplist ::= grouplist COMMA item */ + { 271, -1 }, /* (225) grouplist ::= item */ + { 254, 0 }, /* (226) having_opt ::= */ + { 254, -2 }, /* (227) having_opt ::= HAVING expr */ + { 257, 0 }, /* (228) limit_opt ::= */ + { 257, -2 }, /* (229) limit_opt ::= LIMIT signed */ + { 257, -4 }, /* (230) limit_opt ::= LIMIT signed OFFSET signed */ + { 257, -4 }, /* (231) limit_opt ::= LIMIT signed COMMA signed */ + { 256, 0 }, /* (232) slimit_opt ::= */ + { 256, -2 }, /* (233) slimit_opt ::= SLIMIT signed */ + { 256, -4 }, /* (234) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed COMMA signed */ + { 247, 0 }, /* (236) where_opt ::= */ + { 247, -2 }, /* (237) where_opt ::= WHERE expr */ + { 261, -3 }, /* (238) expr ::= LP expr RP */ + { 261, -1 }, /* (239) expr ::= ID */ + { 261, -3 }, /* (240) expr ::= ID DOT ID */ + { 261, -3 }, /* (241) expr ::= ID DOT STAR */ + { 261, -1 }, /* (242) expr ::= INTEGER */ + { 261, -2 }, /* (243) expr ::= MINUS INTEGER */ + { 261, -2 }, /* (244) expr ::= PLUS INTEGER */ + { 261, -1 }, /* (245) expr ::= FLOAT */ + { 261, -2 }, /* (246) expr ::= MINUS FLOAT */ + { 261, -2 }, /* (247) expr ::= PLUS FLOAT */ + { 261, -1 }, /* (248) expr ::= STRING */ + { 261, -1 }, /* (249) expr ::= NOW */ + { 261, -1 }, /* (250) expr ::= VARIABLE */ + { 261, -2 }, /* (251) expr ::= PLUS VARIABLE */ + { 261, -2 }, /* (252) expr ::= MINUS VARIABLE */ + { 261, -1 }, /* (253) expr ::= BOOL */ + { 261, -1 }, /* (254) expr ::= NULL */ + { 261, -4 }, /* (255) expr ::= ID LP exprlist RP */ + { 261, -4 }, /* (256) expr ::= ID LP STAR RP */ + { 261, -3 }, /* (257) expr ::= expr IS NULL */ + { 261, -4 }, /* (258) expr ::= expr IS NOT NULL */ + { 261, -3 }, /* (259) expr ::= expr LT expr */ + { 261, -3 }, /* (260) expr ::= expr GT expr */ + { 261, -3 }, /* (261) expr ::= expr LE expr */ + { 261, -3 }, /* (262) expr ::= expr GE expr */ + { 261, -3 }, /* (263) expr ::= expr NE expr */ + { 261, -3 }, /* (264) expr ::= expr EQ expr */ + { 261, -5 }, /* (265) expr ::= expr BETWEEN expr AND expr */ + { 261, -3 }, /* (266) expr ::= expr AND expr */ + { 261, -3 }, /* (267) expr ::= expr OR expr */ + { 261, -3 }, /* (268) expr ::= expr PLUS expr */ + { 261, -3 }, /* (269) expr ::= expr MINUS expr */ + { 261, -3 }, /* (270) expr ::= expr STAR expr */ + { 261, -3 }, /* (271) expr ::= expr SLASH expr */ + { 261, -3 }, /* (272) expr ::= expr REM expr */ + { 261, -3 }, /* (273) expr ::= expr LIKE expr */ + { 261, -3 }, /* (274) expr ::= expr MATCH expr */ + { 261, -3 }, /* (275) expr ::= expr NMATCH expr */ + { 261, -5 }, /* (276) expr ::= expr IN LP exprlist RP */ + { 200, -3 }, /* (277) exprlist ::= exprlist COMMA expritem */ + { 200, -1 }, /* (278) exprlist ::= expritem */ + { 272, -1 }, /* (279) expritem ::= expr */ + { 272, 0 }, /* (280) expritem ::= */ + { 193, -3 }, /* (281) cmd ::= RESET QUERY CACHE */ + { 193, -3 }, /* (282) cmd ::= SYNCDB ids REPLICA */ + { 193, -7 }, /* (283) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (288) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (289) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (290) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 193, -7 }, /* (291) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (296) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (297) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (298) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 193, -3 }, /* (299) cmd ::= KILL CONNECTION INTEGER */ + { 193, -5 }, /* (300) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 193, -5 }, /* (301) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2224,9 +2220,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 135: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==135); - case 136: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==136); - case 137: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==137); + case 134: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==134); + case 135: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==135); + case 136: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==136); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2414,65 +2410,64 @@ static void yy_reduce( { setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy165);} break; case 51: /* ids ::= ID */ - case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); {yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 53: /* ifexists ::= IF EXISTS */ + case 52: /* ifexists ::= IF EXISTS */ { yymsp[-1].minor.yy0.n = 1;} break; - case 54: /* ifexists ::= */ - case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); - case 190: /* distinct ::= */ yytestcase(yyruleno==190); + case 53: /* ifexists ::= */ + case 55: /* ifnotexists ::= */ yytestcase(yyruleno==55); + case 189: /* distinct ::= */ yytestcase(yyruleno==189); { yymsp[1].minor.yy0.n = 0;} break; - case 55: /* ifnotexists ::= IF NOT EXISTS */ + case 54: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 57: /* cmd ::= CREATE DNODE ids PORT ids */ - case 58: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==58); + case 56: /* cmd ::= CREATE DNODE ids PORT ids */ + case 57: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==57); { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 59: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + case 58: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; - case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy16, &yymsp[-2].minor.yy0);} break; - case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 60: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 1);} break; - case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 61: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 2);} break; - case 63: /* cmd ::= CREATE USER ids PASS ids */ + case 62: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 64: /* bufsize ::= */ - case 66: /* pps ::= */ yytestcase(yyruleno==66); - case 68: /* tseries ::= */ yytestcase(yyruleno==68); - case 70: /* dbs ::= */ yytestcase(yyruleno==70); - case 72: /* streams ::= */ yytestcase(yyruleno==72); - case 74: /* storage ::= */ yytestcase(yyruleno==74); - case 76: /* qtime ::= */ yytestcase(yyruleno==76); - case 78: /* users ::= */ yytestcase(yyruleno==78); - case 80: /* conns ::= */ yytestcase(yyruleno==80); - case 82: /* state ::= */ yytestcase(yyruleno==82); + case 63: /* bufsize ::= */ + case 65: /* pps ::= */ yytestcase(yyruleno==65); + case 67: /* tseries ::= */ yytestcase(yyruleno==67); + case 69: /* dbs ::= */ yytestcase(yyruleno==69); + case 71: /* streams ::= */ yytestcase(yyruleno==71); + case 73: /* storage ::= */ yytestcase(yyruleno==73); + case 75: /* qtime ::= */ yytestcase(yyruleno==75); + case 77: /* users ::= */ yytestcase(yyruleno==77); + case 79: /* conns ::= */ yytestcase(yyruleno==79); + case 81: /* state ::= */ yytestcase(yyruleno==81); { yymsp[1].minor.yy0.n = 0; } break; - case 65: /* bufsize ::= BUFSIZE INTEGER */ - case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); - case 69: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==69); - case 71: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==71); - case 73: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==73); - case 75: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==75); - case 77: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==77); - case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); - case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); - case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); + case 64: /* bufsize ::= BUFSIZE INTEGER */ + case 66: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==66); + case 68: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==68); + case 70: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==70); + case 72: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==72); + case 74: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==74); + case 76: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==76); + case 78: /* users ::= USERS INTEGER */ yytestcase(yyruleno==78); + case 80: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==80); + case 82: /* state ::= STATE ids */ yytestcase(yyruleno==82); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + case 83: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { yylhsminor.yy211.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; yylhsminor.yy211.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; @@ -2486,129 +2481,129 @@ static void yy_reduce( } yymsp[-8].minor.yy211 = yylhsminor.yy211; break; - case 85: /* intitemlist ::= intitemlist COMMA intitem */ - case 163: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==163); + case 84: /* intitemlist ::= intitemlist COMMA intitem */ + case 162: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==162); { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 86: /* intitemlist ::= intitem */ - case 164: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==164); + case 85: /* intitemlist ::= intitem */ + case 163: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==163); { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 87: /* intitem ::= INTEGER */ - case 165: /* tagitem ::= INTEGER */ yytestcase(yyruleno==165); - case 166: /* tagitem ::= FLOAT */ yytestcase(yyruleno==166); - case 167: /* tagitem ::= STRING */ yytestcase(yyruleno==167); - case 168: /* tagitem ::= BOOL */ yytestcase(yyruleno==168); + case 86: /* intitem ::= INTEGER */ + case 164: /* tagitem ::= INTEGER */ yytestcase(yyruleno==164); + case 165: /* tagitem ::= FLOAT */ yytestcase(yyruleno==165); + case 166: /* tagitem ::= STRING */ yytestcase(yyruleno==166); + case 167: /* tagitem ::= BOOL */ yytestcase(yyruleno==167); { toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 88: /* keep ::= KEEP intitemlist */ + case 87: /* keep ::= KEEP intitemlist */ { yymsp[-1].minor.yy165 = yymsp[0].minor.yy165; } break; - case 89: /* cache ::= CACHE INTEGER */ - case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); - case 91: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==91); - case 92: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==92); - case 93: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==93); - case 94: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==94); - case 95: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==95); - case 96: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==96); - case 97: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==97); - case 98: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==98); - case 99: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==99); - case 100: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==100); - case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); - case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); - case 103: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==103); + case 88: /* cache ::= CACHE INTEGER */ + case 89: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==89); + case 90: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==90); + case 91: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==91); + case 92: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==92); + case 93: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==93); + case 94: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==94); + case 95: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==95); + case 96: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==96); + case 97: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==97); + case 98: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==98); + case 99: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==99); + case 100: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==100); + case 101: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==101); + case 102: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==102); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 104: /* db_optr ::= */ + case 103: /* db_optr ::= */ {setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 105: /* db_optr ::= db_optr cache */ + case 104: /* db_optr ::= db_optr cache */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 106: /* db_optr ::= db_optr replica */ - case 122: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==122); + case 105: /* db_optr ::= db_optr replica */ + case 121: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==121); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 107: /* db_optr ::= db_optr quorum */ - case 123: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==123); + case 106: /* db_optr ::= db_optr quorum */ + case 122: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==122); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 108: /* db_optr ::= db_optr days */ + case 107: /* db_optr ::= db_optr days */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 109: /* db_optr ::= db_optr minrows */ + case 108: /* db_optr ::= db_optr minrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 110: /* db_optr ::= db_optr maxrows */ + case 109: /* db_optr ::= db_optr maxrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 111: /* db_optr ::= db_optr blocks */ - case 125: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==125); + case 110: /* db_optr ::= db_optr blocks */ + case 124: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==124); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 112: /* db_optr ::= db_optr ctime */ + case 111: /* db_optr ::= db_optr ctime */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 113: /* db_optr ::= db_optr wal */ + case 112: /* db_optr ::= db_optr wal */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 114: /* db_optr ::= db_optr fsync */ + case 113: /* db_optr ::= db_optr fsync */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 115: /* db_optr ::= db_optr comp */ - case 126: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==126); + case 114: /* db_optr ::= db_optr comp */ + case 125: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==125); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 116: /* db_optr ::= db_optr prec */ + case 115: /* db_optr ::= db_optr prec */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.precision = yymsp[0].minor.yy0; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 117: /* db_optr ::= db_optr keep */ - case 124: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==124); + case 116: /* db_optr ::= db_optr keep */ + case 123: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==123); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.keep = yymsp[0].minor.yy165; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 118: /* db_optr ::= db_optr update */ - case 127: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==127); + case 117: /* db_optr ::= db_optr update */ + case 126: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==126); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 119: /* db_optr ::= db_optr cachelast */ - case 128: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==128); + case 118: /* db_optr ::= db_optr cachelast */ + case 127: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==127); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 120: /* db_optr ::= db_optr vgroups */ + case 119: /* db_optr ::= db_optr vgroups */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfVgroups = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 121: /* alter_db_optr ::= */ + case 120: /* alter_db_optr ::= */ { setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 129: /* typename ::= ids */ + case 128: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; tSetColumnType (&yylhsminor.yy106, &yymsp[0].minor.yy0); } yymsp[0].minor.yy106 = yylhsminor.yy106; break; - case 130: /* typename ::= ids LP signed RP */ + case 129: /* typename ::= ids LP signed RP */ { if (yymsp[-1].minor.yy207 <= 0) { yymsp[-3].minor.yy0.type = 0; @@ -2620,7 +2615,7 @@ static void yy_reduce( } yymsp[-3].minor.yy106 = yylhsminor.yy106; break; - case 131: /* typename ::= ids UNSIGNED */ + case 130: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); @@ -2628,20 +2623,20 @@ static void yy_reduce( } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 132: /* signed ::= INTEGER */ + case 131: /* signed ::= INTEGER */ { yylhsminor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[0].minor.yy207 = yylhsminor.yy207; break; - case 133: /* signed ::= PLUS INTEGER */ + case 132: /* signed ::= PLUS INTEGER */ { yymsp[-1].minor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 134: /* signed ::= MINUS INTEGER */ + case 133: /* signed ::= MINUS INTEGER */ { yymsp[-1].minor.yy207 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 138: /* cmd ::= CREATE TABLE create_table_list */ + case 137: /* cmd ::= CREATE TABLE create_table_list */ { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy326;} break; - case 139: /* create_table_list ::= create_from_stable */ + case 138: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); @@ -2652,14 +2647,14 @@ static void yy_reduce( } yymsp[0].minor.yy326 = yylhsminor.yy326; break; - case 140: /* create_table_list ::= create_table_list create_from_stable */ + case 139: /* create_table_list ::= create_table_list create_from_stable */ { taosArrayPush(yymsp[-1].minor.yy326->childTableInfo, &yymsp[0].minor.yy150); yylhsminor.yy326 = yymsp[-1].minor.yy326; } yymsp[-1].minor.yy326 = yylhsminor.yy326; break; - case 141: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 140: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); @@ -2669,17 +2664,17 @@ static void yy_reduce( } yymsp[-5].minor.yy326 = yylhsminor.yy326; break; - case 142: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 141: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_STABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } yymsp[-9].minor.yy326 = yylhsminor.yy326; break; - case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + case 142: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; @@ -2687,7 +2682,7 @@ static void yy_reduce( } yymsp[-9].minor.yy150 = yylhsminor.yy150; break; - case 144: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; @@ -2695,15 +2690,15 @@ static void yy_reduce( } yymsp[-12].minor.yy150 = yylhsminor.yy150; break; - case 145: /* tagNamelist ::= tagNamelist COMMA ids */ + case 144: /* tagNamelist ::= tagNamelist COMMA ids */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 146: /* tagNamelist ::= ids */ + case 145: /* tagNamelist ::= ids */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 147: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 146: /* create_table_args ::= ifnotexists ids cpxName AS select */ { yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); @@ -2713,56 +2708,56 @@ static void yy_reduce( } yymsp[-4].minor.yy326 = yylhsminor.yy326; break; - case 148: /* columnlist ::= columnlist COMMA column */ + case 147: /* columnlist ::= columnlist COMMA column */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy106); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 149: /* columnlist ::= column */ + case 148: /* columnlist ::= column */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy106);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 150: /* column ::= ids typename */ + case 149: /* column ::= ids typename */ { tSetColumnInfo(&yylhsminor.yy106, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy106); } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 151: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + case 150: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ { taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165;} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 152: /* tagitemlist1 ::= tagitem1 */ + case 151: /* tagitemlist1 ::= tagitem1 */ { yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 153: /* tagitem1 ::= MINUS INTEGER */ - case 154: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==154); - case 155: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==155); - case 156: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==156); + case 152: /* tagitem1 ::= MINUS INTEGER */ + case 153: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==153); + case 154: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==154); + case 155: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==155); { yylhsminor.yy0.n = yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n; yylhsminor.yy0.type = yymsp[0].minor.yy0.type; } yymsp[-1].minor.yy0 = yylhsminor.yy0; break; - case 157: /* tagitem1 ::= INTEGER */ - case 158: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==158); - case 159: /* tagitem1 ::= STRING */ yytestcase(yyruleno==159); - case 160: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==160); - case 161: /* tagitem1 ::= NULL */ yytestcase(yyruleno==161); - case 162: /* tagitem1 ::= NOW */ yytestcase(yyruleno==162); + case 156: /* tagitem1 ::= INTEGER */ + case 157: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==157); + case 158: /* tagitem1 ::= STRING */ yytestcase(yyruleno==158); + case 159: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==159); + case 160: /* tagitem1 ::= NULL */ yytestcase(yyruleno==160); + case 161: /* tagitem1 ::= NOW */ yytestcase(yyruleno==161); { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 169: /* tagitem ::= NULL */ + case 168: /* tagitem ::= NULL */ { yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 170: /* tagitem ::= NOW */ + case 169: /* tagitem ::= NOW */ { yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 171: /* tagitem ::= MINUS INTEGER */ - case 172: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==172); - case 173: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==173); - case 174: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==174); + case 170: /* tagitem ::= MINUS INTEGER */ + case 171: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==171); + case 172: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==172); + case 173: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==173); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; @@ -2771,154 +2766,154 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 175: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 174: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy165, yymsp[-11].minor.yy10, yymsp[-10].minor.yy202, yymsp[-4].minor.yy165, yymsp[-2].minor.yy165, &yymsp[-9].minor.yy532, &yymsp[-7].minor.yy97, &yymsp[-6].minor.yy6, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy165, &yymsp[0].minor.yy367, &yymsp[-1].minor.yy367, yymsp[-3].minor.yy202); } yymsp[-13].minor.yy278 = yylhsminor.yy278; break; - case 176: /* select ::= LP select RP */ + case 175: /* select ::= LP select RP */ {yymsp[-2].minor.yy278 = yymsp[-1].minor.yy278;} break; - case 177: /* union ::= select */ + case 176: /* union ::= select */ { yylhsminor.yy503 = setSubclause(NULL, yymsp[0].minor.yy278); } yymsp[0].minor.yy503 = yylhsminor.yy503; break; - case 178: /* union ::= union UNION ALL select */ + case 177: /* union ::= union UNION ALL select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-3].minor.yy503, SQL_TYPE_UNIONALL, yymsp[0].minor.yy278); } yymsp[-3].minor.yy503 = yylhsminor.yy503; break; - case 179: /* union ::= union UNION select */ + case 178: /* union ::= union UNION select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-2].minor.yy503, SQL_TYPE_UNION, yymsp[0].minor.yy278); } yymsp[-2].minor.yy503 = yylhsminor.yy503; break; - case 180: /* cmd ::= union */ + case 179: /* cmd ::= union */ { setSqlInfo(pInfo, yymsp[0].minor.yy503, NULL, TSDB_SQL_SELECT); } break; - case 181: /* select ::= SELECT selcollist */ + case 180: /* select ::= SELECT selcollist */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy165, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } yymsp[-1].minor.yy278 = yylhsminor.yy278; break; - case 182: /* sclp ::= selcollist COMMA */ + case 181: /* sclp ::= selcollist COMMA */ {yylhsminor.yy165 = yymsp[-1].minor.yy165;} yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 183: /* sclp ::= */ - case 215: /* orderby_opt ::= */ yytestcase(yyruleno==215); + case 182: /* sclp ::= */ + case 214: /* orderby_opt ::= */ yytestcase(yyruleno==214); {yymsp[1].minor.yy165 = 0;} break; - case 184: /* selcollist ::= sclp distinct expr as */ + case 183: /* selcollist ::= sclp distinct expr as */ { yylhsminor.yy165 = tSqlExprListAppend(yymsp[-3].minor.yy165, yymsp[-1].minor.yy202, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 185: /* selcollist ::= sclp STAR */ + case 184: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); yylhsminor.yy165 = tSqlExprListAppend(yymsp[-1].minor.yy165, pNode, 0, 0); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 186: /* as ::= AS ids */ + case 185: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 187: /* as ::= ids */ + case 186: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 188: /* as ::= */ + case 187: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 189: /* distinct ::= DISTINCT */ + case 188: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 191: /* from ::= FROM tablelist */ - case 192: /* from ::= FROM sub */ yytestcase(yyruleno==192); + case 190: /* from ::= FROM tablelist */ + case 191: /* from ::= FROM sub */ yytestcase(yyruleno==191); {yymsp[-1].minor.yy10 = yymsp[0].minor.yy10;} break; - case 193: /* sub ::= LP union RP */ + case 192: /* sub ::= LP union RP */ {yymsp[-2].minor.yy10 = addSubquery(NULL, yymsp[-1].minor.yy503, NULL);} break; - case 194: /* sub ::= LP union RP ids */ + case 193: /* sub ::= LP union RP ids */ {yymsp[-3].minor.yy10 = addSubquery(NULL, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} break; - case 195: /* sub ::= sub COMMA LP union RP ids */ + case 194: /* sub ::= sub COMMA LP union RP ids */ {yylhsminor.yy10 = addSubquery(yymsp[-5].minor.yy10, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} yymsp[-5].minor.yy10 = yylhsminor.yy10; break; - case 196: /* tablelist ::= ids cpxName */ + case 195: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } yymsp[-1].minor.yy10 = yylhsminor.yy10; break; - case 197: /* tablelist ::= ids cpxName ids */ + case 196: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy10 = yylhsminor.yy10; break; - case 198: /* tablelist ::= tablelist COMMA ids cpxName */ + case 197: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-3].minor.yy10, &yymsp[-1].minor.yy0, NULL); } yymsp[-3].minor.yy10 = yylhsminor.yy10; break; - case 199: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 198: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-4].minor.yy10, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-4].minor.yy10 = yylhsminor.yy10; break; - case 200: /* tmvar ::= VARIABLE */ + case 199: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 201: /* interval_option ::= intervalKey LP tmvar RP */ + case 200: /* interval_option ::= intervalKey LP tmvar RP */ {yylhsminor.yy532.interval = yymsp[-1].minor.yy0; yylhsminor.yy532.offset.n = 0; yylhsminor.yy532.token = yymsp[-3].minor.yy46;} yymsp[-3].minor.yy532 = yylhsminor.yy532; break; - case 202: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + case 201: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ {yylhsminor.yy532.interval = yymsp[-3].minor.yy0; yylhsminor.yy532.offset = yymsp[-1].minor.yy0; yylhsminor.yy532.token = yymsp[-5].minor.yy46;} yymsp[-5].minor.yy532 = yylhsminor.yy532; break; - case 203: /* interval_option ::= */ + case 202: /* interval_option ::= */ {memset(&yymsp[1].minor.yy532, 0, sizeof(yymsp[1].minor.yy532));} break; - case 204: /* intervalKey ::= INTERVAL */ + case 203: /* intervalKey ::= INTERVAL */ {yymsp[0].minor.yy46 = TK_INTERVAL;} break; - case 205: /* intervalKey ::= EVERY */ + case 204: /* intervalKey ::= EVERY */ {yymsp[0].minor.yy46 = TK_EVERY; } break; - case 206: /* session_option ::= */ + case 205: /* session_option ::= */ {yymsp[1].minor.yy97.col.n = 0; yymsp[1].minor.yy97.gap.n = 0;} break; - case 207: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 206: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-6].minor.yy97.col = yymsp[-4].minor.yy0; yymsp[-6].minor.yy97.gap = yymsp[-1].minor.yy0; } break; - case 208: /* windowstate_option ::= */ + case 207: /* windowstate_option ::= */ { yymsp[1].minor.yy6.col.n = 0; yymsp[1].minor.yy6.col.z = NULL;} break; - case 209: /* windowstate_option ::= STATE_WINDOW LP ids RP */ + case 208: /* windowstate_option ::= STATE_WINDOW LP ids RP */ { yymsp[-3].minor.yy6.col = yymsp[-1].minor.yy0; } break; - case 210: /* fill_opt ::= */ + case 209: /* fill_opt ::= */ { yymsp[1].minor.yy165 = 0; } break; - case 211: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 210: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { SVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); @@ -2928,34 +2923,34 @@ static void yy_reduce( yymsp[-5].minor.yy165 = yymsp[-1].minor.yy165; } break; - case 212: /* fill_opt ::= FILL LP ID RP */ + case 211: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-3].minor.yy165 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 213: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 212: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 214: /* sliding_opt ::= */ + case 213: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 216: /* orderby_opt ::= ORDER BY sortlist */ + case 215: /* orderby_opt ::= ORDER BY sortlist */ {yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 217: /* sortlist ::= sortlist COMMA item sortorder */ + case 216: /* sortlist ::= sortlist COMMA item sortorder */ { yylhsminor.yy165 = tListItemAppend(yymsp[-3].minor.yy165, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 218: /* sortlist ::= item sortorder */ + case 217: /* sortlist ::= item sortorder */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 219: /* item ::= ids cpxName */ + case 218: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2964,235 +2959,235 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 220: /* sortorder ::= ASC */ + case 219: /* sortorder ::= ASC */ { yymsp[0].minor.yy47 = TSDB_ORDER_ASC; } break; - case 221: /* sortorder ::= DESC */ + case 220: /* sortorder ::= DESC */ { yymsp[0].minor.yy47 = TSDB_ORDER_DESC;} break; - case 222: /* sortorder ::= */ + case 221: /* sortorder ::= */ { yymsp[1].minor.yy47 = TSDB_ORDER_ASC; } break; - case 223: /* groupby_opt ::= */ + case 222: /* groupby_opt ::= */ { yymsp[1].minor.yy165 = 0;} break; - case 224: /* groupby_opt ::= GROUP BY grouplist */ + case 223: /* groupby_opt ::= GROUP BY grouplist */ { yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 225: /* grouplist ::= grouplist COMMA item */ + case 224: /* grouplist ::= grouplist COMMA item */ { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 226: /* grouplist ::= item */ + case 225: /* grouplist ::= item */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 227: /* having_opt ::= */ - case 237: /* where_opt ::= */ yytestcase(yyruleno==237); - case 281: /* expritem ::= */ yytestcase(yyruleno==281); + case 226: /* having_opt ::= */ + case 236: /* where_opt ::= */ yytestcase(yyruleno==236); + case 280: /* expritem ::= */ yytestcase(yyruleno==280); {yymsp[1].minor.yy202 = 0;} break; - case 228: /* having_opt ::= HAVING expr */ - case 238: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==238); + case 227: /* having_opt ::= HAVING expr */ + case 237: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==237); {yymsp[-1].minor.yy202 = yymsp[0].minor.yy202;} break; - case 229: /* limit_opt ::= */ - case 233: /* slimit_opt ::= */ yytestcase(yyruleno==233); + case 228: /* limit_opt ::= */ + case 232: /* slimit_opt ::= */ yytestcase(yyruleno==232); {yymsp[1].minor.yy367.limit = -1; yymsp[1].minor.yy367.offset = 0;} break; - case 230: /* limit_opt ::= LIMIT signed */ - case 234: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==234); + case 229: /* limit_opt ::= LIMIT signed */ + case 233: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==233); {yymsp[-1].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-1].minor.yy367.offset = 0;} break; - case 231: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 230: /* limit_opt ::= LIMIT signed OFFSET signed */ { yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 232: /* limit_opt ::= LIMIT signed COMMA signed */ + case 231: /* limit_opt ::= LIMIT signed COMMA signed */ { yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 235: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ + case 234: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ {yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 236: /* slimit_opt ::= SLIMIT signed COMMA signed */ + case 235: /* slimit_opt ::= SLIMIT signed COMMA signed */ {yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 239: /* expr ::= LP expr RP */ + case 238: /* expr ::= LP expr RP */ {yylhsminor.yy202 = yymsp[-1].minor.yy202; yylhsminor.yy202->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy202->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 240: /* expr ::= ID */ + case 239: /* expr ::= ID */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 241: /* expr ::= ID DOT ID */ + case 240: /* expr ::= ID DOT ID */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 242: /* expr ::= ID DOT STAR */ + case 241: /* expr ::= ID DOT STAR */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 243: /* expr ::= INTEGER */ + case 242: /* expr ::= INTEGER */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 244: /* expr ::= MINUS INTEGER */ - case 245: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==245); + case 243: /* expr ::= MINUS INTEGER */ + case 244: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==244); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 246: /* expr ::= FLOAT */ + case 245: /* expr ::= FLOAT */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 247: /* expr ::= MINUS FLOAT */ - case 248: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==248); + case 246: /* expr ::= MINUS FLOAT */ + case 247: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==247); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 249: /* expr ::= STRING */ + case 248: /* expr ::= STRING */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 250: /* expr ::= NOW */ + case 249: /* expr ::= NOW */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 251: /* expr ::= VARIABLE */ + case 250: /* expr ::= VARIABLE */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 252: /* expr ::= PLUS VARIABLE */ - case 253: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==253); + case 251: /* expr ::= PLUS VARIABLE */ + case 252: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==252); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 254: /* expr ::= BOOL */ + case 253: /* expr ::= BOOL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 255: /* expr ::= NULL */ + case 254: /* expr ::= NULL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 256: /* expr ::= ID LP exprlist RP */ + case 255: /* expr ::= ID LP exprlist RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(yymsp[-1].minor.yy165, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 257: /* expr ::= ID LP STAR RP */ + case 256: /* expr ::= ID LP STAR RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 258: /* expr ::= expr IS NULL */ + case 257: /* expr ::= expr IS NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, NULL, TK_ISNULL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 259: /* expr ::= expr IS NOT NULL */ + case 258: /* expr ::= expr IS NOT NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-3].minor.yy202, NULL, TK_NOTNULL);} yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 260: /* expr ::= expr LT expr */ + case 259: /* expr ::= expr LT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 261: /* expr ::= expr GT expr */ + case 260: /* expr ::= expr GT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 262: /* expr ::= expr LE expr */ + case 261: /* expr ::= expr LE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 263: /* expr ::= expr GE expr */ + case 262: /* expr ::= expr GE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 264: /* expr ::= expr NE expr */ + case 263: /* expr ::= expr NE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 265: /* expr ::= expr EQ expr */ + case 264: /* expr ::= expr EQ expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_EQ);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 266: /* expr ::= expr BETWEEN expr AND expr */ + case 265: /* expr ::= expr BETWEEN expr AND expr */ { tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy202); yylhsminor.yy202 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy202, yymsp[-2].minor.yy202, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy202, TK_LE), TK_AND);} yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 267: /* expr ::= expr AND expr */ + case 266: /* expr ::= expr AND expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_AND);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 268: /* expr ::= expr OR expr */ + case 267: /* expr ::= expr OR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_OR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 269: /* expr ::= expr PLUS expr */ + case 268: /* expr ::= expr PLUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_PLUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 270: /* expr ::= expr MINUS expr */ + case 269: /* expr ::= expr MINUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MINUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 271: /* expr ::= expr STAR expr */ + case 270: /* expr ::= expr STAR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_STAR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 272: /* expr ::= expr SLASH expr */ + case 271: /* expr ::= expr SLASH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_DIVIDE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 273: /* expr ::= expr REM expr */ + case 272: /* expr ::= expr REM expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_REM); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 274: /* expr ::= expr LIKE expr */ + case 273: /* expr ::= expr LIKE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LIKE); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 275: /* expr ::= expr MATCH expr */ + case 274: /* expr ::= expr MATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 276: /* expr ::= expr NMATCH expr */ + case 275: /* expr ::= expr NMATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NMATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 277: /* expr ::= expr IN LP exprlist RP */ + case 276: /* expr ::= expr IN LP exprlist RP */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-4].minor.yy202, (tSqlExpr*)yymsp[-1].minor.yy165, TK_IN); } yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 278: /* exprlist ::= exprlist COMMA expritem */ + case 277: /* exprlist ::= exprlist COMMA expritem */ {yylhsminor.yy165 = tSqlExprListAppend(yymsp[-2].minor.yy165,yymsp[0].minor.yy202,0, 0);} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 279: /* exprlist ::= expritem */ + case 278: /* exprlist ::= expritem */ {yylhsminor.yy165 = tSqlExprListAppend(0,yymsp[0].minor.yy202,0, 0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 280: /* expritem ::= expr */ + case 279: /* expritem ::= expr */ {yylhsminor.yy202 = yymsp[0].minor.yy202;} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 282: /* cmd ::= RESET QUERY CACHE */ + case 281: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 283: /* cmd ::= SYNCDB ids REPLICA */ + case 282: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 284: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 283: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 284: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); @@ -3201,21 +3196,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 286: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 285: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 287: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 286: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 288: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 287: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3226,7 +3221,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 289: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 288: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3240,7 +3235,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 290: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 289: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3252,21 +3247,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 291: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 290: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 292: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 291: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 293: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 292: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3277,21 +3272,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 294: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 293: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 295: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 294: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 296: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 295: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3302,7 +3297,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 297: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 296: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3316,7 +3311,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 298: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 297: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3328,20 +3323,20 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 299: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 298: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 300: /* cmd ::= KILL CONNECTION INTEGER */ + case 299: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 301: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 300: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 302: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 301: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index a68102ea6e..4b248f90e7 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -70,6 +70,11 @@ typedef struct SQueryPlanNode { struct SQueryPlanNode *pParent; } SQueryPlanNode; +typedef struct SDataPayloadInfo { + int32_t msgType; + SArray *payload; +} SDataPayloadInfo; + /** * Optimize the query execution plan, currently not implement yet. * @param pQueryNode diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index 5f95f86d4a..2de0ae2da3 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -37,18 +37,28 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { return 0; } -static int32_t createInsertPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { +static int32_t createModificationOpPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { SInsertStmtInfo* pInsert = (SInsertStmtInfo*)pNode; *pQueryPlan = calloc(1, sizeof(SQueryPlanNode)); SArray* blocks = taosArrayInit(taosArrayGetSize(pInsert->pDataBlocks), POINTER_BYTES); - if (NULL == *pQueryPlan || NULL == blocks) { + + SDataPayloadInfo* pPayload = calloc(1, sizeof(SDataPayloadInfo)); + if (NULL == *pQueryPlan || NULL == blocks || NULL == pPayload) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } (*pQueryPlan)->info.type = QNODE_MODIFY; taosArrayAddAll(blocks, pInsert->pDataBlocks); - (*pQueryPlan)->pExtInfo = blocks; + + if (pNode->type == TSDB_SQL_INSERT) { + pPayload->msgType = TDMT_VND_SUBMIT; + } else if (pNode->type == TSDB_SQL_CREATE_TABLE) { + pPayload->msgType = TDMT_VND_CREATE_TABLE; + } + + pPayload->payload = blocks; + (*pQueryPlan)->pExtInfo = pPayload; return TSDB_CODE_SUCCESS; } @@ -69,7 +79,7 @@ int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { case TSDB_SQL_INSERT: case TSDB_SQL_CREATE_TABLE: - return createInsertPlan(pNode, pQueryPlan); + return createModificationOpPlan(pNode, pQueryPlan); default: return TSDB_CODE_FAILED; diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 978b1554f3..9e1eea2b35 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -191,13 +191,15 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { subplan->level = 0; if (NULL != pCxt->pCurrentSubplan) { subplan->level = pCxt->pCurrentSubplan->level + 1; - if (NULL == pCxt->pCurrentSubplan->pChildern) { - pCxt->pCurrentSubplan->pChildern = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + if (NULL == pCxt->pCurrentSubplan->pChildren) { + pCxt->pCurrentSubplan->pChildren = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); } - taosArrayPush(pCxt->pCurrentSubplan->pChildern, &subplan); + + taosArrayPush(pCxt->pCurrentSubplan->pChildren, &subplan); subplan->pParents = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(subplan->pParents, &pCxt->pCurrentSubplan); } + SArray* currentLevel; if (subplan->level >= taosArrayGetSize(pCxt->pDag->pSubplans)) { currentLevel = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); @@ -205,6 +207,7 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { } else { currentLevel = taosArrayGetP(pCxt->pDag->pSubplans, subplan->level); } + taosArrayPush(currentLevel, &subplan); pCxt->pCurrentSubplan = subplan; ++(pCxt->pDag->numOfSubplans); @@ -290,24 +293,28 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { return node; } -static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { - SArray* vgs = (SArray*)pPlanNode->pExtInfo; - size_t numOfVg = taosArrayGetSize(vgs); - for (int32_t i = 0; i < numOfVg; ++i) { +static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { + SDataPayloadInfo* pPayload = (SDataPayloadInfo*) pPlanNode->pExtInfo; + + size_t numOfVgroups = taosArrayGetSize(pPayload->payload); + for (int32_t i = 0; i < numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); - SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); + SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(pPayload->payload, i); + vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); - subplan->pNode = NULL; subplan->pDataSink = createDataInserter(pCxt, blocks); - subplan->type = QUERY_TYPE_MODIFY; + subplan->pNode = NULL; + subplan->type = QUERY_TYPE_MODIFY; + subplan->msgType = pPayload->msgType; + RECOVERY_CURRENT_SUBPLAN(pCxt); } } static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { if (QNODE_MODIFY == pRoot->info.type) { - splitInsertSubplan(pCxt, pRoot); + splitModificationOpSubPlan(pCxt, pRoot); } else { SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); ++(pCxt->nextId.templateId); @@ -325,6 +332,7 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD .pCurrentSubplan = NULL, .nextId = {0} // todo queryid }; + *pDag = context.pDag; context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 9b2c9c1796..b25d9a3627 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -793,7 +793,7 @@ static cJSON* subplanToJson(const SSubplan* subplan) { return NULL; } - // The 'type', 'level', 'execEpSet', 'pChildern' and 'pParents' fields do not need to be serialized. + // The 'type', 'level', 'execEpSet', 'pChildren' and 'pParents' fields do not need to be serialized. bool res = addObject(jSubplan, jkSubplanId, subplanIdToJson, &subplan->id); if (res) { @@ -835,7 +835,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { SDataInserter* insert = (SDataInserter*)(subplan->pDataSink); *len = insert->size; *str = insert->pData; - insert->pData == NULL; + insert->pData = NULL; return TSDB_CODE_SUCCESS; } @@ -844,6 +844,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } + *str = cJSON_Print(json); *len = strlen(*str) + 1; return TSDB_CODE_SUCCESS; diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 6381771400..9621c2e227 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -31,17 +31,20 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) destroyQueryPlan(logicPlan); return code; } + code = optimizeQueryPlan(logicPlan); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); return code; } + code = createDag(logicPlan, NULL, pDag); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); qDestroyQueryDag(*pDag); return code; } + destroyQueryPlan(logicPlan); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 20eb94c2ff..8ef67a8e93 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -28,7 +28,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { for (int32_t m = 0; m < level->taskNum; ++m) { SSchTask *task = taosArrayGet(level->subTasks, m); SSubplan *plan = task->plan; - int32_t childNum = plan->pChildern ? (int32_t)taosArrayGetSize(plan->pChildern) : 0; + int32_t childNum = plan->pChildren ? (int32_t)taosArrayGetSize(plan->pChildren) : 0; int32_t parentNum = plan->pParents ? (int32_t)taosArrayGetSize(plan->pParents) : 0; if (childNum > 0) { @@ -40,7 +40,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { } for (int32_t n = 0; n < childNum; ++n) { - SSubplan **child = taosArrayGet(plan->pChildern, n); + SSubplan **child = taosArrayGet(plan->pChildren, n); SSchTask **childTask = taosHashGet(planToTask, child, POINTER_BYTES); if (NULL == childTask || NULL == *childTask) { qError("subplan relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); @@ -122,6 +122,7 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SSchJob *job) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + //?? job->attr.needFetch = true; job->levelNum = levelNum; @@ -547,22 +548,29 @@ int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, in _return: tfree(param); - SCH_RET(code); } int32_t schHandleSubmitCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_SUBMIT_RSP, code); } + +int32_t schHandleCreateTableCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_CREATE_TABLE_RSP, code); +} + int32_t schHandleQueryCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); } + int32_t schHandleFetchCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code); } + int32_t schHandleReadyCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_RES_READY_RSP, code); } + int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { SSchCallbackParam *pParam = (SSchCallbackParam *)param; qDebug("drop task rsp received, queryId:%"PRIx64 ",taksId:%"PRIx64 ",code:%d", pParam->queryId, pParam->taskId, code); @@ -570,6 +578,9 @@ int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { + case TDMT_VND_CREATE_TABLE: + *fp = schHandleCreateTableCallback; + break; case TDMT_VND_SUBMIT: *fp = schHandleSubmitCallback; break; @@ -640,6 +651,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { int32_t code = 0; switch (msgType) { + case TDMT_VND_CREATE_TABLE: case TDMT_VND_SUBMIT: { if (NULL == task->msg || task->msgLen <= 0) { qError("submit msg is NULL"); @@ -746,19 +758,15 @@ int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TDMT_VND_SUBMIT : TDMT_VND_QUERY; +// int32_t msgType = (plan->type == QUERY_TYPE_MODIFY)? TDMT_VND_SUBMIT : TDMT_VND_QUERY; - SCH_ERR_RET(schBuildAndSendMsg(job, task, msgType)); - + SCH_ERR_RET(schBuildAndSendMsg(job, task, plan->msgType)); SCH_ERR_RET(schPushTaskToExecList(job, task)); task->status = JOB_TASK_STATUS_EXECUTING; - return TSDB_CODE_SUCCESS; } - - int32_t schLaunchJob(SSchJob *job) { SSchLevel *level = taosArrayGet(job->levels, job->levelIdx); for (int32_t i = 0; i < level->taskNum; ++i) { diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index b418ade172..338ad1a2c0 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -58,7 +58,7 @@ void schtBuildQueryDag(SQueryDag *dag) { scanPlan.execEpSet.numOfEps = 1; scanPlan.execEpSet.port[0] = 6030; strcpy(scanPlan.execEpSet.fqdn[0], "ep0"); - scanPlan.pChildern = NULL; + scanPlan.pChildren = NULL; scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); scanPlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); @@ -68,14 +68,14 @@ void schtBuildQueryDag(SQueryDag *dag) { mergePlan.type = QUERY_TYPE_MERGE; mergePlan.level = 0; mergePlan.execEpSet.numOfEps = 0; - mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); + mergePlan.pChildren = taosArrayInit(1, POINTER_BYTES); mergePlan.pParents = NULL; mergePlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); SSubplan *mergePointer = (SSubplan *)taosArrayPush(merge, &mergePlan); SSubplan *scanPointer = (SSubplan *)taosArrayPush(scan, &scanPlan); - taosArrayPush(mergePointer->pChildern, &scanPointer); + taosArrayPush(mergePointer->pChildren, &scanPointer); taosArrayPush(scanPointer->pParents, &mergePointer); taosArrayPush(dag->pSubplans, &merge); @@ -100,7 +100,7 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[0].execEpSet.numOfEps = 1; insertPlan[0].execEpSet.port[0] = 6030; strcpy(insertPlan[0].execEpSet.fqdn[0], "ep0"); - insertPlan[0].pChildern = NULL; + insertPlan[0].pChildren = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; insertPlan[0].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); @@ -113,7 +113,7 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[1].execEpSet.numOfEps = 1; insertPlan[1].execEpSet.port[0] = 6030; strcpy(insertPlan[1].execEpSet.fqdn[0], "ep1"); - insertPlan[1].pChildern = NULL; + insertPlan[1].pChildren = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; insertPlan[1].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); From 5d63e31262ae943afc6cbcb2049134c9820164a3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 2 Jan 2022 23:28:17 +0800 Subject: [PATCH 18/86] [td-11818] fix bugs. --- source/libs/planner/src/physicalPlan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 9e1eea2b35..a53cbe836d 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -281,6 +281,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { default: assert(false); } + if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) { node->pChildren = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); size_t size = taosArrayGetSize(pPlanNode->pChildren); @@ -290,6 +291,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { taosArrayPush(node->pChildren, &child); } } + return node; } @@ -316,9 +318,11 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { if (QNODE_MODIFY == pRoot->info.type) { splitModificationOpSubPlan(pCxt, pRoot); } else { - SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); + SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); ++(pCxt->nextId.templateId); - subplan->pNode = createPhyNode(pCxt, pRoot); + + subplan->msgType = TDMT_VND_QUERY; + subplan->pNode = createPhyNode(pCxt, pRoot); subplan->pDataSink = createDataDispatcher(pCxt, pRoot); } // todo deal subquery From 3efe621526c2b94367108a0ff72e6fb128dfbdfc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 17:44:47 +0800 Subject: [PATCH 19/86] integration with wal module --- include/dnode/mnode/sdb/sdb.h | 13 ++++++++-- source/dnode/mnode/impl/CMakeLists.txt | 1 + source/dnode/mnode/impl/inc/mndInt.h | 3 +++ source/dnode/mnode/impl/src/mndSync.c | 34 +++++++++++++++++++++++++- source/dnode/mnode/sdb/inc/sdbInt.h | 1 + source/dnode/mnode/sdb/src/sdb.c | 5 ++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 9373e258be..fa10d46878 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -260,7 +260,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2 * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The number of rows in the table + * @return int32_t The number of rows in the table */ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); @@ -269,10 +269,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The max id of the table + * @return int32_t The max id of the table */ int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type); +/** + * @brief Update the version of sdb + * + * @param pSdb The sdb object. + * @param val The update value of the version. + * @return int32_t The current version of sdb + */ +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val); + SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); void sdbFreeRaw(SSdbRaw *pRaw); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 98c604e520..6768651922 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -8,6 +8,7 @@ target_include_directories( target_link_libraries( mnode PRIVATE sdb + PRIVATE wal PRIVATE transport PRIVATE cjson PRIVATE sync diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 15ff65a8fc..5c8d409d90 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -17,11 +17,13 @@ #define _TD_MND_INT_H_ #include "mndDef.h" + #include "sdb.h" #include "tcache.h" #include "tep.h" #include "tqueue.h" #include "ttime.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -65,6 +67,7 @@ typedef struct { typedef struct { int32_t errCode; sem_t syncSem; + SWal *pWal; SSyncNode *pSyncNode; ESyncState state; } SSyncMgmt; diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 6a2fca836f..d3d4ef33e9 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -20,6 +20,21 @@ int32_t mndInitSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; tsem_init(&pMgmt->syncSem, 0, 0); + char path[PATH_MAX] = {0}; + snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); + SWalCfg cfg = {.vgId = 1, + .fsyncPeriod = 0, + .rollPeriod = -1, + .segSize = -1, + .retentionPeriod = 0, + .retentionSize = 0, + .level = TAOS_WAL_FSYNC}; + pMgmt->pWal = walOpen(path, &cfg); + if (pMgmt->pWal == NULL) { + mError("failed to open wal in %s since %s", path, terrstr()); + return -1; + } + pMgmt->state = TAOS_SYNC_STATE_LEADER; pMgmt->pSyncNode = NULL; return 0; @@ -27,7 +42,11 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - tsem_destroy(&pMgmt->syncSem); + if (pMgmt->pWal != NULL) { + walClose(pMgmt->pWal); + pMgmt->pWal = NULL; + tsem_destroy(&pMgmt->syncSem); + } } static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { @@ -41,6 +60,19 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync } int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + + int64_t ver = sdbUpdateVer(pSdb, 1); + if (walWrite(pWal, ver, 1, pRaw, sdbGetRawTotalSize(pRaw)) < 0) { + sdbUpdateVer(pSdb, -1); + mError("failed to write raw:%p since %s, ver:%" PRId64, pRaw, terrstr(), ver); + return -1; + } + + mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + walFsync(pWal, true); + #if 1 return 0; #else diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 070aa56944..98c822cae8 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -59,6 +59,7 @@ typedef struct SSdb { char *tmpDir; int64_t lastCommitVer; int64_t curVer; + int64_t tableVer[SDB_MAX]; int32_t maxId[SDB_MAX]; EKeyType keyTypes[SDB_MAX]; SHashObj *hashObjs[SDB_MAX]; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 97bc0ecbdb..7df5052d6e 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -159,3 +159,8 @@ static int32_t sdbCreateDir(SSdb *pSdb) { return 0; } + +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { + pSdb->curVer += val; + return val; +} \ No newline at end of file From ab9366215590a2ce5139525e9558bc3ee877df81 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 17:54:54 +0800 Subject: [PATCH 20/86] Move the location of the test cases --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 -- source/dnode/mnode/impl/CMakeLists.txt | 6 +++++- source/dnode/mnode/impl/test/CMakeLists.txt | 4 ++++ source/dnode/{mgmt => mnode}/impl/test/acct/CMakeLists.txt | 0 source/dnode/{mgmt => mnode}/impl/test/acct/acct.cpp | 0 source/dnode/mnode/impl/test/mnodeTests.cpp | 0 source/dnode/{mgmt => mnode}/impl/test/user/CMakeLists.txt | 0 source/dnode/{mgmt => mnode}/impl/test/user/user.cpp | 0 8 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 source/dnode/mnode/impl/test/CMakeLists.txt rename source/dnode/{mgmt => mnode}/impl/test/acct/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/acct/acct.cpp (100%) delete mode 100644 source/dnode/mnode/impl/test/mnodeTests.cpp rename source/dnode/{mgmt => mnode}/impl/test/user/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/user/user.cpp (100%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index b0596bed08..b36cdbd690 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,6 +1,5 @@ enable_testing() -add_subdirectory(acct) # add_subdirectory(auth) # add_subdirectory(balance) add_subdirectory(cluster) @@ -17,7 +16,6 @@ add_subdirectory(stb) # add_subdirectory(sync) # add_subdirectory(telem) # add_subdirectory(trans) -add_subdirectory(user) add_subdirectory(vgroup) add_subdirectory(sut) diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 6768651922..adbef3b55f 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -12,4 +12,8 @@ target_link_libraries( PRIVATE transport PRIVATE cjson PRIVATE sync -) \ No newline at end of file +) + +if(${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt new file mode 100644 index 0000000000..fa7b45f988 --- /dev/null +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -0,0 +1,4 @@ +enable_testing() + +add_subdirectory(acct) +add_subdirectory(user) diff --git a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/acct/CMakeLists.txt rename to source/dnode/mnode/impl/test/acct/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp similarity index 100% rename from source/dnode/mgmt/impl/test/acct/acct.cpp rename to source/dnode/mnode/impl/test/acct/acct.cpp diff --git a/source/dnode/mnode/impl/test/mnodeTests.cpp b/source/dnode/mnode/impl/test/mnodeTests.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/source/dnode/mgmt/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/user/CMakeLists.txt rename to source/dnode/mnode/impl/test/user/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp similarity index 100% rename from source/dnode/mgmt/impl/test/user/user.cpp rename to source/dnode/mnode/impl/test/user/user.cpp From 0e8c226085bc8acb0154a52ff623c586014007f2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 18:19:30 +0800 Subject: [PATCH 21/86] the starting version of wal is 0 --- source/dnode/mnode/impl/test/acct/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/acct/acct.cpp | 4 ++-- source/dnode/mnode/impl/test/user/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/user/user.cpp | 4 ++-- source/dnode/mnode/sdb/src/sdb.c | 4 +++- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt index a06becd127..8c8bf54bc4 100644 --- a/source/dnode/mnode/impl/test/acct/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. ACCT_SRC) -add_executable(dnode_test_acct ${ACCT_SRC}) +add_executable(mnode_test_acct ${ACCT_SRC}) target_link_libraries( - dnode_test_acct + mnode_test_acct PUBLIC sut ) add_test( - NAME dnode_test_acct - COMMAND dnode_test_acct + NAME mnode_test_acct + COMMAND mnode_test_acct ) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index be0ad4ab0f..934a2d96b4 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,7 +1,7 @@ /** * @file acct.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module acct-msg tests + * @brief MNODE module acct-msg tests * @version 0.1 * @date 2021-12-15 * @@ -13,7 +13,7 @@ class DndTestAcct : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; diff --git a/source/dnode/mnode/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt index 5068660eba..c6aeef7221 100644 --- a/source/dnode/mnode/impl/test/user/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/user/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. USER_SRC) -add_executable(dnode_test_user ${USER_SRC}) +add_executable(mnode_test_user ${USER_SRC}) target_link_libraries( - dnode_test_user + mnode_test_user PUBLIC sut ) add_test( - NAME dnode_test_user - COMMAND dnode_test_user + NAME mnode_test_user + COMMAND mnode_test_user ) diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index aa160304c8..00153e778c 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,7 +1,7 @@ /** * @file user.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module user-msg tests + * @brief MNODE module user-msg tests * @version 0.1 * @date 2021-12-15 * @@ -13,7 +13,7 @@ class DndTestUser : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 7df5052d6e..fb6ac7bb37 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -51,6 +51,8 @@ SSdb *sdbInit(SSdbOpt *pOption) { taosInitRWLatch(&pSdb->locks[i]); } + pSdb->curVer = -1; + pSdb->lastCommitVer = -1; pSdb->pMnode = pOption->pMnode; mDebug("sdb init successfully"); return pSdb; @@ -162,5 +164,5 @@ static int32_t sdbCreateDir(SSdb *pSdb) { int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { pSdb->curVer += val; - return val; + return pSdb->curVer; } \ No newline at end of file From 5ac3398f3add7d99a2c5b6f82dc0cb93eee2fdf9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:36:31 +0800 Subject: [PATCH 22/86] Mnode intergate with wal module --- include/dnode/mnode/sdb/sdb.h | 8 ++ include/util/taoserror.h | 1 + source/dnode/mnode/impl/src/mndSync.c | 103 +++++++++++++++++++++++--- source/dnode/mnode/sdb/inc/sdbInt.h | 2 - source/libs/wal/inc/walInt.h | 2 + source/libs/wal/src/walRead.c | 2 + source/util/src/terror.c | 1 + 7 files changed, 106 insertions(+), 13 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index fa10d46878..48c8df5ba0 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -188,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb); */ int32_t sdbReadFile(SSdb *pSdb); +/** + * @brief Write sdb file. + * + * @param pSdb The sdb object. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t sdbWriteFile(SSdb *pSdb); + /** * @brief Parse and write raw data to sdb, then free the pRaw object * diff --git a/include/util/taoserror.h b/include/util/taoserror.h index ae36ac7216..2dcc74213c 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -160,6 +160,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339) #define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A) #define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B) +#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C) // mnode-dnode #define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index d3d4ef33e9..3f5bb77855 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -15,10 +15,10 @@ #define _DEFAULT_SOURCE #include "mndSync.h" +#include "mndTrans.h" -int32_t mndInitSync(SMnode *pMnode) { +static int32_t mndInitWal(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - tsem_init(&pMgmt->syncSem, 0, 0); char path[PATH_MAX] = {0}; snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); @@ -26,12 +26,95 @@ int32_t mndInitSync(SMnode *pMnode) { .fsyncPeriod = 0, .rollPeriod = -1, .segSize = -1, - .retentionPeriod = 0, - .retentionSize = 0, + .retentionPeriod = -1, + .retentionSize = -1, .level = TAOS_WAL_FSYNC}; pMgmt->pWal = walOpen(path, &cfg); - if (pMgmt->pWal == NULL) { - mError("failed to open wal in %s since %s", path, terrstr()); + if (pMgmt->pWal == NULL) return -1; + + return 0; +} + +static void mndCloseWal(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + + if (pMgmt->pWal != NULL) { + walClose(pMgmt->pWal); + pMgmt->pWal = NULL; + } +} + +static int32_t mndRestoreWal(SMnode *pMnode) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + int64_t lastSdbVer = sdbUpdateVer(pSdb, 0); + int32_t code = -1; + + SWalReadHandle *pHandle = walOpenReadHandle(pWal); + if (pHandle == NULL) return -1; + + int64_t start = walGetFirstVer(pWal); + int64_t end = walGetLastVer(pWal); + start = MAX(lastSdbVer, start); + + for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { + if (walReadWithHandle(pHandle, ver) < 0) { + mError("failed to read with wal handle since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + SWalHead *pHead = pHandle->pHead; + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + if (sdbVer + 1 != ver) { + terrno = TSDB_CODE_SDB_INVALID_WAl_VER; + mError("failed to write wal to sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); + goto WAL_RESTORE_OVER; + } + + if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) { + mError("failed to write wal to sdb since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + sdbUpdateVer(pSdb, 1); + } + + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + if (sdbVer != lastSdbVer) { + if (walBeginSnapshot(pWal, sdbVer) < 0) { + goto WAL_RESTORE_OVER; + } + + if (sdbVer != lastSdbVer) { + mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + if (sdbWriteFile(pSdb) != 0) { + goto WAL_RESTORE_OVER; + } + } + + if (walEndSnapshot(pWal) < 0) { + goto WAL_RESTORE_OVER; + } + } + + code = 0; + +WAL_RESTORE_OVER: + walCloseReadHandle(pHandle); + return 0; +} + +int32_t mndInitSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_init(&pMgmt->syncSem, 0, 0); + + if (mndInitWal(pMnode) < 0) { + mError("failed to open wal since %s", terrstr()); + return -1; + } + + if (mndRestoreWal(pMnode) < 0) { + mError("failed to restore wal since %s", terrstr()); return -1; } @@ -42,11 +125,8 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - if (pMgmt->pWal != NULL) { - walClose(pMgmt->pWal); - pMgmt->pWal = NULL; - tsem_destroy(&pMgmt->syncSem); - } + tsem_destroy(&pMgmt->syncSem); + mndCloseWal(pMnode); } static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { @@ -71,6 +151,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { } mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + walCommit(pWal, ver); walFsync(pWal, true); #if 1 diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 98c822cae8..25db988a0c 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -72,8 +72,6 @@ typedef struct SSdb { SdbDecodeFp decodeFps[SDB_MAX]; } SSdb; -int32_t sdbWriteFile(SSdb *pSdb); - const char *sdbTableName(ESdbType type); void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 1579cad7b6..871c95193f 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -20,6 +20,8 @@ #include "tchecksum.h" #include "wal.h" +#include "taoserror.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index c80fb4eed8..b5a30e4397 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -19,8 +19,10 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { SWalReadHandle *pRead = malloc(sizeof(SWalReadHandle)); if (pRead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + pRead->pWal = pWal; pRead->readIdxTfd = -1; pRead->readLogTfd = -1; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9fa5b3198b..e821f1f803 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -170,6 +170,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_STATUS_TYPE, "Invalid status type") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_VER, "Invalid raw data version") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_LEN, "Invalid raw data len") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_CONTENT, "Invalid raw data content") +TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_WAl_VER, "Invalid wal version") // mnode-dnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "Dnode already exists") From 99e53317ce03583c3acbbc056c25276c4bd32d90 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:41:45 +0800 Subject: [PATCH 23/86] minor changes --- source/dnode/mnode/impl/src/mndSync.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 3f5bb77855..7c8a8cdb96 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -37,7 +37,6 @@ static int32_t mndInitWal(SMnode *pMnode) { static void mndCloseWal(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - if (pMgmt->pWal != NULL) { walClose(pMgmt->pWal); pMgmt->pWal = NULL; @@ -59,7 +58,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { - mError("failed to read with wal handle since %s, ver:%" PRId64, terrstr(), ver); + mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; } @@ -67,12 +66,12 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t sdbVer = sdbUpdateVer(pSdb, 0); if (sdbVer + 1 != ver) { terrno = TSDB_CODE_SDB_INVALID_WAl_VER; - mError("failed to write wal to sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); + mError("failed to read wal from sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); goto WAL_RESTORE_OVER; } if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) { - mError("failed to write wal to sdb since %s, ver:%" PRId64, terrstr(), ver); + mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; } @@ -85,11 +84,9 @@ static int32_t mndRestoreWal(SMnode *pMnode) { goto WAL_RESTORE_OVER; } - if (sdbVer != lastSdbVer) { - mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); - if (sdbWriteFile(pSdb) != 0) { - goto WAL_RESTORE_OVER; - } + mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + if (sdbWriteFile(pSdb) != 0) { + goto WAL_RESTORE_OVER; } if (walEndSnapshot(pWal) < 0) { @@ -101,7 +98,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { WAL_RESTORE_OVER: walCloseReadHandle(pHandle); - return 0; + return code; } int32_t mndInitSync(SMnode *pMnode) { From 513ba4b9a9faf899f37385d32da908c978f09134 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 02:23:46 +0000 Subject: [PATCH 24/86] more --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fd0ada95d9..65d0b1915c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,7 +19,9 @@ "ms-vscode.cmake-tools", "austin.code-gnu-global", "visualstudioexptteam.vscodeintel", - "eamodio.gitlens" + "eamodio.gitlens", + "matepek.vscode-catch2-test-adapter", + "spmeesseman.vscode-taskexplorer" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. From 2b7b433a95637390a2ed130c51ad181475b90854 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 10:30:57 +0800 Subject: [PATCH 25/86] [td-11818] fix deadlock. --- source/client/src/clientMain.c | 4 +++- source/libs/scheduler/src/scheduler.c | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e7c44d9f28..e5f3eba5c2 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -29,7 +29,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { // this function may be called by user or system, or by both simultaneously. void taos_cleanup(void) { - tscDebug("start to cleanup client environment"); + tscInfo("start to cleanup client environment"); if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) { return; @@ -47,6 +47,8 @@ void taos_cleanup(void) { rpcCleanup(); taosCloseLog(); + + tscInfo("all local resources released"); } TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 8ef67a8e93..bcdbc57798 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -456,15 +456,27 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; - + + switch (msgType) { + case TDMT_VND_CREATE_TABLE_RSP: { + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); + } else { +// job->resNumOfRows += rsp->affectedRows; + code = schProcessOnTaskSuccess(job, task); + if (code) { + goto _task_error; + } + } + } case TDMT_VND_SUBMIT_RSP: { - SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; - if (rsp->code != TSDB_CODE_SUCCESS) { - SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); } else { + SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; job->resNumOfRows += rsp->affectedRows; - + code = schProcessOnTaskSuccess(job, task); if (code) { goto _task_error; From 26796d19a709fea7ebe707855c374f900fe5165f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 02:49:54 +0000 Subject: [PATCH 26/86] fix encode and decode bug --- source/common/src/tmsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0874c471aa..c1048f8482 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { buf = taosDecodeFixedU64(buf, &pReq->ver); buf = taosDecodeFixedU32(buf, &nsize); + pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq)); for (size_t i = 0; i < nsize; i++) { SVCreateTbReq req; buf = tDeserializeSVCreateTbReq(buf, &req); From 961ffa77e123d1a9983737d689fbf48cb3b7bd6e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 10:55:28 +0800 Subject: [PATCH 27/86] [td-11818] fix bug in create multiple tables; --- source/client/test/clientTests.cpp | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index a3116fecea..ae1a36bd36 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -465,12 +465,12 @@ TEST(testCase, connect_Test) { TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); + ASSERT_NE(pConn, nullptr); TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -490,3 +490,32 @@ TEST(testCase, create_multiple_tables) { taos_free_result(pRes); taos_close(pConn); } + +//TEST(testCase, projection_query_tables) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// ASSERT_EQ(pConn, nullptr); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "select * from t_2"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// 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_free_result(pRes); +// taos_close(pConn); +//} + From 1dba25656af04ef9597f1e6f6c09cb5b04f86cda Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 4 Jan 2022 11:15:00 +0800 Subject: [PATCH 28/86] feature/qnode --- include/libs/planner/planner.h | 2 +- source/libs/planner/inc/plannerInt.h | 2 +- source/libs/planner/src/physicalPlan.c | 2 +- source/libs/planner/src/planner.c | 2 +- source/libs/scheduler/src/scheduler.c | 4 +-- source/libs/scheduler/test/schedulerTests.cpp | 29 +++++++++++-------- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index f1a9447e9c..81a6d59e8d 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -147,7 +147,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** // @subplan subplan to be schedule // @templateId templateId of a group of datasource subplans of this @subplan // @ep one execution location of this group of datasource subplans -int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); +int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep); int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str); diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index 35c6d59ffe..61d622155f 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -101,7 +101,7 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str); int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); -int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); +int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep); int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len); int32_t stringToSubplan(const char* str, SSubplan** subplan); diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 22a1beaa35..715090d4b3 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -336,6 +336,6 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD return TSDB_CODE_SUCCESS; } -int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { //todo } diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 6381771400..96556ee3ff 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -46,7 +46,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) return TSDB_CODE_SUCCESS; } -int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { return setSubplanExecutionNode(subplan, templateId, ep); } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 090c7b6fa7..68ccb16fc3 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -404,8 +404,8 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { return TSDB_CODE_SUCCESS; } } else { - strncpy(job->resEp.fqdn, task->execAddr.fqdn, sizeof(job->resEp.fqdn)); - job->resEp.port = task->execAddr.port; + strncpy(job->resEp.fqdn, task->execAddr.epAddr[task->execAddr.inUse].fqdn, sizeof(job->resEp.fqdn)); + job->resEp.port = task->execAddr.epAddr[task->execAddr.inUse].port; } job->fetchTask = task; diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index b418ade172..2c8eafb825 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -54,10 +54,11 @@ void schtBuildQueryDag(SQueryDag *dag) { scanPlan.id.templateId = 0x0000000000000002; scanPlan.id.subplanId = 0x0000000000000003; scanPlan.type = QUERY_TYPE_SCAN; - scanPlan.level = 1; - scanPlan.execEpSet.numOfEps = 1; - scanPlan.execEpSet.port[0] = 6030; - strcpy(scanPlan.execEpSet.fqdn[0], "ep0"); + scanPlan.execNode.numOfEps = 1; + scanPlan.execNode.nodeId = 1; + scanPlan.execNode.inUse = 0; + scanPlan.execNode.epAddr[0].port = 6030; + strcpy(scanPlan.execNode.epAddr[0].fqdn, "ep0"); scanPlan.pChildern = NULL; scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); scanPlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); @@ -67,7 +68,7 @@ void schtBuildQueryDag(SQueryDag *dag) { mergePlan.id.subplanId = 0x5555555555; mergePlan.type = QUERY_TYPE_MERGE; mergePlan.level = 0; - mergePlan.execEpSet.numOfEps = 0; + mergePlan.execNode.numOfEps = 0; mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); mergePlan.pParents = NULL; mergePlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); @@ -97,9 +98,11 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[0].id.subplanId = 0x0000000000000004; insertPlan[0].type = QUERY_TYPE_MODIFY; insertPlan[0].level = 0; - insertPlan[0].execEpSet.numOfEps = 1; - insertPlan[0].execEpSet.port[0] = 6030; - strcpy(insertPlan[0].execEpSet.fqdn[0], "ep0"); + insertPlan[0].execNode.numOfEps = 1; + insertPlan[0].execNode.nodeId = 1; + insertPlan[0].execNode.inUse = 0; + insertPlan[0].execNode.epAddr[0].port = 6030; + strcpy(insertPlan[0].execNode.epAddr[0].fqdn, "ep0"); insertPlan[0].pChildern = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; @@ -110,9 +113,11 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[1].id.subplanId = 0x0000000000000005; insertPlan[1].type = QUERY_TYPE_MODIFY; insertPlan[1].level = 0; - insertPlan[1].execEpSet.numOfEps = 1; - insertPlan[1].execEpSet.port[0] = 6030; - strcpy(insertPlan[1].execEpSet.fqdn[0], "ep1"); + insertPlan[1].execNode.numOfEps = 1; + insertPlan[1].execNode.nodeId = 1; + insertPlan[1].execNode.inUse = 1; + insertPlan[1].execNode.epAddr[0].port = 6030; + strcpy(insertPlan[1].execNode.epAddr[0].fqdn, "ep1"); insertPlan[1].pChildern = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; @@ -132,7 +137,7 @@ int32_t schtPlanToString(const SSubplan *subplan, char** str, int32_t* len) { return 0; } -int32_t schtExecNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t schtExecNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { return 0; } From efb3d812b183e7831717045ad158a036cd4b2f68 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 11:23:54 +0800 Subject: [PATCH 29/86] add commit version to sdb --- include/dnode/mnode/sdb/sdb.h | 37 ++++---- source/dnode/mnode/sdb/inc/sdbInt.h | 5 +- source/dnode/mnode/sdb/src/sdb.c | 11 ++- source/dnode/mnode/sdb/src/sdbFile.c | 128 +++++++++++++++++++++++++-- source/dnode/mnode/sdb/src/sdbHash.c | 37 ++++---- 5 files changed, 171 insertions(+), 47 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 48c8df5ba0..497da71c13 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -102,25 +102,24 @@ typedef enum { } ESdbStatus; typedef enum { - SDB_START = 0, - SDB_TRANS = 1, - SDB_CLUSTER = 2, - SDB_MNODE = 3, - SDB_QNODE = 4, - SDB_SNODE = 5, - SDB_BNODE = 6, - SDB_DNODE = 7, - SDB_USER = 8, - SDB_AUTH = 9, - SDB_ACCT = 10, - SDB_CONSUMER = 11, - SDB_CGROUP = 12, - SDB_TOPIC = 13, - SDB_VGROUP = 14, - SDB_STB = 15, - SDB_DB = 16, - SDB_FUNC = 17, - SDB_MAX = 18 + SDB_TRANS = 0, + SDB_CLUSTER = 1, + SDB_MNODE = 2, + SDB_QNODE = 3, + SDB_SNODE = 4, + SDB_BNODE = 5, + SDB_DNODE = 6, + SDB_USER = 7, + SDB_AUTH = 8, + SDB_ACCT = 9, + SDB_CONSUMER = 10, + SDB_CGROUP = 11, + SDB_TOPIC = 12, + SDB_VGROUP = 13, + SDB_STB = 14, + SDB_DB = 15, + SDB_FUNC = 16, + SDB_MAX = 17 } ESdbType; typedef struct SSdb SSdb; diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 25db988a0c..c99dff57e1 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -17,11 +17,12 @@ #define _TD_SDB_INT_H_ #include "os.h" + #include "sdb.h" -#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" +#include "tmsg.h" #ifdef __cplusplus extern "C" { @@ -60,7 +61,7 @@ typedef struct SSdb { int64_t lastCommitVer; int64_t curVer; int64_t tableVer[SDB_MAX]; - int32_t maxId[SDB_MAX]; + int64_t maxId[SDB_MAX]; EKeyType keyTypes[SDB_MAX]; SHashObj *hashObjs[SDB_MAX]; SRWLatch locks[SDB_MAX]; diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index fb6ac7bb37..0671434218 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -49,6 +49,9 @@ SSdb *sdbInit(SSdbOpt *pOption) { for (ESdbType i = 0; i < SDB_MAX; ++i) { taosInitRWLatch(&pSdb->locks[i]); + pSdb->maxId[i] = 0; + pSdb->tableVer[i] = -1; + pSdb->keyTypes[i] = SDB_KEY_INT32; } pSdb->curVer = -1; @@ -61,10 +64,10 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - // if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); - sdbWriteFile(pSdb); - // } + if (pSdb->curVer != pSdb->lastCommitVer) { + mDebug("write sdb file for curVer:% " PRId64 " and lastCommitVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + sdbWriteFile(pSdb); + } if (pSdb->currDir != NULL) { tfree(pSdb->currDir); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 5a03b3409e..c5306478f2 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -17,10 +17,13 @@ #include "sdbInt.h" #include "tchecksum.h" +#define SDB_TABLE_SIZE 24 +#define SDB_RESERVE_SIZE 512 + static int32_t sdbRunDeployFp(SSdb *pSdb) { mDebug("start to deploy sdb"); - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbDeployFp fp = pSdb->deployFps[i]; if (fp == NULL) continue; @@ -34,6 +37,100 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) { return 0; } +static int32_t sdbReadFileHead(SSdb *pSdb, FileFd fd) { + int32_t ret = taosReadFile(fd, &pSdb->curVer, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + ret = taosReadFile(fd, &maxId, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->maxId[i] = maxId; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + ret = taosReadFile(fd, &ver, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->tableVer[i] = ver; + } + } + + char reserve[SDB_RESERVE_SIZE] = {0}; + ret = taosWriteFile(fd, reserve, sizeof(reserve)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(reserve)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + return 0; +} + +static int32_t sdbWriteFileHead(SSdb *pSdb, FileFd fd) { + if (taosWriteFile(fd, &pSdb->curVer, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + if (i < SDB_MAX) { + maxId = pSdb->maxId[i]; + } + if (taosWriteFile(fd, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + if (i < SDB_MAX) { + ver = pSdb->tableVer[i]; + } + if (taosWriteFile(fd, &ver, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + char reserve[512] = {0}; + if (taosWriteFile(fd, reserve, sizeof(reserve)) != sizeof(reserve)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + int32_t sdbReadFile(SSdb *pSdb) { int64_t offset = 0; int32_t code = 0; @@ -43,7 +140,7 @@ int32_t sdbReadFile(SSdb *pSdb) { SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed read file since %s", terrstr()); + mError("failed read file since %s", terrstr()); return -1; } @@ -58,6 +155,14 @@ int32_t sdbReadFile(SSdb *pSdb) { return 0; } + if (sdbReadFileHead(pSdb, fd) != 0) { + mError("failed to read file:%s head since %s", file, terrstr()); + pSdb->curVer = -1; + free(pRaw); + taosCloseFile(fd); + return -1; + } + while (1) { readLen = sizeof(SSdbRaw); ret = taosReadFile(fd, pRaw, readLen); @@ -104,6 +209,8 @@ int32_t sdbReadFile(SSdb *pSdb) { } code = 0; + pSdb->lastCommitVer = pSdb->curVer; + mError("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); PARSE_SDB_DATA_ERROR: taosCloseFile(fd); @@ -130,11 +237,17 @@ int32_t sdbWriteFile(SSdb *pSdb) { return -1; } - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + if (sdbWriteFileHead(pSdb, fd) != 0) { + mError("failed to write file:%s head since %s", tmpfile, terrstr()); + taosCloseFile(fd); + return -1; + } + + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; - mTrace("sdb write %s, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); + mTrace("write %s to file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); SHashObj *hash = pSdb->hashObjs[i]; SRWLatch *pLock = &pSdb->locks[i]; @@ -155,7 +268,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { pRaw->status = pRow->status; int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen; if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -163,7 +276,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -201,7 +314,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { if (code != 0) { mError("failed to write file:%s since %s", curfile, tstrerror(code)); } else { - mDebug("write file:%s successfully", curfile); + pSdb->lastCommitVer = pSdb->curVer; + mDebug("write file:%s successfully, ver:%" PRId64, curfile, pSdb->lastCommitVer); } terrno = code; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 597484dad1..4b11ec3e76 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -38,6 +38,10 @@ const char *sdbTableName(ESdbType type) { return "auth"; case SDB_ACCT: return "acct"; + case SDB_CONSUMER: + return "consumer"; + case SDB_CGROUP: + return "cgroup"; case SDB_TOPIC: return "topic"; case SDB_VGROUP: @@ -70,7 +74,7 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { } static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { - if (type >= SDB_MAX || type <= SDB_START) { + if (type >= SDB_MAX || type < 0) { terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE; return NULL; } @@ -100,8 +104,6 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) { } static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -126,10 +128,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosWUnLockLatch(pLock); - if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { - pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); - } - + int32_t code = 0; SdbInsertFp insertFp = pSdb->insertFps[pRow->type]; if (insertFp != NULL) { code = (*insertFp)(pSdb, pRow->pObj); @@ -143,12 +142,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * } } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT64) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + pSdb->tableVer[pRow->type]++; + return 0; } static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pNewRow->type]; taosRLockLatch(pLock); @@ -157,23 +162,24 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosRUnLockLatch(pLock); return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize); } - SSdbRow *pOldRow = *ppOldRow; + SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; taosRUnLockLatch(pLock); + int32_t code = 0; SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type]; if (updateFp != NULL) { code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj); } sdbFreeRow(pSdb, pNewRow); + + pSdb->tableVer[pOldRow->type]++; return code; } static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -190,9 +196,10 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); - // sdbRelease(pSdb, pOldRow->pObj); + pSdb->tableVer[pOldRow->type]++; sdbFreeRow(pSdb, pRow); - return code; + // sdbRelease(pSdb, pOldRow->pObj); + return 0; } int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) { @@ -277,7 +284,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); - if (pRow->type >= SDB_MAX || pRow->type <= SDB_START) return; + if (pRow->type >= SDB_MAX ) return; SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); From 04d5badb3ce4f0442d3f92dfdfe65a145cdf4b09 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 03:46:55 +0000 Subject: [PATCH 30/86] add forward compatilibity --- source/util/src/encode.c | 3 +-- source/util/test/encodeTest.cpp | 46 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 40c03ea051..096509d42a 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -127,15 +127,14 @@ void tEndDecode(SCoder* pCoder) { struct SCoderNode* pNode; ASSERT(pCoder->type == TD_DECODER); - ASSERT(tDecodeIsEnd(pCoder)); pNode = TD_SLIST_HEAD(&(pCoder->stack)); ASSERT(pNode); TD_SLIST_POP(&(pCoder->stack)); pCoder->data = pNode->data; + pCoder->pos = pCoder->size + pNode->pos; pCoder->size = pNode->size; - pCoder->pos = pCoder->pos + pNode->pos; free(pNode); } diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 1a861701d7..b178ee0b10 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -360,8 +360,8 @@ TEST(td_encode_test, compound_struct_encode_test) { SStructA_v2 sa2 = {.A_a = 10, .A_b = 65478, .A_c = "Hello", .A_d = 67, .A_e = 13}; SFinalReq_v1 req1 = {.pA = &sa1, .v_a = 15, .v_b = 35}; SFinalReq_v2 req2 = {.pA = &sa2, .v_a = 15, .v_b = 32, .v_c = 37}; - SFinalReq_v1 dreq1; - SFinalReq_v2 dreq21, dreq22; + SFinalReq_v1 dreq11, dreq21; + SFinalReq_v2 dreq12, dreq22; // Get size tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER); @@ -386,27 +386,30 @@ TEST(td_encode_test, compound_struct_encode_test) { tCoderClear(&encoder); // Decode + // buf1 -> req1 tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); - GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq1), 0); - GTEST_ASSERT_EQ(dreq1.pA->A_a, req1.pA->A_a); - GTEST_ASSERT_EQ(dreq1.pA->A_b, req1.pA->A_b); - GTEST_ASSERT_EQ(strcmp(dreq1.pA->A_c, req1.pA->A_c), 0); - GTEST_ASSERT_EQ(dreq1.v_a, req1.v_a); - GTEST_ASSERT_EQ(dreq1.v_b, req1.v_b); + GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq11), 0); + GTEST_ASSERT_EQ(dreq11.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq11.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq11.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq11.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq11.v_b, req1.v_b); tCoderClear(&decoder); + // buf1 -> req2 (backward compatibility) tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); - GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq21), 0); - GTEST_ASSERT_EQ(dreq21.pA->A_a, req1.pA->A_a); - GTEST_ASSERT_EQ(dreq21.pA->A_b, req1.pA->A_b); - GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req1.pA->A_c), 0); - GTEST_ASSERT_EQ(dreq21.pA->A_d, 0); - GTEST_ASSERT_EQ(dreq21.pA->A_e, 0); - GTEST_ASSERT_EQ(dreq21.v_a, req1.v_a); - GTEST_ASSERT_EQ(dreq21.v_b, req1.v_b); - GTEST_ASSERT_EQ(dreq21.v_c, 0); + GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq12), 0); + GTEST_ASSERT_EQ(dreq12.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq12.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq12.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq12.pA->A_d, 0); + GTEST_ASSERT_EQ(dreq12.pA->A_e, 0); + GTEST_ASSERT_EQ(dreq12.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq12.v_b, req1.v_b); + GTEST_ASSERT_EQ(dreq12.v_c, 0); tCoderClear(&decoder); + // buf2 -> req2 tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq22), 0); GTEST_ASSERT_EQ(dreq22.pA->A_a, req2.pA->A_a); @@ -418,4 +421,13 @@ TEST(td_encode_test, compound_struct_encode_test) { GTEST_ASSERT_EQ(dreq22.v_b, req2.v_b); GTEST_ASSERT_EQ(dreq22.v_c, req2.v_c); tCoderClear(&decoder); + + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); + GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq21), 0); + GTEST_ASSERT_EQ(dreq21.pA->A_a, req2.pA->A_a); + GTEST_ASSERT_EQ(dreq21.pA->A_b, req2.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req2.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq21.v_a, req2.v_a); + GTEST_ASSERT_EQ(dreq21.v_b, req2.v_b); + tCoderClear(&decoder); } \ No newline at end of file From f548a08401c37bbb5a0d9ed4178de8da31f8da38 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 03:55:41 +0000 Subject: [PATCH 31/86] fix big endian bug --- source/util/src/encode.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 096509d42a..758d3f442d 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -88,13 +88,9 @@ void tEndEncode(SCoder* pCoder) { pCoder->size = pNode->size; pCoder->pos = pNode->pos; - if (TD_RT_ENDIAN() == pCoder->endian) { - tPut(int32_t, pCoder->data + pCoder->pos, len); - } else { - tRPut32(pCoder->data + pCoder->pos, len); - } + tEncodeI32(pCoder, len); - TD_CODER_MOVE_POS(pCoder, len + sizeof(int32_t)); + TD_CODER_MOVE_POS(pCoder, len); free(pNode); } From d862dcae8387d85fdb620b31467b437dc877d722 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 12:58:39 +0800 Subject: [PATCH 32/86] [td-11818] refactor, fix bug in repeat create table, add request id for each query. --- include/libs/planner/planner.h | 2 +- include/os/osSysinfo.h | 2 - source/client/inc/clientInt.h | 2 + source/client/src/clientEnv.c | 34 ++++++- source/client/src/clientImpl.c | 3 +- source/client/test/clientTests.cpp | 135 +++++++++++++++---------- source/libs/planner/inc/plannerInt.h | 2 +- source/libs/planner/src/physicalPlan.c | 5 +- source/libs/planner/src/planner.c | 4 +- source/libs/transport/src/rpcMain.c | 2 +- source/os/src/osSysinfo.c | 4 - 11 files changed, 126 insertions(+), 69 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 5ad53703c7..a310b04e9e 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -141,7 +141,7 @@ struct SQueryNode; /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 6952b91742..b410255ea4 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -68,8 +68,6 @@ typedef struct { SysNameInfo taosGetSysNameInfo(); -int64_t taosGetPid(); - #ifdef __cplusplus } #endif diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7aa4bc9ee9..705d6ef786 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -146,6 +146,8 @@ int taos_init(); void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo); void destroyTscObj(void*pObj); +uint64_t generateRequestId(); + void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); void destroyRequest(SRequestObj* pRequest); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 960ba95324..bfb884c57e 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -87,6 +87,7 @@ static void tscInitLogFile() { } } +// todo close the transporter properly void closeTransporter(STscObj* pTscObj) { if (pTscObj == NULL || pTscObj->pTransporter == NULL) { return; @@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty return NULL; } - // TODO generated request uuid - pRequest->requestId = 0; + pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampMs(); pRequest->type = type; @@ -410,6 +410,36 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { return 0; } +/** + * The request id is an unsigned integer format of 64bit. + *+------------+-----+-----------+---------------+ + *| uid|localIp| PId | timestamp | serial number | + *+------------+-----+-----------+---------------+ + *| 16bit |12bit|20bit |16bit | + *+------------+-----+-----------+---------------+ + * @return + */ +static int32_t requestSerialId = 0; +uint64_t generateRequestId() { + uint64_t hashId = 0; + + char uid[64] = {0}; + int32_t code = taosGetSystemUid(uid, tListLen(uid)); + if (code != TSDB_CODE_SUCCESS) { + tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", tstrerror(TAOS_SYSTEM_ERROR(errno))); + + } else { + hashId = MurmurHash3_32(uid, strlen(uid)); + } + + int64_t ts = taosGetTimestampUs(); + uint64_t pid = taosGetPId(); + int32_t val = atomic_add_fetch_32(&requestSerialId, 1); + + uint64_t id = ((hashId & 0xFFFF) << 48) | ((pid & 0x0FFF) << 36) | ((ts & 0xFFFFF) << 16) | (val & 0xFFFF); + return id; +} + #if 0 #include "cJSON.h" static setConfRet taos_set_config_imp(const char *config){ diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index b0b2c57ee4..0d590235ad 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -198,13 +198,14 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { pRequest->type = pQuery->type; - return qCreateQueryDag(pQuery, pDag); + return qCreateQueryDag(pQuery, pDag, pRequest->requestId); } int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); } + return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index ae1a36bd36..bb40d9ada2 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -147,29 +147,29 @@ TEST(testCase, connect_Test) { // taos_close(pConn); //} -//TEST(testCase, create_db_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create database abc1 vgroups 4"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_close(pConn); -//} +TEST(testCase, create_db_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database abc1 vgroups 4"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_close(pConn); +} // //TEST(testCase, create_dnode_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -249,36 +249,36 @@ TEST(testCase, connect_Test) { //// taos_close(pConn); //} -// TEST(testCase, create_stable_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); -// if (taos_errno(pRes) != 0) { -// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// taos_close(pConn); -//} + TEST(testCase, create_stable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -470,7 +470,15 @@ TEST(testCase, create_multiple_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + taos_free_result(pRes); + pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -491,6 +499,25 @@ TEST(testCase, create_multiple_tables) { taos_close(pConn); } +TEST(testCase, generated_request_id_test) { + uint64_t id0 = generateRequestId(); + + uint64_t id1 = generateRequestId(); + uint64_t id2 = generateRequestId(); + uint64_t id3 = generateRequestId(); + uint64_t id4 = generateRequestId(); + + ASSERT_NE(id0, id1); + ASSERT_NE(id1, id2); + ASSERT_NE(id2, id3); + ASSERT_NE(id4, id3); + ASSERT_NE(id0, id2); + ASSERT_NE(id0, id4); + ASSERT_NE(id0, id3); + +// SHashObj *phash = taosHashInit() +} + //TEST(testCase, projection_query_tables) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // ASSERT_EQ(pConn, nullptr); diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index 4b248f90e7..ebd75b9a82 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -105,7 +105,7 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str); */ int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId); int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len); int32_t stringToSubplan(const char* str, SSubplan** subplan); diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index a53cbe836d..4ff9881ccd 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -309,6 +309,7 @@ static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlan subplan->pNode = NULL; subplan->type = QUERY_TYPE_MODIFY; subplan->msgType = pPayload->msgType; + subplan->id.queryId = pCxt->pDag->queryId; RECOVERY_CURRENT_SUBPLAN(pCxt); } @@ -328,7 +329,7 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { // todo deal subquery } -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag) { +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId) { TRY(TSDB_MAX_TAG_CONDITIONS) { SPlanContext context = { .pCatalog = pCatalog, @@ -338,6 +339,8 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD }; *pDag = context.pDag; + context.pDag->queryId = requestId; + context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); } CATCH(code) { diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 9621c2e227..388a57c7e3 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 SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, uint64_t requestId) { SQueryPlanNode* logicPlan; int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { @@ -38,7 +38,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) return code; } - code = createDag(logicPlan, NULL, pDag); + code = createDag(logicPlan, NULL, pDag, requestId); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); qDestroyQueryDag(*pDag); diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 19fe803035..310944e9b6 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -700,7 +700,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { pConn->sid = sid; pConn->tranId = (uint16_t)(taosRand() & 0xFFFF); pConn->ownId = htonl(pConn->sid); - pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId); + pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPId() + (int64_t)pConn->tranId); pConn->spi = pRpc->spi; pConn->encrypt = pRpc->encrypt; if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_PASSWORD_LEN); diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index cb231e15a0..df006f44eb 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -1130,8 +1130,4 @@ SysNameInfo taosGetSysNameInfo() { return info; } -int64_t taosGetPid() { - getpid(); -} - #endif \ No newline at end of file From 0d3972ed277cf4b22675e0739b2aec6e0bea8e9e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 13:00:49 +0800 Subject: [PATCH 33/86] [td-11818] fix compiler error in a unit test. --- source/libs/planner/test/phyPlanTests.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index 02d06bb49d..b6f9612653 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -45,7 +45,8 @@ protected: int32_t run() { SQueryDag* dag = nullptr; - int32_t code = createDag(logicPlan_.get(), nullptr, &dag); + uint64_t requestId = 20; + int32_t code = createDag(logicPlan_.get(), nullptr, &dag, requestId); dag_.reset(dag); return code; } @@ -60,7 +61,8 @@ protected: return code; } SQueryDag* dag = nullptr; - code = qCreateQueryDag(query, &dag); + uint64_t requestId = 20; + code = qCreateQueryDag(query, &dag, requestId); dag_.reset(dag); return code; } From 28480de78583fca53b07710380f38d4f7f5bc303 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 13:15:23 +0800 Subject: [PATCH 34/86] [td-11818]fix compiler error. --- include/util/thash.h | 2 +- source/util/src/thash.c | 58 ++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/include/util/thash.h b/include/util/thash.h index f38ab50893..a736fc26af 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -24,7 +24,7 @@ extern "C" { #include "tlockfree.h" typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); -typedef int32_t (*_equal_fn_t)(const void*, const void*, uint32_t len); +typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len); typedef void (*_hash_before_fn_t)(void *); typedef void (*_hash_free_fn_t)(void *); diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 2841f27da4..f90b157558 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -28,13 +28,13 @@ tfree(_n); \ } while (0) -#define FREE_HASH_NODE(_h, _n) \ - do { \ - if ((_h)->freeFp) { \ +#define FREE_HASH_NODE(_h, _n) \ + do { \ + if ((_h)->freeFp) { \ (_h)->freeFp(GET_HASH_NODE_DATA(_n)); \ - } \ - \ - DO_FREE_HASH_NODE(_n); \ + } \ + \ + DO_FREE_HASH_NODE(_n); \ } while (0); static FORCE_INLINE void __wr_lock(void *lock, int32_t type) { @@ -55,7 +55,6 @@ static FORCE_INLINE void __rd_unlock(void *lock, int32_t type) { if (type == HASH_NO_LOCK) { return; } - taosRUnLockLatch(lock); } @@ -63,7 +62,6 @@ static FORCE_INLINE void __wr_unlock(void *lock, int32_t type) { if (type == HASH_NO_LOCK) { return; } - taosWUnLockLatch(lock); } @@ -225,12 +223,12 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da // need the resize process, write lock applied if (HASH_NEED_RESIZE(pHashObj)) { - __wr_lock(&pHashObj->lock, pHashObj->type); + __wr_lock((void*) &pHashObj->lock, pHashObj->type); taosHashTableResize(pHashObj); - __wr_unlock(&pHashObj->lock, pHashObj->type); + __wr_unlock((void*) &pHashObj->lock, pHashObj->type); } - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; @@ -272,7 +270,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da } // enable resize - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); atomic_add_fetch_32(&pHashObj->size, 1); return 0; @@ -289,7 +287,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da } // enable resize - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return pHashObj->enableUpdate ? 0 : -2; } @@ -308,14 +306,14 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; // no data, return directly if (atomic_load_32(&pe->num) == 0) { - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return NULL; } @@ -358,7 +356,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo taosRUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -370,14 +368,14 @@ void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, v uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; // no data, return directly if (atomic_load_32(&pe->num) == 0) { - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return NULL; } @@ -415,7 +413,7 @@ void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, v taosRUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -436,7 +434,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; @@ -450,7 +448,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi assert(pe->next == NULL); taosWUnLockLatch(&pe->latch); - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return -1; } @@ -491,7 +489,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi taosWUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return code; } @@ -502,7 +500,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi } // disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t numOfEntries = (int32_t)pHashObj->capacity; for (int32_t i = 0; i < numOfEntries; ++i) { @@ -566,7 +564,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi } } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return 0; } @@ -577,7 +575,7 @@ void taosHashClear(SHashObj *pHashObj) { SHashNode *pNode, *pNext; - __wr_lock(&pHashObj->lock, pHashObj->type); + __wr_lock((void*) &pHashObj->lock, pHashObj->type); for (int32_t i = 0; i < pHashObj->capacity; ++i) { SHashEntry *pEntry = pHashObj->hashList[i]; @@ -601,7 +599,7 @@ void taosHashClear(SHashObj *pHashObj) { } atomic_store_32(&pHashObj->size, 0); - __wr_unlock(&pHashObj->lock, pHashObj->type); + __wr_unlock((void*) &pHashObj->lock, pHashObj->type); } void taosHashCleanup(SHashObj *pHashObj) { @@ -864,7 +862,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) { char *data = NULL; // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); SHashNode *pNode = NULL; if (p) { @@ -911,7 +909,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) { } } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -920,7 +918,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { if (pHashObj == NULL || p == NULL) return; // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int slot; taosHashReleaseNode(pHashObj, p, &slot); @@ -930,7 +928,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { taosWUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); } void taosHashRelease(SHashObj *pHashObj, void *p) { From c5e3fdde863ffa8acc5d4301c8dc591397768d3e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 05:39:43 +0000 Subject: [PATCH 35/86] show tables not show stb --- source/dnode/vnode/meta/src/metaBDBImpl.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 4254ad0acd..b8ad7ab235 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -577,11 +577,16 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { STbCfg tbCfg; void * pBuf; - if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) { - pBuf = value.data; - metaDecodeTbInfo(pBuf, &tbCfg); - return tbCfg.name; - } else { - return NULL; + for (;;) { + if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) { + pBuf = value.data; + metaDecodeTbInfo(pBuf, &tbCfg); + if (tbCfg.type == META_SUPER_TABLE) { + continue; + } + return tbCfg.name; + } else { + return NULL; + } } } \ No newline at end of file From 81e7ff450e73b5635ee49f1448dd25fe3ef70d85 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 13:40:47 +0800 Subject: [PATCH 36/86] minor changes --- source/dnode/mnode/impl/src/mndSync.c | 16 ++++++++-------- source/dnode/mnode/sdb/src/sdbFile.c | 6 +++--- source/libs/wal/src/walWrite.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 7c8a8cdb96..49eaa45156 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -54,7 +54,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t start = walGetFirstVer(pWal); int64_t end = walGetLastVer(pWal); - start = MAX(lastSdbVer, start); + start = MAX(lastSdbVer + 1, start); for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { @@ -79,19 +79,19 @@ static int32_t mndRestoreWal(SMnode *pMnode) { } int64_t sdbVer = sdbUpdateVer(pSdb, 0); - if (sdbVer != lastSdbVer) { - if (walBeginSnapshot(pWal, sdbVer) < 0) { - goto WAL_RESTORE_OVER; - } + if (walBeginSnapshot(pWal, sdbVer) < 0) { + goto WAL_RESTORE_OVER; + } + if (sdbVer != lastSdbVer) { mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); if (sdbWriteFile(pSdb) != 0) { goto WAL_RESTORE_OVER; } + } - if (walEndSnapshot(pWal) < 0) { - goto WAL_RESTORE_OVER; - } + if (walEndSnapshot(pWal) < 0) { + goto WAL_RESTORE_OVER; } code = 0; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index c5306478f2..cc36b8ec13 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -81,7 +81,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, FileFd fd) { } char reserve[SDB_RESERVE_SIZE] = {0}; - ret = taosWriteFile(fd, reserve, sizeof(reserve)); + ret = taosReadFile(fd, reserve, sizeof(reserve)); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -122,7 +122,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, FileFd fd) { } } - char reserve[512] = {0}; + char reserve[SDB_RESERVE_SIZE] = {0}; if (taosWriteFile(fd, reserve, sizeof(reserve)) != sizeof(reserve)) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -210,7 +210,7 @@ int32_t sdbReadFile(SSdb *pSdb) { code = 0; pSdb->lastCommitVer = pSdb->curVer; - mError("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); + mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); PARSE_SDB_DATA_ERROR: taosCloseFile(fd); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index c8ffd9d07d..05750d6446 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -148,7 +148,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { int32_t walEndSnapshot(SWal *pWal) { int64_t ver = pWal->vers.verInSnapshotting; - if (ver == -1) return -1; + if (ver == -1) return 0; pWal->vers.snapshotVer = ver; int ts = taosGetTimestampSec(); From 1826b3035f1adb64f722da7f9530cbbd9edf225f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 21:55:10 -0800 Subject: [PATCH 37/86] minor changes --- tests/script/general/table/basic1.sim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/script/general/table/basic1.sim b/tests/script/general/table/basic1.sim index f2341a84ce..298f663822 100644 --- a/tests/script/general/table/basic1.sim +++ b/tests/script/general/table/basic1.sim @@ -46,7 +46,6 @@ print =============== create child table sql create table c1 using st tags(1) sql create table c2 using st tags(2) -return sql show tables if $rows != 2 then return -1 @@ -56,6 +55,8 @@ print $data00 $data01 $data02 print $data10 $data11 $data22 print $data20 $data11 $data22 +return + print =============== insert data sql insert into c1 values(now+1s, 1) sql insert into c1 values(now+2s, 2) From 4079bd2b5536d117b585b72e59ecb88d75566e67 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:14:12 +0800 Subject: [PATCH 38/86] refactor code --- source/libs/index/src/index.c | 21 +++---- source/libs/index/src/index_cache.c | 2 +- .../index/src/index_fst_counting_writer.c | 4 +- source/libs/index/src/index_tfile.c | 56 ++++++++++--------- source/libs/index/test/indexTests.cc | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0657c68458..691e564c68 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,16 +74,15 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); if (sIdx->tindex == NULL) { goto END; } + sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; - sIdx->path = calloc(1, strlen(path) + 1); - memcpy(sIdx->path, path, strlen(path)); + sIdx->path = tstrdup(path); pthread_mutex_init(&sIdx->mtx, NULL); - *index = sIdx; - return 0; #endif + END: if (sIdx != NULL) { indexClose(sIdx); } @@ -310,18 +309,14 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // Get col info IndexCache* cache = NULL; - pthread_mutex_lock(&sIdx->mtx); char buf[128] = {0}; ICacheKey key = {.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); + pthread_mutex_lock(&sIdx->mtx); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); - if (pCache == NULL) { - pthread_mutex_unlock(&sIdx->mtx); - return -1; - } - cache = *pCache; + cache = (pCache == NULL) ? NULL : *pCache; pthread_mutex_unlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); @@ -329,7 +324,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result STermValueType s = kTypeValue; if (0 == indexCacheSearch(cache, query, *result, &s)) { if (s == kTypeDeletion) { - indexInfo("col: %s already drop by other opera", term->colName); + indexInfo("col: %s already drop by", term->colName); // coloum already drop by other oper, no need to query tindex return 0; } else { @@ -504,17 +499,15 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); + if (reader == NULL) { goto END; } - char buf[128] = {0}; TFileHeader* header = &reader->header; ICacheKey key = { .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; pthread_mutex_lock(&sIdx->mtx); - IndexTFile* ifile = (IndexTFile*)sIdx->tindex; tfileCachePut(ifile->cache, &key, reader); - pthread_mutex_unlock(&sIdx->mtx); return ret; END: diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index e95de9286e..a4993257b3 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -261,7 +261,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { return -1; } + if (cache == NULL) { return 0; } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 0f29da1c27..c3e1aab381 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -18,7 +18,7 @@ #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { - if (ctx->offset + len > ctx->limit) { return -1; } + // if (ctx->offset + len > ctx->limit) { return -1; } if (ctx->type == TFile) { assert(len == tfWrite(ctx->file.fd, buf, len)); @@ -111,8 +111,8 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { free(ctx->mem.buf); } else { + // ctx->flush(ctx); tfClose(ctx->file.fd); - ctx->flush(ctx); if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index d4d13ddf19..b32226775d 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -67,29 +67,18 @@ TFileCache* tfileCacheCreate(const char* path) { for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - // refactor later, use colname and version info - char colName[256] = {0}; - if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { - indexInfo("try parse invalid file: %s, skip it", file); - continue; - } - - char fullName[256] = {0}; - sprintf(fullName, "%s/%s", path, file); - - WriterCtx* wc = writerCtxCreate(TFile, fullName, true, 1024 * 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); if (wc == NULL) { indexError("failed to open index:%s", file); goto End; } - char buf[128] = {0}; TFileReader* reader = tfileReaderCreate(wc); + if (reader == NULL) { goto End; } TFileHeader* header = &reader->header; - ICacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; + + char buf[128] = {0}; + ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); assert(sz < sizeof(buf)); @@ -256,7 +245,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // sort by coltype and write to tindex if (order == false) { __compar_fn_t fn; - int8_t colType = tw->header.colType; + + int8_t colType = tw->header.colType; if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { fn = tfileStrCompare; } else { @@ -351,10 +341,16 @@ void tfileWriterDestroy(TFileWriter* tw) { } IndexTFile* indexTFileCreate(const char* path) { - IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); - if (tfile == NULL) { return NULL; } + TFileCache* cache = tfileCacheCreate(path); + if (cache == NULL) { return NULL; } - tfile->cache = tfileCacheCreate(path); + IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); + if (tfile == NULL) { + tfileCacheDestroy(cache); + return NULL; + } + + tfile->cache = cache; return tfile; } void indexTFileDestroy(IndexTFile* tfile) { @@ -366,6 +362,7 @@ void indexTFileDestroy(IndexTFile* tfile) { int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; if (tfile == NULL) { return ret; } + IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; @@ -545,7 +542,6 @@ static int tfileReaderLoadHeader(TFileReader* reader) { int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); if (nread == -1) { - // indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { @@ -566,7 +562,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s ", nread, reader->header.fstOffset, ctx->file.buf); + indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); @@ -613,15 +610,20 @@ void tfileReaderUnRef(TFileReader* reader) { static SArray* tfileGetFileList(const char* path) { SArray* files = taosArrayInit(4, sizeof(void*)); + char buf[128] = {0}; + uint64_t suid; + uint32_t version; + DIR* dir = opendir(path); if (NULL == dir) { return NULL; } - struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type && DT_DIR) { continue; } - size_t len = strlen(entry->d_name); - char* buf = calloc(1, len + 1); - memcpy(buf, entry->d_name, len); + char* file = entry->d_name; + if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } + + size_t len = strlen(path) + 1 + strlen(file) + 1; + char* buf = calloc(1, len); + sprintf(buf, "%s/%s", path, file); taosArrayPush(files, &buf); } closedir(dir); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 77b6e02f18..b33b5b7632 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -848,7 +848,7 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 50 * 10000); + index->WriteMultiMillonData("tag2", "Test", 10 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From 09fe692b85560067c05c1f55f36c13d655022449 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 15:17:17 +0800 Subject: [PATCH 39/86] [td-11818] refactor log/fix bug in create child table. --- include/libs/catalog/catalog.h | 4 +- source/client/src/clientEnv.c | 4 +- source/client/src/clientImpl.c | 13 +- source/client/test/clientTests.cpp | 193 ++++++++++++------------- source/libs/catalog/src/catalog.c | 10 +- source/libs/parser/src/dCDAstProcess.c | 2 +- source/libs/qcom/src/querymsg.c | 11 +- source/libs/transport/src/rpcMain.c | 11 +- 8 files changed, 120 insertions(+), 128 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 1bd29ce396..6250bbbe9e 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -90,12 +90,12 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, cons /** * Force renew a table's local cached meta data. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @return error code */ -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName); +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName); /** * Force renew a table's local cached meta data and get the new one. diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index bfb884c57e..1c7354b445 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -53,8 +53,8 @@ static void registerRequest(SRequestObj* pRequest) { int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1); int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 1); - tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d", pRequest->self, - pRequest->pTscObj->id, num, currentInst, total); + tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d, reqId:0x%"PRIx64, pRequest->self, + pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId); } } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 0d590235ad..71fd8462af 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -371,7 +371,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con taos_close(pTscObj); pTscObj = NULL; } else { - tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p", pTscObj->id, pTscObj->connId, pTscObj->pTransporter); + tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p, reqId:0x%"PRIx64, pTscObj->id, pTscObj->connId, pTscObj->pTransporter, pRequest->requestId); destroyRequest(pRequest); } @@ -441,14 +441,13 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { * There is not response callback function for submit response. * The actual inserted number of points is the first number. */ + int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { - 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); + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->requestId, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } else { - 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); + tscError("reqId:0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x"PRIx64, pRequest->requestId, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index bb40d9ada2..193f436734 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -57,95 +57,95 @@ TEST(testCase, connect_Test) { taos_close(pConn); } -//TEST(testCase, create_user_Test) { -// TAOS* pConn = taos_connect("localhost", "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("localhost", "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("localhost", "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, create_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); -//TEST(testCase, show_user_Test) { -// TAOS* pConn = taos_connect("localhost", "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); -//} + 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)); + } -//TEST(testCase, drop_user_Test) { -// TAOS* pConn = taos_connect("localhost", "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); -//} + taos_free_result(pRes); + taos_close(pConn); +} -//TEST(testCase, show_db_Test) { -// TAOS* pConn = taos_connect("localhost", "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); -//} +TEST(testCase, create_account_Test) { + TAOS* pConn = taos_connect("localhost", "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("localhost", "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("localhost", "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("localhost", "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("localhost", "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); +} TEST(testCase, create_db_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -500,22 +500,17 @@ TEST(testCase, create_multiple_tables) { } TEST(testCase, generated_request_id_test) { - uint64_t id0 = generateRequestId(); + SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - uint64_t id1 = generateRequestId(); - uint64_t id2 = generateRequestId(); - uint64_t id3 = generateRequestId(); - uint64_t id4 = generateRequestId(); + for(int32_t i = 0; i < 1000000; ++i) { + uint64_t v = generateRequestId(); + void* result = taosHashGet(phash, &v, sizeof(v)); + ASSERT_EQ(result, nullptr); - ASSERT_NE(id0, id1); - ASSERT_NE(id1, id2); - ASSERT_NE(id2, id3); - ASSERT_NE(id4, id3); - ASSERT_NE(id0, id2); - ASSERT_NE(id0, id4); - ASSERT_NE(id0, id3); + taosHashPut(phash, &v, sizeof(v), NULL, 0); + } -// SHashObj *phash = taosHashInit() + taosHashClear(phash); } //TEST(testCase, projection_query_tables) { diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 236264873e..5992962419 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -675,28 +675,26 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta); } -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName) { +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName) { + if (NULL == pCatalog || NULL == pTransporter || NULL == pMgmtEps || NULL == pTableName) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } SVgroupInfo vgroupInfo = {0}; int32_t code = 0; - CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo)); + CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo)); STableMetaOutput output = {0}; - CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo, &output)); + CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &output)); //CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output)); _return: - tfree(output.tbMeta); - CTG_RET(code); } diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 6b42a93b73..1e92e32fef 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -501,7 +501,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p struct SVCreateTbReq req = {0}; req.type = TD_CHILD_TABLE; req.name = strdup(tNameGetTableName(&tableName)); - req.ctbCfg.suid = pSuperTableMeta->suid; + req.ctbCfg.suid = pSuperTableMeta->uid; req.ctbCfg.pTag = row; SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index b50eb2c92d..f24b191db3 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -43,15 +43,12 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 bMsg->header.vgId = htonl(bInput->vgId); if (bInput->dbName) { - strncpy(bMsg->dbFname, bInput->dbName, sizeof(bMsg->dbFname)); - bMsg->dbFname[sizeof(bMsg->dbFname) - 1] = 0; + tstrncpy(bMsg->dbFname, bInput->dbName, tListLen(bMsg->dbFname)); } - strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname)); - bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0; + tstrncpy(bMsg->tableFname, bInput->tableFullName, tListLen(bMsg->tableFname)); *msgLen = (int32_t)sizeof(*bMsg); - return TSDB_CODE_SUCCESS; } @@ -211,7 +208,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaMsg* msg, bool isSuperTable, STabl pTableMeta->vgId = isSuperTable ? 0 : msg->vgId; pTableMeta->tableType = isSuperTable ? TSDB_SUPER_TABLE : msg->tableType; - pTableMeta->uid = msg->suid; + pTableMeta->uid = msg->tuid; pTableMeta->suid = msg->suid; pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; @@ -272,7 +269,7 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { memcpy(pOut->tbFname, pMetaMsg->tbFname, sizeof(pOut->tbFname)); } - code = queryCreateTableMetaFromMsg(pMetaMsg, false, &pOut->tbMeta); + code = queryCreateTableMetaFromMsg(pMetaMsg, (pMetaMsg->tableType == TSDB_SUPER_TABLE), &pOut->tbMeta); } return code; diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 310944e9b6..a7b9bfedbe 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -1094,13 +1094,16 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { SRpcReqContext *pContext; pConn = rpcProcessMsgHead(pRpc, pRecv, &pContext); + char ipstr[24] = {0}; + taosIpPort2String(pRecv->ip, pRecv->port, ipstr); + 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, + tDebug("%s %p %p, %s received from %s, 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), ipstr, 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, - pConn, (void *)pHead->ahandle, pHead->msgType, pRecv->ip, pRecv->port, terrno, pRecv->msgLen, + tDebug("%s %p %p, %d received from %s, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, + pConn, (void *)pHead->ahandle, pHead->msgType, ipstr, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); } From 7128b3cdab2bcd31671016b8415207a4f043062d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 15:20:16 +0800 Subject: [PATCH 40/86] [td-11818] refactor. --- include/libs/parser/parsenodes.h | 4 ++-- source/libs/parser/inc/insertParser.h | 2 +- source/libs/parser/inc/parserInt.h | 2 +- source/libs/parser/src/dCDAstProcess.c | 13 +++++++------ source/libs/parser/src/insertParser.c | 6 +++--- source/libs/parser/src/parser.c | 4 ++-- source/libs/parser/test/insertParserTest.cpp | 4 ++-- source/libs/planner/src/logicPlan.c | 2 +- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index b326ac032c..18596a9e18 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -154,14 +154,14 @@ typedef struct SVgDataBlocks { char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ... } SVgDataBlocks; -typedef struct SInsertStmtInfo { +typedef struct SVnodeModifOpStmtInfo { int16_t nodeType; SArray* pDataBlocks; // data block for each vgroup, SArray. int8_t schemaAttache; // denote if submit block is built with table schema or not uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert uint32_t insertType; // insert data from [file|sql statement| bound statement] const char* sql; // current sql statement position -} SInsertStmtInfo; +} SVnodeModifOpStmtInfo; typedef struct SDclStmtInfo { int16_t nodeType; diff --git a/source/libs/parser/inc/insertParser.h b/source/libs/parser/inc/insertParser.h index b0191b155d..796bd9b429 100644 --- a/source/libs/parser/inc/insertParser.h +++ b/source/libs/parser/inc/insertParser.h @@ -22,7 +22,7 @@ extern "C" { #include "parser.h" -int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo); +int32_t parseInsertSql(SParseContext* pContext, SVnodeModifOpStmtInfo** pInfo); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 346bd0cbe4..d1629a2a3e 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -70,7 +70,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ */ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); -SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); +SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); /** * Evaluate the numeric and timestamp arithmetic expression in the WHERE clause. diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 1e92e32fef..d343451516 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -548,11 +548,12 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p taosArrayPush(pBufArray, &pVgData); } while (true); - SInsertStmtInfo* pStmtInfo = calloc(1, sizeof(SInsertStmtInfo)); - pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; + SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo)); + pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; pStmtInfo->pDataBlocks = pBufArray; - *pOutput = pStmtInfo; - *len = sizeof(SInsertStmtInfo); + + *pOutput = (char*) pStmtInfo; + *len = sizeof(SVnodeModifOpStmtInfo); return TSDB_CODE_SUCCESS; } @@ -823,14 +824,14 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c return NULL; } -SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { +SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; assert(pCreateTable->type == TSQL_CREATE_CTABLE); SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf* pMsgBuf = &m; - SInsertStmtInfo* pInsertStmt = NULL; + SVnodeModifOpStmtInfo* pInsertStmt = NULL; int32_t msgLen = 0; int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pInsertStmt, &msgLen); diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index 66966f75db..c0ba4f40b4 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -61,7 +61,7 @@ typedef struct SInsertParseContext { SArray* pTableDataBlocks; // global SArray* pVgDataBlocks; // global int32_t totalNum; - SInsertStmtInfo* pOutput; + SVnodeModifOpStmtInfo* pOutput; } SInsertParseContext; static int32_t skipInsertInto(SInsertParseContext* pCxt) { @@ -611,7 +611,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { // [(field1_name, ...)] // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; -int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { +int32_t parseInsertSql(SParseContext* pContext, SVnodeModifOpStmtInfo** pInfo) { SInsertParseContext context = { .pComCxt = pContext, .pSql = (char*) pContext->pSql, @@ -620,7 +620,7 @@ int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), .pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false), .totalNum = 0, - .pOutput = calloc(1, sizeof(SInsertStmtInfo)) + .pOutput = calloc(1, sizeof(SVnodeModifOpStmtInfo)) }; if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pOutput) { diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 1b4d05808c..9455d23a1c 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -53,7 +53,7 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (toVnode) { - SInsertStmtInfo *pInsertInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); + SVnodeModifOpStmtInfo *pInsertInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); if (pInsertInfo == NULL) { return terrno; } @@ -87,7 +87,7 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { int32_t qParseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { if (isInsertSql(pCxt->pSql, pCxt->sqlLen)) { - return parseInsertSql(pCxt, (SInsertStmtInfo**)pQuery); + return parseInsertSql(pCxt, (SVnodeModifOpStmtInfo**)pQuery); } else { return parseQuerySql(pCxt, pQuery); } diff --git a/source/libs/parser/test/insertParserTest.cpp b/source/libs/parser/test/insertParserTest.cpp index 9e681c7ccb..5c175cd023 100644 --- a/source/libs/parser/test/insertParserTest.cpp +++ b/source/libs/parser/test/insertParserTest.cpp @@ -60,7 +60,7 @@ protected: return code_; } - SInsertStmtInfo* reslut() { + SVnodeModifOpStmtInfo* reslut() { return res_; } @@ -128,7 +128,7 @@ private: char sqlBuf_[max_sql_len]; SParseContext cxt_; int32_t code_; - SInsertStmtInfo* res_; + SVnodeModifOpStmtInfo* res_; }; // INSERT INTO tb_name VALUES (field1_value, ...) diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index 2de0ae2da3..d04fd716c2 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -38,7 +38,7 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { } static int32_t createModificationOpPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { - SInsertStmtInfo* pInsert = (SInsertStmtInfo*)pNode; + SVnodeModifOpStmtInfo* pInsert = (SVnodeModifOpStmtInfo*)pNode; *pQueryPlan = calloc(1, sizeof(SQueryPlanNode)); SArray* blocks = taosArrayInit(taosArrayGetSize(pInsert->pDataBlocks), POINTER_BYTES); From c94f30e3838106d50423bd8c64eb901ca6675313 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 3 Jan 2022 23:20:29 -0800 Subject: [PATCH 41/86] add some logs --- source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mndShow.c | 2 +- source/dnode/mnode/impl/src/mndSync.c | 16 ++++++++----- source/dnode/mnode/impl/src/mndTrans.c | 14 +++++++---- source/dnode/mnode/impl/src/mnode.c | 28 +++++++++++----------- source/dnode/mnode/sdb/src/sdb.c | 4 ++-- source/dnode/mnode/sdb/src/sdbFile.c | 1 + source/dnode/mnode/sdb/src/sdbHash.c | 32 +++++++++++++++++++++----- 8 files changed, 64 insertions(+), 35 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d110969025..1d78359015 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -354,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) { } if (pStatus->dnodeId == 0) { - mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); + mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { if (pStatus->clusterId != pMnode->clusterId) { if (pDnode != NULL) { diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index c156c87123..125c250614 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -152,7 +152,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { } int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 49eaa45156..19fb89454e 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -52,11 +52,12 @@ static int32_t mndRestoreWal(SMnode *pMnode) { SWalReadHandle *pHandle = walOpenReadHandle(pWal); if (pHandle == NULL) return -1; - int64_t start = walGetFirstVer(pWal); - int64_t end = walGetLastVer(pWal); - start = MAX(lastSdbVer + 1, start); + int64_t first = walGetFirstVer(pWal); + int64_t last = walGetLastVer(pWal); + mDebug("restore sdb wal start, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last); - for (int64_t ver = start; ver >= 0 && ver <= end; ++ver) { + first = MAX(lastSdbVer + 1, first); + for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) { if (walReadWithHandle(pHandle, ver) < 0) { mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver); goto WAL_RESTORE_OVER; @@ -76,15 +77,18 @@ static int32_t mndRestoreWal(SMnode *pMnode) { } sdbUpdateVer(pSdb, 1); + mDebug("wal:%" PRId64 ", is restored", ver); } int64_t sdbVer = sdbUpdateVer(pSdb, 0); + mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer); + if (walBeginSnapshot(pWal, sdbVer) < 0) { goto WAL_RESTORE_OVER; } if (sdbVer != lastSdbVer) { - mInfo("sdb restore wal from %" PRId64 " to %" PRId64, lastSdbVer, sdbVer); + mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer); if (sdbWriteFile(pSdb) != 0) { goto WAL_RESTORE_OVER; } @@ -147,7 +151,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { return -1; } - mTrace("raw:%p has been write to wal, ver:%" PRId64, pRaw, ver); + mTrace("raw:%p, write to wal, ver:%" PRId64, pRaw, ver); walCommit(pWal, ver); walFsync(pWal, true); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 5062048d6d..bf472a504c 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -169,7 +169,7 @@ TRANS_ENCODE_OVER: return NULL; } - mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos); + mTrace("trans:%d, encode to raw:%p, row:%p len:%d", pTrans->id, pRaw, pTrans, dataPos); return pRaw; } @@ -226,6 +226,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -235,6 +236,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -243,6 +245,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < commitLogNum; ++i) { SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER; pData = NULL; @@ -284,13 +288,13 @@ TRANS_DECODE_OVER: return NULL; } - mTrace("trans:%d, decode from raw:%p, data:%p", pTrans->id, pRaw, pTrans); + mTrace("trans:%d, decode from raw:%p, row:%p", pTrans->id, pRaw, pTrans); return pRow; } static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { pTrans->stage = TRN_STAGE_PREPARE; - mTrace("trans:%d, perform insert action, data:%p", pTrans->id, pTrans); + mTrace("trans:%d, perform insert action, row:%p", pTrans->id, pTrans); return 0; } @@ -303,13 +307,13 @@ static void mndTransDropData(STrans *pTrans) { } static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { - mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); + mTrace("trans:%d, perform delete action, row:%p", pTrans->id, pTrans); mndTransDropData(pTrans); return 0; } static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) { - mTrace("trans:%d, perform update action, data:%p", pOldTrans->id, pOldTrans); + mTrace("trans:%d, perform update action, old_row:%p new_row:%p", pOldTrans->id, pOldTrans, pNewTrans); pOldTrans->stage = pNewTrans->stage; return 0; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 3a55961d4a..abc86a7d35 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -185,7 +185,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { for (int32_t s = pos; s >= 0; s--) { SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, s); - mDebug("step:%s will cleanup", pStep->name); + mDebug("%s will cleanup", pStep->name); if (pStep->cleanupFp != NULL) { (*pStep->cleanupFp)(pMnode); } @@ -204,12 +204,12 @@ static int32_t mndExecSteps(SMnode *pMnode) { if ((*pStep->initFp)(pMnode) != 0) { int32_t code = terrno; - mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); + mError("%s exec failed since %s, start to cleanup", pStep->name, terrstr()); mndCleanupSteps(pMnode, pos); terrno = code; return -1; } else { - mDebug("step:%s is initialized", pStep->name); + mDebug("%s is initialized", pStep->name); } } @@ -357,7 +357,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); return NULL; } @@ -365,7 +365,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { taosFreeQitem(pMsg); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); return NULL; } memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); @@ -374,12 +374,12 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { pMsg->rpcMsg = *pRpcMsg; pMsg->createdTime = taosGetTimestampSec(); - mTrace("msg:%p, app:%p is created, RPC:%p", pMsg, pRpcMsg->ahandle, pRpcMsg->handle); + mTrace("msg:%p, is created, app:%p RPC:%p user:%s", pMsg, pRpcMsg->ahandle, pRpcMsg->handle, pMsg->user); return pMsg; } void mndCleanupMsg(SMnodeMsg *pMsg) { - mTrace("msg:%p, app:%p is destroyed, RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); + mTrace("msg:%p, is destroyed, app:%p RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); rpcFreeCont(pMsg->rpcMsg.pCont); pMsg->rpcMsg.pCont = NULL; taosFreeQitem(pMsg); @@ -397,37 +397,37 @@ void mndProcessMsg(SMnodeMsg *pMsg) { void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); - mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType)); + mTrace("msg:%p, type:%s will be processed, app:%p", pMsg, TMSG_INFO(msgType), ahandle); if (isReq && !mndIsMaster(pMnode)) { code = TSDB_CODE_APP_NOT_READY; - mDebug("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mDebug("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } if (isReq && pMsg->rpcMsg.pCont == NULL) { code = TSDB_CODE_MND_INVALID_MSG_LEN; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(msgType)]; if (fp == NULL) { code = TSDB_CODE_MSG_NOT_PROCESSED; - mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle); + mError("msg:%p, failed to process since no msg handle, app:%p", pMsg, ahandle); goto PROCESS_RPC_END; } code = (*fp)(pMsg); if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mTrace("msg:%p, app:%p in progressing", pMsg, ahandle); + mTrace("msg:%p, in progress, app:%p", pMsg, ahandle); return; } else if (code != 0) { code = terrno; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } else { - mTrace("msg:%p, app:%p is processed", pMsg, ahandle); + mTrace("msg:%p, is processed, app:%p", pMsg, ahandle); } PROCESS_RPC_END: diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 0671434218..ef5bb6f16f 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -65,7 +65,7 @@ void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastCommitVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + mDebug("write sdb file for current ver:%" PRId64 " != last commit ver:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); sdbWriteFile(pSdb); } @@ -138,7 +138,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { pSdb->maxId[sdbType] = 0; pSdb->hashObjs[sdbType] = hash; taosInitRWLatch(&pSdb->locks[sdbType]); - mDebug("sdb table:%d is initialized", sdbType); + mDebug("sdb table:%s is initialized", sdbTableName(sdbType)); return 0; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index cc36b8ec13..970fdc2061 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -146,6 +146,7 @@ int32_t sdbReadFile(SSdb *pSdb) { char file[PATH_MAX] = {0}; snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); + mDebug("start to read file:%s", file); FileFd fd = taosOpenFileRead(file); if (fd <= 0) { diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 4b11ec3e76..733075757f 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -57,18 +57,35 @@ const char *sdbTableName(ESdbType type) { } } +static const char *sdbStatusStr(ESdbStatus status) { + switch (status) { + case SDB_STATUS_CREATING: + return "creating"; + case SDB_STATUS_UPDATING: + return "updating"; + case SDB_STATUS_DROPPING: + return "dropping"; + case SDB_STATUS_READY: + return "ready"; + case SDB_STATUS_DROPPED: + return "dropped"; + default: + return "undefine"; + } +} + void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { EKeyType keyType = pSdb->keyTypes[pRow->type]; if (keyType == SDB_KEY_BINARY) { - mTrace("%s:%s, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper, - pRow->pObj); + mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, + oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT32) { - mTrace("%s:%d, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper, - pRow->pObj); + mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT64) { - mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, - pRow->refCount, oper, pRow->pObj); + mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else { } } @@ -165,6 +182,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "updateRow"); taosRUnLockLatch(pLock); int32_t code = 0; @@ -193,6 +211,8 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "deleteRow"); + taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); From 1ddd99b6fc5330850bddd4925a8d09c7b0fe5ca0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 07:39:08 +0000 Subject: [PATCH 42/86] fix problem --- source/dnode/vnode/impl/src/vnodeQuery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index cbc4d75e8b..5f850f0112 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -86,7 +86,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (pTbCfg->type == META_SUPER_TABLE) { nTagCols = pTbCfg->stbCfg.nTagCols; pTagSchema = pTbCfg->stbCfg.pTagSchema; - } else if (pTbCfg->type == META_SUPER_TABLE) { + } else if (pTbCfg->type == META_CHILD_TABLE) { nTagCols = pStbCfg->stbCfg.nTagCols; pTagSchema = pStbCfg->stbCfg.pTagSchema; } else { From 4bdac1fdbf987faf2be31ff78620934b35966d00 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:59:54 +0800 Subject: [PATCH 43/86] optimize tfile --- source/libs/index/src/index.c | 2 +- source/libs/index/src/index_cache.c | 2 +- source/libs/index/src/index_tfile.c | 11 ++++++----- source/libs/index/test/indexTests.cc | 12 +++++------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 691e564c68..44d3066589 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -397,7 +397,7 @@ static void indexDestroyTempResult(SArray* result) { } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { if (sIdx == NULL) { return -1; } - indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index a4993257b3..517cb1640d 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,7 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 5 * 10000 +#define MEM_TERM_LIMIT 10 * 10000 // ref index_cache.h:22 //#define CACHE_KEY_LEN(p) \ // (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index b32226775d..753dbe87b1 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -264,7 +264,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - // taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL); + taosArraySort(v->tableId, tfileUidCompare); + taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -545,8 +546,8 @@ static int tfileReaderLoadHeader(TFileReader* reader) { indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { - indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), - errno, reader->ctx->file.fd, reader->ctx->file.buf); + indexInfo("actual Read: %d, to read: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), + reader->ctx->file.fd, reader->ctx->file.buf); } // assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); @@ -562,8 +563,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, - ctx->file.size); + indexInfo("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index b33b5b7632..c3d6e5541f 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -701,7 +701,8 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << std::endl; + std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } int sz = taosArrayGetSize(result); @@ -834,11 +835,8 @@ static void write_and_search(IndexObj* idx) { std::string colName("tag1"), colVal("Hello"); int target = idx->SearchOne("tag1", "Hello"); - std::cout << "search: " << target << std::endl; target = idx->SearchOne("tag2", "Test"); - std::cout << "search: " << target << std::endl; - - idx->PutOne(colName, colVal); + // idx->PutOne(colName, colVal); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { std::string path = "/tmp/cache_and_tfile"; @@ -847,8 +845,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); - index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 10 * 10000); + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From eb9a70975ae47bc227e246300358ffb4db6b88b6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 4 Jan 2022 16:13:46 +0800 Subject: [PATCH 44/86] feature/qnode --- source/libs/qcom/src/querymsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index f24b191db3..507650159f 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -247,8 +247,8 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { pOut->metaNum = 2; if (pMetaMsg->dbFname[0]) { - snprintf(pOut->ctbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); - snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); + snprintf(pOut->ctbFname, sizeof(pOut->ctbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, sizeof(pOut->tbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); } else { memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); From 9328785043dc788d8f747c1c013d60c7fcc42ba1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 16:21:32 +0800 Subject: [PATCH 45/86] [td-11818] refactor. --- include/libs/catalog/catalog.h | 4 +- include/os/osSysinfo.h | 2 +- source/client/src/clientEnv.c | 19 +++++---- source/client/src/clientImpl.c | 6 +-- source/client/test/clientTests.cpp | 12 +++++- source/dnode/mnode/impl/src/mndCluster.c | 2 +- source/libs/catalog/src/catalog.c | 4 +- source/libs/parser/src/dCDAstProcess.c | 50 +++++++++++++++--------- source/libs/scheduler/src/scheduler.c | 5 ++- source/os/src/osSysinfo.c | 6 +-- 10 files changed, 68 insertions(+), 42 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 6250bbbe9e..3916898829 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -100,13 +100,13 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, co /** * Force renew a table's local cached meta data and get the new one. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) * @return error code */ -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); /** diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index b410255ea4..36ff4194d8 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB); void taosPrintOsInfo(); int taosSystem(const char *cmd); void taosKillSystem(); -int32_t taosGetSystemUid(char *uid, int32_t uidlen); +int32_t taosGetSystemUUID(char *uid, int32_t uidlen); char * taosGetCmdlineByPID(int pid); void taosSetCoreDump(bool enable); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 1c7354b445..47d0e517d5 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -419,17 +419,20 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { *+------------+-----+-----------+---------------+ * @return */ -static int32_t requestSerialId = 0; uint64_t generateRequestId() { - uint64_t hashId = 0; + static uint64_t hashId = 0; + static int32_t requestSerialId = 0; - char uid[64] = {0}; - int32_t code = taosGetSystemUid(uid, tListLen(uid)); - if (code != TSDB_CODE_SUCCESS) { - tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", tstrerror(TAOS_SYSTEM_ERROR(errno))); + if (hashId == 0) { + char uid[64] = {0}; + int32_t code = taosGetSystemUUID(uid, tListLen(uid)); + if (code != TSDB_CODE_SUCCESS) { + tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", + tstrerror(TAOS_SYSTEM_ERROR(errno))); - } else { - hashId = MurmurHash3_32(uid, strlen(uid)); + } else { + hashId = MurmurHash3_32(uid, strlen(uid)); + } } int64_t ts = taosGetTimestampUs(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 71fd8462af..394bf654c0 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj* (*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlLen = sqlLen; - tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr); + tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId); return TSDB_CODE_SUCCESS; } @@ -443,10 +443,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { */ int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { - tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->requestId, + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->self, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } else { - tscError("reqId:0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x"PRIx64, pRequest->requestId, + tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%"PRIx64, pRequest->self, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 193f436734..26f1141cc0 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -496,6 +496,17 @@ TEST(testCase, create_multiple_tables) { } taos_free_result(pRes); + +// for(int32_t i = 0; i < 10000; ++i) { +// char sql[512] = {0}; +// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); +// TAOS_RES* pres = taos_query(pConn, sql); +// if (taos_errno(pres) != 0) { +// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); +// } +// taos_free_result(pres); +// } + taos_close(pConn); } @@ -506,7 +517,6 @@ TEST(testCase, generated_request_id_test) { uint64_t v = generateRequestId(); void* result = taosHashGet(phash, &v, sizeof(v)); ASSERT_EQ(result, nullptr); - taosHashPut(phash, &v, sizeof(v), NULL, 0); } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 00cfa6b413..b29f8276fe 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -145,7 +145,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { clusterObj.createdTime = taosGetTimestampMs(); clusterObj.updateTime = clusterObj.createdTime; - int32_t code = taosGetSystemUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); + int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN); if (code != 0) { strcpy(clusterObj.name, "tdengine2.0"); mError("failed to get name from system, set to default val %s", clusterObj.name); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 5992962419..abcfafa786 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -698,8 +698,8 @@ _return: CTG_RET(code); } -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, true, pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, true, pTableMeta); } int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index d343451516..6007fc300c 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -326,6 +326,31 @@ typedef struct SVgroupTablesBatch { SVgroupInfo info; } SVgroupTablesBatch; +static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputTag, SKVRowBuilder* pKvRowBuilder, + SArray* pTagValList, int32_t tsPrecision, SMsgBuf* pMsgBuf) { + const char* msg1 = "illegal value or data overflow"; + int32_t code = TSDB_CODE_SUCCESS; + + for (int32_t i = 0; i < numOfInputTag; ++i) { + SSchema* pSchema = &pTagSchema[i]; + + char* endPtr = NULL; + char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; + + SKvParam param = {.builder = pKvRowBuilder, .schema = pSchema}; + + SToken* pItem = taosArrayGet(pTagValList, i); + code = parseValueToken(&endPtr, pItem, pSchema, tsPrecision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); + + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(pKvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + return code; +} + int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; @@ -354,10 +379,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } SArray* pValList = pCreateTableInfo->pTagVals; + size_t numOfInputTag = taosArrayGetSize(pValList); - size_t numOfInputTag = taosArrayGetSize(pValList); STableMeta* pSuperTableMeta = NULL; - code = catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); if (code != TSDB_CODE_SUCCESS) { return code; @@ -463,21 +487,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return buildInvalidOperationMsg(pMsgBuf, msg2); } - for (int32_t i = 0; i < numOfInputTag; ++i) { - SSchema* pSchema = &pTagSchema[i]; - - char* endPtr = NULL; - char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; - - SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; - - SToken* pItem = taosArrayGet(pValList, i); - code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); - - if (code != TSDB_CODE_SUCCESS) { - tdDestroyKVRowBuilder(&kvRowBuilder); - return buildInvalidOperationMsg(pMsgBuf, msg4); - } + code = doParseSerializeTagValue(pTagSchema, numOfInputTag, &kvRowBuilder, pValList, tinfo.precision, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; } } @@ -499,8 +511,8 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); struct SVCreateTbReq req = {0}; - req.type = TD_CHILD_TABLE; - req.name = strdup(tNameGetTableName(&tableName)); + req.type = TD_CHILD_TABLE; + req.name = strdup(tNameGetTableName(&tableName)); req.ctbCfg.suid = pSuperTableMeta->uid; req.ctbCfg.pTag = row; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 22556f742b..9079912c40 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -372,7 +372,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { SCH_ERR_RET(schMoveTaskToSuccList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ERR_LOG(" task may already moved, status:%d", task->status); return TSDB_CODE_SUCCESS; } @@ -480,7 +480,6 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; - switch (msgType) { case TDMT_VND_CREATE_TABLE_RSP: { if (rspCode != TSDB_CODE_SUCCESS) { @@ -492,6 +491,8 @@ int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *ms goto _task_error; } } + + break; } case TDMT_VND_SUBMIT_RSP: { if (rspCode != TSDB_CODE_SUCCESS) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index df006f44eb..e235b0714e 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -252,7 +252,7 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { GUID guid; CoCreateGuid(&guid); @@ -452,7 +452,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { uuid_t uuid = {0}; uuid_generate(uuid); // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null @@ -1070,7 +1070,7 @@ void taosSetCoreDump(bool enable) { #endif } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { int fd; int len = 0; From a94487ab34050b800a09be6104059f457087e2a3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 08:29:05 +0000 Subject: [PATCH 46/86] fix invalid read --- source/dnode/vnode/meta/src/metaBDBImpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index b8ad7ab235..ae6693f973 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -382,8 +382,8 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *pSKey // Second key is the first tag void *pTagVal = tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId); - pDbt[1].data = varDataVal(pTagVal); - pDbt[1].size = varDataLen(pTagVal); + pDbt[1].data = pTagVal; + pDbt[1].size = sizeof(int32_t); // Set index key memset(pSKey, 0, sizeof(*pSKey)); From c426ae83836191a36931041fa0b146d30ad1852f Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 03:32:48 -0500 Subject: [PATCH 47/86] TD-12696 bug fix for insert --- source/libs/parser/inc/dataBlockMgt.h | 2 +- source/libs/parser/src/insertParser.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/inc/dataBlockMgt.h b/source/libs/parser/inc/dataBlockMgt.h index 69dad4d9f4..cd84222c65 100644 --- a/source/libs/parser/inc/dataBlockMgt.h +++ b/source/libs/parser/inc/dataBlockMgt.h @@ -126,7 +126,7 @@ static FORCE_INLINE void getMemRowAppendInfo(SSchema *pSchema, uint8_t memRowTyp int32_t idx, int32_t *toffset) { int32_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { - schemaIdx = spd->boundedColumns[idx]; + schemaIdx = spd->boundedColumns[idx] - 1; if (isDataRowT(memRowType)) { *toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart } else { diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index c0ba4f40b4..cde426fb9a 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -425,7 +425,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i]]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From e5155adcacfe766176d2d2c9fd36f6716693d877 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:05:33 -0500 Subject: [PATCH 48/86] TD-12696 bug fix for insert --- source/libs/parser/src/insertParser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index cde426fb9a..c63e854051 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -106,6 +106,7 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { SVgroupInfo vg; CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); + pCxt->pTableMeta->vgId = vg.vgId; // todo remove return TSDB_CODE_SUCCESS; } @@ -425,7 +426,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From b15ea75b996d2705ea7f90a44ed98e212cfeb998 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:16:32 -0500 Subject: [PATCH 49/86] TD-12696 bug fix for insert --- source/client/src/clientImpl.c | 5 ++++- source/client/src/clientMain.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 71fd8462af..a4750309e8 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -203,7 +203,10 @@ int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { - return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); + SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; + int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res); + pRequest->affectedRows = res.numOfRows; + return res.code; } return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e5f3eba5c2..2b875b3eb5 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -262,6 +262,8 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } -int taos_affected_rows(TAOS_RES *res) { return 1; } +int taos_affected_rows(TAOS_RES *res) { + return ((SRequestObj*)res)->affectedRows; +} int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } From dcb0de0b5cf7d86ec0f40ab4b4c4deb6e9db2e93 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 01:17:25 -0800 Subject: [PATCH 50/86] test cases for trans --- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 + source/dnode/mgmt/impl/test/sut/inc/server.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 10 ++- source/dnode/mnode/impl/test/CMakeLists.txt | 1 + source/dnode/mnode/impl/test/acct/acct.cpp | 6 +- .../mnode/impl/test/trans/CMakeLists.txt | 11 +++ source/dnode/mnode/impl/test/trans/trans.cpp | 86 +++++++++++++++++++ source/dnode/mnode/impl/test/user/user.cpp | 8 +- source/dnode/mnode/sdb/src/sdbFile.c | 2 +- 9 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 source/dnode/mnode/impl/test/trans/CMakeLists.txt create mode 100644 source/dnode/mnode/impl/test/trans/trans.cpp diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index 41382fbab5..24278a73f7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -37,6 +37,8 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); + void ServerStop(); + void ServerStart(); SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); private: diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h index aa7b37f221..5f9e4846a7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/server.h +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -21,10 +21,10 @@ class TestServer { bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); void Stop(); void Restart(); + bool DoStart(); private: SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); - bool DoStart(); private: SDnode* pDnode; diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 429d5a6976..e1b6664e9f 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -16,13 +16,13 @@ #include "base.h" void Testbase::InitLog(const char* path) { - dDebugFlag = 207; + dDebugFlag = 0; vDebugFlag = 0; - mDebugFlag = 207; + mDebugFlag = 143; cDebugFlag = 0; jniDebugFlag = 0; tmrDebugFlag = 0; - uDebugFlag = 143; + uDebugFlag = 0; rpcDebugFlag = 0; qDebugFlag = 0; wDebugFlag = 0; @@ -60,6 +60,10 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } +void Testbase::ServerStop() { server.Stop(); } + +void Testbase::ServerStart() { server.DoStart(); } + SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index fa7b45f988..dfac7a76c9 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -2,3 +2,4 @@ enable_testing() add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(trans) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 934a2d96b4..5f105d99f3 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,11 +1,11 @@ /** * @file acct.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module acct-msg tests - * @version 0.1 + * @brief MNODE module acct tests + * @version 1.0 * @date 2021-12-15 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ diff --git a/source/dnode/mnode/impl/test/trans/CMakeLists.txt b/source/dnode/mnode/impl/test/trans/CMakeLists.txt new file mode 100644 index 0000000000..d7c9756794 --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. TRANS_SRC) +add_executable(mnode_test_trans ${TRANS_SRC}) +target_link_libraries( + mnode_test_trans + PUBLIC sut +) + +add_test( + NAME mnode_test_trans + COMMAND mnode_test_trans +) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp new file mode 100644 index 0000000000..1400ad897f --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -0,0 +1,86 @@ +/** + * @file user.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module trans tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "base.h" +#include "os.h" + +class DndTestTrans : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } + static void TearDownTestSuite() { test.Cleanup(); } + static void KillThenRestartServer() { + char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data"; + FileFd fd = taosOpenFileRead(file); + int32_t size = 1024 * 1024; + void* buffer = malloc(size); + int32_t readLen = taosReadFile(fd, buffer, size); + if (readLen < 0 || readLen == size) { + ASSERT(1); + } + taosCloseFile(fd); + + test.ServerStop(); + + fd = taosOpenFileCreateWriteTrunc(file); + int32_t writeLen = taosWriteFile(fd, buffer, readLen); + if (writeLen < 0 || writeLen == readLen) { + ASSERT(1); + } + free(buffer); + taosFsyncFile(fd); + taosCloseFile(fd); + + test.ServerStart(); + } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestTrans::test; + +TEST_F(DndTestTrans, 01_CreateUser_Crash) { + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + KillThenRestartServer(); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("u2", TSDB_USER_LEN); + // CheckBinary("super", 10); + // CheckBinary("normal", 10); + // CheckTimestamp(); + // CheckTimestamp(); + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("root", TSDB_USER_LEN); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ad2e38e0a4..536150ccfd 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,8 +1,8 @@ /** * @file user.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module user-msg tests - * @version 0.1 + * @brief MNODE module user tests + * @version 1.0 * @date 2021-12-15 * * @copyright Copyright (c) 2021 @@ -13,7 +13,7 @@ class DndTestUser : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; @@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) { EXPECT_EQ(test.GetShowRows(), 1); } -TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { +TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserMsg); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 970fdc2061..1f6d6cbda8 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -231,7 +231,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { mDebug("start to write file:%s", curfile); - FileFd fd = taosOpenFileCreateWrite(tmpfile); + FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile); if (fd <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr()); From 5f70d7b241908fc6e4fd9ffda468c955c111d47c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 01:39:48 -0800 Subject: [PATCH 51/86] minor changes --- source/dnode/mnode/impl/test/trans/trans.cpp | 18 +++++++++--------- source/dnode/mnode/sdb/src/sdb.c | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 1400ad897f..1be38b3289 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -1,5 +1,5 @@ /** - * @file user.cpp + * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests * @version 1.0 @@ -75,12 +75,12 @@ TEST_F(DndTestTrans, 01_CreateUser_Crash) { test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 2); - // CheckBinary("root", TSDB_USER_LEN); - // CheckBinary("u2", TSDB_USER_LEN); - // CheckBinary("super", 10); - // CheckBinary("normal", 10); - // CheckTimestamp(); - // CheckTimestamp(); - // CheckBinary("root", TSDB_USER_LEN); - // CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index ef5bb6f16f..39b5bb4d5b 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -64,8 +64,9 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for current ver:%" PRId64 " != last commit ver:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + if (pSdb->curVer > pSdb->lastCommitVer) { + mDebug("write sdb file for current ver:%" PRId64 " larger than last commit ver:%" PRId64, pSdb->curVer, + pSdb->lastCommitVer); sdbWriteFile(pSdb); } From 1c7c7ee6720b73b9a5e55e200b28a32a8e512ac5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 09:54:38 +0000 Subject: [PATCH 52/86] add more plugins --- .devcontainer/devcontainer.json | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 65d0b1915c..b258a2a252 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,13 +6,17 @@ "dockerfile": "Dockerfile", // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 // Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon - "args": { "VARIANT": "ubuntu-21.04" } + "args": { + "VARIANT": "ubuntu-21.04" + } }, - "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], - + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], // Set *default* container specific settings.json values on container create. "settings": {}, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-vscode.cpptools", @@ -21,15 +25,13 @@ "visualstudioexptteam.vscodeintel", "eamodio.gitlens", "matepek.vscode-catch2-test-adapter", - "spmeesseman.vscode-taskexplorer" + "spmeesseman.vscode-taskexplorer", + "cschlosser.doxdocgen" ], - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "gcc -v", - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "root" -} +} \ No newline at end of file From cee5a2ecbe92212ee1b3bba2b39069973055069a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 18:01:31 +0800 Subject: [PATCH 53/86] optimize tfile --- include/util/tfile.h | 2 +- .../index/inc/index_fst_counting_writer.h | 5 +++++ .../index/src/index_fst_counting_writer.c | 20 ++++++++++++++++++- source/libs/index/test/indexTests.cc | 2 +- source/util/src/tfile.c | 10 ++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/util/tfile.h b/include/util/tfile.h index b3d141c443..d3813051a4 100644 --- a/include/util/tfile.h +++ b/include/util/tfile.h @@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd); bool tfValid(int64_t tfd); int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence); int32_t tfFtruncate(int64_t tfd, int64_t length); - +void * tfMmapReadOnly(int64_t tfd, int64_t length); #ifdef __cplusplus } #endif diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index fcc0d5a0b3..d7363f2f4c 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -22,6 +22,8 @@ extern "C" { #include "tfile.h" +//#define USE_MMAP 1 + #define DefaultMem 1024 * 1024 static char tmpFile[] = "./index"; @@ -39,6 +41,9 @@ typedef struct WriterCtx { bool readOnly; char buf[256]; int size; +#ifdef USE_MMAP + char* ptr; +#endif } file; struct { int32_t capa; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index c3e1aab381..2b64d65e46 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -31,7 +31,12 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len) { int nRead = 0; if (ctx->type == TFile) { +#ifdef USE_MMAP + nRead = len < ctx->file.size ? len : ctx->file.size; + memcpy(buf, ctx->file.ptr, nRead); +#else nRead = tfRead(ctx->file.fd, buf, len); +#endif } else { memcpy(buf, ctx->mem.buf + ctx->offset, len); } @@ -43,7 +48,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off int nRead = 0; if (ctx->type == TFile) { // tfLseek(ctx->file.fd, offset, 0); +#ifdef USE_MMAP + int32_t last = ctx->file.size - offset; + nRead = last >= len ? len : last; + memcpy(buf, ctx->file.ptr + offset, nRead); +#else nRead = tfPread(ctx->file.fd, buf, len, offset); +#endif } else { // refactor later assert(0); @@ -83,6 +94,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int struct stat fstat; stat(path, &fstat); ctx->file.size = fstat.st_size; +#ifdef USE_MMAP + ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.fd, ctx->file.size); +#endif } memcpy(ctx->file.buf, path, strlen(path)); if (ctx->file.fd < 0) { @@ -111,8 +125,12 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { free(ctx->mem.buf); } else { - // ctx->flush(ctx); tfClose(ctx->file.fd); + if (ctx->file.readOnly) { +#ifdef USE_MMAP + munmap(ctx->file.ptr, ctx->file.size); +#endif + } if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index c3d6e5541f..badc510b19 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -28,7 +28,7 @@ #include "tutil.h" using namespace std; -#define NUM_OF_THREAD 10 +#define NUM_OF_THREAD 5 class DebugInfo { public: diff --git a/source/util/src/tfile.c b/source/util/src/tfile.c index 4cb20802c7..0f68e9204d 100644 --- a/source/util/src/tfile.c +++ b/source/util/src/tfile.c @@ -158,3 +158,13 @@ int32_t tfFtruncate(int64_t tfd, int64_t length) { taosReleaseRef(tsFileRsetId, tfd); return code; } + +void *tfMmapReadOnly(int64_t tfd, int64_t length) { + void *p = taosAcquireRef(tsFileRsetId, tfd); + if (p == NULL) return NULL; + int32_t fd = (int32_t)(uintptr_t)p; + + void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); + taosReleaseRef(tsFileRsetId, tfd); + return ptr; +} From 0b9d4c5f71a0001d4ef3e9a84afbe217a43e2c7d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 19:37:38 +0800 Subject: [PATCH 54/86] [td-11818] fix memory leaks. --- source/client/src/clientEnv.c | 10 +- source/client/src/clientMsgHandler.c | 6 + source/client/test/clientTests.cpp | 341 +++++++++++++------------ source/libs/parser/src/dCDAstProcess.c | 30 ++- source/libs/parser/src/parser.c | 2 +- 5 files changed, 208 insertions(+), 181 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 47d0e517d5..99a0d50fdb 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty return pRequest; } +static void doFreeReqResultInfo(SReqResultInfo* pResInfo) { + tfree(pResInfo->pRspMsg); + tfree(pResInfo->length); + tfree(pResInfo->row); + tfree(pResInfo->pCol); + tfree(pResInfo->fields); +} + static void doDestroyRequest(void* p) { assert(p != NULL); SRequestObj* pRequest = (SRequestObj*)p; @@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) { tfree(pRequest->sqlstr); tfree(pRequest->pInfo); - tfree(pRequest->body.resInfo.pRspMsg); + doFreeReqResultInfo(&pRequest->body.resInfo); deregisterRequest(pRequest); tfree(pRequest); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e402403496..017fa493cf 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; setErrno(pRequest, code); + free(pMsg->pData); sem_post(&pRequest->body.rspSem); return code; } @@ -37,6 +38,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { + free(pMsg->pData); setErrno(pRequest, code); sem_post(&pRequest->body.rspSem); return code; @@ -73,6 +75,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns); + free(pMsg->pData); sem_post(&pRequest->body.rspSem); return 0; } @@ -238,6 +241,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo rsp with the vnode id list SRequestObj* pRequest = param; + free(pMsg->pData); tsem_post(&pRequest->body.rspSem); } @@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { + free(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; @@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { tNameGetDbName(&name, db); setConnectionDB(pRequest->pTscObj, db); + free(pMsg->pData); tsem_post(&pRequest->body.rspSem); return 0; } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 26f1141cc0..2bf3232b26 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -57,95 +57,96 @@ TEST(testCase, connect_Test) { taos_close(pConn); } -TEST(testCase, create_user_Test) { - TAOS* pConn = taos_connect("localhost", "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("localhost", "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("localhost", "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("localhost", "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("localhost", "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("localhost", "root", "taosdata", NULL, 0); +//TEST(testCase, create_user_Test) { +// TAOS* pConn = taos_connect("localhost", "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, "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("localhost", "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("localhost", "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("localhost", "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_free_result(pRes); +// taos_close(pConn); +//} +// +//TEST(testCase, drop_user_Test) { +// TAOS* pConn = taos_connect("localhost", "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("localhost", "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); +//} TEST(testCase, create_db_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -249,36 +250,36 @@ TEST(testCase, create_db_Test) { //// taos_close(pConn); //} - TEST(testCase, create_stable_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create database abc1"); - if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); - if (taos_errno(pRes) != 0) { - printf("error in create stable, reason:%s\n", taos_errstr(pRes)); - } - - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); - - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); - - taos_free_result(pRes); - taos_close(pConn); -} +// TEST(testCase, create_stable_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in create db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); +// if (taos_errno(pRes) != 0) { +// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// +// taos_free_result(pRes); +// taos_close(pConn); +//} //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -463,64 +464,64 @@ TEST(testCase, create_db_Test) { // taos_close(pConn); //} -TEST(testCase, create_multiple_tables) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - ASSERT_NE(pConn, nullptr); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - taos_free_result(pRes); - - pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); - if (taos_errno(pRes) != 0) { - printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); - if (taos_errno(pRes) != 0) { - printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - 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_free_result(pRes); - -// for(int32_t i = 0; i < 10000; ++i) { -// char sql[512] = {0}; -// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); -// TAOS_RES* pres = taos_query(pConn, sql); -// if (taos_errno(pres) != 0) { -// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); -// } -// taos_free_result(pres); +//TEST(testCase, create_multiple_tables) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// ASSERT_NE(pConn, nullptr); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); // } - - taos_close(pConn); -} +// +// taos_free_result(pRes); +// pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// 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_free_result(pRes); +// +//// for(int32_t i = 0; i < 10000; ++i) { +//// char sql[512] = {0}; +//// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); +//// TAOS_RES* pres = taos_query(pConn, sql); +//// if (taos_errno(pres) != 0) { +//// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); +//// } +//// taos_free_result(pres); +//// } +// +// taos_close(pConn); +//} TEST(testCase, generated_request_id_test) { SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - for(int32_t i = 0; i < 1000000; ++i) { - uint64_t v = generateRequestId(); - void* result = taosHashGet(phash, &v, sizeof(v)); - ASSERT_EQ(result, nullptr); - taosHashPut(phash, &v, sizeof(v), NULL, 0); - } +// for(int32_t i = 0; i < 1000000; ++i) { +// uint64_t v = generateRequestId(); +// void* result = taosHashGet(phash, &v, sizeof(v)); +// ASSERT_EQ(result, nullptr); +// taosHashPut(phash, &v, sizeof(v), NULL, 0); +// } - taosHashClear(phash); + taosHashCleanup(phash); } //TEST(testCase, projection_query_tables) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 6007fc300c..8ff0636969 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -378,6 +378,11 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return code; } + SKVRowBuilder kvRowBuilder = {0}; + if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + SArray* pValList = pCreateTableInfo->pTagVals; size_t numOfInputTag = taosArrayGetSize(pValList); @@ -393,26 +398,22 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); STableComInfo tinfo = getTableInfo(pSuperTableMeta); - SKVRowBuilder kvRowBuilder = {0}; - if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - SArray* pNameList = NULL; - size_t nameSize = 0; + size_t numOfBoundTags = 0; int32_t schemaSize = getNumOfTags(pSuperTableMeta); if (pCreateTableInfo->pTagNames) { pNameList = pCreateTableInfo->pTagNames; - nameSize = taosArrayGetSize(pNameList); + numOfBoundTags = taosArrayGetSize(pNameList); - if (numOfInputTag != nameSize || schemaSize < numOfInputTag) { + if (numOfInputTag != numOfBoundTags || schemaSize < numOfInputTag) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg2); } bool findColumnIndex = false; - for (int32_t i = 0; i < nameSize; ++i) { + for (int32_t i = 0; i < numOfBoundTags; ++i) { SToken* sToken = taosArrayGet(pNameList, i); char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // create tmp buf to avoid alter orginal sqlstr @@ -440,6 +441,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pItem->pVar.nLen > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg3); } } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { @@ -460,12 +462,14 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p int16_t len = varDataTLen(tagVal); if (len > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg3); } } if (code != TSDB_CODE_SUCCESS) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg4); } @@ -484,11 +488,14 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } else { if (schemaSize != numOfInputTag) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg2); } code = doParseSerializeTagValue(pTagSchema, numOfInputTag, &kvRowBuilder, pValList, tinfo.precision, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return code; } } @@ -496,6 +503,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder); if (row == NULL) { + tfree(pSuperTableMeta); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -504,6 +512,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SName tableName = {0}; code = createSName(&tableName, &pCreateTableInfo->name, pCtx, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { + tfree(pSuperTableMeta); return code; } @@ -529,6 +538,8 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p assert(info.vgId == pTableBatch->info.vgId); taosArrayPush(pTableBatch->req.pArray, &req); } + + tfree(pSuperTableMeta); } // TODO: serialize and @@ -567,6 +578,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p *pOutput = (char*) pStmtInfo; *len = sizeof(SVnodeModifOpStmtInfo); + taosHashCleanup(pVgroupHashmap); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 9455d23a1c..ad248f1795 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -241,5 +241,5 @@ void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaReq) { } void qDestroyQuery(SQueryNode* pQuery) { - // todo + tfree(pQuery); } From bcad6bb52840f782fd37a6f5fd6adf20c810de00 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 03:44:44 -0800 Subject: [PATCH 55/86] restore from wal --- include/dnode/bnode/bnode.h | 12 ++--- include/dnode/mnode/mnode.h | 14 +++--- include/dnode/qnode/qnode.h | 12 ++--- include/dnode/snode/snode.h | 12 ++--- include/util/taoserror.h | 2 +- source/dnode/bnode/inc/bndInt.h | 6 +-- source/dnode/mgmt/impl/inc/dndDnode.h | 4 +- source/dnode/mgmt/impl/inc/dndTransport.h | 4 +- source/dnode/mgmt/impl/src/dndBnode.c | 6 +-- source/dnode/mgmt/impl/src/dndDnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndMnode.c | 12 +++-- source/dnode/mgmt/impl/src/dndQnode.c | 6 +-- source/dnode/mgmt/impl/src/dndSnode.c | 6 +-- source/dnode/mgmt/impl/src/dndTransport.c | 17 ++++--- source/dnode/mgmt/impl/src/dnode.c | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 15 ++++--- source/dnode/mnode/impl/inc/mndTrans.h | 1 + source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mndSync.c | 2 + source/dnode/mnode/impl/src/mndTrans.c | 25 ++++++----- source/dnode/mnode/impl/src/mnode.c | 47 +++++++++++--------- source/dnode/mnode/impl/test/trans/trans.cpp | 6 +-- source/dnode/qnode/inc/qndInt.h | 6 +-- source/dnode/snode/inc/sndInt.h | 6 +-- source/libs/transport/src/rpcMain.c | 2 +- source/util/src/terror.c | 2 +- 26 files changed, 130 insertions(+), 107 deletions(-) diff --git a/include/dnode/bnode/bnode.h b/include/dnode/bnode/bnode.h index 23cc3ca617..3cc26861ab 100644 --- a/include/dnode/bnode/bnode.h +++ b/include/dnode/bnode/bnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SBnode SBnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SBnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnodeOpt; /* ------------------------ SBnode ------------------------ */ diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index a288e3e630..de4b4e4e89 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -24,9 +24,10 @@ extern "C" { typedef struct SDnode SDnode; typedef struct SMnode SMnode; typedef struct SMnodeMsg SMnodeMsg; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct SMnodeLoad { int64_t numOfDnode; @@ -62,9 +63,10 @@ typedef struct { SReplica replicas[TSDB_MAX_REPLICA]; SMnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + PutReqToMWriteQFp putReqToMWriteQFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SMnodeOpt; /* ------------------------ SMnode ------------------------ */ diff --git a/include/dnode/qnode/qnode.h b/include/dnode/qnode/qnode.h index 8084175a90..554c57a045 100644 --- a/include/dnode/qnode/qnode.h +++ b/include/dnode/qnode/qnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SQnode SQnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfStartTask; @@ -47,9 +47,9 @@ typedef struct { int64_t clusterId; SQnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnodeOpt; /* ------------------------ SQnode ------------------------ */ diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 4913d2572f..43d3dd9b4b 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SSnode SSnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SSnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnodeOpt; /* ------------------------ SSnode ------------------------ */ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 2dcc74213c..0305404937 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -253,7 +253,7 @@ int32_t* taosGetErrno(); // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) -#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401) +#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401) #define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402) #define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410) #define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411) diff --git a/source/dnode/bnode/inc/bndInt.h b/source/dnode/bnode/inc/bndInt.h index d44c520a26..cddb1e50f1 100644 --- a/source/dnode/bnode/inc/bndInt.h +++ b/source/dnode/bnode/inc/bndInt.h @@ -33,9 +33,9 @@ typedef struct SBnode { int32_t dnodeId; int64_t clusterId; SBnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnode; #ifdef __cplusplus diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index a2015913a7..69c2aa1fbf 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); -void dndSendStatusMsg(SDnode *pDnode); +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg); +void dndSendStatusReq(SDnode *pDnode); void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/impl/inc/dndTransport.h b/source/dnode/mgmt/impl/inc/dndTransport.h index 312da69fa2..42fb379fc1 100644 --- a/source/dnode/mgmt/impl/inc/dndTransport.h +++ b/source/dnode/mgmt/impl/inc/dndTransport.h @@ -23,8 +23,8 @@ extern "C" { int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index c12d449517..dfe4eda145 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) { static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 30b069f349..f5f9bbf1b8 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { taosRUnLockLatch(&pMgmt->latch); } -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { tmsg_t msgType = pMsg->msgType; SEpSet epSet = {0}; @@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { return 0; } -void dndSendStatusMsg(SDnode *pDnode) { +void dndSendStatusReq(SDnode *pDnode) { int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); SStatusMsg *pStatus = rpcMallocCont(contLen); @@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) { pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); - dndSendMsgToMnode(pDnode, &rpcMsg); + dndSendReqToMnode(pDnode, &rpcMsg); } static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { @@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) { taosMsleep(ms); if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) { - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); } } } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 577cb0c3b0..a8bf26f133 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -19,6 +19,7 @@ #include "dndTransport.h" #include "dndWorker.h" +static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg); static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg); static SMnode *dndAcquireMnode(SDnode *pDnode) { @@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { return true; } +static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) { + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg); +} + static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; + pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 1f3d6ee371..e73a0cb0d8 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) { static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index ab4ca191a9..070fc8663e 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -179,9 +179,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) { static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index bb16ef0b77..cf0f561609 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; @@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) { dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); - SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING}; + SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_OFFLINE}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); return; @@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) { dInfo("dnode-transport is cleaned up"); } -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { STransMgmt *pMgmt = &pDnode->tmgmt; - if (pMgmt->clientRpc == NULL) return; + if (pMgmt->clientRpc == NULL) { + terrno = TSDB_CODE_DND_OFFLINE; + return -1; + } + rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL); + return 0; } -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) { +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dndSendMsgToDnode(pDnode, &epSet, pMsg); + return dndSendReqToDnode(pDnode, &epSet, pMsg); } diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 88a96dadc4..33cec5ff47 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -213,7 +213,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { } dndSetStat(pDnode, DND_STAT_RUNNING); - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); dndReportStartup(pDnode, "TDengine", "initialized successfully"); dInfo("TDengine is initialized successfully, pDnode:%p", pDnode); diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 5c8d409d90..89fb2e3189 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -91,15 +91,16 @@ typedef struct SMnode { STelemMgmt telemMgmt; SSyncMgmt syncMgmt; MndMsgFp msgFp[TDMT_MAX]; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; + PutReqToMWriteQFp putReqToMWriteQFp; } SMnode; -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); -void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg); +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); uint64_t mndGenerateUid(char *name, int32_t len) ; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 201fcde1a9..bd053d91b6 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -45,6 +45,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); void mndTransProcessRsp(SMnodeMsg *pMsg); +void mndTransPullup(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1d78359015..2cca70b04e 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -557,7 +557,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) { .ahandle = pMsg->rpcMsg.ahandle}; mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config); - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + mndSendReqToDnode(pMnode, &epSet, &rpcMsg); return 0; } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 19fb89454e..bf1697fb19 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -83,6 +83,8 @@ static int32_t mndRestoreWal(SMnode *pMnode) { int64_t sdbVer = sdbUpdateVer(pSdb, 0); mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer); + mndTransPullup(pMnode); + if (walBeginSnapshot(pWal, sdbVer) < 0) { goto WAL_RESTORE_OVER; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index bf472a504c..ee4a49ffdc 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -52,7 +52,6 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); static void mndTransExecute(SMnode *pMnode, STrans *pTrans); static void mndTransSendRpcRsp(STrans *pTrans); static int32_t mndProcessTransMsg(SMnodeMsg *pMsg); -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg); int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, @@ -64,7 +63,6 @@ int32_t mndInitTrans(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndTransActionDelete}; mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransMsg); - mndSetMsgHandle(pMnode, TDMT_MND_TRANS_RSP, mndProcessTransRsp); return sdbSetTable(pMnode->pSdb, table); } @@ -615,12 +613,15 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr } memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen); - pAction->msgSent = 1; - pAction->msgReceived = 0; - pAction->errCode = 0; - - mDebug("trans:%d, action:%d is sent", pTrans->id, action); - mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg); + if (mndSendReqToDnode(pMnode, &pAction->epSet, &rpcMsg) == 0) { + mDebug("trans:%d, action:%d is sent", pTrans->id, action); + pAction->msgSent = 1; + pAction->msgReceived = 0; + pAction->errCode = 0; + } else { + mDebug("trans:%d, action:%d not sent since %s", pTrans->id, action, terrstr()); + return -1; + } } return 0; @@ -885,7 +886,11 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + mndTransPullup(pMsg->pMnode); + return 0; +} + +void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; void *pIter = NULL; @@ -897,5 +902,3 @@ static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { sdbRelease(pMnode->pSdb, pTrans); } } - -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg) { return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index abc86a7d35..0653a0f5d4 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -34,21 +34,27 @@ #include "mndUser.h" #include "mndVgroup.h" -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { - (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); } -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) { - (*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToMnodeFp)(pMnode->pDnode, pMsg); } -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) { - (*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendRedirectRspFp != NULL) { + (*pMnode->sendRedirectRspFp)(pMnode->pDnode, pMsg); } } @@ -56,11 +62,8 @@ static void mndTransReExecute(void *param, void *tmrId) { SMnode *pMnode = param; if (mndIsMaster(pMnode)) { STransMsg *pMsg = rpcMallocCont(sizeof(STransMsg)); - SEpSet epSet = {.inUse = 0, .numOfEps = 1}; - epSet.port[0] = pMnode->replicas[pMnode->selfIndex].port; - memcpy(epSet.fqdn[0], pMnode->replicas[pMnode->selfIndex].fqdn, TSDB_FQDN_LEN); - SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; + pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg); } taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer); @@ -76,7 +79,7 @@ static int32_t mndInitTimer(SMnode *pMnode) { return -1; } - if (taosTmrReset(mndTransReExecute, 1000, pMnode, pMnode->timer, &pMnode->transTimer)) { + if (taosTmrReset(mndTransReExecute, 6000, pMnode, pMnode->timer, &pMnode->transTimer)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -223,9 +226,10 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->pDnode = pOption->pDnode; - pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; - pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; - pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; + pMnode->putReqToMWriteQFp = pOption->putReqToMWriteQFp; + pMnode->sendReqToDnodeFp = pOption->sendReqToDnodeFp; + pMnode->sendReqToMnodeFp = pOption->sendReqToMnodeFp; + pMnode->sendRedirectRspFp = pOption->sendRedirectRspFp; pMnode->cfg.sver = pOption->cfg.sver; pMnode->cfg.enableTelem = pOption->cfg.enableTelem; pMnode->cfg.statusInterval = pOption->cfg.statusInterval; @@ -236,8 +240,9 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->cfg.gitinfo = strdup(pOption->cfg.gitinfo); pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo); - if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) { + if (pMnode->sendReqToDnodeFp == NULL || pMnode->sendReqToMnodeFp == NULL || pMnode->sendRedirectRspFp == NULL || + pMnode->putReqToMWriteQFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 || + pMnode->cfg.statusInterval < 1) { terrno = TSDB_CODE_MND_INVALID_OPTIONS; return -1; } @@ -433,7 +438,7 @@ void mndProcessMsg(SMnodeMsg *pMsg) { PROCESS_RPC_END: if (isReq) { if (code == TSDB_CODE_APP_NOT_READY) { - mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); + mndSendRedirectRsp(pMnode, &pMsg->rpcMsg); } else if (code != 0) { SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code}; rpcSendResponse(&rpcRsp); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 1be38b3289..d2bf92ad13 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -2,7 +2,7 @@ * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests - * @version 1.0 + * @version 0.1 * @date 2022-01-04 * * @copyright Copyright (c) 2022 @@ -75,10 +75,10 @@ TEST_F(DndTestTrans, 01_CreateUser_Crash) { test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 2); + CheckBinary("u1", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("super", 10); CheckBinary("normal", 10); + CheckBinary("super", 10); CheckTimestamp(); CheckTimestamp(); CheckBinary("root", TSDB_USER_LEN); diff --git a/source/dnode/qnode/inc/qndInt.h b/source/dnode/qnode/inc/qndInt.h index e9f1229a9d..529c407efa 100644 --- a/source/dnode/qnode/inc/qndInt.h +++ b/source/dnode/qnode/inc/qndInt.h @@ -32,9 +32,9 @@ typedef struct SQnode { int32_t dnodeId; int64_t clusterId; SQnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnode; #ifdef __cplusplus diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 8827c92eef..3b41c7f4b1 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -32,9 +32,9 @@ typedef struct SSnode { int32_t dnodeId; int64_t clusterId; SSnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnode; #ifdef __cplusplus diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 310944e9b6..242bdb1558 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -1195,7 +1195,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead, SRpcReqConte } rpcSendReqToServer(pRpc, pContext); rpcFreeCont(rpcMsg.pCont); - } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_EXITING) { + } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_OFFLINE) { pContext->code = pHead->code; rpcProcessConnError(pContext, NULL); rpcFreeCont(rpcMsg.pCont); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index e821f1f803..0bf56dbaaf 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -253,7 +253,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_EXIST, "Transaction not exis // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_DND_EXITING, "Dnode is exiting") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_OFFLINE, "Dnode is offline") TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, "Invalid message length") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_READ_FILE_ERROR, "Read dnode.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR, "Write dnode.json error") From 821b9ea4d3ff7f173b2514f93249abb2eda59185 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:04:23 -0800 Subject: [PATCH 56/86] minor changes --- include/common/tmsg.h | 6 +- source/dnode/mnode/impl/src/mndAcct.c | 36 ++++++------ source/dnode/mnode/impl/src/mndUser.c | 42 +++++++------- source/dnode/mnode/impl/test/acct/acct.cpp | 12 ++-- source/dnode/mnode/impl/test/trans/trans.cpp | 4 +- source/dnode/mnode/impl/test/user/user.cpp | 60 ++++++++++---------- source/libs/parser/inc/astToMsg.h | 6 +- source/libs/parser/src/astToMsg.c | 16 +++--- src/client/src/tscServer.c | 12 ++-- 9 files changed, 97 insertions(+), 97 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 19897ecb24..ac26e4f074 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -345,18 +345,18 @@ typedef struct { int32_t maxStreams; int32_t accessState; // Configured only by command int64_t maxStorage; // In unit of GB -} SCreateAcctMsg, SAlterAcctMsg; +} SCreateAcctReq, SAlterAcctReq; typedef struct { char user[TSDB_USER_LEN]; -} SDropUserMsg, SDropAcctMsg; +} SDropUserReq, SDropAcctReq; typedef struct { int8_t type; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; int8_t superUser; // denote if it is a super user or not -} SCreateUserMsg, SAlterUserMsg; +} SCreateUserReq, SAlterUserReq; typedef struct { int32_t contLen; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 2847d19bea..0cf940b987 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -25,10 +25,10 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct); static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw); static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct); -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct); -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew); +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg); +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg); int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, @@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndAcctActionUpdate, .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq); return sdbSetTable(pMnode->pSdb, table); } @@ -176,29 +176,29 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; } -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) { - mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOldAcct->acct, pOldAcct, pNewAcct); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) { + mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOld->acct, pOld, pNew); - pOldAcct->updateTime = pNewAcct->updateTime; - pOldAcct->status = pNewAcct->status; - memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctCfg)); + pOld->updateTime = pNew->updateTime; + pOld->status = pNew->status; + memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg)); return 0; } -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 6311d3e8da..3ffb979ed1 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -28,11 +28,11 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser); static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw); static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser); -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser); +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew); static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg); -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg); +static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg); +static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg); static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); @@ -47,9 +47,9 @@ int32_t mndInitUser(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); @@ -192,10 +192,10 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { return 0; } -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) { - mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOldUser->user, pOldUser, pNewUser); - memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN); - pOldUser->updateTime = pNewUser->updateTime; +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) { + mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOld->user, pOld, pNew); + memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN); + pOld->updateTime = pNew->updateTime; return 0; } @@ -247,9 +247,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, return 0; } -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; + SCreateUserReq *pCreate = pMsg->rpcMsg.pCont; mDebug("user:%s, start to create", pCreate->user); @@ -291,15 +291,15 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) { +static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pMsg) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("user:%s, failed to update since %s", pOldUser->user, terrstr()); + mError("user:%s, failed to update since %s", pOld->user, terrstr()); return -1; } - mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user); + mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user); - SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser); + SSdbRaw *pRedoRaw = mndUserActionEncode(pNew); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); @@ -317,9 +317,9 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewU return 0; } -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; + SAlterUserReq *pAlter = pMsg->rpcMsg.pCont; mDebug("user:%s, start to alter", pAlter->user); @@ -394,9 +394,9 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { return 0; } -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SDropUserMsg *pDrop = pMsg->rpcMsg.pCont; + SDropUserReq *pDrop = pMsg->rpcMsg.pCont; mDebug("user:%s, start to drop", pDrop->user); diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 5f105d99f3..f517b26596 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -26,9 +26,9 @@ class DndTestAcct : public ::testing::Test { Testbase DndTestAcct::test; TEST_F(DndTestAcct, 01_CreateAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); + int32_t contLen = sizeof(SCreateAcctReq); - SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); + SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -36,9 +36,9 @@ TEST_F(DndTestAcct, 01_CreateAcct) { } TEST_F(DndTestAcct, 02_AlterAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); + int32_t contLen = sizeof(SCreateAcctReq); - SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); + SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -46,9 +46,9 @@ TEST_F(DndTestAcct, 02_AlterAcct) { } TEST_F(DndTestAcct, 03_DropAcct) { - int32_t contLen = sizeof(SDropAcctMsg); + int32_t contLen = sizeof(SDropAcctReq); - SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); + SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index d2bf92ad13..19bba13345 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -52,9 +52,9 @@ Testbase DndTestTrans::test; TEST_F(DndTestTrans, 01_CreateUser_Crash) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 536150ccfd..5ccb079633 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -45,9 +45,9 @@ TEST_F(DndTestUser, 01_ShowUser) { TEST_F(DndTestUser, 02_Create_User) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); @@ -57,9 +57,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); @@ -69,9 +69,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "root"); strcpy(pReq->pass, "1"); @@ -81,9 +81,9 @@ TEST_F(DndTestUser, 02_Create_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); @@ -101,9 +101,9 @@ TEST_F(DndTestUser, 02_Create_User) { TEST_F(DndTestUser, 03_Alter_User) { { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); @@ -113,9 +113,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); @@ -125,9 +125,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u4"); strcpy(pReq->pass, "1"); @@ -137,9 +137,9 @@ TEST_F(DndTestUser, 03_Alter_User) { } { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "1"); @@ -151,9 +151,9 @@ TEST_F(DndTestUser, 03_Alter_User) { TEST_F(DndTestUser, 04_Drop_User) { { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -162,9 +162,9 @@ TEST_F(DndTestUser, 04_Drop_User) { } { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u4"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -173,9 +173,9 @@ TEST_F(DndTestUser, 04_Drop_User) { } { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); @@ -192,9 +192,9 @@ TEST_F(DndTestUser, 04_Drop_User) { TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); @@ -204,9 +204,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { } { - int32_t contLen = sizeof(SCreateUserMsg); + int32_t contLen = sizeof(SCreateUserReq); - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); @@ -235,9 +235,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - int32_t contLen = sizeof(SAlterUserMsg); + int32_t contLen = sizeof(SAlterUserReq); - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); @@ -266,9 +266,9 @@ TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - int32_t contLen = sizeof(SDropUserMsg); + int32_t contLen = sizeof(SDropUserReq); - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index ba33767a05..30919d25dd 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -5,9 +5,9 @@ #include "tmsg.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 792c0db266..ab8c9b8094 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -2,8 +2,8 @@ #include "astGenerator.h" #include "parserUtil.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateUserMsg* pMsg = (SCreateUserMsg*)calloc(1, sizeof(SCreateUserMsg)); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateUserReq* pMsg = (SCreateUserReq*)calloc(1, sizeof(SCreateUserReq)); if (pMsg == NULL) { // tscError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -25,8 +25,8 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in return pMsg; } -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateAcctMsg *pCreateMsg = (SCreateAcctMsg *) calloc(1, sizeof(SCreateAcctMsg)); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateAcctReq *pCreateMsg = (SCreateAcctReq *) calloc(1, sizeof(SCreateAcctReq)); if (pCreateMsg == NULL) { qError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -64,24 +64,24 @@ SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in } } - *outputLen = sizeof(SCreateAcctMsg); + *outputLen = sizeof(SCreateAcctReq); return pCreateMsg; } -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); if (pName->n >= TSDB_USER_LEN) { return NULL; } - SDropUserMsg* pMsg = calloc(1, sizeof(SDropUserMsg)); + SDropUserReq* pMsg = calloc(1, sizeof(SDropUserReq)); if (pMsg == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } strncpy(pMsg->user, pName->z, pName->n); - *msgLen = sizeof(SDropUserMsg); + *msgLen = sizeof(SDropUserReq); return pMsg; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 42799927e6..48127147f8 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1210,13 +1210,13 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateAcctMsg); + pCmd->payloadLen = sizeof(SCreateAcctReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateAcctMsg *pAlterMsg = (SCreateAcctMsg *)pCmd->payload; + SCreateAcctReq *pAlterMsg = (SCreateAcctReq *)pCmd->payload; SStrToken *pName = &pInfo->pMiscInfo->user.user; SStrToken *pPwd = &pInfo->pMiscInfo->user.passwd; @@ -1255,14 +1255,14 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateUserMsg); + pCmd->payloadLen = sizeof(SCreateUserReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateUserMsg *pAlterMsg = (SCreateUserMsg *)pCmd->payload; + SCreateUserReq *pAlterMsg = (SCreateUserReq *)pCmd->payload; SUserInfo *pUser = &pInfo->pMiscInfo->user; strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n); @@ -1369,7 +1369,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char user[TSDB_USER_LEN] = {0}; tstrncpy(user, pCmd->payload, TSDB_USER_LEN); - pCmd->payloadLen = sizeof(SDropUserMsg); + pCmd->payloadLen = sizeof(SDropUserReq); pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TDMT_MND_DROP_USER:TDMT_MND_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1377,7 +1377,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SDropUserMsg *pDropMsg = (SDropUserMsg *)pCmd->payload; + SDropUserReq *pDropMsg = (SDropUserReq *)pCmd->payload; tstrncpy(pDropMsg->user, user, tListLen(user)); return TSDB_CODE_SUCCESS; From 0526051edd43778bbd14c34ead72aa0aaa1c65d5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:18:09 -0800 Subject: [PATCH 57/86] minor changes --- source/dnode/mgmt/impl/test/CMakeLists.txt | 3 --- source/dnode/mnode/impl/test/CMakeLists.txt | 6 ++++- source/dnode/mnode/impl/test/acct/acct.cpp | 2 +- .../impl/test/bnode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/bnode/bnode.cpp | 26 +++++++++---------- .../impl/test/qnode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/qnode/qnode.cpp | 26 +++++++++---------- .../impl/test/snode/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/snode/snode.cpp | 26 +++++++++---------- source/dnode/mnode/impl/test/trans/trans.cpp | 2 +- source/dnode/mnode/impl/test/user/user.cpp | 4 +-- 11 files changed, 48 insertions(+), 47 deletions(-) rename source/dnode/{mgmt => mnode}/impl/test/bnode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/bnode/bnode.cpp (87%) rename source/dnode/{mgmt => mnode}/impl/test/qnode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/qnode/qnode.cpp (87%) rename source/dnode/{mgmt => mnode}/impl/test/snode/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/snode/snode.cpp (87%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index b36cdbd690..1896a605cd 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -7,9 +7,6 @@ add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) add_subdirectory(mnode) -add_subdirectory(qnode) -add_subdirectory(snode) -add_subdirectory(bnode) add_subdirectory(profile) add_subdirectory(show) add_subdirectory(stb) diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index dfac7a76c9..075ff38bc6 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -1,5 +1,9 @@ enable_testing() -add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(acct) add_subdirectory(trans) +add_subdirectory(qnode) +add_subdirectory(snode) +add_subdirectory(bnode) + diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index f517b26596..5a7df55c4c 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -3,7 +3,7 @@ * @author slguan (slguan@taosdata.com) * @brief MNODE module acct tests * @version 1.0 - * @date 2021-12-15 + * @date 2022-01-04 * * @copyright Copyright (c) 2022 * diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/bnode/CMakeLists.txt rename to source/dnode/mnode/impl/test/bnode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/bnode/bnode.cpp rename to source/dnode/mnode/impl/test/bnode/bnode.cpp index b1a85522c4..eee61cbf4e 100644 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file bnode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestBnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_bnode1", 9068); + test.Init("/tmp/mnode_test_bnode1", 9018); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9068"; + const char* firstEp = "localhost:9018"; - server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); + server2.Start("/tmp/mnode_test_bnode2", fqdn, 9019, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9069); + pReq->port = htonl(9019); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckBinary("localhost:9069", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); + CheckBinary("localhost:9019", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/qnode/CMakeLists.txt rename to source/dnode/mnode/impl/test/qnode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/qnode/qnode.cpp rename to source/dnode/mnode/impl/test/qnode/qnode.cpp index 40464de816..6e71eb51eb 100644 --- a/source/dnode/mgmt/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file qnode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestQnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_qnode1", 9064); + test.Init("/tmp/mnode_test_qnode1", 9014); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9064"; + const char* firstEp = "localhost:9014"; - server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp); + server2.Start("/tmp/mnode_test_qnode2", fqdn, 9015, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9065); + pReq->port = htonl(9015); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9064", TSDB_EP_LEN); - CheckBinary("localhost:9065", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); + CheckBinary("localhost:9015", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestQnode, 04_Create_Qnode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mnode/impl/test/snode/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/snode/CMakeLists.txt rename to source/dnode/mnode/impl/test/snode/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp similarity index 87% rename from source/dnode/mgmt/impl/test/snode/snode.cpp rename to source/dnode/mnode/impl/test/snode/snode.cpp index a14a575beb..4c32edc152 100644 --- a/source/dnode/mgmt/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -1,11 +1,11 @@ /** - * @file dnode.cpp + * @file snode.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module snode tests + * @version 1.0 + * @date 2022-01-05 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ @@ -18,11 +18,11 @@ class DndTestSnode : public ::testing::Test { public: static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_snode1", 9066); + test.Init("/tmp/mnode_test_snode1", 9016); const char* fqdn = "localhost"; - const char* firstEp = "localhost:9066"; + const char* firstEp = "localhost:9016"; - server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp); + server2.Start("/tmp/mnode_test_snode2", fqdn, 9017, firstEp); taosMsleep(300); } @@ -72,7 +72,7 @@ TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } } @@ -97,7 +97,7 @@ TEST_F(DndTestSnode, 04_Create_Snode) { SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9067); + pReq->port = htonl(9017); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); @@ -126,8 +126,8 @@ TEST_F(DndTestSnode, 04_Create_Snode) { CheckInt16(1); CheckInt16(2); - CheckBinary("localhost:9066", TSDB_EP_LEN); - CheckBinary("localhost:9067", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); + CheckBinary("localhost:9017", TSDB_EP_LEN); CheckTimestamp(); CheckTimestamp(); } @@ -148,7 +148,7 @@ TEST_F(DndTestSnode, 04_Create_Snode) { EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } } \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 19bba13345..ca7a8a0981 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -2,7 +2,7 @@ * @file trans.cpp * @author slguan (slguan@taosdata.com) * @brief MNODE module trans tests - * @version 0.1 + * @version 1.0 * @date 2022-01-04 * * @copyright Copyright (c) 2022 diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 5ccb079633..ce8fd1b166 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -3,9 +3,9 @@ * @author slguan (slguan@taosdata.com) * @brief MNODE module user tests * @version 1.0 - * @date 2021-12-15 + * @date 2022-01-04 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ From 8279e49cb0ed6d9de62106095aff00f1280db9fb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 20:18:15 +0800 Subject: [PATCH 58/86] optimize read performace case --- source/libs/index/test/indexTests.cc | 76 ++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index badc510b19..ef41855c33 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -679,6 +679,17 @@ class IndexObj { } return numOfTable; } + int ReadMultiMillonData(const std::string& colName, const std::string& colVal = "Hello world", + size_t numOfTable = 100 * 10000) { + std::string tColVal = colVal; + + int colValSize = tColVal.size(); + for (int i = 0; i < numOfTable; i++) { + tColVal[i % colValSize] = 'a' + i % 26; + SearchOne(colName, tColVal); + } + return 0; + } int Put(SIndexMultiTerm* fvs, uint64_t uid) { numOfWrite += taosArrayGetSize(fvs); @@ -701,8 +712,8 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName - << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; + std::cout << "search and time cost:" << e - s << "\tquery col:" << colName << "\t val: " << colVal + << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } int sz = taosArrayGetSize(result); @@ -711,6 +722,31 @@ class IndexObj { return sz; // assert(taosArrayGetSize(result) == targetSize); } + int SearchOneTarget(const std::string& colName, const std::string& colVal, uint64_t val) { + SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermQueryAdd(mq, term, QUERY_TERM); + + SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + + int64_t s = taosGetTimestampUs(); + if (Search(mq, result) == 0) { + int64_t e = taosGetTimestampUs(); + std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; + } else { + } + int sz = taosArrayGetSize(result); + indexMultiTermQueryDestroy(mq); + taosArrayDestroy(result); + assert(sz == 1); + uint64_t* ret = (uint64_t*)taosArrayGet(result, 0); + assert(val = *ret); + + return sz; + } + void PutOne(const std::string& colName, const std::string& colVal) { SIndexMultiTerm* terms = indexMultiTermCreate(); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), @@ -831,12 +867,15 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) { assert(numOfTable == target); } -static void write_and_search(IndexObj* idx) { - std::string colName("tag1"), colVal("Hello"); - +static void single_write_and_search(IndexObj* idx) { int target = idx->SearchOne("tag1", "Hello"); target = idx->SearchOne("tag2", "Test"); - // idx->PutOne(colName, colVal); +} +static void multi_write_and_search(IndexObj* idx) { + int target = idx->SearchOne("tag1", "Hello"); + target = idx->SearchOne("tag2", "Test"); + idx->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + idx->WriteMultiMillonData("tag2", "Test", 100 * 10000); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { std::string path = "/tmp/cache_and_tfile"; @@ -851,7 +890,21 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { for (int i = 0; i < NUM_OF_THREAD; i++) { // - threads[i] = std::thread(write_and_search, index); + threads[i] = std::thread(single_write_and_search, index); + } + for (int i = 0; i < NUM_OF_THREAD; i++) { + // TOD + threads[i].join(); + } +} +TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) { + std::string path = "/tmp/cache_and_tfile"; + if (index->Init(path) != 0) {} + + std::thread threads[NUM_OF_THREAD]; + for (int i = 0; i < NUM_OF_THREAD; i++) { + // + threads[i] = std::thread(multi_write_and_search, index); } for (int i = 0; i < NUM_OF_THREAD; i++) { // TOD @@ -860,13 +913,16 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } TEST_F(IndexEnv2, testIndex_restart) { - std::string path = "/tmp/test1"; + std::string path = "/tmp/cache_and_tfile"; if (index->Init(path) != 0) {} + index->SearchOneTarget("tag1", "Hello", 10); + index->SearchOneTarget("tag2", "Test", 10); } -TEST_F(IndexEnv2, testIndex_performance) { - std::string path = "/tmp/test2"; +TEST_F(IndexEnv2, testIndex_read_performance) { + std::string path = "/tmp/cache_and_tfile"; if (index->Init(path) != 0) {} + index->ReadMultiMillonData("tag1", "Hello"); } TEST_F(IndexEnv2, testIndexMultiTag) { std::string path = "/tmp/test3"; From dfd724a81c1d443a0e96701b3155352ac4390e0c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:19:06 -0800 Subject: [PATCH 59/86] minor changes --- source/dnode/mnode/impl/test/bnode/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/qnode/CMakeLists.txt | 8 ++++---- source/dnode/mnode/impl/test/snode/CMakeLists.txt | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt index ea769a701c..b58b1a856b 100644 --- a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. STEST_SRC) -add_executable(dnode_test_bnode ${STEST_SRC}) +add_executable(mnode_test_bnode ${STEST_SRC}) target_link_libraries( - dnode_test_bnode + mnode_test_bnode PUBLIC sut ) add_test( - NAME dnode_test_bnode - COMMAND dnode_test_bnode + NAME mnode_test_bnode + COMMAND mnode_test_bnode ) diff --git a/source/dnode/mnode/impl/test/qnode/CMakeLists.txt b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt index 2edb6de8b8..77ac39e409 100644 --- a/source/dnode/mnode/impl/test/qnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. QTEST_SRC) -add_executable(dnode_test_qnode ${QTEST_SRC}) +add_executable(mnode_test_qnode ${QTEST_SRC}) target_link_libraries( - dnode_test_qnode + mnode_test_qnode PUBLIC sut ) add_test( - NAME dnode_test_qnode - COMMAND dnode_test_qnode + NAME mnode_test_qnode + COMMAND mnode_test_qnode ) diff --git a/source/dnode/mnode/impl/test/snode/CMakeLists.txt b/source/dnode/mnode/impl/test/snode/CMakeLists.txt index 180b1ec163..44a5f35f94 100644 --- a/source/dnode/mnode/impl/test/snode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/snode/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. STEST_SRC) -add_executable(dnode_test_snode ${STEST_SRC}) +add_executable(mnode_test_snode ${STEST_SRC}) target_link_libraries( - dnode_test_snode + mnode_test_snode PUBLIC sut ) add_test( - NAME dnode_test_snode - COMMAND dnode_test_snode + NAME mnode_test_snode + COMMAND mnode_test_snode ) From 7974143dc7b3fa4aa09b107aaa79e0ed8a8fbef2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:36:54 -0800 Subject: [PATCH 60/86] minor changes --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 + source/dnode/mgmt/impl/test/bnode/bnode.cpp | 154 ++++++++++++++++++ .../dnode/mgmt/impl/test/cluster/cluster.cpp | 2 +- source/dnode/mgmt/impl/test/db/db.cpp | 2 +- source/dnode/mgmt/impl/test/dnode/dnode.cpp | 2 +- source/dnode/mgmt/impl/test/mnode/mnode.cpp | 2 +- .../dnode/mgmt/impl/test/profile/profile.cpp | 2 +- .../dnode/mgmt/impl/test/qnode/CMakeLists.txt | 11 ++ source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 26 +++ source/dnode/mgmt/impl/test/show/show.cpp | 2 +- source/dnode/mgmt/impl/test/stb/stb.cpp | 2 +- .../mgmt/impl/test/sut/inc/{base.h => sut.h} | 0 .../dnode/mgmt/impl/test/sut/src/client.cpp | 2 +- .../dnode/mgmt/impl/test/sut/src/server.cpp | 2 +- .../impl/test/sut/src/{base.cpp => sut.cpp} | 2 +- source/dnode/mgmt/impl/test/vgroup/vgroup.cpp | 2 +- source/dnode/mnode/impl/test/acct/acct.cpp | 14 +- source/dnode/mnode/impl/test/bnode/bnode.cpp | 16 +- source/dnode/mnode/impl/test/qnode/qnode.cpp | 16 +- source/dnode/mnode/impl/test/snode/snode.cpp | 16 +- source/dnode/mnode/impl/test/trans/trans.cpp | 8 +- source/dnode/mnode/impl/test/user/user.cpp | 16 +- 22 files changed, 247 insertions(+), 54 deletions(-) create mode 100644 source/dnode/mgmt/impl/test/bnode/bnode.cpp create mode 100644 source/dnode/mgmt/impl/test/qnode/CMakeLists.txt create mode 100644 source/dnode/mgmt/impl/test/qnode/dqnode.cpp rename source/dnode/mgmt/impl/test/sut/inc/{base.h => sut.h} (100%) rename source/dnode/mgmt/impl/test/sut/src/{base.cpp => sut.cpp} (99%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index 1896a605cd..6e6015b5f4 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,5 +1,7 @@ enable_testing() +add_subdirectory(qnode) + # add_subdirectory(auth) # add_subdirectory(balance) add_subdirectory(cluster) diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp new file mode 100644 index 0000000000..b06fd1bbca --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/bnode.cpp @@ -0,0 +1,154 @@ +/** + * @file dnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module dnode-msg tests + * @version 0.1 + * @date 2021-12-15 + * + * @copyright Copyright (c) 2021 + * + */ + +#include "sut.h" + +class DndTestBnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/dnode_test_bnode1", 9068); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9068"; + + server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase DndTestBnode::test; +TestServer DndTestBnode::server2; + +TEST_F(DndTestBnode, 01_ShowBnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + CHECK_META("show bnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + CHECK_META("show bnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckTimestamp(); + } +} + +TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } +} + +TEST_F(DndTestBnode, 04_Create_Bnode) { + { + // create dnode + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9069); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + taosMsleep(1300); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + // create bnode + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9069", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + // drop bnode + int32_t contLen = sizeof(SMDropBnodeMsg); + + SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckTimestamp(); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp index 7734826789..7d9bff7b23 100644 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ b/source/dnode/mgmt/impl/test/cluster/cluster.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestCluster : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 7ba19677fd..a78b8388c6 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDb : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index 54d7e73be6..9041098d71 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDnode : public ::testing::Test { public: diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp index e9b1ef45bd..3d4844c3f6 100644 --- a/source/dnode/mgmt/impl/test/mnode/mnode.cpp +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestMnode : public ::testing::Test { public: diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 87e6bfde74..77122d1bb9 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestProfile : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt new file mode 100644 index 0000000000..2536001231 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. DQTEST_SRC) +add_executable(dnode_test_qnode ${DQTEST_SRC}) +target_link_libraries( + dnode_test_qnode + PUBLIC sut +) + +add_test( + NAME dnode_test_qnode + COMMAND dnode_test_qnode +) diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp new file mode 100644 index 0000000000..8678e098f4 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -0,0 +1,26 @@ +/** + * @file dqnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestQnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestQnode::test; diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp index a0df0f2921..8622672758 100644 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ b/source/dnode/mgmt/impl/test/show/show.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestShow : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index dca0f48516..40af751e33 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestStb : public ::testing::Test { protected: diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/sut.h similarity index 100% rename from source/dnode/mgmt/impl/test/sut/inc/base.h rename to source/dnode/mgmt/impl/test/sut/inc/sut.h diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index 13429cec28..086ba7bb0f 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; diff --git a/source/dnode/mgmt/impl/test/sut/src/server.cpp b/source/dnode/mgmt/impl/test/sut/src/server.cpp index 8ac5f62144..fb2974294c 100644 --- a/source/dnode/mgmt/impl/test/sut/src/server.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/server.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void* serverLoop(void* param) { while (1) { diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp similarity index 99% rename from source/dnode/mgmt/impl/test/sut/src/base.cpp rename to source/dnode/mgmt/impl/test/sut/src/sut.cpp index e1b6664e9f..46ced254c6 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void Testbase::InitLog(const char* path) { dDebugFlag = 0; diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index 718fbea50d..15a0c8087c 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestVgroup : public ::testing::Test { protected: diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 5a7df55c4c..906a066f74 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestAcct : public ::testing::Test { +class MndTestAcct : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); } static void TearDownTestSuite() { test.Cleanup(); } @@ -23,9 +23,9 @@ class DndTestAcct : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestAcct::test; +Testbase MndTestAcct::test; -TEST_F(DndTestAcct, 01_CreateAcct) { +TEST_F(MndTestAcct, 01_Create_Acct) { int32_t contLen = sizeof(SCreateAcctReq); SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen); @@ -35,7 +35,7 @@ TEST_F(DndTestAcct, 01_CreateAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 02_AlterAcct) { +TEST_F(MndTestAcct, 02_Alter_Acct) { int32_t contLen = sizeof(SCreateAcctReq); SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen); @@ -45,7 +45,7 @@ TEST_F(DndTestAcct, 02_AlterAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 03_DropAcct) { +TEST_F(MndTestAcct, 03_Drop_Acct) { int32_t contLen = sizeof(SDropAcctReq); SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen); @@ -55,7 +55,7 @@ TEST_F(DndTestAcct, 03_DropAcct) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } -TEST_F(DndTestAcct, 04_ShowAcct) { +TEST_F(MndTestAcct, 04_Show_Acct) { int32_t contLen = sizeof(SShowMsg); SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index eee61cbf4e..2d44249f77 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestBnode : public ::testing::Test { +class MndTestBnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestBnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestBnode::test; -TestServer DndTestBnode::server2; +Testbase MndTestBnode::test; +TestServer MndTestBnode::server2; -TEST_F(DndTestBnode, 01_ShowBnode) { +TEST_F(MndTestBnode, 01_Show_Bnode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); CHECK_META("show bnodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestBnode, 01_ShowBnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { +TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateBnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { } } -TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { +TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateBnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { } } -TEST_F(DndTestBnode, 04_Create_Bnode) { +TEST_F(MndTestBnode, 04_Create_Bnode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index 6e71eb51eb..ca768db56c 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestQnode : public ::testing::Test { +class MndTestQnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestQnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestQnode::test; -TestServer DndTestQnode::server2; +Testbase MndTestQnode::test; +TestServer MndTestQnode::server2; -TEST_F(DndTestQnode, 01_ShowQnode) { +TEST_F(MndTestQnode, 01_Show_Qnode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestQnode, 01_ShowQnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { } } -TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { } } -TEST_F(DndTestQnode, 04_Create_Qnode) { +TEST_F(MndTestQnode, 04_Create_Qnode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index 4c32edc152..7816de6ab9 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestSnode : public ::testing::Test { +class MndTestSnode : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} @@ -35,10 +35,10 @@ class DndTestSnode : public ::testing::Test { static TestServer server2; }; -Testbase DndTestSnode::test; -TestServer DndTestSnode::server2; +Testbase MndTestSnode::test; +TestServer MndTestSnode::server2; -TEST_F(DndTestSnode, 01_ShowSnode) { +TEST_F(MndTestSnode, 01_Show_Snode) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); CHECK_META("show snodes", 3); @@ -50,7 +50,7 @@ TEST_F(DndTestSnode, 01_ShowSnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { +TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateSnodeMsg); @@ -77,7 +77,7 @@ TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { } } -TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { +TEST_F(MndTestSnode, 03_Create_Snode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateSnodeMsg); @@ -90,7 +90,7 @@ TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { } } -TEST_F(DndTestSnode, 04_Create_Snode) { +TEST_F(MndTestSnode, 04_Create_Snode) { { // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index ca7a8a0981..97a8bd2caf 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -9,10 +9,10 @@ * */ -#include "base.h" +#include "sut.h" #include "os.h" -class DndTestTrans : public ::testing::Test { +class MndTestTrans : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } static void TearDownTestSuite() { test.Cleanup(); } @@ -48,9 +48,9 @@ class DndTestTrans : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestTrans::test; +Testbase MndTestTrans::test; -TEST_F(DndTestTrans, 01_CreateUser_Crash) { +TEST_F(MndTestTrans, 01_Create_User_Crash) { { int32_t contLen = sizeof(SCreateUserReq); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ce8fd1b166..76954db213 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -9,9 +9,9 @@ * */ -#include "base.h" +#include "sut.h" -class DndTestUser : public ::testing::Test { +class MndTestUser : public ::testing::Test { protected: static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } static void TearDownTestSuite() { test.Cleanup(); } @@ -23,9 +23,9 @@ class DndTestUser : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestUser::test; +Testbase MndTestUser::test; -TEST_F(DndTestUser, 01_ShowUser) { +TEST_F(MndTestUser, 01_Show_User) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); @@ -43,7 +43,7 @@ TEST_F(DndTestUser, 01_ShowUser) { CheckBinary("root", TSDB_USER_LEN); } -TEST_F(DndTestUser, 02_Create_User) { +TEST_F(MndTestUser, 02_Create_User) { { int32_t contLen = sizeof(SCreateUserReq); @@ -99,7 +99,7 @@ TEST_F(DndTestUser, 02_Create_User) { EXPECT_EQ(test.GetShowRows(), 2); } -TEST_F(DndTestUser, 03_Alter_User) { +TEST_F(MndTestUser, 03_Alter_User) { { int32_t contLen = sizeof(SAlterUserReq); @@ -149,7 +149,7 @@ TEST_F(DndTestUser, 03_Alter_User) { } } -TEST_F(DndTestUser, 04_Drop_User) { +TEST_F(MndTestUser, 04_Drop_User) { { int32_t contLen = sizeof(SDropUserReq); @@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) { EXPECT_EQ(test.GetShowRows(), 1); } -TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { +TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserReq); From 268c3343d589bce88b5996ffdf2de422bba66f6a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 04:42:03 -0800 Subject: [PATCH 61/86] minor changes --- include/common/tmsg.h | 6 +-- source/dnode/mgmt/impl/src/dndBnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndQnode.c | 8 ++-- source/dnode/mgmt/impl/src/dndSnode.c | 8 ++-- source/dnode/mgmt/impl/test/bnode/bnode.cpp | 16 ++++---- source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 41 ++++++++++++++++++++ source/dnode/mnode/impl/src/mndBnode.c | 14 +++---- source/dnode/mnode/impl/src/mndQnode.c | 14 +++---- source/dnode/mnode/impl/src/mndSnode.c | 14 +++---- source/dnode/mnode/impl/test/bnode/bnode.cpp | 16 ++++---- source/dnode/mnode/impl/test/qnode/qnode.cpp | 16 ++++---- source/dnode/mnode/impl/test/snode/snode.cpp | 16 ++++---- 12 files changed, 109 insertions(+), 68 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ac26e4f074..affab8903c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -851,15 +851,15 @@ typedef struct { typedef struct { int32_t dnodeId; -} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg; +} SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq; typedef struct { int32_t dnodeId; -} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg; +} SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq; typedef struct { int32_t dnodeId; -} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg; +} SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq; typedef struct { int32_t dnodeId; diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index dfe4eda145..da3295b5d7 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -256,7 +256,7 @@ static int32_t dndDropBnode(SDnode *pDnode) { } int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateBnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -268,7 +268,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropBnodeMsg *pMsg = pRpcMsg->pCont; + SDDropBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index e73a0cb0d8..642c17b661 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -261,7 +261,7 @@ static int32_t dndDropQnode(SDnode *pDnode) { } int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateQnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -273,7 +273,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropQnodeMsg *pMsg = pRpcMsg->pCont; + SDDropQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index 070fc8663e..a295a2d481 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -256,7 +256,7 @@ static int32_t dndDropSnode(SDnode *pDnode) { } int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateSnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { @@ -268,7 +268,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropSnodeMsg *pMsg = pRpcMsg->pCont; + SDDropSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp index b06fd1bbca..7777d60550 100644 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ b/source/dnode/mgmt/impl/test/bnode/bnode.cpp @@ -52,9 +52,9 @@ TEST_F(DndTestBnode, 01_ShowBnode) { TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { { // create bnode - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(DndTestBnode, 04_Create_Bnode) { { // drop bnode - int32_t contLen = sizeof(SMDropBnodeMsg); + int32_t contLen = sizeof(SMDropBnodeReq); - SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index 8678e098f4..fa9038107e 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -24,3 +24,44 @@ class DndTestQnode : public ::testing::Test { }; Testbase DndTestQnode::test; + +TEST_F(DndTestQnode, 04_Drop_User) { + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + // { + // int32_t contLen = sizeof(SDropUserReq); + + // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + // strcpy(pReq->user, "u4"); + + // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + // ASSERT_NE(pMsg, nullptr); + // ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + // } + + // { + // int32_t contLen = sizeof(SDropUserReq); + + // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + // strcpy(pReq->user, "u1"); + + // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + // ASSERT_NE(pMsg, nullptr); + // ASSERT_EQ(pMsg->code, 0); + // } + + // test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + // CHECK_META("show users", 4); + + // test.SendShowRetrieveMsg(); + // EXPECT_EQ(test.GetShowRows(), 1); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index ceaebe3f6d..886784805e 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg)); + SDCreateBnodeReq *pMsg = malloc(sizeof(SDCreateBnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateBnodeMsg); + action.contLen = sizeof(SDCreateBnodeReq); action.msgType = TDMT_DND_CREATE_BNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { +static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { SBnodeObj bnodeObj = {0}; bnodeObj.id = pDnode->id; bnodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_BNODE_OVER: static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateBnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg)); + SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropBnodeMsg); + action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_BNODE_OVER: static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropBnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("bnode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index a0c4ff8218..ea4cfa41c8 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg)); + SDCreateQnodeReq *pMsg = malloc(sizeof(SDCreateQnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateQnodeMsg); + action.contLen = sizeof(SDCreateQnodeReq); action.msgType = TDMT_DND_CREATE_QNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) { +static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { SQnodeObj qnodeObj = {0}; qnodeObj.id = pDnode->id; qnodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_QNODE_OVER: static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateQnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg)); + SDDropQnodeReq *pMsg = malloc(sizeof(SDDropQnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropQnodeMsg); + action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_QNODE_OVER: static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropQnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("qnode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index ac03e1659c..3ab1ad4eaf 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -178,7 +178,7 @@ static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg)); + SDCreateSnodeReq *pMsg = malloc(sizeof(SDCreateSnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -188,7 +188,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDCreateSnodeMsg); + action.contLen = sizeof(SDCreateSnodeReq); action.msgType = TDMT_DND_CREATE_SNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -199,7 +199,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } -static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) { +static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { SSnodeObj snodeObj = {0}; snodeObj.id = pDnode->id; snodeObj.createdTime = taosGetTimestampMs(); @@ -242,7 +242,7 @@ CREATE_SNODE_OVER: static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateSnodeReq *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -290,7 +290,7 @@ static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg)); + SDDropSnodeReq *pMsg = malloc(sizeof(SDDropSnodeReq)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,7 +300,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); action.pCont = pMsg; - action.contLen = sizeof(SDDropSnodeMsg); + action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -350,7 +350,7 @@ DROP_SNODE_OVER: static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropSnodeReq *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("snode:%d, start to drop", pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index 2d44249f77..fa06d9ac69 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestBnode, 01_Show_Bnode) { TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { { // create bnode - int32_t contLen = sizeof(SMCreateBnodeMsg); + int32_t contLen = sizeof(SMCreateBnodeReq); - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { { // drop bnode - int32_t contLen = sizeof(SMDropBnodeMsg); + int32_t contLen = sizeof(SMDropBnodeReq); - SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index ca768db56c..f5dfc35188 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestQnode, 01_Show_Qnode) { TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { { // create qnode - int32_t contLen = sizeof(SMCreateQnodeMsg); + int32_t contLen = sizeof(SMCreateQnodeReq); - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { { // drop qnode - int32_t contLen = sizeof(SMDropQnodeMsg); + int32_t contLen = sizeof(SMDropQnodeReq); - SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen); + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index 7816de6ab9..4819bc556c 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -52,9 +52,9 @@ TEST_F(MndTestSnode, 01_Show_Snode) { TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -79,9 +79,9 @@ TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { TEST_F(MndTestSnode, 03_Create_Snode_Invalid_Id) { { - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -111,9 +111,9 @@ TEST_F(MndTestSnode, 04_Create_Snode) { { // create snode - int32_t contLen = sizeof(SMCreateSnodeMsg); + int32_t contLen = sizeof(SMCreateSnodeReq); - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); @@ -134,9 +134,9 @@ TEST_F(MndTestSnode, 04_Create_Snode) { { // drop snode - int32_t contLen = sizeof(SMDropSnodeMsg); + int32_t contLen = sizeof(SMDropSnodeReq); - SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen); + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); From 99379fd5a61c0ab536d8b43e701b697c86b5ed13 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 20:56:55 +0800 Subject: [PATCH 62/86] add test case --- source/libs/index/test/indexTests.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index ef41855c33..0ce48bcec4 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -755,6 +755,14 @@ class IndexObj { Put(terms, 10); indexMultiTermDestroy(terms); } + void PutOneTarge(const std::string& colName, const std::string& colVal, uint64_t val) { + SIndexMultiTerm* terms = indexMultiTermCreate(); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermAdd(terms, term); + Put(terms, val); + indexMultiTermDestroy(terms); + } void Debug() { std::cout << "numOfWrite:" << numOfWrite << std::endl; std::cout << "numOfRead:" << numOfRead << std::endl; @@ -922,7 +930,10 @@ TEST_F(IndexEnv2, testIndex_restart) { TEST_F(IndexEnv2, testIndex_read_performance) { std::string path = "/tmp/cache_and_tfile"; if (index->Init(path) != 0) {} + index->PutOneTarge("tag1", "Hello", 12); + index->PutOneTarge("tag1", "Hello", 15); index->ReadMultiMillonData("tag1", "Hello"); + std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl; } TEST_F(IndexEnv2, testIndexMultiTag) { std::string path = "/tmp/test3"; From c5decfec282e426fc198c30119b0da0d71580b02 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 05:31:49 -0800 Subject: [PATCH 63/86] test for dqnode --- source/dnode/mgmt/impl/src/dndBnode.c | 18 ++++-- source/dnode/mgmt/impl/src/dndQnode.c | 20 +++++-- source/dnode/mgmt/impl/src/dndSnode.c | 21 +++++-- source/dnode/mgmt/impl/src/dnode.c | 24 ++++++++ source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 59 +++++++++++--------- 5 files changed, 103 insertions(+), 39 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index da3295b5d7..1b2e56edfe 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pBnode = pMgmt->pBnode; } else { @@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { static int32_t dndOpenBnode(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; - SBnodeOpt option = {0}; + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode != NULL) { + dndReleaseBnode(pDnode, pBnode); + terrno = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; + dError("failed to create bnode since %s", terrstr()); + return -1; + } + + SBnodeOpt option = {0}; dndBuildBnodeOption(pDnode, &option); - SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option); + pBnode = bndOpen(pDnode->dir.bnode, &option); if (pBnode == NULL) { dError("failed to open bnode since %s", terrstr()); return -1; @@ -261,6 +269,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to create bnode since %s", terrstr()); return -1; } else { return dndOpenBnode(pDnode); @@ -273,6 +282,7 @@ int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to drop bnode since %s", terrstr()); return -1; } else { return dndDropBnode(pDnode); diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 642c17b661..7dd3e168ce 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pQnode = pMgmt->pQnode; } else { @@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { static int32_t dndOpenQnode(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; - SQnodeOpt option = {0}; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode != NULL) { + dndReleaseQnode(pDnode, pQnode); + terrno = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; + dError("failed to create qnode since %s", terrstr()); + return -1; + } + + SQnodeOpt option = {0}; dndBuildQnodeOption(pDnode, &option); - SQnode *pQnode = qndOpen(&option); + pQnode = qndOpen(&option); if (pQnode == NULL) { dError("failed to open qnode since %s", terrstr()); return -1; @@ -266,6 +275,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to create qnode since %s", terrstr()); return -1; } else { return dndOpenQnode(pDnode); @@ -278,6 +288,7 @@ int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to drop qnode since %s", terrstr()); return -1; } else { return dndDropQnode(pDnode); @@ -293,6 +304,7 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pQnode != NULL) { code = qndProcessMsg(pQnode, pMsg, &pRsp); } + dndReleaseQnode(pDnode, pQnode); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index a295a2d481..567c7dcdb0 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pSnode = pMgmt->pSnode; } else { @@ -170,9 +170,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); - } + } dndCleanupWorker(&pMgmt->writeWorker); } @@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { static int32_t dndOpenSnode(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; - SSnodeOpt option = {0}; + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode != NULL) { + dndReleaseSnode(pDnode, pSnode); + terrno = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; + dError("failed to create snode since %s", terrstr()); + return -1; + } + + SSnodeOpt option = {0}; dndBuildSnodeOption(pDnode, &option); - SSnode *pSnode = sndOpen(pDnode->dir.snode, &option); + pSnode = sndOpen(pDnode->dir.snode, &option); if (pSnode == NULL) { dError("failed to open snode since %s", terrstr()); return -1; @@ -261,6 +269,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to create snode since %s", terrstr()); return -1; } else { return dndOpenSnode(pDnode); @@ -273,6 +282,7 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to drop snode since %s", terrstr()); return -1; } else { return dndDropSnode(pDnode); @@ -288,6 +298,7 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pSnode != NULL) { code = sndProcessMsg(pSnode, pMsg, &pRsp); } + dndReleaseSnode(pDnode, pSnode); if (pRsp != NULL) { pRsp->ahandle = pMsg->ahandle; diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 33cec5ff47..ef5c15743c 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -14,8 +14,11 @@ */ #define _DEFAULT_SOURCE +#include "dndBnode.h" #include "dndDnode.h" #include "dndMnode.h" +#include "dndQnode.h" +#include "dndSnode.h" #include "dndTransport.h" #include "dndVnodes.h" #include "sync.h" @@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) { return NULL; } + if (dndInitQnode(pDnode) != 0) { + dError("failed to init qnode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitSnode(pDnode) != 0) { + dError("failed to init snode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitBnode(pDnode) != 0) { + dError("failed to init bnode"); + dndCleanup(pDnode); + return NULL; + } + if (dndInitMnode(pDnode) != 0) { dError("failed to init mnode"); dndCleanup(pDnode); @@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) { dndSetStat(pDnode, DND_STAT_STOPPED); dndCleanupTrans(pDnode); dndCleanupMnode(pDnode); + dndCleanupBnode(pDnode); + dndCleanupSnode(pDnode); + dndCleanupQnode(pDnode); dndCleanupVnodes(pDnode); dndCleanupDnode(pDnode); vnodeClear(); diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index fa9038107e..7c8b502a58 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -25,43 +25,50 @@ class DndTestQnode : public ::testing::Test { Testbase DndTestQnode::test; -TEST_F(DndTestQnode, 04_Drop_User) { +TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { { - int32_t contLen = sizeof(SDropUserReq); + int32_t contLen = sizeof(SDCreateQnodeReq); - SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - strcpy(pReq->user, ""); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); } - // { - // int32_t contLen = sizeof(SDropUserReq); + { + int32_t contLen = sizeof(SDCreateQnodeReq); - // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - // strcpy(pReq->user, "u4"); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); - // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - // ASSERT_NE(pMsg, nullptr); - // ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); - // } + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } - // { - // int32_t contLen = sizeof(SDropUserReq); + { + int32_t contLen = sizeof(SDCreateQnodeReq); - // SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); - // strcpy(pReq->user, "u1"); + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); - // SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - // ASSERT_NE(pMsg, nullptr); - // ASSERT_EQ(pMsg->code, 0); - // } + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } - // test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - // CHECK_META("show users", 4); + test.Restart(); - // test.SendShowRetrieveMsg(); - // EXPECT_EQ(test.GetShowRows(), 1); + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } } \ No newline at end of file From 49ef94fb6972b3fd1d5409c5399f41d3fea9292f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 22:58:52 +0800 Subject: [PATCH 64/86] refactor code --- source/libs/index/src/index.c | 3 ++- source/libs/index/test/indexTests.cc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 44d3066589..b5a65a9fda 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -401,7 +401,7 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) { IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); - if (pReader == NULL) { indexWarn("empty pReader found"); } + if (pReader == NULL) { indexWarn("empty tfile reader found"); } // handle flush Iterate* cacheIter = indexCacheIteratorCreate(pCache); Iterate* tfileIter = tfileIteratorCreate(pReader); @@ -512,6 +512,7 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { return ret; END: tfileWriterClose(tw); + return -1; } int32_t indexSerialCacheKey(ICacheKey* key, char* buf) { diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 0ce48bcec4..2ba6b505c5 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -934,6 +934,7 @@ TEST_F(IndexEnv2, testIndex_read_performance) { index->PutOneTarge("tag1", "Hello", 15); index->ReadMultiMillonData("tag1", "Hello"); std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl; + assert(3 == index->SearchOne("tag1", "Hello")); } TEST_F(IndexEnv2, testIndexMultiTag) { std::string path = "/tmp/test3"; From a75899024c8d04f2966b12b6fa9dc98bd4168a66 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 23:09:30 +0800 Subject: [PATCH 65/86] add test case --- source/libs/index/test/indexTests.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 2ba6b505c5..9c92af26a2 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -937,6 +937,17 @@ TEST_F(IndexEnv2, testIndex_read_performance) { assert(3 == index->SearchOne("tag1", "Hello")); } TEST_F(IndexEnv2, testIndexMultiTag) { - std::string path = "/tmp/test3"; + std::string path = "/tmp/multi_tag"; if (index->Init(path) != 0) {} + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); + index->WriteMultiMillonData("tag3", "Test", 100 * 10000); + index->WriteMultiMillonData("tag4", "Test", 100 * 10000); +} +TEST_F(IndexEnv2, testLongComVal) { + std::string path = "/tmp/long_colVal"; + if (index->Init(path) != 0) {} + // gen colVal by randstr + std::string randstr = "xxxxxxxxxxxxxxxxx"; + index->WriteMultiMillonData("tag1", randstr, 100 * 10000); } From 82745dea8062c9ef15f22ba85aa6d4b485c5a0a3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 23:13:08 +0800 Subject: [PATCH 66/86] refactor code --- include/os/os.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/include/os/os.h b/include/os/os.h index 53a6cef96a..0135865461 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -22,11 +22,13 @@ extern "C" { #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -36,18 +38,14 @@ extern "C" { #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include +#include #include +#include +#include + +#include #include "osAtomic.h" #include "osDef.h" From a84af557023f947cf2708aa90435a27e85b68fd1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 23:24:37 +0800 Subject: [PATCH 67/86] refactor code --- include/os/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/os/os.h b/include/os/os.h index 0135865461..972880da9c 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -40,7 +40,7 @@ extern "C" { #include #include #include -#include +#include #include #include #include From c0aded7b570bbc78bf0651fd05fd2209b64029c8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 17:58:02 -0800 Subject: [PATCH 68/86] add test cases --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 + .../dnode/mgmt/impl/test/bnode/CMakeLists.txt | 11 ++ source/dnode/mgmt/impl/test/bnode/bnode.cpp | 154 ------------------ source/dnode/mgmt/impl/test/bnode/dbnode.cpp | 133 +++++++++++++++ source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 61 ++++++- .../dnode/mgmt/impl/test/snode/CMakeLists.txt | 11 ++ source/dnode/mgmt/impl/test/snode/dsnode.cpp | 133 +++++++++++++++ 7 files changed, 350 insertions(+), 155 deletions(-) create mode 100644 source/dnode/mgmt/impl/test/bnode/CMakeLists.txt delete mode 100644 source/dnode/mgmt/impl/test/bnode/bnode.cpp create mode 100644 source/dnode/mgmt/impl/test/bnode/dbnode.cpp create mode 100644 source/dnode/mgmt/impl/test/snode/CMakeLists.txt create mode 100644 source/dnode/mgmt/impl/test/snode/dsnode.cpp diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index 6e6015b5f4..da043f8fe2 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,6 +1,8 @@ enable_testing() add_subdirectory(qnode) +add_subdirectory(bnode) +add_subdirectory(snode) # add_subdirectory(auth) # add_subdirectory(balance) diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt new file mode 100644 index 0000000000..22edc9b257 --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. BQTEST_SRC) +add_executable(dnode_test_bnode ${BQTEST_SRC}) +target_link_libraries( + dnode_test_bnode + PUBLIC sut +) + +add_test( + NAME dnode_test_bnode + COMMAND dnode_test_bnode +) diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp deleted file mode 100644 index 7777d60550..0000000000 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file dnode.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "sut.h" - -class DndTestBnode : public ::testing::Test { - public: - void SetUp() override {} - void TearDown() override {} - - public: - static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_bnode1", 9068); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9068"; - - server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); - taosMsleep(300); - } - - static void TearDownTestSuite() { - server2.Stop(); - test.Cleanup(); - } - - static Testbase test; - static TestServer server2; -}; - -Testbase DndTestBnode::test; -TestServer DndTestBnode::server2; - -TEST_F(DndTestBnode, 01_ShowBnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(1); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} - -TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); - } -} - -TEST_F(DndTestBnode, 04_Create_Bnode) { - { - // create dnode - int32_t contLen = sizeof(SCreateDnodeMsg); - - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9069); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - } - - { - // create bnode - int32_t contLen = sizeof(SMCreateBnodeReq); - - SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckBinary("localhost:9069", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); - } - - { - // drop bnode - int32_t contLen = sizeof(SMDropBnodeReq); - - SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/bnode/dbnode.cpp b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp new file mode 100644 index 0000000000..dd8c13c4bd --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dbnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestBnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestBnode::test; + +TEST_F(DndTestBnode, 01_Create_Bnode) { + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestBnode, 01_Drop_Bnode) { + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index 7c8b502a58..48de6e03eb 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -25,7 +25,7 @@ class DndTestQnode : public ::testing::Test { Testbase DndTestQnode::test; -TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { +TEST_F(DndTestQnode, 01_Create_Qnode) { { int32_t contLen = sizeof(SDCreateQnodeReq); @@ -71,4 +71,63 @@ TEST_F(DndTestQnode, 01_Create_Qnode_Invalid) { ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); } +} + +TEST_F(DndTestQnode, 01_Drop_Qnode) { + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt new file mode 100644 index 0000000000..9c163d1999 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. SQTEST_SRC) +add_executable(dnode_test_snode ${SQTEST_SRC}) +target_link_libraries( + dnode_test_snode + PUBLIC sut +) + +add_test( + NAME dnode_test_snode + COMMAND dnode_test_snode +) diff --git a/source/dnode/mgmt/impl/test/snode/dsnode.cpp b/source/dnode/mgmt/impl/test/snode/dsnode.cpp new file mode 100644 index 0000000000..2ec624b942 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/dsnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dsnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module snode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestSnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestSnode::test; + +TEST_F(DndTestSnode, 01_Create_Snode) { + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestSnode, 01_Drop_Snode) { + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} \ No newline at end of file From feee87ddfa14be2267a6035af257ea04adef76f9 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 5 Jan 2022 10:11:26 +0800 Subject: [PATCH 69/86] feature/qnode --- source/libs/scheduler/inc/schedulerInt.h | 5 ++-- source/libs/scheduler/src/scheduler.c | 31 +++++++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index fa4ae0d152..1d5d0599e6 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -114,8 +114,9 @@ typedef struct SSchJob { #define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN) #define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY) -#define SCH_JOB_ERR_LOG(param, ...) qError("QID:%"PRIx64 param, job->queryId, __VA_ARGS__) -#define SCH_TASK_ERR_LOG(param, ...) qError("QID:%"PRIx64",TID:%"PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) +#define SCH_JOB_ELOG(param, ...) qError("QID:% "PRIx64 param, job->queryId, __VA_ARGS__) +#define SCH_TASK_ELOG(param, ...) qError("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) +#define SCH_TASK_DLOG(param, ...) qDebug("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) #define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 22556f742b..ff254da6fb 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -270,6 +270,8 @@ int32_t schPushTaskToExecList(SSchJob *job, SSchTask *task) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "execTasks"); + return TSDB_CODE_SUCCESS; } @@ -284,6 +286,8 @@ int32_t schMoveTaskToSuccList(SSchJob *job, SSchTask *task, bool *moved) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "succTasks"); + *moved = true; return TSDB_CODE_SUCCESS; @@ -299,6 +303,8 @@ int32_t schMoveTaskToFailList(SSchJob *job, SSchTask *task, bool *moved) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "failTasks"); + *moved = true; return TSDB_CODE_SUCCESS; @@ -372,7 +378,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { SCH_ERR_RET(schMoveTaskToSuccList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ELOG("task may already moved, status:%d", task->status); return TSDB_CODE_SUCCESS; } @@ -447,11 +453,11 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { SCH_ERR_RET(schTaskCheckAndSetRetry(job, task, errCode, &needRetry)); if (!needRetry) { - SCH_TASK_ERR_LOG("task failed[%x], no more retry", errCode); + SCH_TASK_ELOG("task failed[%x], no more retry", errCode); SCH_ERR_RET(schMoveTaskToFailList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ELOG("task may already moved, status:%d", task->status); } if (SCH_TASK_NEED_WAIT_ALL(task)) { @@ -492,6 +498,7 @@ int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *ms goto _task_error; } } + break; } case TDMT_VND_SUBMIT_RSP: { if (rspCode != TSDB_CODE_SUCCESS) { @@ -567,19 +574,25 @@ int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, in int32_t code = 0; SSchCallbackParam *pParam = (SSchCallbackParam *)param; - SSchJob **job = taosHashGet(schMgmt.jobs, &pParam->queryId, sizeof(pParam->queryId)); - if (NULL == job || NULL == (*job)) { + SSchJob **pjob = taosHashGet(schMgmt.jobs, &pParam->queryId, sizeof(pParam->queryId)); + if (NULL == pjob || NULL == (*pjob)) { qError("taosHashGet queryId:%"PRIx64" not exist", pParam->queryId); SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); } - SSchTask **task = taosHashGet((*job)->execTasks, &pParam->taskId, sizeof(pParam->taskId)); - if (NULL == task || NULL == (*task)) { + SSchJob *job = *pjob; + + SSchTask **ptask = taosHashGet(job->execTasks, &pParam->taskId, sizeof(pParam->taskId)); + if (NULL == ptask || NULL == (*ptask)) { qError("taosHashGet taskId:%"PRIx64" not exist", pParam->taskId); SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); } + + SSchTask *task = *ptask; + + SCH_TASK_DLOG("Got msg:%d, rspCode:%d", msgType, rspCode); - schProcessRspMsg(*job, *task, msgType, pMsg->pData, pMsg->len, rspCode); + schProcessRspMsg(job, task, msgType, pMsg->pData, pMsg->len, rspCode); _return: tfree(param); @@ -809,7 +822,7 @@ int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SCH_ERR_RET(schSetTaskCondidateAddrs(job, task)); if (NULL == task->condidateAddrs || taosArrayGetSize(task->condidateAddrs) <= 0) { - SCH_TASK_ERR_LOG("no valid condidate node for task:%"PRIx64, task->taskId); + SCH_TASK_ELOG("no valid condidate node for task:%"PRIx64, task->taskId); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } From 75077c4ae9078a06ab6d4e9158356c16135113d1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 5 Jan 2022 02:12:50 +0000 Subject: [PATCH 70/86] make multi-thread query work --- source/dnode/vnode/meta/src/metaBDBImpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index ae6693f973..4220a604b4 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -255,7 +255,7 @@ static int metaOpenBDBEnv(DB_ENV **ppEnv, const char *path) { return -1; } - ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_MPOOL, 0); + ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0); if (ret != 0) { BDB_PERR("Failed to open META env", ret); return -1; From 6ae9a421e01d6b902c56d4356cbdf2dcff1e6222 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 18:27:11 -0800 Subject: [PATCH 71/86] fix crash while process transmsg --- source/dnode/mgmt/impl/src/dndQnode.c | 18 +++++++++------- source/dnode/mgmt/impl/src/dndSnode.c | 18 +++++++++------- source/dnode/mnode/impl/src/mnode.c | 16 +++++++------- source/dnode/mnode/impl/test/qnode/qnode.cpp | 22 ++++++++++++-------- source/libs/transport/src/rpcMain.c | 2 ++ 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 7dd3e168ce..845ea8bf9a 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -306,14 +306,16 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { } dndReleaseQnode(pDnode, pQnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index 567c7dcdb0..7f234629cb 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -300,14 +300,16 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { } dndReleaseSnode(pDnode, pSnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 0653a0f5d4..7c740df06d 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -366,14 +366,16 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { return NULL; } - SRpcConnInfo connInfo = {0}; - if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { - taosFreeQitem(pMsg); - terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); - return NULL; + if (pRpcMsg->msgType != TDMT_MND_TRANS) { + SRpcConnInfo connInfo = {0}; + if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { + taosFreeQitem(pMsg); + terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); + return NULL; + } + memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); } - memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); pMsg->pMnode = pMnode; pMsg->rpcMsg = *pRpcMsg; diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index f5dfc35188..3fdd5315a4 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -50,7 +50,18 @@ TEST_F(MndTestQnode, 01_Show_Qnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { +TEST_F(MndTestQnode, 02_Create_Qnode) { + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + { int32_t contLen = sizeof(SMCreateQnodeReq); @@ -63,11 +74,6 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -75,14 +81,12 @@ TEST_F(MndTestQnode, 02_Create_Qnode_Invalid_Id) { CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } -} -TEST_F(MndTestQnode, 03_Create_Qnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateQnodeReq); SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); + pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 242bdb1558..c816cb45a3 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -423,6 +423,8 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t } void rpcSendResponse(const SRpcMsg *pRsp) { + if (pRsp->handle == NULL) return; + int msgLen = 0; SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcMsg rpcMsg = *pRsp; From ad965dbcb462508d5c2b3822510cb84a5603b982 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 19:24:28 -0800 Subject: [PATCH 72/86] invalid release --- source/dnode/mnode/impl/src/mndBnode.c | 12 +++++++----- source/dnode/mnode/impl/src/mndQnode.c | 12 +++++++----- source/dnode/mnode/impl/src/mndSnode.c | 12 +++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 886784805e..312438a535 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -26,7 +26,7 @@ static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj); static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw); static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj); static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj); -static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode); +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew); static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg); @@ -155,9 +155,9 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { return 0; } -static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) { - mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOldBnode->id, pOldBnode, pNewBnode); - pOldBnode->updateTime = pNewBnode->updateTime; +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) { + mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -251,6 +251,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { mError("bnode:%d, bnode already exist", pObj->id); + terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST; mndReleaseBnode(pMnode, pObj); return -1; } @@ -370,11 +371,12 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { int32_t code = mndDropBnode(pMnode, pMsg, pObj); if (code != 0) { + sdbRelease(pMnode->pSdb, pObj); mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index ea4cfa41c8..5ff3a79040 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -26,7 +26,7 @@ static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj); static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw); static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj); static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj); -static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode); +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew); static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg); @@ -155,9 +155,9 @@ static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { return 0; } -static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) { - mTrace("qnode:%d, perform update action, old_row:%p new_row:%p", pOldQnode->id, pOldQnode, pNewQnode); - pOldQnode->updateTime = pNewQnode->updateTime; +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew) { + mTrace("qnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -251,6 +251,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { SQnodeObj *pObj = mndAcquireQnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { mError("qnode:%d, qnode already exist", pObj->id); + terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST; mndReleaseQnode(pMnode, pObj); return -1; } @@ -370,11 +371,12 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { int32_t code = mndDropQnode(pMnode, pMsg, pObj); if (code != 0) { + sdbRelease(pMnode->pSdb, pObj); mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 3ab1ad4eaf..5d13211380 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -26,7 +26,7 @@ static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj); static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw); static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj); static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj); -static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode); +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew); static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg); @@ -155,9 +155,9 @@ static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { return 0; } -static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) { - mTrace("snode:%d, perform update action, old_row:%p new_row:%p", pOldSnode->id, pOldSnode, pNewSnode); - pOldSnode->updateTime = pNewSnode->updateTime; +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew) { + mTrace("snode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -251,6 +251,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { SSnodeObj *pObj = mndAcquireSnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { mError("snode:%d, snode already exist", pObj->id); + terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; mndReleaseSnode(pMnode, pObj); return -1; } @@ -370,11 +371,12 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { int32_t code = mndDropSnode(pMnode, pMsg, pObj); if (code != 0) { + sdbRelease(pMnode->pSdb, pObj); mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } From 0d4490bce89344a08db60843fa7e8fdced78e17e Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 22:32:38 -0500 Subject: [PATCH 73/86] TD-12696 bug fix for insert --- include/common/tmsg.h | 4 ---- source/libs/parser/src/dataBlockMgt.c | 2 +- source/libs/parser/src/insertParser.c | 10 ++++++---- source/libs/parser/test/insertParserTest.cpp | 8 ++------ source/libs/parser/test/mockCatalogService.cpp | 4 ++-- source/libs/planner/test/phyPlanTests.cpp | 2 +- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index affab8903c..1b2b6a677a 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -156,10 +156,6 @@ typedef struct { uint16_t port; } SEpAddr; -typedef struct { - int32_t numOfVnodes; -} SMsgDesc; - typedef struct SMsgHead { int32_t contLen; int32_t vgId; diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index b315ea613f..bc4eae7ae9 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -467,7 +467,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB } int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t payloadType, SArray** pVgDataBlocks) { - const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg); + const int INSERT_HEAD_SIZE = sizeof(SSubmitMsg); int code = 0; bool isRawPayload = IS_RAW_PAYLOAD(payloadType); SHashObj* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index c63e854051..73b1b17353 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -121,11 +121,13 @@ static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pS } static void buildMsgHeader(SVgDataBlocks* blocks) { - SMsgDesc* desc = (SMsgDesc*)blocks->pData; - desc->numOfVnodes = htonl(1); - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + // SMsgDesc* desc = (SMsgDesc*)blocks->pData; + // desc->numOfVnodes = htonl(1); + // SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)blocks->pData; submit->header.vgId = htonl(blocks->vg.vgId); - submit->header.contLen = htonl(blocks->size - sizeof(SMsgDesc)); + // submit->header.contLen = htonl(blocks->size - sizeof(SMsgDesc)); + submit->header.contLen = htonl(blocks->size); submit->length = submit->header.contLen; submit->numOfBlocks = htonl(blocks->numOfTables); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); diff --git a/source/libs/parser/test/insertParserTest.cpp b/source/libs/parser/test/insertParserTest.cpp index 5c175cd023..9b007fb36d 100644 --- a/source/libs/parser/test/insertParserTest.cpp +++ b/source/libs/parser/test/insertParserTest.cpp @@ -70,9 +70,7 @@ protected: for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(res_->pDataBlocks, i); cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; - SMsgDesc* desc = (SMsgDesc*)(vg->pData); - cout << "numOfVnodes:" << ntohl(desc->numOfVnodes) << endl; - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)vg->pData; cout << "length:" << ntohl(submit->length) << ", numOfBlocks:" << ntohl(submit->numOfBlocks) << endl; int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); @@ -95,9 +93,7 @@ protected: SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(res_->pDataBlocks, i); ASSERT_EQ(vg->numOfTables, numOfTables); ASSERT_GE(vg->size, 0); - SMsgDesc* desc = (SMsgDesc*)(vg->pData); - ASSERT_EQ(ntohl(desc->numOfVnodes), 1); - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)vg->pData; ASSERT_GE(ntohl(submit->length), 0); ASSERT_GE(ntohl(submit->numOfBlocks), 0); int32_t numOfBlocks = ntohl(submit->numOfBlocks); diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 3be358fec8..bdd023be83 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -27,7 +27,7 @@ std::unique_ptr mockCatalogService; class TableBuilder : public ITableBuilder { public: virtual TableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) { - assert(colId_ < schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); + assert(colId_ <= schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); SSchema* col = schema()->schema + colId_; col->type = type; col->colId = colId_++; @@ -66,7 +66,7 @@ private: return std::unique_ptr(new TableBuilder(meta)); } - TableBuilder(STableMeta* schemaMeta) : colId_(0), rowsize_(0), meta_(new MockTableMeta()) { + TableBuilder(STableMeta* schemaMeta) : colId_(1), rowsize_(0), meta_(new MockTableMeta()) { meta_->schema.reset(schemaMeta); } diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index b6f9612653..3f6f5ab77b 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -33,7 +33,7 @@ protected: void pushScan(const string& db, const string& table, int32_t scanOp) { shared_ptr meta = mockCatalogService->getTableMeta(db, table); EXPECT_TRUE(meta); - unique_ptr scan((SQueryPlanNode*)calloc(1, sizeof(SQueryPlanNode))); + unique_ptr scan((SQueryPlanNode*)myCalloc(1, sizeof(SQueryPlanNode))); scan->info.type = scanOp; scan->numOfCols = meta->schema->tableInfo.numOfColumns; scan->pSchema = (SSchema*)myCalloc(1, sizeof(SSchema) * scan->numOfCols); From 17b9917bfab758917811e9f8d164d4341a6452e4 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 22:43:29 -0500 Subject: [PATCH 74/86] TD-12696 bug fix for insert --- source/libs/parser/src/insertParser.c | 4 ---- source/libs/parser/test/mockCatalogService.cpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index 73b1b17353..8b3c328cce 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -121,12 +121,8 @@ static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pS } static void buildMsgHeader(SVgDataBlocks* blocks) { - // SMsgDesc* desc = (SMsgDesc*)blocks->pData; - // desc->numOfVnodes = htonl(1); - // SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); SSubmitMsg* submit = (SSubmitMsg*)blocks->pData; submit->header.vgId = htonl(blocks->vg.vgId); - // submit->header.contLen = htonl(blocks->size - sizeof(SMsgDesc)); submit->header.contLen = htonl(blocks->size); submit->length = submit->header.contLen; submit->numOfBlocks = htonl(blocks->numOfTables); diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index bdd023be83..2a0f6b38eb 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -28,7 +28,7 @@ class TableBuilder : public ITableBuilder { public: virtual TableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) { assert(colId_ <= schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); - SSchema* col = schema()->schema + colId_; + SSchema* col = schema()->schema + (colId_ - 1); col->type = type; col->colId = colId_++; col->bytes = bytes; From 27224db24b09d8ad97e94b5aa56ac801ffe8f301 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 5 Jan 2022 14:09:02 +0800 Subject: [PATCH 75/86] [td-11818] fix memory leak and refactor code. --- include/libs/parser/parser.h | 2 +- source/client/src/clientImpl.c | 27 ++-- source/client/src/clientMsgHandler.c | 1 + source/client/test/clientTests.cpp | 197 +++++++++++++------------ source/libs/catalog/src/catalog.c | 1 - source/libs/parser/src/astGenerator.c | 2 +- source/libs/parser/src/astToMsg.c | 2 +- source/libs/parser/src/dCDAstProcess.c | 111 ++++++++------ source/libs/parser/src/parser.c | 8 +- source/libs/planner/src/logicPlan.c | 12 ++ source/libs/planner/src/physicalPlan.c | 8 +- source/libs/planner/src/planner.c | 36 ++++- 12 files changed, 240 insertions(+), 167 deletions(-) diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index a9e1f26d20..5bd18641bf 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -43,7 +43,7 @@ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); bool qIsDdlQuery(const SQueryNode* pQuery); -void qDestroyQuery(SQueryNode* pQuery); +void qDestroyQuery(SQueryNode* pQueryNode); /** * 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/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index a967a65c44..2bc276b0af 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -192,13 +192,12 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { } tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(pSendMsg); return TSDB_CODE_SUCCESS; } -int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { - pRequest->type = pQuery->type; - return qCreateQueryDag(pQuery, pDag, pRequest->requestId); +int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) { + pRequest->type = pQueryNode->type; + return qCreateQueryDag(pQueryNode, pDag, pRequest->requestId); } int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { @@ -364,8 +363,6 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(body); - if (pRequest->code != TSDB_CODE_SUCCESS) { const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); printf("failed to connect to server, reason: %s\n\n", errorMsg); @@ -456,17 +453,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); } - SDataBuf buf = {.len = pMsg->contLen}; - buf.pData = calloc(1, pMsg->contLen); - if (buf.pData == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - pMsg->code = TSDB_CODE_OUT_OF_MEMORY; - } else { - memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; + + if (pMsg->contLen > 0) { + buf.pData = calloc(1, pMsg->contLen); + if (buf.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pMsg->code = TSDB_CODE_OUT_OF_MEMORY; + } else { + memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + } } pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); rpcFreeCont(pMsg->pCont); + destroySendMsgInfo(pSendInfo); } TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) { diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 017fa493cf..5ac5d871c9 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -272,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; + free(pMsg->pData); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 2bf3232b26..e6759115ed 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -171,7 +171,7 @@ TEST(testCase, create_db_Test) { } taos_close(pConn); } -// + //TEST(testCase, create_dnode_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -190,7 +190,7 @@ TEST(testCase, create_db_Test) { // // taos_close(pConn); //} -// + //TEST(testCase, drop_dnode_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -250,36 +250,36 @@ TEST(testCase, create_db_Test) { //// taos_close(pConn); //} -// TEST(testCase, create_stable_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); -// if (taos_errno(pRes) != 0) { -// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// taos_close(pConn); -//} + TEST(testCase, create_stable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -293,7 +293,7 @@ TEST(testCase, create_db_Test) { // // // // taos_close(pConn); //} -// + //TEST(testCase, create_ctable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -304,12 +304,12 @@ TEST(testCase, create_db_Test) { // } // taos_free_result(pRes); // -//// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); -//// if (taos_errno(pRes) != 0) { -//// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); -//// } -//// -//// taos_free_result(pRes); +// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); // taos_close(pConn); //} // @@ -343,7 +343,7 @@ TEST(testCase, create_db_Test) { // taos_free_result(pRes); // taos_close(pConn); //} -// + //TEST(testCase, show_vgroup_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -376,7 +376,7 @@ TEST(testCase, create_db_Test) { // // taos_close(pConn); //} -// + //TEST(testCase, drop_stable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -464,66 +464,73 @@ TEST(testCase, create_db_Test) { // taos_close(pConn); //} -//TEST(testCase, create_multiple_tables) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// ASSERT_NE(pConn, nullptr); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); -// if (taos_errno(pRes) != 0) { -// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); +TEST(testCase, create_multiple_tables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(pConn, nullptr); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s", taos_errstr(pRes)); + taos_free_result(pRes); + taos_close(pConn); + return; + } + + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + taos_free_result(pRes); + pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); + if (taos_errno(pRes) != 0) { + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + 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_free_result(pRes); + +// for(int32_t i = 0; i < 10000; ++i) { +// char sql[512] = {0}; +// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); +// TAOS_RES* pres = taos_query(pConn, sql); +// if (taos_errno(pres) != 0) { +// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); +// } +// taos_free_result(pres); // } + + taos_close(pConn); +} + +//TEST(testCase, generated_request_id_test) { +// SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); // -// taos_free_result(pRes); -// pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); -// if (taos_errno(pRes) != 0) { -// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } -// -// 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_free_result(pRes); -// -//// for(int32_t i = 0; i < 10000; ++i) { -//// char sql[512] = {0}; -//// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); -//// TAOS_RES* pres = taos_query(pConn, sql); -//// if (taos_errno(pres) != 0) { -//// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); -//// } -//// taos_free_result(pres); +//// for(int32_t i = 0; i < 1000000; ++i) { +//// uint64_t v = generateRequestId(); +//// void* result = taosHashGet(phash, &v, sizeof(v)); +//// ASSERT_EQ(result, nullptr); +//// taosHashPut(phash, &v, sizeof(v), NULL, 0); //// } // -// taos_close(pConn); +// taosHashCleanup(phash); //} -TEST(testCase, generated_request_id_test) { - SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - -// for(int32_t i = 0; i < 1000000; ++i) { -// uint64_t v = generateRequestId(); -// void* result = taosHashGet(phash, &v, sizeof(v)); -// ASSERT_EQ(result, nullptr); -// taosHashPut(phash, &v, sizeof(v), NULL, 0); -// } - - taosHashCleanup(phash); -} - //TEST(testCase, projection_query_tables) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // ASSERT_EQ(pConn, nullptr); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index abcfafa786..045c92b586 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -214,7 +214,6 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE SEpSet epSet; ctgGenEpSet(&epSet, vgroupInfo); - rpcSendRecv(pRpc, &epSet, &rpcMsg, &rpcRsp); if (TSDB_CODE_SUCCESS != rpcRsp.code) { diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 3f45012405..288d6296fa 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -785,7 +785,7 @@ void destroySqlInfo(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->funcs); if (pInfo->type == TSDB_SQL_SELECT) { destroyAllSqlNode(&pInfo->sub); - } else if (pInfo->type == TSDB_SQL_CREATE_STABLE) { + } else if (pInfo->type == TSDB_SQL_CREATE_STABLE || pInfo->type == TSDB_SQL_CREATE_TABLE) { pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo); } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeItem); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index ab8c9b8094..981eac1266 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -330,7 +330,7 @@ SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* p assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T); pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - *len = sizeof(SDropTableMsg); + *len = sizeof(SDropStbMsg); return pDropTableMsg; } diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 8ff0636969..d9bfb86028 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -1,5 +1,5 @@ -#include -#include +#include "tmsg.h" +#include "ttime.h" #include "astToMsg.h" #include "parserInt.h" #include "parserUtil.h" @@ -248,16 +248,10 @@ static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, in } static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { - assert(pFieldList != NULL); + assert(pFieldList != NULL && pMsgBuf != NULL); const char* msg1 = "first column must be timestamp"; - const char* msg2 = "row length exceeds max length"; - const char* msg3 = "duplicated column names"; - const char* msg4 = "invalid data type"; - const char* msg5 = "invalid binary/nchar column length"; - const char* msg6 = "invalid column name"; - const char* msg7 = "too many columns"; - const char* msg8 = "illegal number of columns"; + const char* msg2 = "illegal number of columns"; // first column must be timestamp SField* pField = taosArrayGet(pFieldList, 0); @@ -268,7 +262,7 @@ static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { // number of fields no less than 2 size_t numOfCols = taosArrayGetSize(pFieldList); if (numOfCols <= 1) { - return buildInvalidOperationMsg(pMsgBuf, msg8); + return buildInvalidOperationMsg(pMsgBuf, msg2); } return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf); @@ -326,6 +320,8 @@ typedef struct SVgroupTablesBatch { SVgroupInfo info; } SVgroupTablesBatch; +static SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap); + static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputTag, SKVRowBuilder* pKvRowBuilder, SArray* pTagValList, int32_t tsPrecision, SMsgBuf* pMsgBuf) { const char* msg1 = "illegal value or data overflow"; @@ -351,6 +347,39 @@ static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputT return code; } +static void addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const SName* pTableName, SKVRow row, uint64_t suid, SVgroupInfo* pVgInfo) { + struct SVCreateTbReq req = {0}; + req.type = TD_CHILD_TABLE; + req.name = strdup(tNameGetTableName(pTableName)); + req.ctbCfg.suid = suid; + req.ctbCfg.pTag = row; + + SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); + if (pTableBatch == NULL) { + SVgroupTablesBatch tBatch = {0}; + tBatch.info = *pVgInfo; + + tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); + taosArrayPush(tBatch.req.pArray, &req); + + taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + assert(pVgInfo->vgId == pTableBatch->info.vgId); + taosArrayPush(pTableBatch->req.pArray, &req); + } +} + +static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { + size_t size = taosArrayGetSize(pTbBatch->req.pArray); + for(int32_t i = 0; i < size; ++i) { + SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); + tfree(pTableReq->name); + tfree(pTableReq->ctbCfg.pTag); + } + + taosArrayDestroy(pTbBatch->req.pArray); +} + int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; @@ -519,36 +548,32 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SVgroupInfo info = {0}; catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); - struct SVCreateTbReq req = {0}; - req.type = TD_CHILD_TABLE; - req.name = strdup(tNameGetTableName(&tableName)); - req.ctbCfg.suid = pSuperTableMeta->uid; - req.ctbCfg.pTag = row; - - SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); - if (pTableBatch == NULL) { - SVgroupTablesBatch tBatch = {0}; - tBatch.info = info; - - tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); - taosArrayPush(tBatch.req.pArray, &req); - - taosHashPut(pVgroupHashmap, &info.vgId, sizeof(info.vgId), &tBatch, sizeof(tBatch)); - } else { // add to the correct vgroup - assert(info.vgId == pTableBatch->info.vgId); - taosArrayPush(pTableBatch->req.pArray, &req); - } - + addCreateTbReqIntoVgroup(pVgroupHashmap, &tableName, row, pSuperTableMeta->uid, &info); tfree(pSuperTableMeta); } - // TODO: serialize and + SArray *pBufArray = doSerializeVgroupCreateTableInfo(pVgroupHashmap); + + SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo)); + pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; + pStmtInfo->pDataBlocks = pBufArray; + + *pOutput = (char*) pStmtInfo; + *len = sizeof(SVnodeModifOpStmtInfo); + + taosHashCleanup(pVgroupHashmap); + return TSDB_CODE_SUCCESS; +} + +SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); SVgroupTablesBatch* pTbBatch = NULL; do { pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); - if (pTbBatch == NULL) break; + if (pTbBatch == NULL) { + break; + } int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); void* buf = malloc(tlen); @@ -569,17 +594,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); taosArrayPush(pBufArray, &pVgData); + destroyCreateTbReqBatch(pTbBatch); } while (true); - - SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo)); - pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; - pStmtInfo->pDataBlocks = pBufArray; - - *pOutput = (char*) pStmtInfo; - *len = sizeof(SVnodeModifOpStmtInfo); - - taosHashCleanup(pVgroupHashmap); - return TSDB_CODE_SUCCESS; + return pBufArray; } SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { @@ -855,14 +872,14 @@ SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBas SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf* pMsgBuf = &m; - SVnodeModifOpStmtInfo* pInsertStmt = NULL; + SVnodeModifOpStmtInfo* pModifSqlStmt = NULL; int32_t msgLen = 0; - int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pInsertStmt, &msgLen); + int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pModifSqlStmt, &msgLen); if (code != TSDB_CODE_SUCCESS) { - tfree(pInsertStmt); + tfree(pModifSqlStmt); return NULL; } - return pInsertStmt; + return pModifSqlStmt; } \ No newline at end of file diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index ad248f1795..bdb3dcd3e3 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -240,6 +240,10 @@ void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaReq) { taosArrayDestroy(pMetaReq->pUdf); } -void qDestroyQuery(SQueryNode* pQuery) { - tfree(pQuery); +void qDestroyQuery(SQueryNode* pQueryNode) { + if (nodeType(pQueryNode) == TSDB_SQL_INSERT || nodeType(pQueryNode) == TSDB_SQL_CREATE_TABLE) { + SVnodeModifOpStmtInfo* pModifInfo = (SVnodeModifOpStmtInfo*)pQueryNode; + taosArrayDestroy(pModifInfo->pDataBlocks); + } + tfree(pQueryNode); } diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index d04fd716c2..fa7b3776dc 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -392,6 +392,18 @@ SArray* createQueryPlanImpl(const SQueryStmtInfo* pQueryInfo) { } static void doDestroyQueryNode(SQueryPlanNode* pQueryNode) { + if (pQueryNode->info.type == QNODE_MODIFY) { + SDataPayloadInfo* pInfo = pQueryNode->pExtInfo; + + size_t size = taosArrayGetSize(pInfo->payload); + for (int32_t i = 0; i < size; ++i) { + SVgDataBlocks* pBlock = taosArrayGetP(pInfo->payload, i); + tfree(pBlock); + } + + taosArrayDestroy(pInfo->payload); + } + tfree(pQueryNode->pExtInfo); tfree(pQueryNode->pSchema); tfree(pQueryNode->info.name); diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 7f472be756..e7468e44eb 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -305,10 +305,10 @@ static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlan SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(pPayload->payload, i); vgroupInfoToEpSet(&blocks->vg, &subplan->execNode); - subplan->pDataSink = createDataInserter(pCxt, blocks); - subplan->pNode = NULL; - subplan->type = QUERY_TYPE_MODIFY; - subplan->msgType = pPayload->msgType; + subplan->pDataSink = createDataInserter(pCxt, blocks); + subplan->pNode = NULL; + subplan->type = QUERY_TYPE_MODIFY; + subplan->msgType = pPayload->msgType; subplan->id.queryId = pCxt->pDag->queryId; RECOVERY_CURRENT_SUBPLAN(pCxt); diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index e50f4d02b9..b61c7c390f 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -16,12 +16,44 @@ #include "parser.h" #include "plannerInt.h" +static void destroyDataSinkNode(SDataSink* pSinkNode) { + if (pSinkNode == NULL) { + return; + } + tfree(pSinkNode); +} + void qDestroySubplan(SSubplan* pSubplan) { - // todo + if (pSubplan == NULL) { + return; + } + + taosArrayDestroy(pSubplan->pChildren); + taosArrayDestroy(pSubplan->pParents); + destroyDataSinkNode(pSubplan->pDataSink); + // todo destroy pNode + tfree(pSubplan); } void qDestroyQueryDag(struct SQueryDag* pDag) { - // todo + if (pDag == NULL) { + return; + } + + size_t size = taosArrayGetSize(pDag->pSubplans); + for(size_t i = 0; i < size; ++i) { + SArray* pa = taosArrayGetP(pDag->pSubplans, i); + + size_t t = taosArrayGetSize(pa); + for(int32_t j = 0; j < t; ++j) { + SSubplan* pSubplan = taosArrayGetP(pa, j); + qDestroySubplan(pSubplan); + } + taosArrayDestroy(pa); + } + + taosArrayDestroy(pDag->pSubplans); + tfree(pDag); } int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, uint64_t requestId) { From 9dd5922d150bb6f5c2232ea638201d8d646a37c9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 22:36:24 -0800 Subject: [PATCH 76/86] error returned when trans rollback --- source/dnode/mnode/impl/inc/mndDef.h | 8 ++++---- source/dnode/mnode/impl/src/mndTrans.c | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 267a3f6cf5..93a5722842 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -64,10 +64,10 @@ typedef enum { TRN_STAGE_PREPARE = 0, TRN_STAGE_REDO_LOG = 1, TRN_STAGE_REDO_ACTION = 2, - TRN_STAGE_UNDO_LOG = 3, - TRN_STAGE_UNDO_ACTION = 4, - TRN_STAGE_COMMIT_LOG = 5, - TRN_STAGE_COMMIT = 6, + TRN_STAGE_COMMIT_LOG = 3, + TRN_STAGE_COMMIT = 4, + TRN_STAGE_UNDO_ACTION = 5, + TRN_STAGE_UNDO_LOG = 6, TRN_STAGE_ROLLBACK = 7, TRN_STAGE_FINISHED = 8 } ETrnStage; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index ee4a49ffdc..82fe296166 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -496,10 +496,15 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { } static void mndTransSendRpcRsp(STrans *pTrans) { - if (pTrans->rpcHandle != NULL) { - mDebug("trans:%d, send rsp, ahandle:%p code:0x%x", pTrans->id, pTrans->rpcAHandle, pTrans->code & 0xFFFF); - SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; - rpcSendResponse(&rspMsg); + if (pTrans->stage == TRN_STAGE_FINISHED || pTrans->stage == TRN_STAGE_UNDO_LOG || + pTrans->stage == TRN_STAGE_UNDO_ACTION || pTrans->stage == TRN_STAGE_ROLLBACK) { + if (pTrans->rpcHandle != NULL) { + mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, + pTrans->rpcAHandle); + SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; + rpcSendResponse(&rspMsg); + pTrans->rpcHandle = NULL; + } } } @@ -764,7 +769,6 @@ static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans) { pTrans->failedTimes++; mError("trans:%d, stage keep on commitLog since %s", pTrans->id, terrstr()); continueExec = false; - ; } return continueExec; @@ -791,7 +795,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) { int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); if (code == 0) { - pTrans->stage = TRN_STAGE_REDO_LOG; + pTrans->stage = TRN_STAGE_UNDO_LOG; mDebug("trans:%d, stage from undoAction to undoLog", pTrans->id); continueExec = true; } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { @@ -814,7 +818,6 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { pTrans->stage = TRN_STAGE_FINISHED; mDebug("trans:%d, stage from rollback to finished", pTrans->id); continueExec = true; - ; } else { pTrans->failedTimes++; mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr()); @@ -880,9 +883,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } } - if (pTrans->stage == TRN_STAGE_FINISHED) { - mndTransSendRpcRsp(pTrans); - } + mndTransSendRpcRsp(pTrans); } static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { From 4728b159c796b36a298c5f0ce9bb72debcccf500 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 5 Jan 2022 16:00:06 +0800 Subject: [PATCH 77/86] feature/qnode --- include/libs/catalog/catalog.h | 19 ++- source/libs/catalog/inc/catalogInt.h | 8 ++ source/libs/catalog/src/catalog.c | 166 +++++++++++++++++----- source/libs/catalog/test/catalogTests.cpp | 7 +- 4 files changed, 154 insertions(+), 46 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 3916898829..e39236ea76 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -50,6 +50,7 @@ typedef struct SCatalogCfg { uint32_t maxDBCacheNum; } SCatalogCfg; + int32_t catalogInit(SCatalogCfg *cfg); /** @@ -87,15 +88,28 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB */ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +/** + * Get a super table's meta data. + * @param pCatalog (input, got with catalogGetHandle) + * @param pTransporter (input, rpc object) + * @param pMgmtEps (input, mnode EPs) + * @param pTableName (input, table name, NOT including db name) + * @param pTableMeta(output, table meta data, NEED to free it by calller) + * @return error code + */ +int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); + + /** * Force renew a table's local cached meta data. * @param pCatalog (input, got with catalogGetHandle) * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) + * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @return error code */ -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName); +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable); /** * Force renew a table's local cached meta data and get the new one. @@ -104,9 +118,10 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, co * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) + * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @return error code */ -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable); /** diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index f426139c14..c4f2b54cf8 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -64,6 +64,14 @@ typedef struct SCatalogMgmt { typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); +#define CTG_IS_STABLE(isSTable) (1 == (isSTable)) +#define CTG_IS_NOT_STABLE(isSTable) (0 == (isSTable)) +#define CTG_IS_UNKNOWN_STABLE(isSTable) ((isSTable) < 0) +#define CTG_SET_STABLE(isSTable, tbType) do { (isSTable) = ((tbType) == TSDB_SUPER_TABLE) ? 1 : ((tbType) > TSDB_SUPER_TABLE ? 0 : -1); } while (0) +#define CTG_TBTYPE_MATCH(isSTable, tbType) (CTG_IS_UNKNOWN_STABLE(isSTable) || (CTG_IS_STABLE(isSTable) && (tbType) == TSDB_SUPER_TABLE) || (CTG_IS_NOT_STABLE(isSTable) && (tbType) != TSDB_SUPER_TABLE)) + +#define CTG_TABLE_NOT_EXIST(code) (code == TSDB_CODE_TDB_INVALID_TABLE_ID) + #define ctgFatal(...) do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgError(...) do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgWarn(...) do { if (ctgDebugFlag & DEBUG_WARN) { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }} while(0) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index abcfafa786..f7139f21b8 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -105,6 +105,8 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN } *exist = 1; + + tbMeta = *pTableMeta; if (tbMeta->tableType != TSDB_CHILD_TABLE) { return TSDB_CODE_SUCCESS; @@ -143,6 +145,29 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN return TSDB_CODE_SUCCESS; } +int32_t ctgGetTableTypeFromCache(struct SCatalog* pCatalog, const SName* pTableName, int32_t *tbType) { + if (NULL == pCatalog->tableCache.cache) { + return TSDB_CODE_SUCCESS; + } + + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); + + size_t sz = 0; + STableMeta *pTableMeta = NULL; + + taosHashGetCloneExt(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName), NULL, (void **)&pTableMeta, &sz); + + if (NULL == pTableMeta) { + return TSDB_CODE_SUCCESS; + } + + *tbType = pTableMeta->tableType; + + return TSDB_CODE_SUCCESS; +} + + void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) { epSet->inUse = 0; epSet->numOfEps = vgroupInfo->numOfEps; @@ -153,14 +178,7 @@ void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) { } } -int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMetaOutput* output) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == output) { - CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); - } - - char tbFullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(pTableName, tbFullName); - +int32_t ctgGetTableMetaFromMnodeImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, char* tbFullName, STableMetaOutput* output) { SBuildTableMetaInput bInput = {.vgId = 0, .dbName = NULL, .tableFullName = tbFullName}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; @@ -179,6 +197,12 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp); if (TSDB_CODE_SUCCESS != rpcRsp.code) { + if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) { + output->metaNum = 0; + ctgDebug("tbmeta:%s not exist in mnode", tbFullName); + return TSDB_CODE_SUCCESS; + } + ctgError("error rsp for table meta, code:%x", rpcRsp.code); CTG_ERR_RET(rpcRsp.code); } @@ -188,6 +212,13 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE return TSDB_CODE_SUCCESS; } +int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMetaOutput* output) { + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); + + return ctgGetTableMetaFromMnodeImpl(pCatalog, pRpc, pMgmtEps, tbFullName, output); +} + int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == vgroupInfo || NULL == output) { @@ -197,7 +228,7 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE char dbFullName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pTableName, dbFullName); - SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = pTableName->tname}; + SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = (char *)pTableName->tname}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; @@ -218,6 +249,12 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE rpcSendRecv(pRpc, &epSet, &rpcMsg, &rpcRsp); if (TSDB_CODE_SUCCESS != rpcRsp.code) { + if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) { + output->metaNum = 0; + ctgDebug("tbmeta:%s not exist in vnode", pTableName->tname); + return TSDB_CODE_SUCCESS; + } + ctgError("error rsp for table meta, code:%x", rpcRsp.code); CTG_ERR_RET(rpcRsp.code); } @@ -322,22 +359,28 @@ _return: CTG_RET(TSDB_CODE_SUCCESS); } -int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta) { +int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta, int32_t isSTable) { if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } int32_t exist = 0; - if (!forceUpdate) { + if (!forceUpdate) { CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); - if (exist) { + if (exist && CTG_TBTYPE_MATCH(isSTable, (*pTableMeta)->tableType)) { return TSDB_CODE_SUCCESS; } + } else if (CTG_IS_UNKNOWN_STABLE(isSTable)) { + int32_t tbType = 0; + + CTG_ERR_RET(ctgGetTableTypeFromCache(pCatalog, pTableName, &tbType)); + + CTG_SET_STABLE(isSTable, tbType); } - CTG_ERR_RET(catalogRenewTableMeta(pCatalog, pRpc, pMgmtEps, pTableName)); + CTG_ERR_RET(ctgRenewTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, isSTable)); CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); @@ -364,19 +407,27 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out } if (NULL == pCatalog->tableCache.cache) { - pCatalog->tableCache.cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->tableCache.cache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for tablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->tableCache.cache, NULL, cache)) { + taosHashCleanup(cache); + } } if (NULL == pCatalog->tableCache.stableCache) { - pCatalog->tableCache.stableCache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->tableCache.stableCache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for stablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->tableCache.stableCache, NULL, cache)) { + taosHashCleanup(cache); + } } if (output->metaNum == 2) { @@ -481,6 +532,50 @@ int32_t ctgValidateAndRemoveDb(struct SCatalog* pCatalog, const char* dbName, SD return TSDB_CODE_SUCCESS; } +int32_t ctgRenewTableMetaImpl(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable) { + if (NULL == pCatalog || NULL == pTransporter || NULL == pMgmtEps || NULL == pTableName) { + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + SVgroupInfo vgroupInfo = {0}; + int32_t code = 0; + + CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo)); + + STableMetaOutput voutput = {0}; + STableMetaOutput moutput = {0}; + STableMetaOutput *output = &voutput; + + if (CTG_IS_STABLE(isSTable)) { + CTG_ERR_JRET(ctgGetTableMetaFromMnode(pCatalog, pTransporter, pMgmtEps, pTableName, &moutput)); + + if (0 == moutput.metaNum) { + CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &voutput)); + } else { + output = &moutput; + } + } else { + CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &voutput)); + + if (voutput.metaNum > 0 && TSDB_SUPER_TABLE == voutput.tbMeta->tableType) { + CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCatalog, pTransporter, pMgmtEps, voutput.tbFname, &moutput)); + + tfree(voutput.tbMeta); + voutput.tbMeta = moutput.tbMeta; + moutput.tbMeta = NULL; + } + } + + CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, output)); + +_return: + + tfree(voutput.tbMeta); + tfree(moutput.tbMeta); + + CTG_RET(code); +} + int32_t catalogInit(SCatalogCfg *cfg) { if (ctgMgmt.pCluster) { @@ -643,11 +738,15 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB } if (NULL == pCatalog->dbCache.cache) { - pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->dbCache.cache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER); CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->dbCache.cache, NULL, cache)) { + taosHashCleanup(cache); + } } else { CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo)); } @@ -672,34 +771,23 @@ _return: } int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta); + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta, -1); } -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName) { +int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta, 1); +} + +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable) { if (NULL == pCatalog || NULL == pTransporter || NULL == pMgmtEps || NULL == pTableName) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } - SVgroupInfo vgroupInfo = {0}; - int32_t code = 0; - - CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo)); - - STableMetaOutput output = {0}; - - CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &output)); - - //CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); - - CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output)); - -_return: - tfree(output.tbMeta); - CTG_RET(code); + return ctgRenewTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, isSTable); } -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, true, pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, true, pTableMeta, isSTable); } int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList) { diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 1d8a48dfcb..4fc53e5f18 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -45,7 +45,7 @@ void ctgTestSetPrepareSTableMeta(); bool ctgTestStop = false; bool ctgTestEnableSleep = false; -bool ctgTestDeadLoop = true; +bool ctgTestDeadLoop = false; int32_t ctgTestCurrentVgVersion = 0; int32_t ctgTestVgVersion = 1; @@ -600,7 +600,6 @@ void *ctgTestSetCtableMetaThread(void *param) { } -#if 0 TEST(tableMeta, normalTable) { struct SCatalog* pCtg = NULL; @@ -768,7 +767,7 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); tableMeta = NULL; - code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 9); ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); @@ -999,8 +998,6 @@ TEST(multiThread, getSetDbVgroupCase) { catalogDestroy(); } -#endif - TEST(multiThread, ctableMeta) { struct SCatalog* pCtg = NULL; From 3bd42107652d23ae7a110442ef4595db30ea979e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 01:31:13 -0800 Subject: [PATCH 78/86] When an error occurs in rollback or retry, the failed result is returned first --- include/dnode/mnode/sdb/sdb.h | 1 + source/dnode/mnode/impl/inc/mndTrans.h | 1 + source/dnode/mnode/impl/src/mndBnode.c | 111 ++++++------ source/dnode/mnode/impl/src/mndQnode.c | 111 ++++++------ source/dnode/mnode/impl/src/mndSnode.c | 109 ++++++------ source/dnode/mnode/impl/src/mndTrans.c | 43 +++-- source/dnode/mnode/impl/test/bnode/bnode.cpp | 168 +++++++++++++++++-- source/dnode/mnode/impl/test/qnode/qnode.cpp | 146 +++++++++++++++- source/dnode/mnode/impl/test/snode/snode.cpp | 168 +++++++++++++++++-- source/dnode/mnode/sdb/src/sdbHash.c | 4 + 10 files changed, 655 insertions(+), 207 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 497da71c13..c7198eee6f 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -94,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw; typedef struct SSdbRow SSdbRow; typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType; typedef enum { + SDB_STATUS_INIT = 0, SDB_STATUS_CREATING = 1, SDB_STATUS_UPDATING = 2, SDB_STATUS_DROPPING = 3, diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index bd053d91b6..fda3fed13d 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -28,6 +28,7 @@ typedef struct { int8_t msgSent; int8_t msgReceived; int32_t errCode; + int32_t acceptableCode; int32_t contLen; void *pCont; } STransAction; diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 312438a535..14d49213e9 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -59,9 +59,8 @@ int32_t mndInitBnode(SMnode *pMnode) { void mndCleanupBnode(SMnode *pMnode) {} static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) { - SSdb *pSdb = pMnode->pSdb; - SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &bnodeId); - if (pObj == NULL) { + SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; } return pObj; @@ -169,6 +168,14 @@ static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) { return 0; } +static int32_t mndSetCreateBnodeUndoLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndBnodeActionEncode(pObj); + 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 mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -190,6 +197,7 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.pCont = pMsg; action.contLen = sizeof(SDCreateBnodeReq); action.msgType = TDMT_DND_CREATE_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -199,39 +207,47 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } +static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { + SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropBnodeReq); + action.msgType = TDMT_DND_DROP_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; + + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { + int32_t code = -1; + SBnodeObj bnodeObj = {0}; bnodeObj.id = pDnode->id; bnodeObj.createdTime = taosGetTimestampMs(); bnodeObj.updateTime = bnodeObj.createdTime; - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_BNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + if (pTrans == NULL) goto CREATE_BNODE_OVER; + mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId); - - if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } - - if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } - - if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } + if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeUndoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeUndoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_BNODE_OVER; code = 0; @@ -254,6 +270,9 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST; mndReleaseBnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_BNODE_NOT_EXIST) { + mError("bnode:%d, failed to create bnode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); @@ -303,6 +322,7 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn action.pCont = pMsg; action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -314,33 +334,15 @@ static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBn static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) { int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("bnode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_BNODE_OVER; - } + if (pTrans == NULL) goto DROP_BNODE_OVER; mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id); - - if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } + if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER; + if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER; + if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_BNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_BNODE_OVER; code = 0; @@ -364,8 +366,7 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("bnode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; + mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 5ff3a79040..6951aa8717 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -59,9 +59,8 @@ int32_t mndInitQnode(SMnode *pMnode) { void mndCleanupQnode(SMnode *pMnode) {} static SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId) { - SSdb *pSdb = pMnode->pSdb; - SQnodeObj *pObj = sdbAcquire(pSdb, SDB_QNODE, &qnodeId); - if (pObj == NULL) { + SQnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_QNODE, &qnodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_QNODE_NOT_EXIST; } return pObj; @@ -169,6 +168,14 @@ static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) { return 0; } +static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj); + 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 mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -190,6 +197,7 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.pCont = pMsg; action.contLen = sizeof(SDCreateQnodeReq); action.msgType = TDMT_DND_CREATE_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -199,39 +207,47 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } +static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { + SDDropQnodeReq *pMsg = malloc(sizeof(SDDropQnodeReq)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropQnodeReq); + action.msgType = TDMT_DND_DROP_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; + + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { + int32_t code = -1; + SQnodeObj qnodeObj = {0}; qnodeObj.id = pDnode->id; qnodeObj.createdTime = taosGetTimestampMs(); qnodeObj.updateTime = qnodeObj.createdTime; - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_QNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + if (pTrans == NULL) goto CREATE_QNODE_OVER; + mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); - - if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } - - if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } - - if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } + if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_QNODE_OVER; code = 0; @@ -254,6 +270,9 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST; mndReleaseQnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) { + mError("qnode:%d, failed to create qnode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); @@ -303,6 +322,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn action.pCont = pMsg; action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -314,33 +334,15 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) { int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("qnode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_QNODE_OVER; - } + if (pTrans == NULL) goto DROP_QNODE_OVER; mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); - - if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } - - if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } - - if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } + if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER; + if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER; + if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_QNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_QNODE_OVER; code = 0; @@ -364,8 +366,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("qnode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_QNODE_NOT_EXIST; + mError("qnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 5d13211380..7221a2fbf4 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -59,9 +59,8 @@ int32_t mndInitSnode(SMnode *pMnode) { void mndCleanupSnode(SMnode *pMnode) {} static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { - SSdb *pSdb = pMnode->pSdb; - SSnodeObj *pObj = sdbAcquire(pSdb, SDB_SNODE, &snodeId); - if (pObj == NULL) { + SSnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_SNODE, &snodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; } return pObj; @@ -169,6 +168,14 @@ static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { return 0; } +static int32_t mndSetCreateSnodeUndoLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndSnodeActionEncode(pObj); + 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 mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -190,6 +197,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S action.pCont = pMsg; action.contLen = sizeof(SDCreateSnodeReq); action.msgType = TDMT_DND_CREATE_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -199,39 +207,48 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S return 0; } +static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + SDDropSnodeReq *pMsg = malloc(sizeof(SDDropSnodeReq)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropSnodeReq); + action.msgType = TDMT_DND_DROP_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { + int32_t code = -1; + SSnodeObj snodeObj = {0}; snodeObj.id = pDnode->id; snodeObj.createdTime = taosGetTimestampMs(); snodeObj.updateTime = snodeObj.createdTime; - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_SNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + if (pTrans == NULL) goto CREATE_SNODE_OVER; + mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); - if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } - - if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } - - if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } + if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeUndoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_SNODE_OVER; code = 0; @@ -254,6 +271,9 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; mndReleaseSnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) { + mError("snode:%d, failed to create snode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); @@ -303,6 +323,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn action.pCont = pMsg; action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); @@ -314,33 +335,16 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) { int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_SNODE_OVER; - } + if (pTrans == NULL) goto DROP_SNODE_OVER; mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } - - if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } - - if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } + if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER; + if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER; + if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_SNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_SNODE_OVER; code = 0; @@ -364,8 +368,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("snode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; + mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 82fe296166..c1686c2923 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -143,6 +143,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { STransAction *pAction = taosArrayGet(pTrans->redoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) } @@ -151,6 +152,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { STransAction *pAction = taosArrayGet(pTrans->undoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) } @@ -253,6 +255,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < redoActionNum; ++i) { SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); if (action.pCont == NULL) goto TRANS_DECODE_OVER; @@ -264,6 +267,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < undoActionNum; ++i) { SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); if (action.pCont == NULL) goto TRANS_DECODE_OVER; @@ -496,16 +500,32 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { } static void mndTransSendRpcRsp(STrans *pTrans) { - if (pTrans->stage == TRN_STAGE_FINISHED || pTrans->stage == TRN_STAGE_UNDO_LOG || - pTrans->stage == TRN_STAGE_UNDO_ACTION || pTrans->stage == TRN_STAGE_ROLLBACK) { - if (pTrans->rpcHandle != NULL) { - mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, - pTrans->rpcAHandle); - SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; - rpcSendResponse(&rspMsg); - pTrans->rpcHandle = NULL; + bool sendRsp = false; + + if (pTrans->stage == TRN_STAGE_FINISHED) { + sendRsp = true; + } + + if (pTrans->policy == TRN_POLICY_ROLLBACK) { + if (pTrans->stage == TRN_STAGE_UNDO_LOG || pTrans->stage == TRN_STAGE_UNDO_ACTION || + pTrans->stage == TRN_STAGE_ROLLBACK) { + sendRsp = true; } } + + if (pTrans->policy == TRN_POLICY_RETRY) { + if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 0) { + sendRsp = true; + } + } + + if (sendRsp && pTrans->rpcHandle != NULL) { + mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, + pTrans->rpcAHandle); + SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; + rpcSendResponse(&rspMsg); + pTrans->rpcHandle = NULL; + } } void mndTransProcessRsp(SMnodeMsg *pMsg) { @@ -547,7 +567,8 @@ void mndTransProcessRsp(SMnodeMsg *pMsg) { pAction->errCode = pMsg->rpcMsg.code; } - mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->rpcMsg.code); + mDebug("trans:%d, action:%d response is received, code:0x%x, accept:0x%x", transId, action, pMsg->rpcMsg.code, + pAction->acceptableCode); mndTransExecute(pMnode, pTrans); HANDLE_ACTION_RSP_OVER: @@ -647,7 +668,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA if (pAction == NULL) continue; if (pAction->msgSent && pAction->msgReceived) { numOfReceived++; - if (pAction->errCode != 0) { + if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) { errCode = pAction->errCode; } } @@ -695,7 +716,7 @@ static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans) { } else { pTrans->code = terrno; pTrans->stage = TRN_STAGE_UNDO_LOG; - mError("trans:%d, stage from redoLog to undoLog", pTrans->id); + mError("trans:%d, stage from redoLog to undoLog since %s", pTrans->id, terrstr()); } return continueExec; diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index fa06d9ac69..07dc163df5 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -50,7 +50,18 @@ TEST_F(MndTestBnode, 01_Show_Bnode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { +TEST_F(MndTestBnode, 02_Create_Bnode) { + { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + { int32_t contLen = sizeof(SMCreateBnodeReq); @@ -63,11 +74,6 @@ TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -75,24 +81,21 @@ TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) { CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } -} -TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateBnodeReq); SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); + pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST); } } -TEST_F(MndTestBnode, 04_Create_Bnode) { +TEST_F(MndTestBnode, 03_Drop_Bnode) { { - // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); @@ -110,7 +113,6 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { } { - // create bnode int32_t contLen = sizeof(SMCreateBnodeReq); SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); @@ -133,7 +135,6 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { } { - // drop bnode int32_t contLen = sizeof(SMDropBnodeReq); SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); @@ -151,4 +152,143 @@ TEST_F(MndTestBnode, 04_Create_Bnode) { CheckBinary("localhost:9018", TSDB_EP_LEN); CheckTimestamp(); } + + { + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_BNODE_NOT_EXIST); + } +} + +TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, bnode is creating + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, bnode is creating + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, bnode is dropping + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, bnode is dropping + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } } \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index 3fdd5315a4..612b138ccc 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -90,13 +90,12 @@ TEST_F(MndTestQnode, 02_Create_Qnode) { SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_QNODE_ALREADY_EXIST); } } -TEST_F(MndTestQnode, 04_Create_Qnode) { +TEST_F(MndTestQnode, 03_Drop_Qnode) { { - // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); @@ -114,7 +113,6 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { } { - // create qnode int32_t contLen = sizeof(SMCreateQnodeReq); SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); @@ -137,7 +135,6 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { } { - // drop qnode int32_t contLen = sizeof(SMDropQnodeReq); SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); @@ -155,4 +152,143 @@ TEST_F(MndTestQnode, 04_Create_Qnode) { CheckBinary("localhost:9014", TSDB_EP_LEN); CheckTimestamp(); } + + { + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_QNODE_NOT_EXIST); + } +} + +TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, qnode is creating + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, qnode is creating + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, qnode is dropping + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, qnode is dropping + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } } \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index 4819bc556c..cebb5fe113 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -50,7 +50,18 @@ TEST_F(MndTestSnode, 01_Show_Snode) { EXPECT_EQ(test.GetShowRows(), 0); } -TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { +TEST_F(MndTestSnode, 02_Create_Snode) { + { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + { int32_t contLen = sizeof(SMCreateSnodeReq); @@ -63,11 +74,6 @@ TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); CHECK_META("show snodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -75,24 +81,21 @@ TEST_F(MndTestSnode, 02_Create_Snode_Invalid_Id) { CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } -} -TEST_F(MndTestSnode, 03_Create_Snode_Invalid_Id) { { int32_t contLen = sizeof(SMCreateSnodeReq); SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); + pReq->dnodeId = htonl(1); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_SNODE_ALREADY_EXIST); } } -TEST_F(MndTestSnode, 04_Create_Snode) { +TEST_F(MndTestSnode, 03_Drop_Snode) { { - // create dnode int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); @@ -110,7 +113,6 @@ TEST_F(MndTestSnode, 04_Create_Snode) { } { - // create snode int32_t contLen = sizeof(SMCreateSnodeReq); SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); @@ -133,7 +135,6 @@ TEST_F(MndTestSnode, 04_Create_Snode) { } { - // drop snode int32_t contLen = sizeof(SMDropSnodeReq); SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); @@ -151,4 +152,143 @@ TEST_F(MndTestSnode, 04_Create_Snode) { CheckBinary("localhost:9016", TSDB_EP_LEN); CheckTimestamp(); } + + { + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_SNODE_NOT_EXIST); + } +} + +TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, snode is creating + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, snode is creating + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, snode is dropping + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, snode is dropping + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + if (pMsg->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 733075757f..13b2c7daa5 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -69,6 +69,8 @@ static const char *sdbStatusStr(ESdbStatus status) { return "ready"; case SDB_STATUS_DROPPED: return "dropped"; + case SDB_STATUS_INIT: + return "init"; default: return "undefine"; } @@ -261,6 +263,8 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) { } void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { + terrno = 0; + SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return NULL; From 7916c1e6221c1f8e3398b30d389493f7018e52d5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 5 Jan 2022 17:49:15 +0800 Subject: [PATCH 79/86] [td-11818] fix memory leak and refactor. --- source/client/src/clientEnv.c | 6 +- source/client/src/clientImpl.c | 1 - source/client/test/clientTests.cpp | 339 +++++++++++++------------ source/libs/parser/inc/astToMsg.h | 2 +- source/libs/parser/inc/parserInt.h | 8 - source/libs/parser/inc/sql.y | 16 +- source/libs/parser/src/astGenerator.c | 16 +- source/libs/parser/src/astToMsg.c | 27 +- source/libs/parser/src/dCDAstProcess.c | 160 ++++++++---- source/libs/parser/src/parser.c | 20 +- source/libs/parser/src/sql.c | 16 +- 11 files changed, 335 insertions(+), 276 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 99a0d50fdb..0e3afb60c0 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -423,7 +423,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { *+------------+-----+-----------+---------------+ *| uid|localIp| PId | timestamp | serial number | *+------------+-----+-----------+---------------+ - *| 16bit |12bit|20bit |16bit | + *| 12bit |12bit|24bit |16bit | *+------------+-----+-----------+---------------+ * @return */ @@ -443,11 +443,11 @@ uint64_t generateRequestId() { } } - int64_t ts = taosGetTimestampUs(); + int64_t ts = taosGetTimestampMs(); uint64_t pid = taosGetPId(); int32_t val = atomic_add_fetch_32(&requestSerialId, 1); - uint64_t id = ((hashId & 0xFFFF) << 48) | ((pid & 0x0FFF) << 36) | ((ts & 0xFFFFF) << 16) | (val & 0xFFFF); + uint64_t id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF); return id; } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 2bc276b0af..a416033946 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -540,7 +540,6 @@ void* doFetchRow(SRequestObj* pRequest) { asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(body); pResultInfo->current = 0; if (pResultInfo->numOfRows <= pResultInfo->current) { diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index e6759115ed..ef2dcc21df 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -57,96 +57,96 @@ TEST(testCase, connect_Test) { taos_close(pConn); } -//TEST(testCase, create_user_Test) { -// TAOS* pConn = taos_connect("localhost", "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("localhost", "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("localhost", "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("localhost", "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_free_result(pRes); -// taos_close(pConn); -//} -// -//TEST(testCase, drop_user_Test) { -// TAOS* pConn = taos_connect("localhost", "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("localhost", "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); -//} +TEST(testCase, create_user_Test) { + TAOS* pConn = taos_connect("localhost", "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("localhost", "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("localhost", "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("localhost", "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_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, drop_user_Test) { + TAOS* pConn = taos_connect("localhost", "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("localhost", "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); +} TEST(testCase, create_db_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -172,61 +172,61 @@ TEST(testCase, create_db_Test) { taos_close(pConn); } -//TEST(testCase, create_dnode_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); -// if (taos_errno(pRes) != 0) { -// printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); -// if (taos_errno(pRes) != 0) { -// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// taos_close(pConn); -//} +TEST(testCase, create_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); -//TEST(testCase, drop_dnode_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); -// if (taos_errno(pRes) != 0) { -// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -//TEST(testCase, use_db_test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_close(pConn); -//} + TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); + if (taos_errno(pRes) != 0) { + printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); + if (taos_errno(pRes) != 0) { + printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + taos_close(pConn); +} + +TEST(testCase, drop_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); + if (taos_errno(pRes) != 0) { + printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, use_db_test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_close(pConn); +} //TEST(testCase, drop_db_test) { //// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -281,18 +281,18 @@ TEST(testCase, create_db_Test) { taos_close(pConn); } -//TEST(testCase, create_table_Test) { -// // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// // assert(pConn != NULL); -// // -// // TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// // taos_free_result(pRes); -// // -// // pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); -// // taos_free_result(pRes); -// // -// // taos_close(pConn); -//} +TEST(testCase, create_table_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); + taos_free_result(pRes); + + taos_close(pConn); +} //TEST(testCase, create_ctable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -518,18 +518,21 @@ TEST(testCase, create_multiple_tables) { taos_close(pConn); } -//TEST(testCase, generated_request_id_test) { -// SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); -// -//// for(int32_t i = 0; i < 1000000; ++i) { -//// uint64_t v = generateRequestId(); -//// void* result = taosHashGet(phash, &v, sizeof(v)); -//// ASSERT_EQ(result, nullptr); -//// taosHashPut(phash, &v, sizeof(v), NULL, 0); -//// } -// -// taosHashCleanup(phash); -//} +TEST(testCase, generated_request_id_test) { + SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + + for(int32_t i = 0; i < 50000000; ++i) { + uint64_t v = generateRequestId(); + void* result = taosHashGet(phash, &v, sizeof(v)); + if (result != nullptr) { + printf("0x%"PRIx64", index:%d\n", v, i); + } + assert(result == nullptr); + taosHashPut(phash, &v, sizeof(v), NULL, 0); + } + + taosHashCleanup(phash); +} //TEST(testCase, projection_query_tables) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 30919d25dd..153bb43ba0 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -10,7 +10,7 @@ SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); -SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SCreateStbMsg* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index d1629a2a3e..d18934d5f5 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -38,14 +38,6 @@ typedef struct SMsgBuf { char *buf; } SMsgBuf; -// create table operation type -enum TSQL_CREATE_TABLE_TYPE { - TSQL_CREATE_TABLE = 0x1, - TSQL_CREATE_STABLE = 0x2, - TSQL_CREATE_CTABLE = 0x3, - TSQL_CREATE_STREAM = 0x4, -}; - void clearTableMetaInfo(STableMetaInfo* pTableMetaInfo); void clearAllTableMetaInfo(SQueryStmtInfo* pQueryInfo, bool removeMeta, uint64_t id); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index c6e1c004e3..6e91ad997c 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -370,7 +370,7 @@ create_table_list(A) ::= create_from_stable(Z). { pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); taosArrayPush(pCreateTable->childTableInfo, &Z); - pCreateTable->type = TSQL_CREATE_CTABLE; + pCreateTable->type = TSDB_SQL_CREATE_TABLE; A = pCreateTable; } @@ -381,7 +381,7 @@ create_table_list(A) ::= create_table_list(X) create_from_stable(Z). { %type create_table_args{SCreateTableSql*} create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { - A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE); + A = tSetCreateTableInfo(X, NULL, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); V.n += Z.n; @@ -391,7 +391,7 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { // create super table %type create_stable_args{SCreateTableSql*} create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. { - A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE); + A = tSetCreateTableInfo(X, Y, NULL, TSDB_SQL_CREATE_STABLE); setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_STABLE); V.n += Z.n; @@ -421,11 +421,11 @@ tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(STo // create stream // create table table_name as select count(*) from super_table_name interval(time) create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). { - A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); - - V.n += Z.n; - setCreatedTableName(pInfo, &V, &U); +// A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM); +// setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); +// +// V.n += Z.n; +// setCreatedTableName(pInfo, &V, &U); } %type column{SField} diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 288d6296fa..0cb3cea95f 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -579,25 +579,21 @@ SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSe SCreateTableSql *pCreate = calloc(1, sizeof(SCreateTableSql)); switch (type) { - case TSQL_CREATE_TABLE: { + case TSDB_SQL_CREATE_TABLE: { pCreate->colInfo.pColumns = pCols; assert(pTags == NULL); break; } - case TSQL_CREATE_STABLE: { + case TSDB_SQL_CREATE_STABLE: { pCreate->colInfo.pColumns = pCols; pCreate->colInfo.pTagColumns = pTags; assert(pTags != NULL && pCols != NULL); break; } - case TSQL_CREATE_STREAM: { - pCreate->pSelect = pSelect; - break; - } - - case TSQL_CREATE_CTABLE: { - assert(0); - } +// case TSQL_CREATE_STREAM: { +// pCreate->pSelect = pSelect; +// break; +// } default: assert(false); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 981eac1266..2ef6d4acec 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -230,7 +230,7 @@ SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCt return pCreateMsg; } -SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { +SCreateStbMsg* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { SSchema* pSchema; int32_t numOfTags = 0; @@ -239,16 +239,16 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le numOfTags = (int32_t) taosArrayGetSize(pCreateTableSql->colInfo.pTagColumns); } - SCreateStbMsg* pCreateTableMsg = (SCreateStbMsg*)calloc(1, sizeof(SCreateStbMsg) + (numOfCols + numOfTags) * sizeof(SSchema)); + SCreateStbMsg* pCreateStbMsg = (SCreateStbMsg*)calloc(1, sizeof(SCreateStbMsg) + (numOfCols + numOfTags) * sizeof(SSchema)); char* pMsg = NULL; +#if 0 int32_t tableType = pCreateTableSql->type; if (tableType != TSQL_CREATE_TABLE && tableType != TSQL_CREATE_STABLE) { // create by using super table, tags value -#if 0 SArray* list = pInfo->pCreateTableInfo->childTableInfo; int32_t numOfTables = (int32_t)taosArrayGetSize(list); - pCreateTableMsg->numOfTables = htonl(numOfTables); + pCreateStbMsg->numOfTables = htonl(numOfTables); pMsg = (char*)pCreateMsg; for (int32_t i = 0; i < numOfTables; ++i) { @@ -268,25 +268,27 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le int32_t len = (int32_t)(pMsg - (char*)pCreate); pCreate->len = htonl(len); } + + } else { #endif - } else { // create (super) table + // create (super) table SName n = {0}; int32_t code = createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf); if (code != 0) { return NULL; } - code = tNameExtractFullName(&n, pCreateTableMsg->name); + code = tNameExtractFullName(&n, pCreateStbMsg->name); if (code != 0) { buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified"); return NULL; } - pCreateTableMsg->igExists = pCreateTableSql->existCheck ? 1 : 0; - pCreateTableMsg->numOfColumns = htonl(numOfCols); - pCreateTableMsg->numOfTags = htonl(numOfTags); + pCreateStbMsg->igExists = pCreateTableSql->existCheck ? 1 : 0; + pCreateStbMsg->numOfColumns = htonl(numOfCols); + pCreateStbMsg->numOfTags = htonl(numOfTags); - pSchema = (SSchema*) pCreateTableMsg->pSchema; + pSchema = (SSchema*)pCreateStbMsg->pSchema; for (int i = 0; i < numOfCols; ++i) { SField* pField = taosArrayGet(pCreateTableSql->colInfo.pColumns, i); pSchema->type = pField->type; @@ -306,12 +308,11 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le } pMsg = (char*)pSchema; - } - int32_t msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); + int32_t msgLen = (int32_t)(pMsg - (char*)pCreateStbMsg); *len = msgLen; - return pCreateTableMsg; + return pCreateStbMsg; } SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index d9bfb86028..c9d157e6a2 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -1,10 +1,12 @@ -#include "tmsg.h" -#include "ttime.h" +#include +#include #include "astToMsg.h" #include "parserInt.h" #include "parserUtil.h" #include "queryInfoUtil.h" #include "tglobal.h" +#include "tmsg.h" +#include "ttime.h" /* is contained in pFieldList or not */ static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { @@ -291,11 +293,9 @@ static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf); } -int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { +int32_t doCheckForCreateTable(SCreateTableSql* pCreateTable, SMsgBuf* pMsgBuf) { const char* msg1 = "invalid table name"; - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - SArray* pFieldList = pCreateTable->colInfo.pColumns; SArray* pTagList = pCreateTable->colInfo.pTagColumns; assert(pFieldList != NULL); @@ -374,20 +374,25 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { for(int32_t i = 0; i < size; ++i) { SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); tfree(pTableReq->name); - tfree(pTableReq->ctbCfg.pTag); + + if (pTableReq->type == TSDB_NORMAL_TABLE) { + tfree(pTableReq->ntbCfg.pSchema); + } else if (pTableReq->type == TSDB_CHILD_TABLE) { + tfree(pTableReq->ctbCfg.pTag); + } else { + assert(0); + } } taosArrayDestroy(pTbBatch->req.pArray); } -int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { +static int32_t doCheckAndBuildCreateCTableReq(SCreateTableSql* pCreateTable, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, SArray** pBufArray) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; const char* msg3 = "tag value too long"; const char* msg4 = "illegal value or data overflow"; - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); // super table name, create table by using dst @@ -545,6 +550,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return code; } + // Find a appropriate vgroup to accommodate this table , according to the table name SVgroupInfo info = {0}; catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); @@ -552,16 +558,103 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p tfree(pSuperTableMeta); } - SArray *pBufArray = doSerializeVgroupCreateTableInfo(pVgroupHashmap); + *pBufArray = doSerializeVgroupCreateTableInfo(pVgroupHashmap); + + taosHashCleanup(pVgroupHashmap); + return TSDB_CODE_SUCCESS; +} + +static int32_t serializeVgroupTablesBatchImpl(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) { + int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); + void* buf = malloc(tlen); + if (buf == NULL) { + // TODO: handle error + } + + ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); + ((SMsgHead*)buf)->contLen = htonl(tlen); + + void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); + + SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); + pVgData->vg = pTbBatch->info; + pVgData->pData = buf; + pVgData->size = tlen; + pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); + + taosArrayPush(pBufArray, &pVgData); +} + +static int32_t doBuildSingleTableBatchReq(SName* pTableName, SArray* pColumns, SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) { + struct SVCreateTbReq req = {0}; + req.type = TD_NORMAL_TABLE; + req.name = strdup(tNameGetTableName(pTableName)); + + req.ntbCfg.nCols = taosArrayGetSize(pColumns); + int32_t num = req.ntbCfg.nCols; + + req.ntbCfg.pSchema = calloc(num, sizeof(SSchema)); + for(int32_t i = 0; i < num; ++i) { + SSchema* pSchema = taosArrayGet(pColumns, i); + memcpy(&req.ntbCfg.pSchema[i], pSchema, sizeof(SSchema)); + } + + pBatch->info = *pVgroupInfo; + pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); + if (pBatch->req.pArray == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + taosArrayPush(pBatch->req.pArray, &req); + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckAndBuildCreateTableReq(SCreateTableSql* pCreateTable, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { + SArray* pBufArray = NULL; + + // it is a sql statement to create a normal table + if (pCreateTable->childTableInfo == NULL) { + assert(taosArrayGetSize(pCreateTable->colInfo.pColumns) > 0 && pCreateTable->colInfo.pTagColumns == NULL); + int32_t code = doCheckForCreateTable(pCreateTable, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + SName tableName = {0}; + code = createSName(&tableName, &pCreateTable->name, pCtx, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); + + SVgroupTablesBatch tbatch = {0}; + code = doBuildSingleTableBatchReq(&tableName, pCreateTable->colInfo.pColumns, &info, &tbatch); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + pBufArray = taosArrayInit(1, POINTER_BYTES); + if (pBufArray == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + serializeVgroupTablesBatchImpl(&tbatch, pBufArray); + destroyCreateTbReqBatch(&tbatch); + + } else { // it is a child table, created according to a super table + doCheckAndBuildCreateCTableReq(pCreateTable, pCtx, pMsgBuf, &pBufArray); + } SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo)); pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; pStmtInfo->pDataBlocks = pBufArray; - + *pOutput = (char*) pStmtInfo; *len = sizeof(SVnodeModifOpStmtInfo); - taosHashCleanup(pVgroupHashmap); return TSDB_CODE_SUCCESS; } @@ -575,27 +668,10 @@ SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap) { break; } - int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); - void* buf = malloc(tlen); - if (buf == NULL) { - // TODO: handle error - } - - ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); - ((SMsgHead*)buf)->contLen = htonl(tlen); - - void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); - - SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); - pVgData->vg = pTbBatch->info; - pVgData->pData = buf; - pVgData->size = tlen; - pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); - - taosArrayPush(pBufArray, &pVgData); + /*int32_t code = */serializeVgroupTablesBatchImpl(pTbBatch, pBufArray); destroyCreateTbReqBatch(pTbBatch); } while (true); + return pBufArray; } @@ -805,21 +881,13 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c case TSDB_SQL_CREATE_STABLE: { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - assert(pCreateTable->type != TSQL_CREATE_CTABLE); - - if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { - if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { - terrno = code; - goto _error; - } - - pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); - pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; - } else if (pCreateTable->type == TSQL_CREATE_STREAM) { - // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { - // return code; + if ((code = doCheckForCreateTable(pCreateTable, pMsgBuf)) != TSDB_CODE_SUCCESS) { + terrno = code; + goto _error; } + pDcl->pMsg = (char*)buildCreateStbMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->msgType = TDMT_MND_CREATE_STB; break; } @@ -867,7 +935,7 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - assert(pCreateTable->type == TSQL_CREATE_CTABLE); + assert(pCreateTable->type == TSDB_SQL_CREATE_TABLE); SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf* pMsgBuf = &m; @@ -875,7 +943,7 @@ SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBas SVnodeModifOpStmtInfo* pModifSqlStmt = NULL; int32_t msgLen = 0; - int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pModifSqlStmt, &msgLen); + int32_t code = doCheckAndBuildCreateTableReq(pCreateTable, pCtx, pMsgBuf, (char**) &pModifSqlStmt, &msgLen); if (code != TSDB_CODE_SUCCESS) { tfree(pModifSqlStmt); return NULL; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index bdb3dcd3e3..85a8d9e047 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -44,21 +44,21 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (!isDqlSqlStatement(&info)) { - bool toVnode = false; +// bool toVnode = false; if (info.type == TSDB_SQL_CREATE_TABLE) { - SCreateTableSql* pCreateSql = info.pCreateTableInfo; - if (pCreateSql->type == TSQL_CREATE_CTABLE || pCreateSql->type == TSQL_CREATE_TABLE) { - toVnode = true; - } - } +// SCreateTableSql* pCreateSql = info.pCreateTableInfo; +// if (pCreateSql->type == TSQL_CREATE_CTABLE || pCreateSql->type == TSQL_CREATE_TABLE) { +// toVnode = true; +// } +// } - if (toVnode) { - SVnodeModifOpStmtInfo *pInsertInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); - if (pInsertInfo == NULL) { +// if (toVnode) { + SVnodeModifOpStmtInfo * pModifStmtInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); + if (pModifStmtInfo == NULL) { return terrno; } - *pQuery = (SQueryNode*) pInsertInfo; + *pQuery = (SQueryNode*)pModifStmtInfo; } else { SDclStmtInfo* pDcl = qParserValidateDclSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); if (pDcl == NULL) { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index d265031a81..a6537998f7 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -2642,7 +2642,7 @@ static void yy_reduce( pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy150); - pCreateTable->type = TSQL_CREATE_CTABLE; + pCreateTable->type = TSDB_SQL_CREATE_TABLE; yylhsminor.yy326 = pCreateTable; } yymsp[0].minor.yy326 = yylhsminor.yy326; @@ -2656,7 +2656,7 @@ static void yy_reduce( break; case 140: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2666,7 +2666,7 @@ static void yy_reduce( break; case 141: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSQL_CREATE_STABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSDB_SQL_CREATE_STABLE); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_STABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; @@ -2700,11 +2700,11 @@ static void yy_reduce( break; case 146: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); - - yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; - setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); +// yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); +// setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); +// +// yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; +// setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } yymsp[-4].minor.yy326 = yylhsminor.yy326; break; From 69349c38d47f20e707329073f37eed60d581d31e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 02:08:56 -0800 Subject: [PATCH 80/86] fix gtest errors --- source/dnode/mgmt/impl/test/profile/profile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 77122d1bb9..b705a94af6 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -17,15 +17,15 @@ class DndTestProfile : public ::testing::Test { static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; + static int32_t connId; public: void SetUp() override {} void TearDown() override {} - - int32_t connId; }; Testbase DndTestProfile::test; +int32_t DndTestProfile::connId; TEST_F(DndTestProfile, 01_ConnectMsg) { int32_t contLen = sizeof(SConnectMsg); From fdca2ec4bfc1ce0f868a405dbae337533e9fc33a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 02:18:47 -0800 Subject: [PATCH 81/86] minor changes --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 - .../mgmt/impl/test/cluster/CMakeLists.txt | 11 ----- .../dnode/mgmt/impl/test/cluster/cluster.cpp | 41 ------------------- .../impl/test/show/CMakeLists.txt | 0 .../{mgmt => mnode}/impl/test/show/show.cpp | 0 5 files changed, 54 deletions(-) delete mode 100644 source/dnode/mgmt/impl/test/cluster/CMakeLists.txt delete mode 100644 source/dnode/mgmt/impl/test/cluster/cluster.cpp rename source/dnode/{mgmt => mnode}/impl/test/show/CMakeLists.txt (100%) rename source/dnode/{mgmt => mnode}/impl/test/show/show.cpp (100%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index da043f8fe2..b13edf7d5a 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -6,13 +6,11 @@ add_subdirectory(snode) # add_subdirectory(auth) # add_subdirectory(balance) -add_subdirectory(cluster) add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) add_subdirectory(mnode) add_subdirectory(profile) -add_subdirectory(show) add_subdirectory(stb) # add_subdirectory(sync) # add_subdirectory(telem) diff --git a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt b/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt deleted file mode 100644 index a63f3106e6..0000000000 --- a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -aux_source_directory(. CLUSTER_SRC) -add_executable(dnode_test_cluster ${CLUSTER_SRC}) -target_link_libraries( - dnode_test_cluster - PUBLIC sut -) - -add_test( - NAME dnode_test_cluster - COMMAND dnode_test_cluster -) diff --git a/source/dnode/mgmt/impl/test/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp deleted file mode 100644 index 7d9bff7b23..0000000000 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file cluster.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module cluster-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "sut.h" - -class DndTestCluster : public ::testing::Test { - protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); } - static void TearDownTestSuite() { test.Cleanup(); } - - static Testbase test; - - public: - void SetUp() override {} - void TearDown() override {} -}; - -Testbase DndTestCluster::test; - -TEST_F(DndTestCluster, 01_ShowCluster) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); - CHECK_META( "show cluster", 3); - CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - IgnoreInt64(); - IgnoreBinary(TSDB_CLUSTER_ID_LEN); - CheckTimestamp(); -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/show/CMakeLists.txt b/source/dnode/mnode/impl/test/show/CMakeLists.txt similarity index 100% rename from source/dnode/mgmt/impl/test/show/CMakeLists.txt rename to source/dnode/mnode/impl/test/show/CMakeLists.txt diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mnode/impl/test/show/show.cpp similarity index 100% rename from source/dnode/mgmt/impl/test/show/show.cpp rename to source/dnode/mnode/impl/test/show/show.cpp From 9e3a6804a9d5ca9e1403f154d0b078803e5d1c61 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 02:20:59 -0800 Subject: [PATCH 82/86] add show test --- source/dnode/mnode/impl/test/CMakeLists.txt | 2 +- .../dnode/mnode/impl/test/show/CMakeLists.txt | 8 ++-- source/dnode/mnode/impl/test/show/show.cpp | 37 +++++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index 075ff38bc6..6cdc43344d 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -6,4 +6,4 @@ add_subdirectory(trans) add_subdirectory(qnode) add_subdirectory(snode) add_subdirectory(bnode) - +add_subdirectory(show) diff --git a/source/dnode/mnode/impl/test/show/CMakeLists.txt b/source/dnode/mnode/impl/test/show/CMakeLists.txt index 9786f65605..cc0706ca50 100644 --- a/source/dnode/mnode/impl/test/show/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/show/CMakeLists.txt @@ -1,11 +1,11 @@ aux_source_directory(. SHOW_SRC) -add_executable(dnode_test_show ${SHOW_SRC}) +add_executable(mnode_test_show ${SHOW_SRC}) target_link_libraries( - dnode_test_show + mnode_test_show PUBLIC sut ) add_test( - NAME dnode_test_show - COMMAND dnode_test_show + NAME mnode_test_show + COMMAND mnode_test_show ) diff --git a/source/dnode/mnode/impl/test/show/show.cpp b/source/dnode/mnode/impl/test/show/show.cpp index 8622672758..6d2c9150f2 100644 --- a/source/dnode/mnode/impl/test/show/show.cpp +++ b/source/dnode/mnode/impl/test/show/show.cpp @@ -1,19 +1,19 @@ /** * @file show.cpp * @author slguan (slguan@taosdata.com) - * @brief DNODE module show-msg tests - * @version 0.1 - * @date 2021-12-15 + * @brief MNODE module show tests + * @version 1.0 + * @date 2022-01-06 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ #include "sut.h" -class DndTestShow : public ::testing::Test { +class MndTestShow : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_show", 9091); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9020); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; @@ -23,9 +23,9 @@ class DndTestShow : public ::testing::Test { void TearDown() override {} }; -Testbase DndTestShow::test; +Testbase MndTestShow::test; -TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { +TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { int32_t contLen = sizeof(SShowMsg); SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); @@ -37,7 +37,7 @@ TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } -TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { +TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { int32_t contLen = sizeof(SShowMsg); SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); @@ -49,12 +49,12 @@ TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } -TEST_F(DndTestShow, 02_ShowMsg_Conn) { +TEST_F(MndTestShow, 03_ShowMsg_Conn) { int32_t contLen = sizeof(SConnectMsg); SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); pReq->pid = htonl(1234); - strcpy(pReq->app, "dnode_test_show"); + strcpy(pReq->app, "mnode_test_show"); strcpy(pReq->db, ""); SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); @@ -85,3 +85,18 @@ TEST_F(DndTestShow, 02_ShowMsg_Conn) { EXPECT_EQ(pRetrieveRsp->compressed, 0); EXPECT_EQ(pRetrieveRsp->compLen, 0); } + +TEST_F(MndTestShow, 04_ShowMsg_Cluster) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); + CHECK_META( "show cluster", 3); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + IgnoreInt64(); + IgnoreBinary(TSDB_CLUSTER_ID_LEN); + CheckTimestamp(); +} \ No newline at end of file From 11d6b02aa4fb0c2097c7b17b7986c5d3305d03ac Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 02:35:34 -0800 Subject: [PATCH 83/86] minor changes --- source/dnode/mnode/impl/src/mndAuth.c | 1 - source/dnode/mnode/impl/src/mndCluster.c | 1 - source/dnode/mnode/impl/src/mndShow.c | 22 +++++++++++----------- source/dnode/mnode/impl/src/mndUser.c | 1 - 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index bcefbfde21..a2fc7a57b3 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "os.h" #include "mndAuth.h" int32_t mndInitAuth(SMnode *pMnode) { return 0; } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index b29f8276fe..8cb98a148f 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "mndCluster.h" #include "mndShow.h" -#include "mndTrans.h" #define TSDB_CLUSTER_VER_NUMBE 1 #define TSDB_CLUSTER_RESERVE_SIZE 64 diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 125c250614..81e15497bf 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -22,8 +22,8 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg); static void mndFreeShowObj(SShowObj *pShow); static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId); static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove); -static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg); +static int32_t mndProcessShowReq(SMnodeMsg *pMsg); +static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg); static bool mndCheckRetrieveFinished(SShowObj *pShow); int32_t mndInitShow(SMnode *pMnode) { @@ -36,8 +36,8 @@ int32_t mndInitShow(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowMsg); - mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowReq); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveReq); return 0; } @@ -115,7 +115,7 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove); } -static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessShowReq(SMnodeMsg *pMnodeMsg) { SMnode *pMnode = pMnodeMsg->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; SShowMsg *pMsg = pMnodeMsg->rpcMsg.pCont; @@ -168,14 +168,14 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { } } -static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { - SMnode *pMnode = pMnodeMsg->pMnode; +static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; int32_t rowsToRead = 0; int32_t size = 0; int32_t rowsRead = 0; - SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont; + SRetrieveTableMsg *pRetrieve = pMsg->rpcMsg.pCont; int64_t showId = htobe64(pRetrieve->showId); SShowObj *pShow = mndAcquireShowObj(pMnode, showId); @@ -227,7 +227,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { // if free flag is set, client wants to clean the resources if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead); + rowsRead = (*retrieveFp)(pMsg, pShow, pRsp->data, rowsToRead); } mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); @@ -235,8 +235,8 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision - pMnodeMsg->pCont = pRsp; - pMnodeMsg->contLen = size; + pMsg->pCont = pRsp; + pMsg->contLen = size; if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 3ffb979ed1..0891cf43b3 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "mndUser.h" #include "mndShow.h" -#include "mndSync.h" #include "mndTrans.h" #include "tkey.h" From 11eb2719f8df8ae2ece30fdf2be93fa65cdc8a40 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 5 Jan 2022 19:17:14 +0800 Subject: [PATCH 84/86] refactor code --- source/libs/index/src/index.c | 63 +++++++--- source/libs/index/src/index_cache.c | 73 +++++++---- source/libs/index/src/index_tfile.c | 181 ++++++++++++++++------------ 3 files changed, 193 insertions(+), 124 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index b5a65a9fda..9c66cfe72f 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -63,7 +63,9 @@ static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch); int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // pthread_once(&isInit, indexInit); SIndex* sIdx = calloc(1, sizeof(SIndex)); - if (sIdx == NULL) { return -1; } + if (sIdx == NULL) { + return -1; + } #ifdef USE_LUCENE index_t* index = index_open(path); @@ -73,7 +75,9 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #ifdef USE_INVERTED_INDEX // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); - if (sIdx->tindex == NULL) { goto END; } + if (sIdx->tindex == NULL) { + goto END; + } sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; @@ -84,7 +88,9 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #endif END: - if (sIdx != NULL) { indexClose(sIdx); } + if (sIdx != NULL) { + indexClose(sIdx); + } *index = NULL; return -1; @@ -100,7 +106,9 @@ void indexClose(SIndex* sIdx) { void* iter = taosHashIterate(sIdx->colObj, NULL); while (iter) { IndexCache** pCache = iter; - if (*pCache) { indexCacheUnRef(*pCache); } + if (*pCache) { + indexCacheUnRef(*pCache); + } iter = taosHashIterate(sIdx->colObj, iter); } taosHashCleanup(sIdx->colObj); @@ -158,7 +166,9 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { IndexCache** cache = taosHashGet(index->colObj, buf, sz); assert(*cache != NULL); int ret = indexCachePut(*cache, p, uid); - if (ret != 0) { return ret; } + if (ret != 0) { + return ret; + } } #endif @@ -188,7 +198,9 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result int tsz = 0; index_multi_search(index->index, (const char**)fields, (const char**)keys, types, nQuery, opera, &tResult, &tsz); - for (int i = 0; i < tsz; i++) { taosArrayPush(result, &tResult[i]); } + for (int i = 0; i < tsz; i++) { + taosArrayPush(result, &tResult[i]); + } for (int i = 0; i < nQuery; i++) { free(fields[i]); @@ -245,7 +257,9 @@ void indexOptsDestroy(SIndexOpts* opts) { */ SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType opera) { SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)malloc(sizeof(SIndexMultiTermQuery)); - if (p == NULL) { return NULL; } + if (p == NULL) { + return NULL; + } p->opera = opera; p->query = taosArrayInit(4, sizeof(SIndexTermQuery)); return p; @@ -267,7 +281,9 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName, int32_t nColName, const char* colVal, int32_t nColVal) { SIndexTerm* t = (SIndexTerm*)calloc(1, (sizeof(SIndexTerm))); - if (t == NULL) { return NULL; } + if (t == NULL) { + return NULL; + } t->suid = suid; t->operType = oper; @@ -340,7 +356,9 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result return 0; } static void indexInterResultsDestroy(SArray* results) { - if (results == NULL) { return; } + if (results == NULL) { + return; + } size_t sz = taosArrayGetSize(results); for (size_t i = 0; i < sz; i++) { @@ -396,16 +414,22 @@ static void indexDestroyTempResult(SArray* result) { taosArrayDestroy(result); } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { - if (sIdx == NULL) { return -1; } + if (sIdx == NULL) { + return -1; + } indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); - if (pReader == NULL) { indexWarn("empty tfile reader found"); } + if (pReader == NULL) { + indexWarn("empty tfile reader found"); + } // handle flush Iterate* cacheIter = indexCacheIteratorCreate(pCache); Iterate* tfileIter = tfileIteratorCreate(pReader); - if (tfileIter == NULL) { indexWarn("empty tfile reader iterator"); } + if (tfileIter == NULL) { + indexWarn("empty tfile reader iterator"); + } SArray* result = taosArrayInit(1024, sizeof(void*)); @@ -452,10 +476,6 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) { while (tn == true) { IterateValue* tv = tfileIter->getValue(tfileIter); TFileValue* tfv = tfileValueCreate(tv->colVal); - if (tv->val == NULL) { - // HO - printf("NO...."); - } taosArrayAddAll(tfv->tableId, tv->val); indexMergeSameKey(result, tfv); tn = tfileIter->next(tfileIter); @@ -476,7 +496,9 @@ void iterateValueDestroy(IterateValue* value, bool destroy) { taosArrayDestroy(value->val); value->val = NULL; } else { - if (value->val != NULL) { taosArrayClear(value->val); } + if (value->val != NULL) { + taosArrayClear(value->val); + } } free(value->colVal); value->colVal = NULL; @@ -499,11 +521,12 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); - if (reader == NULL) { goto END; } + if (reader == NULL) { + goto END; + } TFileHeader* header = &reader->header; - ICacheKey key = { - .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; + ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)}; pthread_mutex_lock(&sIdx->mtx); IndexTFile* ifile = (IndexTFile*)sIdx->tindex; diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 517cb1640d..d87c601b00 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -21,10 +21,6 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later #define MEM_TERM_LIMIT 10 * 10000 -// ref index_cache.h:22 -//#define CACHE_KEY_LEN(p) \ -// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + -// sizeof(p->operType)) static void indexMemRef(MemTable* tbl); static void indexMemUnRef(MemTable* tbl); @@ -119,7 +115,9 @@ void indexCacheDestroySkiplist(SSkipList* slt) { tSkipListDestroy(slt); } void indexCacheDestroyImm(IndexCache* cache) { - if (cache == NULL) { return; } + if (cache == NULL) { + return; + } MemTable* tbl = NULL; pthread_mutex_lock(&cache->mtx); @@ -132,7 +130,9 @@ void indexCacheDestroyImm(IndexCache* cache) { } void indexCacheDestroy(void* cache) { IndexCache* pCache = cache; - if (pCache == NULL) { return; } + if (pCache == NULL) { + return; + } indexMemUnRef(pCache->mem); indexMemUnRef(pCache->imm); free(pCache->colName); @@ -142,7 +142,9 @@ void indexCacheDestroy(void* cache) { Iterate* indexCacheIteratorCreate(IndexCache* cache) { Iterate* iiter = calloc(1, sizeof(Iterate)); - if (iiter == NULL) { return NULL; } + if (iiter == NULL) { + return NULL; + } pthread_mutex_lock(&cache->mtx); @@ -160,7 +162,9 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) { return iiter; } void indexCacheIteratorDestroy(Iterate* iter) { - if (iter == NULL) { return; } + if (iter == NULL) { + return; + } tSkipListDestroyIter(iter->iter); iterateValueDestroy(&iter->val, true); free(iter); @@ -198,13 +202,17 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) { } int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { - if (cache == NULL) { return -1; } + if (cache == NULL) { + return -1; + } IndexCache* pCache = cache; indexCacheRef(pCache); // encode data CacheTerm* ct = calloc(1, sizeof(CacheTerm)); - if (cache == NULL) { return -1; } + if (cache == NULL) { + return -1; + } // set up key ct->colType = term->colType; ct->colVal = (char*)calloc(1, sizeof(char) * (term->nColVal + 1)); @@ -235,7 +243,9 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u } static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SArray* result, STermValueType* s) { - if (mem == NULL) { return 0; } + if (mem == NULL) { + return 0; + } char* key = getIndexKey(ct); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); @@ -261,7 +271,9 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { return 0; } + if (cache == NULL) { + return 0; + } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; @@ -275,14 +287,12 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV SIndexTerm* term = query->term; EIndexQueryType qtype = query->qType; CacheTerm ct = {.colVal = term->colVal, .version = atomic_load_32(&pCache->version)}; - // indexCacheDebug(pCache); int ret = indexQueryMem(mem, &ct, qtype, result, s); if (ret == 0 && *s != kTypeDeletion) { // continue search in imm ret = indexQueryMem(imm, &ct, qtype, result, s); } - // cacheTermDestroy(ct); indexMemUnRef(mem); indexMemUnRef(imm); @@ -291,23 +301,33 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV } void indexCacheRef(IndexCache* cache) { - if (cache == NULL) { return; } + if (cache == NULL) { + return; + } int ref = T_REF_INC(cache); UNUSED(ref); } void indexCacheUnRef(IndexCache* cache) { - if (cache == NULL) { return; } + if (cache == NULL) { + return; + } int ref = T_REF_DEC(cache); - if (ref == 0) { indexCacheDestroy(cache); } + if (ref == 0) { + indexCacheDestroy(cache); + } } void indexMemRef(MemTable* tbl) { - if (tbl == NULL) { return; } + if (tbl == NULL) { + return; + } int ref = T_REF_INC(tbl); UNUSED(ref); } void indexMemUnRef(MemTable* tbl) { - if (tbl == NULL) { return; } + if (tbl == NULL) { + return; + } int ref = T_REF_DEC(tbl); if (ref == 0) { SSkipList* slt = tbl->mem; @@ -317,7 +337,9 @@ void indexMemUnRef(MemTable* tbl) { } static void cacheTermDestroy(CacheTerm* ct) { - if (ct == NULL) { return; } + if (ct == NULL) { + return; + } free(ct->colVal); free(ct); } @@ -332,7 +354,9 @@ static int32_t compareKey(const void* l, const void* r) { // compare colVal int32_t cmp = strcmp(lt->colVal, rt->colVal); - if (cmp == 0) { return rt->version - lt->version; } + if (cmp == 0) { + return rt->version - lt->version; + } return cmp; } @@ -352,11 +376,10 @@ static void doMergeWork(SSchedMsg* msg) { } static bool indexCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; - if (iter == NULL) { return false; } - IterateValue* iv = &itera->val; - if (iv->colVal != NULL && iv->val != NULL) { - // indexError("value in cache: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val)); + if (iter == NULL) { + return false; } + IterateValue* iv = &itera->val; iterateValueDestroy(iv, false); bool next = tSkipListIterNext(iter); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 753dbe87b1..958d511630 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -55,15 +55,14 @@ static void tfileGenFileFullName(char* fullname, const char* path, uint64_t s TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); - if (tcache == NULL) { return NULL; } + if (tcache == NULL) { + return NULL; + } tcache->tableCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); tcache->capacity = 64; SArray* files = tfileGetFileList(path); - - uint64_t suid; - int32_t colId, version; for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); @@ -74,12 +73,13 @@ TFileCache* tfileCacheCreate(const char* path) { } TFileReader* reader = tfileReaderCreate(wc); - if (reader == NULL) { goto End; } + if (reader == NULL) { + goto End; + } TFileHeader* header = &reader->header; + ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; - char buf[128] = {0}; - ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; - + char buf[128] = {0}; int32_t sz = indexSerialCacheKey(&key, buf); assert(sz < sizeof(buf)); taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); @@ -93,7 +93,9 @@ End: return NULL; } void tfileCacheDestroy(TFileCache* tcache) { - if (tcache == NULL) { return; } + if (tcache == NULL) { + return; + } // free table cache TFileReader** reader = taosHashIterate(tcache->tableCache, NULL); @@ -114,7 +116,9 @@ TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) { int32_t sz = indexSerialCacheKey(key, buf); assert(sz < sizeof(buf)); TFileReader** reader = taosHashGet(tcache->tableCache, buf, sz); - if (reader == NULL) { return NULL; } + if (reader == NULL) { + return NULL; + } tfileReaderRef(*reader); return *reader; @@ -137,7 +141,9 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) { } TFileReader* tfileReaderCreate(WriterCtx* ctx) { TFileReader* reader = calloc(1, sizeof(TFileReader)); - if (reader == NULL) { return NULL; } + if (reader == NULL) { + return NULL; + } // T_REF_INC(reader); reader->ctx = ctx; @@ -157,7 +163,9 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) { return reader; } void tfileReaderDestroy(TFileReader* reader) { - if (reader == NULL) { return; } + if (reader == NULL) { + return; + } // T_REF_INC(reader); fstDestroy(reader->fst); writerCtxDestroy(reader->ctx, reader->remove); @@ -197,7 +205,9 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c tfileGenFileFullName(fullname, path, suid, colName, version); // indexInfo("open write file name %s", fullname); WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64); - if (wcx == NULL) { return NULL; } + if (wcx == NULL) { + return NULL; + } TFileHeader tfh = {0}; tfh.suid = suid; @@ -212,24 +222,15 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c tfileGenFileFullName(fullname, path, suid, colName, version); WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); - // indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); - if (wc == NULL) { return NULL; } + indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); + if (wc == NULL) { + return NULL; + } TFileReader* reader = tfileReaderCreate(wc); return reader; } TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { - // char pathBuf[128] = {0}; - // sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version); - // TFileHeader header = {.suid = suid, .version = version, .colName = {0}, colType = colType}; - // memcpy(header.colName, ); - - // char buf[TFILE_HADER_PRE_SIZE]; - // int len = TFILE_HADER_PRE_SIZE; - // if (len != ctx->write(ctx, buf, len)) { - // indexError("index: %" PRIu64 " failed to write header info", header->suid); - // return NULL; - //} TFileWriter* tw = calloc(1, sizeof(TFileWriter)); if (tw == NULL) { indexError("index: %" PRIu64 " failed to alloc TFilerWriter", header->suid); @@ -278,34 +279,14 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // check buf has enough space or not int32_t ttsz = TF_TABLE_TATOAL_SIZE(tbsz); - // if (offset + ttsz >= bufLimit) { - // // batch write - // indexInfo("offset: %d, ttsz: %d", offset, ttsz); - // // std::cout << "offset: " << offset << std::endl; - // // std::cout << "ttsz:" << ttsz < < < std::endl; - // tw->ctx->write(tw->ctx, buf, offset); - // offset = 0; - // memset(buf, 0, bufLimit); - // p = buf; - //} - // if (ttsz >= bufLimit) { - //} char* buf = calloc(1, ttsz * sizeof(char)); char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); tw->ctx->write(tw->ctx, buf, ttsz); - // offset += ttsz; - // p = buf + offset; - // set up value offset v->offset = tw->offset; tw->offset += ttsz; free(buf); } - // if (offset != 0) { - // write reversed data in buf to tindex - // tw->ctx->write(tw->ctx, buf, offset); - //} - // tfree(buf); tw->fb = fstBuilderCreate(tw->ctx, 0); if (tw->fb == NULL) { @@ -331,19 +312,25 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { return 0; } void tfileWriterClose(TFileWriter* tw) { - if (tw == NULL) { return; } + if (tw == NULL) { + return; + } writerCtxDestroy(tw->ctx, false); free(tw); } void tfileWriterDestroy(TFileWriter* tw) { - if (tw == NULL) { return; } + if (tw == NULL) { + return; + } writerCtxDestroy(tw->ctx, false); free(tw); } IndexTFile* indexTFileCreate(const char* path) { TFileCache* cache = tfileCacheCreate(path); - if (cache == NULL) { return NULL; } + if (cache == NULL) { + return NULL; + } IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); if (tfile == NULL) { @@ -355,21 +342,27 @@ IndexTFile* indexTFileCreate(const char* path) { return tfile; } void indexTFileDestroy(IndexTFile* tfile) { - if (tfile == NULL) { return; } + if (tfile == NULL) { + return; + } tfileCacheDestroy(tfile->cache); free(tfile); } int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; - if (tfile == NULL) { return ret; } + if (tfile == NULL) { + return ret; + } IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; ICacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; TFileReader* reader = tfileCacheGet(pTfile->cache, &key); - if (reader == NULL) { return 0; } + if (reader == NULL) { + return 0; + } return tfileReaderSearch(reader, query, result); } @@ -391,7 +384,9 @@ static bool tfileIteratorNext(Iterate* iiter) { TFileFstIter* tIter = iiter->iter; StreamWithStateResult* rt = streamWithStateNextWith(tIter->st, NULL); - if (rt == NULL) { return false; } + if (rt == NULL) { + return false; + } int32_t sz = 0; char* ch = (char*)fstSliceData(&rt->data, &sz); @@ -401,7 +396,9 @@ static bool tfileIteratorNext(Iterate* iiter) { offset = (uint64_t)(rt->out.out); swsResultDestroy(rt); // set up iterate value - if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { return false; } + if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { + return false; + } iv->colVal = colVal; return true; @@ -412,7 +409,9 @@ static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; } static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { TFileFstIter* tIter = calloc(1, sizeof(TFileFstIter)); - if (tIter == NULL) { return NULL; } + if (tIter == NULL) { + return NULL; + } tIter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS); tIter->fb = fstSearch(reader->fst, tIter->ctx); @@ -422,7 +421,9 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { } Iterate* tfileIteratorCreate(TFileReader* reader) { - if (reader == NULL) { return NULL; } + if (reader == NULL) { + return NULL; + } Iterate* iter = calloc(1, sizeof(Iterate)); iter->iter = tfileFstIteratorCreate(reader); @@ -437,7 +438,9 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { return iter; } void tfileIteratorDestroy(Iterate* iter) { - if (iter == NULL) { return; } + if (iter == NULL) { + return; + } IterateValue* iv = &iter->val; iterateValueDestroy(iv, true); @@ -452,7 +455,9 @@ void tfileIteratorDestroy(Iterate* iter) { } TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { - if (tf == NULL) { return NULL; } + if (tf == NULL) { + return NULL; + } ICacheKey key = {.suid = suid, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; return tfileCacheGet(tf->cache, &key); } @@ -464,7 +469,9 @@ static int tfileUidCompare(const void* a, const void* b) { } static int tfileStrCompare(const void* a, const void* b) { int ret = strcmp((char*)a, (char*)b); - if (ret == 0) { return ret; } + if (ret == 0) { + return ret; + } return ret < 0 ? -1 : 1; } @@ -479,13 +486,17 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) { TFileValue* tfileValueCreate(char* val) { TFileValue* tf = calloc(1, sizeof(TFileValue)); - if (tf == NULL) { return NULL; } + if (tf == NULL) { + return NULL; + } tf->colVal = tstrdup(val); tf->tableId = taosArrayInit(32, sizeof(uint64_t)); return tf; } int tfileValuePush(TFileValue* tf, uint64_t val) { - if (tf == NULL) { return -1; } + if (tf == NULL) { + return -1; + } taosArrayPush(tf->tableId, &val); return 0; } @@ -506,7 +517,9 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset) { int32_t fstOffset = offset + sizeof(tw->header.fstOffset); tw->header.fstOffset = fstOffset; - if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { return -1; } + if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { + return -1; + } tw->offset += sizeof(fstOffset); return 0; } @@ -517,7 +530,9 @@ static int tfileWriteHeader(TFileWriter* writer) { memcpy(buf, (char*)header, sizeof(buf)); int nwrite = writer->ctx->write(writer->ctx, buf, sizeof(buf)); - if (sizeof(buf) != nwrite) { return -1; } + if (sizeof(buf) != nwrite) { + return -1; + } writer->offset = nwrite; return 0; } @@ -559,7 +574,9 @@ static int tfileReaderLoadFst(TFileReader* reader) { static int FST_MAX_SIZE = 64 * 1024 * 1024; char* buf = calloc(1, sizeof(char) * FST_MAX_SIZE); - if (buf == NULL) { return -1; } + if (buf == NULL) { + return -1; + } WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); @@ -584,23 +601,31 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* int32_t total = sizeof(uint64_t) * nid; char* buf = calloc(1, total); - if (buf == NULL) { return -1; } + if (buf == NULL) { + return -1; + } nread = ctx->readFrom(ctx, buf, total, offset + sizeof(nid)); assert(total == nread); - for (int32_t i = 0; i < nid; i++) { taosArrayPush(result, (uint64_t*)buf + i); } + for (int32_t i = 0; i < nid; i++) { + taosArrayPush(result, (uint64_t*)buf + i); + } free(buf); return 0; } void tfileReaderRef(TFileReader* reader) { - if (reader == NULL) { return; } + if (reader == NULL) { + return; + } int ref = T_REF_INC(reader); UNUSED(ref); } void tfileReaderUnRef(TFileReader* reader) { - if (reader == NULL) { return; } + if (reader == NULL) { + return; + } int ref = T_REF_DEC(reader); if (ref == 0) { // do nothing @@ -616,11 +641,15 @@ static SArray* tfileGetFileList(const char* path) { uint32_t version; DIR* dir = opendir(path); - if (NULL == dir) { return NULL; } + if (NULL == dir) { + return NULL; + } struct dirent* entry; while ((entry = readdir(dir)) != NULL) { char* file = entry->d_name; - if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } + if (0 != tfileParseFileName(file, &suid, buf, &version)) { + continue; + } size_t len = strlen(path) + 1 + strlen(file) + 1; char* buf = calloc(1, len); @@ -643,15 +672,9 @@ static void tfileDestroyFileName(void* elem) { free(p); } static int tfileCompare(const void* a, const void* b) { - const char* aName = *(char**)a; - const char* bName = *(char**)b; - - size_t aLen = strlen(aName); - size_t bLen = strlen(bName); - - int ret = strncmp(aName, bName, aLen > bLen ? aLen : bLen); - if (ret == 0) { return ret; } - return ret < 0 ? -1 : 1; + const char* as = *(char**)a; + const char* bs = *(char**)b; + return strcmp(as, bs); } static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, int* version) { From 7d29af7316da3f91442fb2fc5735a7195cc807a7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 5 Jan 2022 19:22:06 +0800 Subject: [PATCH 85/86] refactor code --- source/libs/index/src/index.c | 56 +++--------- source/libs/index/src/index_cache.c | 64 ++++---------- source/libs/index/src/index_tfile.c | 128 +++++++--------------------- 3 files changed, 62 insertions(+), 186 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 9c66cfe72f..9b7f1c8383 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -63,9 +63,7 @@ static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch); int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // pthread_once(&isInit, indexInit); SIndex* sIdx = calloc(1, sizeof(SIndex)); - if (sIdx == NULL) { - return -1; - } + if (sIdx == NULL) { return -1; } #ifdef USE_LUCENE index_t* index = index_open(path); @@ -75,9 +73,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #ifdef USE_INVERTED_INDEX // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); - if (sIdx->tindex == NULL) { - goto END; - } + if (sIdx->tindex == NULL) { goto END; } sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; @@ -88,9 +84,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #endif END: - if (sIdx != NULL) { - indexClose(sIdx); - } + if (sIdx != NULL) { indexClose(sIdx); } *index = NULL; return -1; @@ -106,9 +100,7 @@ void indexClose(SIndex* sIdx) { void* iter = taosHashIterate(sIdx->colObj, NULL); while (iter) { IndexCache** pCache = iter; - if (*pCache) { - indexCacheUnRef(*pCache); - } + if (*pCache) { indexCacheUnRef(*pCache); } iter = taosHashIterate(sIdx->colObj, iter); } taosHashCleanup(sIdx->colObj); @@ -166,9 +158,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { IndexCache** cache = taosHashGet(index->colObj, buf, sz); assert(*cache != NULL); int ret = indexCachePut(*cache, p, uid); - if (ret != 0) { - return ret; - } + if (ret != 0) { return ret; } } #endif @@ -198,9 +188,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result int tsz = 0; index_multi_search(index->index, (const char**)fields, (const char**)keys, types, nQuery, opera, &tResult, &tsz); - for (int i = 0; i < tsz; i++) { - taosArrayPush(result, &tResult[i]); - } + for (int i = 0; i < tsz; i++) { taosArrayPush(result, &tResult[i]); } for (int i = 0; i < nQuery; i++) { free(fields[i]); @@ -257,9 +245,7 @@ void indexOptsDestroy(SIndexOpts* opts) { */ SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType opera) { SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)malloc(sizeof(SIndexMultiTermQuery)); - if (p == NULL) { - return NULL; - } + if (p == NULL) { return NULL; } p->opera = opera; p->query = taosArrayInit(4, sizeof(SIndexTermQuery)); return p; @@ -281,9 +267,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName, int32_t nColName, const char* colVal, int32_t nColVal) { SIndexTerm* t = (SIndexTerm*)calloc(1, (sizeof(SIndexTerm))); - if (t == NULL) { - return NULL; - } + if (t == NULL) { return NULL; } t->suid = suid; t->operType = oper; @@ -356,9 +340,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result return 0; } static void indexInterResultsDestroy(SArray* results) { - if (results == NULL) { - return; - } + if (results == NULL) { return; } size_t sz = taosArrayGetSize(results); for (size_t i = 0; i < sz; i++) { @@ -414,22 +396,16 @@ static void indexDestroyTempResult(SArray* result) { taosArrayDestroy(result); } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { - if (sIdx == NULL) { - return -1; - } + if (sIdx == NULL) { return -1; } indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); - if (pReader == NULL) { - indexWarn("empty tfile reader found"); - } + if (pReader == NULL) { indexWarn("empty tfile reader found"); } // handle flush Iterate* cacheIter = indexCacheIteratorCreate(pCache); Iterate* tfileIter = tfileIteratorCreate(pReader); - if (tfileIter == NULL) { - indexWarn("empty tfile reader iterator"); - } + if (tfileIter == NULL) { indexWarn("empty tfile reader iterator"); } SArray* result = taosArrayInit(1024, sizeof(void*)); @@ -496,9 +472,7 @@ void iterateValueDestroy(IterateValue* value, bool destroy) { taosArrayDestroy(value->val); value->val = NULL; } else { - if (value->val != NULL) { - taosArrayClear(value->val); - } + if (value->val != NULL) { taosArrayClear(value->val); } } free(value->colVal); value->colVal = NULL; @@ -521,9 +495,7 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); - if (reader == NULL) { - goto END; - } + if (reader == NULL) { goto END; } TFileHeader* header = &reader->header; ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)}; diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index d87c601b00..ca1d9e3fa4 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -115,9 +115,7 @@ void indexCacheDestroySkiplist(SSkipList* slt) { tSkipListDestroy(slt); } void indexCacheDestroyImm(IndexCache* cache) { - if (cache == NULL) { - return; - } + if (cache == NULL) { return; } MemTable* tbl = NULL; pthread_mutex_lock(&cache->mtx); @@ -130,9 +128,7 @@ void indexCacheDestroyImm(IndexCache* cache) { } void indexCacheDestroy(void* cache) { IndexCache* pCache = cache; - if (pCache == NULL) { - return; - } + if (pCache == NULL) { return; } indexMemUnRef(pCache->mem); indexMemUnRef(pCache->imm); free(pCache->colName); @@ -142,9 +138,7 @@ void indexCacheDestroy(void* cache) { Iterate* indexCacheIteratorCreate(IndexCache* cache) { Iterate* iiter = calloc(1, sizeof(Iterate)); - if (iiter == NULL) { - return NULL; - } + if (iiter == NULL) { return NULL; } pthread_mutex_lock(&cache->mtx); @@ -162,9 +156,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) { return iiter; } void indexCacheIteratorDestroy(Iterate* iter) { - if (iter == NULL) { - return; - } + if (iter == NULL) { return; } tSkipListDestroyIter(iter->iter); iterateValueDestroy(&iter->val, true); free(iter); @@ -202,17 +194,13 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) { } int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { - if (cache == NULL) { - return -1; - } + if (cache == NULL) { return -1; } IndexCache* pCache = cache; indexCacheRef(pCache); // encode data CacheTerm* ct = calloc(1, sizeof(CacheTerm)); - if (cache == NULL) { - return -1; - } + if (cache == NULL) { return -1; } // set up key ct->colType = term->colType; ct->colVal = (char*)calloc(1, sizeof(char) * (term->nColVal + 1)); @@ -243,9 +231,7 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u } static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SArray* result, STermValueType* s) { - if (mem == NULL) { - return 0; - } + if (mem == NULL) { return 0; } char* key = getIndexKey(ct); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); @@ -271,9 +257,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { - return 0; - } + if (cache == NULL) { return 0; } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; @@ -301,33 +285,23 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV } void indexCacheRef(IndexCache* cache) { - if (cache == NULL) { - return; - } + if (cache == NULL) { return; } int ref = T_REF_INC(cache); UNUSED(ref); } void indexCacheUnRef(IndexCache* cache) { - if (cache == NULL) { - return; - } + if (cache == NULL) { return; } int ref = T_REF_DEC(cache); - if (ref == 0) { - indexCacheDestroy(cache); - } + if (ref == 0) { indexCacheDestroy(cache); } } void indexMemRef(MemTable* tbl) { - if (tbl == NULL) { - return; - } + if (tbl == NULL) { return; } int ref = T_REF_INC(tbl); UNUSED(ref); } void indexMemUnRef(MemTable* tbl) { - if (tbl == NULL) { - return; - } + if (tbl == NULL) { return; } int ref = T_REF_DEC(tbl); if (ref == 0) { SSkipList* slt = tbl->mem; @@ -337,9 +311,7 @@ void indexMemUnRef(MemTable* tbl) { } static void cacheTermDestroy(CacheTerm* ct) { - if (ct == NULL) { - return; - } + if (ct == NULL) { return; } free(ct->colVal); free(ct); } @@ -354,9 +326,7 @@ static int32_t compareKey(const void* l, const void* r) { // compare colVal int32_t cmp = strcmp(lt->colVal, rt->colVal); - if (cmp == 0) { - return rt->version - lt->version; - } + if (cmp == 0) { return rt->version - lt->version; } return cmp; } @@ -376,9 +346,7 @@ static void doMergeWork(SSchedMsg* msg) { } static bool indexCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; - if (iter == NULL) { - return false; - } + if (iter == NULL) { return false; } IterateValue* iv = &itera->val; iterateValueDestroy(iv, false); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 958d511630..6437991358 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -55,9 +55,7 @@ static void tfileGenFileFullName(char* fullname, const char* path, uint64_t s TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); - if (tcache == NULL) { - return NULL; - } + if (tcache == NULL) { return NULL; } tcache->tableCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); tcache->capacity = 64; @@ -73,9 +71,7 @@ TFileCache* tfileCacheCreate(const char* path) { } TFileReader* reader = tfileReaderCreate(wc); - if (reader == NULL) { - goto End; - } + if (reader == NULL) { goto End; } TFileHeader* header = &reader->header; ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; @@ -93,9 +89,7 @@ End: return NULL; } void tfileCacheDestroy(TFileCache* tcache) { - if (tcache == NULL) { - return; - } + if (tcache == NULL) { return; } // free table cache TFileReader** reader = taosHashIterate(tcache->tableCache, NULL); @@ -116,9 +110,7 @@ TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) { int32_t sz = indexSerialCacheKey(key, buf); assert(sz < sizeof(buf)); TFileReader** reader = taosHashGet(tcache->tableCache, buf, sz); - if (reader == NULL) { - return NULL; - } + if (reader == NULL) { return NULL; } tfileReaderRef(*reader); return *reader; @@ -141,9 +133,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) { } TFileReader* tfileReaderCreate(WriterCtx* ctx) { TFileReader* reader = calloc(1, sizeof(TFileReader)); - if (reader == NULL) { - return NULL; - } + if (reader == NULL) { return NULL; } // T_REF_INC(reader); reader->ctx = ctx; @@ -163,9 +153,7 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) { return reader; } void tfileReaderDestroy(TFileReader* reader) { - if (reader == NULL) { - return; - } + if (reader == NULL) { return; } // T_REF_INC(reader); fstDestroy(reader->fst); writerCtxDestroy(reader->ctx, reader->remove); @@ -205,9 +193,7 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c tfileGenFileFullName(fullname, path, suid, colName, version); // indexInfo("open write file name %s", fullname); WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64); - if (wcx == NULL) { - return NULL; - } + if (wcx == NULL) { return NULL; } TFileHeader tfh = {0}; tfh.suid = suid; @@ -223,9 +209,7 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); - if (wc == NULL) { - return NULL; - } + if (wc == NULL) { return NULL; } TFileReader* reader = tfileReaderCreate(wc); return reader; @@ -312,25 +296,19 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { return 0; } void tfileWriterClose(TFileWriter* tw) { - if (tw == NULL) { - return; - } + if (tw == NULL) { return; } writerCtxDestroy(tw->ctx, false); free(tw); } void tfileWriterDestroy(TFileWriter* tw) { - if (tw == NULL) { - return; - } + if (tw == NULL) { return; } writerCtxDestroy(tw->ctx, false); free(tw); } IndexTFile* indexTFileCreate(const char* path) { TFileCache* cache = tfileCacheCreate(path); - if (cache == NULL) { - return NULL; - } + if (cache == NULL) { return NULL; } IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); if (tfile == NULL) { @@ -342,27 +320,21 @@ IndexTFile* indexTFileCreate(const char* path) { return tfile; } void indexTFileDestroy(IndexTFile* tfile) { - if (tfile == NULL) { - return; - } + if (tfile == NULL) { return; } tfileCacheDestroy(tfile->cache); free(tfile); } int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; - if (tfile == NULL) { - return ret; - } + if (tfile == NULL) { return ret; } IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; ICacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; TFileReader* reader = tfileCacheGet(pTfile->cache, &key); - if (reader == NULL) { - return 0; - } + if (reader == NULL) { return 0; } return tfileReaderSearch(reader, query, result); } @@ -384,9 +356,7 @@ static bool tfileIteratorNext(Iterate* iiter) { TFileFstIter* tIter = iiter->iter; StreamWithStateResult* rt = streamWithStateNextWith(tIter->st, NULL); - if (rt == NULL) { - return false; - } + if (rt == NULL) { return false; } int32_t sz = 0; char* ch = (char*)fstSliceData(&rt->data, &sz); @@ -396,9 +366,7 @@ static bool tfileIteratorNext(Iterate* iiter) { offset = (uint64_t)(rt->out.out); swsResultDestroy(rt); // set up iterate value - if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { - return false; - } + if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { return false; } iv->colVal = colVal; return true; @@ -409,9 +377,7 @@ static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; } static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { TFileFstIter* tIter = calloc(1, sizeof(TFileFstIter)); - if (tIter == NULL) { - return NULL; - } + if (tIter == NULL) { return NULL; } tIter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS); tIter->fb = fstSearch(reader->fst, tIter->ctx); @@ -421,9 +387,7 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { } Iterate* tfileIteratorCreate(TFileReader* reader) { - if (reader == NULL) { - return NULL; - } + if (reader == NULL) { return NULL; } Iterate* iter = calloc(1, sizeof(Iterate)); iter->iter = tfileFstIteratorCreate(reader); @@ -438,9 +402,7 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { return iter; } void tfileIteratorDestroy(Iterate* iter) { - if (iter == NULL) { - return; - } + if (iter == NULL) { return; } IterateValue* iv = &iter->val; iterateValueDestroy(iv, true); @@ -455,9 +417,7 @@ void tfileIteratorDestroy(Iterate* iter) { } TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { - if (tf == NULL) { - return NULL; - } + if (tf == NULL) { return NULL; } ICacheKey key = {.suid = suid, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; return tfileCacheGet(tf->cache, &key); } @@ -469,9 +429,7 @@ static int tfileUidCompare(const void* a, const void* b) { } static int tfileStrCompare(const void* a, const void* b) { int ret = strcmp((char*)a, (char*)b); - if (ret == 0) { - return ret; - } + if (ret == 0) { return ret; } return ret < 0 ? -1 : 1; } @@ -486,17 +444,13 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) { TFileValue* tfileValueCreate(char* val) { TFileValue* tf = calloc(1, sizeof(TFileValue)); - if (tf == NULL) { - return NULL; - } + if (tf == NULL) { return NULL; } tf->colVal = tstrdup(val); tf->tableId = taosArrayInit(32, sizeof(uint64_t)); return tf; } int tfileValuePush(TFileValue* tf, uint64_t val) { - if (tf == NULL) { - return -1; - } + if (tf == NULL) { return -1; } taosArrayPush(tf->tableId, &val); return 0; } @@ -517,9 +471,7 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset) { int32_t fstOffset = offset + sizeof(tw->header.fstOffset); tw->header.fstOffset = fstOffset; - if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { - return -1; - } + if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { return -1; } tw->offset += sizeof(fstOffset); return 0; } @@ -530,9 +482,7 @@ static int tfileWriteHeader(TFileWriter* writer) { memcpy(buf, (char*)header, sizeof(buf)); int nwrite = writer->ctx->write(writer->ctx, buf, sizeof(buf)); - if (sizeof(buf) != nwrite) { - return -1; - } + if (sizeof(buf) != nwrite) { return -1; } writer->offset = nwrite; return 0; } @@ -574,9 +524,7 @@ static int tfileReaderLoadFst(TFileReader* reader) { static int FST_MAX_SIZE = 64 * 1024 * 1024; char* buf = calloc(1, sizeof(char) * FST_MAX_SIZE); - if (buf == NULL) { - return -1; - } + if (buf == NULL) { return -1; } WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); @@ -601,31 +549,23 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* int32_t total = sizeof(uint64_t) * nid; char* buf = calloc(1, total); - if (buf == NULL) { - return -1; - } + if (buf == NULL) { return -1; } nread = ctx->readFrom(ctx, buf, total, offset + sizeof(nid)); assert(total == nread); - for (int32_t i = 0; i < nid; i++) { - taosArrayPush(result, (uint64_t*)buf + i); - } + for (int32_t i = 0; i < nid; i++) { taosArrayPush(result, (uint64_t*)buf + i); } free(buf); return 0; } void tfileReaderRef(TFileReader* reader) { - if (reader == NULL) { - return; - } + if (reader == NULL) { return; } int ref = T_REF_INC(reader); UNUSED(ref); } void tfileReaderUnRef(TFileReader* reader) { - if (reader == NULL) { - return; - } + if (reader == NULL) { return; } int ref = T_REF_DEC(reader); if (ref == 0) { // do nothing @@ -641,15 +581,11 @@ static SArray* tfileGetFileList(const char* path) { uint32_t version; DIR* dir = opendir(path); - if (NULL == dir) { - return NULL; - } + if (NULL == dir) { return NULL; } struct dirent* entry; while ((entry = readdir(dir)) != NULL) { char* file = entry->d_name; - if (0 != tfileParseFileName(file, &suid, buf, &version)) { - continue; - } + if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } size_t len = strlen(path) + 1 + strlen(file) + 1; char* buf = calloc(1, len); From ad94dff047eaba6671d4c652daab285ca6e78704 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 5 Jan 2022 04:18:56 -0800 Subject: [PATCH 86/86] mionr changes --- include/common/tmsg.h | 4 +- source/client/src/clientMsgHandler.c | 4 +- source/dnode/mgmt/impl/test/bnode/dbnode.cpp | 54 ++++---- source/dnode/mgmt/impl/test/db/db.cpp | 54 ++++---- source/dnode/mgmt/impl/test/dnode/dnode.cpp | 56 ++++----- source/dnode/mgmt/impl/test/mnode/mnode.cpp | 82 ++++++------ .../dnode/mgmt/impl/test/profile/profile.cpp | 58 ++++----- source/dnode/mgmt/impl/test/qnode/dqnode.cpp | 54 ++++---- source/dnode/mgmt/impl/test/snode/dsnode.cpp | 54 ++++---- source/dnode/mgmt/impl/test/stb/stb.cpp | 32 ++--- source/dnode/mgmt/impl/test/sut/inc/client.h | 2 +- source/dnode/mgmt/impl/test/sut/inc/sut.h | 6 +- .../dnode/mgmt/impl/test/sut/src/client.cpp | 10 +- source/dnode/mgmt/impl/test/sut/src/sut.cpp | 24 ++-- source/dnode/mgmt/impl/test/vgroup/vgroup.cpp | 18 +-- source/dnode/mnode/impl/src/mndAcct.c | 12 +- source/dnode/mnode/impl/src/mndBnode.c | 82 ++++++------ source/dnode/mnode/impl/src/mndQnode.c | 82 ++++++------ source/dnode/mnode/impl/src/mndShow.c | 48 +++---- source/dnode/mnode/impl/src/mndSnode.c | 82 ++++++------ source/dnode/mnode/impl/src/mndUser.c | 62 ++++----- source/dnode/mnode/impl/test/acct/acct.cpp | 28 ++--- source/dnode/mnode/impl/test/bnode/bnode.cpp | 110 ++++++++-------- source/dnode/mnode/impl/test/qnode/qnode.cpp | 110 ++++++++-------- source/dnode/mnode/impl/test/show/show.cpp | 34 ++--- source/dnode/mnode/impl/test/snode/snode.cpp | 110 ++++++++-------- source/dnode/mnode/impl/test/trans/trans.cpp | 16 +-- source/dnode/mnode/impl/test/user/user.cpp | 118 +++++++++--------- source/libs/parser/inc/astToMsg.h | 2 +- source/libs/parser/src/astToMsg.c | 4 +- source/libs/parser/src/dCDAstProcess.c | 2 +- src/client/src/tscServer.c | 18 +-- 32 files changed, 716 insertions(+), 716 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 1b2b6a677a..cd8fe7b0d2 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -506,7 +506,7 @@ typedef struct { int64_t qId; }; // query handle int8_t free; -} SRetrieveTableMsg; +} SRetrieveTableReq; typedef struct SRetrieveTableRsp { int64_t useconds; @@ -808,7 +808,7 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; int16_t payloadLen; char payload[]; -} SShowMsg; +} SShowReq; typedef struct { char db[TSDB_DB_FNAME_LEN]; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e402403496..1d74de9ab3 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -87,14 +87,14 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { - SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); + SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq)); if (pRetrieveMsg == NULL) { return NULL; } pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId); pMsgSendInfo->msgInfo.pData = pRetrieveMsg; - pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg); + pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq); } else { SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); if (pFetchMsg == NULL) { diff --git a/source/dnode/mgmt/impl/test/bnode/dbnode.cpp b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp index dd8c13c4bd..bafe8242a6 100644 --- a/source/dnode/mgmt/impl/test/bnode/dbnode.cpp +++ b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp @@ -32,9 +32,9 @@ TEST_F(DndTestBnode, 01_Create_Bnode) { SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID); } { @@ -43,9 +43,9 @@ TEST_F(DndTestBnode, 01_Create_Bnode) { SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -54,9 +54,9 @@ TEST_F(DndTestBnode, 01_Create_Bnode) { SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); } test.Restart(); @@ -67,9 +67,9 @@ TEST_F(DndTestBnode, 01_Create_Bnode) { SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); } } @@ -80,9 +80,9 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) { SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID); } { @@ -91,9 +91,9 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) { SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -102,9 +102,9 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) { SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); } test.Restart(); @@ -115,9 +115,9 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) { SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); } { @@ -126,8 +126,8 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) { SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } \ 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 a78b8388c6..3a69ae2305 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -26,7 +26,7 @@ class DndTestDb : public ::testing::Test { Testbase DndTestDb::test; TEST_F(DndTestDb, 01_ShowDb) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); 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"); @@ -47,7 +47,7 @@ TEST_F(DndTestDb, 01_ShowDb) { CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -77,15 +77,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); @@ -106,14 +106,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("ms", 3); // precision CheckInt8(0); // update - test.SendShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_VGROUP, "1.d1"); CHECK_META("show vgroups", 4); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt32(2); CheckInt32(3); @@ -138,13 +138,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->quorum = 2; pReq->cacheLastRow = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); @@ -168,10 +168,10 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { // restart test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); @@ -199,15 +199,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -237,15 +237,15 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d2", TSDB_DB_NAME_LEN - 1); @@ -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(TDMT_MND_USE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(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 9041098d71..51af008fc3 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -51,7 +51,7 @@ TestServer DndTestDnode::server4; TestServer DndTestDnode::server5; TEST_F(DndTestDnode, 01_ShowDnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); @@ -62,7 +62,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) { CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -81,9 +81,9 @@ TEST_F(DndTestDnode, 02_ConfigDnode) { pReq->dnodeId = htonl(1); strcpy(pReq->config, "ddebugflag 131"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { @@ -94,16 +94,16 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9042); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -127,14 +127,14 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -152,9 +152,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9043); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -164,9 +164,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9044); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -176,15 +176,15 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9045); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 4); CheckInt16(1); @@ -225,9 +225,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { server5.Restart(); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 4); CheckInt16(1); diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp index 3d4844c3f6..9a725c20d3 100644 --- a/source/dnode/mgmt/impl/test/mnode/mnode.cpp +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -51,7 +51,7 @@ TestServer DndTestMnode::server4; TestServer DndTestMnode::server5; TEST_F(DndTestMnode, 01_ShowDnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); CHECK_META("show mnodes", 5); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); @@ -60,7 +60,7 @@ TEST_F(DndTestMnode, 01_ShowDnode) { CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time"); CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -77,9 +77,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); } } @@ -90,9 +90,9 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } } @@ -105,13 +105,13 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9062); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -122,12 +122,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -149,12 +149,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -170,14 +170,14 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); // pReq->dnodeId = htonl(2); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 1); // CheckInt16(1); @@ -194,9 +194,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9063"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // { @@ -205,9 +205,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9064"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // { @@ -216,15 +216,15 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9065"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // taosMsleep(1300); -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 4); // CheckInt16(1); @@ -265,9 +265,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // server5.Restart(); // taosMsleep(1300); -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 4); // CheckInt16(1); diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index b705a94af6..29b71f1c27 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(TDMT_MND_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -67,14 +67,14 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, "invalid_db"); - 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); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB); + ASSERT_EQ(pRsp->contLen, 0); } TEST_F(DndTestProfile, 03_ConnectMsg_Show) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, ""); CHECK_META("show connections", 7); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user"); @@ -84,7 +84,7 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) { CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt32(1); CheckBinary("root", TSDB_USER_LEN); @@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -138,9 +138,9 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -153,10 +153,10 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - 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); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONNECTION); + ASSERT_EQ(pRsp->contLen, 0); } { @@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -198,9 +198,9 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID); } TEST_F(DndTestProfile, 07_KillQueryMsg) { @@ -211,10 +211,10 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->connId = htonl(connId); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - ASSERT_EQ(pMsg->contLen, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + ASSERT_EQ(pRsp->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(TDMT_MND_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -261,13 +261,13 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { pReq->connId = htonl(2345); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID); } TEST_F(DndTestProfile, 09_KillQueryMsg) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QUERIES, ""); CHECK_META("show queries", 14); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId"); @@ -285,6 +285,6 @@ TEST_F(DndTestProfile, 09_KillQueryMsg) { CHECK_SCHEMA(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info"); CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp index 48de6e03eb..e609783eb0 100644 --- a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -32,9 +32,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) { SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID); } { @@ -43,9 +43,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) { SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -54,9 +54,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) { SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); } test.Restart(); @@ -67,9 +67,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) { SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); } } @@ -80,9 +80,9 @@ TEST_F(DndTestQnode, 01_Drop_Qnode) { SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID); } { @@ -91,9 +91,9 @@ TEST_F(DndTestQnode, 01_Drop_Qnode) { SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -102,9 +102,9 @@ TEST_F(DndTestQnode, 01_Drop_Qnode) { SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); } test.Restart(); @@ -115,9 +115,9 @@ TEST_F(DndTestQnode, 01_Drop_Qnode) { SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); } { @@ -126,8 +126,8 @@ TEST_F(DndTestQnode, 01_Drop_Qnode) { SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/dsnode.cpp b/source/dnode/mgmt/impl/test/snode/dsnode.cpp index 2ec624b942..1e6bcdb3fb 100644 --- a/source/dnode/mgmt/impl/test/snode/dsnode.cpp +++ b/source/dnode/mgmt/impl/test/snode/dsnode.cpp @@ -32,9 +32,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) { SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID); } { @@ -43,9 +43,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) { SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -54,9 +54,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) { SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); } test.Restart(); @@ -67,9 +67,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) { SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); } } @@ -80,9 +80,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) { SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_ID_INVALID); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID); } { @@ -91,9 +91,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) { SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -102,9 +102,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) { SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); } test.Restart(); @@ -115,9 +115,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) { SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); } { @@ -126,8 +126,8 @@ TEST_F(DndTestSnode, 01_Drop_Snode) { SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index 40af751e33..b3d5d29785 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -51,9 +51,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -101,12 +101,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { strcpy(pSchema->name, "tag3"); } - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); @@ -114,7 +114,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckTimestamp(); @@ -128,7 +128,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(TDMT_MND_STB_META, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_STB_META, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -203,9 +203,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { // restart test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); @@ -219,13 +219,13 @@ 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(TDMT_MND_DROP_STB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/sut/inc/client.h b/source/dnode/mgmt/impl/test/sut/inc/client.h index e1e430318e..9cf688fc02 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/client.h +++ b/source/dnode/mgmt/impl/test/sut/inc/client.h @@ -21,7 +21,7 @@ class TestClient { bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port); void Cleanup(); - SRpcMsg* SendMsg(SRpcMsg* pMsg); + SRpcMsg* SendReq(SRpcMsg* pReq); void SetRpcRsp(SRpcMsg* pRsp); tsem_t* GetSem(); diff --git a/source/dnode/mgmt/impl/test/sut/inc/sut.h b/source/dnode/mgmt/impl/test/sut/inc/sut.h index 24278a73f7..fd9c1cd93e 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/sut.h +++ b/source/dnode/mgmt/impl/test/sut/inc/sut.h @@ -39,7 +39,7 @@ class Testbase { void Restart(); void ServerStop(); void ServerStart(); - SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); + SRpcMsg* SendReq(tmsg_t msgType, void* pCont, int32_t contLen); private: void InitLog(const char* path); @@ -50,8 +50,8 @@ class Testbase { int32_t connId; public: - void SendShowMetaMsg(int8_t showType, const char* db); - void SendShowRetrieveMsg(); + void SendShowMetaReq(int8_t showType, const char* db); + void SendShowRetrieveReq(); STableMetaMsg* GetShowMeta(); SRetrieveTableRsp* GetRetrieveRsp(); diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index 086ba7bb0f..fd5dcd77d9 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -15,10 +15,10 @@ #include "sut.h" -static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { +static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; - client->SetRpcRsp(pMsg); - uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code); + client->SetRpcRsp(pRsp); + uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pRsp->msgType), pRsp->code); tsem_post(client->GetSem()); } @@ -59,14 +59,14 @@ void TestClient::Cleanup() { rpcClose(clientRpc); } -SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) { +SRpcMsg* TestClient::SendReq(SRpcMsg* pReq) { SEpSet epSet = {0}; epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN); - rpcSendRequest(clientRpc, &epSet, pMsg, NULL); + rpcSendRequest(clientRpc, &epSet, pReq, NULL); tsem_wait(&sem); return pRsp; diff --git a/source/dnode/mgmt/impl/test/sut/src/sut.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp index 46ced254c6..72a6416e22 100644 --- a/source/dnode/mgmt/impl/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -64,23 +64,23 @@ void Testbase::ServerStop() { server.Stop(); } void Testbase::ServerStart() { server.DoStart(); } -SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { +SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; rpcMsg.contLen = contLen; rpcMsg.msgType = msgType; - return client.SendMsg(&rpcMsg); + return client.SendReq(&rpcMsg); } -void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { - int32_t contLen = sizeof(SShowMsg); - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen); +void Testbase::SendShowMetaReq(int8_t showType, const char* db) { + int32_t contLen = sizeof(SShowReq); + SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen); pShow->type = showType; strcpy(pShow->db, db); - SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen); - SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; + SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen); + SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont; ASSERT(pShowRsp != nullptr); pShowRsp->showId = htobe64(pShowRsp->showId); @@ -121,15 +121,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; } const char* Testbase::GetMetaTbName() { return pMeta->tbFname; } -void Testbase::SendShowRetrieveMsg() { - int32_t contLen = sizeof(SRetrieveTableMsg); +void Testbase::SendShowRetrieveReq() { + int32_t contLen = sizeof(SRetrieveTableReq); - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen); + SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen); pRetrieve->showId = htobe64(showId); pRetrieve->free = 0; - SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); - pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; + SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); + pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont; pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index 15a0c8087c..7fa3b4ab61 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -60,9 +60,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } @@ -100,9 +100,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } @@ -121,9 +121,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { rpcMsg.contLen = sizeof(SDropVnodeMsg); rpcMsg.msgType = TDMT_DND_DROP_VNODE; - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 0cf940b987..945a6523ef 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -26,9 +26,9 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw); static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew); -static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg); -static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg); +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq); +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq); +static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq); int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, @@ -185,19 +185,19 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) { return 0; } -static int32_t mndProcessCreateAcctReq(SMnodeMsg *pMsg) { +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessAlterAcctReq(SMnodeMsg *pMsg) { +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessDropAcctReq(SMnodeMsg *pMsg) { +static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; mError("failed to process create acct request since %s", terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 14d49213e9..6325bbb6fd 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -27,12 +27,12 @@ static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw); static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj); static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj); static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew); -static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); int32_t mndInitBnode(SMnode *pMnode) { @@ -185,22 +185,22 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDCreateBnodeReq *pMsg = malloc(sizeof(SDCreateBnodeReq)); - if (pMsg == NULL) { + SDCreateBnodeReq *pReq = malloc(sizeof(SDCreateBnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDCreateBnodeReq); action.msgType = TDMT_DND_CREATE_BNODE; action.acceptableCode = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } @@ -208,29 +208,29 @@ static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S } static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq)); - if (pMsg == NULL) { + SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { +static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { int32_t code = -1; SBnodeObj bnodeObj = {0}; @@ -238,7 +238,7 @@ static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode bnodeObj.createdTime = taosGetTimestampMs(); bnodeObj.updateTime = bnodeObj.createdTime; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) goto CREATE_BNODE_OVER; mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId); @@ -256,9 +256,9 @@ CREATE_BNODE_OVER: return code; } -static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateBnodeReq *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateBnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -282,7 +282,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateBnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { @@ -310,32 +310,32 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq)); - if (pMsg == NULL) { + SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) { +static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pReq, SBnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); if (pTrans == NULL) goto DROP_BNODE_OVER; mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id); @@ -351,9 +351,9 @@ DROP_BNODE_OVER: return code; } -static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropBnodeReq *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropBnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("bnode:%d, start to drop", pDrop->dnodeId); @@ -370,7 +370,7 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndDropBnode(pMnode, pMsg, pObj); + int32_t code = mndDropBnode(pMnode, pReq, pObj); if (code != 0) { sdbRelease(pMnode->pSdb, pObj); mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); @@ -381,18 +381,18 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -431,8 +431,8 @@ static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 6951aa8717..a223890e8c 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -27,12 +27,12 @@ static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw); static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj); static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj); static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew); -static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter); int32_t mndInitQnode(SMnode *pMnode) { @@ -185,22 +185,22 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDCreateQnodeReq *pMsg = malloc(sizeof(SDCreateQnodeReq)); - if (pMsg == NULL) { + SDCreateQnodeReq *pReq = malloc(sizeof(SDCreateQnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDCreateQnodeReq); action.msgType = TDMT_DND_CREATE_QNODE; action.acceptableCode = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } @@ -208,29 +208,29 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S } static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDDropQnodeReq *pMsg = malloc(sizeof(SDDropQnodeReq)); - if (pMsg == NULL) { + SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { +static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { int32_t code = -1; SQnodeObj qnodeObj = {0}; @@ -238,7 +238,7 @@ static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode qnodeObj.createdTime = taosGetTimestampMs(); qnodeObj.updateTime = qnodeObj.createdTime; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) goto CREATE_QNODE_OVER; mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); @@ -256,9 +256,9 @@ CREATE_QNODE_OVER: return code; } -static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateQnodeReq *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateQnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -282,7 +282,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndCreateQnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateQnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { @@ -310,32 +310,32 @@ static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDDropQnodeReq *pMsg = malloc(sizeof(SDDropQnodeReq)); - if (pMsg == NULL) { + SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) { +static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pReq, SQnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); if (pTrans == NULL) goto DROP_QNODE_OVER; mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); @@ -351,9 +351,9 @@ DROP_QNODE_OVER: return code; } -static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropQnodeReq *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropQnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("qnode:%d, start to drop", pDrop->dnodeId); @@ -370,7 +370,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndDropQnode(pMnode, pMsg, pObj); + int32_t code = mndDropQnode(pMnode, pReq, pObj); if (code != 0) { sdbRelease(pMnode->pSdb, pObj); mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); @@ -381,18 +381,18 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -431,8 +431,8 @@ static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 81e15497bf..9c145f6445 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -18,12 +18,12 @@ #define SHOW_STEP_SIZE 100 -static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg); +static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq); static void mndFreeShowObj(SShowObj *pShow); static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId); static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove); -static int32_t mndProcessShowReq(SMnodeMsg *pMsg); -static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg); +static int32_t mndProcessShowReq(SMnodeMsg *pReq); +static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq); static bool mndCheckRetrieveFinished(SShowObj *pShow); int32_t mndInitShow(SMnode *pMnode) { @@ -49,20 +49,20 @@ void mndCleanupShow(SMnode *pMnode) { } } -static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { +static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq) { SShowMgmt *pMgmt = &pMnode->showMgmt; int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1); if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1); - int32_t size = sizeof(SShowObj) + pMsg->payloadLen; + int32_t size = sizeof(SShowObj) + pReq->payloadLen; SShowObj showObj = {0}; showObj.id = showId; showObj.pMnode = pMnode; - showObj.type = pMsg->type; - showObj.payloadLen = pMsg->payloadLen; - memcpy(showObj.db, pMsg->db, TSDB_DB_FNAME_LEN); - memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen); + showObj.type = pReq->type; + showObj.payloadLen = pReq->payloadLen; + memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); + memcpy(showObj.payload, pReq->payload, pReq->payloadLen); int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000; SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime); @@ -115,12 +115,12 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove); } -static int32_t mndProcessShowReq(SMnodeMsg *pMnodeMsg) { - SMnode *pMnode = pMnodeMsg->pMnode; +static int32_t mndProcessShowReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; - SShowMsg *pMsg = pMnodeMsg->rpcMsg.pCont; - int8_t type = pMsg->type; - int16_t payloadLen = htonl(pMsg->payloadLen); + SShowReq *pShowReq = pReq->rpcMsg.pCont; + int8_t type = pShowReq->type; + int16_t payloadLen = htonl(pShowReq->payloadLen); if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) { terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; @@ -135,7 +135,7 @@ static int32_t mndProcessShowReq(SMnodeMsg *pMnodeMsg) { return -1; } - SShowObj *pShow = mndCreateShowObj(pMnode, pMsg); + SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq); if (pShow == NULL) { mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr()); return -1; @@ -151,13 +151,13 @@ static int32_t mndProcessShowReq(SMnodeMsg *pMnodeMsg) { return -1; } - int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); + int32_t code = (*metaFp)(pReq, pShow, &pRsp->tableMeta); mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { - pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; - pMnodeMsg->pCont = pRsp; + pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; + pReq->pCont = pRsp; pRsp->showId = htobe64(pShow->id); mndReleaseShowObj(pShow, false); return TSDB_CODE_SUCCESS; @@ -168,14 +168,14 @@ static int32_t mndProcessShowReq(SMnodeMsg *pMnodeMsg) { } } -static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; int32_t rowsToRead = 0; int32_t size = 0; int32_t rowsRead = 0; - SRetrieveTableMsg *pRetrieve = pMsg->rpcMsg.pCont; + SRetrieveTableReq *pRetrieve = pReq->rpcMsg.pCont; int64_t showId = htobe64(pRetrieve->showId); SShowObj *pShow = mndAcquireShowObj(pMnode, showId); @@ -227,7 +227,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg) { // if free flag is set, client wants to clean the resources if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsRead = (*retrieveFp)(pMsg, pShow, pRsp->data, rowsToRead); + rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead); } mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); @@ -235,8 +235,8 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pMsg) { pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision - pMsg->pCont = pRsp; - pMsg->contLen = size; + pReq->pCont = pRsp; + pReq->contLen = size; if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 7221a2fbf4..1b66bedbcc 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -27,12 +27,12 @@ static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw); static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj); static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj); static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew); -static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter); int32_t mndInitSnode(SMnode *pMnode) { @@ -185,22 +185,22 @@ static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDCreateSnodeReq *pMsg = malloc(sizeof(SDCreateSnodeReq)); - if (pMsg == NULL) { + SDCreateSnodeReq *pReq = malloc(sizeof(SDCreateSnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDCreateSnodeReq); action.msgType = TDMT_DND_CREATE_SNODE; action.acceptableCode = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } @@ -208,29 +208,29 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S } static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDDropSnodeReq *pMsg = malloc(sizeof(SDDropSnodeReq)); - if (pMsg == NULL) { + SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { +static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { int32_t code = -1; SSnodeObj snodeObj = {0}; @@ -238,7 +238,7 @@ static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode snodeObj.createdTime = taosGetTimestampMs(); snodeObj.updateTime = snodeObj.createdTime; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) goto CREATE_SNODE_OVER; mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); @@ -257,9 +257,9 @@ CREATE_SNODE_OVER: return code; } -static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateSnodeReq *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateSnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -283,7 +283,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndCreateSnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateSnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { @@ -311,32 +311,32 @@ static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDDropSnodeReq *pMsg = malloc(sizeof(SDDropSnodeReq)); - if (pMsg == NULL) { + SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; + action.pCont = pReq; action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) { +static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pReq, SSnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); if (pTrans == NULL) goto DROP_SNODE_OVER; mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); @@ -353,9 +353,9 @@ DROP_SNODE_OVER: return code; } -static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropSnodeReq *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropSnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("snode:%d, start to drop", pDrop->dnodeId); @@ -372,7 +372,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndDropSnode(pMnode, pMsg, pObj); + int32_t code = mndDropSnode(pMnode, pReq, pObj); if (code != 0) { sdbRelease(pMnode->pSdb, pObj); mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); @@ -383,18 +383,18 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -433,8 +433,8 @@ static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0891cf43b3..e73b34e688 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -28,12 +28,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw); static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew); -static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg); -static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg); -static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg); -static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq); +static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq); +static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq); +static int32_t mndProcessDropUserReq(SMnodeMsg *pReq); +static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); int32_t mndInitUser(SMnode *pMnode) { @@ -212,7 +212,7 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) { sdbRelease(pSdb, pUser); } -static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) { +static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -221,7 +221,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); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to create since %s", user, terrstr()); return -1; @@ -246,9 +246,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, return 0; } -static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SCreateUserReq *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SCreateUserReq *pCreate = pReq->rpcMsg.pCont; mDebug("user:%s, start to create", pCreate->user); @@ -272,14 +272,14 @@ static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg) { return -1; } - SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; } - int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg); + int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pReq); mndReleaseUser(pMnode, pOperUser); if (code != 0) { @@ -290,8 +290,8 @@ static int32_t mndProcessCreateUserReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pMsg) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); +static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pReq) { + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to update since %s", pOld->user, terrstr()); return -1; @@ -316,9 +316,9 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMn return 0; } -static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SAlterUserReq *pAlter = pMsg->rpcMsg.pCont; +static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SAlterUserReq *pAlter = pReq->rpcMsg.pCont; mDebug("user:%s, start to alter", pAlter->user); @@ -341,7 +341,7 @@ static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { return -1; } - SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; @@ -355,7 +355,7 @@ static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass); newUser.updateTime = taosGetTimestampMs(); - int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg); + int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pReq); mndReleaseUser(pMnode, pOperUser); mndReleaseUser(pMnode, pUser); @@ -367,8 +367,8 @@ static int32_t mndProcessAlterUserReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); +static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pReq, SUserObj *pUser) { + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to drop since %s", pUser->user, terrstr()); return -1; @@ -393,9 +393,9 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { return 0; } -static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SDropUserReq *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SDropUserReq *pDrop = pReq->rpcMsg.pCont; mDebug("user:%s, start to drop", pDrop->user); @@ -412,7 +412,7 @@ static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { return -1; } - SUserObj *pOperUser = mndAcquireUser(pMnode, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; @@ -420,7 +420,7 @@ static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndDropUser(pMnode, pMsg, pUser); + int32_t code = mndDropUser(pMnode, pReq, pUser); mndReleaseUser(pMnode, pOperUser); mndReleaseUser(pMnode, pUser); @@ -432,8 +432,8 @@ static int32_t mndProcessDropUserReq(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -478,8 +478,8 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p return 0; } -static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SUserObj *pUser = NULL; diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 906a066f74..315f23f798 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -30,9 +30,9 @@ TEST_F(MndTestAcct, 01_Create_Acct) { SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(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); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(MndTestAcct, 02_Alter_Acct) { @@ -40,9 +40,9 @@ TEST_F(MndTestAcct, 02_Alter_Acct) { SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(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); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(MndTestAcct, 03_Drop_Acct) { @@ -50,18 +50,18 @@ TEST_F(MndTestAcct, 03_Drop_Acct) { SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(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); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(MndTestAcct, 04_Show_Acct) { - int32_t contLen = sizeof(SShowMsg); + int32_t contLen = sizeof(SShowReq); - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); + SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); pReq->type = TSDB_MGMT_TABLE_ACCT; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp index 07dc163df5..e32c0e7f91 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -39,14 +39,14 @@ Testbase MndTestBnode::test; TestServer MndTestBnode::server2; TEST_F(MndTestBnode, 01_Show_Bnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); CHECK_META("show bnodes", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -57,9 +57,9 @@ TEST_F(MndTestBnode, 02_Create_Bnode) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } { @@ -68,13 +68,13 @@ TEST_F(MndTestBnode, 02_Create_Bnode) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); CHECK_META("show bnodes", 3); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -88,9 +88,9 @@ TEST_F(MndTestBnode, 02_Create_Bnode) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST); } } @@ -102,13 +102,13 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9019); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -118,12 +118,12 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -140,12 +140,12 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -159,9 +159,9 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_BNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_NOT_EXIST); } } @@ -174,9 +174,9 @@ TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -187,9 +187,9 @@ TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -200,9 +200,9 @@ TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -219,9 +219,9 @@ TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } @@ -238,9 +238,9 @@ TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -251,9 +251,9 @@ TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -264,9 +264,9 @@ TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -283,9 +283,9 @@ TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp index 612b138ccc..55806dca4d 100644 --- a/source/dnode/mnode/impl/test/qnode/qnode.cpp +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -39,14 +39,14 @@ Testbase MndTestQnode::test; TestServer MndTestQnode::server2; TEST_F(MndTestQnode, 01_Show_Qnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -57,9 +57,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } { @@ -68,13 +68,13 @@ TEST_F(MndTestQnode, 02_Create_Qnode) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); CHECK_META("show qnodes", 3); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -88,9 +88,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_QNODE_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_ALREADY_EXIST); } } @@ -102,13 +102,13 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9015); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -118,12 +118,12 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -140,12 +140,12 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) { SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -159,9 +159,9 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) { SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_QNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_NOT_EXIST); } } @@ -174,9 +174,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -187,9 +187,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -200,9 +200,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -219,9 +219,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } @@ -238,9 +238,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -251,9 +251,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -264,9 +264,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -283,9 +283,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } diff --git a/source/dnode/mnode/impl/test/show/show.cpp b/source/dnode/mnode/impl/test/show/show.cpp index 6d2c9150f2..b4a625d8be 100644 --- a/source/dnode/mnode/impl/test/show/show.cpp +++ b/source/dnode/mnode/impl/test/show/show.cpp @@ -26,27 +26,27 @@ class MndTestShow : public ::testing::Test { Testbase MndTestShow::test; TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { - int32_t contLen = sizeof(SShowMsg); + int32_t contLen = sizeof(SShowReq); - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); + SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); pReq->type = TSDB_MGMT_TABLE_MAX; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { - int32_t contLen = sizeof(SShowMsg); + int32_t contLen = sizeof(SShowReq); - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); + SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq)); pReq->type = TSDB_MGMT_TABLE_START; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } TEST_F(MndTestShow, 03_ShowMsg_Conn) { @@ -57,11 +57,11 @@ TEST_F(MndTestShow, 03_ShowMsg_Conn) { strcpy(pReq->app, "mnode_test_show"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, ""); STableMetaMsg* pMeta = test.GetShowMeta(); EXPECT_STREQ(pMeta->tbFname, "show connections"); @@ -75,7 +75,7 @@ TEST_F(MndTestShow, 03_ShowMsg_Conn) { EXPECT_EQ(pMeta->tuid, 0); EXPECT_EQ(pMeta->suid, 0); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp(); EXPECT_EQ(pRetrieveRsp->numOfRows, 1); @@ -87,13 +87,13 @@ TEST_F(MndTestShow, 03_ShowMsg_Conn) { } TEST_F(MndTestShow, 04_ShowMsg_Cluster) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_CLUSTER, ""); CHECK_META( "show cluster", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); IgnoreInt64(); diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp index cebb5fe113..9e07be842f 100644 --- a/source/dnode/mnode/impl/test/snode/snode.cpp +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -39,14 +39,14 @@ Testbase MndTestSnode::test; TestServer MndTestSnode::server2; TEST_F(MndTestSnode, 01_Show_Snode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); CHECK_META("show snodes", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -57,9 +57,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } { @@ -68,13 +68,13 @@ TEST_F(MndTestSnode, 02_Create_Snode) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); CHECK_META("show snodes", 3); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -88,9 +88,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_SNODE_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_ALREADY_EXIST); } } @@ -102,13 +102,13 @@ TEST_F(MndTestSnode, 03_Drop_Snode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9017); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -118,12 +118,12 @@ TEST_F(MndTestSnode, 03_Drop_Snode) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -140,12 +140,12 @@ TEST_F(MndTestSnode, 03_Drop_Snode) { SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -159,9 +159,9 @@ TEST_F(MndTestSnode, 03_Drop_Snode) { SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_SNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_NOT_EXIST); } } @@ -174,9 +174,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -187,9 +187,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -200,9 +200,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_CREATING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -219,9 +219,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } @@ -238,9 +238,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } { @@ -251,9 +251,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -264,9 +264,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { pReq->dnodeId = htonl(2); server2.Stop(); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_SDB_OBJ_DROPPING); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -283,9 +283,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - if (pMsg->code == 0) break; + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; taosMsleep(1000); } diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 97a8bd2caf..37c426f573 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -58,21 +58,21 @@ TEST_F(MndTestTrans, 01_Create_User_Crash) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); KillThenRestartServer(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckBinary("u1", TSDB_USER_LEN); @@ -83,4 +83,4 @@ TEST_F(MndTestTrans, 01_Create_User_Crash) { CheckTimestamp(); CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 76954db213..a696158d2b 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -26,7 +26,7 @@ class MndTestUser : public ::testing::Test { Testbase MndTestUser::test; TEST_F(MndTestUser, 01_Show_User) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); @@ -34,7 +34,7 @@ TEST_F(MndTestUser, 01_Show_User) { CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("root", TSDB_USER_LEN); @@ -51,9 +51,9 @@ TEST_F(MndTestUser, 02_Create_User) { strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); } { @@ -63,9 +63,9 @@ TEST_F(MndTestUser, 02_Create_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); } { @@ -75,9 +75,9 @@ TEST_F(MndTestUser, 02_Create_User) { strcpy(pReq->user, "root"); strcpy(pReq->pass, "1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_ALREADY_EXIST); } { @@ -87,15 +87,15 @@ TEST_F(MndTestUser, 02_Create_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -107,9 +107,9 @@ TEST_F(MndTestUser, 03_Alter_User) { strcpy(pReq->user, ""); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); } { @@ -119,9 +119,9 @@ TEST_F(MndTestUser, 03_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); } { @@ -131,9 +131,9 @@ TEST_F(MndTestUser, 03_Alter_User) { strcpy(pReq->user, "u4"); strcpy(pReq->pass, "1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST); } { @@ -143,9 +143,9 @@ TEST_F(MndTestUser, 03_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } @@ -156,9 +156,9 @@ TEST_F(MndTestUser, 04_Drop_User) { SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); } { @@ -167,9 +167,9 @@ TEST_F(MndTestUser, 04_Drop_User) { SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u4"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST); } { @@ -178,15 +178,15 @@ TEST_F(MndTestUser, 04_Drop_User) { SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); } @@ -198,9 +198,9 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -210,15 +210,15 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 3); CheckBinary("u1", TSDB_USER_LEN); @@ -241,15 +241,15 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 3); CheckBinary("u1", TSDB_USER_LEN); @@ -271,15 +271,15 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckBinary("root", TSDB_USER_LEN); @@ -294,10 +294,10 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { // restart test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); CHECK_META("show users", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckBinary("root", TSDB_USER_LEN); diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 30919d25dd..bbb7731261 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -8,7 +8,7 @@ SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); +SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index ab8c9b8094..81181c34dc 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -85,8 +85,8 @@ SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, cha return pMsg; } -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, char* msgBuf, int32_t msgLen) { - SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); +SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, char* msgBuf, int32_t msgLen) { + SShowReq* pShowMsg = calloc(1, sizeof(SShowReq)); pShowMsg->type = pShowInfo->showType; if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 6007fc300c..faaa9924f6 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -109,7 +109,7 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** ou *pEpSet = pCtx->mgmtEpSet; *output = buildShowMsg(pShowInfo, pCtx, pMsgBuf->buf, pMsgBuf->len); - *outputLen = sizeof(SShowMsg) /* + htons(pShowMsg->payloadLen)*/; + *outputLen = sizeof(SShowReq) /* + htons(pShowMsg->payloadLen)*/; } return TSDB_CODE_SUCCESS; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 48127147f8..e0489a76d2 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -603,7 +603,7 @@ int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo) { } int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload; + SRetrieveTableReq *pRetrieveMsg = (SRetrieveTableReq *) pSql->cmd.payload; SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); @@ -638,10 +638,10 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql->res.qId); } - pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg); + pSql->cmd.payloadLen = sizeof(SRetrieveTableReq); pSql->cmd.msgType = TDMT_VND_FETCH; - pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); + pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableReq)); return TSDB_CODE_SUCCESS; } @@ -1420,7 +1420,7 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->msgType = TDMT_MND_SHOW; - pCmd->payloadLen = sizeof(SShowMsg) + 100; + pCmd->payloadLen = sizeof(SShowReq) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1428,13 +1428,13 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SShowInfo *pShowInfo = &pInfo->pMiscInfo->showOpt; - SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload; + SShowReq *pShowMsg = (SShowReq *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); if (pShowInfo->showType == TSDB_MGMT_TABLE_FUNCTION) { pShowMsg->type = pShowInfo->showType; pShowMsg->payloadLen = 0; - pCmd->payloadLen = sizeof(SShowMsg); + pCmd->payloadLen = sizeof(SShowReq); return TSDB_CODE_SUCCESS; } @@ -1463,7 +1463,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pShowMsg->payloadLen = htons(pEpAddr->n); } - pCmd->payloadLen = sizeof(SShowMsg) + htons(pShowMsg->payloadLen); + pCmd->payloadLen = sizeof(SShowReq) + htons(pShowMsg->payloadLen); return TSDB_CODE_SUCCESS; } @@ -1742,7 +1742,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->msgType = TDMT_MND_SHOW_RETRIEVE; - pCmd->payloadLen = sizeof(SRetrieveTableMsg); + pCmd->payloadLen = sizeof(SRetrieveTableReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1750,7 +1750,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg*)pCmd->payload; + SRetrieveTableReq *pRetrieveMsg = (SRetrieveTableReq*)pCmd->payload; pRetrieveMsg->qId = htobe64(pSql->res.qId); pRetrieveMsg->free = htons(pQueryInfo->type);