diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index fe438c4396..4cb6c5c724 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -57,7 +57,11 @@ void vmGetVnodeLoadsLite(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo) { if (!pVnode->failed) { SVnodeLoadLite vload = {0}; if (vnodeGetLoadLite(pVnode->pImpl, &vload) == 0) { - (void)taosArrayPush(pInfo->pVloads, &vload); + if (taosArrayPush(pInfo->pVloads, &vload) == NULL) { + taosArrayDestroy(pInfo->pVloads); + pInfo->pVloads = NULL; + break; + } } } pIter = taosHashIterate(pMgmt->hash, pIter); @@ -841,6 +845,9 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { arbHbRsp.dnodeId = pMgmt->pData->dnodeId; strncpy(arbHbRsp.arbToken, arbHbReq.arbToken, TSDB_ARB_TOKEN_SIZE); arbHbRsp.hbMembers = taosArrayInit(size, sizeof(SVArbHbRspMember)); + if (arbHbRsp.hbMembers == NULL) { + goto _OVER; + } for (int32_t i = 0; i < size; i++) { SVArbHbReqMember *pReqMember = taosArrayGet(arbHbReq.hbMembers, i); @@ -865,7 +872,11 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { continue; } - (void)taosArrayPush(arbHbRsp.hbMembers, &rspMember); + if (taosArrayPush(arbHbRsp.hbMembers, &rspMember) == NULL) { + dError("dnodeId:%d vgId:%d failed to push arb hb rsp member", arbHbReq.dnodeId, pReqMember->vgId); + vmReleaseVnode(pMgmt, pVnode); + goto _OVER; + } vmReleaseVnode(pMgmt, pVnode); } diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index af5530215b..315c4d7430 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -256,7 +256,9 @@ _OVER: SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; (void)taosGetFqdnPortFromEp(tsFirst, &dnodeEp.ep); - (void)taosArrayPush(pData->dnodeEps, &dnodeEp); + if (taosArrayPush(pData->dnodeEps, &dnodeEp) == NULL) { + return terrno; + } } if ((code = dmReadDnodePairs(pData)) != 0) { @@ -398,7 +400,11 @@ static void dmResetEps(SDnodeData *pData, SArray *dnodeEps) { for (int32_t i = 0; i < numOfEps; i++) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); - (void)taosHashPut(pData->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + int32_t code = taosHashPut(pData->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + if (code) { + dError("dnode:%d, fqdn:%s port:%u isMnode:%d failed to put into hash, reason:%s", pDnodeEp->id, pDnodeEp->ep.fqdn, + pDnodeEp->ep.port, pDnodeEp->isMnode, tstrerror(code)); + } } pData->validMnodeEps = true; diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 6f562cef4a..820abcaea6 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -156,7 +156,7 @@ int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp); int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids, int64_t* tbUid); int32_t metaTrimTables(SMeta* pMeta); -void metaDropTables(SMeta* pMeta, SArray* tbUids); +int32_t metaDropTables(SMeta* pMeta, SArray* tbUids); int metaTtlFindExpired(SMeta* pMeta, int64_t timePointMs, SArray* tbUids, int32_t ttlDropMaxCount); int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp); int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs); @@ -435,9 +435,9 @@ typedef struct SVCommitSched { } SVCommitSched; typedef struct SVMonitorObj { - char strClusterId[TSDB_CLUSTER_ID_LEN]; - char strDnodeId[TSDB_NODE_ID_LEN]; - char strVgId[TSDB_VGROUP_ID_LEN]; + char strClusterId[TSDB_CLUSTER_ID_LEN]; + char strDnodeId[TSDB_NODE_ID_LEN]; + char strVgId[TSDB_VGROUP_ID_LEN]; } SVMonitorObj; typedef struct { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 1668f699ae..7daea64e18 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1486,7 +1486,12 @@ int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *pUidTagInfo) { taosHashInit(numOfElems / 0.7, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); for (int i = 0; i < numOfElems; i++) { STUidTagInfo *pTagInfo = taosArrayGet(pUidTagInfo, i); - (void)taosHashPut(pSepecifiedUidMap, &pTagInfo->uid, sizeof(uint64_t), &i, sizeof(int32_t)); + int32_t code = taosHashPut(pSepecifiedUidMap, &pTagInfo->uid, sizeof(uint64_t), &i, sizeof(int32_t)); + if (code) { + metaCloseCtbCursor(pCur); + taosHashCleanup(pSepecifiedUidMap); + return code; + } } } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 0334990365..5d87c02ab2 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -381,7 +381,11 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb break; } - (void)taosArrayPush(tbUidList, &(((SCtbIdxKey *)pKey)->uid)); + if (taosArrayPush(tbUidList, &(((SCtbIdxKey *)pKey)->uid)) == NULL) { + tdbFree(pKey); + (void)tdbTbcClose(pCtbIdxc); + return terrno; + } } (void)tdbTbcClose(pCtbIdxc); @@ -505,7 +509,11 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { return terrno = TSDB_CODE_TDB_STB_NOT_EXIST; } - oStbEntry.pBuf = taosMemoryMalloc(nData); + if ((oStbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + return terrno; + } memcpy(oStbEntry.pBuf, pData, nData); tDecoderInit(&dc, oStbEntry.pBuf, nData); (void)metaDecodeEntry(&dc, &oStbEntry); @@ -527,6 +535,13 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { STsdb *pTsdb = pMeta->pVnode->pTsdb; SArray *uids = taosArrayInit(8, sizeof(int64_t)); + if (uids == NULL) { + if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); + tDecoderClear(&dc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + return terrno; + } if (deltaCol == 1) { int16_t cid = pReq->schemaRow.pSchema[nCols - 1].colId; int8_t col_type = pReq->schemaRow.pSchema[nCols - 1].type; @@ -1108,7 +1123,10 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi } if ((type == TSDB_CHILD_TABLE || type == TSDB_NORMAL_TABLE) && tbUids) { - (void)taosArrayPush(tbUids, &uid); + if (taosArrayPush(tbUids, &uid) == NULL) { + rc = terrno; + goto _exit; + } if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { (void)tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); @@ -1125,11 +1143,15 @@ _exit: return rc; } -void metaDropTables(SMeta *pMeta, SArray *tbUids) { - if (taosArrayGetSize(tbUids) == 0) return; +int32_t metaDropTables(SMeta *pMeta, SArray *tbUids) { + int32_t code = 0; + if (taosArrayGetSize(tbUids) == 0) return TSDB_CODE_SUCCESS; int64_t nCtbDropped = 0; SSHashObj *suidHash = tSimpleHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); + if (suidHash == NULL) { + return terrno; + } metaWLock(pMeta); for (int i = 0; i < taosArrayGetSize(tbUids); ++i) { @@ -1137,7 +1159,8 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) { tb_uid_t suid = 0; int8_t sysTbl = 0; int type; - (void)metaDropTableByUid(pMeta, uid, &type, &suid, &sysTbl); + code = metaDropTableByUid(pMeta, uid, &type, &suid, &sysTbl); + if (code) return code; if (!sysTbl && type == TSDB_CHILD_TABLE && suid != 0 && suidHash) { int64_t *pVal = tSimpleHashGet(suidHash, &suid, sizeof(tb_uid_t)); if (pVal) { @@ -1145,7 +1168,8 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) { } else { nCtbDropped = 1; } - (void)tSimpleHashPut(suidHash, &suid, sizeof(tb_uid_t), &nCtbDropped, sizeof(int64_t)); + code = tSimpleHashPut(suidHash, &suid, sizeof(tb_uid_t), &nCtbDropped, sizeof(int64_t)); + if (code) return code; } /* if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { @@ -1170,6 +1194,7 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) { tSimpleHashCleanup(suidHash); pMeta->changed = true; + return 0; } static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { @@ -1210,7 +1235,10 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { tbFName[TSDB_TABLE_FNAME_LEN] = '\0'; int32_t ret = vnodeValidateTableHash(pMeta->pVnode, tbFName); if (ret < 0 && terrno == TSDB_CODE_VND_HASH_MISMATCH) { - (void)taosArrayPush(uidList, &me.uid); + if (taosArrayPush(uidList, &me.uid) == NULL) { + code = terrno; + break; + } } } tDecoderClear(&dc); @@ -1239,7 +1267,8 @@ int32_t metaTrimTables(SMeta *pMeta) { } metaInfo("vgId:%d, trim %ld tables", TD_VID(pMeta->pVnode), taosArrayGetSize(tbUids)); - metaDropTables(pMeta, tbUids); + code = metaDropTables(pMeta, tbUids); + if (code) goto end; end: taosArrayDestroy(tbUids); @@ -1867,11 +1896,19 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } else { memcpy(&val.i64, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); } - (void)taosArrayPush(pTagArray, &val); + if (taosArrayPush(pTagArray, &val) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(pTagArray); + goto _err; + } } else { STagVal val = {.cid = pCol->colId}; if (tTagGet(pOldTag, &val)) { - (void)taosArrayPush(pTagArray, &val); + if (taosArrayPush(pTagArray, &val) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(pTagArray); + goto _err; + } } } } @@ -2238,6 +2275,9 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT } SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair)); + if (tagIdxList == NULL) { + goto _err; + } TBC *pTagIdxc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL)); @@ -2255,7 +2295,9 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT } SMetaPair pair = {.key = pKey, nKey = nKey}; - (void)taosArrayPush(tagIdxList, &pair); + if (taosArrayPush(tagIdxList, &pair) == NULL) { + goto _err; + } } (void)tdbTbcClose(pTagIdxc); @@ -2797,7 +2839,14 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) { SColCmprWrapper *p = &e.colCmpr; for (int32_t i = 0; i < p->nCols; i++) { SColCmpr *pCmpr = &p->pColCmpr[i]; - (void)taosHashPut(pColCmprObj, &pCmpr->id, sizeof(pCmpr->id), &pCmpr->alg, sizeof(pCmpr->alg)); + rc = taosHashPut(pColCmprObj, &pCmpr->id, sizeof(pCmpr->id), &pCmpr->alg, sizeof(pCmpr->alg)); + if (rc < 0) { + tDecoderClear(&dc); + tdbFree(pData); + metaULock(pMeta); + taosHashClear(pColCmprObj); + return rc; + } } } else { tDecoderClear(&dc); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 75db6e2925..a7ce9acbe5 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -960,7 +960,9 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, } if (ttlReq.nUids > 0) { - metaDropTables(pVnode->pMeta, ttlReq.pTbUids); + int32_t code = metaDropTables(pVnode->pMeta, ttlReq.pTbUids); + if (code) return code; + (void)tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false); } diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index b7ca99d26a..c33e0ee501 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -154,6 +154,10 @@ static void *taosCacheTimedRefresh(void *handle); static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); + if (pCacheArrayList == NULL) { + uError("failed to allocate memory, reason:%s", strerror(errno)); + return; + } (void)taosThreadMutexInit(&guard, NULL); @@ -169,7 +173,11 @@ TdThread doRegisterCacheObj(SCacheObj *pCacheObj) { (void)taosThreadOnce(&cacheThreadInit, doInitRefreshThread); (void)taosThreadMutexLock(&guard); - (void)taosArrayPush(pCacheArrayList, &pCacheObj); + if (taosArrayPush(pCacheArrayList, &pCacheObj) != 0) { + uError("failed to add cache object into array, reason:%s", strerror(errno)); + (void)taosThreadMutexUnlock(&guard); + return cacheRefreshWorker; + } (void)taosThreadMutexUnlock(&guard); return cacheRefreshWorker; @@ -262,7 +270,7 @@ static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) { pNode->pNext = pEntry->next; pEntry->next = pNode; pEntry->num += 1; - //A S S E R T((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); + // A S S E R T((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); } static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode *pNode) { @@ -274,7 +282,7 @@ static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode pNode->pNext = NULL; pe->num -= 1; - //A S S E R T((pe->next && pe->num > 0) || (NULL == pe->next && pe->num == 0)); + // A S S E R T((pe->next && pe->num > 0) || (NULL == pe->next && pe->num == 0)); } static FORCE_INLINE SCacheEntry *doFindEntry(SCacheObj *pCacheObj, const void *key, size_t keyLen) { @@ -499,7 +507,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) { uDebug("cache:%s, data: %p acquired by data in cache, refcnt:%d", pCacheObj->name, ptNode->data, ref); // the data if referenced by at least one object, so the reference count must be greater than the value of 2. - //A S S E R T(ref >= 2); + // A S S E R T(ref >= 2); return data; } @@ -574,19 +582,19 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { if (ref == 1) { // If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may be // destroyed by refresh worker if decrease ref count before removing it from linked-list. - //A S S E R T(pNode->pTNodeHeader->pData == pNode); + // A S S E R T(pNode->pTNodeHeader->pData == pNode); __trashcan_wr_lock(pCacheObj); (void)doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader); __trashcan_unlock(pCacheObj); ref = T_REF_DEC(pNode); - //A S S E R T(ref == 0); + // A S S E R T(ref == 0); doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader); } else { ref = T_REF_DEC(pNode); - //A S S E R T(ref >= 0); + // A S S E R T(ref >= 0); } } else { // NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread @@ -608,7 +616,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { "others already, prev must in trashcan", pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data, T_REF_VAL_GET(pNode)); - //A S S E R T(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL); + // A S S E R T(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL); } else { removeNodeInEntryList(pe, prev, p); uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key, @@ -668,7 +676,7 @@ void doTraverseElems(SCacheObj *pCacheObj, bool (*fp)(void *param, SCacheNode *p } else { *pPre = next; pEntry->num -= 1; - //A S S E R T((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); + // A S S E R T((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); (void)atomic_sub_fetch_ptr(&pCacheObj->numOfElems, 1); pNode = next; @@ -734,7 +742,7 @@ SCacheNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pDat void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) { if (pNode->inTrashcan) { /* node is already in trash */ - //A S S E R T(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode); + // A S S E R T(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode); return; } @@ -780,7 +788,7 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) { STrashElem *pElem = pCacheObj->pTrash; while (pElem) { T_REF_VAL_CHECK(pElem->pData); - //A S S E R T(pElem->next != pElem && pElem->prev != pElem); + // A S S E R T(pElem->next != pElem && pElem->prev != pElem); if (force || (T_REF_VAL_GET(pElem->pData) == 0)) { uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key,