From 69fa2a187ae7f37258d7e7d6aa74f437dcd3bf80 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Jul 2024 13:58:17 +0800 Subject: [PATCH 1/2] enh: refactor return code --- include/util/tRealloc.h | 2 +- include/util/tarray2.h | 2 +- source/dnode/qnode/src/qnode.c | 15 ++++--- source/dnode/snode/src/snode.c | 1 - source/dnode/vnode/src/inc/tsdb.h | 1 - source/dnode/vnode/src/tsdb/tsdbFSet2.c | 12 +++-- source/dnode/vnode/src/tsdb/tsdbFile2.c | 2 +- source/dnode/vnode/src/tsdb/tsdbIter.c | 4 +- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 47 ++++++-------------- source/dnode/vnode/src/tsdb/tsdbSnapInfo.c | 6 +-- source/dnode/vnode/src/tsdb/tsdbUtil.c | 51 ++++++++++++---------- source/dnode/vnode/src/vnd/vnodeBufPool.c | 6 +-- source/util/src/tarray.c | 6 +-- 13 files changed, 73 insertions(+), 82 deletions(-) diff --git a/include/util/tRealloc.h b/include/util/tRealloc.h index 3229c53039..b830fac284 100644 --- a/include/util/tRealloc.h +++ b/include/util/tRealloc.h @@ -41,7 +41,7 @@ static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) { pBuf = (uint8_t *)taosMemoryRealloc(pBuf, bsize + sizeof(int64_t)); if (pBuf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } diff --git a/include/util/tarray2.h b/include/util/tarray2.h index 2e9b0c7cb5..0d1ceded6c 100644 --- a/include/util/tarray2.h +++ b/include/util/tarray2.h @@ -55,7 +55,7 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arr, int32_t expSize, int32_ capacity <<= 1; } void *p = taosMemoryRealloc(a->data, capacity * eleSize); - if (p == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (p == NULL) return terrno; a->capacity = capacity; a->data = p; return 0; diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index b0fcd3400d..e80cbf1391 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -13,17 +13,17 @@ * along with this program. If not, see . */ -#include "tqueue.h" #include "executor.h" #include "qndInt.h" #include "query.h" #include "qworker.h" +#include "tqueue.h" int32_t qndOpen(const SQnodeOpt *pOption, SQnode **pQnode) { *pQnode = taosMemoryCalloc(1, sizeof(SQnode)); if (NULL == *pQnode) { qError("calloc SQnode failed"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pQnode)->qndId = QNODE_HANDLE; @@ -75,9 +75,9 @@ int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) { return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false); } -int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg) { +int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo *pInfo, SRpcMsg *pMsg) { int32_t code = -1; - int64_t ts = pInfo->timestamp; + int64_t ts = pInfo->timestamp; SReadHandle handle = {.pMsgCb = &pQnode->msgCb, .pWorkerCb = pInfo->workerCb}; qTrace("message in qnode queue is processing"); @@ -113,6 +113,9 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg) { terrno = TSDB_CODE_APP_ERROR; } - if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS; - return code; + if (code == 0) { + return TSDB_CODE_ACTION_IN_PROGRESS; + } else { + return code; + } } diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 3f2ebccdba..5e536e5fbf 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -64,7 +64,6 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { int32_t code = 0; SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode)); if (pSnode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index d496853cd5..978821f890 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -244,7 +244,6 @@ void tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive); STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid); int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode); int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive); -SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable); // STbDataIter int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter); void *tsdbTbDataIterDestroy(STbDataIter *pIter); diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index 2c0662b83b..305ce6b56f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -18,14 +18,14 @@ int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl) { if (!(lvl[0] = taosMemoryMalloc(sizeof(SSttLvl)))) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } lvl[0]->level = level; TARRAY2_INIT(lvl[0]->fobjArr); return 0; } -static void tsdbSttLvlClearFObj(void *data) { tsdbTFileObjUnref(*(STFileObj **)data); } +static void tsdbSttLvlClearFObj(void *data) { TAOS_UNUSED(tsdbTFileObjUnref(*(STFileObj **)data)); } int32_t tsdbSttLvlClear(SSttLvl **lvl) { if (lvl[0] != NULL) { @@ -451,7 +451,9 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset) { fset[0] = taosMemoryCalloc(1, sizeof(STFileSet)); - if (fset[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (fset[0] == NULL) { + return terrno; + } fset[0]->fid = fid; fset[0]->maxVerValid = VERSION_MAX; @@ -543,7 +545,9 @@ int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_ int32_t tsdbTFileSetRangeInitRef(STsdb *pTsdb, const STFileSet *fset1, int64_t sver, int64_t ever, STFileSetRange **fsr) { fsr[0] = taosMemoryCalloc(1, sizeof(*fsr[0])); - if (fsr[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (fsr[0] == NULL) { + return terrno; + } fsr[0]->fid = fset1->fid; fsr[0]->sver = sver; fsr[0]->ever = ever; diff --git a/source/dnode/vnode/src/tsdb/tsdbFile2.c b/source/dnode/vnode/src/tsdb/tsdbFile2.c index a500074a65..52f1ef72ee 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile2.c @@ -227,7 +227,7 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) { int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj) { fobj[0] = taosMemoryMalloc(sizeof(*fobj[0])); if (!fobj[0]) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosThreadMutexInit(&fobj[0]->mutex, NULL); diff --git a/source/dnode/vnode/src/tsdb/tsdbIter.c b/source/dnode/vnode/src/tsdb/tsdbIter.c index 42afe1cdc0..d97a5153f3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbIter.c +++ b/source/dnode/vnode/src/tsdb/tsdbIter.c @@ -507,7 +507,7 @@ int32_t tsdbIterOpen(const STsdbIterConfig *config, STsdbIter **iter) { iter[0] = taosMemoryCalloc(1, sizeof(*iter[0])); if (iter[0] == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } iter[0]->type = config->type; @@ -677,7 +677,7 @@ int32_t tsdbIterMergerOpen(const TTsdbIterArray *iterArray, SIterMerger **merger merger[0] = taosMemoryCalloc(1, sizeof(*merger[0])); if (merger[0] == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } merger[0]->isTomb = isTomb; diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index e5bcf65bd7..3114c0fa04 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -54,7 +54,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) { pMemTable = (SMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable)); if (pMemTable == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } taosInitRWLatch(&pMemTable->latch); @@ -71,7 +71,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) { pMemTable->nBucket = MEM_MIN_HASH; pMemTable->aBucket = (STbData **)taosMemoryCalloc(pMemTable->nBucket, sizeof(STbData *)); if (pMemTable->aBucket == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(pMemTable); goto _err; } @@ -174,7 +174,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid // do delete SDelData *pDelData = (SDelData *)vnodeBufPoolMalloc(pPool, sizeof(*pDelData)); if (pDelData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } pDelData->version = version; @@ -195,7 +195,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid pMemTable->minVer = TMIN(pMemTable->minVer, version); pMemTable->maxVer = TMAX(pMemTable->maxVer, version); - tsdbCacheDel(pTsdb, suid, uid, sKey, eKey); + TAOS_UNUSED(tsdbCacheDel(pTsdb, suid, uid, sKey, eKey)); tsdbTrace("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 " at version %" PRId64, @@ -214,7 +214,7 @@ int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backwa (*ppIter) = (STbDataIter *)taosMemoryCalloc(1, sizeof(STbDataIter)); if ((*ppIter) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -329,7 +329,7 @@ static int32_t tsdbMemTableRehash(SMemTable *pMemTable) { int32_t nBucket = pMemTable->nBucket * 2; STbData **aBucket = (STbData **)taosMemoryCalloc(nBucket, sizeof(STbData *)); if (aBucket == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -369,7 +369,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid ASSERT(pPool != NULL); pTbData = vnodeBufPoolMallocAligned(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2); if (pTbData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } pTbData->suid = suid; @@ -520,7 +520,7 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN ASSERT(0); } if (pNode == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -589,7 +589,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, // copy and construct block data SBlockData *pBlockData = vnodeBufPoolMalloc(pPool, sizeof(*pBlockData)); if (pBlockData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -599,7 +599,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, pBlockData->aUid = NULL; pBlockData->aVersion = vnodeBufPoolMalloc(pPool, aColData[0].nData); if (pBlockData->aVersion == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } for (int32_t i = 0; i < pBlockData->nRow; i++) { // todo: here can be optimized @@ -608,7 +608,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, pBlockData->aTSKEY = vnodeBufPoolMalloc(pPool, aColData[0].nData); if (pBlockData->aTSKEY == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } memcpy(pBlockData->aTSKEY, aColData[0].pData, aColData[0].nData); @@ -616,7 +616,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, pBlockData->nColData = nColData - 1; pBlockData->aColData = vnodeBufPoolMalloc(pPool, sizeof(SColData) * pBlockData->nColData); if (pBlockData->aColData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -661,7 +661,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, } if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) { - tsdbCacheColFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, pBlockData); + TAOS_UNUSED(tsdbCacheColFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, pBlockData)); } // SMemTable @@ -720,7 +720,7 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, pTbData->maxKey = key.key.ts; } if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) { - tsdbCacheRowFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, version, nRow, aRow); + TAOS_UNUSED(tsdbCacheRowFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, version, nRow, aRow)); } // SMemTable @@ -780,22 +780,3 @@ static FORCE_INLINE int32_t tbDataPCmprFn(const void *p1, const void *p2) { return 0; } - -SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable) { - SArray *aTbDataP = taosArrayInit(pMemTable->nTbData, sizeof(STbData *)); - if (aTbDataP == NULL) goto _exit; - - for (int32_t iBucket = 0; iBucket < pMemTable->nBucket; iBucket++) { - STbData *pTbData = pMemTable->aBucket[iBucket]; - - while (pTbData) { - taosArrayPush(aTbDataP, &pTbData); - pTbData = pTbData->next; - } - } - - taosArraySort(aTbDataP, tbDataPCmprFn); - -_exit: - return aTbDataP; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c index f515cd5352..56364fbc6a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c @@ -42,7 +42,6 @@ static int32_t tsdbTFileSetRangeCmprFn(STFileSetRange* x, STFileSetRange* y) { STsdbFSetPartition* tsdbFSetPartitionCreate() { STsdbFSetPartition* pSP = taosMemoryCalloc(1, sizeof(STsdbFSetPartition)); if (pSP == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } for (int32_t i = 0; i < TSDB_FSET_RANGE_TYP_MAX; i++) { @@ -140,7 +139,6 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** STsdbFSetPartList* tsdbFSetPartListCreate() { STsdbFSetPartList* pList = taosMemoryCalloc(1, sizeof(STsdbFSetPartList)); if (pList == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } TARRAY2_INIT(pList); @@ -160,7 +158,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray)); if (pDiff == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } TARRAY2_INIT(pDiff); @@ -169,7 +167,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray TARRAY2_FOREACH(pList, part) { STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange)); if (r == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } int64_t maxVerValid = -1; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 66db7baab9..a1ca8ccda2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -154,14 +154,16 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize) { int32_t n = 0; + int32_t code; int32_t offset; tMapDataReset(pMapData); n += tGetI32v(p + n, &pMapData->nItem); if (pMapData->nItem) { - if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) { - return TSDB_CODE_OUT_OF_MEMORY; + code = tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem); + if (code) { + return code; } int32_t lOffset = 0; @@ -172,8 +174,9 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize) { } n += tGetI32v(p + n, &pMapData->nData); - if (tRealloc(&pMapData->pData, pMapData->nData)) { - return TSDB_CODE_OUT_OF_MEMORY; + code = tRealloc(&pMapData->pData, pMapData->nData); + if (code) { + return code; } memcpy(pMapData->pData, p + n, pMapData->nData); n += pMapData->nData; @@ -753,7 +756,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) *pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = key.ts})); if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; return code; } @@ -766,7 +769,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) continue; } else if (pTSchema->columns[jCol].colId > pTColumn->colId) { if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } continue; } @@ -778,7 +781,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) pColVal->value.pData = NULL; code = tRealloc(&pColVal->value.pData, pColVal->value.nData); if (code) { - return TSDB_CODE_OUT_OF_MEMORY; + return code; } if (pColVal->value.nData) { @@ -787,14 +790,14 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) } if (taosArrayPush(pMerger->pArray, pColVal) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } for (; iCol < pMerger->pTSchema->numOfCols; ++iCol) { pTColumn = &pMerger->pTSchema->columns[iCol]; if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -866,7 +869,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema) { pMerger->pTSchema = pSchema; pMerger->pArray = taosArrayInit(pSchema->numOfCols, sizeof(SColVal)); if (pMerger->pArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } else { return TSDB_CODE_SUCCESS; } @@ -1036,11 +1039,11 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx, TSDBKEY *pItem1 = taosArrayGet(aSkyline, sidx * 2); TSDBKEY *pItem2 = taosArrayGet(aSkyline, sidx * 2 + 1); if (taosArrayPush(pSkyline, &pItem1) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pSkyline, &pItem2) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } else { SArray *pSkyline1 = NULL; @@ -1048,10 +1051,13 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx, midx = (sidx + eidx) / 2; pSkyline1 = taosArrayInit((midx - sidx + 1) * 2, POINTER_BYTES); + if (pSkyline1 == NULL) { + return terrno; + } pSkyline2 = taosArrayInit((eidx - midx) * 2, POINTER_BYTES); - if (pSkyline1 == NULL || pSkyline1 == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _clear; + if (pSkyline2 == NULL) { + taosArrayDestroy(pSkyline1); + return terrno; } code = tsdbBuildDeleteSkylineImpl(aSkyline, sidx, midx, pSkyline1); @@ -1076,25 +1082,25 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr int32_t dataNum = eidx - sidx + 1; SArray *aTmpSkyline = taosArrayInit(dataNum * 2, sizeof(TSDBKEY)); if (aTmpSkyline == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SArray *pSkyline = taosArrayInit(dataNum * 2, POINTER_BYTES); if (pSkyline == NULL) { taosArrayDestroy(aTmpSkyline); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosArrayClear(aSkyline); for (int32_t i = sidx; i <= eidx; ++i) { pDelData = (SDelData *)taosArrayGet(aDelData, i); if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->sKey, .version = pDelData->version}) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _clear; } if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->eKey, .version = 0}) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _clear; } } @@ -1106,7 +1112,7 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr for (int32_t i = 0; i < skylineNum; ++i) { TSDBKEY *p = taosArrayGetP(pSkyline, i); if (taosArrayPush(aSkyline, p) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _clear; } } @@ -1196,7 +1202,7 @@ static int32_t tBlockDataAdjustColData(SBlockData *pBlockData, int32_t nColData) } else if (pBlockData->nColData < nColData) { SColData *aColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SBlockData) * nColData); if (aColData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -1284,7 +1290,7 @@ int32_t tBlockDataAddColData(SBlockData *pBlockData, int16_t cid, int8_t type, i SColData *newColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SColData) * (pBlockData->nColData + 1)); if (newColData == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBlockData->aColData = newColData; @@ -1452,6 +1458,7 @@ int32_t tBlockDataCompress(SBlockData *bData, void *pCompr, SBuffer *buffers, SB SColCompressInfo *pInfo = pCompr; code = tsdbGetColCmprAlgFromSet(pInfo->pColCmpr, 1, &pInfo->defaultCmprAlg); + TAOS_UNUSED(code); SDiskDataHdr hdr = { .delimiter = TSDB_FILE_DLMT, diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c index ad183839d7..f3c2693b75 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c @@ -140,8 +140,9 @@ void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) { // allocate a new node pNode = taosMemoryMalloc(sizeof(*pNode) + size); if (pNode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - if (pPool->lock) taosThreadSpinUnlock(pPool->lock); + if (pPool->lock) { + taosThreadSpinUnlock(pPool->lock); + } return NULL; } @@ -173,7 +174,6 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { // allocate a new node pNode = taosMemoryMalloc(sizeof(*pNode) + size); if (pNode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; if (pPool->lock) taosThreadSpinUnlock(pPool->lock); return NULL; } diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index ec5e41f256..cb46a9f80e 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -18,9 +18,9 @@ #include "tcoding.h" // todo refactor API -#define BOUNDARY_SIZE 1024*1024*1024 // 1G +#define BOUNDARY_SIZE 1024 * 1024 * 1024 // 1G #define BOUNDARY_SMALL_FACTOR 1.2 -#define BOUNDARY_BIG_FACTOR 2 +#define BOUNDARY_BIG_FACTOR 2 SArray* taosArrayInit(size_t size, size_t elemSize) { if (elemSize == 0) { @@ -198,7 +198,7 @@ void* taosArrayGet(const SArray* pArray, size_t index) { } if (index >= pArray->size) { - uError("index is out of range, current:%" PRIzu " max:%"PRIzu, index, pArray->size); + uError("index is out of range, current:%" PRIzu " max:%" PRIzu, index, pArray->size); return NULL; } From 8f04f32b9637dbdf8c25d6ece92cce36779dad9f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Jul 2024 14:41:45 +0800 Subject: [PATCH 2/2] make it compile --- source/dnode/qnode/src/qnode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index e80cbf1391..3a326657c9 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -13,11 +13,12 @@ * along with this program. If not, see . */ +#include "tqueue.h" + #include "executor.h" #include "qndInt.h" #include "query.h" #include "qworker.h" -#include "tqueue.h" int32_t qndOpen(const SQnodeOpt *pOption, SQnode **pQnode) { *pQnode = taosMemoryCalloc(1, sizeof(SQnode));