From b21e162f1950ef61f13b1f8ceb212045da8bacff Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 19 Sep 2024 11:36:29 +0800 Subject: [PATCH] enh: error code handle --- source/dnode/vnode/src/meta/metaOpen.c | 22 +- source/dnode/vnode/src/meta/metaQuery.c | 51 ++-- source/dnode/vnode/src/meta/metaTable.c | 292 ++++++++++++++++---- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 4 +- 4 files changed, 289 insertions(+), 80 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 1917c09526..591c40332a 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -27,15 +27,15 @@ static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int k static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); -static int32_t metaInitLock(SMeta *pMeta) { +static void metaInitLock(SMeta *pMeta) { TdThreadRwlockAttr attr; (void)taosThreadRwlockAttrInit(&attr); (void)taosThreadRwlockAttrSetKindNP(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); (void)taosThreadRwlockInit(&pMeta->lock, &attr); (void)taosThreadRwlockAttrDestroy(&attr); - return 0; + return; } -static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); } +static void metaDestroyLock(SMeta *pMeta) { (void)taosThreadRwlockDestroy(&pMeta->lock); } static void metaCleanup(SMeta **ppMeta); @@ -56,7 +56,7 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { TSDB_CHECK_CODE(code = terrno, lino, _exit); } - (void)metaInitLock(pMeta); + metaInitLock(pMeta); pMeta->path = (char *)&pMeta[1]; strcpy(pMeta->path, path); @@ -188,17 +188,23 @@ int metaAlterCache(SMeta *pMeta, int32_t nPage) { void metaRLock(SMeta *pMeta) { metaTrace("meta rlock %p", &pMeta->lock); - (void)taosThreadRwlockRdlock(&pMeta->lock); + if (taosThreadRwlockRdlock(&pMeta->lock) != 0) { + metaError("vgId:%d failed to lock %p", TD_VID(pMeta->pVnode), &pMeta->lock); + } } void metaWLock(SMeta *pMeta) { metaTrace("meta wlock %p", &pMeta->lock); - (void)taosThreadRwlockWrlock(&pMeta->lock); + if (taosThreadRwlockWrlock(&pMeta->lock) != 0) { + metaError("vgId:%d failed to lock %p", TD_VID(pMeta->pVnode), &pMeta->lock); + } } void metaULock(SMeta *pMeta) { metaTrace("meta ulock %p", &pMeta->lock); - (void)taosThreadRwlockUnlock(&pMeta->lock); + if (taosThreadRwlockUnlock(&pMeta->lock) != 0) { + metaError("vgId:%d failed to unlock %p", TD_VID(pMeta->pVnode), &pMeta->lock); + } } static void metaCleanup(SMeta **ppMeta) { @@ -223,7 +229,7 @@ static void metaCleanup(SMeta **ppMeta) { if (pMeta->pSkmDb) tdbTbClose(pMeta->pSkmDb); if (pMeta->pTbDb) tdbTbClose(pMeta->pTbDb); if (pMeta->pEnv) tdbClose(pMeta->pEnv); - (void)metaDestroyLock(pMeta); + metaDestroyLock(pMeta); taosMemoryFreeClear(*ppMeta); } diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 6123dc7642..b78b141ba9 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -353,7 +353,11 @@ int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType) { tDecoderClear(&pTbCur->mr.coder); - (void)metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); + ret = metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); + if (ret < 0) { + return ret; + } + if (pTbCur->mr.me.type == jumpTableType) { continue; } @@ -387,7 +391,10 @@ _query: SMetaEntry me = {0}; tDecoderInit(&dc, pData, nData); - (void)metaDecodeEntry(&dc, &me); + int32_t code = metaDecodeEntry(&dc, &me); + if (code) { + goto _err; + } if (me.type == TSDB_SUPER_TABLE) { if (sver == -1 || sver == me.stbEntry.schemaRow.version) { pSchema = tCloneSSchemaWrapper(&me.stbEntry.schemaRow); @@ -502,17 +509,17 @@ int32_t metaResumeCtbCursor(SMCtbCursor *pCtbCur, int8_t first) { ctbIdxKey.suid = pCtbCur->suid; ctbIdxKey.uid = INT64_MIN; int c = 0; - (void)tdbTbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c); + ret = tdbTbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c); if (c > 0) { - (void)tdbTbcMoveToNext(pCtbCur->pCur); + ret = tdbTbcMoveToNext(pCtbCur->pCur); } } else { int c = 0; ret = tdbTbcMoveTo(pCtbCur->pCur, pCtbCur->pKey, pCtbCur->kLen, &c); if (c < 0) { - (void)tdbTbcMoveToPrev(pCtbCur->pCur); + ret = tdbTbcMoveToPrev(pCtbCur->pCur); } else { - (void)tdbTbcMoveToNext(pCtbCur->pCur); + ret = tdbTbcMoveToNext(pCtbCur->pCur); } } } @@ -570,9 +577,9 @@ SMStbCursor *metaOpenStbCursor(SMeta *pMeta, tb_uid_t suid) { } // move to the suid - (void)tdbTbcMoveTo(pStbCur->pCur, &suid, sizeof(suid), &c); + ret = tdbTbcMoveTo(pStbCur->pCur, &suid, sizeof(suid), &c); if (c > 0) { - (void)tdbTbcMoveToNext(pStbCur->pCur); + ret = tdbTbcMoveToNext(pStbCur->pCur); } return pStbCur; @@ -670,12 +677,12 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv } if (c < 0) { - (void)tdbTbcMoveToPrev(pSkmDbC); + int32_t ret = tdbTbcMoveToPrev(pSkmDbC); } const void *pKey = NULL; int32_t nKey = 0; - (void)tdbTbcGet(pSkmDbC, &pKey, &nKey, NULL, NULL); + int32_t ret = tdbTbcGet(pSkmDbC, &pKey, &nKey, NULL, NULL); if (((SSkmDbKey *)pKey)->uid != skmDbKey.uid) { metaULock(pMeta); @@ -805,9 +812,9 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { // move to the suid smaIdxKey.uid = uid; smaIdxKey.smaUid = INT64_MIN; - (void)tdbTbcMoveTo(pSmaCur->pCur, &smaIdxKey, sizeof(smaIdxKey), &c); + ret = tdbTbcMoveTo(pSmaCur->pCur, &smaIdxKey, sizeof(smaIdxKey), &c); if (c > 0) { - (void)tdbTbcMoveToNext(pSmaCur->pCur); + ret = tdbTbcMoveToNext(pSmaCur->pCur); } return pSmaCur; @@ -916,7 +923,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { _err: metaReaderClear(&mr); taosArrayDestroy(pSmaIds); - (void)tFreeTSmaWrapper(pSW, deepCopy); + pSW = tFreeTSmaWrapper(pSW, deepCopy); return NULL; } @@ -1583,7 +1590,10 @@ int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo, SMetaReader *pR } // upsert the cache metaWLock(pMeta); - (void)metaCacheUpsert(pMeta, pInfo); + int32_t ret = metaCacheUpsert(pMeta, pInfo); + if (ret != 0) { + metaError("vgId:%d, failed to upsert cache, uid:%" PRId64, TD_VID(pMeta->pVnode), uid); + } metaULock(pMeta); if (lock) { @@ -1633,7 +1643,12 @@ int32_t metaGetStbStats(void *pVnode, int64_t uid, int64_t *numOfTables, int32_t // upsert the cache metaWLock(pVnodeObj->pMeta); - (void)metaStatsCacheUpsert(pVnodeObj->pMeta, &state); + + int32_t ret = metaStatsCacheUpsert(pVnodeObj->pMeta, &state); + if (ret) { + metaError("failed to upsert stats, uid:%" PRId64 ", ctbNum:%" PRId64 ", colNum:%d", uid, ctbNum, colNum); + } + metaULock(pVnodeObj->pMeta); _exit: @@ -1646,6 +1661,10 @@ void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t deltaCtb, int32_t del if (metaStatsCacheGet(pMeta, uid, &stats) == TSDB_CODE_SUCCESS) { stats.ctbNum += deltaCtb; stats.colNum += deltaCol; - (void)metaStatsCacheUpsert(pMeta, &stats); + int32_t code = metaStatsCacheUpsert(pMeta, &stats); + if (code) { + metaError("vgId:%d, failed to update stats, uid:%" PRId64 ", ctbNum:%" PRId64 ", colNum:%d", + TD_VID(pMeta->pVnode), uid, deltaCtb, deltaCol); + } } } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 5bbb41a7b0..fd7e6171c2 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -175,7 +175,11 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const } if (term != NULL) { - (void)indexMultiTermAdd(terms, term); + int32_t ret = indexMultiTermAdd(terms, term); + if (ret < 0) { + metaError("vgId:%d, failed to add term to multi term, uid: %" PRId64 ", key: %s, type: %d, ret: %d", + TD_VID(pMeta->pVnode), tuid, key, type, ret); + } } else { code = terrno; goto _exception; @@ -254,7 +258,11 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len); } if (term != NULL) { - (void)indexMultiTermAdd(terms, term); + int32_t ret = indexMultiTermAdd(terms, term); + if (ret < 0) { + metaError("vgId:%d, failed to add term to multi term, uid: %" PRId64 ", key: %s, type: %d, ret: %d", + TD_VID(pMeta->pVnode), tuid, key, type, ret); + } } else { code = terrno; goto _exception; @@ -351,6 +359,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb int c = 0; int rc = 0; int32_t lino; + int32_t ret; // check if super table exists rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData); @@ -393,25 +402,56 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb tdbTbcClose(pCtbIdxc); - (void)tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, tbUidList, pReq->suid); + ret = tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, tbUidList, pReq->suid); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } metaWLock(pMeta); for (int32_t iChild = 0; iChild < taosArrayGetSize(tbUidList); iChild++) { tb_uid_t uid = *(tb_uid_t *)taosArrayGet(tbUidList, iChild); - (void)metaDropTableByUid(pMeta, uid, NULL, NULL, NULL); + ret = metaDropTableByUid(pMeta, uid, NULL, NULL, NULL); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(terrno)); + } } // drop super table _drop_super_table: tdbTbGet(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pData, &nData); - (void)tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = ((SUidIdxVal *)pData)[0].version, .uid = pReq->suid}, + ret = tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = ((SUidIdxVal *)pData)[0].version, .uid = pReq->suid}, sizeof(STbDbKey), pMeta->txn); - (void)tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, pMeta->txn); - (void)tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); - (void)tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } - (void)metaStatsCacheDrop(pMeta, pReq->suid); + ret = tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } + + ret = tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } + + ret = tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } + + ret = metaStatsCacheDrop(pMeta, pReq->suid); + if (ret < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, + tstrerror(terrno)); + } metaULock(pMeta); @@ -519,7 +559,14 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { } memcpy(oStbEntry.pBuf, pData, nData); tDecoderInit(&dc, oStbEntry.pBuf, nData); - (void)metaDecodeEntry(&dc, &oStbEntry); + ret = metaDecodeEntry(&dc, &oStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to decode stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + return terrno; + } nStbEntry.version = version; nStbEntry.type = TSDB_SUPER_TABLE; @@ -550,7 +597,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int8_t col_type = pReq->schemaRow.pSchema[nCols - 1].type; TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pReq->suid, uids)); - (void)tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type); + TAOS_CHECK_RETURN(tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type)); } else if (deltaCol == -1) { int16_t cid = -1; bool hasPrimaryKey = false; @@ -566,7 +613,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (cid != -1) { TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pReq->suid, uids)); - (void)tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey); + TAOS_CHECK_RETURN(tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey)); } } if (uids) taosArrayDestroy(uids); @@ -575,25 +622,41 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { metaWLock(pMeta); // compare two entry if (oStbEntry.stbEntry.schemaRow.version != pReq->schemaRow.version) { - (void)metaSaveToSkmDb(pMeta, &nStbEntry); + ret = metaSaveToSkmDb(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to save skm db:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } } // update table.db - (void)metaSaveToTbDb(pMeta, &nStbEntry); + ret = metaSaveToTbDb(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to save tb db:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } // update uid index - (void)metaUpdateUidIdx(pMeta, &nStbEntry); + ret = metaUpdateUidIdx(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to update uid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } // metaStatsCacheDrop(pMeta, nStbEntry.uid); if (updStat) { - (void)metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol); + metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol); } metaULock(pMeta); if (updStat) { int64_t ctbNum; - (void)metaGetStbStats(pMeta->pVnode, pReq->suid, &ctbNum, NULL); + ret = metaGetStbStats(pMeta->pVnode, pReq->suid, &ctbNum, NULL); + if (ret < 0) { + metaError("vgId:%d, failed to get stb stats:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol); metaTimeSeriesNotifyCheck(pMeta); } @@ -745,7 +808,11 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { } metaWLock(pMeta); - (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + ret = tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to upsert tag idx key:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } metaULock(pMeta); metaDestroyTagIdxKey(pTagIdxKey); @@ -762,9 +829,17 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { metaWLock(pMeta); // update table.db - (void)metaSaveToTbDb(pMeta, &nStbEntry); + ret = metaSaveToTbDb(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to save tb db:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } // update uid index - (void)metaUpdateUidIdx(pMeta, &nStbEntry); + ret = metaUpdateUidIdx(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to update uid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(ret)); + } metaULock(pMeta); if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); @@ -896,7 +971,11 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) } metaWLock(pMeta); - (void)tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + ret = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete tag idx key:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->stb, + pReq->stbUid, tstrerror(ret)); + } metaULock(pMeta); metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; @@ -932,9 +1011,17 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) metaWLock(pMeta); // update table.db - (void)metaSaveToTbDb(pMeta, &nStbEntry); + ret = metaSaveToTbDb(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to save tb db:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->stb, + pReq->stbUid, tstrerror(ret)); + } // update uid index - (void)metaUpdateUidIdx(pMeta, &nStbEntry); + ret = metaUpdateUidIdx(pMeta, &nStbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to update uid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->stb, + pReq->stbUid, tstrerror(ret)); + } metaULock(pMeta); tDeleteSchemaWrapper(tag); @@ -958,6 +1045,7 @@ _err: int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRsp **pMetaRsp) { SMetaEntry me = {0}; SMetaReader mr = {0}; + int32_t ret; // validate message if (pReq->type != TSDB_CHILD_TABLE && pReq->type != TSDB_NORMAL_TABLE) { @@ -1033,18 +1121,34 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs if (!sysTbl) { int32_t nCols = 0; - (void)metaGetStbStats(pMeta->pVnode, me.ctbEntry.suid, 0, &nCols); + ret = metaGetStbStats(pMeta->pVnode, me.ctbEntry.suid, 0, &nCols); + if (ret < 0) { + metaError("vgId:%d, failed to get stb stats:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->ctb.suid, tstrerror(ret)); + } pStats->numOfTimeSeries += nCols - 1; } metaWLock(pMeta); - (void)metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1, 0); - (void)metaUidCacheClear(pMeta, me.ctbEntry.suid); - (void)metaTbGroupCacheClear(pMeta, me.ctbEntry.suid); + metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1, 0); + ret = metaUidCacheClear(pMeta, me.ctbEntry.suid); + if (ret < 0) { + metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->ctb.suid, tstrerror(ret)); + } + ret = metaTbGroupCacheClear(pMeta, me.ctbEntry.suid); + if (ret < 0) { + metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->ctb.suid, tstrerror(ret)); + } metaULock(pMeta); if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - (void)tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, me.ctbEntry.suid, NULL); + ret = tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, me.ctbEntry.suid, NULL); + if (ret < 0) { + metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pReq->name, tstrerror(ret)); + goto _err; + } } } else { me.ntbEntry.btime = pReq->btime; @@ -1060,7 +1164,11 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs pStats->numOfNTimeSeries += me.ntbEntry.schemaRow.nCols - 1; if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - (void)tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, -1, &me.ntbEntry.schemaRow); + ret = tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, -1, &me.ntbEntry.schemaRow); + if (ret < 0) { + metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pReq->name, tstrerror(ret)); + goto _err; + } } } @@ -1078,7 +1186,11 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs (*pMetaRsp)->suid = pReq->ctb.suid; strcpy((*pMetaRsp)->tbName, pReq->name); } else { - (void)metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp); + ret = metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp); + if (ret < 0) { + metaError("vgId:%d, failed to update meta rsp:%s since %s", TD_VID(pMeta->pVnode), pReq->name, + tstrerror(ret)); + } for (int32_t i = 0; i < pReq->colCmpr.nCols; i++) { SColCmpr *p = &pReq->colCmpr.pColCmpr[i]; (*pMetaRsp)->pSchemaExt[i].colId = p->id; @@ -1135,7 +1247,11 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi } if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - (void)tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); + int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); + if (ret < 0) { + metaError("vgId:%d, failed to drop table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, uid, + tstrerror(ret)); + } } } @@ -1233,7 +1349,11 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { SMetaEntry me = {0}; SDecoder dc = {0}; tDecoderInit(&dc, pData, nData); - (void)metaDecodeEntry(&dc, &me); + code = metaDecodeEntry(&dc, &me); + if (code < 0) { + tDecoderClear(&dc); + return code; + } if (me.type != TSDB_SUPER_TABLE) { char tbFName[TSDB_TABLE_FNAME_LEN + 1]; @@ -1340,6 +1460,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p int rc = 0; SMetaEntry e = {0}; SDecoder dc = {0}; + int32_t ret = 0; rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData); if (rc < 0) { @@ -1347,7 +1468,11 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } int64_t version = ((SUidIdxVal *)pData)[0].version; - (void)tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); + rc = tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); + if (rc < 0) { + tdbFree(pData); + return rc; + } tDecoderInit(&dc, pData, nData); rc = metaDecodeEntry(&dc, &e); @@ -1370,7 +1495,12 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p SMetaEntry stbEntry = {0}; tDecoderInit(&tdc, tData, tLen); - (void)metaDecodeEntry(&tdc, &stbEntry); + int32_t ret = metaDecodeEntry(&tdc, &stbEntry); + if (ret < 0) { + metaError("vgId:%d, failed to decode child table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, + e.ctbEntry.suid, tstrerror(ret)); + return ret; + } if (pSysTbl) *pSysTbl = metaTbInFilterCache(pMeta, stbEntry.name, 1) ? 1 : 0; @@ -1378,7 +1508,11 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; - (void)metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); + ret = metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); + if (ret < 0) { + metaError("vgId:%d, failed to delete json var from idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), + e.name, e.uid, tstrerror(ret)); + } } else { for (int i = 0; i < pTagSchema->nCols; i++) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[i]; @@ -1406,7 +1540,11 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p if (metaCreateTagIdxKey(e.ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, uid, &pTagIdxKey, &nTagIdxKey) == 0) { - (void)tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + ret = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete tag idx key:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), + e.name, e.uid, tstrerror(ret)); + } } metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; @@ -1418,9 +1556,21 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } } - (void)tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), pMeta->txn); - (void)tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn); - (void)tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn); + ret = tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } + ret = tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete name idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } + ret = tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete uid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteBtimeIdx(pMeta, &e); if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e); @@ -1428,13 +1578,25 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p if (e.type != TSDB_SUPER_TABLE) metaDeleteTtl(pMeta, &e); if (e.type == TSDB_CHILD_TABLE) { - (void)tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), - pMeta->txn); + ret = + tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete ctb idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } --pMeta->pVnode->config.vndStats.numOfCTables; - (void)metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1, 0); - (void)metaUidCacheClear(pMeta, e.ctbEntry.suid); - (void)metaTbGroupCacheClear(pMeta, e.ctbEntry.suid); + metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1, 0); + ret = metaUidCacheClear(pMeta, e.ctbEntry.suid); + if (ret < 0) { + metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, + e.ctbEntry.suid, tstrerror(ret)); + } + ret = metaTbGroupCacheClear(pMeta, e.ctbEntry.suid); + if (ret < 0) { + metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, + e.ctbEntry.suid, tstrerror(ret)); + } /* if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { tsdbCacheDropTable(pMeta->pVnode->pTsdb, e.uid, e.ctbEntry.suid, NULL); @@ -1452,16 +1614,36 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } */ } else if (e.type == TSDB_SUPER_TABLE) { - (void)tdbTbDelete(pMeta->pSuidIdx, &e.uid, sizeof(tb_uid_t), pMeta->txn); + ret = tdbTbDelete(pMeta->pSuidIdx, &e.uid, sizeof(tb_uid_t), pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to delete suid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } // drop schema.db (todo) - (void)metaStatsCacheDrop(pMeta, uid); - (void)metaUidCacheClear(pMeta, uid); - (void)metaTbGroupCacheClear(pMeta, uid); + ret = metaStatsCacheDrop(pMeta, uid); + if (ret < 0) { + metaError("vgId:%d, failed to drop stats cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } + ret = metaUidCacheClear(pMeta, uid); + if (ret < 0) { + metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } + ret = metaTbGroupCacheClear(pMeta, uid); + if (ret < 0) { + metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, + e.uid, tstrerror(ret)); + } --pMeta->pVnode->config.vndStats.numOfSTables; } - (void)metaCacheDrop(pMeta, uid); + ret = metaCacheDrop(pMeta, uid); + if (ret < 0) { + metaError("vgId:%d, failed to drop cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid, + tstrerror(ret)); + } tDecoderClear(&dc); tdbFree(pData); @@ -1535,21 +1717,21 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl TBC *pUidIdxc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL)); - (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + ret = tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); if (c != 0) { tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c); return TSDB_CODE_FAILED; } - (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); oversion = ((SUidIdxVal *)pData)[0].version; // search table.db TBC *pTbDbc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL)); - (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + ret = tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); if (c != 0) { tdbTbcClose(pUidIdxc); tdbTbcClose(pTbDbc); @@ -1557,13 +1739,13 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl return TSDB_CODE_FAILED; } - (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); // get table entry SDecoder dc = {0}; if ((entry.pBuf = taosMemoryMalloc(nData)) == NULL) { - (void)tdbTbcClose(pUidIdxc); - (void)tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); return terrno; } memcpy(entry.pBuf, pData, nData); diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 3191ddb447..85ed223c6c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -1051,7 +1051,9 @@ _end: return code; } -void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void)tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } +void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { + SRBTreeNode *node = tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); +} bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; }