From 1b9b49c95fa8d8e7eec60926687655fed80b17a1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 30 Dec 2021 03:33:05 -0800 Subject: [PATCH 01/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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 961ffa77e123d1a9983737d689fbf48cb3b7bd6e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 10:55:28 +0800 Subject: [PATCH 17/20] [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 18/20] 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 d862dcae8387d85fdb620b31467b437dc877d722 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 12:58:39 +0800 Subject: [PATCH 19/20] [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 20/20] [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; }