diff --git a/include/os/osFile.h b/include/os/osFile.h index 8bacb1bf7c..a56c54b086 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -120,15 +120,29 @@ int32_t taosSetFileHandlesLimit(); int32_t taosLinkFile(char *src, char *dst); -FILE* taosOpenCFile(const char* filename, const char* mode); -int taosSeekCFile(FILE* file, int64_t offset, int whence); -size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream ); -size_t taosWriteToCFile(const void* ptr, size_t size, size_t nitems, FILE* stream); -int taosCloseCFile(FILE *); -int taosSetAutoDelFile(char* path); +FILE *taosOpenCFile(const char *filename, const char *mode); +int taosSeekCFile(FILE *file, int64_t offset, int whence); +size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream); +size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *stream); +int taosCloseCFile(FILE *); +int taosSetAutoDelFile(char *path); bool lastErrorIsFileNotExist(); +#ifdef BUILD_WITH_RAND_ERR +#define STUB_RAND_NETWORK_ERR(status) \ + do { \ + if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ + uint32_t r = taosRand() % tsRandErrDivisor; \ + if ((r + 1) <= tsRandErrChance) { \ + status = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ + } \ + } \ + while (0) +#else +#define STUB_RAND_NETWORK_ERR(status) +#endif + #ifdef __cplusplus } #endif diff --git a/include/util/taoserror.h b/include/util/taoserror.h index cbcf977994..02e6a49bb6 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -468,6 +468,8 @@ int32_t taosGetErrSize(); #define TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR TAOS_DEF_ERROR_CODE(0, 0x0427) #define TSDB_CODE_DNODE_INVALID_EN_WHITELIST TAOS_DEF_ERROR_CODE(0, 0x0428) #define TSDB_CODE_DNODE_INVALID_MONITOR_PARAS TAOS_DEF_ERROR_CODE(0, 0x0429) +#define TSDB_CODE_MNODE_STOPPED TAOS_DEF_ERROR_CODE(0, 0x042A) + // mnode-sma #define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480) diff --git a/include/util/tdef.h b/include/util/tdef.h index 35c4adab50..f087c28684 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -294,7 +294,7 @@ typedef enum ELogicConditionType { #define TSDB_SHOW_SUBQUERY_LEN 1000 #define TSDB_LOG_VAR_LEN 32 -#define TSDB_MAX_EP_NUM 10 +#define TSDB_MAX_EP_NUM 10 #define TSDB_ARB_GROUP_MEMBER_NUM 2 #define TSDB_ARB_TOKEN_SIZE 32 @@ -568,12 +568,7 @@ enum { SND_WORKER_TYPE__UNIQUE, }; -enum { - RAND_ERR_MEMORY = 1, - RAND_ERR_FILE = 2, - // RAND_ERR_SCOPE_XXX... = 4, - // ... -}; +enum { RAND_ERR_MEMORY = 1, RAND_ERR_FILE = 2, RAND_ERR_NETWORK = 4 }; #define DEFAULT_HANDLE 0 #define MNODE_HANDLE 1 diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1df68b5389..8e44c9c4b4 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -934,7 +934,8 @@ SColVal *tRowIterNext(SRowIter *pIter) { pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type); goto _exit; } else { - ASSERT(0); + uError("unexpected column id %d, %d", cid, pTColumn->colId); + goto _exit; } } else { pIter->cv = COL_VAL_NONE(pTColumn->colId, pTColumn->type); @@ -1356,11 +1357,8 @@ int32_t tValueCompare(const SValue *tv1, const SValue *tv2) { int32_t ret = memcmp(tv1->pData, tv2->pData, tv1->nData < tv2->nData ? tv1->nData : tv2->nData); return ret ? ret : (tv1->nData < tv2->nData ? -1 : (tv1->nData > tv2->nData ? 1 : 0)); } - case TSDB_DATA_TYPE_DECIMAL: - ASSERT(0); - break; default: - ASSERT(0); + break; } return 0; @@ -2600,7 +2598,7 @@ static FORCE_INLINE void tColDataGetValue3(SColData *pColData, int32_t iVal, *pColVal = COL_VAL_NULL(pColData->cid, pColData->type); break; default: - ASSERT(0); + break; } } static FORCE_INLINE void tColDataGetValue4(SColData *pColData, int32_t iVal, SColVal *pColVal) { // HAS_VALUE @@ -2628,7 +2626,7 @@ static FORCE_INLINE void tColDataGetValue5(SColData *pColData, int32_t iVal, tColDataGetValue4(pColData, iVal, pColVal); break; default: - ASSERT(0); + break; } } static FORCE_INLINE void tColDataGetValue6(SColData *pColData, int32_t iVal, @@ -2641,7 +2639,7 @@ static FORCE_INLINE void tColDataGetValue6(SColData *pColData, int32_t iVal, tColDataGetValue4(pColData, iVal, pColVal); break; default: - ASSERT(0); + break; } } static FORCE_INLINE void tColDataGetValue7(SColData *pColData, int32_t iVal, @@ -2657,7 +2655,7 @@ static FORCE_INLINE void tColDataGetValue7(SColData *pColData, int32_t iVal, tColDataGetValue4(pColData, iVal, pColVal); break; default: - ASSERT(0); + break; } } static void (*tColDataGetValueImpl[])(SColData *pColData, int32_t iVal, SColVal *pColVal) = { @@ -2671,7 +2669,6 @@ static void (*tColDataGetValueImpl[])(SColData *pColData, int32_t iVal, SColVal tColDataGetValue7 // HAS_VALUE | HAS_NULL | HAS_NONE }; void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) { - ASSERT(iVal >= 0 && iVal < pColData->nVal && pColData->flag); tColDataGetValueImpl[pColData->flag](pColData, iVal, pColVal); } @@ -3334,7 +3331,8 @@ static void tColDataMergeImpl(SColData *pColData, int32_t iStart, int32_t iEnd / } else if (bv == BIT_FLG_NULL) { flag |= HAS_NULL; } else { - ASSERT(0); + uError("invalid bit value:%d", bv); + return; } if (flag == pColData->flag) break; diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 2a8e7951b1..79847d4e4a 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -397,11 +397,6 @@ char getPrecisionUnit(int32_t precision) { } int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPrecision) { - ASSERT(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || - fromPrecision == TSDB_TIME_PRECISION_NANO); - ASSERT(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO || - toPrecision == TSDB_TIME_PRECISION_NANO); - switch (fromPrecision) { case TSDB_TIME_PRECISION_MILLI: { switch (toPrecision) { @@ -418,7 +413,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre } return utime * 1000000; default: - ASSERT(0); return utime; } } // end from milli @@ -434,7 +428,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre } return utime * 1000; default: - ASSERT(0); return utime; } } // end from micro @@ -447,12 +440,10 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre case TSDB_TIME_PRECISION_NANO: return utime; default: - ASSERT(0); return utime; } } // end from nano default: { - ASSERT(0); return utime; // only to pass windows compilation } } // end switch fromPrecision @@ -463,10 +454,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre // !!!!notice:there are precision problems, double lose precison if time is too large, for example: // 1626006833631000000*1.0 = double = 1626006833631000064 // int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) { -// assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || -// fromPrecision == TSDB_TIME_PRECISION_NANO); -// assert(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO || -// toPrecision == TSDB_TIME_PRECISION_NANO); // static double factors[3][3] = {{1., 1000., 1000000.}, {1.0 / 1000, 1., 1000.}, {1.0 / 1000000, 1.0 / 1000, 1.}}; // ((double)time * factors[fromPrecision][toPrecision]); //} @@ -783,7 +770,6 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { if (pInterval->sliding == 0) { - ASSERT(pInterval->interval == 0); return ts; } @@ -814,7 +800,6 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { } else { if (IS_CALENDAR_TIME_DURATION(pInterval->intervalUnit)) { int64_t news = (ts / pInterval->sliding) * pInterval->sliding; - ASSERT(news <= ts); if (pInterval->slidingUnit == 'd' || pInterval->slidingUnit == 'w') { #if defined(WINDOWS) && _MSC_VER >= 1900 int64_t timezone = _timezone; @@ -887,8 +872,6 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) { } } - ASSERT(pInterval->offset >= 0); - if (pInterval->offset > 0) { // try to move current window to the left-hande-side, due to the offset effect. int64_t newe = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1; @@ -1284,7 +1267,6 @@ static int32_t parseTsFormat(const char* formatStr, SArray* formats) { } if (last) { // expand - assert(last->type == TS_FORMAT_NODE_TYPE_CHAR); last->len++; formatStr++; } else { @@ -1311,7 +1293,6 @@ static int32_t parseTsFormat(const char* formatStr, SArray* formats) { } } if (lastOtherFormat) { - assert(lastOtherFormat->type == TS_FORMAT_NODE_TYPE_CHAR); lastOtherFormat->len++; formatStr++; } else { @@ -1664,7 +1645,6 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec } continue; } - assert(node->type == TS_FORMAT_NODE_TYPE_KEYWORD); switch (node->key->id) { case TSFKW_A_M: case TSFKW_P_M: @@ -1929,7 +1909,7 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) { if (!*formats) { *formats = taosArrayInit(8, sizeof(TSFormatNode)); - if (!*formats){ + if (!*formats) { TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } TAOS_CHECK_RETURN(parseTsFormat(format, *formats)); @@ -2002,7 +1982,7 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1, /*o*/ -1, -1, -1, -1, 3, -1, /*u*/ 1, -1, 7, -1, 9, -1}; -#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97] +#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx)-97] // clang-format off static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/ diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index fc070d0d05..e8e7a75889 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -22,7 +22,7 @@ static inline int32_t mmAcquire(SMnodeMgmt *pMgmt) { int32_t code = 0; (void)taosThreadRwlockRdlock(&pMgmt->lock); if (pMgmt->stopped) { - code = -1; + code = TSDB_CODE_MNODE_STOPPED; } else { (void)atomic_add_fetch_32(&pMgmt->refCount, 1); } @@ -134,16 +134,19 @@ int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { + int32_t code = 0; if (NULL == pMgmt->pMnode) { const STraceId *trace = &pMsg->info.traceId; - dGError("msg:%p, stop to pre-process in mnode since mnode is NULL, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - return -1; + code = TSDB_CODE_MNODE_NOT_FOUND; + dGError("msg:%p, stop to pre-process in mnode since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType)); + return code; } pMsg->info.node = pMgmt->pMnode; - if (mndPreProcessQueryMsg(pMsg) != 0) { + if ((code = mndPreProcessQueryMsg(pMsg)) != 0) { const STraceId *trace = &pMsg->info.traceId; - dGError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); - return -1; + dGError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, tstrerror(code), + TMSG_INFO(pMsg->msgType)); + return code; } return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg); } diff --git a/source/dnode/mnode/impl/inc/mndArbGroup.h b/source/dnode/mnode/impl/inc/mndArbGroup.h index fcd11310e7..779d64c7e2 100644 --- a/source/dnode/mnode/impl/inc/mndArbGroup.h +++ b/source/dnode/mnode/impl/inc/mndArbGroup.h @@ -29,7 +29,7 @@ void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pObj); SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup); SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw); -void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup); +int32_t mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup); int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup); int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup); diff --git a/source/dnode/mnode/impl/src/mndArbGroup.c b/source/dnode/mnode/impl/src/mndArbGroup.c index 32b62422e9..23434e5ee3 100644 --- a/source/dnode/mnode/impl/src/mndArbGroup.c +++ b/source/dnode/mnode/impl/src/mndArbGroup.c @@ -102,8 +102,10 @@ void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pGroup) { sdbRelease(pSdb, pGroup); } -void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) { - ASSERT(pVgObj->replica == 2); +int32_t mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) { + if (pVgObj->replica != 2) { + TAOS_RETURN(TSDB_CODE_INVALID_PARA); + } (void)memset(outGroup, 0, sizeof(SArbGroup)); outGroup->dbUid = pVgObj->dbUid; outGroup->vgId = pVgObj->vgId; @@ -111,6 +113,8 @@ void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) { SArbGroupMember *pMember = &outGroup->members[i]; pMember->info.dnodeId = pVgObj->vnodeGid[i].dnodeId; } + + TAOS_RETURN(TSDB_CODE_SUCCESS); } SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index d0eed37f99..9b83fa8a1d 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -629,7 +629,7 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { SVgObj *pVgObj = pVgroups + v; SArbGroup arbGroup = {0}; - mndArbGroupInitFromVgObj(pVgObj, &arbGroup); + TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupRedoLogs(pTrans, &arbGroup)); } } @@ -663,7 +663,7 @@ static int32_t mndSetCreateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { SVgObj *pVgObj = pVgroups + v; SArbGroup arbGroup = {0}; - mndArbGroupInitFromVgObj(pVgObj, &arbGroup); + TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupUndoLogs(pTrans, &arbGroup)); } } @@ -698,7 +698,7 @@ static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj * for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) { SVgObj *pVgObj = pVgroups + v; SArbGroup arbGroup = {0}; - mndArbGroupInitFromVgObj(pVgObj, &arbGroup); + TAOS_CHECK_RETURN(mndArbGroupInitFromVgObj(pVgObj, &arbGroup)); TAOS_CHECK_RETURN(mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup)); } } @@ -1156,44 +1156,30 @@ static int32_t mndSetAlterDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p } static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { - int32_t code = 0; + int32_t code = 0, lino = 0; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; + SVgObj *pVgroup = NULL; SArray *pArray = mndBuildDnodesArray(pMnode, 0); while (1) { - SVgObj *pVgroup = NULL; pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; if (mndVgroupInDb(pVgroup, pNewDb->uid)) { SVgObj newVgroup = {0}; - if ((code = mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray, &newVgroup)) != 0) { - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - taosArrayDestroy(pArray); - TAOS_RETURN(code); - } + TAOS_CHECK_GOTO(mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray, &newVgroup), &lino, + _err); + if (pNewDb->cfg.withArbitrator != pOldDb->cfg.withArbitrator) { if (pNewDb->cfg.withArbitrator) { SArbGroup arbGroup = {0}; - mndArbGroupInitFromVgObj(&newVgroup, &arbGroup); - if ((code = mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup)) != 0) { - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - taosArrayDestroy(pArray); - TAOS_RETURN(code); - } - + TAOS_CHECK_GOTO(mndArbGroupInitFromVgObj(&newVgroup, &arbGroup), &lino, _err); + TAOS_CHECK_GOTO(mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup), &lino, _err); } else { SArbGroup arbGroup = {0}; - mndArbGroupInitFromVgObj(pVgroup, &arbGroup); - if ((code = mndSetDropArbGroupCommitLogs(pTrans, &arbGroup)) != 0) { - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - taosArrayDestroy(pArray); - TAOS_RETURN(code); - } + TAOS_CHECK_GOTO(mndArbGroupInitFromVgObj(pVgroup, &arbGroup), &lino, _err); + TAOS_CHECK_GOTO(mndSetDropArbGroupCommitLogs(pTrans, &arbGroup), &lino, _err); } } } @@ -1203,6 +1189,14 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * taosArrayDestroy(pArray); TAOS_RETURN(code); + +_err: + mError("db:%s, %s failed at %d since %s", pNewDb->name, __func__, lino, tstrerror(code)); + + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + taosArrayDestroy(pArray); + TAOS_RETURN(code); } static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *pNew) { diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 7cabeed0e4..86802914b8 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -180,7 +180,11 @@ static void mndFreeShowObj(SShowObj *pShow) { ShowFreeIterFp freeFp = pMgmt->freeIterFps[pShow->type]; if (freeFp != NULL) { if (pShow->pIter != NULL) { + mTrace("show:0x%" PRIx64 ", is destroying, data:%p, pIter:%p, ", pShow->id, pShow, pShow->pIter); + (*freeFp)(pMnode, pShow->pIter); + + pShow->pIter = NULL; } } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index c4823dc62e..49cacb3dce 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -3147,7 +3147,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ if (TSDB_CODE_MND_USER_NOT_EXIST == code) { SGetUserAuthRsp rsp = {.dropped = 1}; (void)memcpy(rsp.user, pUsers[i].user, TSDB_USER_LEN); - (void)taosArrayPush(batchRsp.pArray, &rsp); + TSDB_CHECK_NULL(taosArrayPush(batchRsp.pArray, &rsp), code, lino, _OVER, TSDB_CODE_OUT_OF_MEMORY); } mError("user:%s, failed to auth user since %s", pUsers[i].user, tstrerror(code)); code = 0; @@ -3168,7 +3168,12 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ TAOS_CHECK_GOTO(code, &lino, _OVER); } - (void)taosArrayPush(batchRsp.pArray, &rsp); + if (!(taosArrayPush(batchRsp.pArray, &rsp))) { + code = TSDB_CODE_OUT_OF_MEMORY; + mndReleaseUser(pMnode, pUser); + tFreeSGetUserAuthRsp(&rsp); + TAOS_CHECK_GOTO(code, &lino, _OVER); + } mndReleaseUser(pMnode, pUser); } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 21602627e9..0334990365 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -129,7 +129,11 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const } SIndexMultiTerm *terms = indexMultiTermCreate(); - int16_t nCols = taosArrayGetSize(pTagVals); + if (terms == NULL) { + return terrno; + } + + int16_t nCols = taosArrayGetSize(pTagVals); for (int i = 0; i < nCols; i++) { STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; @@ -142,8 +146,14 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); } else if (type == TSDB_DATA_TYPE_NCHAR) { if (pTagVal->nData > 0) { - char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + if (val == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + } int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); + if (len < 0) { + TAOS_CHECK_GOTO(len, NULL, _exception); + } memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); type = TSDB_DATA_TYPE_VARCHAR; term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, val, len); @@ -160,16 +170,24 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const int len = sizeof(val); term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len); } + if (term != NULL) { (void)indexMultiTermAdd(terms, term); + } else { + code = terrno; + goto _exception; } } - (void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); + code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); indexMultiTermDestroy(terms); taosArrayDestroy(pTagVals); #endif - return 0; + return code; +_exception: + indexMultiTermDestroy(terms); + taosArrayDestroy(pTagVals); + return code; } int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) { #ifdef USE_INVERTED_INDEX @@ -191,7 +209,11 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche } SIndexMultiTerm *terms = indexMultiTermCreate(); - int16_t nCols = taosArrayGetSize(pTagVals); + if (terms == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int16_t nCols = taosArrayGetSize(pTagVals); for (int i = 0; i < nCols; i++) { STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; @@ -204,8 +226,14 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); } else if (type == TSDB_DATA_TYPE_NCHAR) { if (pTagVal->nData > 0) { - char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + if (val == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + } int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); + if (len < 0) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + } memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); type = TSDB_DATA_TYPE_VARCHAR; term = indexTermCreate(suid, DEL_VALUE, type, key, nKey, val, len); @@ -224,13 +252,20 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche } if (term != NULL) { (void)indexMultiTermAdd(terms, term); + } else { + code = terrno; + goto _exception; } } - (void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); + code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); indexMultiTermDestroy(terms); taosArrayDestroy(pTagVals); #endif - return 0; + return code; +_exception: + indexMultiTermDestroy(terms); + taosArrayDestroy(pTagVals); + return code; } static inline void metaTimeSeriesNotifyCheck(SMeta *pMeta) { @@ -867,7 +902,6 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) goto _err; } - nStbEntry.stbEntry.schemaRow = *row; nStbEntry.stbEntry.schemaTag = *tag; nStbEntry.stbEntry.rsmaParam = oStbEntry.stbEntry.rsmaParam; @@ -1580,7 +1614,12 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl : pAlterTbReq->compress; (void)updataTableColCmpr(&entry.colCmpr, pCol, 1, compress); freeColCmpr = true; - ASSERT(entry.colCmpr.nCols == pSchema->nCols); + if (entry.colCmpr.nCols != pSchema->nCols) { + if (pNewSchema) taosMemoryFree(pNewSchema); + if (freeColCmpr) taosMemoryFree(entry.colCmpr.pColCmpr); + terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; + goto _err; + } break; case TSDB_ALTER_TABLE_DROP_COLUMN: if (pColumn == NULL) { @@ -1617,7 +1656,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl } (void)updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0); - ASSERT(entry.colCmpr.nCols == pSchema->nCols); + if (entry.colCmpr.nCols != pSchema->nCols) { + terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; + goto _err; + } break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: if (pColumn == NULL) { @@ -1698,7 +1740,7 @@ _err: (void)tdbTbcClose(pUidIdxc); tDecoderClear(&dc); - return TSDB_CODE_FAILED; + return terrno != 0 ? terrno : TSDB_CODE_FAILED; } static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { @@ -2514,8 +2556,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { if (tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0) { metaError("vgId:%d, failed to get stable suid for update. version:%" PRId64, TD_VID(pMeta->pVnode), pCtbEntry->version); - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; - ret = -1; + ret = TSDB_CODE_TDB_INVALID_TABLE_ID; goto end; } tbDbKey.uid = pCtbEntry->ctbEntry.suid; @@ -2529,6 +2570,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { } if (stbEntry.stbEntry.schemaTag.pSchema == NULL) { + ret = TSDB_CODE_INVALID_PARA; goto end; } @@ -2573,7 +2615,9 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { } } end: - // metaDestroyTagIdxKey(pTagIdxKey); + if (terrno != 0) { + ret = terrno; + } tDecoderClear(&dc); tdbFree(pData); return ret; diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index d90e869bd4..264758bf3e 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -213,7 +213,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS TAOS_CHECK_GOTO(code, &lino, _exit); } SSDataBlock datablock = {.info.type = STREAM_CHECKPOINT}; - (void)taosArrayPush(pRSmaStat->blocks, &datablock); + TSDB_CHECK_NULL(taosArrayPush(pRSmaStat->blocks, &datablock), code, lino, _exit, TSDB_CODE_OUT_OF_MEMORY); // init smaMgmt TAOS_CHECK_GOTO(smaInit(), &lino, _exit); diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 4acdc3e92c..d77b933e28 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -1430,7 +1430,7 @@ static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type) { blockDataDestroy(packData->pDataBlock); } } else { - ASSERTS(0, "unknown type:%d", type); + smaWarn("%s:%d unknown type:%d", __func__, __LINE__, type); } taosArrayClear(pItems); } @@ -1540,14 +1540,13 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA ++nDelete; } } else { - ASSERTS(0, "unknown msg type:%d", inputType); + smaWarn("%s:%d unknown msg type:%d", __func__, __LINE__, inputType); break; } } if (nSubmit > 0 || nDelete > 0) { int32_t size = TARRAY_SIZE(pSubmitArr); - ASSERTS(size > 0, "size is %d", size); int32_t inputType = nSubmit > 0 ? STREAM_INPUT__MERGED_SUBMIT : STREAM_INPUT__REF_DATA_BLOCK; for (int32_t i = 1; i <= TSDB_RETENTION_L2; ++i) { TAOS_CHECK_EXIT(tdExecuteRSmaImpl(pSma, pSubmitArr->pData, size, version, inputType, pInfo, type, i)); @@ -1677,7 +1676,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { } } } else { - ASSERTS(0, "unknown rsma exec type:%d", (int32_t)type); + smaWarn("%s:%d unknown rsma exec type:%d", __func__, __LINE__, (int32_t)type); code = TSDB_CODE_APP_ERROR; TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 20d4363c73..ae57576279 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -3162,6 +3162,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal, .cacheStatus = TSDB_LAST_CACHE_VALID}; TAOS_CHECK_GOTO(tsdbCacheReallocSLastCol(&lastCol, NULL), &lino, _err); + tsdbCacheFreeSLastColItem(lastColVal); taosArraySet(pColArray, iCol, &lastCol); int32_t aColIndex = taosArraySearchIdx(aColArray, &lastCol.colVal.cid, compareInt16Val, TD_EQ); if (aColIndex >= 0) { diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c index 51f8f15537..f80c898f68 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c @@ -1036,7 +1036,9 @@ static int32_t tsdbDataFileDoWriteBlockData(SDataFileWriter *writer, SBlockData code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid, &cmprInfo.pColCmpr); - ASSERT(code == TSDB_CODE_SUCCESS); + if (code) { + tsdbWarn("vgId:%d failed to get column compress algrithm", TD_VID(writer->config->tsdb->pVnode)); + } TAOS_CHECK_GOTO(tBlockDataCompress(bData, &cmprInfo, buffers, assist), &lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 901632894e..21c5d33ec9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -319,7 +319,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray } else { // all blocks are qualified taosArrayClear(pBlockLoadInfo->aSttBlk); px = taosArrayAddBatch(pBlockLoadInfo->aSttBlk, pArray->data, pArray->size); - if (px == NULL){ + if (px == NULL) { return terrno; } } @@ -336,7 +336,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray } if (p->suid == suid) { - void* px = taosArrayPush(pTmp, p); + void *px = taosArrayPush(pTmp, p); if (px == NULL) { code = terrno; break; @@ -372,7 +372,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl TStatisBlkArray *pStatisBlkArray, uint64_t suid, const char *id) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; - void* px = NULL; + void *px = NULL; int32_t startIndex = 0; int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray); @@ -415,7 +415,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl // existed if (i < rows) { - SSttTableRowsInfo* pInfo = &pBlockLoadInfo->info; + SSttTableRowsInfo *pInfo = &pBlockLoadInfo->info; if (pInfo->pUid == NULL) { pInfo->pUid = taosArrayInit(rows, sizeof(int64_t)); @@ -530,7 +530,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl } } - _end: +_end: (void)tStatisBlockDestroy(&block); double el = (taosGetTimestampUs() - st) / 1000.0; @@ -672,7 +672,7 @@ int32_t tLDataIterOpen2(SLDataIter *pIter, SSttFileReader *pSttFileReader, int32 } void tLDataIterClose2(SLDataIter *pIter) { - (void) tsdbSttFileReaderClose(&pIter->pReader); // always return 0 + (void)tsdbSttFileReaderClose(&pIter->pReader); // always return 0 pIter->pReader = NULL; } @@ -826,7 +826,7 @@ static int32_t findNextValidRow(SLDataIter *pIter, const char *idStr) { return code; } -int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool* hasNext) { +int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool *hasNext) { int32_t step = pIter->backward ? -1 : 1; int32_t code = 0; int32_t iBlockL = pIter->iSttBlk; @@ -835,7 +835,7 @@ int32_t tLDataIterNextRow(SLDataIter *pIter, const char *idStr, bool* hasNext) { *hasNext = false; terrno = 0; - + // no qualified last file block in current file, no need to fetch row if (pIter->pSttBlk == NULL) { return code; @@ -1020,7 +1020,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF // let's record the time window for current table of uid in the stt files if (pSttDataInfo != NULL && numOfRows > 0) { - void* px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); + void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); if (px == NULL) { return terrno; } @@ -1041,7 +1041,7 @@ _end: return code; } -void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void) tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } +void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void)tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; } @@ -1050,14 +1050,12 @@ static void tLDataIterPinSttBlock(SLDataIter *pIter, const char *id) { if (pInfo->blockData[0].sttBlockIndex == pIter->iSttBlk) { pInfo->blockData[0].pin = true; - ASSERT(!pInfo->blockData[1].pin); tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id); return; } if (pInfo->blockData[1].sttBlockIndex == pIter->iSttBlk) { pInfo->blockData[1].pin = true; - ASSERT(!pInfo->blockData[0].pin); tsdbTrace("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id); return; } @@ -1068,14 +1066,12 @@ static void tLDataIterPinSttBlock(SLDataIter *pIter, const char *id) { static void tLDataIterUnpinSttBlock(SLDataIter *pIter, const char *id) { SSttBlockLoadInfo *pInfo = pIter->pBlockLoadInfo; if (pInfo->blockData[0].pin) { - ASSERT(!pInfo->blockData[1].pin); pInfo->blockData[0].pin = false; tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[0].sttBlockIndex, pIter->cid, id); return; } if (pInfo->blockData[1].pin) { - ASSERT(!pInfo->blockData[0].pin); pInfo->blockData[1].pin = false; tsdbTrace("unpin stt-block:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[1].sttBlockIndex, pIter->cid, id); return; @@ -1117,7 +1113,7 @@ int32_t tMergeTreeNext(SMergeTree *pMTree, bool *pHasNext) { code = tLDataIterNextRow(pIter, pMTree->idStr, &hasVal); if (!hasVal || (code != 0)) { if (code == TSDB_CODE_FILE_CORRUPTED) { - code = 0; // suppress the file corrupt error to enable all queries within this cluster can run without failed. + code = 0; // suppress the file corrupt error to enable all queries within this cluster can run without failed. } pMTree->pIter = NULL; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 5849ef9fcc..e080463fc8 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -129,7 +129,6 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1; code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns); if (code < 0) { - code = TSDB_CODE_INVALID_MSG; goto _exit; } } else { @@ -545,7 +544,7 @@ int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList) { } int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1); if (NULL == pCur) { qError("vnode get all table list failed"); @@ -575,7 +574,7 @@ int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bo } int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SVnode *pVnodeObj = pVnode; SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1); if (NULL == pCur) { @@ -589,7 +588,7 @@ int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) { break; } - if (NULL == taosArrayPush(list, &id)) { + if (NULL == taosArrayPush(list, &id)) { qError("taosArrayPush failed"); code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; @@ -602,7 +601,7 @@ _exit: } int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid); if (!pCur) { return TSDB_CODE_OUT_OF_MEMORY; @@ -614,7 +613,7 @@ int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) { break; } - if (NULL == taosArrayPush(list, &id)) { + if (NULL == taosArrayPush(list, &id)) { qError("taosArrayPush failed"); code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; @@ -628,7 +627,7 @@ _exit: int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1), void *arg) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid); if (!pCur) { return terrno; @@ -644,7 +643,7 @@ int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bo continue; } - if (NULL == taosArrayPush(list, &id)) { + if (NULL == taosArrayPush(list, &id)) { qError("taosArrayPush failed"); code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 7344f7d521..48256c744a 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -24,13 +24,13 @@ #include "tgrant.h" #define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \ - do { \ - int _code = colDataSetVal(pCol, rows, buf, isNull);\ - if (TSDB_CODE_SUCCESS != _code) { \ - terrno = _code; \ - return _code; \ - } \ - } while(0) + do { \ + int _code = colDataSetVal(pCol, rows, buf, isNull); \ + if (TSDB_CODE_SUCCESS != _code) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) extern SConfig* tsCfg; @@ -81,7 +81,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { QRY_OPTR_CHECK(pOutput); SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); + int32_t code = createDataBlock(&pBlock); if (code) { return code; } @@ -239,7 +239,7 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) { QRY_OPTR_CHECK(pOutput); SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); + int32_t code = createDataBlock(&pBlock); if (code) { return code; } @@ -284,15 +284,15 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) { return v; } -static int32_t buildRetension(SArray* pRetension, char **ppRetentions ) { +static int32_t buildRetension(SArray* pRetension, char** ppRetentions) { size_t size = taosArrayGetSize(pRetension); if (size == 0) { *ppRetentions = NULL; return TSDB_CODE_SUCCESS; } - char* p1 = taosMemoryCalloc(1, 100); - if(NULL == p1) { + char* p1 = taosMemoryCalloc(1, 100); + if (NULL == p1) { return terrno; } int32_t len = 0; @@ -372,7 +372,7 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, break; } - char* pRetentions = NULL; + char* pRetentions = NULL; QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions)); int32_t dbFNameLen = strlen(dbFName); int32_t hashPrefix = 0; @@ -431,7 +431,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) { QRY_OPTR_CHECK(pOutput); SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); + int32_t code = createDataBlock(&pBlock); if (code) { return code; } @@ -455,7 +455,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) { QRY_OPTR_CHECK(pOutput); SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); + int32_t code = createDataBlock(&pBlock); if (code) { return code; } @@ -582,36 +582,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { } else { *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL"); } - - /* - if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_GEOMETRY) { - if (pTagVal->nData > 0) { - if (num) { - *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", "); - } - - memcpy(buf + VARSTR_HEADER_SIZE + *len, pTagVal->pData, pTagVal->nData); - *len += pTagVal->nData; - } - } else if (type == TSDB_DATA_TYPE_NCHAR) { - if (pTagVal->nData > 0) { - if (num) { - *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ", "); - } - int32_t tlen = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, buf + VARSTR_HEADER_SIZE + *len); - } - } else if (type == TSDB_DATA_TYPE_DOUBLE) { - double val = *(double *)(&pTagVal->i64); - int len = 0; - term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, (const char *)&val, len); - } else if (type == TSDB_DATA_TYPE_BOOL) { - int val = *(int *)(&pTagVal->i64); - int len = 0; - term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_INT, key, nKey, (const char *)&val, len); - } - */ } - _exit: taosArrayDestroy(pTagVals); @@ -871,26 +842,26 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN; - if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { goto _exit; } infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN; - if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { goto _exit; } infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN; - if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { goto _exit; } *pOutput = pBlock; _exit: - if(terrno != TSDB_CODE_SUCCESS) { + if (terrno != TSDB_CODE_SUCCESS) { taosMemoryFree(pBlock); taosArrayDestroy(pBlock->pDataBlock); } @@ -914,7 +885,7 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p QRY_OPTR_CHECK(pOutput); SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); + int32_t code = createDataBlock(&pBlock); if (code) { return code; } @@ -949,7 +920,8 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { if (((SValueNode*)pProj)->isNull) { QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true)); } else { - QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false)); + QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, + nodesGetValueFromNode((SValueNode*)pProj), false)); } } } diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index b68ea5a781..e35b26627b 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -126,7 +126,7 @@ uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint6 int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid); int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo, int32_t* num); -uint64_t tableListGetSize(const STableListInfo* pTableList); +int32_t tableListGetSize(const STableListInfo* pTableList, int32_t* pRes); uint64_t tableListGetSuid(const STableListInfo* pTableList); STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index); int32_t tableListFind(const STableListInfo* pTableList, uint64_t uid, int32_t startIndex); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index 6b5fadbaa1..a219a5b5f0 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -176,7 +176,10 @@ int32_t createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandl code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds, &pInfo->pDstSlotIds); QUERY_CHECK_CODE(code, lino, _error); - int32_t totalTables = tableListGetSize(pTableListInfo); + int32_t totalTables = 0; + code = tableListGetSize(pTableListInfo, &totalTables); + QUERY_CHECK_CODE(code, lino, _error); + int32_t capacity = 0; pInfo->pUidList = taosArrayInit(4, sizeof(int64_t)); @@ -271,7 +274,10 @@ int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { SSDataBlock* pBufRes = pInfo->pBufferedRes; uint64_t suid = tableListGetSuid(pTableList); - int32_t size = tableListGetSize(pTableList); + int32_t size = 0; + code = tableListGetSize(pTableList, &size); + QUERY_CHECK_CODE(code, lino, _end); + if (size == 0) { setOperatorCompleted(pOperator); (*ppRes) = NULL; diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index d90f59047d..f354c9a1cc 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -894,12 +894,12 @@ int32_t doExtractResultBlocks(SExchangeInfo* pExchangeInfo, SSourceDataInfo* pDa int32_t rawLen = *(int32_t*)pStart; pStart += sizeof(int32_t); - ASSERT(compLen <= rawLen && compLen != 0); + QUERY_CHECK_CONDITION((compLen <= rawLen && compLen != 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); pNextStart = pStart + compLen; if (pRetrieveRsp->compressed && (compLen < rawLen)) { int32_t t = tsDecompressString(pStart, compLen, 1, pDataInfo->decompBuf, rawLen, ONE_STAGE_COMP, NULL, 0); - ASSERT(t == rawLen); + QUERY_CHECK_CONDITION((t == rawLen), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); pStart = pDataInfo->decompBuf; } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 24eafe7d57..29ffd900f2 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -197,7 +197,6 @@ void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayL pGroupResInfo->freeItem = true; pGroupResInfo->pRows = pArrayList; pGroupResInfo->index = 0; - ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo)); } bool hasRemainResults(SGroupResInfo* pGroupResInfo) { @@ -1560,7 +1559,12 @@ int32_t getGroupIdFromTagsVal(void* pVnode, uint64_t uid, SNodeList* pGroupNode, return code; } - ASSERT(nodeType(pNew) == QUERY_NODE_VALUE); + if (nodeType(pNew) != QUERY_NODE_VALUE) { + nodesDestroyList(groupNew); + pAPI->metaReaderFn.clearReader(&mr); + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR)); + return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + } SValueNode* pValue = (SValueNode*)pNew; if (pValue->node.resType.type == TSDB_DATA_TYPE_NULL || pValue->isNull) { @@ -1879,7 +1883,8 @@ int32_t createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCond->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pNode; } else { - ASSERT(0); + code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + QUERY_CHECK_CODE(code, lino, _end); } _end: @@ -2149,7 +2154,8 @@ int32_t relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SAr } else if (p->info.colId < pmInfo->colId) { i++; } else { - ASSERT(0); + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR)); + return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } } return code; @@ -2383,9 +2389,13 @@ void resetLimitInfoForNextGroup(SLimitInfo* pLimitInfo) { pLimitInfo->remainOffset = pLimitInfo->limit.offset; } -uint64_t tableListGetSize(const STableListInfo* pTableList) { - ASSERT(taosArrayGetSize(pTableList->pTableList) == taosHashGetSize(pTableList->map)); - return taosArrayGetSize(pTableList->pTableList); +int32_t tableListGetSize(const STableListInfo* pTableList, int32_t* pRes) { + if (taosArrayGetSize(pTableList->pTableList) != taosHashGetSize(pTableList->map)) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR)); + return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + } + (*pRes) = taosArrayGetSize(pTableList->pTableList); + return TSDB_CODE_SUCCESS; } uint64_t tableListGetSuid(const STableListInfo* pTableList) { return pTableList->idInfo.suid; } @@ -2430,7 +2440,6 @@ uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint64_t tab } STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, *slot); - ASSERT(pKeyInfo->uid == tableUid); return pKeyInfo->groupId; } @@ -2457,7 +2466,8 @@ int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1; code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot)); if (code != TSDB_CODE_SUCCESS) { - ASSERT(code != TSDB_CODE_DUP_KEY); // we have checked the existence of uid in hash map above + // we have checked the existence of uid in hash map above + QUERY_CHECK_CONDITION((code != TSDB_CODE_DUP_KEY), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); taosArrayPopTailBatch(pTableList->pTableList, 1); // let's pop the last element in the array list } @@ -2474,7 +2484,12 @@ _end: int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo, int32_t* size) { int32_t totalGroups = tableListGetOutputGroups(pTableList); - int32_t numOfTables = tableListGetSize(pTableList); + int32_t numOfTables = 0; + int32_t code = tableListGetSize(pTableList, &numOfTables); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + return code; + } if (ordinalGroupIndex < 0 || ordinalGroupIndex >= totalGroups) { return TSDB_CODE_INVALID_PARA; diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index b2cbef8919..570de21e0f 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -1295,7 +1295,13 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT // this value may be changed if new tables are created taosRLockLatch(&pTaskInfo->lock); - int32_t numOfTables = tableListGetSize(pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pTableListInfo, &numOfTables); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + taosRUnLockLatch(&pTaskInfo->lock); + return code; + } if (uid == 0) { if (numOfTables != 0) { @@ -1439,7 +1445,13 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT tDeleteSchemaWrapper(mtInfo.schema); return code; } - int32_t size = tableListGetSize(pTableListInfo); + int32_t size = 0; + code = tableListGetSize(pTableListInfo, &size); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + tDeleteSchemaWrapper(mtInfo.schema); + return code; + } code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, NULL, (void**)&pInfo->dataReader, NULL, NULL); @@ -1520,7 +1532,10 @@ SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) { SArray* pUidList = taosArrayInit(10, sizeof(uint64_t)); QUERY_CHECK_NULL(pUidList, code, lino, _end, terrno); - int32_t numOfTables = tableListGetSize(pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pTableListInfo, &numOfTables); + QUERY_CHECK_CODE(code, lino, _end); + for (int32_t i = 0; i < numOfTables; ++i) { STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i); QUERY_CHECK_NULL(pKeyInfo, code, lino, _end, terrno); diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 031ffbb50e..966bda382b 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -1115,7 +1115,14 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pDeleterParam->suid = tableListGetSuid(pTableListInfo); // TODO extract uid list - int32_t numOfTables = tableListGetSize(pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pTableListInfo, &numOfTables); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + taosMemoryFree(pDeleterParam); + return code; + } + pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t)); if (NULL == pDeleterParam->pUidList) { taosMemoryFree(pDeleterParam); diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index fe9d0d3cf0..63f7667890 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -415,7 +415,8 @@ static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiN int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs); if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); - taosMemoryFreeClear(pExpr); + pExprSupp->numOfExprs += 1; + pExprSupp->pExprInfo = pExpr; return code; } @@ -447,6 +448,7 @@ int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFi QUERY_CHECK_CODE(code, lino, _error); pOperator->exprSupp.pExprInfo = pExprInfo; + pOperator->exprSupp.numOfExprs = pInfo->numOfExpr; SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp; code = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pNoFillSupp->pExprInfo, &pNoFillSupp->numOfExprs); @@ -511,7 +513,6 @@ int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFi } setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo); - pOperator->exprSupp.numOfExprs = pInfo->numOfExpr; pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 959ace1228..3f203e7a95 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -213,7 +213,6 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData memcpy(pkey->pData, val, dataLen); } else if (IS_VAR_DATA_TYPE(pkey->type)) { memcpy(pkey->pData, val, varDataTLen(val)); - ASSERT(varDataTLen(val) <= pkey->bytes); } else { memcpy(pkey->pData, val, pkey->bytes); } @@ -241,7 +240,6 @@ static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) { } else if (IS_VAR_DATA_TYPE(pkey->type)) { varDataCopy(pStart, pkey->pData); pStart += varDataTLen(pkey->pData); - ASSERT(varDataTLen(pkey->pData) <= pkey->bytes); } else { memcpy(pStart, pkey->pData, pkey->bytes); pStart += pkey->bytes; @@ -740,7 +738,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { memcpy(data + (*columnLen), src, dataLen); int32_t v = (data + (*columnLen) + dataLen - (char*)pPage); - ASSERT(v > 0); + QUERY_CHECK_CONDITION((v > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); contentLen = dataLen; } else { @@ -748,7 +746,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { char* src = colDataGetData(pColInfoData, j); memcpy(data + (*columnLen), src, varDataTLen(src)); int32_t v = (data + (*columnLen) + varDataTLen(src) - (char*)pPage); - ASSERT(v > 0); + QUERY_CHECK_CONDITION((v > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); contentLen = varDataTLen(src); } @@ -762,7 +760,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { colDataSetNull_f(bitmap, (*rows)); } else { memcpy(data + (*columnLen), colDataGetData(pColInfoData, j), bytes); - ASSERT((data + (*columnLen) + bytes - (char*)pPage) <= getBufPageSize(pInfo->pBuf)); + QUERY_CHECK_CONDITION(((data + (*columnLen) + bytes - (char*)pPage) <= getBufPageSize(pInfo->pBuf)), code, + lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); } contentLen = bytes; } @@ -1299,7 +1298,7 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) { SStreamPartitionOperatorInfo* pInfo = pOperator->info; SSDataBlock* pDest = pInfo->binfo.pRes; - ASSERT(hasRemainPartion(pInfo)); + QUERY_CHECK_CONDITION((hasRemainPartion(pInfo)), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); SPartitionDataInfo* pParInfo = (SPartitionDataInfo*)pInfo->parIte; blockDataCleanup(pDest); int32_t rows = taosArrayGetSize(pParInfo->rowIds); @@ -1343,7 +1342,7 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) { pDest->info.id.groupId = pParInfo->groupId; pOperator->resultInfo.totalRows += pDest->info.rows; pInfo->parIte = taosHashIterate(pInfo->pPartitions, pInfo->parIte); - ASSERT(pDest->info.rows > 0); + QUERY_CHECK_CONDITION((pDest->info.rows > 0), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); _end: if (code != TSDB_CODE_SUCCESS) { @@ -1549,7 +1548,8 @@ static int32_t doStreamHashPartitionNext(SOperatorInfo* pOperator, SSDataBlock** return code; } default: - ASSERTS(0, "invalid SSDataBlock type"); + code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + QUERY_CHECK_CODE(code, lino, _end); } // there is an scalar expression that needs to be calculated right before apply the group aggregation. diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 6a775dfc79..db8ac00111 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1083,7 +1083,10 @@ static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) { return getBlockForEmptyTable(pOperator, pStart); } } else { // group by tag + no sort - int32_t numOfTables = tableListGetSize(pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pTableListInfo, &numOfTables); + QUERY_CHECK_CODE(code, lino, _end); + if (pTableScanInfo->tableEndIndex + 1 >= numOfTables) { // get empty group, mark processed & rm from hash void* pIte = taosHashIterate(pTableListInfo->remainGroups, NULL); @@ -1172,7 +1175,10 @@ static SSDataBlock* startNextGroupScan(SOperatorInfo* pOperator) { STableScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStorageAPI* pAPI = &pTaskInfo->storageAPI; - int32_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables); + QUERY_CHECK_CODE(code, lino, _end); + if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pInfo->base.pTableListInfo)) { setOperatorCompleted(pOperator); if (pOperator->dynamicTask) { @@ -1305,7 +1311,7 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { // scan table one by one sequentially if (pInfo->scanMode == TABLE_SCAN__TABLE_ORDER) { - int32_t numOfTables = 0; // tableListGetSize(pTaskInfo->pTableListInfo); + int32_t numOfTables = 0; STableKeyInfo tInfo = {0}; pInfo->countState = TABLE_COUNT_STATE_END; @@ -1320,7 +1326,13 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { pInfo->currentTable++; taosRLockLatch(&pTaskInfo->lock); - numOfTables = tableListGetSize(pInfo->base.pTableListInfo); + numOfTables = 0; + code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables); + if (code != TSDB_CODE_SUCCESS) { + taosRUnLockLatch(&pTaskInfo->lock); + lino = __LINE__; + goto _end; + } if (pInfo->currentTable >= numOfTables) { qDebug("all table checked in table list, total:%d, return NULL, %s", numOfTables, GET_TASKID(pTaskInfo)); @@ -3613,7 +3625,9 @@ static int32_t extractTableIdList(const STableListInfo* pTableListInfo, SArray** QUERY_CHECK_NULL(tableIdList, code, lino, _end, terrno); // Transfer the Array of STableKeyInfo into uid list. - size_t size = tableListGetSize(pTableListInfo); + int32_t size = 0; + code = tableListGetSize(pTableListInfo, &size); + QUERY_CHECK_CODE(code, lino, _end); for (int32_t i = 0; i < size; ++i) { STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i); QUERY_CHECK_NULL(pkeyInfo, code, lino, _end, terrno); @@ -4629,7 +4643,13 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); - int32_t size = tableListGetSize(pInfo->pTableListInfo); + int32_t size = 0; + code = tableListGetSize(pInfo->pTableListInfo, &size); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + return code; + } + if (size == 0) { setTaskStatus(pTaskInfo, TASK_COMPLETED); (*ppRes) = NULL; @@ -4927,7 +4947,13 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu static int32_t setGroupStartEndIndex(STableMergeScanInfo* pInfo) { pInfo->bGroupProcessed = false; - size_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); + int32_t numOfTables = 0; + int32_t code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + return code; + } + int32_t i = pInfo->tableStartIndex + 1; for (; i < numOfTables; ++i) { STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i); @@ -5266,7 +5292,10 @@ int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock* int64_t st = taosGetTimestampUs(); - size_t tableListSize = tableListGetSize(pInfo->base.pTableListInfo); + int32_t tableListSize = 0; + code = tableListGetSize(pInfo->base.pTableListInfo, &tableListSize); + QUERY_CHECK_CODE(code, lino, _end); + if (!pInfo->hasGroupId) { pInfo->hasGroupId = true; @@ -5643,7 +5672,10 @@ void startGroupTableMergeScan(SOperatorInfo* pOperator) { qDebug("%s table merge scan start group %" PRIu64, GET_TASKID(pTaskInfo), pInfo->groupId); { - size_t numOfTables = tableListGetSize(pInfo->base.pTableListInfo); + int32_t numOfTables = 0; + code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables); + QUERY_CHECK_CODE(code, lino, _end); + int32_t i = pInfo->tableStartIndex + 1; for (; i < numOfTables; ++i) { STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->base.pTableListInfo, i); @@ -5763,7 +5795,10 @@ int32_t doTableMergeScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { int64_t st = taosGetTimestampUs(); - size_t tableListSize = tableListGetSize(pInfo->base.pTableListInfo); + int32_t tableListSize = 0; + code = tableListGetSize(pInfo->base.pTableListInfo, &tableListSize); + QUERY_CHECK_CODE(code, lino, _end); + if (!pInfo->hasGroupId) { pInfo->hasGroupId = true; diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 6559ba0e68..9eb9d60226 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2843,7 +2843,10 @@ int32_t createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanP QUERY_CHECK_CODE(code, lino, _error); pInfo->pTableListInfo = pTableListInfo; - size_t num = tableListGetSize(pTableListInfo); + int32_t num = 0; + code = tableListGetSize(pTableListInfo, &num); + QUERY_CHECK_CODE(code, lino, _error); + void* pList = tableListGetInfo(pTableListInfo, 0); code = readHandle->api.tsdReader.tsdReaderOpen(readHandle->vnode, &cond, pList, num, pInfo->pResBlock, diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 59c19a706c..cdfbd7a850 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -324,8 +324,11 @@ _end: static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bool isNull); -static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVal* pRowVal, bool reset) { +static int32_t copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVal* pRowVal, bool reset) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SColumnInfoData* pTsCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, pFillInfo->srcTsSlotId); + QUERY_CHECK_NULL(pTsCol, code, lino, _end, terrno); pRowVal->key = ((int64_t*)pTsCol->pData)[rowIndex]; for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { @@ -342,15 +345,24 @@ static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SRowVa } SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId); + QUERY_CHECK_NULL(pSrcCol, code, lino, _end, terrno); bool isNull = colDataIsNull_s(pSrcCol, rowIndex); char* p = colDataGetData(pSrcCol, rowIndex); saveColData(pRowVal->pRowVal, i, p, reset ? true : isNull); } else { - ASSERT(0); + code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + QUERY_CHECK_CODE(code, lino, _end); } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t outputRows) { @@ -362,20 +374,18 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order); bool ascFill = FILL_IS_ASC_FILL(pFillInfo); -#if 0 - ASSERT(ascFill && (pFillInfo->currentKey >= pFillInfo->start) || (!ascFill && (pFillInfo->currentKey <= pFillInfo->start))); -#endif - while (pFillInfo->numOfCurrent < outputRows) { int64_t ts = ((int64_t*)pTsCol->pData)[pFillInfo->index]; // set the next value for interpolation if (pFillInfo->currentKey < ts && ascFill) { SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->next : &pFillInfo->prev; - copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); + code = copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); + QUERY_CHECK_CODE(code, lino, _end); } else if (pFillInfo->currentKey > ts && !ascFill) { SRowVal* pRVal = pFillInfo->type == TSDB_FILL_NEXT ? &pFillInfo->prev : &pFillInfo->next; - copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); + code = copyCurrentRowIntoBuf(pFillInfo, pFillInfo->index, pRVal, false); + QUERY_CHECK_CODE(code, lino, _end); } if (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && @@ -392,21 +402,24 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t goto _end; } } else { - ASSERT(pFillInfo->currentKey == ts); + QUERY_CHECK_CONDITION((pFillInfo->currentKey == ts), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); int32_t index = pBlock->info.rows; int32_t nextRowIndex = pFillInfo->index + 1; if (pFillInfo->type == TSDB_FILL_NEXT) { if ((pFillInfo->index + 1) < pFillInfo->numOfRows) { - copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, false); + code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, false); + QUERY_CHECK_CODE(code, lino, _end); } else { // reset to null after last row - copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); + code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); + QUERY_CHECK_CODE(code, lino, _end); } } if (pFillInfo->type == TSDB_FILL_PREV) { if (nextRowIndex + 1 >= pFillInfo->numOfRows && !FILL_IS_ASC_FILL(pFillInfo)) { - copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); + code = copyCurrentRowIntoBuf(pFillInfo, nextRowIndex, &pFillInfo->next, true); + QUERY_CHECK_CODE(code, lino, _end); } } @@ -500,7 +513,9 @@ static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bo } } -static void appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_t resultCapacity) { +static int32_t appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_t resultCapacity) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; /* * These data are generated according to fill strategy, since the current timestamp is out of the time window of * real result set. Note that we need to keep the direct previous result rows, to generated the filled data. @@ -512,7 +527,14 @@ static void appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int64_ pFillInfo->numOfTotal += pFillInfo->numOfCurrent; - ASSERT(pFillInfo->numOfCurrent == resultCapacity); + QUERY_CHECK_CONDITION((pFillInfo->numOfCurrent == resultCapacity), code, lino, _end, + TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) { @@ -635,15 +657,6 @@ void taosFillSetStartInfo(SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey) // the endKey is now the aligned time window value. truncate time window isn't correct. pFillInfo->end = endKey; - -#if 0 - if (pFillInfo->order == TSDB_ORDER_ASC) { - ASSERT(pFillInfo->start <= pFillInfo->end); - } else { - ASSERT(pFillInfo->start >= pFillInfo->end); - } -#endif - pFillInfo->index = 0; pFillInfo->numOfRows = numOfRows; } @@ -687,7 +700,6 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma numOfRes = taosTimeCountIntervalForFill(lastKey, pFillInfo->currentKey, pFillInfo->interval.sliding, pFillInfo->interval.slidingUnit, pFillInfo->interval.precision, pFillInfo->order); - ASSERT(numOfRes >= numOfRows); } else { // reach the end of data if ((ekey1 < pFillInfo->currentKey && FILL_IS_ASC_FILL(pFillInfo)) || (ekey1 > pFillInfo->currentKey && !FILL_IS_ASC_FILL(pFillInfo))) { @@ -719,23 +731,30 @@ void taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* po int32_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity) { int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; int32_t remain = taosNumOfRemainRows(pFillInfo); int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity); - ASSERT(numOfRes <= capacity); + QUERY_CHECK_CONDITION((numOfRes <= capacity), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); // no data existed for fill operation now, append result according to the fill strategy if (remain == 0) { - appendFilledResult(pFillInfo, p, numOfRes); + code = appendFilledResult(pFillInfo, p, numOfRes); + QUERY_CHECK_CODE(code, lino, _end); } else { code = fillResultImpl(pFillInfo, p, (int32_t)numOfRes); - ASSERT(numOfRes == pFillInfo->numOfCurrent); + QUERY_CHECK_CODE(code, lino, _end); + QUERY_CHECK_CONDITION((numOfRes == pFillInfo->numOfCurrent), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); } qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%" PRId64 "-%" PRId64 ", currentKey:%" PRId64 ", current : % d, total : % d, %s", pFillInfo, pFillInfo->numOfRows, pFillInfo->index, pFillInfo->start, pFillInfo->end, pFillInfo->currentKey, pFillInfo->numOfCurrent, pFillInfo->numOfTotal, pFillInfo->id); +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } diff --git a/source/libs/geometry/src/geosWrapper.c b/source/libs/geometry/src/geosWrapper.c index dde34edc91..b349ab5cbe 100644 --- a/source/libs/geometry/src/geosWrapper.c +++ b/source/libs/geometry/src/geosWrapper.c @@ -331,18 +331,26 @@ int32_t doGeosRelation(const GEOSGeometry *geom1, const GEOSPreparedGeometry *pr if (!preparedGeom1) { if (!swapped) { - ASSERT(relationFn); + if (!relationFn) { + return TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + } *res = relationFn(geosCtx->handle, geom1, geom2); } else { - ASSERT(swappedRelationFn); + if (!swappedRelationFn) { + return TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + } *res = swappedRelationFn(geosCtx->handle, geom1, geom2); } } else { if (!swapped) { - ASSERT(preparedRelationFn); + if (!preparedRelationFn) { + return TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + } *res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2); } else { - ASSERT(swappedPreparedRelationFn); + if (!swappedPreparedRelationFn) { + return TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + } *res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2); } } @@ -391,7 +399,9 @@ int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, const GEOSPreparedGeometry **outputPreparedGeom) { SGeosContext *geosCtx = getThreadLocalGeosCtx(); - ASSERT(outputGeom); // it is not allowed if outputGeom is NULL + if (!outputGeom) { + return TSDB_CODE_FUNC_FUNTION_PARA_VALUE; + } *outputGeom = NULL; if (outputPreparedGeom) { // it means not to generate PreparedGeometry if outputPreparedGeom is NULL diff --git a/source/libs/geometry/test/geomFuncTestUtil.cpp b/source/libs/geometry/test/geomFuncTestUtil.cpp index 0918781499..25b2dd7c8d 100644 --- a/source/libs/geometry/test/geomFuncTestUtil.cpp +++ b/source/libs/geometry/test/geomFuncTestUtil.cpp @@ -66,7 +66,7 @@ void setScalarParam(SScalarParam *sclParam, int32_t type, void *valueArray, TDRo break; } default: { - ASSERT(0); + ASSERT_TRUE(false); break; } } diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0f2b53c68a..e2c74f0dbb 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -237,8 +237,7 @@ int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { indexDebug("w suid:%" PRIu64 ", colName:%s, colType:%d", key.suid, key.colName, key.colType); IndexCache** cache = taosHashGet(index->colObj, buf, sz); - ASSERTS(*cache != NULL, "index-cache already release"); - if (*cache == NULL) return -1; + if (*cache == NULL) return TSDB_CODE_INVALID_PTR; int ret = idxCachePut(*cache, p, uid); if (ret != 0) { @@ -295,7 +294,9 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery) { }; int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) { SIndexTermQuery q = {.qType = qType, .term = term}; - (void)taosArrayPush(pQuery->query, &q); + if (taosArrayPush(pQuery->query, &q) == NULL) { + return terrno; + } return 0; } @@ -303,6 +304,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy int32_t nColName, const char* colVal, int32_t nColVal) { SIndexTerm* tm = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm))); if (tm == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -311,6 +313,10 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy tm->colType = colType; tm->colName = (char*)taosMemoryCalloc(1, nColName + 1); + if (tm->colName == NULL) { + taosMemoryFree(tm); + return NULL; + } memcpy(tm->colName, colName, nColName); tm->nColName = nColName; @@ -326,8 +332,23 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy buf = strndup(emptyStr, (int32_t)strlen(emptyStr)); len = (int32_t)strlen(emptyStr); } + tm->colVal = buf; + if (tm->colVal == NULL) { + taosMemoryFree(tm->colName); + taosMemoryFree(tm); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + tm->nColVal = len; + if (tm->nColVal < 0) { + taosMemoryFree(tm->colName); + taosMemoryFree(tm->colVal); + taosMemoryFree(tm); + terrno = len; + return NULL; + } return tm; } diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index e62f506b1a..8dc63ed105 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -308,90 +308,6 @@ int idxUidCompare(const void* a, const void* b) { uint64_t r = *(uint64_t*)b; return l - r; } -#ifdef BUILD_NO_CALL -int32_t idxConvertData(void* src, int8_t type, void** dst) { - int tlen = -1; - switch (type) { - case TSDB_DATA_TYPE_TIMESTAMP: - tlen = taosEncodeFixedI64(NULL, *(int64_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedI64(dst, *(int64_t*)src); - break; - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_UTINYINT: - tlen = taosEncodeFixedU8(NULL, *(uint8_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedU8(dst, *(uint8_t*)src); - break; - case TSDB_DATA_TYPE_TINYINT: - tlen = taosEncodeFixedI8(NULL, *(uint8_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedI8(dst, *(uint8_t*)src); - break; - case TSDB_DATA_TYPE_SMALLINT: - tlen = taosEncodeFixedI16(NULL, *(int16_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedI16(dst, *(int16_t*)src); - break; - case TSDB_DATA_TYPE_USMALLINT: - tlen = taosEncodeFixedU16(NULL, *(uint16_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedU16(dst, *(uint16_t*)src); - break; - case TSDB_DATA_TYPE_INT: - tlen = taosEncodeFixedI32(NULL, *(int32_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedI32(dst, *(int32_t*)src); - break; - case TSDB_DATA_TYPE_FLOAT: - tlen = taosEncodeBinary(NULL, src, sizeof(float)); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeBinary(dst, src, sizeof(float)); - break; - case TSDB_DATA_TYPE_UINT: - tlen = taosEncodeFixedU32(NULL, *(uint32_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedU32(dst, *(uint32_t*)src); - break; - case TSDB_DATA_TYPE_BIGINT: - tlen = taosEncodeFixedI64(NULL, *(int64_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedI64(dst, *(int64_t*)src); - break; - case TSDB_DATA_TYPE_DOUBLE: - tlen = taosEncodeBinary(NULL, src, sizeof(double)); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeBinary(dst, src, sizeof(double)); - break; - case TSDB_DATA_TYPE_UBIGINT: - tlen = taosEncodeFixedU64(NULL, *(uint64_t*)src); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeFixedU64(dst, *(uint64_t*)src); - break; - case TSDB_DATA_TYPE_NCHAR: { - tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); - - break; - } - case TSDB_DATA_TYPE_VARCHAR: // TSDB_DATA_TYPE_BINARY - case TSDB_DATA_TYPE_VARBINARY: - case TSDB_DATA_TYPE_GEOMETRY: { - tlen = taosEncodeBinary(NULL, src, strlen(src)); - *dst = taosMemoryCalloc(1, tlen + 1); - tlen = taosEncodeBinary(dst, src, strlen(src)); - break; - } - default: - ASSERTS(0, "index invalid input type"); - break; - } - *dst = (char*)*dst - tlen; - // indexMayFillNumbericData(*dst, tlen); - return tlen; -} -#endif int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (src == NULL) { @@ -513,7 +429,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { break; } default: - ASSERTS(0, "index invalid input type"); + tlen = TSDB_CODE_INVALID_DATA_FMT; break; } return tlen; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index 2858d09c30..03474c0143 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -661,7 +661,16 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP } SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST); - (void)indexMultiTermQueryAdd(mtm, tm, qtype); + if (mtm == NULL) { + indexTermDestroy(tm); + return TSDB_CODE_OUT_OF_MEMORY; + } + + if ((ret = indexMultiTermQueryAdd(mtm, tm, qtype)) != 0) { + indexMultiTermQueryDestroy(mtm); + return ret; + } + ret = indexJsonSearch(arg->ivtIdx, mtm, output->result); indexMultiTermQueryDestroy(mtm); } else { @@ -1119,7 +1128,6 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result, *status = st; } - if (taosArrayAddAll(result, param.result) == NULL) { sifFreeParam(¶m); return TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index 54d28f4784..3edd61bd08 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -98,7 +98,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output } int32_t sz = taosArrayGetSize(nodes->stack) - 1; FstBuilderNodeUnfinished* un = taosArrayGet(nodes->stack, sz); - ASSERTS(un->last == NULL, "index-fst meet unexpected node"); + if (un->last != NULL) return; // FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition)); @@ -318,8 +318,6 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode // set_comm_input void fstStateSetCommInput(FstState* s, uint8_t inp) { - ASSERT(s->state == OneTransNext || s->state == OneTrans); - uint8_t val; COMMON_INDEX(inp, 0b111111, val); s->val = (s->val & fstStateDict[s->state].val) | val; @@ -327,7 +325,6 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) { // comm_input uint8_t fstStateCommInput(FstState* s, bool* null) { - ASSERT(s->state == OneTransNext || s->state == OneTrans); uint8_t v = s->val & 0b00111111; if (v == 0) { *null = true; @@ -340,7 +337,6 @@ uint8_t fstStateCommInput(FstState* s, bool* null) { // input_len uint64_t fstStateInputLen(FstState* s) { - ASSERT(s->state == OneTransNext || s->state == OneTrans); bool null = false; (void)fstStateCommInput(s, &null); return null ? 1 : 0; @@ -348,11 +344,9 @@ uint64_t fstStateInputLen(FstState* s) { // end_addr uint64_t fstStateEndAddrForOneTransNext(FstState* s, FstSlice* data) { - ASSERT(s->state == OneTransNext); return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s); } uint64_t fstStateEndAddrForOneTrans(FstState* s, FstSlice* data, PackSizes sizes) { - ASSERT(s->state == OneTrans); return FST_SLICE_LEN(data) - 1 - fstStateInputLen(s) - 1 // pack size - FST_GET_TRANSITION_PACK_SIZE(sizes) - FST_GET_OUTPUT_PACK_SIZE(sizes); } @@ -366,7 +360,6 @@ uint64_t fstStateEndAddrForAnyTrans(FstState* state, uint64_t version, FstSlice* } // input uint8_t fstStateInput(FstState* s, FstNode* node) { - ASSERT(s->state == OneTransNext || s->state == OneTrans); FstSlice* slice = &node->data; bool null = false; uint8_t inp = fstStateCommInput(s, &null); @@ -374,7 +367,6 @@ uint8_t fstStateInput(FstState* s, FstNode* node) { return null == false ? inp : data[node->start - 1]; } uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { - ASSERT(s->state == AnyTrans); FstSlice* slice = &node->data; uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size @@ -386,7 +378,6 @@ uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { // trans_addr CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) { - ASSERT(s->state == OneTransNext || s->state == OneTrans); FstSlice* slice = &node->data; if (s->state == OneTransNext) { return (CompiledAddr)(node->end) - 1; @@ -402,8 +393,6 @@ CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) { } } CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i) { - ASSERT(s->state == AnyTrans); - FstSlice* slice = &node->data; uint8_t tSizes = FST_GET_TRANSITION_PACK_SIZE(node->sizes); uint64_t at = node->start - fstStateNtransLen(s) - 1 - fstStateTransIndexSize(s, node->version, node->nTrans) - @@ -414,7 +403,6 @@ CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i // sizes PackSizes fstStateSizes(FstState* s, FstSlice* slice) { - ASSERT(s->state == OneTrans || s->state == AnyTrans); uint64_t i; if (s->state == OneTrans) { i = FST_SLICE_LEN(slice) - 1 - fstStateInputLen(s) - 1; @@ -427,8 +415,6 @@ PackSizes fstStateSizes(FstState* s, FstSlice* slice) { } // Output Output fstStateOutput(FstState* s, FstNode* node) { - ASSERT(s->state == OneTrans); - uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes); if (oSizes == 0) { return 0; @@ -441,8 +427,6 @@ Output fstStateOutput(FstState* s, FstNode* node) { return unpackUint64(data + i, oSizes); } Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { - ASSERT(s->state == AnyTrans); - uint8_t oSizes = FST_GET_OUTPUT_PACK_SIZE(node->sizes); if (oSizes == 0) { return 0; @@ -458,19 +442,14 @@ Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { // anyTrans specify function void fstStateSetFinalState(FstState* s, bool yes) { - ASSERT(s->state == AnyTrans); if (yes) { s->val |= 0b01000000; } return; } -bool fstStateIsFinalState(FstState* s) { - ASSERT(s->state == AnyTrans); - return (s->val & 0b01000000) == 0b01000000; -} +bool fstStateIsFinalState(FstState* s) { return (s->val & 0b01000000) == 0b01000000; } void fstStateSetStateNtrans(FstState* s, uint8_t n) { - ASSERT(s->state == AnyTrans); if (n <= 0b00111111) { s->val = (s->val & 0b11000000) | n; } @@ -478,7 +457,6 @@ void fstStateSetStateNtrans(FstState* s, uint8_t n) { } // state_ntrans uint8_t fstStateStateNtrans(FstState* s, bool* null) { - ASSERT(s->state == AnyTrans); *null = false; uint8_t n = s->val & 0b00111111; @@ -488,16 +466,13 @@ uint8_t fstStateStateNtrans(FstState* s, bool* null) { return n; } uint64_t fstStateTotalTransSize(FstState* s, uint64_t version, PackSizes sizes, uint64_t nTrans) { - ASSERT(s->state == AnyTrans); uint64_t idxSize = fstStateTransIndexSize(s, version, nTrans); return nTrans + (nTrans * FST_GET_TRANSITION_PACK_SIZE(sizes)) + idxSize; } uint64_t fstStateTransIndexSize(FstState* s, uint64_t version, uint64_t nTrans) { - ASSERT(s->state == AnyTrans); return (version >= 2 && nTrans > TRANS_INDEX_THRESHOLD) ? 256 : 0; } uint64_t fstStateNtransLen(FstState* s) { - ASSERT(s->state == AnyTrans); bool null = false; (void)fstStateStateNtrans(s, &null); return null == true ? 1 : 0; @@ -526,7 +501,6 @@ Output fstStateFinalOutput(FstState* s, uint64_t version, FstSlice* slice, PackS return unpackUint64(data + at, (uint8_t)oSizes); } uint64_t fstStateFindInput(FstState* s, FstNode* node, uint8_t b, bool* null) { - ASSERT(s->state == AnyTrans); FstSlice* slice = &node->data; if (node->version >= 2 && node->nTrans > TRANS_INDEX_THRESHOLD) { uint64_t at = node->start - fstStateNtransLen(s) - 1 // pack size @@ -672,17 +646,14 @@ bool fstNodeGetTransitionAddrAt(FstNode* node, uint64_t i, CompiledAddr* res) { bool s = true; FstState* st = &node->state; if (st->state == OneTransNext) { - ASSERT(i == 0); (void)fstStateTransAddr(st, node); } else if (st->state == OneTrans) { - ASSERT(i == 0); (void)fstStateTransAddr(st, node); } else if (st->state == AnyTrans) { (void)fstStateTransAddrForAnyTrans(st, node, i); } else if (FST_STATE_EMPTY_FINAL(node)) { s = false; } else { - ASSERT(0); } return s; } @@ -718,7 +689,6 @@ bool fstNodeFindInput(FstNode* node, uint8_t b, uint64_t* res) { bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode* builderNode) { int32_t sz = taosArrayGetSize(builderNode->trans); - ASSERT(sz < 256); if (sz == 0 && builderNode->isFinal && builderNode->finalOutput == 0) { return true; } else if (sz != 1 || builderNode->isFinal) { @@ -800,7 +770,6 @@ void fstBuilderInsertOutput(FstBuilder* b, FstSlice bs, Output in) { uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); if (prefixLen == FST_SLICE_LEN(s)) { - ASSERT(out == 0); return; } @@ -844,7 +813,6 @@ void fstBuilderCompileFrom(FstBuilder* b, uint64_t istate) { addr = fstBuilderCompile(b, bn); fstBuilderNodeDestroy(bn); - ASSERT(addr != NONE_ADDRESS); } fstUnFinishedNodesTopLastFreeze(b->unfinished, addr); return; diff --git a/source/libs/index/src/indexFstFile.c b/source/libs/index/src/indexFstFile.c index 69fee8d29d..5c6a39d13c 100644 --- a/source/libs/index/src/indexFstFile.c +++ b/source/libs/index/src/indexFstFile.c @@ -104,7 +104,10 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of do { char key[1024] = {0}; - ASSERT(strlen(ctx->file.buf) + 1 + 64 < sizeof(key)); + if (strlen(ctx->file.buf) + 1 + 64 >= sizeof(key)) { + return TSDB_CODE_INDEX_INVALID_FILE; + } + idxGenLRUKey(key, ctx->file.buf, blkId); LRUHandle* h = taosLRUCacheLookup(ctx->lru, key, strlen(key)); @@ -118,8 +121,10 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of if (left < kBlockSize) { nread = TMIN(left, len); int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset); - ASSERTS(bytes == nread, "index read incomplete data"); - if (bytes != nread) break; + if (bytes != nread) { + total = TSDB_CODE_INDEX_INVALID_FILE; + break; + } total += bytes; return total; @@ -129,7 +134,6 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of SDataBlock* blk = taosMemoryCalloc(1, cacheMemSize); blk->blockId = blkId; blk->nread = taosPReadFile(ctx->file.pFile, blk->buf, kBlockSize, blkId * kBlockSize); - ASSERTS(blk->nread <= kBlockSize, "index read incomplete data"); if (blk->nread < kBlockSize && blk->nread < len) { taosMemoryFree(blk); break; @@ -288,7 +292,6 @@ int32_t idxFileWrite(IdxFstFile* write, uint8_t* buf, uint32_t len) { // update checksum IFileCtx* ctx = write->wrt; int nWrite = ctx->write(ctx, buf, len); - ASSERTS(nWrite == len, "index write incomplete data"); if (nWrite != len) { code = TAOS_SYSTEM_ERROR(errno); return code; diff --git a/source/libs/index/src/indexFstNode.c b/source/libs/index/src/indexFstNode.c index b934cb0536..7f1a86bc55 100644 --- a/source/libs/index/src/indexFstNode.c +++ b/source/libs/index/src/indexFstNode.c @@ -97,9 +97,7 @@ void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { // bool fstBuilderNodeCompileTo(FstBuilderNode *b, IdxFile *wrt, CompiledAddr lastAddr, CompiledAddr // startAddr) { - // size_t sz = taosArrayGetSize(b->trans); -// assert(sz < 256); // if (FST_BUILDER_NODE_IS_FINAL(b) // && FST_BUILDER_NODE_TRANS_ISEMPTY(b) // && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { diff --git a/source/libs/index/src/indexFstRegister.c b/source/libs/index/src/indexFstRegister.c index e27ab939b3..a8c4365a44 100644 --- a/source/libs/index/src/indexFstRegister.c +++ b/source/libs/index/src/indexFstRegister.c @@ -57,8 +57,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { if (start >= sz && end >= sz) { return; } - ASSERTS(start >= end, "index-fst start lower than end"); - if (start < end) return; + if (start < end) { + return; + } int32_t s = (int32_t)start; int32_t e = (int32_t)end; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 1e81445d11..8c06296732 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -933,17 +933,20 @@ static int tfileWriteFooter(TFileWriter* write) { char buf[sizeof(FILE_MAGIC_NUMBER) + 1] = {0}; void* pBuf = (void*)buf; (void)taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER); - int nwrite = write->ctx->write(write->ctx, buf, (int32_t)strlen(buf)); + int nwrite = write->ctx->write(write->ctx, (uint8_t*)buf, (int32_t)strlen(buf)); indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx)); - ASSERTS(nwrite == sizeof(FILE_MAGIC_NUMBER), "index write incomplete data"); - return nwrite; + if (nwrite != sizeof(FILE_MAGIC_NUMBER)) { + return TAOS_SYSTEM_ERROR(errno); + } else { + return nwrite; + } } static int tfileReaderLoadHeader(TFileReader* reader) { // TODO simple tfile header later char buf[TFILE_HEADER_SIZE] = {0}; - int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); + int64_t nread = reader->ctx->readFrom(reader->ctx, (uint8_t*)buf, sizeof(buf), 0); if (nread == -1) { indexError("actual Read: %d, to read: %d, code:0x%x, filename: %s", (int)(nread), (int)sizeof(buf), errno, @@ -967,14 +970,13 @@ static int tfileReaderLoadFst(TFileReader* reader) { } int64_t ts = taosGetTimestampUs(); - int32_t nread = ctx->readFrom(ctx, buf, fstSize, reader->header.fstOffset); + int32_t nread = ctx->readFrom(ctx, (uint8_t*)buf, fstSize, reader->header.fstOffset); int64_t cost = taosGetTimestampUs() - ts; indexInfo("nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %d, time cost: %" PRId64 "us", nread, reader->header.fstOffset, fstSize, ctx->file.buf, size, cost); // we assuse fst size less than FST_MAX_SIZE - ASSERTS(nread > 0 && nread <= fstSize, "index read incomplete fst"); if (nread <= 0 || nread > fstSize) { - return -1; + return TSDB_CODE_INDEX_INVALID_FILE; } FstSlice st = fstSliceCreate((uint8_t*)buf, nread); @@ -989,8 +991,10 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* IFileCtx* ctx = reader->ctx; // add block cache char block[4096] = {0}; - int32_t nread = ctx->readFrom(ctx, block, sizeof(block), offset); - ASSERT(nread >= sizeof(uint32_t)); + int32_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset); + if (nread < sizeof(uint32_t)) { + return TSDB_CODE_INDEX_INVALID_FILE; + } char* p = block; int32_t nid = *(int32_t*)p; @@ -1007,7 +1011,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* memset(block, 0, sizeof(block)); offset += sizeof(block); - nread = ctx->readFrom(ctx, block, sizeof(block), offset); + nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset); memcpy(buf + left, block, sizeof(uint64_t) - left); (void)taosArrayPush(result, (uint64_t*)buf); @@ -1026,13 +1030,14 @@ static int tfileReaderVerify(TFileReader* reader) { int size = ctx->size(ctx); if (size < sizeof(tMagicNumber) || size <= sizeof(reader->header)) { - return -1; - } else if (ctx->readFrom(ctx, buf, sizeof(tMagicNumber), size - sizeof(tMagicNumber)) != sizeof(tMagicNumber)) { - return -1; + return TSDB_CODE_INDEX_INVALID_FILE; + } else if (ctx->readFrom(ctx, (uint8_t*)buf, sizeof(tMagicNumber), size - sizeof(tMagicNumber)) != + sizeof(tMagicNumber)) { + return TSDB_CODE_INDEX_INVALID_FILE; } (void)taosDecodeFixedU64(buf, &tMagicNumber); - return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : -1; + return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : TSDB_CODE_INDEX_INVALID_FILE; } void tfileReaderRef(TFileReader* rd) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index ae4dc280b4..7e84ef8482 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11072,7 +11072,10 @@ static int32_t createStreamReqVersionInfo(SSDataBlock* pBlock, SArray** pArray, for (int32_t i = 0; i < pBlock->info.rows; ++i) { SVgroupVer v = {.vgId = *(int32_t*)colDataGetData(pCol1, i), .ver = *(int64_t*)colDataGetData(pCol2, i)}; - (void)taosArrayPush(*pArray, &v); + if((taosArrayPush(*pArray, &v)) == NULL) { + taosArrayDestroy(*pArray); + return terrno; + } } } else { int32_t precision = (pInterval->interval > 0) ? pInterval->precision : TSDB_TIME_PRECISION_MILLI; diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 83e55791d2..29fb18ef07 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -420,7 +420,10 @@ int32_t remoteChkpGetDelFile(char* path, SArray* toDel) { } void cleanDir(const char* pPath, const char* id) { - ASSERT(pPath != NULL); + if (pPath == NULL) { + stError("%s try to clean dir, but path is NULL", id); + return; + } if (taosIsDir(pPath)) { taosRemoveDir(pPath); @@ -2603,7 +2606,7 @@ void taskDbDestroy(void* pDb, bool flush) { stDebug("succ to destroy stream backend:%p", wrapper); int8_t nCf = tListLen(ginitDict); - if (flush && wrapper->removeAllFiles == 0) { + if (flush && wrapper->removeAllFiles == 0) { if (wrapper->db && wrapper->pCf) { rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create(); rocksdb_flushoptions_set_wait(flushOpt, 1); diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 1c129a0ed1..5054339e8e 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -45,9 +45,6 @@ // static inline int64_t syncNodeAbs64(int64_t a, int64_t b) { - ASSERT(a >= 0); - ASSERT(b >= 0); - int64_t c = a > b ? a - b : b - a; return c; } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 179bb4d503..d947a488bf 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -3523,6 +3523,9 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) { return 0; } SyncTerm matchTerm = syncLogBufferGetLastMatchTerm(ths->pLogBuf); + if (matchTerm < 0) { + return TSDB_CODE_SYN_INTERNAL_ERROR; + } if (pMsg->currentTerm == matchTerm) { (void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex); } diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c index 22947bdd8e..5e6204dde8 100644 --- a/source/libs/sync/src/syncPipeline.c +++ b/source/libs/sync/src/syncPipeline.c @@ -46,8 +46,8 @@ int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) { int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry) { int32_t code = 0; + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); SyncIndex index = pEntry->index; if (index - pBuf->startIndex >= pBuf->size) { @@ -102,13 +102,13 @@ int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt pBuf->entries[index % pBuf->size] = tmp; pBuf->endIndex = index + 1; - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return 0; _err: - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); taosMsleep(1); TAOS_RETURN(code); } @@ -134,7 +134,11 @@ int32_t syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncI if (prevIndex >= pBuf->startIndex) { pEntry = pBuf->entries[(prevIndex + pBuf->size) % pBuf->size].pItem; - ASSERTS(pEntry != NULL, "no log entry found"); + if (pEntry == NULL) { + sError("vgId:%d, failed to get pre log term since no log entry found", pNode->vgId); + *pSyncTerm = -1; + TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR); + } prevLogTerm = pEntry->term; *pSyncTerm = prevLogTerm; return 0; @@ -142,9 +146,18 @@ int32_t syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncI if (pMgr && pMgr->startIndex <= prevIndex && prevIndex < pMgr->endIndex) { int64_t timeMs = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].timeMs; - ASSERTS(timeMs != 0, "no log entry found"); + if (timeMs == 0) { + sError("vgId:%d, failed to get pre log term since timeMs is 0", pNode->vgId); + *pSyncTerm = -1; + TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR); + } prevLogTerm = pMgr->states[(prevIndex + pMgr->size) % pMgr->size].term; - ASSERT(prevIndex == 0 || prevLogTerm != 0); + if (!(prevIndex == 0 || prevLogTerm != 0)) { + sError("vgId:%d, failed to get pre log term prevIndex:%" PRId64 ", prevLogTerm:%" PRId64, pNode->vgId, prevIndex, + prevLogTerm); + *pSyncTerm = -1; + TAOS_RETURN(TSDB_CODE_SYN_INTERNAL_ERROR); + } *pSyncTerm = prevLogTerm; return 0; } @@ -289,7 +302,7 @@ int32_t syncLogBufferInitWithoutLock(SSyncLogBuffer* pBuf, SSyncNode* pNode) { pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex); // validate - (void)syncLogBufferValidate(pBuf); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return 0; _exit: @@ -307,8 +320,8 @@ int32_t syncLogBufferInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) { } int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) { + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); for (SyncIndex index = pBuf->startIndex; index < pBuf->endIndex; index++) { SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem; if (pEntry == NULL) continue; @@ -321,15 +334,19 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) { if (code < 0) { sError("vgId:%d, failed to re-initialize sync log buffer since %s.", pNode->vgId, tstrerror(code)); } - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return code; } FORCE_INLINE SyncTerm syncLogBufferGetLastMatchTermWithoutLock(SSyncLogBuffer* pBuf) { SyncIndex index = pBuf->matchIndex; SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem; - ASSERT(pEntry != NULL); + if (pEntry == NULL) { + sError("failed to get last match term since entry is null"); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } return pEntry->term; } @@ -348,8 +365,8 @@ bool syncLogBufferIsEmpty(SSyncLogBuffer* pBuf) { } int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm) { + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); int32_t code = 0; SyncIndex index = pEntry->index; SyncIndex prevIndex = pEntry->index - 1; @@ -357,6 +374,12 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt SSyncRaftEntry* pExist = NULL; bool inBuf = true; + if (lastMatchTerm < 0) { + sError("vgId:%d, failed to accept, lastMatchTerm:%" PRId64, pNode->vgId, lastMatchTerm); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } + if (index <= pBuf->commitIndex) { sTrace("vgId:%d, already committed. index:%" PRId64 ", term:%" PRId64 ". log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", @@ -364,7 +387,11 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt pBuf->endIndex); SyncTerm term = -1; code = syncLogReplGetPrevLogTerm(NULL, pNode, index + 1, &term); - ASSERT(pEntry->term >= 0); + if (pEntry->term < 0) { + sError("vgId:%d, failed to accept, pEntry->term:%" PRId64, pNode->vgId, pEntry->term); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } if (term == pEntry->term) { code = 0; } @@ -401,7 +428,12 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt // check current in buffer code = syncLogBufferGetOneEntry(pBuf, pNode, index, &inBuf, &pExist); if (pExist != NULL) { - ASSERT(pEntry->index == pExist->index); + if (pEntry->index != pExist->index) { + sError("vgId:%d, failed to accept, pEntry->index:%" PRId64 ", pExist->index:%" PRId64, pNode->vgId, pEntry->index, + pExist->index); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } if (pEntry->term != pExist->term) { (void)syncLogBufferRollback(pBuf, pNode, index); } else { @@ -411,7 +443,14 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt pBuf->endIndex); SyncTerm existPrevTerm = -1; (void)syncLogReplGetPrevLogTerm(NULL, pNode, index, &existPrevTerm); - ASSERT(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm)); + if (!(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm))) { + sError("vgId:%d, failed to accept, pEntry->term:%" PRId64 ", pExist->indexpExist->term:%" PRId64 + ", pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64 ", prevTerm:%" PRId64 + ", existPrevTerm:%" PRId64, + pNode->vgId, pEntry->term, pExist->term, pEntry->index, pBuf->matchIndex, prevTerm, existPrevTerm); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } code = 0; goto _out; } @@ -446,8 +485,8 @@ _out: syncEntryDestroy(pExist); pExist = NULL; } - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); TAOS_RETURN(code); } @@ -479,8 +518,8 @@ int32_t syncLogStorePersist(SSyncLogStore* pLogStore, SSyncNode* pNode, SSyncRaf } int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm, char* str) { + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); SSyncLogStore* pLogStore = pNode->pLogStore; int64_t matchIndex = pBuf->matchIndex; @@ -488,7 +527,11 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p while (pBuf->matchIndex + 1 < pBuf->endIndex) { int64_t index = pBuf->matchIndex + 1; - ASSERT(index >= 0); + if (index < 0) { + sError("vgId:%d, failed to proceed index:%" PRId64, pNode->vgId, index); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } // try to proceed SSyncLogBufEntry* pBufEntry = &pBuf->entries[index % pBuf->size]; @@ -501,14 +544,37 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p goto _out; } - ASSERT(index == pEntry->index); + if (index != pEntry->index) { + sError("vgId:%d, failed to proceed index:%" PRId64 ", pEntry->index:%" PRId64, pNode->vgId, index, pEntry->index); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } // match SSyncRaftEntry* pMatch = pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem; - ASSERT(pMatch != NULL); - ASSERT(pMatch->index == pBuf->matchIndex); - ASSERT(pMatch->index + 1 == pEntry->index); - ASSERT(prevLogIndex == pMatch->index); + if (pMatch == NULL) { + sError("vgId:%d, failed to proceed since pMatch is null", pNode->vgId); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } + if (pMatch->index != pBuf->matchIndex) { + sError("vgId:%d, failed to proceed, pMatch->index:%" PRId64 ", pBuf->matchIndex:%" PRId64, pNode->vgId, + pMatch->index, pBuf->matchIndex); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } + if (pMatch->index + 1 != pEntry->index) { + sError("vgId:%d, failed to proceed, pMatch->index:%" PRId64 ", pEntry->index:%" PRId64, pNode->vgId, + pMatch->index, pEntry->index); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } + if (prevLogIndex != pMatch->index) { + sError("vgId:%d, failed to proceed, prevLogIndex:%" PRId64 ", pMatch->index:%" PRId64, pNode->vgId, prevLogIndex, + pMatch->index); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } if (pMatch->term != prevLogTerm) { sInfo( @@ -567,7 +633,12 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p // replicate on demand (void)syncNodeReplicateWithoutLock(pNode); - ASSERT(pEntry->index == pBuf->matchIndex); + if (pEntry->index != pBuf->matchIndex) { + sError("vgId:%d, failed to proceed, pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64, pNode->vgId, + pEntry->index, pBuf->matchIndex); + code = TSDB_CODE_SYN_INTERNAL_ERROR; + goto _out; + } // update my match index matchIndex = pBuf->matchIndex; @@ -579,8 +650,8 @@ _out: if (pMatchTerm) { *pMatchTerm = pBuf->entries[(matchIndex + pBuf->size) % pBuf->size].pItem->term; } - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return matchIndex; } @@ -643,17 +714,36 @@ _exit: } int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf) { - ASSERT(pBuf->startIndex <= pBuf->matchIndex); - ASSERT(pBuf->commitIndex <= pBuf->matchIndex); - ASSERT(pBuf->matchIndex < pBuf->endIndex); - ASSERT(pBuf->endIndex - pBuf->startIndex <= pBuf->size); - ASSERT(pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem); + if (pBuf->startIndex > pBuf->matchIndex) { + sError("failed to validate, pBuf->startIndex:%" PRId64 ", pBuf->matchIndex:%" PRId64, pBuf->startIndex, + pBuf->matchIndex); + return TSDB_CODE_SYN_INTERNAL_ERROR; + } + if (pBuf->commitIndex > pBuf->matchIndex) { + sError("failed to validate, pBuf->commitIndex:%" PRId64 ", pBuf->matchIndex:%" PRId64, pBuf->commitIndex, + pBuf->matchIndex); + return TSDB_CODE_SYN_INTERNAL_ERROR; + } + if (pBuf->matchIndex >= pBuf->endIndex) { + sError("failed to validate, pBuf->matchIndex:%" PRId64 ", pBuf->endIndex:%" PRId64, pBuf->matchIndex, + pBuf->endIndex); + return TSDB_CODE_SYN_INTERNAL_ERROR; + } + if (pBuf->endIndex - pBuf->startIndex > pBuf->size) { + sError("failed to validate, pBuf->endIndex:%" PRId64 ", pBuf->startIndex:%" PRId64 ", pBuf->size:%" PRId64, + pBuf->endIndex, pBuf->startIndex, pBuf->size); + return TSDB_CODE_SYN_INTERNAL_ERROR; + } + if (pBuf->entries[(pBuf->matchIndex + pBuf->size) % pBuf->size].pItem == NULL) { + sError("failed to validate since pItem is null"); + return TSDB_CODE_SYN_INTERNAL_ERROR; + } return 0; } int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t commitIndex) { + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); SSyncLogStore* pLogStore = pNode->pLogStore; SSyncFSM* pFsm = pNode->pFsm; @@ -778,15 +868,18 @@ _out: syncEntryDestroy(pNextEntry); pNextEntry = NULL; } - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); TAOS_RETURN(code); } void syncLogReplReset(SSyncLogReplMgr* pMgr) { if (pMgr == NULL) return; - ASSERT(pMgr->startIndex >= 0); + if (pMgr->startIndex < 0) { + sError("failed to reset, pMgr->startIndex:%" PRId64, pMgr->startIndex); + return; + } for (SyncIndex index = pMgr->startIndex; index < pMgr->endIndex; index++) { (void)memset(&pMgr->states[index % pMgr->size], 0, sizeof(pMgr->states[0])); } @@ -1285,13 +1378,13 @@ int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex } if (pBuf->endIndex != toIndex) return TSDB_CODE_SYN_INTERNAL_ERROR; - (void)syncLogBufferValidate(pBuf); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return 0; } int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) { + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); (void)taosThreadMutexLock(&pBuf->mutex); - (void)syncLogBufferValidate(pBuf); SyncIndex lastVer = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore); if (lastVer != pBuf->matchIndex) return TSDB_CODE_SYN_INTERNAL_ERROR; SyncIndex index = pBuf->endIndex - 1; @@ -1308,8 +1401,8 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) { SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i]; syncLogReplReset(pMgr); } - (void)syncLogBufferValidate(pBuf); (void)taosThreadMutexUnlock(&pBuf->mutex); + TAOS_CHECK_RETURN(syncLogBufferValidate(pBuf)); return 0; } diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 820075787f..e8172385b2 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -240,6 +240,7 @@ typedef struct { void* pThrd; queue qmsg; TdThreadMutex mtx; // protect qmsg; + int64_t num; } SAsyncItem; typedef struct { diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 908468f094..6096f69ca2 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -30,6 +30,8 @@ static int32_t FAST_FAILURE_LIMIT = 1; static int64_t httpDefaultChanId = -1; +static int64_t httpSeqNum = 0; + typedef struct SHttpModule { uv_loop_t* loop; SAsyncPool* asyncPool; @@ -50,6 +52,7 @@ typedef struct SHttpMsg { EHttpCompFlag flag; int8_t quit; int64_t chanId; + int64_t seq; } SHttpMsg; typedef struct SHttpClient { @@ -62,6 +65,7 @@ typedef struct SHttpClient { uint16_t port; struct sockaddr_in dest; int64_t chanId; + int64_t seq; } SHttpClient; typedef struct SHttpConnList { @@ -193,14 +197,14 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, uint32_t ip = 0; int32_t code = taosGetIpv4FromFqdn(server, &ip); if (code) { - tError("http-report failed to resolving domain names: %s", server); + tError("http-report failed to resolving domain names %s, reason: %s", server, tstrerror(code)); return TSDB_CODE_RPC_FQDN_ERROR; } char buf[256] = {0}; tinet_ntoa(buf, ip); int ret = uv_ip4_addr(buf, port, dest); if (ret != 0) { - tError("http-report failed to get addr %s", uv_err_name(ret)); + tError("http-report failed to get addr, reason:%s", uv_err_name(ret)); return TSDB_CODE_THIRDPARTY_ERROR; } return 0; @@ -215,14 +219,15 @@ static void* httpThread(void* arg) { static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg) { + int64_t seqNum = atomic_fetch_add_64(&httpSeqNum, 1); if (server == NULL || uri == NULL) { - tError("http-report failed to report to invalid addr, chanId:%" PRId64 "", chanId); + tError("http-report failed to report to invalid addr, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seqNum); *httpMsg = NULL; return TSDB_CODE_INVALID_PARA; } if (pCont == NULL || contLen == 0) { - tError("http-report failed to report empty packet, chanId:%" PRId64 "", chanId); + tError("http-report failed to report empty packet, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seqNum); *httpMsg = NULL; return TSDB_CODE_INVALID_PARA; } @@ -233,6 +238,7 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, return TSDB_CODE_OUT_OF_MEMORY; } + msg->seq = seqNum; msg->port = port; msg->server = taosStrdup(server); msg->uri = taosStrdup(uri); @@ -259,7 +265,11 @@ static void httpDestroyMsg(SHttpMsg* msg) { taosMemoryFree(msg->cont); taosMemoryFree(msg); } -static void httpDestroyMsgWrapper(void* cont, void* param) { httpDestroyMsg((SHttpMsg*)cont); } +static void httpDestroyMsgWrapper(void* cont, void* param) { + SHttpMsg* pMsg = cont; + tWarn("http-report destroy msg, chanId:%" PRId64 ", seq:%" PRId64 "", pMsg->chanId, pMsg->seq); + httpDestroyMsg(pMsg); +} static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) { SHttpMsg *msg = NULL, *quitMsg = NULL; @@ -272,6 +282,8 @@ static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) { QUEUE_REMOVE(h); msg = QUEUE_DATA(h, SHttpMsg, q); if (!msg->quit) { + tError("http-report failed to report chanId:%" PRId64 ",seq:%" PRId64 ", reason: %s", msg->chanId, msg->seq, + tstrerror(TSDB_CODE_HTTP_MODULE_QUIT)); httpDestroyMsg(msg); } else { quitMsg = msg; @@ -281,6 +293,25 @@ static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) { QUEUE_PUSH(&item->qmsg, &quitMsg->q); } } +static void httpTrace(queue* q) { + if (!(rpcDebugFlag & DEBUG_DEBUG) || (QUEUE_IS_EMPTY(q))) { + return; + } + + int64_t startSeq = 0, endSeq = 0; + SHttpMsg* msg = NULL; + + queue* h = QUEUE_HEAD(q); + msg = QUEUE_DATA(h, SHttpMsg, q); + startSeq = msg->seq; + + h = QUEUE_TAIL(q); + msg = QUEUE_DATA(h, SHttpMsg, q); + endSeq = msg->seq; + + tDebug("http-report process msg, start_seq:%" PRId64 ", end_seq:%" PRId64 ", max_seq:%" PRId64 "", startSeq, endSeq, + atomic_load_64(&httpSeqNum) - 1); +} static void httpAsyncCb(uv_async_t* handle) { SAsyncItem* item = handle->data; @@ -290,7 +321,7 @@ static void httpAsyncCb(uv_async_t* handle) { queue wq; QUEUE_INIT(&wq); - static int32_t BATCH_SIZE = 5; + static int32_t BATCH_SIZE = 20; int32_t count = 0; (void)taosThreadMutexLock(&item->mtx); @@ -303,6 +334,8 @@ static void httpAsyncCb(uv_async_t* handle) { } (void)taosThreadMutexUnlock(&item->mtx); + httpTrace(&wq); + while (!QUEUE_IS_EMPTY(&wq)) { queue* h = QUEUE_HEAD(&wq); QUEUE_REMOVE(h); @@ -345,47 +378,50 @@ static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested } static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { + STUB_RAND_NETWORK_ERR(nread); SHttpClient* cli = handle->data; if (nread < 0) { - tError("http-report recv error:%s", uv_strerror(nread)); + tError("http-report recv error:%s, seq:%" PRId64 "", uv_strerror(nread), cli->seq); } else { - tTrace("http-report succ to recv %d bytes", (int32_t)nread); + tTrace("http-report succ to recv %d bytes, seq:%" PRId64 "", (int32_t)nread, cli->seq); } if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } } static void clientSentCb(uv_write_t* req, int32_t status) { + STUB_RAND_NETWORK_ERR(status); SHttpClient* cli = req->data; if (status != 0) { - tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, - cli->port, cli->chanId); + tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "", + uv_strerror(status), cli->addr, cli->port, cli->chanId, cli->seq); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } return; } else { - tTrace("http-report succ to send data, chanId:%" PRId64 "", cli->chanId); + tTrace("http-report succ to send data, chanId:%" PRId64 ", seq:%" PRId64 "", cli->chanId, cli->seq); } + status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb); if (status != 0) { - tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, - cli->port, cli->chanId); + tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "", + uv_strerror(status), cli->addr, cli->port, cli->chanId, cli->seq); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } } } static void clientConnCb(uv_connect_t* req, int32_t status) { + STUB_RAND_NETWORK_ERR(status); SHttpClient* cli = req->data; int64_t chanId = cli->chanId; SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); if (status != 0) { httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); - - tError("http-report failed to conn to server, reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), - cli->addr, cli->port, chanId); + tError("http-report failed to conn to server, reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "", + uv_strerror(status), cli->addr, cli->port, chanId, cli->seq); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } @@ -398,8 +434,8 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb); if (0 != status) { - tError("http-report failed to send data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, - cli->port, chanId); + tError("http-report failed to send data,reason:%s, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 "", + uv_strerror(status), cli->addr, cli->port, chanId, cli->seq); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } @@ -412,7 +448,7 @@ int32_t httpSendQuit(SHttpModule* http, int64_t chanId) { if (msg == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - + msg->seq = atomic_fetch_add_64(&httpSeqNum, 1); msg->quit = 1; msg->chanId = chanId; @@ -442,10 +478,11 @@ static void httpWalkCb(uv_handle_t* handle, void* arg) { return; } static void httpHandleQuit(SHttpMsg* msg) { + int64_t seq = msg->seq; int64_t chanId = msg->chanId; taosMemoryFree(msg); - tDebug("http-report receive quit, chanId:%" PRId64 "", chanId); + tDebug("http-report receive quit, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, seq); SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); if (http == NULL) return; uv_walk(http->loop, httpWalkCb, NULL); @@ -542,7 +579,7 @@ static void httpHandleReq(SHttpMsg* msg) { code = TSDB_CODE_OUT_OF_MEMORY; goto END; } - + cli->seq = msg->seq; cli->conn.data = cli; cli->tcp.data = cli; cli->req.data = cli; @@ -556,8 +593,8 @@ static void httpHandleReq(SHttpMsg* msg) { cli->wbuf = wb; cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE); if (cli->rbuf == NULL) { - tError("http-report failed to alloc read buf, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, - chanId, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("http-report failed to alloc read buf, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ",reason:%s", cli->addr, + cli->port, chanId, cli->seq, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); destroyHttpClient(cli); (void)taosReleaseRef(httpRefMgt, chanId); return; @@ -565,8 +602,8 @@ static void httpHandleReq(SHttpMsg* msg) { int err = uv_tcp_init(http->loop, &cli->tcp); if (err != 0) { - tError("http-report failed to init socket handle, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, - chanId, uv_strerror(err)); + tError("http-report failed to init socket handle, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", + cli->addr, cli->port, chanId, cli->seq, uv_strerror(err)); destroyHttpClient(cli); (void)taosReleaseRef(httpRefMgt, chanId); return; @@ -575,8 +612,8 @@ static void httpHandleReq(SHttpMsg* msg) { // set up timeout to avoid stuck; int32_t fd = taosCreateSocketWithTimeout(5000); if (fd < 0) { - tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, - tstrerror(TAOS_SYSTEM_ERROR(errno))); + tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr, + cli->port, chanId, cli->seq, tstrerror(TAOS_SYSTEM_ERROR(errno))); destroyHttpClient(cli); (void)taosReleaseRef(httpRefMgt, chanId); return; @@ -584,8 +621,9 @@ static void httpHandleReq(SHttpMsg* msg) { int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd); if (ret != 0) { - tError("http-report failed to open socket, reason:%s, dst:%s:%d, chanId:%" PRId64 ",reason:%s", uv_strerror(ret), - cli->addr, cli->port, chanId, uv_strerror(ret)); + tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr, + cli->port, chanId, cli->seq, uv_strerror(ret)); + destroyHttpClient(cli); (void)taosReleaseRef(httpRefMgt, chanId); return; @@ -593,8 +631,8 @@ static void httpHandleReq(SHttpMsg* msg) { ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb); if (ret != 0) { - tError("http-report failed to connect to http-server,dst:%s:%d, chanId:%" PRId64 ",reson:%s", cli->addr, cli->port, - chanId, uv_strerror(ret)); + tError("http-report failed to connect to http-server,dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reson:%s", + cli->addr, cli->port, chanId, cli->seq, uv_strerror(ret)); httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); destroyHttpClient(cli); } @@ -603,8 +641,8 @@ static void httpHandleReq(SHttpMsg* msg) { END: if (ignore == false) { - tError("http-report failed to report to addr: %s:%d, chanId:%" PRId64 ", reason:%s", msg->server, msg->port, chanId, - tstrerror(code)); + tError("http-report failed to report to addr: %s:%d, chanId:%" PRId64 ",seq:%" PRId64 " reason:%s", msg->server, + msg->port, chanId, msg->seq, tstrerror(code)); } httpDestroyMsg(msg); taosMemoryFree(header); @@ -652,6 +690,7 @@ static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, code = TSDB_CODE_HTTP_MODULE_QUIT; goto _ERROR; } + tDebug("http-report start to report, chanId:%" PRId64 ", seq:%" PRId64 "", chanId, msg->seq); code = transAsyncSend(load->asyncPool, &(msg->q)); if (code != 0) { @@ -661,6 +700,11 @@ static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, msg = NULL; _ERROR: + + if (code != 0) { + tError("http-report failed to report reason:%s, chanId:%" PRId64 ", seq:%" PRId64 "", tstrerror(code), chanId, + msg->seq); + } httpDestroyMsg(msg); if (load != NULL) taosReleaseRef(httpRefMgt, chanId); return code; @@ -684,6 +728,7 @@ int64_t transInitHttpChanImpl(); static void transHttpEnvInit() { httpRefMgt = taosOpenRef(64, transHttpDestroyHandle); httpDefaultChanId = transInitHttpChanImpl(); + httpSeqNum = 0; } void transHttpEnvDestroy() { @@ -748,7 +793,7 @@ int64_t taosInitHttpChan() { } void taosDestroyHttpChan(int64_t chanId) { - tDebug("http-report send quit, chanId:%" PRId64 "", chanId); + tDebug("http-report send quit, chanId: %" PRId64 "", chanId); int ret = 0; SHttpModule* load = taosAcquireRef(httpRefMgt, chanId); @@ -772,4 +817,4 @@ void taosDestroyHttpChan(int64_t chanId) { (void)taosReleaseRef(httpRefMgt, chanId); (void)taosRemoveRef(httpRefMgt, chanId); -} \ No newline at end of file +} diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 862a74c72b..336a182153 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -923,10 +923,12 @@ static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_ } } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { - // impl later + STUB_RAND_NETWORK_ERR(nread); + if (handle->data == NULL) { return; } + SCliConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -1117,6 +1119,8 @@ static bool cliHandleNoResp(SCliConn* conn) { return res; } static void cliSendCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); + SCliConn* pConn = transReqQueueRemove(req); if (pConn == NULL) return; @@ -1434,6 +1438,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { cliSendBatch(conn); } static void cliSendBatchCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); SCliConn* conn = req->data; SCliThrd* thrd = conn->hostThrd; SCliBatch* p = conn->pBatch; @@ -1523,6 +1528,8 @@ void cliConnCb(uv_connect_t* req, int status) { pConn->timer = NULL; } + STUB_RAND_NETWORK_ERR(status); + if (status != 0) { cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); if (timeout == false) { @@ -2193,7 +2200,6 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { SCliMsg* cliMsg = transQueueGet(&conn->cliMsgs, i); if (cliMsg->type == Release) { - ASSERTS(pMsg == NULL, "trans-cli recv invaid release-req"); tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, conn->refId); cliDestroyConn(conn, true); @@ -3015,7 +3021,6 @@ _exception: } int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { if (transpointId == NULL) { - ASSERT(0); return TSDB_CODE_INVALID_PARA; } int32_t code = 0; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5d82e157b3..a0836eae3d 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -183,7 +183,7 @@ int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { } } } else { - ASSERTS(0, "invalid read from sock buf"); + tError("failed to reset buffer, total:%d, len:%d, reason:%s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG)); return TSDB_CODE_INVALID_MSG; } return 0; @@ -869,3 +869,8 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { *ppBuf = pBuf; return len; } + +// int32_t transGenRandomError(int32_t status) { +// STUB_RAND_NETWORK_ERR(status) +// return status; +// } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index c1b934c812..53a7dee7be 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -468,8 +468,8 @@ static bool uvHandleReq(SSvrConn* pConn) { tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, pConn->refId); - ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); if (transMsg.info.handle == NULL) { + tError("%s handle %p conn:%p handle failed to init" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn); return false; } @@ -493,6 +493,8 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { SSvrConn* conn = cli->data; SWorkThrd* pThrd = conn->hostThrd; + STUB_RAND_NETWORK_ERR(nread); + if (true == pThrd->quit) { tInfo("work thread received quit msg, destroy conn"); destroyConn(conn, true); @@ -553,6 +555,7 @@ void uvOnTimeoutCb(uv_timer_t* handle) { } void uvOnSendCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); SSvrConn* conn = transReqQueueRemove(req); if (conn == NULL) return; @@ -602,6 +605,7 @@ void uvOnSendCb(uv_write_t* req, int status) { } } static void uvOnPipeWriteCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); if (status == 0) { tTrace("success to dispatch conn to work thread"); } else { @@ -949,6 +953,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { } } void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { + STUB_RAND_NETWORK_ERR(nread); if (nread < 0) { if (nread != UV_EOF) { tError("read error %s", uv_err_name(nread)); @@ -960,15 +965,19 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { return; } // free memory allocated by - ASSERTS(nread == strlen(notify), "trans-svr mem corrupted"); - ASSERTS(buf->base[0] == notify[0], "trans-svr mem corrupted"); + if (nread != strlen(notify) || strncmp(buf->base, notify, strlen(notify)) != 0) { + tError("failed to read pip "); + taosMemoryFree(buf->base); + uv_close((uv_handle_t*)q, NULL); + } + taosMemoryFree(buf->base); SWorkThrd* pThrd = q->data; uv_pipe_t* pipe = (uv_pipe_t*)q; if (!uv_pipe_pending_count(pipe)) { - tError("No pending count"); + tError("no pending count, unexpected error"); uv_close((uv_handle_t*)q, NULL); return; } @@ -1041,9 +1050,11 @@ void* transAcceptThread(void* arg) { return NULL; } void uvOnPipeConnectionCb(uv_connect_t* connect, int status) { + STUB_RAND_NETWORK_ERR(status); if (status != 0) { return; - } + }; + SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req); (void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); } @@ -1344,25 +1355,32 @@ static void uvPipeListenCb(uv_stream_t* handle, int status) { uv_pipe_t* pipe = &(srv->pipe[srv->numOfWorkerReady][0]); int ret = uv_pipe_init(srv->loop, pipe, 1); - ASSERTS(ret == 0, "trans-svr failed to init pipe"); - if (ret != 0) return; + if (ret != 0) { + tError("trans-svr failed to init pipe, errmsg: %s", uv_err_name(ret)); + } ret = uv_accept((uv_stream_t*)&srv->pipeListen, (uv_stream_t*)pipe); - ASSERTS(ret == 0, "trans-svr failed to accept pipe msg"); - if (ret != 0) return; + if (ret != 0) { + tError("trans-svr failed to accept pipe, errmsg: %s", uv_err_name(ret)); + return; + } ret = uv_is_readable((uv_stream_t*)pipe); - ASSERTS(ret == 1, "trans-svr pipe status corrupted"); - if (ret != 1) return; - + if (ret != 1) { + tError("trans-svr failed to check pipe, pip not readable"); + return; + } ret = uv_is_writable((uv_stream_t*)pipe); - ASSERTS(ret == 1, "trans-svr pipe status corrupted"); - if (ret != 1) return; + if (ret != 1) { + tError("trans-svr failed to check pipe, pip not writable"); + return; + } ret = uv_is_closing((uv_handle_t*)pipe); - ASSERTS(ret == 0, "trans-svr pipe status corrupted"); - if (ret != 0) return; - + if (ret != 0) { + tError("trans-svr failed to check pipe, pip is closing"); + return; + } srv->numOfWorkerReady++; } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index c274c7fbab..144baeb148 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -904,7 +904,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { int32_t code = _fstat64(pFile->fd, &fileStat); #else struct stat fileStat; - int32_t code = fstat(pFile->fd, &fileStat); + int32_t code = fstat(pFile->fd, &fileStat); #endif if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -1611,7 +1611,7 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) { #ifdef WINDOWS return _fseeki64(file, offset, whence); #else - int code = fseeko(file, offset, whence); + int code = fseeko(file, offset, whence); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); } diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 91eb7763bc..49a5c2a2a2 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -24,7 +24,7 @@ int32_t tsRandErrChance = 1; int64_t tsRandErrDivisor = 10001; -int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE); +int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE | RAND_ERR_NETWORK); threadlocal bool tsEnableRandErr = 0; #if defined(USE_TD_MEMORY) || defined(USE_ADDR2LINE) @@ -385,7 +385,7 @@ char *taosStrdup(const char *ptr) { } #endif - return tstrdup(ptr); + return tstrdup(ptr); #endif } diff --git a/source/util/src/tbloomfilter.c b/source/util/src/tbloomfilter.c index 2108389aec..c87c482167 100644 --- a/source/util/src/tbloomfilter.c +++ b/source/util/src/tbloomfilter.c @@ -79,6 +79,7 @@ _error: int32_t tBloomFilterPutHash(SBloomFilter* pBF, uint64_t hash1, uint64_t hash2) { if (tBloomFilterIsFull(pBF)) { + uError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_INVALID_PARA)); return TSDB_CODE_FAILED; } bool hasChange = false; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 7c7afe8d6f..6701842ec9 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -389,6 +389,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_CHARSET, "charset not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_LOCALE, "locale not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR, "ttlChangeOnWrite not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_EN_WHITELIST, "enableWhiteList not match") +TAOS_DEFINE_ERROR(TSDB_CODE_MNODE_STOPPED, "Mnode stopped") // vnode TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, "Vnode is closed or removed") diff --git a/source/util/src/tscalablebf.c b/source/util/src/tscalablebf.c index 5a5cba5f0a..4fac5a2b4f 100644 --- a/source/util/src/tscalablebf.c +++ b/source/util/src/tscalablebf.c @@ -118,6 +118,8 @@ int32_t tScalableBfPut(SScalableBf* pSBf, const void* keyBuf, uint32_t len, int3 } SBloomFilter* pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1); + QUERY_CHECK_NULL(pNormalBf, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); + if (tBloomFilterIsFull(pNormalBf)) { code = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth, pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO, &pNormalBf); diff --git a/tests/army/query/last/test_last.py b/tests/army/query/last/test_last.py new file mode 100644 index 0000000000..287cc97974 --- /dev/null +++ b/tests/army/query/last/test_last.py @@ -0,0 +1,192 @@ +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame import * +from frame.eos import * + + +class TDTestCase(TBase): + """Add test case to verify TD-30816 (last/last_row accuracy) + """ + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def prepare_data(self): + tdSql.execute("create database db_td30816 cachemodel 'both';") + tdSql.execute("use db_td30816;") + # create regular table + tdSql.execute("create table rt_int (ts timestamp, c1 int primary key, c2 int);") + tdSql.execute("create table rt_str (ts timestamp, c1 varchar(16) primary key, c2 varchar(16));") + + # create stable + tdSql.execute("create table st_pk_int (ts timestamp, c1 int primary key, c2 int) tags (t1 int);") + tdSql.execute("create table st_pk_str (ts timestamp, c1 varchar(16) primary key, c2 varchar(16)) tags (t1 int);") + + # create child table + tdSql.execute("create table ct1 using st_pk_int tags(1);") + tdSql.execute("create table ct2 using st_pk_int tags(2);") + + tdSql.execute("create table ct3 using st_pk_str tags(3);") + tdSql.execute("create table ct4 using st_pk_str tags(4);") + + # insert data to regular table + tdSql.execute("insert into rt_int values ('2021-01-01 00:00:00', 1, NULL);") + tdSql.execute("insert into rt_int values ('2021-01-01 00:00:01', 2, 1);") + tdSql.execute("insert into rt_str values ('2021-01-01 00:00:00', 'a', NULL);") + tdSql.execute("insert into rt_str values ('2021-01-01 00:00:01', 'b', '1');") + + # insert data to child table + tdSql.execute("insert into ct1 values ('2021-01-01 00:00:00', 1, 1);") + tdSql.execute("insert into ct1 values ('2021-01-01 00:00:01', 2, NULL);") + tdSql.execute("insert into ct2 values ('2021-01-01 00:00:00', 3, 3);") + tdSql.execute("insert into ct2 values ('2021-01-01 00:00:01', 4, NULL);") + + tdSql.execute("insert into ct3 values ('2021-01-01 00:00:00', 'a', '1');") + tdSql.execute("insert into ct3 values ('2021-01-01 00:00:01', 'b', NULL);") + tdSql.execute("insert into ct4 values ('2021-01-01 00:00:00', 'c', '3');") + tdSql.execute("insert into ct4 values ('2021-01-01 00:00:01', 'd', NULL);") + + def test_last_with_primarykey_int_ct(self): + tdSql.execute("use db_td30816;") + tdSql.query("select last(*) from st_pk_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 4) + tdSql.checkData(0, 2, 3) + + tdSql.query("select last_row(*) from st_pk_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 4) + tdSql.checkData(0, 2, None) + + # delete and insert data + tdSql.execute("delete from ct1 where ts='2021-01-01 00:00:01';") + tdSql.execute("delete from ct2 where ts='2021-01-01 00:00:01';") + tdSql.execute("insert into ct1 values ('2021-01-01 00:00:00', 0, 5);") + tdSql.execute("insert into ct2 values ('2021-01-01 00:00:00', -1, 6);") + tdSql.query("select last(*) from st_pk_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 3) + tdSql.checkData(0, 2, 3) + + tdSql.query("select last_row(*) from st_pk_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 3) + tdSql.checkData(0, 2, 3) + tdLog.info("Finish test_last_with_primarykey_int_ct") + + def test_last_with_primarykey_str_ct(self): + tdSql.execute("use db_td30816;") + tdSql.query("select last(*) from st_pk_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 'd') + tdSql.checkData(0, 2, '3') + + tdSql.query("select last_row(*) from st_pk_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 'd') + tdSql.checkData(0, 2, None) + + # delete and insert data + tdSql.execute("delete from ct3 where ts='2021-01-01 00:00:01';") + tdSql.execute("delete from ct4 where ts='2021-01-01 00:00:01';") + tdSql.execute("insert into ct3 values ('2021-01-01 00:00:00', '6', '5');") + tdSql.execute("insert into ct4 values ('2021-01-01 00:00:00', '7', '6');") + + tdSql.query("select last(*) from st_pk_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 'c') + tdSql.checkData(0, 2, '3') + + tdSql.query("select last_row(*) from st_pk_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 'c') + tdSql.checkData(0, 2, 3) + tdLog.info("Finish test_last_with_primarykey_str_ct") + + def test_last_with_primarykey_int_rt(self): + tdSql.execute("use db_td30816;") + tdSql.query("select last(*) from rt_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 2) + tdSql.checkData(0, 2, 1) + + tdSql.query("select last_row(*) from rt_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 2) + tdSql.checkData(0, 2, 1) + + tdSql.execute("delete from rt_int where ts='2021-01-01 00:00:01';") + tdSql.execute("insert into rt_int values ('2021-01-01 00:00:00', 0, 5);") + + tdSql.query("select last(*) from rt_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 1) + tdSql.checkData(0, 2, 5) + + tdSql.query("select last_row(*) from rt_int;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 1) + tdSql.checkData(0, 2, None) + tdLog.info("Finish test_last_with_primarykey_int_rt") + + def test_last_with_primarykey_str_rt(self): + tdSql.execute("use db_td30816;") + tdSql.query("select last(*) from rt_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 'b') + tdSql.checkData(0, 2, '1') + + tdSql.query("select last_row(*) from rt_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:01') + tdSql.checkData(0, 1, 'b') + tdSql.checkData(0, 2, '1') + + tdSql.execute("delete from rt_str where ts='2021-01-01 00:00:01';") + tdSql.execute("insert into rt_str values ('2021-01-01 00:00:00', '2', '5');") + + tdSql.query("select last(*) from rt_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 'a') + tdSql.checkData(0, 2, '5') + + tdSql.query("select last_row(*) from rt_str;") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '2021-01-01 00:00:00') + tdSql.checkData(0, 1, 'a') + tdSql.checkData(0, 2, None) + tdLog.info("Finish test_last_with_primarykey_str_rt") + + def run(self): + self.prepare_data() + # regular table + self.test_last_with_primarykey_int_rt() + self.test_last_with_primarykey_str_rt() + # child tables + self.test_last_with_primarykey_int_ct() + self.test_last_with_primarykey_str_ct() + + def stop(self): + tdSql.execute("drop database db_td30816;") + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 3553f0d913..3ec1d7c428 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -38,6 +38,7 @@ ,,y,army,./pytest.sh python3 ./test.py -f query/queryBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f tmq/tmqBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_compare_asc_desc.py +,,y,army,./pytest.sh python3 ./test.py -f query/last/test_last.py # # system test @@ -310,7 +311,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/balance_vgroups_r1.py -N 6 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShell.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShellError.py -,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShellNetChk.py +,,n,system-test,python3 ./test.py -f 0-others/taosShellNetChk.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/telemetry.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/backquote_check.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosdMonitor.py diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh index b1571aa173..aa73d4cb23 100755 --- a/tests/script/sh/checkAsan.sh +++ b/tests/script/sh/checkAsan.sh @@ -49,6 +49,7 @@ fi indirect_leak=$(cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l) python_error=$(cat ${LOG_DIR}/*.info | grep -w "stack" | wc -l) +python_taos_error=$(cat ${LOG_DIR}/*.info |grep "#" | grep -w "TDinternal" | wc -l) # ignore @@ -84,17 +85,18 @@ echo -e "\033[44;32;1m"asan memory_leak: $memory_leak"\033[0m" echo -e "\033[44;32;1m"asan indirect_leak: $indirect_leak"\033[0m" echo -e "\033[44;32;1m"asan runtime error: $runtime_error"\033[0m" echo -e "\033[44;32;1m"asan python error: $python_error"\033[0m" +echo -e "\033[44;32;1m"asan python taos error: $python_taos_error"\033[0m" -let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error+$python_error" +let "errors=$error_num+$memory_leak+$indirect_leak+$runtime_error+$python_error+$python_taos_error" if [ $errors -eq 0 ]; then echo -e "\033[44;32;1m"no asan errors"\033[0m" exit 0 else echo -e "\033[44;31;1m"asan total errors: $errors"\033[0m" - if [ $python_error -ne 0 ]; then - cat ${LOG_DIR}/*.info + if [ $python_error -ne 0 ] || [ $python_taos_error -ne 0 ] ; then + cat ${LOG_DIR}/*.info |grep "#" | grep -w "TDinternal" fi cat ${LOG_DIR}/*.asan exit 1 -fi +fi \ No newline at end of file