From b6a8619d40bbeca1dee9fd0de0e3ee5cd43cb851 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 4 Sep 2024 10:00:14 +0800 Subject: [PATCH 01/90] enh:modify error code passing in libs/ --- source/libs/geometry/src/geomFunc.c | 8 ++-- source/libs/geometry/src/geosWrapper.c | 2 +- source/libs/index/src/index.c | 2 +- source/libs/index/src/indexCache.c | 8 ++-- source/libs/index/src/indexComm.c | 24 ++++++------ source/libs/index/src/indexFilter.c | 8 ++-- source/libs/index/src/indexTfile.c | 8 ++-- source/libs/index/src/indexUtil.c | 2 +- source/libs/nodes/src/nodesCloneFuncs.c | 4 +- source/libs/nodes/src/nodesCodeFuncs.c | 8 ++-- source/libs/nodes/src/nodesMsgFuncs.c | 2 +- source/libs/nodes/src/nodesUtilFuncs.c | 6 +-- source/libs/parser/src/parInsertSml.c | 14 +++---- source/libs/parser/src/parInsertSql.c | 10 ++--- source/libs/parser/src/parInsertStmt.c | 12 +++--- source/libs/parser/src/parInsertUtil.c | 14 +++---- source/libs/parser/src/parTranslater.c | 52 ++++++++++++------------- source/libs/parser/src/parUtil.c | 4 +- source/libs/parser/src/parser.c | 6 +-- 19 files changed, 97 insertions(+), 97 deletions(-) diff --git a/source/libs/geometry/src/geomFunc.c b/source/libs/geometry/src/geomFunc.c index 1752493dff..2ce2d92fa7 100644 --- a/source/libs/geometry/src/geomFunc.c +++ b/source/libs/geometry/src/geomFunc.c @@ -43,7 +43,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) { *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -74,7 +74,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { // make a zero ending string inputGeom = taosMemoryCalloc(1, varDataLen(input) + 1); if (inputGeom == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } (void)memcpy(inputGeom, varDataVal(input), varDataLen(input)); @@ -83,7 +83,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -114,7 +114,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) { size_t size = strlen(outputWKT); *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } diff --git a/source/libs/geometry/src/geosWrapper.c b/source/libs/geometry/src/geosWrapper.c index 5eeea54715..13c5f7208e 100644 --- a/source/libs/geometry/src/geosWrapper.c +++ b/source/libs/geometry/src/geosWrapper.c @@ -96,7 +96,7 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData int32_t code = 0; char *wktPatternWithSpace = taosMemoryCalloc(4, 1024); if (NULL == wktPatternWithSpace) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)sprintf( diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0d834a68cb..b2fd0afd68 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -112,7 +112,7 @@ int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { int code = TSDB_CODE_SUCCESS; SIndex* idx = taosMemoryCalloc(1, sizeof(SIndex)); if (idx == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, END); + TAOS_CHECK_GOTO(terrno, NULL, END); } idx->lru = taosLRUCacheInit(opts->cacheSize, -1, .5); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index a89cc47925..1b31c1e50b 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -137,7 +137,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); if (pCt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCt->colVal = term->colVal; @@ -206,7 +206,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); if (pCt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCt->colVal = term->colVal; @@ -584,7 +584,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // encode data CacheTerm* ct = taosMemoryCalloc(1, sizeof(CacheTerm)); if (ct == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // set up key ct->colType = term->colType; @@ -594,7 +594,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1)); if (ct->colVal == NULL) { taosMemoryFree(ct); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(ct->colVal, term->colVal, term->nColVal); } diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 8dc63ed105..2c681a1df3 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -323,7 +323,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_TIMESTAMP: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int64_t*)src, *dst, -1); tlen = strlen(*dst); @@ -332,7 +332,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UTINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint8_t*)src, *dst, 1); tlen = strlen(*dst); @@ -340,7 +340,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_TINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int8_t*)src, *dst, 1); tlen = strlen(*dst); @@ -348,7 +348,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_SMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int16_t*)src, *dst, -1); tlen = strlen(*dst); @@ -361,7 +361,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_INT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int32_t*)src, *dst, -1); tlen = strlen(*dst); @@ -369,7 +369,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint32_t*)src, *dst, 1); tlen = strlen(*dst); @@ -377,7 +377,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_BIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%" PRIu64, *(uint64_t*)src); tlen = strlen(*dst); @@ -385,7 +385,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UBIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint64_t*)src, *dst, 1); tlen = strlen(*dst); @@ -393,7 +393,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_FLOAT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%.9lf", *(float*)src); tlen = strlen(*dst); @@ -401,7 +401,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_DOUBLE: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%.9lf", *(double*)src); tlen = strlen(*dst); @@ -410,7 +410,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; @@ -422,7 +422,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index 03474c0143..fa59fe23fe 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -197,7 +197,7 @@ static FORCE_INLINE int32_t sifGetValueFromNode(SNode *node, char **value) { } char *tv = taosMemoryCalloc(1, valLen + 1); if (tv == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(tv, pData, valLen); @@ -273,7 +273,7 @@ static int32_t sifInitParamValByCol(SNode *r, SNode *l, SIFParam *param, SIFCtx } char *tv = taosMemoryCalloc(1, valLen + 1); if (tv == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(tv, pData, valLen); @@ -373,7 +373,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam)); if (NULL == paramList) { - SIF_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SIF_ERR_RET(terrno); } if (nodeType(node->pLeft) == QUERY_NODE_OPERATOR && @@ -405,7 +405,7 @@ static int32_t sifInitParamList(SIFParam **params, SNodeList *nodeList, SIFCtx * SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam)); if (tParams == NULL) { indexError("failed to calloc, nodeList: %p", nodeList); - SIF_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SIF_ERR_RET(terrno); } SListCell *cell = nodeList->pHead; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 55a9bb06d9..405e899100 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -201,7 +201,7 @@ int32_t tfileReaderCreate(IFileCtx* ctx, TFileReader** pReader) { int32_t code = 0; TFileReader* reader = taosMemoryCalloc(1, sizeof(TFileReader)); if (reader == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } reader->ctx = ctx; reader->remove = false; @@ -609,7 +609,7 @@ int32_t tfileWriterCreate(IFileCtx* ctx, TFileHeader* header, TFileWriter** pWri int32_t code = 0; TFileWriter* tw = taosMemoryCalloc(1, sizeof(TFileWriter)); if (tw == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; indexError("index: %" PRIu64 " failed to alloc TFilerWriter since %s", header->suid, tstrerror(code)); return code; } @@ -661,7 +661,7 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { int32_t cap = 4 * 1024; char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (size_t i = 0; i < sz; i++) { @@ -1137,7 +1137,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { size_t len = strlen(path) + 1 + strlen(file) + 1; char* buf = taosMemoryCalloc(1, len); if (buf == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } sprintf(buf, "%s/%s", path, file); diff --git a/source/libs/index/src/indexUtil.c b/source/libs/index/src/indexUtil.c index 6a52b7b5a4..aca1ec37fe 100644 --- a/source/libs/index/src/indexUtil.c +++ b/source/libs/index/src/indexUtil.c @@ -44,7 +44,7 @@ int32_t iIntersection(SArray *in, SArray *out) { } MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); if (mi == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < sz; i++) { SArray *t = taosArrayGetP(in, i); diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index e2c5b42e39..b76e4448d3 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -179,7 +179,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { int32_t len = pSrc->node.resType.bytes + 1; pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pDst->datum.p, pSrc->datum.p, len); break; @@ -188,7 +188,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { int32_t len = getJsonValueLen(pSrc->datum.p); pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pDst->datum.p, pSrc->datum.p, len); break; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 1425df5c5a..74879a53af 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -4083,14 +4083,14 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { case TSDB_DATA_TYPE_GEOMETRY: { pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + 1); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } varDataSetLen(pNode->datum.p, pNode->node.resType.bytes - VARSTR_HEADER_SIZE); if (TSDB_DATA_TYPE_NCHAR == pNode->node.resType.type) { char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + VARSTR_HEADER_SIZE + 1); if (NULL == buf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tjsonGetStringValue(pJson, jkValueDatum, buf); @@ -4112,12 +4112,12 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { case TSDB_DATA_TYPE_JSON: { pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + 1); if (NULL == buf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tjsonGetStringValue(pJson, jkValueDatum, buf); diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index b3568e914e..e71cfc47f8 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -952,7 +952,7 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) { } pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + 1); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tlvDecodeBinary(pTlv, pNode->datum.p); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 1d6c19346a..d58ee8dbdd 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -120,7 +120,7 @@ static int32_t callocNodeChunk(SNodeAllocator* pAllocator, SNodeMemChunk** pOutC SNodeMemChunk* pNewChunk = taosMemoryCalloc(1, sizeof(SNodeMemChunk) + pAllocator->chunkSize); if (NULL == pNewChunk) { if (pOutChunk) *pOutChunk = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pNewChunk->pBuf = (char*)(pNewChunk + 1); pNewChunk->availableSize = pAllocator->chunkSize; @@ -141,7 +141,7 @@ static int32_t callocNodeChunk(SNodeAllocator* pAllocator, SNodeMemChunk** pOutC static int32_t nodesCallocImpl(int32_t size, void** pOut) { if (NULL == g_pNodeAllocator) { *pOut = taosMemoryCalloc(1, size); - if (!*pOut) return TSDB_CODE_OUT_OF_MEMORY; + if (!*pOut) return terrno; return TSDB_CODE_SUCCESS; } @@ -180,7 +180,7 @@ void nodesFree(void* p) { static int32_t createNodeAllocator(int32_t chunkSize, SNodeAllocator** pAllocator) { *pAllocator = taosMemoryCalloc(1, sizeof(SNodeAllocator)); if (NULL == *pAllocator) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pAllocator)->chunkSize = chunkSize; int32_t code = callocNodeChunk(*pAllocator, NULL); diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index acd1851d76..23025dcab9 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -48,7 +48,7 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* static int32_t smlBoundColumnData(SArray* cols, SBoundColInfo* pBoundInfo, SSchema* pSchema, bool isTag) { bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool)); if (NULL == pUseCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBoundInfo->numOfBound = 0; @@ -139,7 +139,7 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem int32_t output = 0; void* p = taosMemoryCalloc(1, kv->length * TSDB_NCHAR_SIZE); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) { @@ -240,7 +240,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 taosMemoryFree(tmp); } else { uError("SML smlBuildCol out of memory"); - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; } goto end; } @@ -253,7 +253,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 } char* pUcs4 = taosMemoryCalloc(1, size); if (NULL == pUcs4) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) { @@ -315,7 +315,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pCreateTblReq) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName, pTableMeta->tableInfo.numOfTags, @@ -323,7 +323,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1); if (pCreateTblReq->ctb.stbName == NULL){ - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen); @@ -400,7 +400,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc int32_t len = 0; char* pUcs4 = taosMemoryCalloc(1, pColSchema->bytes - VARSTR_HEADER_SIZE); if (NULL == pUcs4) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) { diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index a8db514ee3..b87a1aabd0 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -182,7 +182,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, E bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool)); if (NULL == pUseCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBoundInfo->numOfBound = 0; @@ -768,7 +768,7 @@ static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* p } pStmt->pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pStmt->pCreateTblReq) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } insBuildCreateTbReq(pStmt->pCreateTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid, pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags, @@ -850,7 +850,7 @@ static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) { case TSDB_DATA_TYPE_NCHAR: pValue->datum.p = taosMemoryCalloc(1, pVal->nData + VARSTR_HEADER_SIZE); if (NULL == pValue->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pValue->datum.p, pVal->nData); memcpy(varDataVal(pValue->datum.p), pVal->pData, pVal->nData); @@ -1916,7 +1916,7 @@ static int32_t processCtbAutoCreationAndCtbMeta(SInsertParseContext* pCxt, SVnod pStbRowsCxt->pCreateCtbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (pStbRowsCxt->pCreateCtbReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } if (code == TSDB_CODE_SUCCESS) { insBuildCreateTbReq(pStbRowsCxt->pCreateCtbReq, pStbRowsCxt->ctbName.tname, pStbRowsCxt->pTag, @@ -2319,7 +2319,7 @@ static void destroyStbRowsDataContext(SStbRowsDataContext* pStbRowsCxt) { static int32_t constructStbRowsDataContext(SVnodeModifyOpStmt* pStmt, SStbRowsDataContext** ppStbRowsCxt) { SStbRowsDataContext* pStbRowsCxt = taosMemoryCalloc(1, sizeof(SStbRowsDataContext)); if (!pStbRowsCxt) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tNameAssign(&pStbRowsCxt->stbName, &pStmt->targetTableName); int32_t code = collectUseTable(&pStbRowsCxt->stbName, pStmt->pTableNameHashObj); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 025459a8c9..c1a228d572 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -32,7 +32,7 @@ typedef struct SKvParam { int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) { *pData = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == *pData) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSubmitTbData* pNew = *pData; @@ -190,7 +190,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch int32_t output = 0; void* p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { @@ -224,7 +224,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch if (NULL == pDataBlock->pData->pCreateTbReq) { pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pDataBlock->pData->pCreateTbReq) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -465,7 +465,7 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc if (fields) { *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E)); if (NULL == *fields) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSchema* schema = &pSchema[boundColumns[0]]; @@ -572,7 +572,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese *pDst = taosMemoryCalloc(1, sizeof(STableDataCxt)); if (NULL == *pDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STableDataCxt* pNewCxt = (STableDataCxt*)*pDst; @@ -650,7 +650,7 @@ int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_ if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) { pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pBlock->pData->pCreateTbReq) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index b0581d2fd3..e77678fb69 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -188,7 +188,7 @@ int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) { pInfo->hasBoundCols = false; pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t)); if (NULL == pInfo->pColIndex) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < numOfBound; ++i) { pInfo->pColIndex[i] = i; @@ -230,7 +230,7 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat STableDataCxt* pTableCxt = taosMemoryCalloc(1, sizeof(STableDataCxt)); if (NULL == pTableCxt) { *pOutput = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -264,7 +264,7 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat if (TSDB_CODE_SUCCESS == code) { pTableCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == pTableCxt->pData) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pTableCxt->pData->flags = (pCreateTbReq != NULL && NULL != *pCreateTbReq) ? SUBMIT_REQ_AUTO_CREATE_TABLE : 0; pTableCxt->pData->flags |= colMode ? SUBMIT_REQ_COLUMN_DATA_FORMAT : 0; @@ -300,7 +300,7 @@ static int32_t rebuildTableData(SSubmitTbData* pSrc, SSubmitTbData** pDst) { int32_t code = TSDB_CODE_SUCCESS; SSubmitTbData* pTmp = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == pTmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pTmp->flags = pSrc->flags; pTmp->suid = pSrc->suid; @@ -477,12 +477,12 @@ static int32_t createVgroupDataCxt(STableDataCxt* pTableCxt, SHashObj* pVgroupHa SVgroupDataCxt** pOutput) { SVgroupDataCxt* pVgCxt = taosMemoryCalloc(1, sizeof(SVgroupDataCxt)); if (NULL == pVgCxt) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitReq2)); if (NULL == pVgCxt->pData) { insDestroyVgroupDataCxt(pVgCxt); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgCxt->vgId = pTableCxt->pMeta->vgId; @@ -840,7 +840,7 @@ int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, } SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == dst) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } if (TSDB_CODE_SUCCESS == code) { dst->numOfTables = taosArrayGetSize(src->pData->aSubmitTbData); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 6c86a6c12f..d79a880e72 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2928,7 +2928,7 @@ static int32_t rewriteQueryTimeFunc(STranslateContext* pCxt, int64_t val, SNode* char* pStr = taosMemoryCalloc(1, 20); if (NULL == pStr) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } snprintf(pStr, 20, "%" PRId64 "", val); int32_t code = rewriteFuncToValue(pCxt, &pStr, pNode); @@ -3768,7 +3768,7 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { size_t vgroupNum = taosArrayGetSize(pVgs); *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); if (NULL == *pVgsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pVgsInfo)->numOfVgroups = vgroupNum; for (int32_t i = 0; i < vgroupNum; ++i) { @@ -3797,7 +3797,7 @@ static int32_t dnodeToVgroupsInfo(SArray* pDnodes, SVgroupsInfo** pVgsInfo) { size_t ndnode = taosArrayGetSize(pDnodes); *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * ndnode); if (NULL == *pVgsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pVgsInfo)->numOfVgroups = ndnode; for (int32_t i = 0; i < ndnode; ++i) { @@ -3925,7 +3925,7 @@ static int32_t setSuperTableVgroupList(STranslateContext* pCxt, SName* pName, SR static int32_t setNormalTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { pRealTable->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (NULL == pRealTable->pVgroupList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRealTable->pVgroupList->numOfVgroups = 1; return getTableHashVgroupImpl(pCxt, pName, pRealTable->pVgroupList->vgroups); @@ -4033,7 +4033,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo } SVgroupsInfo* pVgpsInfo = taosMemoryCalloc(1, sizeof(int32_t) + sizeof(SVgroupInfo)); if (!pVgpsInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } pVgpsInfo->numOfVgroups = 1; @@ -6346,7 +6346,7 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* const char* pTbName = taosArrayGetP(pInfo->aTbnames, k); char* pNewTbName = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN + TSDB_TABLE_NAME_LEN + 1); if (!pNewTbName) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } if (NULL == taosArrayPush(pTbNames, &pNewTbName)) { @@ -8670,7 +8670,7 @@ static int32_t createRollupTableMeta(SCreateTableStmt* pStmt, int8_t precision, int32_t numOfField = LIST_LENGTH(pStmt->pCols) + LIST_LENGTH(pStmt->pTags); STableMeta* pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + numOfField * sizeof(SSchema)); if (NULL == pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pMeta->tableType = TSDB_SUPER_TABLE; pMeta->tableInfo.numOfTags = LIST_LENGTH(pStmt->pTags); @@ -9466,7 +9466,7 @@ static int32_t checkCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pS static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { int32_t code = checkCreateSmaIndex(pCxt, pStmt); pStmt->pReq = taosMemoryCalloc(1, sizeof(SMCreateSmaReq)); - if (pStmt->pReq == NULL) code = TSDB_CODE_OUT_OF_MEMORY; + if (pStmt->pReq == NULL) code = terrno; if (TSDB_CODE_SUCCESS == code) { code = buildCreateSmaReq(pCxt, pStmt, pStmt->pReq); } @@ -11376,7 +11376,7 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { *buf = taosMemoryCalloc(1, *len); if (*buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY); @@ -11636,7 +11636,7 @@ static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) { pStmt->pCfg = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); if (NULL == pStmt->pCfg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SName name; @@ -11650,7 +11650,7 @@ static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateD static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTableStmt* pStmt) { pStmt->pDbCfg = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); if (NULL == pStmt->pDbCfg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pDbCfg); if (TSDB_CODE_SUCCESS == code) { @@ -12074,7 +12074,7 @@ static int32_t translateCreateTSMA(STranslateContext* pCxt, SCreateTSMAStmt* pSt SName useTbName = {0}; if (code == TSDB_CODE_SUCCESS) { pStmt->pReq = taosMemoryCalloc(1, sizeof(SMCreateSmaReq)); - if (!pStmt->pReq) return TSDB_CODE_OUT_OF_MEMORY; + if (!pStmt->pReq) return terrno; } if (code == TSDB_CODE_SUCCESS) { code = buildCreateTSMAReq(pCxt, pStmt, pStmt->pReq, &useTbName); @@ -12382,7 +12382,7 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t* *numOfCols = LIST_LENGTH(pProjections); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SNode* pNode; @@ -12414,7 +12414,7 @@ static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema) *numOfCols = 1; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; (*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; @@ -12427,7 +12427,7 @@ static int32_t extractDescribeResultSchema(STableMeta* pMeta, int32_t* numOfCols if (pMeta && useCompress(pMeta->tableType)) *numOfCols = DESCRIBE_RESULT_COLS_COMPRESS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12467,7 +12467,7 @@ static int32_t extractShowCreateDatabaseResultSchema(int32_t* numOfCols, SSchema *numOfCols = 2; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12485,7 +12485,7 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema** *numOfCols = 2; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12503,7 +12503,7 @@ static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** p *numOfCols = SHOW_CREATE_VIEW_RESULT_COLS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12521,7 +12521,7 @@ static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pS *numOfCols = 3; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12543,7 +12543,7 @@ static int32_t extractCompactDbResultSchema(int32_t* numOfCols, SSchema** pSchem *numOfCols = COMPACT_DB_RESULT_COLS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -13269,7 +13269,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema)); if (NULL == req.name || NULL == req.ntb.schemaRow.pSchema) { tdDestroySVCreateTbReq(&req); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pStmt->ignoreExists) { req.flags |= TD_CREATE_IF_NOT_EXISTS; @@ -13346,7 +13346,7 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFreeClear(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; @@ -14069,7 +14069,7 @@ static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFi { pCreateInfo = taosMemoryCalloc(1, sizeof(SCreateTbInfo)); if (NULL == pCreateInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } @@ -14379,7 +14379,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFreeClear(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; @@ -14829,7 +14829,7 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFree(pMsg); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = vg; pVgData->pData = pMsg; @@ -14934,7 +14934,7 @@ static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFree(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = *pVg; pVgData->pData = buf; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 250e9385b4..5c4ced7004 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -463,7 +463,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi int32_t valLen = (int32_t)strlen(jsonValue); char* tmp = taosMemoryCalloc(1, valLen * TSDB_NCHAR_SIZE); if (!tmp) { - retCode = TSDB_CODE_OUT_OF_MEMORY; + retCode = terrno; goto end; } val.type = TSDB_DATA_TYPE_NCHAR; @@ -1039,7 +1039,7 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) { *pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema)); if (NULL == *pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pMeta)->uid = pViewMeta->viewId; (*pMeta)->vgId = MNODE_HANDLE; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index e96aaf52ed..17f62ac157 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -172,7 +172,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { case TSDB_DATA_TYPE_VARBINARY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes); @@ -182,7 +182,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { case TSDB_DATA_TYPE_GEOMETRY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes); @@ -192,7 +192,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { pVal->node.resType.bytes *= TSDB_NCHAR_SIZE; pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t output = 0; From a4962b58a6fb06c594ef3949cb657c3ecabe2af7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 5 Sep 2024 17:52:21 +0800 Subject: [PATCH 02/90] add trace --- source/util/src/tref.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 0eac7b4427..d3fafa4167 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -19,10 +19,11 @@ #include "tlog.h" #include "tutil.h" -#define TSDB_REF_OBJECTS 50 -#define TSDB_REF_STATE_EMPTY 0 -#define TSDB_REF_STATE_ACTIVE 1 -#define TSDB_REF_STATE_DELETED 2 +#define TSDB_REF_OBJECTS 50 +#define TSDB_REF_STATE_EMPTY 0 +#define TSDB_REF_STATE_ACTIVE 1 +#define TSDB_REF_STATE_DELETED 2 +#define TSDB_REF_ITER_THRESHOLD 100 typedef struct SRefNode { struct SRefNode *prev; // previous node @@ -188,6 +189,7 @@ void *taosAcquireRef(int32_t rsetId, int64_t rid) { int32_t hash; SRefNode *pNode; SRefSet *pSet; + int32_t iter = 0; void *p = NULL; if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) { @@ -220,10 +222,14 @@ void *taosAcquireRef(int32_t rsetId, int64_t rid) { if (pNode->rid == rid) { break; } - + iter++; pNode = pNode->next; } + if (iter >= TSDB_REF_ITER_THRESHOLD) { + uWarn("rsetId:%d rid:%" PRId64 " iter:%d", rsetId, rid, iter); + } + if (pNode) { if (pNode->removed == 0) { pNode->count++; @@ -277,6 +283,7 @@ void *taosIterateRef(int32_t rsetId, int64_t rid) { do { newP = NULL; int32_t hash = 0; + int32_t iter = 0; if (rid > 0) { hash = rid % pSet->max; taosLockList(pSet->lockedBy + hash); @@ -285,6 +292,11 @@ void *taosIterateRef(int32_t rsetId, int64_t rid) { while (pNode) { if (pNode->rid == rid) break; pNode = pNode->next; + iter++; + } + + if (iter >= TSDB_REF_ITER_THRESHOLD) { + uWarn("rsetId:%d rid:%" PRId64 " iter:%d", rsetId, rid, iter); } if (pNode == NULL) { @@ -376,6 +388,7 @@ static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove) { int32_t hash; SRefSet *pSet; SRefNode *pNode; + int32_t iter = 0; int32_t released = 0; int32_t code = 0; @@ -403,6 +416,11 @@ static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove) { if (pNode->rid == rid) break; pNode = pNode->next; + iter++; + } + + if (iter >= TSDB_REF_ITER_THRESHOLD) { + uWarn("rsetId:%d rid:%" PRId64 " iter:%d", rsetId, rid, iter); } if (pNode) { From 0b21b7dff175950abba00dcb4d551afac2dd09af Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 14:25:50 +0800 Subject: [PATCH 03/90] fix indirect leak --- source/libs/transport/src/trans.c | 12 ++- source/libs/transport/src/transCli.c | 109 ++++++++------------ source/libs/transport/src/transSvr.c | 143 ++++++++++----------------- 3 files changed, 98 insertions(+), 166 deletions(-) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 1c783f44fe..f017909341 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -103,7 +103,7 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->timeToGetConn = 10 * 1000; } pRpc->notWaitAvaliableConn = pInit->notWaitAvaliableConn; - + pRpc->tcphandle = (*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc); @@ -124,14 +124,20 @@ _end: } void rpcClose(void* arg) { tInfo("start to close rpc"); + if (arg == NULL) { + return; + } (void)transRemoveExHandle(transGetInstMgt(), (int64_t)arg); (void)transReleaseExHandle(transGetInstMgt(), (int64_t)arg); tInfo("end to close rpc"); return; } void rpcCloseImpl(void* arg) { + if (arg == NULL) return; SRpcInfo* pRpc = (SRpcInfo*)arg; - (*taosCloseHandle[pRpc->connType])(pRpc->tcphandle); + if (pRpc->tcphandle != NULL) { + (*taosCloseHandle[pRpc->connType])(pRpc->tcphandle); + } taosMemoryFree(pRpc); } @@ -168,7 +174,7 @@ int32_t rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64 return transSendRequest(shandle, pEpSet, pMsg, NULL); } int32_t rpcSendRequestWithCtx(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { - if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0|| pRid == NULL) { + if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0 || pRid == NULL) { return transSendRequest(shandle, pEpSet, pMsg, pCtx); } else { return transSendRequestWithId(shandle, pEpSet, pMsg, pRid); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 78320c450c..5052d79ef3 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -99,12 +99,11 @@ typedef struct SCliMsg { } SCliMsg; typedef struct SCliThrd { - TdThread thread; // tid - int64_t pid; // pid - uv_loop_t* loop; - SAsyncPool* asyncPool; - uv_prepare_t* prepare; - void* pool; // conn pool + TdThread thread; // tid + int64_t pid; // pid + uv_loop_t* loop; + SAsyncPool* asyncPool; + void* pool; // conn pool // timer handles SArray* timerList; // msg queue @@ -167,7 +166,6 @@ static void cliSendCb(uv_write_t* req, int status); static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); static void cliIdleCb(uv_idle_t* handle); -static void cliPrepareCb(uv_prepare_t* handle); static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); static void cliSendBatchCb(uv_write_t* req, int status); @@ -231,7 +229,9 @@ static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); // thread obj static int32_t createThrdObj(void* trans, SCliThrd** pThrd); static void destroyThrdObj(SCliThrd* pThrd); -static void cliWalkCb(uv_handle_t* handle, void* arg); + +int32_t cliSendQuit(SCliThrd* thrd); +static void cliWalkCb(uv_handle_t* handle, void* arg); #define CLI_RELEASE_UV(loop) \ do { \ @@ -2119,33 +2119,6 @@ static void cliAsyncCb(uv_async_t* handle) { if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); } -static void cliPrepareCb(uv_prepare_t* handle) { - SCliThrd* thrd = handle->data; - tTrace("prepare work start"); - - SAsyncPool* pool = thrd->asyncPool; - for (int i = 0; i < pool->nAsync; i++) { - uv_async_t* async = &(pool->asyncs[i]); - SAsyncItem* item = async->data; - - queue wq; - (void)taosThreadMutexLock(&item->mtx); - QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); - - int count = 0; - while (!QUEUE_IS_EMPTY(&wq)) { - queue* h = QUEUE_HEAD(&wq); - QUEUE_REMOVE(h); - - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - (*cliAsyncHandle[pMsg->type])(pMsg, thrd); - count++; - } - } - tTrace("prepare work end"); - if (thrd->stopMsg != NULL) cliHandleQuit(thrd->stopMsg, thrd); -} void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); @@ -2260,6 +2233,12 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, _err: if (cli) { + for (int i = 0; i < cli->numOfThreads; i++) { + if (cli->pThreadObj[i]) { + (void)cliSendQuit(cli->pThreadObj[i]); + destroyThrdObj(cli->pThreadObj[i]); + } + } taosMemoryFree(cli->pThreadObj); taosMemoryFree(cli); } @@ -2339,37 +2318,6 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(code, NULL, _end); } - pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - if (pThrd->prepare == NULL) { - tError("failed to create prepre since:%s", tstrerror(code)); - TAOS_CHECK_GOTO(code, NULL, _end); - } - - code = uv_prepare_init(pThrd->loop, pThrd->prepare); - if (code != 0) { - tError("failed to create prepre since:%s", uv_err_name(code)); - TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); - } - pThrd->prepare->data = pThrd; - - int32_t timerSize = 64; - pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); - if (pThrd->timerList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); - } - - for (int i = 0; i < timerSize; i++) { - uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - if (timer == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); - } - (void)uv_timer_init(pThrd->loop, timer); - if (taosArrayPush(pThrd->timerList, &timer) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); - } - } - pThrd->pool = createConnPool(4); if (pThrd->pool == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -2402,6 +2350,23 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } + int32_t timerSize = 64; + pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); + if (pThrd->timerList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + + for (int i = 0; i < timerSize; i++) { + uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + if (timer == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + (void)uv_timer_init(pThrd->loop, timer); + if (taosArrayPush(pThrd->timerList, &timer) == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + } pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); pThrd->pTransInst = trans; pThrd->quit = false; @@ -2411,17 +2376,21 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { _end: if (pThrd) { + (void)taosThreadMutexDestroy(&pThrd->msgMtx); + (void)uv_loop_close(pThrd->loop); taosMemoryFree(pThrd->loop); - taosMemoryFree(pThrd->prepare); - (void)taosThreadMutexDestroy(&pThrd->msgMtx); transAsyncPoolDestroy(pThrd->asyncPool); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); taosMemoryFree(timer); } taosArrayDestroy(pThrd->timerList); - taosMemoryFree(pThrd->prepare); + + destroyConnPool(pThrd); + transDQDestroy(pThrd->delayQueue, NULL); + transDQDestroy(pThrd->timeoutQueue, NULL); + transDQDestroy(pThrd->waitConnQueue, NULL); taosHashCleanup(pThrd->fqdn2ipCache); taosHashCleanup(pThrd->failFastCache); taosHashCleanup(pThrd->batchCache); @@ -2450,8 +2419,8 @@ static void destroyThrdObj(SCliThrd* pThrd) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); taosMemoryFree(timer); } + uv_loop_close(pThrd->loop); taosArrayDestroy(pThrd->timerList); - taosMemoryFree(pThrd->prepare); taosMemoryFree(pThrd->loop); taosHashCleanup(pThrd->fqdn2ipCache); taosHashCleanup(pThrd->failFastCache); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 11aa468b19..0727e49d8b 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -82,14 +82,13 @@ typedef struct { int64_t ver; } SIpWhiteListTab; typedef struct SWorkThrd { - TdThread thread; - uv_connect_t connect_req; - uv_pipe_t* pipe; - uv_os_fd_t fd; - uv_loop_t* loop; - SAsyncPool* asyncPool; - uv_prepare_t* prepare; - queue msg; + TdThread thread; + uv_connect_t connect_req; + uv_pipe_t* pipe; + uv_os_fd_t fd; + uv_loop_t* loop; + SAsyncPool* asyncPool; + queue msg; queue conn; void* pTransInst; @@ -98,6 +97,7 @@ typedef struct SWorkThrd { SIpWhiteListTab* pWhiteList; int64_t whiteListVer; int8_t enableIpWhiteList; + int8_t inited; } SWorkThrd; typedef struct SServerObj { @@ -139,7 +139,6 @@ static void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) static void uvWorkerAsyncCb(uv_async_t* handle); static void uvAcceptAsyncCb(uv_async_t* handle); static void uvShutDownCb(uv_shutdown_t* req, int status); -static void uvPrepareCb(uv_prepare_t* handle); static bool uvRecvReleaseReq(SSvrConn* conn, STransMsgHead* pHead); @@ -180,6 +179,11 @@ static void uvDestroyConn(uv_handle_t* handle); static void* transWorkerThread(void* arg); static void* transAcceptThread(void* arg); +static void destroyWorkThrd(SWorkThrd* pThrd); +static void destroyWorkThrdObj(SWorkThrd* pThrd); + +static void sendQuitToWorkThrd(SWorkThrd* pThrd); + // add handle loop static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); static int32_t addHandleToAcceptloop(void* arg); @@ -849,52 +853,6 @@ static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { } return false; } -static void uvPrepareCb(uv_prepare_t* handle) { - // prepare callback - SWorkThrd* pThrd = handle->data; - SAsyncPool* pool = pThrd->asyncPool; - - for (int i = 0; i < pool->nAsync; i++) { - uv_async_t* async = &(pool->asyncs[i]); - SAsyncItem* item = async->data; - - queue wq; - (void)taosThreadMutexLock(&item->mtx); - QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); - - while (!QUEUE_IS_EMPTY(&wq)) { - queue* head = QUEUE_HEAD(&wq); - QUEUE_REMOVE(head); - - SSvrMsg* msg = QUEUE_DATA(head, SSvrMsg, q); - if (msg == NULL) { - tError("unexcept occurred, continue"); - continue; - } - // release handle to rpc init - if (msg->type == Quit || msg->type == Update) { - (*transAsyncHandle[msg->type])(msg, pThrd); - continue; - } else { - STransMsg transMsg = msg->msg; - - SExHandle* exh1 = transMsg.info.handle; - int64_t refId = transMsg.info.refId; - SExHandle* exh2 = transAcquireExHandle(transGetSvrRefMgt(), refId); - if (exh2 == NULL || exh1 != exh2) { - tTrace("handle except msg %p, ignore it", exh1); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); - destroySmsg(msg); - continue; - } - msg->pConn = exh1->handle; - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); - (*transAsyncHandle[msg->type])(msg, pThrd); - } - } - } -} static void uvWorkDoTask(uv_work_t* req) { // doing time-consumeing task @@ -1101,25 +1059,6 @@ static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { QUEUE_INIT(&pThrd->msg); - pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - if (pThrd->prepare == NULL) { - tError("failed to init prepare"); - return TSDB_CODE_OUT_OF_MEMORY; - } - - code = uv_prepare_init(pThrd->loop, pThrd->prepare); - if (code != 0) { - tError("failed to init prepare since %s", uv_err_name(code)); - return TSDB_CODE_THIRDPARTY_ERROR; - } - - code = uv_prepare_start(pThrd->prepare, uvPrepareCb); - if (code != 0) { - tError("failed to start prepare since %s", uv_err_name(code)); - return TSDB_CODE_THIRDPARTY_ERROR; - } - pThrd->prepare->data = pThrd; - // conn set QUEUE_INIT(&pThrd->conn); @@ -1421,11 +1360,11 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } - if (false == taosValidIpAndPort(srv->ip, srv->port)) { - code = TAOS_SYSTEM_ERROR(errno); - tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); - goto End; - } + // if (false == taosValidIpAndPort(srv->ip, srv->port)) { + // code = TAOS_SYSTEM_ERROR(errno); + // tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); + // goto End; + // } char pipeName[PATH_MAX]; #if defined(WINDOWS) || defined(DARWIN) @@ -1485,12 +1424,14 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, code = TSDB_CODE_OUT_OF_MEMORY; goto End; } + srv->pThreadObj[i] = thrd; thrd->pTransInst = shandle; thrd->quit = false; thrd->pTransInst = shandle; thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { + destroyWorkThrdObj(thrd); code = TSDB_CODE_OUT_OF_MEMORY; goto End; } @@ -1501,8 +1442,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } - srv->pThreadObj[i] = thrd; - uv_os_sock_t fds[2]; if ((code = uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE)) != 0) { tError("failed to create pipe, errmsg: %s", uv_err_name(code)); @@ -1539,6 +1478,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, tError("failed to create worker-thread:%d", i); goto End; } + thrd->inited = 1; } #endif @@ -1560,6 +1500,12 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, srv->inited = true; return srv; End: + for (int i = 0; i < srv->numOfThreads; i++) { + if (srv->pThreadObj[i] != NULL) { + SWorkThrd* thrd = srv->pThreadObj[i]; + destroyWorkThrd(thrd); + } + } transCloseServer(srv); terrno = code; return NULL; @@ -1663,20 +1609,27 @@ void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { taosMemoryFree(msg); } +void destroyWorkThrdObj(SWorkThrd* pThrd) { + if (pThrd == NULL) { + return; + } + transAsyncPoolDestroy(pThrd->asyncPool); + uvWhiteListDestroy(pThrd->pWhiteList); + uv_loop_close(pThrd->loop); + taosMemoryFree(pThrd->loop); + taosMemoryFree(pThrd); +} void destroyWorkThrd(SWorkThrd* pThrd) { if (pThrd == NULL) { return; } - (void)taosThreadJoin(pThrd->thread, NULL); - SRV_RELEASE_UV(pThrd->loop); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); - transAsyncPoolDestroy(pThrd->asyncPool); - - uvWhiteListDestroy(pThrd->pWhiteList); - - taosMemoryFree(pThrd->prepare); - taosMemoryFree(pThrd->loop); - taosMemoryFree(pThrd); + if (pThrd->inited) { + sendQuitToWorkThrd(pThrd); + (void)taosThreadJoin(pThrd->thread, NULL); + SRV_RELEASE_UV(pThrd->loop); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); + } + destroyWorkThrdObj(pThrd); } void sendQuitToWorkThrd(SWorkThrd* pThrd) { SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); @@ -1693,13 +1646,15 @@ void transCloseServer(void* arg) { tDebug("send quit msg to accept thread"); (void)uv_async_send(srv->pAcceptAsync); (void)taosThreadJoin(srv->thread, NULL); + SRV_RELEASE_UV(srv->loop); + (void)uv_loop_close(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { - sendQuitToWorkThrd(srv->pThreadObj[i]); destroyWorkThrd(srv->pThreadObj[i]); } } else { + SRV_RELEASE_UV(srv->loop); (void)uv_loop_close(srv->loop); } @@ -1708,7 +1663,9 @@ void transCloseServer(void* arg) { taosMemoryFree(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { - taosMemoryFree(srv->pipe[i]); + if (srv->pipe[i] != NULL) { + taosMemoryFree(srv->pipe[i]); + } } taosMemoryFree(srv->pipe); From b6b0e266eb3033821a1655cadaafa26581124229 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 14:28:34 +0800 Subject: [PATCH 04/90] fix indirect leak --- source/libs/transport/src/transSvr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 0727e49d8b..7e06767cb5 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1360,11 +1360,11 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } - // if (false == taosValidIpAndPort(srv->ip, srv->port)) { - // code = TAOS_SYSTEM_ERROR(errno); - // tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); - // goto End; - // } + if (false == taosValidIpAndPort(srv->ip, srv->port)) { + code = TAOS_SYSTEM_ERROR(errno); + tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); + goto End; + } char pipeName[PATH_MAX]; #if defined(WINDOWS) || defined(DARWIN) From 0973fb6eed8a96bc0ec30dfa6e5b59fcfc35b6b3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 16:14:19 +0800 Subject: [PATCH 05/90] fix indirect leak --- source/libs/transport/src/transCli.c | 4 ++-- source/libs/transport/src/transSvr.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5052d79ef3..85c8f7c21a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2387,7 +2387,7 @@ _end: } taosArrayDestroy(pThrd->timerList); - destroyConnPool(pThrd); + (void)destroyConnPool(pThrd); transDQDestroy(pThrd->delayQueue, NULL); transDQDestroy(pThrd->timeoutQueue, NULL); transDQDestroy(pThrd->waitConnQueue, NULL); @@ -2419,7 +2419,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); taosMemoryFree(timer); } - uv_loop_close(pThrd->loop); + (void)uv_loop_close(pThrd->loop); taosArrayDestroy(pThrd->timerList); taosMemoryFree(pThrd->loop); taosHashCleanup(pThrd->fqdn2ipCache); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 7e06767cb5..38c7edeeaf 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1615,7 +1615,7 @@ void destroyWorkThrdObj(SWorkThrd* pThrd) { } transAsyncPoolDestroy(pThrd->asyncPool); uvWhiteListDestroy(pThrd->pWhiteList); - uv_loop_close(pThrd->loop); + (void)uv_loop_close(pThrd->loop); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } From 3b283b63507a64fddd30fa7a219e15e559f733ee Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 16:36:19 +0800 Subject: [PATCH 06/90] fix indirect leak --- source/libs/transport/src/transCli.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 85c8f7c21a..c2ce00c1cf 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2383,6 +2383,7 @@ _end: transAsyncPoolDestroy(pThrd->asyncPool); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); + (void)uv_timer_stop(timer); taosMemoryFree(timer); } taosArrayDestroy(pThrd->timerList); @@ -2417,8 +2418,10 @@ static void destroyThrdObj(SCliThrd* pThrd) { tDebug("thread destroy %" PRId64, pThrd->pid); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); + (void)uv_timer_stop(timer); taosMemoryFree(timer); } + (void)uv_loop_close(pThrd->loop); taosArrayDestroy(pThrd->timerList); taosMemoryFree(pThrd->loop); From 46a79c0be333809745ea9e69580bd5d71af0b934 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 17:50:35 +0800 Subject: [PATCH 07/90] fix indirect leak --- source/libs/transport/src/transCli.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c2ce00c1cf..803e50ce94 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -619,7 +619,11 @@ void* createConnPool(int size) { return taosHashInit(size, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); } void* destroyConnPool(SCliThrd* pThrd) { - void* pool = pThrd->pool; + void* pool = pThrd->pool; + if (pool == NULL) { + return NULL; + } + SConnList* connList = taosHashIterate((SHashObj*)pool, NULL); while (connList != NULL) { while (!QUEUE_IS_EMPTY(&connList->conns)) { From 9a06b6eb58944da6c35c7a9d26e1065fc9a11140 Mon Sep 17 00:00:00 2001 From: WANG Xu Date: Fri, 6 Sep 2024 18:11:32 +0800 Subject: [PATCH 08/90] docs: add browser version requirements --- docs/en/14-reference/01-components/07-explorer.md | 2 +- docs/zh/14-reference/01-components/07-explorer.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/14-reference/01-components/07-explorer.md b/docs/en/14-reference/01-components/07-explorer.md index 2a824c6d8f..c270dadb3b 100644 --- a/docs/en/14-reference/01-components/07-explorer.md +++ b/docs/en/14-reference/01-components/07-explorer.md @@ -4,7 +4,7 @@ sidebar_label: Taos-Explorer description: User guide about taosExplorer --- -taos-explorer is a web service which provides GUI based interactive database management tool. +taos-explorer is a web service which provides GUI based interactive database management tool. To ensure the best experience when accessing taosExplorer, please use Chrome version 79 or higher, Edge version 79 or higher. ## Install diff --git a/docs/zh/14-reference/01-components/07-explorer.md b/docs/zh/14-reference/01-components/07-explorer.md index 5a84490b81..6a8972deea 100644 --- a/docs/zh/14-reference/01-components/07-explorer.md +++ b/docs/zh/14-reference/01-components/07-explorer.md @@ -4,7 +4,7 @@ sidebar_label: taosExplorer toc_max_heading_level: 4 --- -taosExplorer 是一个为用户提供 TDengine 实例的可视化管理交互工具的 web 服务。本节主要讲述其安装和部署。它的各项功能都是基于简单易上手的图形界面,可以直接尝试,如果有需要也可以考高级功能和运维指南中的相关内容。 +taosExplorer 是一个为用户提供 TDengine 实例的可视化管理交互工具的 web 服务。本节主要讲述其安装和部署。它的各项功能都是基于简单易上手的图形界面,可以直接尝试,如果有需要也可以考高级功能和运维指南中的相关内容。为了确保访问 taosExplorer 的最佳体验,请使用 Chrome 79 及以上版本,或 Edge 79 及以上版本。 ## 安装 From 520336e129eeda517a4f28a81504fb41d63431b2 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 9 Sep 2024 15:47:17 +0800 Subject: [PATCH 09/90] osDir --- source/client/src/clientMonitor.c | 5 +-- source/common/src/cos.c | 1 - source/libs/index/src/indexTfile.c | 2 +- source/libs/stream/src/streamBackendRocksdb.c | 6 ++-- source/libs/stream/src/streamCheckpoint.c | 2 +- source/libs/stream/src/streamSnapshot.c | 2 +- source/libs/tdb/src/db/tdbPager.c | 4 +-- source/libs/wal/src/walMeta.c | 4 +-- source/os/src/osDir.c | 34 ++++++++++++++++--- source/util/src/tcompare.c | 4 +-- 10 files changed, 44 insertions(+), 20 deletions(-) diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 9ed6512352..6a0a09f9bd 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -821,9 +821,10 @@ int32_t monitorInit() { return code; } - if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) { + code = taosMulModeMkDir(tmpSlowLogPath, 0777, true); + if (code != 0) { tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr()); - return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + return code; } if (tsem2_init(&monitorSem, 0, 0) != 0) { diff --git a/source/common/src/cos.c b/source/common/src/cos.c index f02130d468..064e06eb43 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) { // 1, list data files' atime under dir(path) tdbDirPtr pDir = taosOpenDir(dir_name); if (pDir == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); vError("failed to open %s since %s", dir_name, terrstr()); } SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile)); diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 55a9bb06d9..8e1c4a2d2f 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -1125,7 +1125,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { TdDirPtr pDir = taosOpenDir(path); if (NULL == pDir) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } TdDirEntryPtr pDirEntry; while ((pDirEntry = taosReadDir(pDir)) != NULL) { diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 4793a8951a..465968dc50 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -599,7 +599,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { // copy file to dst TdDirPtr pDir = taosOpenDir(src); if (pDir == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _ERROR; } @@ -1428,7 +1428,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI code = taosMulModeMkDir(pChkpDir, 0755, true); if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code)); goto _EXIT; } @@ -4633,7 +4633,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { TdDirPtr pDir = taosOpenDir(p->buf); if (pDir == NULL) { (void)taosThreadRwlockUnlock(&p->rwLock); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } TdDirEntryPtr de = NULL; diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 916aee4e6e..05dcab3aae 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -1224,7 +1224,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) { TdDirPtr pDir = taosOpenDir(path); if (pDir == NULL) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } TdDirEntryPtr de = NULL; diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 0390422623..eb222efce6 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -271,7 +271,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { int32_t code = 0; TdDirPtr pDir = taosOpenDir(pSnapFile->path); if (NULL == pDir) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code)); return code; } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index b0f32136a3..4a5ad9d663 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -1136,7 +1136,7 @@ int tdbPagerRestoreJournals(SPager *pPager) { tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName); if (pDir == NULL) { tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } SArray *pTxnList = taosArrayInit(16, sizeof(int64_t)); @@ -1182,7 +1182,7 @@ int tdbPagerRollback(SPager *pPager) { tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName); if (pDir == NULL) { tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno)); - return terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } while ((pDirEntry = tdbReadDir(pDir)) != NULL) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 0eb011113a..fb30dd3376 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -403,7 +403,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { regfree(&logRegPattern); regfree(&idxRegPattern); wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - TAOS_RETURN(TSDB_CODE_FAILED); + return terrno; } SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo)); @@ -422,7 +422,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { regfree(&idxRegPattern); (void)taosCloseDir(&pDir); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + return terrno; } } } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 9f3908183e..d233a4fe0e 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -145,7 +145,10 @@ int32_t taosMulMkDir(const char *dirname) { char *pos = temp; int32_t code = 0; #ifdef WINDOWS - taosRealPath(dirname, temp, sizeof(temp)); + code = taosRealPath(dirname, temp, sizeof(temp)); + if(code != 0) { + return code; + } if (temp[1] == ':') pos += 3; #else (void)strcpy(temp, dirname); @@ -207,7 +210,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { char *pos = temp; int32_t code = 0; #ifdef WINDOWS - taosRealPath(dirname, temp, sizeof(temp)); + code = taosRealPath(dirname, temp, sizeof(temp)); + if(code != 0) { + return code; + } if (temp[1] == ':') pos += 3; #else (void)strcpy(temp, dirname); @@ -430,6 +436,9 @@ TdDirPtr taosOpenDir(const char *dirname) { HANDLE hFind; TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir)); + if(pDir == NULL) { + return NULL; + } strcpy(szFind, dirname); strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录 @@ -437,6 +446,8 @@ TdDirPtr taosOpenDir(const char *dirname) { pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData)); if (INVALID_HANDLE_VALUE == pDir->hFind) { taosMemoryFree(pDir); + DWORD errorCode = GetLastError(); + terrno = TAOS_SYSTEM_ERROR(errorCode); return NULL; } return pDir; @@ -444,6 +455,11 @@ TdDirPtr taosOpenDir(const char *dirname) { DIR *pDir = opendir(dirname); if (pDir == NULL) return NULL; TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir)); + if (dirPtr == NULL) { + (void)closedir(pDir); + terrno = TAOS_SYSTEM_ERROR(errno); + return NULL; + } dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1); dirPtr->pDir = pDir; return dirPtr; @@ -506,22 +522,30 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { } int32_t taosCloseDir(TdDirPtr *ppDir) { + int32_t code = 0; if (ppDir == NULL || *ppDir == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } #ifdef WINDOWS - FindClose((*ppDir)->hFind); + if(!FindClose((*ppDir)->hFind)) { + terrno = TAOS_SYSTEM_ERROR(GetLastError()); + return terrno; + } taosMemoryFree(*ppDir); *ppDir = NULL; return 0; #elif defined(DARWIN) - closedir((*ppDir)->pDir); + code = closedir((*ppDir)->pDir); + if (-1 == code) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } taosMemoryFree(*ppDir); *ppDir = NULL; return 0; #else - int32_t code = closedir((DIR *)*ppDir); + code = closedir((DIR *)*ppDir); *ppDir = NULL; if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index afa048f0ac..b1f4ed0ed3 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1227,8 +1227,8 @@ static void checkRegexCache(void* param, void* tmrId) { if(sRegexCache.exit) { goto _exit; } - bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); - if (!ret) { + bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); + if (stopped) { uError("failed to reset regex cache timer"); goto _exit; } From 43c100b0261c7e6ce880dfaf1024bbab6fc907b5 Mon Sep 17 00:00:00 2001 From: Leo Xu <381899826@qq.com> Date: Mon, 9 Sep 2024 18:11:05 +0800 Subject: [PATCH 10/90] add flexify and S3azure case --- tests/army/storage/s3/azure.py | 86 +++++++ tests/army/storage/s3/s3Basic.py | 2 +- tests/army/storage/s3/s3azure.py | 391 +++++++++++++++++++++++++++++++ 3 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 tests/army/storage/s3/azure.py create mode 100644 tests/army/storage/s3/s3azure.py diff --git a/tests/army/storage/s3/azure.py b/tests/army/storage/s3/azure.py new file mode 100644 index 0000000000..a8b821a50f --- /dev/null +++ b/tests/army/storage/s3/azure.py @@ -0,0 +1,86 @@ +import requests +import hmac +import hashlib +import base64 +from datetime import datetime +from urllib.parse import urlparse, parse_qs +import xml.etree.ElementTree as ET + + +# Define a function to recursively convert XML into a dictionary +def xml_to_dict(element): + if len(element) == 0: + return element.text + result = {} + for child in element: + child_data = xml_to_dict(child) + if child.tag in result: + if isinstance(result[child.tag], list): + result[child.tag].append(child_data) + else: + result[child.tag] = [result[child.tag], child_data] + else: + result[child.tag] = child_data + return result + + +# Get the current time +def get_utc_now(): + return datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') + + +class Azure: + def __init__(self, account_name, account_key, container_name): + self.account_name = account_name + self.account_key = account_key + self.container_name = container_name + + def blob_list(self): + url = f'https://{self.account_name}.blob.core.windows.net/{self.container_name}?comp=list&restype=container&timeout=20' + return self.console_get(url) + + def generate_signature(self, url): + date = get_utc_now() + version = '2021-08-06' + string_to_sign = (f"GET\n\n\n\n\n\n\n\n\n\n\n\n" + f"x-ms-date:{date}\n" + f"x-ms-version:{version}\n" + f"/{self.account_name}/{self.container_name}") + query_params = parse_qs(urlparse(url).query) + for param in query_params: + string_to_sign += "\n%s:%s" % (param, query_params[param][0]) + decoded_key = base64.b64decode(self.account_key) + signed_string = hmac.new(decoded_key, string_to_sign.encode('utf-8'), hashlib.sha256).digest() + signature = base64.b64encode(signed_string).decode('utf-8') + headers = { + 'x-ms-date': date, + 'x-ms-version': version, + 'Authorization': f'SharedKey {self.account_name}:{signature}' + } + return headers + + def console_get(self, url): + # Generate authorization header + headers = self.generate_signature(url) + # request + response = requests.get(url, headers=headers) + xml_data = response.text + # Parse XML data + root = ET.fromstring(xml_data) + + # Convert XML to Dictionary + data_dict = xml_to_dict(root) + return data_dict + + +if __name__ == '__main__': + # Set request parameters + account_name = 'fd2d01cd892f844eeaa2273' + account_key = '1234' + container_name = 'td-test' + + Azure = Azure(account_name, account_key, container_name) + result = Azure.blob_list() + # Print JSON data + for blob in result["Blobs"]["Blob"]: + print(blob["Name"]) diff --git a/tests/army/storage/s3/s3Basic.py b/tests/army/storage/s3/s3Basic.py index c86c8b0b8e..bc55fe6f5c 100644 --- a/tests/army/storage/s3/s3Basic.py +++ b/tests/army/storage/s3/s3Basic.py @@ -129,7 +129,7 @@ class TDTestCase(TBase): time.sleep(2) sc.dnodeStart(1) loop += 1 - # miggrate + # migrate self.migrateDbS3() # check can pass diff --git a/tests/army/storage/s3/s3azure.py b/tests/army/storage/s3/s3azure.py new file mode 100644 index 0000000000..8274db9354 --- /dev/null +++ b/tests/army/storage/s3/s3azure.py @@ -0,0 +1,391 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import time +import random + +import taos +import frame +import frame.etool +import frame.eos +import frame.eutil +import requests + +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame.srvCtl import * +from frame import * +from frame.eos import * +from azure import Azure + +# +# 192.168.1.52 MINIO S3 +# + +''' +s3EndPoint http://192.168.1.52:9000 +s3AccessKey 'zOgllR6bSnw2Ah3mCNel:cdO7oXAu3Cqdb1rUdevFgJMi0LtRwCXdWKQx4bhX' +s3BucketName ci-bucket +s3UploadDelaySec 60 + +for test: +"s3AccessKey" : "fGPPyYjzytw05nw44ViA:vK1VcwxgSOykicx6hk8fL1x15uEtyDSFU3w4hTaZ" +"s3BucketName": "test-bucket" +''' + + +class TDTestCase(TBase): + def __init__(self): + self.fileName = "" # track the upload of S3 file + + account_name = 'fd2d01cd892f844eeaa2273' + url = "http://192.168.0.21/azure_account_key.txt" + response = requests.get(url) + account_key = response.text.strip() + container_name = 'td-test' + + self.azure_class = Azure(account_name, account_key, container_name) + + # index = eutil.cpuRand(20) + 1 + bucketName = "td-test" + updatecfgDict = { + "supportVnodes": "1000", + 's3EndPoint': 'http://192.168.1.49', + 's3AccessKey': 'FlIOwdr5HAnsMyEZ6FBwSPE5:87x1tZJll1SaK4hoiglC8zPRhDgbMeW6ufQqEt8', + 's3BucketName': f'{bucketName}', + 's3PageCacheSize': '10240', + "s3UploadDelaySec": "10", + 's3MigrateIntervalSec': '600', + 's3MigrateEnabled': '1' + } + + tdLog.info(f"assign bucketName is {bucketName}\n") + maxFileSize = (128 + 10) * 1014 * 1024 # add 10M buffer + + def insertData(self): + tdLog.info(f"insert data.") + # taosBenchmark run + json = etool.curFile(__file__, "s3Basic.json") + etool.benchMark(json=json) + + tdSql.execute(f"use {self.db}") + # come from s3_basic.json + self.childtable_count = 6 + self.insert_rows = 2000000 + self.timestamp_step = 100 + + def createStream(self, sname): + sql = f"create stream {sname} fill_history 1 into stm1 as select count(*) from {self.db}.{self.stb} interval(10s);" + tdSql.execute(sql) + + def migrateDbS3(self): + sql = f"s3migrate database {self.db}" + tdSql.execute(sql, show=True) + + def checkDataFile(self, lines, maxFileSize): + # ls -l + # -rwxrwxrwx 1 root root 41652224 Apr 17 14:47 vnode2/tsdb/v2f1974ver47.3.data + overCnt = 0 + for line in lines: + cols = line.split() + fileSize = int(cols[4]) + fileName = cols[8] + # print(f" filesize={fileSize} fileName={fileName} line={line}") + if fileSize > maxFileSize: + tdLog.info(f"error, {fileSize} over max size({maxFileSize}) {fileName}\n") + overCnt += 1 + self.fileName = fileName + else: + tdLog.info(f"{fileName}({fileSize}) check size passed.") + + return overCnt + + def checkUploadToS3(self): + rootPath = sc.clusterRootPath() + cmd = f"ls -l {rootPath}/dnode*/data/vnode/vnode*/tsdb/*.data" + tdLog.info(cmd) + loop = 0 + rets = [] + overCnt = 0 + while loop < 200: + time.sleep(3) + + # check upload to s3 + rets = eos.runRetList(cmd) + cnt = len(rets) + if cnt == 0: + overCnt = 0 + tdLog.info("All data file upload to server over.") + break + overCnt = self.checkDataFile(rets, self.maxFileSize) + if overCnt == 0: + uploadOK = True + tdLog.info(f"All data files({len(rets)}) size bellow {self.maxFileSize}, check upload to s3 ok.") + break + + tdLog.info(f"loop={loop} no upload {overCnt} data files wait 3s retry ...") + if loop == 3: + sc.dnodeStop(1) + time.sleep(2) + sc.dnodeStart(1) + loop += 1 + # migrate + self.migrateDbS3() + + # check can pass + if overCnt > 0: + tdLog.exit(f"s3 have {overCnt} files over size.") + + def doAction(self): + tdLog.info(f"do action.") + + self.flushDb(show=True) + # self.compactDb(show=True) + + # sleep 70s + self.migrateDbS3() + + # check upload to s3 + self.checkUploadToS3() + + def check_azure_exist(self): + result = self.azure_class.blob_list() + if not self.fileName: + tdLog.exit("cannot find S3 file") + datafile = self.fileName.split("/")[-1].split(".")[0] + for blob in result["Blobs"]["Blob"]: + if datafile in blob["Name"]: + tdLog.info("Successfully found the file %s in Azure" % self.fileName) + break + else: + tdLog.exit("failed found the file %s in Azure" % self.fileName) + + def check_azure_not_exist(self): + datafile = self.fileName.split("/")[-1].split(".")[0] + + result = self.azure_class.blob_list() + for blob in result["Blobs"]["Blob"]: + if datafile in blob["Name"]: + tdLog.exit("failed delete the file %s in Azure" % self.fileName) + break + else: + tdLog.info("Successfully delete the file %s in Azure" % self.fileName) + + def checkStreamCorrect(self): + sql = f"select count(*) from {self.db}.stm1" + count = 0 + for i in range(120): + tdSql.query(sql) + count = tdSql.getData(0, 0) + if count == 100000 or count == 100001: + return True + time.sleep(1) + + tdLog.exit(f"stream count is not expect . expect = 100000 or 100001 real={count} . sql={sql}") + + def checkCreateDb(self, keepLocal, chunkSize, compact): + # keyword + kw1 = kw2 = kw3 = "" + if keepLocal is not None: + kw1 = f"s3_keeplocal {keepLocal}" + if chunkSize is not None: + kw2 = f"s3_chunksize {chunkSize}" + if compact is not None: + kw3 = f"s3_compact {compact}" + + sql = f" create database db1 vgroups 1 duration 1h {kw1} {kw2} {kw3}" + tdSql.execute(sql, show=True) + # sql = f"select name,s3_keeplocal,s3_chunksize,s3_compact from information_schema.ins_databases where name='db1';" + sql = f"select * from information_schema.ins_databases where name='db1';" + tdSql.query(sql) + # 29 30 31 -> chunksize keeplocal compact + if chunkSize is not None: + tdSql.checkData(0, 29, chunkSize) + if keepLocal is not None: + keepLocalm = keepLocal * 24 * 60 + tdSql.checkData(0, 30, f"{keepLocalm}m") + if compact is not None: + tdSql.checkData(0, 31, compact) + sql = "drop database db1" + tdSql.execute(sql) + + def checkExcept(self): + # errors + sqls = [ + f"create database db2 s3_keeplocal -1", + f"create database db2 s3_keeplocal 0", + f"create database db2 s3_keeplocal 365001", + f"create database db2 s3_chunksize -1", + f"create database db2 s3_chunksize 0", + f"create database db2 s3_chunksize 900000000", + f"create database db2 s3_compact -1", + f"create database db2 s3_compact 100", + f"create database db2 duration 1d s3_keeplocal 1d" + ] + tdSql.errors(sqls) + + def checkBasic(self): + # create db + keeps = [1, 256, 1024, 365000, None] + chunks = [131072, 600000, 820000, 1048576, None] + comps = [0, 1, None] + + for keep in keeps: + for chunk in chunks: + for comp in comps: + self.checkCreateDb(keep, chunk, comp) + + # --checks3 + idx = 1 + taosd = sc.taosdFile(idx) + cfg = sc.dnodeCfgPath(idx) + cmd = f"{taosd} -c {cfg} --checks3" + + eos.exe(cmd) + # output, error = eos.run(cmd) + # print(lines) + + ''' + tips = [ + "put object s3test.txt: success", + "listing bucket ci-bucket: success", + "get object s3test.txt: success", + "delete object s3test.txt: success" + ] + pos = 0 + for tip in tips: + pos = output.find(tip, pos) + #if pos == -1: + # tdLog.exit(f"checks3 failed not found {tip}. cmd={cmd} output={output}") + ''' + + # except + self.checkExcept() + + # + def preDb(self, vgroups): + cnt = int(time.time()) % 2 + 1 + for i in range(cnt): + vg = eutil.cpuRand(9) + 1 + sql = f"create database predb vgroups {vg}" + tdSql.execute(sql, show=True) + sql = "drop database predb" + tdSql.execute(sql, show=True) + + # history + def insertHistory(self): + tdLog.info(f"insert history data.") + # taosBenchmark run + json = etool.curFile(__file__, "s3Basic1.json") + etool.benchMark(json=json) + + # come from s3_basic.json + self.insert_rows += self.insert_rows / 4 + self.timestamp_step = 50 + + # delete + def checkDelete(self): + # del 1000 rows + start = 1600000000000 + drows = 200 + for i in range(1, drows, 2): + sql = f"from {self.db}.{self.stb} where ts = {start + i * 500}" + tdSql.execute("delete " + sql, show=True) + tdSql.query("select * " + sql) + tdSql.checkRows(0) + + # delete all 500 step + self.flushDb() + self.compactDb() + self.insert_rows -= drows / 2 + sql = f"select count(*) from {self.db}.{self.stb}" + tdSql.checkAgg(sql, self.insert_rows * self.childtable_count) + + # delete 10W rows from 100000 + drows = 100000 + sdel = start + 100000 * self.timestamp_step + edel = start + 100000 * self.timestamp_step + drows * self.timestamp_step + sql = f"from {self.db}.{self.stb} where ts >= {sdel} and ts < {edel}" + tdSql.execute("delete " + sql, show=True) + tdSql.query("select * " + sql) + tdSql.checkRows(0) + + self.insert_rows -= drows + sql = f"select count(*) from {self.db}.{self.stb}" + tdSql.checkAgg(sql, self.insert_rows * self.childtable_count) + + # run + def run(self): + tdLog.debug(f"start to excute {__file__}") + self.sname = "stream1" + if eos.isArm64Cpu(): + tdLog.success(f"{__file__} arm64 ignore executed") + else: + + self.preDb(10) + + # insert data + self.insertData() + + # creat stream + self.createStream(self.sname) + + # check insert data correct + # self.checkInsertCorrect() + + # save + self.snapshotAgg() + + # do action + self.doAction() + # check azure data exist + self.check_azure_exist() + # check save agg result correct + self.checkAggCorrect() + + # check insert correct again + self.checkInsertCorrect() + + # check stream correct and drop stream + # self.checkStreamCorrect() + + # drop stream + self.dropStream(self.sname) + + # # insert history disorder data + # self.insertHistory() + # + # # checkBasic + # self.checkBasic() + + # self.checkInsertCorrect() + # self.snapshotAgg() + # self.doAction() + # self.checkAggCorrect() + # self.checkInsertCorrect(difCnt=self.childtable_count * 1499999) + # self.checkDelete() + # self.doAction() + + # drop database and free s3 file + self.dropDb() + # check azure data not exist + self.check_azure_not_exist() + + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From c65ad1287d1ddeca452b465ccbc298382a8c4a11 Mon Sep 17 00:00:00 2001 From: Leo Xu <381899826@qq.com> Date: Mon, 9 Sep 2024 18:13:12 +0800 Subject: [PATCH 11/90] alter flexify num 1 to 2 --- tests/army/storage/s3/s3azure.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/tests/army/storage/s3/s3azure.py b/tests/army/storage/s3/s3azure.py index 8274db9354..43857cb7ca 100644 --- a/tests/army/storage/s3/s3azure.py +++ b/tests/army/storage/s3/s3azure.py @@ -63,8 +63,8 @@ class TDTestCase(TBase): bucketName = "td-test" updatecfgDict = { "supportVnodes": "1000", - 's3EndPoint': 'http://192.168.1.49', - 's3AccessKey': 'FlIOwdr5HAnsMyEZ6FBwSPE5:87x1tZJll1SaK4hoiglC8zPRhDgbMeW6ufQqEt8', + 's3EndPoint': 'http://192.168.1.49,http://192.168.1.49:81', + 's3AccessKey': 'FlIOwdr5HAnsMyEZ6FBwSPE5:87x1tZJll1SaK4hoiglC8zPRhDgbMeW6ufQqEt8,FlIOvHz0MePAf4KttYqfZM:Hve86EvB6KdvRPa5d1DG38jP6BSSSJC7IxYvSgEP', 's3BucketName': f'{bucketName}', 's3PageCacheSize': '10240', "s3UploadDelaySec": "10", @@ -161,7 +161,7 @@ class TDTestCase(TBase): # check upload to s3 self.checkUploadToS3() - def check_azure_exist(self): + def checkAzureDataExist(self): result = self.azure_class.blob_list() if not self.fileName: tdLog.exit("cannot find S3 file") @@ -173,7 +173,7 @@ class TDTestCase(TBase): else: tdLog.exit("failed found the file %s in Azure" % self.fileName) - def check_azure_not_exist(self): + def checkAzureDataNotExist(self): datafile = self.fileName.split("/")[-1].split(".")[0] result = self.azure_class.blob_list() @@ -352,7 +352,7 @@ class TDTestCase(TBase): # do action self.doAction() # check azure data exist - self.check_azure_exist() + self.checkAzureDataExist() # check save agg result correct self.checkAggCorrect() @@ -365,24 +365,10 @@ class TDTestCase(TBase): # drop stream self.dropStream(self.sname) - # # insert history disorder data - # self.insertHistory() - # - # # checkBasic - # self.checkBasic() - - # self.checkInsertCorrect() - # self.snapshotAgg() - # self.doAction() - # self.checkAggCorrect() - # self.checkInsertCorrect(difCnt=self.childtable_count * 1499999) - # self.checkDelete() - # self.doAction() - # drop database and free s3 file self.dropDb() # check azure data not exist - self.check_azure_not_exist() + self.checkAzureDataNotExist() tdLog.success(f"{__file__} successfully executed") From b57cd278278b11bf46cbe485844c8dce9356fab1 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 9 Sep 2024 18:20:00 +0800 Subject: [PATCH 12/90] enh: add block check --- include/common/tdatablock.h | 1 + source/common/src/tdatablock.c | 70 +++++++++++++++++++++++++++++ source/libs/executor/src/operator.c | 2 + 3 files changed, 73 insertions(+) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 22a43012c5..1d280b5d6b 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -233,6 +233,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); * @brief find how many rows already in order start from first row */ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo); +void blockDataCheck(const SSDataBlock* pDataBlock); int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index ea3e88919b..22bca726d7 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -2936,6 +2936,8 @@ int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, cha // return length of encoded data, return -1 if failed int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) { + blockDataCheck(pBlock); + int32_t dataLen = 0; // todo extract method @@ -3177,6 +3179,9 @@ int32_t blockDecode(SSDataBlock* pBlock, const char* pData, const char** pEndPos } *pEndPos = pStart; + + blockDataCheck(pBlock); + return code; } @@ -3386,3 +3391,68 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) { return nextRowIdx; } + +void blockDataCheck(const SSDataBlock* pDataBlock) { + if (NULL == pDataBlock || pDataBlock->info.rows == 0) { + return; + } + + ASSERT(pDataBlock->info.rows > 0); + + if (!pDataBlock->info.dataLoad) { + return; + } + + bool isVarType = false; + int32_t colLen = 0; + int32_t nextPos = 0; + int64_t checkRows = 0; + int64_t typeValue = 0; + int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock); + for (int32_t i = 0; i < colNum; ++i) { + SColumnInfoData* pCol = (SColumnInfoData*)taosArrayGet(pDataBlock->pDataBlock, i); + isVarType = IS_VAR_DATA_TYPE(pCol->info.type); + checkRows = pDataBlock->info.rows; + + if (isVarType) { + ASSERT(pCol->varmeta.length); + } else { + ASSERT(pCol->nullbitmap); + } + + for (int64_t r = 0; r < checkRows; ++r) { + if (!colDataIsNull_s(pCol, r)) { + ASSERT(pCol->pData); + ASSERT(pCol->varmeta.length <= pCol->varmeta.allocLen); + + if (isVarType) { + ASSERT(pCol->varmeta.allocLen > 0); + ASSERT(pCol->varmeta.offset[r] < pCol->varmeta.length); + if (pCol->reassigned) { + ASSERT(pCol->varmeta.offset[r] >= 0); + } else { + ASSERT(pCol->varmeta.offset[r] == nextPos); + } + + colLen = varDataTLen(pCol->pData + pCol->varmeta.offset[r]); + ASSERT(colLen >= VARSTR_HEADER_SIZE); + ASSERT(colLen <= pCol->info.bytes); + + if (pCol->reassigned) { + ASSERT((pCol->varmeta.offset[r] + colLen) <= pCol->varmeta.length); + } else { + nextPos += colLen; + ASSERT(nextPos <= pCol->varmeta.length); + } + + typeValue = *(char*)(pCol->pData + pCol->varmeta.offset[r] + colLen - 1); + } else { + GET_TYPED_DATA(typeValue, int64_t, pCol->info.type, colDataGetNumData(pCol, r)); + } + } + } + } + + return; +} + diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c index 6fe270161f..de478a146f 100644 --- a/source/libs/executor/src/operator.c +++ b/source/libs/executor/src/operator.c @@ -868,12 +868,14 @@ int32_t setOperatorParams(struct SOperatorInfo* pOperator, SOperatorParam* pInpu SSDataBlock* getNextBlockFromDownstream(struct SOperatorInfo* pOperator, int32_t idx) { SSDataBlock* p = NULL; int32_t code = getNextBlockFromDownstreamImpl(pOperator, idx, true, &p); + blockDataCheck(p); return (code == 0)? p:NULL; } SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, int32_t idx) { SSDataBlock* p = NULL; int32_t code = getNextBlockFromDownstreamImpl(pOperator, idx, false, &p); + blockDataCheck(p); return (code == 0)? p:NULL; } From d199f852f5b383114587a98567b2822acd9484a3 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 9 Sep 2024 19:28:08 +0800 Subject: [PATCH 13/90] fix: check issue --- source/common/src/tdatablock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 22bca726d7..840434a351 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -3415,11 +3415,12 @@ void blockDataCheck(const SSDataBlock* pDataBlock) { checkRows = pDataBlock->info.rows; if (isVarType) { - ASSERT(pCol->varmeta.length); + ASSERT(pCol->varmeta.offset); } else { ASSERT(pCol->nullbitmap); } - + + nextPos = 0; for (int64_t r = 0; r < checkRows; ++r) { if (!colDataIsNull_s(pCol, r)) { ASSERT(pCol->pData); From 4bc8db22fa747ca2f3376d3828e9d054c957c6a7 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 9 Sep 2024 19:54:56 +0800 Subject: [PATCH 14/90] enh: grant column length adaption --- include/common/tgrant.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index f6b98cf844..1660cc6a1b 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -74,26 +74,26 @@ int32_t tGetMachineId(char **result); #ifdef TD_ENTERPRISE #define GRANTS_SCHEMA \ static const SSysDbTableSchema grantsSchema[] = { \ - {.name = "version", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "version", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "timeseries", .bytes = 43 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "dnodes", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "cpu_cores", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ } #else #define GRANTS_SCHEMA \ static const SSysDbTableSchema grantsSchema[] = { \ - {.name = "version", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "version", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ - {.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "timeseries", .bytes = 43 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "dnodes", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ + {.name = "cpu_cores", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ } #endif // #define GRANT_CFG_ADD From 2a3917029f3cc5967f42b99952b7deb100845da8 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 11:29:50 +0800 Subject: [PATCH 15/90] osFile --- include/os/osSocket.h | 2 +- include/util/taoserror.h | 3 + source/common/src/cos_cp.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 7 +- source/dnode/mgmt/mgmt_vnode/src/vmFile.c | 8 +- source/dnode/mgmt/node_util/src/dmEps.c | 7 +- source/dnode/mgmt/node_util/src/dmFile.c | 24 ++---- source/dnode/mnode/sdb/src/sdbFile.c | 32 +++---- source/dnode/vnode/src/tsdb/tsdbFS.c | 7 +- source/dnode/vnode/src/tsdb/tsdbFS2.c | 7 +- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 4 +- source/dnode/vnode/src/vnd/vnodeCommit.c | 7 +- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 2 +- source/libs/executor/src/groupcacheoperator.c | 2 +- source/libs/stream/src/streamBackendRocksdb.c | 9 +- source/libs/stream/src/streamSnapshot.c | 4 +- source/libs/sync/src/syncRaftCfg.c | 6 +- source/libs/sync/src/syncRaftStore.c | 2 +- source/libs/tdb/src/db/tdbUtil.c | 4 +- source/libs/wal/src/walMeta.c | 10 +-- source/libs/wal/src/walRead.c | 10 +-- source/libs/wal/src/walWrite.c | 4 +- source/os/src/osDir.c | 4 +- source/os/src/osEnv.c | 5 +- source/os/src/osFile.c | 83 +++++++++---------- source/os/src/osSocket.c | 14 ++-- source/os/src/osSysinfo.c | 2 +- source/util/src/terror.c | 10 +++ source/util/src/tpagedbuf.c | 2 +- 29 files changed, 131 insertions(+), 152 deletions(-) diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 0427c6b22f..48478c8f49 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -143,7 +143,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes); int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len); -void taosWinSocketInit(); +int32_t taosWinSocketInit(); /* * set timeout(ms) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 4591c7fbcc..4e909b0a1c 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -35,6 +35,8 @@ extern STaosError errors[]; #define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code)))) #define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code)) +#define TAOS_SYSTEM_WINAPI_ERROR(code) (0x81ff0000 | (code)) +#define TAOS_SYSTEM_WINSOCKET_ERROR(code) (0x82ff0000 | (code)) #define TAOS_SUCCEEDED(err) ((err) >= 0) #define TAOS_FAILED(err) ((err) < 0) @@ -153,6 +155,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal #define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137) #define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138) +#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139) //client #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) diff --git a/source/common/src/cos_cp.c b/source/common/src/cos_cp.c index e9af9c0306..793433bba7 100644 --- a/source/common/src/cos_cp.c +++ b/source/common/src/cos_cp.c @@ -175,7 +175,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) { int64_t n = taosReadFile(fd, cp_body, size); if (n < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } else if (n != size) { TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit); } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 563d123b83..d9f6920fcb 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -96,7 +96,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { } if (taosReadFile(pFile, pData, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to read mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -215,10 +215,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { code = TAOS_SYSTEM_ERROR(errno); goto _OVER; } - if (taosRenameFile(file, realfile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); - goto _OVER; - } + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index 8513d31695..d5b1e61aed 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -133,7 +133,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t } if (taosReadFile(pFile, pData, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to read vnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -253,12 +253,8 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { code = TAOS_SYSTEM_ERROR(errno); goto _OVER; } - if (taosRenameFile(file, realfile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); - goto _OVER; - } + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); - code = 0; dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes); _OVER: diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 315c4d7430..7c0272965a 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -222,7 +222,7 @@ int32_t dmReadEps(SDnodeData *pData) { } if (taosReadFile(pFile, content, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to read dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -340,9 +340,8 @@ int32_t dmWriteEps(SDnodeData *pData) { if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); (void)taosCloseFile(&pFile); - if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); - code = 0; pData->updateTime = taosGetTimestampMs(); dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps), pData->dnodeVer); @@ -626,7 +625,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { } if (taosReadFile(pFile, content, size) != size) { - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = terrno; dError("failed to read dnode file:%s since %s", file, terrstr()); goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index c8b24d5469..3412d5ed3a 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -75,7 +75,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { } if (taosReadFile(pFile, content, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to read file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -166,12 +166,8 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { code = TAOS_SYSTEM_ERROR(errno); goto _OVER; } - if (taosRenameFile(file, realfile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); - goto _OVER; - } + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); - code = 0; dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed); _OVER: @@ -262,10 +258,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool goto _OVER; } - if (taosRenameFile(file, realfile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); - goto _OVER; - } + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); encryptDebug("succeed to write checkCode file:%s", realfile); @@ -302,10 +295,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC goto _OVER; } - if (taosRenameFile(file, realfile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); - goto _OVER; - } + TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); encryptDebug("succeed to write encryptCode file:%s", realfile); @@ -338,12 +328,12 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { content = taosMemoryMalloc(size); if (content == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } if (taosReadFile(pFile, content, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; encryptError("failed to read dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -484,7 +474,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) { } if (taosReadFile(pFile, content, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to read dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 94826405dc..813579ac26 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -86,8 +86,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { int64_t sver = 0; int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -100,8 +99,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -110,8 +108,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -120,8 +117,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -132,8 +128,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { int64_t maxId = 0; ret = taosReadFile(pFile, &maxId, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -148,8 +143,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { int64_t ver = 0; ret = taosReadFile(pFile, &ver, sizeof(int64_t)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(int64_t)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -163,8 +157,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { char reserve[SDB_RESERVE_SIZE] = {0}; ret = taosReadFile(pFile, reserve, sizeof(reserve)); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (ret != sizeof(reserve)) { code = TSDB_CODE_FILE_CORRUPTED; @@ -274,7 +267,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { if (ret == 0) break; if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to read sdb file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -305,7 +298,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { ret = taosReadFile(pFile, pRaw->pData, readLen); if (ret < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen); goto _OVER; } @@ -523,7 +516,6 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { if (code == 0) { code = taosRenameFile(tmpfile, curfile); if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); mError("failed to write sdb file:%s since %s", curfile, tstrerror(code)); } } @@ -693,7 +685,7 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) { int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen); if (readlen < 0 || readlen > maxlen) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total); *ppBuf = NULL; *len = 0; @@ -758,8 +750,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i char datafile[PATH_MAX] = {0}; snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); - if (taosRenameFile(pIter->name, datafile) != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosRenameFile(pIter->name, datafile); + if (code != 0) { mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index ed80b5d412..cde4d7ded8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -310,7 +310,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { } if (taosReadFile(pFD, pData, size) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } @@ -711,10 +711,7 @@ static int32_t tsdbFSCommit(STsdb *pTsdb) { if (!taosCheckExistFile(current_t)) goto _exit; // rename the file - if (taosRenameFile(current_t, current) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - TSDB_CHECK_CODE(code, lino, _exit); - } + TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit); // Load the new FS code = tsdbFSCreate(&fs); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 24916bf47c..843e700fd3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -130,7 +130,7 @@ static int32_t load_json(const char *fname, cJSON **json) { } if (taosReadFile(fp, data, size) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } data[size] = '\0'; @@ -309,10 +309,7 @@ static int32_t commit_edit(STFileSystem *fs) { int32_t code; int32_t lino; - if ((code = taosRenameFile(current_t, current))) { - code = TAOS_SYSTEM_ERROR(code); - TSDB_CHECK_CODE(code, lino, _exit); - } + TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit); code = apply_commit(fs); TSDB_CHECK_CODE(code, lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index e044743bea..c34b29f97d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -226,7 +226,7 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor // read n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } else if (n < pFD->szPage) { TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); } @@ -378,7 +378,7 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo ret = taosReadFile(pFD->pFD, buf + n, nRead); if (ret < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } else if (ret < nRead) { TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); } diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index ddd1ac9d4a..c272e540ba 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -211,8 +211,9 @@ int vnodeCommitInfo(const char *dir) { snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME); snprintf(tfname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP); - if (taosRenameFile(tfname, fname) < 0) { - return terrno = TAOS_SYSTEM_ERROR(errno); + int32_t code = taosRenameFile(tfname, fname); + if (code < 0) { + return code; } vInfo("vnode info is committed, dir:%s", dir); @@ -245,7 +246,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { } if (taosReadFile(pFile, pData, size) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } pData[size] = '\0'; diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 86c25009bc..7d8b5d4eda 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -289,7 +289,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) { taosMemoryFree(*ppData); (void)taosCloseFile(&pFile); - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } (void)taosCloseFile(&pFile); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 1796aa7b64..576f3932b6 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -562,7 +562,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize); if (ret != pBasic->bufSize) { taosMemoryFreeClear(*ppBuf); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _return; } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 465968dc50..4e14df9a40 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -296,7 +296,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { char buf[256] = {0}; if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _EXIT; } @@ -367,8 +367,8 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch goto _EXIT; } - if (taosRenameFile(src, dst) != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosRenameFile(src, dst); + if (code != 0) { goto _EXIT; } @@ -507,7 +507,6 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId if (taosIsDir(defaultPath)) { code = taosRenameFile(defaultPath, defaultTmp); if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); goto _EXIT; } else { rename = 1; @@ -1609,7 +1608,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) } if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to read file to load extra info, file:%s, reason:%s", pDst, tstrerror(code)); goto _EXIT; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index eb222efce6..2b69da6007 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -696,7 +696,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t if (strlen(pHdr->name) == strlen(pItem->name) && strcmp(pHdr->name, pItem->name) == 0) { int64_t bytes = taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset); if (bytes != pHdr->size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code)); goto _err; } else { @@ -735,7 +735,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t // open fd again, let's close fd during handle errors. if (taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset) != pHdr->size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code)); goto _err; } diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 82cc86ed86..ac3bba8c42 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -164,9 +164,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { } (void)taosCloseFile(&pFile); - if (taosRenameFile(file, realfile) != 0) { - TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); - } + TAOS_CHECK_EXIT(taosRenameFile(file, realfile)); sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d", pNode->vgId, realfile, len, pNode->raftCfg.lastConfigIndex, pNode->raftCfg.cfg.changeVersion); @@ -280,7 +278,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { } if (taosReadFile(pFile, pData, size) != size) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code)); goto _OVER; } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index cc2aa7d91e..d6482ba2da 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -72,7 +72,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { if (taosReadFile(pFile, pData, size) != size) { sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr()); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } pData[size] = '\0'; diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index d6d33bc7d8..2249123ef5 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -39,7 +39,9 @@ int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique) { int64_t stDev = 0, stIno = 0; int32_t code = taosDevInoFile(fd, &stDev, &stIno); - return code; + if (TSDB_CODE_SUCCESS != code) { + return code; + } memset(fileid, 0, TDB_FILE_ID_LEN); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index fb30dd3376..378e9d1903 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -112,7 +112,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in if (readSize != taosReadFile(pFile, buf, readSize)) { wError("vgId:%d, failed to read file due to %s. readSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), readSize, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } char* candidate = NULL; @@ -177,7 +177,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) { wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; break; } } @@ -522,7 +522,7 @@ static int32_t walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pC } if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (walValidHeadCksum(pCkHead) != 0) { @@ -588,7 +588,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (idxEntry.ver > pFileInfo->lastVer) { @@ -1028,7 +1028,7 @@ int32_t walLoadMeta(SWal* pWal) { (void)taosCloseFile(&pFile); taosMemoryFree(buf); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // load into fileInfoSet code = walMetaDeserialize(pWal, buf); diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index deb5a07672..6476cd39ac 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -144,7 +144,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int if (ret < 0) { wError("vgId:%d, failed to read idx file, since %s", pReader->pWal->cfg.vgId, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } else { wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %ld", pReader->pWal->cfg.vgId, ret, sizeof(SWalIdxEntry)); @@ -270,7 +270,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver) { continue; } else { if (contLen < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } else { TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); } @@ -345,7 +345,7 @@ int32_t walFetchBody(SWalReader *pRead) { wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s, 0x%" PRIx64, vgId, pReadHead->version, ver, tstrerror(terrno), id); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } else { wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since file corrupted, 0x%" PRIx64, @@ -426,7 +426,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex)); if (contLen < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } else { TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); } @@ -467,7 +467,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex)); if (contLen < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } else { TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 52af3e8528..a11831c437 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -214,7 +214,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr); @@ -240,7 +240,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (size != sizeof(SWalCkHead)) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = walValidHeadCksum(&head); diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index d233a4fe0e..dcce5543b2 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -447,7 +447,7 @@ TdDirPtr taosOpenDir(const char *dirname) { if (INVALID_HANDLE_VALUE == pDir->hFind) { taosMemoryFree(pDir); DWORD errorCode = GetLastError(); - terrno = TAOS_SYSTEM_ERROR(errorCode); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errorCode); return NULL; } return pDir; @@ -529,7 +529,7 @@ int32_t taosCloseDir(TdDirPtr *ppDir) { } #ifdef WINDOWS if(!FindClose((*ppDir)->hFind)) { - terrno = TAOS_SYSTEM_ERROR(GetLastError()); + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return terrno; } taosMemoryFree(*ppDir); diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index c0ea49e2cb..8334d609b1 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -64,7 +64,10 @@ int32_t osDefaultInit() { } #ifdef WINDOWS - taosWinSocketInit(); + code = taosWinSocketInit(); + if (code != TSDB_CODE_SUCCESS) { + return code; + } const char *tmpDir = getenv("tmp"); if (tmpDir == NULL) { diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 144baeb148..f4afaeabd1 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -132,6 +132,7 @@ int64_t taosCopyFile(const char *from, const char *to) { if (CopyFile(from, to, 0)) { return 1; } else { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } #else @@ -231,8 +232,9 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { HANDLE transactionHandle = CreateTransaction(NULL, NULL, 0, 0, 0, INFINITE, NULL); if (transactionHandle == INVALID_HANDLE_VALUE) { - printf("failed to rename file %s to %s, reason: CreateTransaction failed.\n", oldName, newName); - return -1; + DWORD error = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(error); + return terrno; } BOOL result = MoveFileTransacted(oldName, newName, NULL, NULL, MOVEFILE_REPLACE_EXISTING, transactionHandle); @@ -241,18 +243,18 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { finished = CommitTransaction(transactionHandle); if (!finished) { DWORD error = GetLastError(); - printf("failed to rename file %s to %s, reason: CommitTransaction errcode %d.\n", oldName, newName, error); + terrno = TAOS_SYSTEM_WINAPI_ERROR(error); } } else { RollbackTransaction(transactionHandle); DWORD error = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(error); finished = false; - printf("failed to rename file %s to %s, reason: MoveFileTransacted errcode %d.\n", oldName, newName, error); } CloseHandle(transactionHandle); - return finished ? 0 : -1; + return finished ? 0 : terrno; #else int32_t code = rename(oldName, newName); if (-1 == code) { @@ -260,7 +262,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { return terrno; } - return code; + return TSDB_CODE_SUCCESS; #endif } @@ -294,12 +296,14 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *a int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { #ifdef WINDOWS if (pFile == NULL || pFile->hFile == NULL) { - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } BY_HANDLE_FILE_INFORMATION bhfi; if (GetFileInformationByHandle(pFile->hFile, &bhfi) == FALSE) { - printf("taosFStatFile get file info fail."); - return -1; + DWORD error = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(error); + return terrno; } if (stDev != NULL) { @@ -395,35 +399,38 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { if (h != INVALID_HANDLE_VALUE && (tdFileOptions & TD_FILE_APPEND) && (tdFileOptions & TD_FILE_WRITE)) { SetFilePointer(h, 0, NULL, FILE_END); } - // if (h == INVALID_HANDLE_VALUE) { - // DWORD dwError = GetLastError(); - // LPVOID lpMsgBuf; - // FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, - // 0, - // (LPTSTR)&lpMsgBuf, 0, NULL); - // printf("CreateFile failed with error %d: %s", dwError, (char*)lpMsgBuf); - // LocalFree(lpMsgBuf); - // } + if (h == INVALID_HANDLE_VALUE) { + DWORD dwError = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(error); + // LPVOID lpMsgBuf; + // FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, + // NULL); + // printf("CreateFile failed with error %d: %s", dwError, (char *)lpMsgBuf); + // LocalFree(lpMsgBuf); + } return h; } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { #if FILE_WITH_LOCK - taosThreadRwlockRdlock(&(pFile->rwlock)); + (void)taosThreadRwlockRdlock(&(pFile->rwlock)); #endif if (pFile->hFile == NULL) { #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } DWORD bytesRead; if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) { + DWORD errCode = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode); bytesRead = -1; } #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return bytesRead; } @@ -449,14 +456,15 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { if (pFile == NULL) { + terrno = TSDB_CODE_INVALID_PARA; return 0; } #if FILE_WITH_LOCK - taosThreadRwlockWrlock(&(pFile->rwlock)); + (void)taosThreadRwlockWrlock(&(pFile->rwlock)); #endif if (pFile->hFile == NULL) { #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return 0; } @@ -470,11 +478,12 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t BOOL result = WriteFile(pFile->hFile, buf, count, &ret, &ol); if (!result) { errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); ret = -1; } #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return ret; } @@ -484,7 +493,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { return -1; } #if FILE_WITH_LOCK - taosThreadRwlockRdlock(&(pFile->rwlock)); + (void)taosThreadRwlockRdlock(&(pFile->rwlock)); #endif LARGE_INTEGER liOffset; @@ -498,7 +507,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { return -1; } #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return liOffset.QuadPart; } @@ -826,25 +835,11 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t } #endif -#ifdef WINDOWS - DWORD ret = 0; - OVERLAPPED ol = {0}; - ol.OffsetHigh = (uint32_t)((offset & 0xFFFFFFFF00000000LL) >> 0x20); - ol.Offset = (uint32_t)(offset & 0xFFFFFFFFLL); - - HANDLE handle = (HANDLE)_get_osfhandle(pFile->fd); - SetLastError(0); - BOOL result = WriteFile(handle, buf, count, &ret, &ol); - if (!result) { - errno = GetLastError(); - ret = -1; - } -#else int64_t ret = pwrite(pFile->fd, buf, count, offset); if (-1 == ret) { code = TAOS_SYSTEM_ERROR(errno); } -#endif + #if FILE_WITH_LOCK (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif @@ -867,14 +862,10 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { int32_t code = 0; -#ifdef WINDOWS - int64_t ret = _lseeki64(pFile->fd, offset, whence); -#else int64_t ret = lseek(pFile->fd, offset, whence); if (-1 == ret) { code = TAOS_SYSTEM_ERROR(errno); } -#endif #if FILE_WITH_LOCK (void)taosThreadRwlockUnlock(&(pFile->rwlock)); diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 2d160b277b..48ca36b5e5 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1170,19 +1170,23 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) { return (int)fd; } -void taosWinSocketInit() { +int32_t taosWinSocketInit() { #ifdef WINDOWS - static char flag = 0; - if (flag == 0) { + static int8_t flag = 0; + if (atomic_val_compare_exchange_8(&flag, 0, 1) == 0) { WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(1, 1); - if (WSAStartup(wVersionRequested, &wsaData) == 0) { - flag = 1; + if (WSAStartup(wVersionRequested, &wsaData) != 0) { + atomic_store_8(&flag, 0) + int errorCode = WSAGetLastError(); + return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode); } } + return 0; #else #endif + return 0; } uint64_t taosHton64(uint64_t val) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 9a4f0f8a98..137bb8f0db 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -300,7 +300,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) { if (taosReadFile(pFile, (void *)email, maxLen) < 0) { taosCloseFile(&pFile); - return -1; + return terrno; } taosCloseFile(&pFile); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 58dde5cd23..5ceec33831 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -850,6 +850,7 @@ static void tsSortError(void) { taosSort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError); } +static char WinAPIErrDesc[256] = {0}; const char* tstrerror(int32_t err) { (void)taosThreadOnce(&tsErrorInit, tsSortError); @@ -860,6 +861,15 @@ const char* tstrerror(int32_t err) { // invalid code return Unknown error return strerror(code); } + #ifdef WINDOWS + if ((err & 0x01ff0000) == 0x01ff0000) { + snprintf(WinAPIErrDesc, 256, "windows api error, code: 0x%08x", err & 0x0000ffff); + return WinAPIErrDesc; + } else if ((err & 0x02ff0000) == 0x02ff0000) { + snprintf(WinAPIErrDesc, 256, "windows socket error, code: 0x%08x", err & 0x0000ffff); + return WinAPIErrDesc; + } + #endif int32_t s = 0; int32_t e = sizeof(errors) / sizeof(errors[0]); diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 32b9b6e18d..de27cf4df9 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -256,7 +256,7 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { void* pPage = (void*)GET_PAYLOAD_DATA(pg); ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length); if (ret != pg->length) { - ret = TAOS_SYSTEM_ERROR(errno); + ret = terrno; return ret; } From 2875b0c753eb8b54491a89a894dcb75920e5ff44 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Tue, 10 Sep 2024 11:41:49 +0800 Subject: [PATCH 16/90] reduce mnode conn/app cache keep time to 3 seconds --- source/dnode/mnode/impl/src/mndProfile.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 3bdfa236d1..9eca3addd5 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -65,6 +65,8 @@ typedef struct { int64_t ipWhiteListVer; } SConnPreparedObj; +#define CACHE_OBJ_KEEP_TIME 3 // s + static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime); static void mndFreeConn(SConnObj *pConn); @@ -161,9 +163,8 @@ static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType tstrncpy(connObj.user, user, TSDB_USER_LEN); tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN); - int32_t keepTime = tsShellActivityTimer * 3; SConnObj *pConn = - taosCachePut(pMgmt->connCache, &connId, sizeof(uint32_t), &connObj, sizeof(connObj), keepTime * 1000); + taosCachePut(pMgmt->connCache, &connId, sizeof(uint32_t), &connObj, sizeof(connObj), CACHE_OBJ_KEEP_TIME * 1000); if (pConn == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("conn:%d, failed to put into cache since %s, user:%s", connId, user, terrstr()); @@ -376,8 +377,7 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq) (void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary)); app.lastAccessTimeMs = taosGetTimestampMs(); - const int32_t keepTime = tsShellActivityTimer * 3; - SAppObj *pApp = taosCachePut(pMgmt->appCache, &pReq->appId, sizeof(pReq->appId), &app, sizeof(app), keepTime * 1000); + SAppObj *pApp = taosCachePut(pMgmt->appCache, &pReq->appId, sizeof(pReq->appId), &app, sizeof(app), CACHE_OBJ_KEEP_TIME * 1000); if (pApp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to app %" PRIx64 " into cache since %s", pReq->appId, terrstr()); @@ -842,7 +842,6 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl int32_t numOfRows = 0; int32_t cols = 0; SConnObj *pConn = NULL; - int32_t keepTime = tsShellActivityTimer * 3; if (pShow->pIter == NULL) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; @@ -856,7 +855,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl break; } - if ((taosGetTimestampMs() - pConn->lastAccessTimeMs) > ((int64_t)keepTime * 1000)) { + if ((taosGetTimestampMs() - pConn->lastAccessTimeMs) > ((int64_t)CACHE_OBJ_KEEP_TIME * 1000)) { continue; } From 51bee72807351202e5d325e8c0e200680cdb634c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 10 Sep 2024 12:58:08 +0800 Subject: [PATCH 17/90] fix(stream):not reset the failed checkpointId --- source/libs/stream/src/streamCheckpoint.c | 25 ++++++++++++++---- source/libs/stream/src/streamDispatch.c | 28 ++++++++++++++------- source/libs/stream/src/streamTask.c | 6 +++-- tests/script/tsim/stream/pauseAndResume.sim | 5 +++- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index e091d0f34b..242e12f591 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -235,6 +235,16 @@ int32_t streamProcessCheckpointTriggerBlock(SStreamTask* pTask, SStreamDataBlock return code; } + if (pActiveInfo->failedId >= checkpointId) { + stError("s-task:%s vgId:%d checkpointId:%" PRId64 " transId:%d, has been marked failed, failedId:%" PRId64 + "discard the checkpoint-trigger block", + id, vgId, checkpointId, transId, pActiveInfo->failedId); + streamMutexUnlock(&pTask->lock); + + streamFreeQitem((SStreamQueueItem*)pBlock); + return code; + } + if (pTask->chkInfo.checkpointId == checkpointId) { { // send checkpoint-ready msg to upstream SRpcMsg msg = {0}; @@ -531,15 +541,20 @@ int32_t streamTaskProcessCheckpointReadyRsp(SStreamTask* pTask, int32_t upstream } void streamTaskClearCheckInfo(SStreamTask* pTask, bool clearChkpReadyMsg) { + SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo; + pTask->chkInfo.startTs = 0; // clear the recorded start time streamTaskOpenAllUpstreamInput(pTask); // open inputQ for all upstream tasks - streamMutexLock(&pTask->chkInfo.pActiveInfo->lock); - streamTaskClearActiveInfo(pTask->chkInfo.pActiveInfo); + streamMutexLock(&pInfo->lock); + streamTaskClearActiveInfo(pInfo); if (clearChkpReadyMsg) { - streamClearChkptReadyMsg(pTask->chkInfo.pActiveInfo); + streamClearChkptReadyMsg(pInfo); } - streamMutexUnlock(&pTask->chkInfo.pActiveInfo->lock); + streamMutexUnlock(&pInfo->lock); + + stDebug("s-task:%s clear active checkpointInfo, failed checkpointId:%"PRId64", current checkpointId:%"PRId64, + pTask->id.idStr, pInfo->failedId, pTask->chkInfo.checkpointId); } int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SVUpdateCheckpointInfoReq* pReq) { @@ -669,7 +684,7 @@ void streamTaskSetFailedCheckpointId(SStreamTask* pTask) { stWarn("s-task:%s checkpoint-info is cleared now, not set the failed checkpoint info", pTask->id.idStr); } else { pInfo->failedId = pInfo->activeId; - stDebug("s-task:%s mark the checkpointId:%" PRId64 " (transId:%d) failed", pTask->id.idStr, pInfo->activeId, + stDebug("s-task:%s mark and set the failed checkpointId:%" PRId64 " (transId:%d)", pTask->id.idStr, pInfo->activeId, pInfo->transId); } } diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 2a32a1d522..4926dcb69d 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -726,9 +726,10 @@ int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, S } int32_t streamDispatchStreamBlock(SStreamTask* pTask) { - const char* id = pTask->id.idStr; - int32_t code = 0; - SStreamDataBlock* pBlock = NULL; + const char* id = pTask->id.idStr; + int32_t code = 0; + SStreamDataBlock* pBlock = NULL; + SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo; int32_t numOfElems = streamQueueGetNumOfItems(pTask->outputq.queue); if (numOfElems > 0) { @@ -746,10 +747,15 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) { return 0; } - if (pTask->chkInfo.pActiveInfo->dispatchTrigger) { - stDebug("s-task:%s already send checkpoint-trigger, no longer dispatch any other data", id); - atomic_store_8(&pTask->outputq.status, TASK_OUTPUT_STATUS__NORMAL); - return 0; + if (pInfo->dispatchTrigger) { + if ((pInfo->activeId != 0) && (pInfo->failedId < pInfo->activeId)) { + stDebug("s-task:%s already send checkpoint-trigger, no longer dispatch any other data", id); + atomic_store_8(&pTask->outputq.status, TASK_OUTPUT_STATUS__NORMAL); + return 0; + } else { + stDebug("s-task:%s dispatch trigger set, and ignore since current active checkpointId:%" PRId64 " failed", id, + pInfo->activeId); + } } if (pTask->msgInfo.pData != NULL) { @@ -788,8 +794,10 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) { if (type == STREAM_INPUT__CHECKPOINT_TRIGGER) { // outputQ should be empty here, otherwise, set the checkpoint failed due to the retrieve req happens if (streamQueueGetNumOfUnAccessedItems(pTask->outputq.queue) > 0) { - stError("s-task:%s items are still in outputQ due to downstream retrieve, failed to init trigger dispatch", - pTask->id.idStr); + stError( + "s-task:%s items are still in outputQ due to downstream retrieve, failed to init and discard " + "checkpoint-trigger dispatch", + pTask->id.idStr); streamTaskSetCheckpointFailed(pTask); clearBufferedDispatchMsg(pTask); continue; @@ -1478,6 +1486,8 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i int32_t numOfFailed = 0; bool triggerDispatchRsp = false; + taosMsleep(500); + // we only set the dispatch msg info for current checkpoint trans streamMutexLock(&pTask->lock); triggerDispatchRsp = (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) && diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 6d8f90f7f6..355a586e52 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -1190,6 +1190,7 @@ void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t c pTask->chkInfo.pActiveInfo->transId = transId; pTask->chkInfo.pActiveInfo->activeId = checkpointId; pTask->chkInfo.pActiveInfo->failedId = checkpointId; + stDebug("s-task:%s set failed checkpointId:%"PRId64, pTask->id.idStr, checkpointId); } int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) { @@ -1239,12 +1240,13 @@ void streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo) { taosMemoryFree(pInfo); } +//NOTE: clear the checkpoint id, and keep the failed id void streamTaskClearActiveInfo(SActiveCheckpointInfo* pInfo) { - pInfo->activeId = 0; // clear the checkpoint id + pInfo->activeId = 0; pInfo->transId = 0; pInfo->allUpstreamTriggerRecv = 0; pInfo->dispatchTrigger = false; - pInfo->failedId = 0; +// pInfo->failedId = 0; taosArrayClear(pInfo->pDispatchTriggerList); taosArrayClear(pInfo->pCheckpointReadyRecvList); diff --git a/tests/script/tsim/stream/pauseAndResume.sim b/tests/script/tsim/stream/pauseAndResume.sim index c2998dea30..1f4caf5c03 100644 --- a/tests/script/tsim/stream/pauseAndResume.sim +++ b/tests/script/tsim/stream/pauseAndResume.sim @@ -109,7 +109,7 @@ endi print ===== idle for 70 sec for checkpoint gen sleep 70000 -print ===== idle 60 sec completed , continue +print ===== idle 70 sec completed , continue print ===== step 1 over @@ -127,9 +127,12 @@ sql create stream streams2 trigger at_once IGNORE EXPIRED 0 IGNORE UPDATE 0 wate sql_error create stream streams2 trigger at_once IGNORE EXPIRED 0 IGNORE UPDATE 0 watermark 1d into streamt2 as select _wstart, count(*) c1, sum(a) c3 from t1 interval(10s); sql create stream if not exists streams2 trigger at_once IGNORE EXPIRED 0 IGNORE UPDATE 0 watermark 1d into streamt2 as select _wstart, count(*) c1, sum(a) c3 from t1 interval(10s); +print start to check stream status + sleep 1000 run tsim/stream/checkTaskStatus.sim +print pause stream2 sql pause stream streams2; sql insert into t1 values(1648791213001,1,12,3,1.0); From a12e96d2c30a2a2edf7b5855de26ef3e3da4635c Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 13:51:25 +0800 Subject: [PATCH 18/90] fix: build on windows --- source/os/src/osFile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index f4afaeabd1..3be2b1e351 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -401,7 +401,7 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } if (h == INVALID_HANDLE_VALUE) { DWORD dwError = GetLastError(); - terrno = TAOS_SYSTEM_WINAPI_ERROR(error); + terrno = TAOS_SYSTEM_WINAPI_ERROR(dwError); // LPVOID lpMsgBuf; // FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, // NULL); From 81b0bdadc1c7b08b93aba2ab3b35c31c137f6298 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 10 Sep 2024 14:31:24 +0800 Subject: [PATCH 19/90] fix(stream): update the acceptcode for task epset update. --- source/dnode/mnode/impl/src/mndStreamUtil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index a405cdde0a..7cb02d1467 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -653,7 +653,7 @@ static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask return code; } - code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, TSDB_CODE_VND_INVALID_VGROUP_ID, 0); + code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, TSDB_CODE_VND_INVALID_VGROUP_ID, TSDB_CODE_VND_INVALID_VGROUP_ID); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(pBuf); } From 568b18d4ed220339e01b0a3e953376b319452829 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 10 Sep 2024 14:34:53 +0800 Subject: [PATCH 20/90] fix(stream): update the acceptcode for task epset update. --- source/dnode/mnode/impl/src/mndStreamUtil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index 7cb02d1467..b2e35827af 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -653,7 +653,7 @@ static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask return code; } - code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, TSDB_CODE_VND_INVALID_VGROUP_ID, TSDB_CODE_VND_INVALID_VGROUP_ID); + code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(pBuf); } From f18c1d87101f2dad0f87eb2584d53db8eea843b7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 10 Sep 2024 14:35:43 +0800 Subject: [PATCH 21/90] enh: error code handle --- source/dnode/vnode/src/inc/vnd.h | 6 +- source/dnode/vnode/src/inc/vnodeInt.h | 2 +- source/dnode/vnode/src/tsdb/tsdbCache.c | 4 +- source/dnode/vnode/src/tsdb/tsdbCommit2.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFS2.c | 7 +- source/dnode/vnode/src/tsdb/tsdbFSet2.c | 6 +- source/dnode/vnode/src/tsdb/tsdbFSet2.h | 2 +- source/dnode/vnode/src/tsdb/tsdbMerge.c | 2 +- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 6 +- source/dnode/vnode/src/tsdb/tsdbSnapInfo.c | 6 +- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 4 +- source/dnode/vnode/src/tsdb/tsdbSttFileRW.c | 5 +- source/dnode/vnode/src/tsdb/tsdbSttFileRW.h | 10 +-- source/dnode/vnode/src/vnd/vnodeAsync.c | 84 +++++++++++---------- source/dnode/vnode/src/vnd/vnodeBufPool.c | 12 ++- source/dnode/vnode/src/vnd/vnodeCfg.c | 2 +- source/dnode/vnode/src/vnd/vnodeCommit.c | 24 ++++-- source/dnode/vnode/src/vnd/vnodeHash.c | 5 +- source/dnode/vnode/src/vnd/vnodeModule.c | 2 +- source/dnode/vnode/src/vnd/vnodeOpen.c | 6 +- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 4 +- source/dnode/vnode/src/vnd/vnodeSvr.c | 6 +- 22 files changed, 106 insertions(+), 101 deletions(-) diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 1bc1eadca7..ff622d2dab 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -56,12 +56,12 @@ typedef enum { } EVAPriority; int32_t vnodeAsyncOpen(int32_t numOfThreads); -int32_t vnodeAsyncClose(); +void vnodeAsyncClose(); int32_t vnodeAChannelInit(int64_t async, SVAChannelID* channelID); int32_t vnodeAChannelDestroy(SVAChannelID* channelID, bool waitRunning); int32_t vnodeAsync(SVAChannelID* channelID, EVAPriority priority, int32_t (*execute)(void*), void (*complete)(void*), void* arg, SVATaskID* taskID); -int32_t vnodeAWait(SVATaskID* taskID); +void vnodeAWait(SVATaskID* taskID); int32_t vnodeACancel(SVATaskID* taskID); int32_t vnodeAsyncSetWorkers(int64_t async, int32_t numWorkers); @@ -95,7 +95,7 @@ struct SVBufPool { }; int32_t vnodeOpenBufPool(SVnode* pVnode); -int32_t vnodeCloseBufPool(SVnode* pVnode); +void vnodeCloseBufPool(SVnode* pVnode); void vnodeBufPoolReset(SVBufPool* pPool); void vnodeBufPoolAddToFreeList(SVBufPool* pPool); int32_t vnodeBufPoolRecycle(SVBufPool* pPool); diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 4bcd5335f7..7b1f3716c4 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -593,7 +593,7 @@ struct SVHashTable { #define vHashNumEntries(ht) ((ht)->numEntries) int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*)); -int32_t vHashDestroy(SVHashTable** ht); +void vHashDestroy(SVHashTable** ht); int32_t vHashPut(SVHashTable* ht, void* obj); int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj); int32_t vHashDrop(SVHashTable* ht, const void* obj); diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index f11788bb47..3a3e20612e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -2153,7 +2153,7 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea uint64_t uid = uidList[j]; STableLoadInfo *pInfo = getTableLoadInfo(pReader, uid); if (!pInfo) { - (void)tTombBlockDestroy(&block); + tTombBlockDestroy(&block); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } @@ -2225,7 +2225,7 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea } } - (void)tTombBlockDestroy(&block); + tTombBlockDestroy(&block); if (finished) { TAOS_RETURN(code); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index 586a86bdb6..58ab8bca82 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -418,7 +418,7 @@ static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) { taosMemoryFree(info); } - TAOS_UNUSED(vHashDestroy(&pTsdb->commitInfo->ht)); + vHashDestroy(&pTsdb->commitInfo->ht); taosArrayDestroy(pTsdb->commitInfo->arr); pTsdb->commitInfo->arr = NULL; taosMemoryFreeClear(pTsdb->commitInfo); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index ea9cb5f768..4ccda58903 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -252,7 +252,7 @@ static int32_t apply_commit(STFileSystem *fs) { if (fset1 && fset2) { if (fset1->fid < fset2->fid) { // delete fset1 - (void)tsdbTFileSetRemove(fset1); + tsdbTFileSetRemove(fset1); i1++; } else if (fset1->fid > fset2->fid) { // create new file set with fid of fset2->fid @@ -271,7 +271,7 @@ static int32_t apply_commit(STFileSystem *fs) { } } else if (fset1) { // delete fset1 - (void)tsdbTFileSetRemove(fset1); + tsdbTFileSetRemove(fset1); i1++; } else { // create new file set with fid of fset2->fid @@ -794,11 +794,10 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { return 0; } -int32_t tsdbEnableBgTask(STsdb *pTsdb) { +void tsdbEnableBgTask(STsdb *pTsdb) { (void)taosThreadMutexLock(&pTsdb->mutex); pTsdb->bgTaskDisabled = false; (void)taosThreadMutexUnlock(&pTsdb->mutex); - return 0; } int32_t tsdbCloseFS(STFileSystem **fs) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index 8864968f63..5a07994678 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -627,8 +627,8 @@ void tsdbTFileSetClear(STFileSet **fset) { } } -int32_t tsdbTFileSetRemove(STFileSet *fset) { - if (fset == NULL) return 0; +void tsdbTFileSetRemove(STFileSet *fset) { + if (fset == NULL) return; for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if (fset->farr[ftype] != NULL) { @@ -638,8 +638,6 @@ int32_t tsdbTFileSetRemove(STFileSet *fset) { } TARRAY2_DESTROY(fset->lvlArr, tsdbSttLvlRemove); - - return 0; } SSttLvl *tsdbTFileSetGetSttLvl(STFileSet *fset, int32_t level) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.h b/source/dnode/vnode/src/tsdb/tsdbFSet2.h index 25c998e945..24ae59e300 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.h @@ -43,7 +43,7 @@ int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset); int32_t tsdbTFileSetInitCopy(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset); int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset); void tsdbTFileSetClear(STFileSet **fset); -int32_t tsdbTFileSetRemove(STFileSet *fset); +void tsdbTFileSetRemove(STFileSet *fset); int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_t ever, STFileSet **fset, TFileOpArray *fopArr); diff --git a/source/dnode/vnode/src/tsdb/tsdbMerge.c b/source/dnode/vnode/src/tsdb/tsdbMerge.c index f14dc98658..a4965d49eb 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMerge.c +++ b/source/dnode/vnode/src/tsdb/tsdbMerge.c @@ -204,7 +204,7 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) { TAOS_CHECK_GOTO(tsdbSttFileReaderOpen(fobj->fname, &config, &reader), &lino, _exit); if ((code = TARRAY2_APPEND(merger->sttReaderArr, reader))) { - (void)tsdbSttFileReaderClose(&reader); + tsdbSttFileReaderClose(&reader); TSDB_CHECK_CODE(code, lino, _exit); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 1099218b73..3191ddb447 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -681,11 +681,7 @@ int32_t tLDataIterOpen2(SLDataIter *pIter, SSttFileReader *pSttFileReader, int32 } void tLDataIterClose2(SLDataIter *pIter) { - int32_t code = tsdbSttFileReaderClose(&pIter->pReader); // always return 0 - if (code != 0) { - tsdbError("%" PRId64 " failed to close tsdb file reader, code:%s", pIter->cid, tstrerror(code)); - } - + tsdbSttFileReaderClose(&pIter->pReader); pIter->pReader = NULL; } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c index 5e84c5ae25..d531179f97 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c @@ -355,7 +355,11 @@ static STsdbFSetPartList* tsdbSnapGetFSetPartList(STFileSystem* fs) { terrno = code; break; } - (void)TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn); + code = TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn); + if (code) { + terrno = code; + break; + } } (void)taosThreadMutexUnlock(&fs->tsdb->mutex); diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 9dd3b371c6..6b9a959157 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -104,7 +104,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) { TSDB_CHECK_CODE(code, lino, _exit); if ((code = TARRAY2_APPEND(reader->sttReaderArr, sttReader))) { - TAOS_UNUSED(tsdbSttFileReaderClose(&sttReader)); + tsdbSttFileReaderClose(&sttReader); TSDB_CHECK_CODE(code, lino, _exit); } } @@ -449,7 +449,7 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) { STsdb* tsdb = reader[0]->tsdb; - TAOS_UNUSED(tTombBlockDestroy(reader[0]->tombBlock)); + tTombBlockDestroy(reader[0]->tombBlock); tBlockDataDestroy(reader[0]->blockData); tsdbIterMergerClose(&reader[0]->dataIterMerger); diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index 2349d3adaf..3d9ea4ef69 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -93,12 +93,12 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); - (void)tsdbSttFileReaderClose(reader); + tsdbSttFileReaderClose(reader); } return code; } -int32_t tsdbSttFileReaderClose(SSttFileReader **reader) { +void tsdbSttFileReaderClose(SSttFileReader **reader) { if (reader[0]) { for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->local); ++i) { tBufferDestroy(reader[0]->local + i); @@ -110,7 +110,6 @@ int32_t tsdbSttFileReaderClose(SSttFileReader **reader) { taosMemoryFree(reader[0]); reader[0] = NULL; } - return 0; } // SSttFSegReader diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.h b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.h index 1b0911617e..f0dc01b059 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.h +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.h @@ -40,7 +40,7 @@ typedef TARRAY2(SSttFileReader *) TSttFileReaderArray; // SSttFileReader int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *config, SSttFileReader **reader); -int32_t tsdbSttFileReaderClose(SSttFileReader **reader); +void tsdbSttFileReaderClose(SSttFileReader **reader); // SSttSegReader int32_t tsdbSttFileReadSttBlk(SSttFileReader *reader, const TSttBlkArray **sttBlkArray); @@ -71,10 +71,10 @@ int32_t tsdbSttFileWriteBlockData(SSttFileWriter *writer, SBlockData *pBlockData int32_t tsdbSttFileWriteTombRecord(SSttFileWriter *writer, const STombRecord *record); bool tsdbSttFileWriterIsOpened(SSttFileWriter *writer); -int32_t tsdbFileWriteSttBlk(STsdbFD *fd, const TSttBlkArray *sttBlkArray, SFDataPtr *ptr, int64_t *fileSize, - int32_t encryptAlgorithm, char* encryptKey); -int32_t tsdbFileWriteSttFooter(STsdbFD *fd, const SSttFooter *footer, int64_t *fileSize, int32_t encryptAlgorithm, - char* encryptKey); +int32_t tsdbFileWriteSttBlk(STsdbFD *fd, const TSttBlkArray *sttBlkArray, SFDataPtr *ptr, int64_t *fileSize, + int32_t encryptAlgorithm, char *encryptKey); +int32_t tsdbFileWriteSttFooter(STsdbFD *fd, const SSttFooter *footer, int64_t *fileSize, int32_t encryptAlgorithm, + char *encryptKey); struct SSttFileWriterConfig { STsdb *tsdb; diff --git a/source/dnode/vnode/src/vnd/vnodeAsync.c b/source/dnode/vnode/src/vnd/vnodeAsync.c index 26a998ce74..4d1e2b47f3 100644 --- a/source/dnode/vnode/src/vnd/vnodeAsync.c +++ b/source/dnode/vnode/src/vnd/vnodeAsync.c @@ -122,7 +122,7 @@ SVAsync *vnodeAsyncs[3]; #define MIN_ASYNC_ID 1 #define MAX_ASYNC_ID (sizeof(vnodeAsyncs) / sizeof(vnodeAsyncs[0]) - 1) -static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) { +static void vnodeAsyncTaskDone(SVAsync *async, SVATask *task) { int32_t ret; if (task->channel != NULL && task->channel->scheduled == task) { @@ -176,10 +176,9 @@ static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) { } else { (void)taosThreadCondBroadcast(&task->waitCond); } - return 0; } -static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { +static void vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { while (async->queue[0].next != &async->queue[0] || async->queue[1].next != &async->queue[1] || async->queue[2].next != &async->queue[2]) { for (int32_t i = 0; i < EVA_PRIORITY_MAX; i++) { @@ -193,11 +192,10 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { .arg = task->arg, })); } - (void)vnodeAsyncTaskDone(async, task); + vnodeAsyncTaskDone(async, task); } } } - return 0; } static void *vnodeAsyncLoop(void *arg) { @@ -215,14 +213,14 @@ static void *vnodeAsyncLoop(void *arg) { // finish last running task if (worker->runningTask != NULL) { - (void)vnodeAsyncTaskDone(async, worker->runningTask); + vnodeAsyncTaskDone(async, worker->runningTask); worker->runningTask = NULL; } for (;;) { if (async->stop || worker->workerId >= async->numWorkers) { if (async->stop) { // cancel all tasks - (void)vnodeAsyncCancelAllTasks(async, cancelArray); + vnodeAsyncCancelAllTasks(async, cancelArray); } worker->state = EVA_WORKER_STATE_STOP; async->numLaunchWorkers--; @@ -269,7 +267,8 @@ static void *vnodeAsyncLoop(void *arg) { (void)taosThreadMutexUnlock(&async->mutex); // do run the task - (void)worker->runningTask->execute(worker->runningTask->arg); + int32_t code = worker->runningTask->execute(worker->runningTask->arg); + TAOS_UNUSED(code); } _exit: @@ -369,7 +368,7 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) { } ret = vHashInit(&(*async)->taskTable, vnodeAsyncTaskHash, vnodeAsyncTaskCompare); if (ret != 0) { - (void)vHashDestroy(&(*async)->channelTable); + vHashDestroy(&(*async)->channelTable); (void)taosThreadMutexDestroy(&(*async)->mutex); (void)taosThreadCondDestroy(&(*async)->hasTask); taosMemoryFree(*async); @@ -418,29 +417,32 @@ static int32_t vnodeAsyncDestroy(SVAsync **async) { (void)taosThreadMutexDestroy(&(*async)->mutex); (void)taosThreadCondDestroy(&(*async)->hasTask); - (void)vHashDestroy(&(*async)->channelTable); - (void)vHashDestroy(&(*async)->taskTable); + vHashDestroy(&(*async)->channelTable); + vHashDestroy(&(*async)->taskTable); taosMemoryFree(*async); *async = NULL; return 0; } -static int32_t vnodeAsyncLaunchWorker(SVAsync *async) { +static void vnodeAsyncLaunchWorker(SVAsync *async) { for (int32_t i = 0; i < async->numWorkers; i++) { if (async->workers[i].state == EVA_WORKER_STATE_ACTIVE) { continue; } else if (async->workers[i].state == EVA_WORKER_STATE_STOP) { - (void)taosThreadJoin(async->workers[i].thread, NULL); + TAOS_UNUSED(taosThreadJoin(async->workers[i].thread, NULL)); async->workers[i].state = EVA_WORKER_STATE_UINIT; } - (void)taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]); - async->workers[i].state = EVA_WORKER_STATE_ACTIVE; - async->numLaunchWorkers++; + int32_t ret = taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]); + if (ret) { + vError("failed to create worker thread since %s", tstrerror(ret)); + } else { + async->workers[i].state = EVA_WORKER_STATE_ACTIVE; + async->numLaunchWorkers++; + } break; } - return 0; } int32_t vnodeAsyncOpen(int32_t numOfThreads) { @@ -450,21 +452,25 @@ int32_t vnodeAsyncOpen(int32_t numOfThreads) { // vnode-commit code = vnodeAsyncInit(&vnodeAsyncs[1], "vnode-commit"); TSDB_CHECK_CODE(code, lino, _exit); - (void)vnodeAsyncSetWorkers(1, numOfThreads); + + code = vnodeAsyncSetWorkers(1, numOfThreads); + TSDB_CHECK_CODE(code, lino, _exit); // vnode-merge code = vnodeAsyncInit(&vnodeAsyncs[2], "vnode-merge"); TSDB_CHECK_CODE(code, lino, _exit); - (void)vnodeAsyncSetWorkers(2, numOfThreads); + + code = vnodeAsyncSetWorkers(2, numOfThreads); + TSDB_CHECK_CODE(code, lino, _exit); _exit: return code; } -int32_t vnodeAsyncClose() { - (void)vnodeAsyncDestroy(&vnodeAsyncs[1]); - (void)vnodeAsyncDestroy(&vnodeAsyncs[2]); - return 0; +void vnodeAsyncClose() { + int32_t ret; + ret = vnodeAsyncDestroy(&vnodeAsyncs[1]); + ret = vnodeAsyncDestroy(&vnodeAsyncs[2]); } int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*execute)(void *), void (*cancel)(void *), @@ -474,6 +480,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec return TSDB_CODE_INVALID_PARA; } + int32_t ret; int64_t id; SVAsync *async = vnodeAsyncs[channelID->async]; @@ -501,7 +508,8 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec SVAChannel channel = { .channelId = channelID->id, }; - (void)vHashGet(async->channelTable, &channel, (void **)&task->channel); + ret = vHashGet(async->channelTable, &channel, (void **)&task->channel); + TAOS_UNUSED(ret); if (task->channel == NULL) { (void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadCondDestroy(&task->waitCond); @@ -513,7 +521,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec task->taskId = id = ++async->nextTaskId; // add task to hash table - int32_t ret = vHashPut(async->taskTable, task); + ret = vHashPut(async->taskTable, task); if (ret != 0) { (void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadCondDestroy(&task->waitCond); @@ -539,7 +547,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec if (async->numIdleWorkers > 0) { (void)taosThreadCondSignal(&(async->hasTask)); } else if (async->numLaunchWorkers < async->numWorkers) { - (void)vnodeAsyncLaunchWorker(async); + vnodeAsyncLaunchWorker(async); } } else if (task->channel->scheduled->state == EVA_TASK_STATE_RUNNING || priority >= VATASK_PIORITY(task->channel->scheduled)) { @@ -579,11 +587,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec return 0; } -int32_t vnodeAWait(SVATaskID *taskID) { - if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) { - return TSDB_CODE_INVALID_PARA; - } - +void vnodeAWait(SVATaskID *taskID) { SVAsync *async = vnodeAsyncs[taskID->async]; SVATask *task = NULL; SVATask task2 = { @@ -592,7 +596,7 @@ int32_t vnodeAWait(SVATaskID *taskID) { (void)taosThreadMutexLock(&async->mutex); - (void)vHashGet(async->taskTable, &task2, (void **)&task); + int32_t ret = vHashGet(async->taskTable, &task2, (void **)&task); if (task) { task->numWait++; (void)taosThreadCondWait(&task->waitCond, &async->mutex); @@ -605,8 +609,6 @@ int32_t vnodeAWait(SVATaskID *taskID) { } (void)taosThreadMutexUnlock(&async->mutex); - - return 0; } int32_t vnodeACancel(SVATaskID *taskID) { @@ -625,14 +627,14 @@ int32_t vnodeACancel(SVATaskID *taskID) { (void)taosThreadMutexLock(&async->mutex); - (void)vHashGet(async->taskTable, &task2, (void **)&task); + ret = vHashGet(async->taskTable, &task2, (void **)&task); if (task) { if (task->state == EVA_TASK_STATE_WAITTING) { cancel = task->cancel; arg = task->arg; task->next->prev = task->prev; task->prev->next = task->next; - (void)vnodeAsyncTaskDone(async, task); + vnodeAsyncTaskDone(async, task); } else { ret = TSDB_CODE_FAILED; } @@ -651,6 +653,7 @@ int32_t vnodeAsyncSetWorkers(int64_t asyncID, int32_t numWorkers) { if (asyncID < MIN_ASYNC_ID || asyncID > MAX_ASYNC_ID || numWorkers <= 0 || numWorkers > VNODE_ASYNC_MAX_WORKERS) { return TSDB_CODE_INVALID_PARA; } + int32_t ret; SVAsync *async = vnodeAsyncs[asyncID]; (void)taosThreadMutexLock(&async->mutex); async->numWorkers = numWorkers; @@ -725,12 +728,13 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { (void)taosThreadMutexLock(&async->mutex); - (void)vHashGet(async->channelTable, &channel2, (void **)&channel); + int32_t ret = vHashGet(async->channelTable, &channel2, (void **)&channel); + TAOS_UNUSED(ret); if (channel) { // unregister channel channel->next->prev = channel->prev; channel->prev->next = channel->next; - (void)vHashDrop(async->channelTable, channel); + ret = vHashDrop(async->channelTable, channel); async->numChannels--; // cancel all waiting tasks @@ -745,7 +749,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { .arg = task->arg, })); } - (void)vnodeAsyncTaskDone(async, task); + vnodeAsyncTaskDone(async, task); } } @@ -760,7 +764,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { .arg = channel->scheduled->arg, })); } - (void)vnodeAsyncTaskDone(async, channel->scheduled); + vnodeAsyncTaskDone(async, channel->scheduled); } taosMemoryFree(channel); } else { diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c index 35b3a87e00..eec4429403 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c @@ -58,7 +58,7 @@ static int32_t vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBu return 0; } -static int vnodeBufPoolDestroy(SVBufPool *pPool) { +static void vnodeBufPoolDestroy(SVBufPool *pPool) { vnodeBufPoolReset(pPool); if (pPool->lock) { (void)taosThreadSpinDestroy(pPool->lock); @@ -66,7 +66,6 @@ static int vnodeBufPoolDestroy(SVBufPool *pPool) { } (void)taosThreadMutexDestroy(&pPool->mutex); taosMemoryFree(pPool); - return 0; } int vnodeOpenBufPool(SVnode *pVnode) { @@ -77,7 +76,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { int32_t code; if ((code = vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i]))) { vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); - (void)vnodeCloseBufPool(pVnode); + vnodeCloseBufPool(pVnode); return code; } @@ -90,16 +89,15 @@ int vnodeOpenBufPool(SVnode *pVnode) { return 0; } -int vnodeCloseBufPool(SVnode *pVnode) { +void vnodeCloseBufPool(SVnode *pVnode) { for (int32_t i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) { if (pVnode->aBufPool[i]) { - (void)vnodeBufPoolDestroy(pVnode->aBufPool[i]); + vnodeBufPoolDestroy(pVnode->aBufPool[i]); pVnode->aBufPool[i] = NULL; } } vDebug("vgId:%d, vnode buffer pool is closed", TD_VID(pVnode)); - return 0; } void vnodeBufPoolReset(SVBufPool *pPool) { @@ -234,7 +232,7 @@ void vnodeBufPoolAddToFreeList(SVBufPool *pPool) { vInfo("vgId:%d, buffer pool of id %d size changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->id, pPool->node.size, size); - (void)vnodeBufPoolDestroy(pPool); + vnodeBufPoolDestroy(pPool); pPool = pNewPool; pVnode->aBufPool[pPool->id] = pPool; } diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index d90badc34c..969b9b9363 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -351,7 +351,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (info == NULL) return -1; tjsonGetNumberValue(info, "nodePort", pNode->nodePort, code); if (code) return code; - (void)tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn); + code = tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn); tjsonGetNumberValue(info, "nodeId", pNode->nodeId, code); if (code) return code; tjsonGetNumberValue(info, "clusterId", pNode->clusterId, code); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index d433498590..3564d90752 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -272,7 +272,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { int64_t lastCommitted = pInfo->info.state.committed; // wait last commit task - (void)vnodeAWait(&pVnode->commitTask); + vnodeAWait(&pVnode->commitTask); code = syncNodeGetConfig(pVnode->sync, &pVnode->config.syncCfg); TSDB_CHECK_CODE(code, lino, _exit); @@ -293,7 +293,8 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { code = vnodeSaveInfo(dir, &pInfo->info); TSDB_CHECK_CODE(code, lino, _exit); - (void)tsdbPreCommit(pVnode->pTsdb); + code = tsdbPreCommit(pVnode->pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); code = metaPrepareAsyncCommit(pVnode->pMeta); TSDB_CHECK_CODE(code, lino, _exit); @@ -395,10 +396,15 @@ _exit: return code; } -int vnodeSyncCommit(SVnode *pVnode) { - (void)vnodeAsyncCommit(pVnode); - (void)vnodeAWait(&pVnode->commitTask); - return 0; +int32_t vnodeSyncCommit(SVnode *pVnode) { + int32_t lino; + int32_t code = vnodeAsyncCommit(pVnode); + TSDB_CHECK_CODE(code, lino, _exit); + vnodeAWait(&pVnode->commitTask); + +_exit: + vError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code)); + return code; } static int vnodeCommitImpl(SCommitInfo *pInfo) { @@ -419,7 +425,8 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); - (void)syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); + code = syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); + TSDB_CHECK_CODE(code, lino, _exit); code = tsdbCommitBegin(pVnode->pTsdb, pInfo); TSDB_CHECK_CODE(code, lino, _exit); @@ -456,7 +463,8 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { return -1; } - (void)syncEndSnapshot(pVnode->sync); + code = syncEndSnapshot(pVnode->sync); + TSDB_CHECK_CODE(code, lino, _exit); _exit: if (code) { diff --git a/source/dnode/vnode/src/vnd/vnodeHash.c b/source/dnode/vnode/src/vnd/vnodeHash.c index 1aab0e4783..c2b37c56a6 100644 --- a/source/dnode/vnode/src/vnd/vnodeHash.c +++ b/source/dnode/vnode/src/vnd/vnodeHash.c @@ -71,9 +71,9 @@ int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*com return 0; } -int32_t vHashDestroy(SVHashTable** ht) { +void vHashDestroy(SVHashTable** ht) { if (ht == NULL) { - return TSDB_CODE_INVALID_PARA; + return; } if (*ht) { @@ -81,7 +81,6 @@ int32_t vHashDestroy(SVHashTable** ht) { taosMemoryFree(*ht); (*ht) = NULL; } - return 0; } int32_t vHashPut(SVHashTable* ht, void* obj) { diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c index 2a2d01ada8..781736edba 100644 --- a/source/dnode/vnode/src/vnd/vnodeModule.c +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -34,7 +34,7 @@ int vnodeInit(int nthreads, StopDnodeFp stopDnodeFp) { void vnodeCleanup() { if (atomic_val_compare_exchange_32(&VINIT, 1, 0) == 0) return; - (void)vnodeAsyncClose(); + vnodeAsyncClose(); walCleanUp(); smaCleanUp(); } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index bdc866500c..1f54fea27c 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -502,7 +502,7 @@ _err: if (pVnode->pTsdb) (void)tsdbClose(&pVnode->pTsdb); if (pVnode->pSma) (void)smaClose(pVnode->pSma); if (pVnode->pMeta) (void)metaClose(&pVnode->pMeta); - if (pVnode->freeList) (void)vnodeCloseBufPool(pVnode); + if (pVnode->freeList) vnodeCloseBufPool(pVnode); taosMemoryFree(pVnode); return NULL; @@ -517,7 +517,7 @@ void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); } void vnodeClose(SVnode *pVnode) { if (pVnode) { - (void)vnodeAWait(&pVnode->commitTask); + vnodeAWait(&pVnode->commitTask); (void)vnodeAChannelDestroy(&pVnode->commitChannel, true); vnodeSyncClose(pVnode); vnodeQueryClose(pVnode); @@ -526,7 +526,7 @@ void vnodeClose(SVnode *pVnode) { if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb); (void)smaClose(pVnode->pSma); if (pVnode->pMeta) metaClose(&pVnode->pMeta); - (void)vnodeCloseBufPool(pVnode); + vnodeCloseBufPool(pVnode); // destroy handle (void)tsem_destroy(&pVnode->syncSem); diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index fb0d0d5277..2a4c83c9ee 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -586,7 +586,7 @@ _exit: } extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb); -extern int32_t tsdbEnableBgTask(STsdb *pTsdb); +extern void tsdbEnableBgTask(STsdb *pTsdb); static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) { (void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); @@ -596,7 +596,7 @@ static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) { } static int32_t vnodeEnableBgTask(SVnode *pVnode) { - (void)tsdbEnableBgTask(pVnode->pTsdb); + tsdbEnableBgTask(pVnode->pTsdb); (void)vnodeAChannelInit(1, &pVnode->commitChannel); return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 1d8b48bf01..2604e2262f 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -2041,7 +2041,7 @@ _exit: } extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb); -extern int32_t tsdbEnableBgTask(STsdb *pTsdb); +extern void tsdbEnableBgTask(STsdb *pTsdb); static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { bool walChanged = false; @@ -2143,10 +2143,10 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) { pVnode->config.sttTrigger = req.sttTrigger; } else { - (void)vnodeAWait(&pVnode->commitTask); + vnodeAWait(&pVnode->commitTask); (void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); pVnode->config.sttTrigger = req.sttTrigger; - (void)tsdbEnableBgTask(pVnode->pTsdb); + tsdbEnableBgTask(pVnode->pTsdb); } } From bb785ce53e01e2db0d0d549a531aed446620f50c Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Tue, 10 Sep 2024 14:47:42 +0800 Subject: [PATCH 22/90] fix(query):set scan flag info --- source/libs/executor/src/timewindowoperator.c | 4 ++-- source/libs/parser/src/parTranslater.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 59883d2b80..93b3759c47 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1082,7 +1082,7 @@ static int32_t openStateWindowAggOptr(SOperatorInfo* pOperator) { } pInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag; - code = setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true); + code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true); QUERY_CHECK_CODE(code, lino, _end); code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId); @@ -1567,7 +1567,7 @@ static int32_t doSessionWindowAggNext(SOperatorInfo* pOperator, SSDataBlock** pp QUERY_CHECK_CODE(code, lino, _end); } // the pDataBlock are always the same one, no need to call this again - code = setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true); + code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true); QUERY_CHECK_CODE(code, lino, _end); code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 62943cb6d5..85c8491aa1 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2559,6 +2559,13 @@ static int32_t translateRepeatScanFunc(STranslateContext* pCxt, SFunctionNode* p return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "%s function is not supported in partition query", pFunc->functionName); } + + if (NULL != pSelect->pWindow) { + if (QUERY_NODE_EVENT_WINDOW == nodeType(pSelect->pWindow) || QUERY_NODE_COUNT_WINDOW == nodeType(pSelect->pWindow)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, + "%s function is not supported in count/event window", pFunc->functionName); + } + } return TSDB_CODE_SUCCESS; } From aa5683cfd9fb9933924e3e0f0a6af0d8e9e2580f Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 14:55:14 +0800 Subject: [PATCH 23/90] osfile --- source/client/src/clientMonitor.c | 4 +-- source/common/src/cos.c | 6 ++-- source/common/src/cos_cp.c | 4 +-- source/common/src/rsync.c | 4 +-- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 6 ++-- source/dnode/mgmt/mgmt_vnode/src/vmFile.c | 6 ++-- source/dnode/mgmt/node_util/src/dmEps.c | 10 +++--- source/dnode/mgmt/node_util/src/dmFile.c | 18 +++++----- source/dnode/mnode/sdb/src/sdbFile.c | 30 ++++++---------- source/dnode/vnode/src/tsdb/tsdbFS.c | 6 ++-- source/dnode/vnode/src/tsdb/tsdbFS2.c | 7 ++-- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 8 ++--- source/dnode/vnode/src/vnd/vnodeCommit.c | 7 ++-- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 5 +-- source/libs/executor/src/groupcacheoperator.c | 10 +++--- source/libs/stream/src/streamBackendRocksdb.c | 4 +-- source/libs/sync/src/syncRaftCfg.c | 6 ++-- source/libs/sync/src/syncRaftStore.c | 8 ++--- source/libs/wal/src/walMeta.c | 20 +++++------ source/libs/wal/src/walRead.c | 6 ++-- source/libs/wal/src/walWrite.c | 12 +++---- source/os/src/osFile.c | 34 ++++++++++++------- source/os/src/osSocket.c | 2 +- source/util/src/tconfig.c | 7 +++- source/util/src/tlog.c | 5 ++- source/util/src/tpagedbuf.c | 5 ++- 26 files changed, 122 insertions(+), 118 deletions(-) diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 6a0a09f9bd..36dc474dd8 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -397,7 +397,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP } if (taosLSeekFile(pFile, 0, SEEK_END) < 0) { - tscError("failed to seek file:%p code: %d", pFile, errno); + tscError("failed to seek file:%p code: %d", pFile, terrno); return; } if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) { @@ -409,7 +409,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) { tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size); if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) { - tscError("failed to seek file:%p code: %d", pFile, errno); + tscError("failed to seek file:%p code: %d", pFile, terrno); return NULL; } diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 064e06eb43..1c06d9206e 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -132,7 +132,7 @@ int32_t s3CheckCfg() { } if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) { (void)fprintf(stderr, "failed to write test file: %s.\n", path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } if (taosFsyncFile(fp) < 0) { (void)fprintf(stderr, "failed to fsync test file: %s.\n", path); @@ -872,7 +872,7 @@ upload: if (i > 0 && cp.parts[i - 1].completed) { if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } @@ -1076,7 +1076,7 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec } if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) { (void)taosCloseFile(&data.infileFD); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = diff --git a/source/common/src/cos_cp.c b/source/common/src/cos_cp.c index 793433bba7..1caf6a7189 100644 --- a/source/common/src/cos_cp.c +++ b/source/common/src/cos_cp.c @@ -210,10 +210,10 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) { TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); } if (taosLSeekFile(fp, 0, SEEK_SET) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosWriteFile(fp, data, strlen(data)) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosFsyncFile(fp) < 0) { diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index b53c4e416e..525e1e0aea 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -90,10 +90,10 @@ static int32_t generateConfigFile(char* confDir) { #endif ); uDebug("[rsync] conf:%s", confContent); - if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) { + if (taosWriteFile(pFile, confContent, strlen(confContent)) != TSDB_CODE_SUCCESS) { uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); (void)taosCloseFile(&pFile); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; return code; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index d9f6920fcb..05a09b9a97 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -83,8 +83,8 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -203,7 +203,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index d5b1e61aed..b7bf25c8d3 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -120,8 +120,8 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -240,7 +240,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 7c0272965a..685d70e1ae 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -209,8 +209,8 @@ int32_t dmReadEps(SDnodeData *pData) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -336,7 +336,7 @@ int32_t dmWriteEps(SDnodeData *pData) { if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); int32_t len = strlen(buffer); - if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); (void)taosCloseFile(&pFile); @@ -612,8 +612,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, terrstr()); goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 3412d5ed3a..c524f4eacf 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -62,8 +62,8 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -154,7 +154,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { @@ -244,7 +244,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool } if (taosWriteFile(pFile, opts.result, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -282,7 +282,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC int32_t len = strlen(encryptCode); if (taosWriteFile(pFile, encryptCode, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { @@ -320,8 +320,8 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { goto _OVER; } - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -461,8 +461,8 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 813579ac26..e19f57ad46 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -168,26 +168,21 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { } static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { - int32_t code = 0; int64_t sver = SDB_FILE_VER; if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { @@ -196,8 +191,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { maxId = pSdb->maxId[i]; } if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } } @@ -207,15 +201,13 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { ver = pSdb->tableVer[i]; } if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } } char reserve[SDB_RESERVE_SIZE] = {0}; if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } return 0; @@ -440,7 +432,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { pRaw->status = pRow->status; if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -472,7 +464,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { } if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -484,7 +476,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { - code = TAOS_SYSTEM_ERROR(errno); + code = errno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -784,7 +776,7 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) { int32_t code = 0; int32_t writelen = taosWriteFile(pIter->file, pBuf, len); if (writelen != len) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total); TAOS_RETURN(code); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index cde4d7ded8..3e2d8c026f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -116,7 +116,7 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { int64_t n = taosWriteFile(pFD, pData, size); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(pFD) < 0) { @@ -296,8 +296,8 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { } int64_t size; - if (taosFStatFile(pFD, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFD, &size, NULL); + if (code != 0) { (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 843e700fd3..ea6f10b1bd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -93,7 +93,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { } if (taosWriteFile(fp, data, strlen(data)) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(fp) < 0) { @@ -120,8 +120,9 @@ static int32_t load_json(const char *fname, cJSON **json) { } int64_t size; - if (taosFStatFile(fp, &size, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + code = taosFStatFile(fp, &size, NULL); + if (code != 0) { + TSDB_CHECK_CODE(code, lino, _exit); } data = taosMemoryMalloc(size + 1); diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index c34b29f97d..b0fbc19ec0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -154,7 +154,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } (void)taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); @@ -183,7 +183,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (pFD->szFile < pFD->pgno) { @@ -220,7 +220,7 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor // seek int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } // read @@ -373,7 +373,7 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo // read last chunk int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET); if (ret < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } ret = taosReadFile(pFD->pFD, buf + n, nRead); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index c272e540ba..485499a28f 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -185,7 +185,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { } if (taosWriteFile(pFile, data, strlen(data)) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(pFile) < 0) { @@ -236,9 +236,8 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } - if (taosFStatFile(pFile, &size, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); - } + code = taosFStatFile(pFile, &size, NULL); + TSDB_CHECK_CODE(code, lino, _exit); pData = taosMemoryMalloc(size + 1); if (pData == NULL) { diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 7d8b5d4eda..e1ac42ca8c 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -272,9 +272,10 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) } int64_t size; - if (taosFStatFile(pFile, &size, NULL) < 0) { + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { (void)taosCloseFile(&pFile); - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code, lino, _exit); } *ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 576f3932b6..15350bdfef 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -315,16 +315,16 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC } int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET); - if (ret == -1) { + if (ret < 0) { releaseFdToFileCtx(pFd); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _return; } ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize); if (ret != pHead->basic.bufSize) { releaseFdToFileCtx(pFd); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _return; } @@ -548,8 +548,8 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa } int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET); - if (ret == -1) { - code = TAOS_SYSTEM_ERROR(errno); + if (ret < 0) { + code = terrno; goto _return; } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 4e14df9a40..993d9d91af 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -1669,7 +1669,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { } if (nBytes != taosWriteFile(pFile, buf, nBytes)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to write file to add extra info, file:%s, reason:%s", pDst, tstrerror(code)); goto _EXIT; } @@ -4970,7 +4970,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { nBytes = taosWriteFile(pFile, content, strlen(content)); if (nBytes != strlen(content)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code)); (void)taosCloseFile(&pFile); goto _ERROR; diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index ac3bba8c42..c7811ed093 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -156,7 +156,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_EXIT(terrno); } if (taosFsyncFile(pFile) < 0) { @@ -265,8 +265,8 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { sError("vgId:%d, failed to fstat sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code)); goto _OVER; } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index d6482ba2da..a4377858d8 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -58,10 +58,10 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr()); - - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + TAOS_CHECK_GOTO(code, &lino, _OVER); } pData = taosMemoryMalloc(size + 1); @@ -130,7 +130,7 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); int32_t len = strlen(buffer); - if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 378e9d1903..3c144cae23 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -106,7 +106,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in int64_t ret = taosLSeekFile(pFile, offset, SEEK_SET); if (ret < 0) { wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), offset); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (readSize != taosReadFile(pFile, buf, readSize)) { @@ -169,9 +169,9 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in } int64_t ret = taosLSeekFile(pFile, offset + readSize, SEEK_SET); if (ret < 0) { - wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(terrno), offset); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; break; } if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) { @@ -518,7 +518,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { static int32_t walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pCkHead) { if (taosLSeekFile(pLogFile, offset, SEEK_SET) < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { @@ -578,14 +578,14 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { // determine the last valid entry end, i.e. offset while ((offset -= sizeof(SWalIdxEntry)) >= 0) { if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) { - wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { - wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno), offset, fnameStr); TAOS_CHECK_GOTO(terrno, &lino, _err); @@ -628,7 +628,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { wError("vgId:%d, failed to seek file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } int64_t count = 0; @@ -654,7 +654,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) { wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } count++; } @@ -950,7 +950,7 @@ int32_t walSaveMeta(SWal* pWal) { if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) { wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) { diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 6476cd39ac..73cf6d46ef 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -137,7 +137,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int wError("vgId:%d, failed to seek idx file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, offset, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } SWalIdxEntry entry = {0}; if ((ret = taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry))) != sizeof(SWalIdxEntry)) { @@ -158,7 +158,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int wError("vgId:%d, failed to seek log file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, entry.offset, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -303,7 +303,7 @@ int32_t walSkipFetchBody(SWalReader *pRead) { } int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR); if (code < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pRead->curVersion++; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index a11831c437..43d5c07270 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -207,7 +207,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // read idx file and get log file pos SWalIdxEntry entry; @@ -232,7 +232,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // TODO TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // validate offset SWalCkHead head; @@ -536,13 +536,13 @@ static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { pWal->stopDnode(); } - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // check alignment of idx entries int64_t endOffset = taosLSeekFile(pWal->pIdxFile, 0, SEEK_END); if (endOffset < 0) { - wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(errno), + wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(terrno), ver); taosMsleep(100); exit(EXIT_FAILURE); @@ -578,7 +578,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, &pWal->writeHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); @@ -634,7 +634,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy } if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, (char *)buf, cyptedBodyLen) != cyptedBodyLen) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 3be2b1e351..042be9c71f 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -437,19 +437,22 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { if (pFile == NULL || pFile->hFile == NULL) { + terrno = TSDB_CODE_INVALID_PARA; return 0; } #if FILE_WITH_LOCK - taosThreadRwlockWrlock(&(pFile->rwlock)); + (void)taosThreadRwlockWrlock(&(pFile->rwlock)); #endif DWORD bytesWritten; if (!WriteFile(pFile->hFile, buf, count, &bytesWritten, NULL)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); bytesWritten = -1; } #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return bytesWritten; } @@ -490,6 +493,7 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (pFile == NULL || pFile->hFile == NULL) { + terrno = TSDB_CODE_INVALID_PARA; return -1; } #if FILE_WITH_LOCK @@ -499,11 +503,15 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { LARGE_INTEGER liOffset; liOffset.QuadPart = offset; if (!SetFilePointerEx(pFile->hFile, liOffset, NULL, whence)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); return -1; } liOffset.QuadPart = 0; if (!SetFilePointerEx(pFile->hFile, liOffset, &liOffset, FILE_CURRENT)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); return -1; } #if FILE_WITH_LOCK @@ -514,13 +522,16 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (pFile == NULL || pFile->hFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } if (size != NULL) { LARGE_INTEGER fileSize; if (!GetFileSizeEx(pFile->hFile, &fileSize)) { - return -1; // Error getting file size + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); + return terrno; // Error getting file size } *size = fileSize.QuadPart; } @@ -528,7 +539,9 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (mtime != NULL) { FILETIME creationTime, lastAccessTime, lastWriteTime; if (!GetFileTime(pFile->hFile, &creationTime, &lastAccessTime, &lastWriteTime)) { - return -1; // Error getting file time + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); + return terrno; // Error getting file time } // Convert the FILETIME structure to a time_t value ULARGE_INTEGER ull; @@ -854,7 +867,7 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (pFile == NULL || pFile->fd < 0) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); @@ -873,7 +886,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (code) { terrno = code; - return terrno; + return -1; } return ret; @@ -890,16 +903,11 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { return terrno; } -#ifdef WINDOWS - struct __stat64 fileStat; - int32_t code = _fstat64(pFile->fd, &fileStat); -#else struct stat fileStat; int32_t code = fstat(pFile->fd, &fileStat); -#endif if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); - return code; + return terrno; } if (size != NULL) { diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 48ca36b5e5..4d650715f9 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1178,7 +1178,7 @@ int32_t taosWinSocketInit() { WSADATA wsaData; wVersionRequested = MAKEWORD(1, 1); if (WSAStartup(wVersionRequested, &wsaData) != 0) { - atomic_store_8(&flag, 0) + atomic_store_8(&flag, 0); int errorCode = WSAGetLastError(); return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode); } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index c6da1537f5..48fe271d33 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -1255,11 +1255,16 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); } size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); + if(fileSize <= 0) { + (void)taosCloseFile(&pFile); + (void)printf("load json file error: %s\n", filepath); + TAOS_CHECK_EXIT(terrno); + } char *buf = taosMemoryMalloc(fileSize + 1); if (!buf) { (void)taosCloseFile(&pFile); (void)printf("load json file error: %s, failed to alloc memory\n", filepath); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } buf[fileSize] = 0; diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 49e1d87d80..98e17c5db9 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -545,9 +545,9 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) { // only an estimate for number of lines int64_t filesize = 0; - if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) { + if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) != 0) { (void)printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } tsLogObj.lines = (int32_t)(filesize / 60); @@ -1003,7 +1003,6 @@ _return: if (pFile) (void)taosCloseFile(&pFile); - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "crash signal is %d", signum); #ifdef _TD_DARWIN_64 diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index de27cf4df9..265f06cbfd 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -136,13 +136,12 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) { int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET); if (ret == -1) { - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = terrno; return terrno; } ret = (int32_t)taosWriteFile(pBuf->pFile, pData, size); if (ret != size) { - terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } @@ -249,7 +248,7 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); if (ret == -1) { - ret = TAOS_SYSTEM_ERROR(errno); + ret = terrno; return ret; } From 08be2b98bc02bc8682a2d47b48e5766266c7939c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 10 Sep 2024 15:20:09 +0800 Subject: [PATCH 24/90] fix: coredump --- source/dnode/vnode/src/vnd/vnodeAsync.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/dnode/vnode/src/vnd/vnodeAsync.c b/source/dnode/vnode/src/vnd/vnodeAsync.c index 4d1e2b47f3..56968fd60e 100644 --- a/source/dnode/vnode/src/vnd/vnodeAsync.c +++ b/source/dnode/vnode/src/vnd/vnodeAsync.c @@ -588,6 +588,10 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec } void vnodeAWait(SVATaskID *taskID) { + if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) { + return; + } + SVAsync *async = vnodeAsyncs[taskID->async]; SVATask *task = NULL; SVATask task2 = { From 529af8d20b4a738bc70189eac52fcfcf5bb6774c Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 10 Sep 2024 16:48:16 +0800 Subject: [PATCH 25/90] fix(tsdb/cache): comment mem's early ts block --- source/dnode/vnode/src/tsdb/tsdbCache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 2b76e8841d..d19a3b034d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -2691,12 +2691,14 @@ static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow, bool *pIgnoreEarli switch (state->state) { case SMEMNEXTROW_ENTER: { if (state->pMem != NULL) { + /* if (state->pMem->maxKey <= state->lastTs) { *ppRow = NULL; *pIgnoreEarlierTs = true; TAOS_RETURN(code); } + */ tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter); TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter); From dc983b9a39a3b317d40caf12870b37fa59b6020c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 10 Sep 2024 16:56:36 +0800 Subject: [PATCH 26/90] fix: add block data check --- include/common/tdatablock.h | 2 +- source/common/src/tdatablock.c | 13 +++++++++---- source/libs/executor/src/dynqueryctrloperator.c | 1 + source/libs/executor/src/executor.c | 5 +++++ source/libs/executor/src/executorInt.c | 2 ++ source/libs/executor/src/groupcacheoperator.c | 2 ++ source/libs/executor/src/mergejoinoperator.c | 8 ++++++-- source/libs/executor/src/mergeoperator.c | 2 ++ source/libs/executor/src/operator.c | 4 ++-- source/libs/executor/src/sortoperator.c | 5 ++++- 10 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 1d280b5d6b..cbfd1efb84 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -233,7 +233,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); * @brief find how many rows already in order start from first row */ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo); -void blockDataCheck(const SSDataBlock* pDataBlock); +void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk); int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 840434a351..6e4162268d 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -731,6 +731,10 @@ int32_t blockDataMergeNRows(SSDataBlock* pDest, const SSDataBlock* pSrc, int32_t } void blockDataShrinkNRows(SSDataBlock* pBlock, int32_t numOfRows) { + if (numOfRows == 0) { + return; + } + if (numOfRows >= pBlock->info.rows) { blockDataCleanup(pBlock); return; @@ -2936,7 +2940,7 @@ int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, cha // return length of encoded data, return -1 if failed int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) { - blockDataCheck(pBlock); + blockDataCheck(pBlock, false); int32_t dataLen = 0; @@ -3180,7 +3184,7 @@ int32_t blockDecode(SSDataBlock* pBlock, const char* pData, const char** pEndPos *pEndPos = pStart; - blockDataCheck(pBlock); + blockDataCheck(pBlock, false); return code; } @@ -3392,14 +3396,14 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) { return nextRowIdx; } -void blockDataCheck(const SSDataBlock* pDataBlock) { +void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { if (NULL == pDataBlock || pDataBlock->info.rows == 0) { return; } ASSERT(pDataBlock->info.rows > 0); - if (!pDataBlock->info.dataLoad) { + if (!pDataBlock->info.dataLoad && !forceChk) { return; } @@ -3457,3 +3461,4 @@ void blockDataCheck(const SSDataBlock* pDataBlock) { return; } + diff --git a/source/libs/executor/src/dynqueryctrloperator.c b/source/libs/executor/src/dynqueryctrloperator.c index 44e8a3cb8a..aa0cc215df 100644 --- a/source/libs/executor/src/dynqueryctrloperator.c +++ b/source/libs/executor/src/dynqueryctrloperator.c @@ -528,6 +528,7 @@ static void seqJoinLaunchNewRetrieveImpl(SOperatorInfo* pOperator, SSDataBlock** qDebug("%s dynamic post task begin", GET_TASKID(pOperator->pTaskInfo)); code = pOperator->pDownstream[1]->fpSet.getNextExtFn(pOperator->pDownstream[1], pParam, ppRes); if (*ppRes && (code == 0)) { + blockDataCheck(*ppRes, false); pPost->isStarted = true; pStbJoin->execInfo.postBlkNum++; pStbJoin->execInfo.postBlkRows += (*ppRes)->info.rows; diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 9e33a3d890..cca1895a85 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -692,8 +692,10 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo if (pTaskInfo->pOpParam && !pTaskInfo->paramSet) { pTaskInfo->paramSet = true; code = pTaskInfo->pRoot->fpSet.getNextExtFn(pTaskInfo->pRoot, pTaskInfo->pOpParam, &pRes); + blockDataCheck(pRes, false); } else { code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes); + blockDataCheck(pRes, false); } QUERY_CHECK_CODE(code, lino, _end); @@ -740,6 +742,7 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo } code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes); + blockDataCheck(pRes, false); QUERY_CHECK_CODE(code, lino, _end); } @@ -839,6 +842,8 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) { qError("%s failed at line %d, code:%s %s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); } + blockDataCheck(*pRes, false); + uint64_t el = (taosGetTimestampUs() - st); pTaskInfo->cost.elapsedTime += el; diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 00138d6871..c8ec1e8fcc 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -617,6 +617,8 @@ int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* p code = TSDB_CODE_SUCCESS; _err: + blockDataCheck(pBlock, true); + colDataDestroy(p); taosMemoryFree(p); return code; diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 1796aa7b64..990c9322b7 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -733,6 +733,8 @@ static FORCE_INLINE int32_t getBlkFromDownstreamOperator(struct SOperatorInfo* p } } + blockDataCheck(pBlock, false); + *ppRes = pBlock; return code; } diff --git a/source/libs/executor/src/mergejoinoperator.c b/source/libs/executor/src/mergejoinoperator.c index 90c2248c12..c29c49e280 100644 --- a/source/libs/executor/src/mergejoinoperator.c +++ b/source/libs/executor/src/mergejoinoperator.c @@ -474,8 +474,11 @@ int32_t mJoinCopyMergeMidBlk(SMJoinMergeCtx* pCtx, SSDataBlock** ppMid, SSDataBl pCtx->midRemains = false; } else { int32_t copyRows = pMore->info.capacity - pMore->info.rows; - MJ_ERR_RET(blockDataMergeNRows(pMore, pLess, pLess->info.rows - copyRows, copyRows)); - blockDataShrinkNRows(pLess, copyRows); + if (copyRows > 0) { + MJ_ERR_RET(blockDataMergeNRows(pMore, pLess, pLess->info.rows - copyRows, copyRows)); + blockDataShrinkNRows(pLess, copyRows); + } + pCtx->midRemains = true; } @@ -1742,6 +1745,7 @@ int32_t mJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** pResBloc if (pBlock && pBlock->info.rows > 0) { *pResBlock = pBlock; } + return code; } diff --git a/source/libs/executor/src/mergeoperator.c b/source/libs/executor/src/mergeoperator.c index 7357329ca6..c94a330dbc 100644 --- a/source/libs/executor/src/mergeoperator.c +++ b/source/libs/executor/src/mergeoperator.c @@ -66,6 +66,7 @@ static int32_t sortMergeloadNextDataBlock(void* param, SSDataBlock** ppBlock); int32_t sortMergeloadNextDataBlock(void* param, SSDataBlock** ppBlock) { SOperatorInfo* pOperator = (SOperatorInfo*)param; int32_t code = pOperator->fpSet.getNextFn(pOperator, ppBlock); + blockDataCheck(*ppBlock, false); return code; } @@ -524,6 +525,7 @@ int32_t doMultiwayMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { if ((*pResBlock) != NULL) { pOperator->resultInfo.totalRows += (*pResBlock)->info.rows; + blockDataCheck(*pResBlock, false); } else { setOperatorCompleted(pOperator); } diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c index de478a146f..cb1149d8a3 100644 --- a/source/libs/executor/src/operator.c +++ b/source/libs/executor/src/operator.c @@ -868,14 +868,14 @@ int32_t setOperatorParams(struct SOperatorInfo* pOperator, SOperatorParam* pInpu SSDataBlock* getNextBlockFromDownstream(struct SOperatorInfo* pOperator, int32_t idx) { SSDataBlock* p = NULL; int32_t code = getNextBlockFromDownstreamImpl(pOperator, idx, true, &p); - blockDataCheck(p); + blockDataCheck(p, false); return (code == 0)? p:NULL; } SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, int32_t idx) { SSDataBlock* p = NULL; int32_t code = getNextBlockFromDownstreamImpl(pOperator, idx, false, &p); - blockDataCheck(p); + blockDataCheck(p, false); return (code == 0)? p:NULL; } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 9b659ac761..27ae5e7281 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -328,7 +328,9 @@ static int32_t getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t loadNextDataBlock(void* param, SSDataBlock** ppBlock) { SOperatorInfo* pOperator = (SOperatorInfo*)param; - return pOperator->fpSet.getNextFn(pOperator, ppBlock); + int32_t code = pOperator->fpSet.getNextFn(pOperator, ppBlock); + blockDataCheck(*ppBlock, false); + return code; } // todo refactor: merged with fetch fp @@ -611,6 +613,7 @@ int32_t fetchNextGroupSortDataBlock(void* param, SSDataBlock** ppBlock) { QUERY_CHECK_CODE(code, lino, _end); if (block != NULL) { + blockDataCheck(block, false); if (block->info.id.groupId == grpSortOpInfo->currGroupId) { grpSortOpInfo->childOpStatus = CHILD_OP_SAME_GROUP; *ppBlock = block; From da990aa91d0fff22dc06f14214dbcddd9fa1f06e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 10 Sep 2024 17:20:32 +0800 Subject: [PATCH 27/90] fix(stream): fix syntax error. --- source/dnode/mnode/impl/src/mndStream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index ade8d541de..0c57f8466d 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -903,7 +903,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { _OVER: if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("stream:%s, failed to create at line:%d since %s", createReq.name, lino, terrstr(code)); + mError("stream:%s, failed to create at line:%d since %s", createReq.name, lino, tstrerror(code)); } else { mDebug("stream:%s create stream completed", createReq.name); code = TSDB_CODE_ACTION_IN_PROGRESS; @@ -1121,7 +1121,7 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre code = mndTransPrepare(pMnode, pTrans); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("failed to prepare checkpoint trans since %s", terrstr(code)); + mError("failed to prepare checkpoint trans since %s", tstrerror(code)); } else { code = TSDB_CODE_ACTION_IN_PROGRESS; } From aea768d2c07e414a68fbe22405acbb856d619da3 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 17:40:19 +0800 Subject: [PATCH 28/90] osFile --- source/client/src/clientMonitor.c | 12 +- source/common/src/cos.c | 16 +- source/common/src/cos_cp.c | 6 +- source/common/src/rsync.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 8 +- source/dnode/mgmt/mgmt_vnode/src/vmFile.c | 6 +- source/dnode/mgmt/node_util/src/dmEps.c | 10 +- source/dnode/mgmt/node_util/src/dmFile.c | 20 +- source/dnode/mnode/impl/src/mndDump.c | 2 +- source/dnode/mnode/sdb/src/sdbFile.c | 10 +- source/dnode/vnode/src/tsdb/tsdbFS.c | 14 +- source/dnode/vnode/src/tsdb/tsdbFS2.c | 6 +- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 8 +- source/dnode/vnode/src/tsdb/tsdbRetention.c | 26 +-- source/dnode/vnode/src/vnd/vnodeCommit.c | 6 +- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 2 +- source/libs/executor/src/groupcacheoperator.c | 2 +- source/libs/function/src/udfd.c | 2 +- source/libs/parser/src/parInsertSql.c | 2 +- source/libs/parser/src/parTranslater.c | 6 +- source/libs/stream/src/streamBackendRocksdb.c | 12 +- source/libs/stream/src/streamSnapshot.c | 4 +- source/libs/sync/src/syncRaftCfg.c | 4 +- source/libs/sync/src/syncRaftStore.c | 8 +- source/libs/wal/src/walMeta.c | 22 +- source/libs/wal/src/walRead.c | 4 +- source/libs/wal/src/walWrite.c | 44 ++-- source/os/src/osFile.c | 212 ++++++------------ source/util/src/tconfig.c | 8 +- source/util/src/tlog.c | 9 +- source/util/src/tpagedbuf.c | 2 +- 31 files changed, 202 insertions(+), 293 deletions(-) diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 36dc474dd8..b890b61668 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -34,11 +34,11 @@ static void processFileInTheEnd(TdFilePtr pFile, char* path) { return; } if (taosFtruncateFile(pFile, 0) != 0) { - tscError("failed to truncate file:%s, errno:%d", path, errno); + tscError("failed to truncate file:%s, errno:%d", path, terrno); return; } if (taosUnLockFile(pFile) != 0) { - tscError("failed to unlock file:%s, errno:%d", path, errno); + tscError("failed to unlock file:%s, errno:%d", path, terrno); return; } if (taosCloseFile(&(pFile)) != 0) { @@ -367,7 +367,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP tscInfo("[monitor] create slow log file:%s", path); pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - tscError("failed to open file:%s since %d", path, errno); + tscError("failed to open file:%s since %d", path, terrno); return; } @@ -549,7 +549,7 @@ static void monitorSendSlowLogAtRunning(int64_t clusterId) { int64_t size = getFileSize(pClient->path); if (size <= pClient->offset) { if (taosFtruncateFile(pClient->pFile, 0) < 0) { - tscError("failed to truncate file:%p code: %d", pClient->pFile, errno); + tscError("failed to truncate file:%p code: %d", pClient->pFile, terrno); } tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile); pClient->offset = 0; @@ -606,7 +606,7 @@ static void monitorSendAllSlowLogAtQuit() { static void processFileRemoved(SlowLogClient* pClient) { if (taosUnLockFile(pClient->pFile) != 0) { - tscError("failed to unlock file:%s since %d", pClient->path, errno); + tscError("failed to unlock file:%s since %d", pClient->path, terrno); return; } (void)taosCloseFile(&(pClient->pFile)); @@ -614,7 +614,7 @@ static void processFileRemoved(SlowLogClient* pClient) { TdFilePtr pFile = taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - tscError("failed to open file:%s since %d", pClient->path, errno); + tscError("failed to open file:%s since %d", pClient->path, terrno); } else { pClient->pFile = pFile; } diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 1c06d9206e..d3b3f1f87d 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -128,7 +128,7 @@ int32_t s3CheckCfg() { if (!fp) { (void)fprintf(stderr, "failed to open test file: %s.\n", path); // uError("ERROR: %s Failed to open %s", __func__, path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) { (void)fprintf(stderr, "failed to write test file: %s.\n", path); @@ -136,7 +136,7 @@ int32_t s3CheckCfg() { } if (taosFsyncFile(fp) < 0) { (void)fprintf(stderr, "failed to fsync test file: %s.\n", path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } (void)taosCloseFile(&fp); @@ -988,12 +988,12 @@ int32_t s3PutObjectFromFile2ByEp(const char *file, const char *object_name, int8 if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { uError("ERROR: %s Failed to stat file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { uError("ERROR: %s Failed to open file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = @@ -1065,14 +1065,14 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { uError("ERROR: %s Failed to stat file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } contentLength = size; if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { uError("ERROR: %s Failed to open file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) { (void)taosCloseFile(&data.infileFD); @@ -1412,8 +1412,8 @@ static int32_t s3GetObjectToFileByEp(const char *object_name, const char *fileNa TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - uError("[s3] open file error, errno:%d, fileName:%s", TAOS_SYSTEM_ERROR(errno), fileName); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + uError("[s3] open file error, errno:%d, fileName:%s", terrno, fileName); + TAOS_RETURN(terrno); } TS3GetData cbd = {0}; diff --git a/source/common/src/cos_cp.c b/source/common/src/cos_cp.c index 1caf6a7189..ce5f666f21 100644 --- a/source/common/src/cos_cp.c +++ b/source/common/src/cos_cp.c @@ -10,7 +10,7 @@ int32_t cos_cp_open(char const* cp_path, SCheckpoint* checkpoint) { TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH); if (!fd) { uError("%s Failed to open %s", __func__, cp_path); - TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_RETURN(terrno); } checkpoint->thefile = fd; @@ -162,7 +162,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) { TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ); if (!fd) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t size = -1; @@ -207,7 +207,7 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) { TdFilePtr fp = checkpoint->thefile; if (taosFtruncateFile(fp, 0) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosLSeekFile(fp, 0, SEEK_SET) < 0) { TAOS_CHECK_GOTO(terrno, &lino, _exit); diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index 525e1e0aea..77787db3ce 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -58,7 +58,7 @@ static int32_t generateConfigFile(char* confDir) { TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } #ifdef WINDOWS diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 05a09b9a97..073ba293e2 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -71,13 +71,13 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { } if (taosStatFile(file, NULL, NULL, NULL) < 0) { - dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno))); + dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(terrno)); return 0; } pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -197,7 +197,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -207,7 +207,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index b7bf25c8d3..2f93d51ea2 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -106,7 +106,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); if (taosStatFile(file, NULL, NULL, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code)); code = 0; return code; @@ -114,7 +114,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open vnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -234,7 +234,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 685d70e1ae..982c139c7b 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -203,7 +203,7 @@ int32_t dmReadEps(SDnodeData *pData) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -333,11 +333,11 @@ int32_t dmWriteEps(SDnodeData *pData) { } pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); - if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + if (pFile == NULL) TAOS_CHECK_GOTO(terrno, NULL, _OVER); int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER); - if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER); (void)taosCloseFile(&pFile); TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); @@ -598,7 +598,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP); if (taosStatFile(file, NULL, NULL, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code)); code = 0; goto _OVER; @@ -606,7 +606,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open dnode file:%s since %s", file, terrstr()); goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index c524f4eacf..61a72f2aeb 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -56,7 +56,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -148,7 +148,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -158,7 +158,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -188,7 +188,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) { *pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC); if (*pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open file:%s since %s", filepath, tstrerror(code)); return code; } @@ -199,7 +199,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) { ret = taosLockFile(*pFile); if (ret == 0) break; - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosMsleep(1000); retryTimes++; dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes); @@ -239,7 +239,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -276,7 +276,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -286,7 +286,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -315,7 +315,7 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; encryptError("failed to open dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -455,7 +455,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 04c9093c11..7613282ef8 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -616,7 +616,7 @@ void mndDumpSdb() { char file[] = "sdb.json"; TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = terrno; mError("failed to write %s since %s", file, terrstr()); return; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index e19f57ad46..fd4819dadd 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -234,7 +234,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { taosMemoryFree(pRaw); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mInfo("read sdb file:%s finished since %s", file, tstrerror(code)); return 0; } @@ -386,7 +386,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code)); TAOS_RETURN(code); } @@ -638,8 +638,8 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter int64_t commitTerm = pSdb->commitTerm; int64_t commitConfig = pSdb->commitConfig; if (taosCopyFile(datafile, pIter->name) < 0) { + code = terrno; (void)taosThreadMutexUnlock(&pSdb->filelock); - code = TAOS_SYSTEM_ERROR(errno); mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); @@ -648,7 +648,7 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter pIter->file = taosOpenFile(pIter->name, TD_FILE_READ); if (pIter->file == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); @@ -708,7 +708,7 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) { pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pIter->file == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open %s since %s", pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 3e2d8c026f..ecf838b761 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -111,7 +111,7 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { // save to file pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFD == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } int64_t n = taosWriteFile(pFD, pData, size); @@ -176,7 +176,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { if (pTsdb->fs.pDelFile) { tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } } @@ -190,7 +190,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // head ========= tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -201,7 +201,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // data ========= tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -216,7 +216,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // sma ============= tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -232,7 +232,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -291,7 +291,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { // load binary TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ); if (pFD == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index ea6f10b1bd..f7c50e4260 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -89,7 +89,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (fp == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosWriteFile(fp, data, strlen(data)) < 0) { @@ -97,7 +97,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { } if (taosFsyncFile(fp) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } _exit: @@ -116,7 +116,7 @@ static int32_t load_json(const char *fname, cJSON **json) { TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ); if (fp == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } int64_t size; diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index b0fbc19ec0..c0a1e4b047 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -46,14 +46,14 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { pFD->pFD = taosOpenFile(lc_path, flag); if (pFD->pFD == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } } else { tsdbInfo("no file: %s", path); - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } pFD->s3File = 1; } @@ -73,7 +73,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { // not check file size when reading data files. if (flag != TD_FILE_READ /* && !pFD->s3File*/) { if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 96b752104d..c80e7c651e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -48,7 +48,7 @@ static int32_t tsdbCopyFileWithLimitedSpeed(TdFilePtr from, TdFilePtr to, int64_ int64_t n; int64_t last = taosGetTimestampMs(); if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) { - TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_RETURN(terrno); } remain -= n; @@ -76,14 +76,14 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi fdFrom = taosOpenFile(fname_from, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size); fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config; @@ -91,7 +91,7 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1); if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: @@ -116,14 +116,14 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } TSDB_CHECK_CODE(code, lino, _exit); @@ -429,7 +429,7 @@ static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } char *object_name = taosDirEntryBaseName(fname); @@ -519,7 +519,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int fdFrom = taosOpenFile(fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size); @@ -527,12 +527,12 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); if (n < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: @@ -618,19 +618,19 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64 fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); if (n < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 485499a28f..53d590bfbd 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -181,7 +181,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { // save info to a vnode_tmp.json pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosWriteFile(pFile, data, strlen(data)) < 0) { @@ -189,7 +189,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { } if (taosFsyncFile(pFile) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } _exit: @@ -233,7 +233,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { // read info pFile = taosOpenFile(fname, TD_FILE_READ); if (pFile == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } code = taosFStatFile(pFile, &size, NULL); diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index e1ac42ca8c..edf6c5a814 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -267,7 +267,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ); if (NULL == pFile) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 15350bdfef..8dfc08f26e 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -204,7 +204,7 @@ static FORCE_INLINE int32_t initOpenCacheFile(SGroupCacheFileFd* pFileFd, char* TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE|TD_FILE_AUTO_DEL); //TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE); if (NULL == newFd) { - QRY_ERR_RET(TAOS_SYSTEM_ERROR(errno)); + QRY_ERR_RET(terrno); } pFileFd->fd = newFd; int32_t code = taosThreadMutexInit(&pFileFd->mutex, NULL); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index b17af44260..6ae718c101 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -994,7 +994,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) { TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); if (file == NULL) { - fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(errno)); + fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(terrno)); return TSDB_CODE_FILE_CORRUPTED; } int64_t count = taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize); diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 9412735ded..51ecc67ec9 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -2268,7 +2268,7 @@ static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* } pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM); if (NULL == pStmt->fp) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return parseDataFromFileImpl(pCxt, pStmt, rowsDataCxt); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 62943cb6d5..b084fd8c5d 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11374,7 +11374,7 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt) static int32_t readFromFile(char* pName, int32_t* len, char** buf) { int64_t filesize = 0; if (taosStatFile(pName, &filesize, NULL, NULL) < 0) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } *len = filesize; @@ -11391,7 +11391,7 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY); if (NULL == tfile) { taosMemoryFreeClear(*buf); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } int64_t s = taosReadFile(tfile, *buf, *len); @@ -14070,7 +14070,7 @@ static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFi if (NULL == pModifyStmt->fp) { fp = taosOpenFile(pCreateStmt->filePath, TD_FILE_READ | TD_FILE_STREAM); if (NULL == fp) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _ERR; } } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 993d9d91af..a177db688d 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -290,7 +290,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { pFile = taosOpenFile(path, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _EXIT; } @@ -357,7 +357,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch } if (taosStatFile(src, NULL, NULL, NULL) != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _EXIT; } @@ -1603,7 +1603,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) // compatible with previous version *processId = -1; code = 0; - stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(TAOS_SYSTEM_ERROR(errno))); + stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(terrno)); goto _EXIT; } @@ -1656,7 +1656,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { pFile = taosOpenFile(pDst, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to open file to add extra info, file:%s, reason:%s", pDst, tstrerror(code)); goto _EXIT; } @@ -4940,7 +4940,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { } if (taosCopyFile(srcBuf, dstBuf) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to copy file from %s to %s, reason:%s", srcBuf, dstBuf, tstrerror(code)); goto _ERROR; } @@ -4953,7 +4953,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { TdFilePtr pFile = taosOpenFile(dstDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("chkp failed to create meta file: %s, reason:%s", dstDir, tstrerror(code)); goto _ERROR; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 2b69da6007..4e804f9ca7 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -556,9 +556,9 @@ _NEXT: uint8_t* buf = taosMemoryCalloc(1, sizeof(SStreamSnapBlockHdr) + kBlockSize); int64_t nread = taosPReadFile(pSnapFile->fd, buf + sizeof(SStreamSnapBlockHdr), kBlockSize, pSnapFile->offset); - if (nread == -1) { + if (nread < 0) { taosMemoryFree(buf); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s snap failed to read snap, file name:%s, type:%d,reason:%s", STREAM_STATE_TRANSFER, item->name, item->type, tstrerror(code)); return code; diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index c7811ed093..e8ed73b089 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -150,7 +150,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = terrno ? terrno : TAOS_SYSTEM_ERROR(errno); + code = terrno; TAOS_CHECK_EXIT(code); } @@ -259,7 +259,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; sError("vgId:%d, failed to open sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code)); goto _OVER; } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index a4377858d8..3bb40286bc 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -54,7 +54,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { if (pFile == NULL) { sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr()); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } int64_t size = 0; @@ -127,15 +127,15 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); - if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (pFile == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER); int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); - if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); (void)taosCloseFile(&pFile); - if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); code = 0; sInfo("vgId:%d, succeed to write raft store file:%s, term:%" PRId64, pNode->vgId, realfile, pStore->currentTerm); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 3c144cae23..5f1ae02166 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -63,7 +63,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in if (pFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); *lastVer = retVer; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // ensure size as non-negative @@ -223,8 +223,8 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in lastEntryEndOffset, fileSize); if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) { - wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + wError("failed to truncate file due to %s. file:%s", strerror(terrno), fnameStr); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pFile) < 0) { @@ -315,7 +315,7 @@ static int32_t walRepairLogFileTs(SWal* pWal, bool* updateMeta) { if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) { wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (updateMeta != NULL) *updateMeta = true; @@ -375,7 +375,7 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) { TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); if (pFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize, @@ -462,7 +462,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { if (code < 0) { wError("failed to stat file since %s. file:%s", terrstr(), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (pFileInfo->lastVer >= pFileInfo->firstVer && fileSize == pFileInfo->fileSize) { @@ -545,7 +545,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (taosStatFile(fnameStr, &fileSize, NULL, NULL) < 0 && errno != ENOENT) { wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (fileSize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) { @@ -565,14 +565,14 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (pIdxFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ); if (pLogFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr()); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } // determine the last valid entry end, i.e. offset @@ -619,7 +619,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { wError("vgId:%d, failed to ftruncate file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } } @@ -941,7 +941,7 @@ int32_t walSaveMeta(SWal* pWal) { if (pMetaFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } char* serialized = NULL; diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 73cf6d46ef..aed7db327f 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -175,7 +175,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) { if (pLogFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pReader->pLogFile = pLogFile; @@ -185,7 +185,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) { if (pIdxFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pReader->pIdxFile = pIdxFile; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 43d5c07270..224a7dc711 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -53,7 +53,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); @@ -62,7 +62,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); } @@ -111,20 +111,20 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { char fnameStr[WAL_FILE_LEN]; if (pWal->pLogFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } } if (pWal->pIdxFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } } @@ -141,7 +141,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { if (pIdxTFile == NULL) { pWal->pIdxFile = NULL; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } walBuildLogName(pWal, fileFirstVer, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); @@ -149,7 +149,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { TAOS_UNUSED(taosCloseFile(&pIdxTFile)); pWal->pLogFile = NULL; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pWal->pLogFile = pLogTFile; @@ -200,7 +200,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (pIdxFile == NULL) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } int64_t idxOff = walGetVerIdxOffset(pWal, ver); code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET); @@ -225,7 +225,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // TODO TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET); if (code < 0) { @@ -260,13 +260,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(code); } code = taosFtruncateFile(pIdxFile, idxOff); if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(code); } pWal->vers.lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; @@ -294,21 +294,21 @@ static int32_t walRollImpl(SWal *pWal) { if (pWal->pIdxFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } if (pWal->pLogFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } @@ -319,13 +319,13 @@ static int32_t walRollImpl(SWal *pWal) { walBuildIdxName(pWal, newFileFirstVer, fnameStr); pIdxFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxFile == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } walBuildLogName(pWal, newFileFirstVer, fnameStr); pLogFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); wDebug("vgId:%d, wal create new file for write:%s", pWal->cfg.vgId, fnameStr); if (pLogFile == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } TAOS_CHECK_GOTO(walRollFileInfo(pWal), &lino, _exit); @@ -672,7 +672,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy _exit: // recover in a reverse order if (taosFtruncateFile(pWal->pLogFile, offset) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); wFatal("vgId:%d, failed to recover WAL logfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId, terrstr(), offset); taosMsleep(100); @@ -681,7 +680,6 @@ _exit: int64_t idxOffset = (index - pFileInfo->firstVer) * sizeof(SWalIdxEntry); if (taosFtruncateFile(pWal->pIdxFile, idxOffset) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); wFatal("vgId:%d, failed to recover WAL idxfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId, terrstr(), idxOffset); taosMsleep(100); @@ -700,12 +698,12 @@ static int32_t walInitWriteFile(SWal *pWal) { walBuildIdxName(pWal, fileFirstVer, fnameStr); pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } walBuildLogName(pWal, fileFirstVer, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // switch file pWal->pIdxFile = pIdxTFile; @@ -755,7 +753,7 @@ int32_t walFsync(SWal *pWal, bool forceFsync) { if (taosFsyncFile(pWal->pLogFile) < 0) { wError("vgId:%d, file:%" PRId64 ".log, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal), strerror(errno)); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; } } TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 042be9c71f..a9cd099d54 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -554,7 +554,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { int32_t taosLockFile(TdFilePtr pFile) { if (pFile == NULL || pFile->hFile == NULL) { - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } BOOL fSuccess = FALSE; @@ -568,7 +569,7 @@ int32_t taosLockFile(TdFilePtr pFile) { &overlapped // overlapped structure ); if (!fSuccess) { - return GetLastError(); + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } return 0; } @@ -582,18 +583,20 @@ int32_t taosUnLockFile(TdFilePtr pFile) { fSuccess = UnlockFileEx(pFile->hFile, 0, ~0, ~0, &overlapped); if (!fSuccess) { - return GetLastError(); + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } return 0; } int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { if (pFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } if (pFile->hFile == NULL) { printf("Ftruncate file error, hFile was null\n"); - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } LARGE_INTEGER li_0; @@ -601,7 +604,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { BOOL cur = SetFilePointerEx(pFile->hFile, li_0, NULL, FILE_CURRENT); if (!cur) { printf("SetFilePointerEx Error getting current position in file.\n"); - return -1; + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; } LARGE_INTEGER li_size; @@ -609,7 +613,6 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { BOOL cur2 = SetFilePointerEx(pFile->hFile, li_size, NULL, FILE_BEGIN); if (cur2 == 0) { int error = GetLastError(); - printf("SetFilePointerEx GetLastError is: %d\n", error); switch (error) { case ERROR_INVALID_HANDLE: errno = EBADF; @@ -618,7 +621,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { errno = EIO; break; } - return -1; + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } if (!SetEndOfFile(pFile->hFile)) { @@ -632,23 +636,27 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { errno = EIO; break; } - return -1; + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } return 0; } int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) { if (pFileOut == NULL || pFileIn == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return -1; } if (pFileIn->hFile == NULL || pFileOut->hFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return -1; } LARGE_INTEGER fileOffset; fileOffset.QuadPart = *offset; if (!SetFilePointerEx(pFileIn->hFile, fileOffset, &fileOffset, FILE_BEGIN)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } @@ -659,6 +667,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in DWORD bytesWritten; for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { if (!ReadFile(pFileIn->hFile, buffer, _SEND_FILE_STEP_, &bytesRead, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return writeLen; } @@ -666,12 +675,14 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in return writeLen; } else if (bytesRead < _SEND_FILE_STEP_) { if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { return (int64_t)(writeLen + bytesRead); } } else { if (!WriteFile(pFileOut->hFile, buffer, _SEND_FILE_STEP_, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { writeLen += _SEND_FILE_STEP_; @@ -683,6 +694,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in if (remain > 0) { DWORD bytesRead; if (!ReadFile(pFileIn->hFile, buffer, (DWORD)remain, &bytesRead, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } @@ -691,6 +703,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } else { DWORD bytesWritten; if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { writeLen += bytesWritten; @@ -740,7 +753,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int64_t leftbytes = count; @@ -763,7 +776,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = code; - return terrno; + return -1; } } else if (readbytes == 0) { #if FILE_WITH_LOCK @@ -926,32 +939,12 @@ int32_t taosLockFile(TdFilePtr pFile) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } - -#ifdef WINDOWS - BOOL fSuccess = FALSE; - LARGE_INTEGER fileSize; - OVERLAPPED overlapped = {0}; - - HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd); - - fSuccess = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, - 0, // reserved - ~0, // number of bytes to lock low - ~0, // number of bytes to lock high - &overlapped // overlapped structure - ); - if (!fSuccess) { - return GetLastError(); - } - return 0; -#else int32_t code = (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int32_t taosUnLockFile(TdFilePtr pFile) { @@ -959,25 +952,12 @@ int32_t taosUnLockFile(TdFilePtr pFile) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } - -#ifdef WINDOWS - BOOL fSuccess = FALSE; - OVERLAPPED overlapped = {0}; - HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd); - - fSuccess = UnlockFileEx(hFile, 0, ~0, ~0, &overlapped); - if (!fSuccess) { - return GetLastError(); - } - return 0; -#else int32_t code = (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { @@ -986,104 +966,29 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { return terrno; } -#ifdef WINDOWS - - HANDLE h = (HANDLE)_get_osfhandle(pFile->fd); - - LARGE_INTEGER li_0; - li_0.QuadPart = (int64_t)0; - BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); - if (!cur) { - printf("SetFilePointerEx Error getting current position in file.\n"); - return -1; - } - - LARGE_INTEGER li_size; - li_size.QuadPart = l_size; - BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); - if (cur2 == 0) { - int error = GetLastError(); - printf("SetFilePointerEx GetLastError is: %d\n", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - if (!SetEndOfFile(h)) { - int error = GetLastError(); - printf("SetEndOfFile GetLastError is:%d", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - return 0; -#else int32_t code = ftruncate(pFile->fd, l_size); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) { if (pFileOut == NULL || pFileIn == NULL) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } if (pFileIn->fd < 0 || pFileOut->fd < 0) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } -#ifdef WINDOWS - - _lseeki64(pFileIn->fd, *offset, 0); - int64_t writeLen = 0; - uint8_t buffer[_SEND_FILE_STEP_] = {0}; - - for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { - size_t rlen = _read(pFileIn->fd, (void *)buffer, _SEND_FILE_STEP_); - if (rlen <= 0) { - return writeLen; - } else if (rlen < _SEND_FILE_STEP_) { - write(pFileOut->fd, (void *)buffer, (uint32_t)rlen); - return (int64_t)(writeLen + rlen); - } else { - write(pFileOut->fd, (void *)buffer, _SEND_FILE_STEP_); - writeLen += _SEND_FILE_STEP_; - } +#ifdef _TD_DARWIN_64 + if(lseek(pFileIn->fd, (int32_t)(*offset), 0) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } - - int64_t remain = size - writeLen; - if (remain > 0) { - size_t rlen = _read(pFileIn->fd, (void *)buffer, (size_t)remain); - if (rlen <= 0) { - return writeLen; - } else { - write(pFileOut->fd, (void *)buffer, (uint32_t)remain); - writeLen += remain; - } - } - return writeLen; - -#elif defined(_TD_DARWIN_64) - - lseek(pFileIn->fd, (int32_t)(*offset), 0); int64_t writeLen = 0; uint8_t buffer[_SEND_FILE_STEP_] = {0}; @@ -1112,7 +1017,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } return writeLen; -#else +#else // for linux int64_t leftbytes = size; int64_t sentbytes; @@ -1128,7 +1033,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in continue; } else { terrno = TAOS_SYSTEM_ERROR(errno); - return terrno; + return -1; } } else if (sentbytes == 0) { return (int64_t)(size - leftbytes); @@ -1223,6 +1128,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { if ((*ppFile)->hFile != NULL) { // FlushFileBuffers((*ppFile)->hFile); if (!CloseHandle((*ppFile)->hFile)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); code = -1; } (*ppFile)->hFile = NULL; @@ -1251,7 +1157,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) STUB_RAND_IO_ERR(terrno) if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int32_t code = 0; @@ -1267,7 +1173,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } DWORD ret = 0; @@ -1278,7 +1184,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) SetLastError(0); BOOL result = ReadFile(pFile->hFile, buf, count, &ret, &ol); if (!result && GetLastError() != ERROR_HANDLE_EOF) { - errno = GetLastError(); + code = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); ret = -1; } #else @@ -1291,7 +1197,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int64_t ret = pread(pFile->fd, buf, count, offset); if (-1 == ret) { @@ -1304,10 +1210,10 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) if (code) { terrno = code; - return code; + return -1; } - return ret; + return 0; } int32_t taosFsyncFile(TdFilePtr pFile) { @@ -1333,7 +1239,12 @@ int32_t taosFsyncFile(TdFilePtr pFile) { if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) { return 0; } - return !FlushFileBuffers(pFile->hFile); + bool ret = FlushFileBuffers(pFile->hFile); + if (!ret) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; + } + return 0; } #else if (pFile->fd >= 0) { @@ -1397,7 +1308,9 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { #ifdef WINDOWS size_t bufferSize = 512; *ptrBuf = taosMemoryMalloc(bufferSize); - if (*ptrBuf == NULL) goto END; + if (*ptrBuf == NULL) { + goto END; + } size_t bytesRead = 0; size_t totalBytesRead = 0; @@ -1405,8 +1318,14 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { while (1) { char *result = fgets(*ptrBuf + totalBytesRead, bufferSize - totalBytesRead, pFile->fp); if (result == NULL) { - taosMemoryFreeClear(*ptrBuf); - goto END; + if (feof(pFile->fp)) { + break; + } else { + ret = -1; + terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp)); + taosMemoryFreeClear(*ptrBuf); + goto END; + } } bytesRead = strlen(*ptrBuf + totalBytesRead); totalBytesRead += bytesRead; @@ -1431,7 +1350,7 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { size_t len = 0; ret = getline(ptrBuf, &len, pFile->fp); if (-1 == ret) { - code = TAOS_SYSTEM_ERROR(errno); + terrno = TAOS_SYSTEM_ERROR(errno); } #endif @@ -1441,10 +1360,6 @@ END: (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif - if (code) { - terrno = code; - } - return ret; } @@ -1636,8 +1551,7 @@ int taosSetAutoDelFile(char *path) { if (succ) { return 0; } else { - DWORD error = GetLastError(); - terrno = TAOS_SYSTEM_ERROR(error); + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return terrno; } #else diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 48fe271d33..bcbf09abdc 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -136,7 +136,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) { static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { char fullDir[PATH_MAX] = {0}; if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) { - int32_t code = TAOS_SYSTEM_ERROR(errno); + int32_t code = terrno; uError("failed to expand dir:%s since %s", inputDir, tstrerror(code)); TAOS_RETURN(code); } @@ -1009,7 +1009,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } while (!taosEOFFile(pFile)) { @@ -1066,7 +1066,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { // success when the file does not exist - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; if (errno == ENOENT) { uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code)); TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -1252,7 +1252,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); if (pFile == NULL) { - TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_EXIT(terrno); } size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); if(fileSize <= 0) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 98e17c5db9..bde3d48a6d 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -207,7 +207,7 @@ int32_t taosInitSlowLog() { tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (tsLogObj.slowHandle->pFile == NULL) { (void)printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return 0; @@ -539,7 +539,7 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) { tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE); if (tsLogObj.logHandle->pFile == NULL) { (void)printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } (void)taosLockLogFile(tsLogObj.logHandle->pFile); @@ -973,7 +973,6 @@ void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, vo pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr()); goto _return; } @@ -1029,11 +1028,10 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr if (NULL == *pFd) { int64_t filesize = 0; if (taosStatFile(filepath, &filesize, NULL, NULL) < 0) { - if (ENOENT == errno) { + if (TAOS_SYSTEM_ERROR(ENOENT) == terrno) { return; } - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to stat file:%s since %s", filepath, terrstr()); return; } @@ -1048,7 +1046,6 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr return; } - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr()); return; } diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 265f06cbfd..534da9cd77 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -64,7 +64,7 @@ static int32_t createDiskFile(SDiskbasedBuf* pBuf) { pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); if (pBuf->pFile == NULL) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return TSDB_CODE_SUCCESS; From 37355b8ae110026d6b05b56aa59cb847296bd300 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 10 Sep 2024 17:49:12 +0800 Subject: [PATCH 29/90] fix(test): update test cases. --- tests/script/tsim/stream/sliding.sim | 2 +- tests/system-test/1-insert/database_pre_suf.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/script/tsim/stream/sliding.sim b/tests/script/tsim/stream/sliding.sim index acf68e0286..b0f347fd14 100644 --- a/tests/script/tsim/stream/sliding.sim +++ b/tests/script/tsim/stream/sliding.sim @@ -608,7 +608,7 @@ $loop_count = 0 print step 7 loop4: -sleep 100 +sleep 1000 $loop_count = $loop_count + 1 if $loop_count == 10 then diff --git a/tests/system-test/1-insert/database_pre_suf.py b/tests/system-test/1-insert/database_pre_suf.py index 2bef94081e..29a6e27525 100755 --- a/tests/system-test/1-insert/database_pre_suf.py +++ b/tests/system-test/1-insert/database_pre_suf.py @@ -283,7 +283,8 @@ class TDTestCase: fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) - + + time.sleep(1) tdSql.query("select count(*) from stable_1;") tdSql.checkData(0,0,10*num_random*n) tdSql.query("select count(*) from hn_table_1_r;") @@ -291,6 +292,10 @@ class TDTestCase: # stream data check tdCom.check_stream_task_status(stream_name,vgroups,90) + print("sleep 30s") + time.sleep(30) + + print("check--------------------------------------------------------------------------") tdSql.query("select startts,wend,max_int from stream_max_stable_1 ;") tdSql.checkRows(20) tdSql.query("select sum(max_int) from stream_max_stable_1 ;") From 135f23c8b965e751024b7d8da00a3ecffe18e6f0 Mon Sep 17 00:00:00 2001 From: Jing Sima Date: Tue, 10 Sep 2024 16:29:19 +0800 Subject: [PATCH 30/90] fix:[TD-32000] fix indirect leak caused by using wrong array destroy function. --- source/libs/scalar/src/filter.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index ec48dd50ae..bb3133ea33 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1729,11 +1729,9 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) { return DEAL_RES_IGNORE_CHILD; } - ctx->code = TSDB_CODE_APP_ERROR; - fltError("invalid condition type, type:%d", node->condType); - return DEAL_RES_ERROR; + FLT_ERR_JRET(TSDB_CODE_APP_ERROR); } if (QUERY_NODE_OPERATOR == nType) { From 01bae36e82d59452978487700e463d5155a86428 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Tue, 10 Sep 2024 18:42:00 +0800 Subject: [PATCH 31/90] enh:modify error code passing in libs/ --- source/libs/geometry/src/geomFunc.c | 8 ++-- source/libs/geometry/src/geosWrapper.c | 2 +- source/libs/index/src/index.c | 2 +- source/libs/index/src/indexCache.c | 8 ++-- source/libs/index/src/indexComm.c | 24 ++++++------ source/libs/index/src/indexFilter.c | 8 ++-- source/libs/index/src/indexTfile.c | 8 ++-- source/libs/index/src/indexUtil.c | 2 +- source/libs/nodes/src/nodesCloneFuncs.c | 4 +- source/libs/nodes/src/nodesCodeFuncs.c | 8 ++-- source/libs/nodes/src/nodesMsgFuncs.c | 2 +- source/libs/nodes/src/nodesUtilFuncs.c | 6 +-- source/libs/parser/src/parInsertSml.c | 14 +++---- source/libs/parser/src/parInsertSql.c | 10 ++--- source/libs/parser/src/parInsertStmt.c | 20 +++++----- source/libs/parser/src/parInsertUtil.c | 14 +++---- source/libs/parser/src/parTranslater.c | 50 ++++++++++++------------- source/libs/parser/src/parUtil.c | 4 +- source/libs/parser/src/parser.c | 12 +++--- 19 files changed, 103 insertions(+), 103 deletions(-) diff --git a/source/libs/geometry/src/geomFunc.c b/source/libs/geometry/src/geomFunc.c index 1752493dff..2ce2d92fa7 100644 --- a/source/libs/geometry/src/geomFunc.c +++ b/source/libs/geometry/src/geomFunc.c @@ -43,7 +43,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) { *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -74,7 +74,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { // make a zero ending string inputGeom = taosMemoryCalloc(1, varDataLen(input) + 1); if (inputGeom == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } (void)memcpy(inputGeom, varDataVal(input), varDataLen(input)); @@ -83,7 +83,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) { *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -114,7 +114,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) { size_t size = strlen(outputWKT); *output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (*output == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } diff --git a/source/libs/geometry/src/geosWrapper.c b/source/libs/geometry/src/geosWrapper.c index 5eeea54715..13c5f7208e 100644 --- a/source/libs/geometry/src/geosWrapper.c +++ b/source/libs/geometry/src/geosWrapper.c @@ -96,7 +96,7 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData int32_t code = 0; char *wktPatternWithSpace = taosMemoryCalloc(4, 1024); if (NULL == wktPatternWithSpace) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)sprintf( diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0d834a68cb..b2fd0afd68 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -112,7 +112,7 @@ int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { int code = TSDB_CODE_SUCCESS; SIndex* idx = taosMemoryCalloc(1, sizeof(SIndex)); if (idx == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, END); + TAOS_CHECK_GOTO(terrno, NULL, END); } idx->lru = taosLRUCacheInit(opts->cacheSize, -1, .5); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index a89cc47925..1b31c1e50b 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -137,7 +137,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); if (pCt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCt->colVal = term->colVal; @@ -206,7 +206,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); if (pCt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCt->colVal = term->colVal; @@ -584,7 +584,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // encode data CacheTerm* ct = taosMemoryCalloc(1, sizeof(CacheTerm)); if (ct == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // set up key ct->colType = term->colType; @@ -594,7 +594,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1)); if (ct->colVal == NULL) { taosMemoryFree(ct); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(ct->colVal, term->colVal, term->nColVal); } diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 8dc63ed105..2c681a1df3 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -323,7 +323,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_TIMESTAMP: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int64_t*)src, *dst, -1); tlen = strlen(*dst); @@ -332,7 +332,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UTINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint8_t*)src, *dst, 1); tlen = strlen(*dst); @@ -340,7 +340,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_TINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int8_t*)src, *dst, 1); tlen = strlen(*dst); @@ -348,7 +348,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_SMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int16_t*)src, *dst, -1); tlen = strlen(*dst); @@ -361,7 +361,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_INT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(int32_t*)src, *dst, -1); tlen = strlen(*dst); @@ -369,7 +369,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint32_t*)src, *dst, 1); tlen = strlen(*dst); @@ -377,7 +377,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_BIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%" PRIu64, *(uint64_t*)src); tlen = strlen(*dst); @@ -385,7 +385,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_UBIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)idxInt2str(*(uint64_t*)src, *dst, 1); tlen = strlen(*dst); @@ -393,7 +393,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_FLOAT: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%.9lf", *(float*)src); tlen = strlen(*dst); @@ -401,7 +401,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_DOUBLE: *dst = taosMemoryCalloc(1, bufSize + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(*dst, "%.9lf", *(double*)src); tlen = strlen(*dst); @@ -410,7 +410,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; @@ -422,7 +422,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); if (*dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index 03474c0143..fa59fe23fe 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -197,7 +197,7 @@ static FORCE_INLINE int32_t sifGetValueFromNode(SNode *node, char **value) { } char *tv = taosMemoryCalloc(1, valLen + 1); if (tv == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(tv, pData, valLen); @@ -273,7 +273,7 @@ static int32_t sifInitParamValByCol(SNode *r, SNode *l, SIFParam *param, SIFCtx } char *tv = taosMemoryCalloc(1, valLen + 1); if (tv == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(tv, pData, valLen); @@ -373,7 +373,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam)); if (NULL == paramList) { - SIF_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SIF_ERR_RET(terrno); } if (nodeType(node->pLeft) == QUERY_NODE_OPERATOR && @@ -405,7 +405,7 @@ static int32_t sifInitParamList(SIFParam **params, SNodeList *nodeList, SIFCtx * SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam)); if (tParams == NULL) { indexError("failed to calloc, nodeList: %p", nodeList); - SIF_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SIF_ERR_RET(terrno); } SListCell *cell = nodeList->pHead; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 55a9bb06d9..405e899100 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -201,7 +201,7 @@ int32_t tfileReaderCreate(IFileCtx* ctx, TFileReader** pReader) { int32_t code = 0; TFileReader* reader = taosMemoryCalloc(1, sizeof(TFileReader)); if (reader == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } reader->ctx = ctx; reader->remove = false; @@ -609,7 +609,7 @@ int32_t tfileWriterCreate(IFileCtx* ctx, TFileHeader* header, TFileWriter** pWri int32_t code = 0; TFileWriter* tw = taosMemoryCalloc(1, sizeof(TFileWriter)); if (tw == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; indexError("index: %" PRIu64 " failed to alloc TFilerWriter since %s", header->suid, tstrerror(code)); return code; } @@ -661,7 +661,7 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { int32_t cap = 4 * 1024; char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (size_t i = 0; i < sz; i++) { @@ -1137,7 +1137,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { size_t len = strlen(path) + 1 + strlen(file) + 1; char* buf = taosMemoryCalloc(1, len); if (buf == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } sprintf(buf, "%s/%s", path, file); diff --git a/source/libs/index/src/indexUtil.c b/source/libs/index/src/indexUtil.c index 6a52b7b5a4..aca1ec37fe 100644 --- a/source/libs/index/src/indexUtil.c +++ b/source/libs/index/src/indexUtil.c @@ -44,7 +44,7 @@ int32_t iIntersection(SArray *in, SArray *out) { } MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); if (mi == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < sz; i++) { SArray *t = taosArrayGetP(in, i); diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index e2c5b42e39..b76e4448d3 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -179,7 +179,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { int32_t len = pSrc->node.resType.bytes + 1; pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pDst->datum.p, pSrc->datum.p, len); break; @@ -188,7 +188,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { int32_t len = getJsonValueLen(pSrc->datum.p); pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pDst->datum.p, pSrc->datum.p, len); break; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 1425df5c5a..74879a53af 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -4083,14 +4083,14 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { case TSDB_DATA_TYPE_GEOMETRY: { pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + 1); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } varDataSetLen(pNode->datum.p, pNode->node.resType.bytes - VARSTR_HEADER_SIZE); if (TSDB_DATA_TYPE_NCHAR == pNode->node.resType.type) { char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + VARSTR_HEADER_SIZE + 1); if (NULL == buf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tjsonGetStringValue(pJson, jkValueDatum, buf); @@ -4112,12 +4112,12 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { case TSDB_DATA_TYPE_JSON: { pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } char* buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + 1); if (NULL == buf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tjsonGetStringValue(pJson, jkValueDatum, buf); diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index b3568e914e..e71cfc47f8 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -952,7 +952,7 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) { } pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + 1); if (NULL == pNode->datum.p) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } code = tlvDecodeBinary(pTlv, pNode->datum.p); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 1d6c19346a..d58ee8dbdd 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -120,7 +120,7 @@ static int32_t callocNodeChunk(SNodeAllocator* pAllocator, SNodeMemChunk** pOutC SNodeMemChunk* pNewChunk = taosMemoryCalloc(1, sizeof(SNodeMemChunk) + pAllocator->chunkSize); if (NULL == pNewChunk) { if (pOutChunk) *pOutChunk = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pNewChunk->pBuf = (char*)(pNewChunk + 1); pNewChunk->availableSize = pAllocator->chunkSize; @@ -141,7 +141,7 @@ static int32_t callocNodeChunk(SNodeAllocator* pAllocator, SNodeMemChunk** pOutC static int32_t nodesCallocImpl(int32_t size, void** pOut) { if (NULL == g_pNodeAllocator) { *pOut = taosMemoryCalloc(1, size); - if (!*pOut) return TSDB_CODE_OUT_OF_MEMORY; + if (!*pOut) return terrno; return TSDB_CODE_SUCCESS; } @@ -180,7 +180,7 @@ void nodesFree(void* p) { static int32_t createNodeAllocator(int32_t chunkSize, SNodeAllocator** pAllocator) { *pAllocator = taosMemoryCalloc(1, sizeof(SNodeAllocator)); if (NULL == *pAllocator) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pAllocator)->chunkSize = chunkSize; int32_t code = callocNodeChunk(*pAllocator, NULL); diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index acd1851d76..23025dcab9 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -48,7 +48,7 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* static int32_t smlBoundColumnData(SArray* cols, SBoundColInfo* pBoundInfo, SSchema* pSchema, bool isTag) { bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool)); if (NULL == pUseCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBoundInfo->numOfBound = 0; @@ -139,7 +139,7 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem int32_t output = 0; void* p = taosMemoryCalloc(1, kv->length * TSDB_NCHAR_SIZE); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) { @@ -240,7 +240,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 taosMemoryFree(tmp); } else { uError("SML smlBuildCol out of memory"); - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; } goto end; } @@ -253,7 +253,7 @@ int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32 } char* pUcs4 = taosMemoryCalloc(1, size); if (NULL == pUcs4) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, size, &len)) { @@ -315,7 +315,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pCreateTblReq) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName, pTableMeta->tableInfo.numOfTags, @@ -323,7 +323,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1); if (pCreateTblReq->ctb.stbName == NULL){ - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } (void)memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen); @@ -400,7 +400,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc int32_t len = 0; char* pUcs4 = taosMemoryCalloc(1, pColSchema->bytes - VARSTR_HEADER_SIZE); if (NULL == pUcs4) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) { diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 9412735ded..421fb003f8 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -182,7 +182,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, E bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool)); if (NULL == pUseCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBoundInfo->numOfBound = 0; @@ -768,7 +768,7 @@ static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* p } pStmt->pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pStmt->pCreateTblReq) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } insBuildCreateTbReq(pStmt->pCreateTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid, pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags, @@ -850,7 +850,7 @@ static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) { case TSDB_DATA_TYPE_NCHAR: pValue->datum.p = taosMemoryCalloc(1, pVal->nData + VARSTR_HEADER_SIZE); if (NULL == pValue->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pValue->datum.p, pVal->nData); memcpy(varDataVal(pValue->datum.p), pVal->pData, pVal->nData); @@ -1916,7 +1916,7 @@ static int32_t processCtbAutoCreationAndCtbMeta(SInsertParseContext* pCxt, SVnod pStbRowsCxt->pCreateCtbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (pStbRowsCxt->pCreateCtbReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } if (code == TSDB_CODE_SUCCESS) { insBuildCreateTbReq(pStbRowsCxt->pCreateCtbReq, pStbRowsCxt->ctbName.tname, pStbRowsCxt->pTag, @@ -2325,7 +2325,7 @@ static void destroyStbRowsDataContext(SStbRowsDataContext* pStbRowsCxt) { static int32_t constructStbRowsDataContext(SVnodeModifyOpStmt* pStmt, SStbRowsDataContext** ppStbRowsCxt) { SStbRowsDataContext* pStbRowsCxt = taosMemoryCalloc(1, sizeof(SStbRowsDataContext)); if (!pStbRowsCxt) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tNameAssign(&pStbRowsCxt->stbName, &pStmt->targetTableName); int32_t code = collectUseTable(&pStbRowsCxt->stbName, pStmt->pTableNameHashObj); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 5b459243a4..b67b7fc583 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -32,7 +32,7 @@ typedef struct SKvParam { int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) { *pData = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == *pData) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSubmitTbData* pNew = *pData; @@ -190,7 +190,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch int32_t output = 0; void* p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { @@ -224,7 +224,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch if (NULL == pDataBlock->pData->pCreateTbReq) { pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pDataBlock->pData->pCreateTbReq) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -530,7 +530,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c int32_t output = 0; void* p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { @@ -564,7 +564,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c if (NULL == pDataBlock->pData->pCreateTbReq) { pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pDataBlock->pData->pCreateTbReq) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -593,13 +593,13 @@ static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_ dst->buffer = taosMemoryCalloc(src->num, max_buf_len); if (NULL == dst->buffer) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } dst->length = taosMemoryCalloc(src->num, sizeof(int32_t)); if (NULL == dst->length) { taosMemoryFreeClear(dst->buffer); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } char* src_buf = src->buffer; @@ -865,7 +865,7 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc if (fields) { *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E)); if (NULL == *fields) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSchema* schema = &pSchema[boundColumns[0]]; @@ -972,7 +972,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese *pDst = taosMemoryCalloc(1, sizeof(STableDataCxt)); if (NULL == *pDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STableDataCxt* pNewCxt = (STableDataCxt*)*pDst; @@ -1050,7 +1050,7 @@ int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_ if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) { pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pBlock->pData->pCreateTbReq) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index b0581d2fd3..e77678fb69 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -188,7 +188,7 @@ int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) { pInfo->hasBoundCols = false; pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t)); if (NULL == pInfo->pColIndex) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < numOfBound; ++i) { pInfo->pColIndex[i] = i; @@ -230,7 +230,7 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat STableDataCxt* pTableCxt = taosMemoryCalloc(1, sizeof(STableDataCxt)); if (NULL == pTableCxt) { *pOutput = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -264,7 +264,7 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat if (TSDB_CODE_SUCCESS == code) { pTableCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == pTableCxt->pData) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pTableCxt->pData->flags = (pCreateTbReq != NULL && NULL != *pCreateTbReq) ? SUBMIT_REQ_AUTO_CREATE_TABLE : 0; pTableCxt->pData->flags |= colMode ? SUBMIT_REQ_COLUMN_DATA_FORMAT : 0; @@ -300,7 +300,7 @@ static int32_t rebuildTableData(SSubmitTbData* pSrc, SSubmitTbData** pDst) { int32_t code = TSDB_CODE_SUCCESS; SSubmitTbData* pTmp = taosMemoryCalloc(1, sizeof(SSubmitTbData)); if (NULL == pTmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pTmp->flags = pSrc->flags; pTmp->suid = pSrc->suid; @@ -477,12 +477,12 @@ static int32_t createVgroupDataCxt(STableDataCxt* pTableCxt, SHashObj* pVgroupHa SVgroupDataCxt** pOutput) { SVgroupDataCxt* pVgCxt = taosMemoryCalloc(1, sizeof(SVgroupDataCxt)); if (NULL == pVgCxt) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitReq2)); if (NULL == pVgCxt->pData) { insDestroyVgroupDataCxt(pVgCxt); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgCxt->vgId = pTableCxt->pMeta->vgId; @@ -840,7 +840,7 @@ int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, } SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == dst) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } if (TSDB_CODE_SUCCESS == code) { dst->numOfTables = taosArrayGetSize(src->pData->aSubmitTbData); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index a0b8c13e58..9878ff279c 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2929,7 +2929,7 @@ static int32_t rewriteQueryTimeFunc(STranslateContext* pCxt, int64_t val, SNode* char* pStr = taosMemoryCalloc(1, 20); if (NULL == pStr) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } snprintf(pStr, 20, "%" PRId64 "", val); int32_t code = rewriteFuncToValue(pCxt, &pStr, pNode); @@ -3769,7 +3769,7 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { size_t vgroupNum = taosArrayGetSize(pVgs); *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); if (NULL == *pVgsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pVgsInfo)->numOfVgroups = vgroupNum; for (int32_t i = 0; i < vgroupNum; ++i) { @@ -3798,7 +3798,7 @@ static int32_t dnodeToVgroupsInfo(SArray* pDnodes, SVgroupsInfo** pVgsInfo) { size_t ndnode = taosArrayGetSize(pDnodes); *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * ndnode); if (NULL == *pVgsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pVgsInfo)->numOfVgroups = ndnode; for (int32_t i = 0; i < ndnode; ++i) { @@ -3926,7 +3926,7 @@ static int32_t setSuperTableVgroupList(STranslateContext* pCxt, SName* pName, SR static int32_t setNormalTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { pRealTable->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (NULL == pRealTable->pVgroupList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRealTable->pVgroupList->numOfVgroups = 1; return getTableHashVgroupImpl(pCxt, pName, pRealTable->pVgroupList->vgroups); @@ -4034,7 +4034,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo } SVgroupsInfo* pVgpsInfo = taosMemoryCalloc(1, sizeof(int32_t) + sizeof(SVgroupInfo)); if (!pVgpsInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } pVgpsInfo->numOfVgroups = 1; @@ -6348,7 +6348,7 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* const char* pTbName = taosArrayGetP(pInfo->aTbnames, k); char* pNewTbName = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN + TSDB_TABLE_NAME_LEN + 1); if (!pNewTbName) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } if (NULL == taosArrayPush(pTbNames, &pNewTbName)) { @@ -8682,7 +8682,7 @@ static int32_t createRollupTableMeta(SCreateTableStmt* pStmt, int8_t precision, int32_t numOfField = LIST_LENGTH(pStmt->pCols) + LIST_LENGTH(pStmt->pTags); STableMeta* pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + numOfField * sizeof(SSchema)); if (NULL == pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pMeta->tableType = TSDB_SUPER_TABLE; pMeta->tableInfo.numOfTags = LIST_LENGTH(pStmt->pTags); @@ -9478,7 +9478,7 @@ static int32_t checkCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pS static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { int32_t code = checkCreateSmaIndex(pCxt, pStmt); pStmt->pReq = taosMemoryCalloc(1, sizeof(SMCreateSmaReq)); - if (pStmt->pReq == NULL) code = TSDB_CODE_OUT_OF_MEMORY; + if (pStmt->pReq == NULL) code = terrno; if (TSDB_CODE_SUCCESS == code) { code = buildCreateSmaReq(pCxt, pStmt, pStmt->pReq); } @@ -11388,7 +11388,7 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { *buf = taosMemoryCalloc(1, *len); if (*buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY); @@ -11648,7 +11648,7 @@ static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) { pStmt->pCfg = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); if (NULL == pStmt->pCfg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SName name; @@ -11662,7 +11662,7 @@ static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateD static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTableStmt* pStmt) { pStmt->pDbCfg = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); if (NULL == pStmt->pDbCfg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pDbCfg); if (TSDB_CODE_SUCCESS == code) { @@ -12086,7 +12086,7 @@ static int32_t translateCreateTSMA(STranslateContext* pCxt, SCreateTSMAStmt* pSt SName useTbName = {0}; if (code == TSDB_CODE_SUCCESS) { pStmt->pReq = taosMemoryCalloc(1, sizeof(SMCreateSmaReq)); - if (!pStmt->pReq) return TSDB_CODE_OUT_OF_MEMORY; + if (!pStmt->pReq) return terrno; } if (code == TSDB_CODE_SUCCESS) { code = buildCreateTSMAReq(pCxt, pStmt, pStmt->pReq, &useTbName); @@ -12394,7 +12394,7 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t* *numOfCols = LIST_LENGTH(pProjections); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SNode* pNode; @@ -12426,7 +12426,7 @@ static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema) *numOfCols = 1; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; (*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; @@ -12439,7 +12439,7 @@ static int32_t extractDescribeResultSchema(STableMeta* pMeta, int32_t* numOfCols if (pMeta && useCompress(pMeta->tableType)) *numOfCols = DESCRIBE_RESULT_COLS_COMPRESS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12479,7 +12479,7 @@ static int32_t extractShowCreateDatabaseResultSchema(int32_t* numOfCols, SSchema *numOfCols = 2; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12497,7 +12497,7 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema** *numOfCols = 2; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12515,7 +12515,7 @@ static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** p *numOfCols = SHOW_CREATE_VIEW_RESULT_COLS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12533,7 +12533,7 @@ static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pS *numOfCols = 3; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -12555,7 +12555,7 @@ static int32_t extractCompactDbResultSchema(int32_t* numOfCols, SSchema** pSchem *numOfCols = COMPACT_DB_RESULT_COLS; *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; @@ -13358,7 +13358,7 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFreeClear(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; @@ -14081,7 +14081,7 @@ static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFi { pCreateInfo = taosMemoryCalloc(1, sizeof(SCreateTbInfo)); if (NULL == pCreateInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } @@ -14391,7 +14391,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFreeClear(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = pTbBatch->info; pVgData->pData = buf; @@ -14841,7 +14841,7 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFree(pMsg); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = vg; pVgData->pData = pMsg; @@ -14946,7 +14946,7 @@ static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == pVgData) { taosMemoryFree(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pVgData->vg = *pVg; pVgData->pData = buf; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 250e9385b4..5c4ced7004 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -463,7 +463,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi int32_t valLen = (int32_t)strlen(jsonValue); char* tmp = taosMemoryCalloc(1, valLen * TSDB_NCHAR_SIZE); if (!tmp) { - retCode = TSDB_CODE_OUT_OF_MEMORY; + retCode = terrno; goto end; } val.type = TSDB_DATA_TYPE_NCHAR; @@ -1039,7 +1039,7 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) { *pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema)); if (NULL == *pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pMeta)->uid = pViewMeta->viewId; (*pMeta)->vgId = MNODE_HANDLE; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index b78cd36f0e..35e626872e 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -172,7 +172,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { case TSDB_DATA_TYPE_VARBINARY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes); @@ -182,7 +182,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { case TSDB_DATA_TYPE_GEOMETRY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes); @@ -192,7 +192,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { pVal->node.resType.bytes *= TSDB_NCHAR_SIZE; pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t output = 0; @@ -460,7 +460,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) { case TSDB_DATA_TYPE_VARBINARY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes); @@ -470,7 +470,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) { case TSDB_DATA_TYPE_GEOMETRY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes); @@ -480,7 +480,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) { pVal->node.resType.bytes *= TSDB_NCHAR_SIZE; pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t output = 0; From 37c12b6c3a1106809dc1bbdd8a63ecee03dee58e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 10 Sep 2024 18:55:02 +0800 Subject: [PATCH 32/90] enh: error handling --- source/dnode/vnode/src/inc/tsdb.h | 2 +- source/dnode/vnode/src/tsdb/tsdbCommit2.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFS.c | 6 ++++-- source/dnode/vnode/src/tsdb/tsdbFS2.c | 20 ++++++++----------- source/dnode/vnode/src/tsdb/tsdbFS2.h | 6 +++--- source/dnode/vnode/src/tsdb/tsdbFile2.c | 3 +-- source/dnode/vnode/src/tsdb/tsdbFile2.h | 2 +- source/dnode/vnode/src/tsdb/tsdbIter.c | 3 ++- source/dnode/vnode/src/tsdb/tsdbOpen.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbRead2.c | 2 +- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 3 +-- source/dnode/vnode/src/tsdb/tsdbRetention.c | 8 ++++---- source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c | 13 ++++++------ source/dnode/vnode/src/tsdb/tsdbUpgrade.c | 2 +- source/libs/stream/src/streamBackendRocksdb.c | 4 ++-- source/util/src/tpagedbuf.c | 4 ++-- source/util/src/tworker.c | 6 +++--- 17 files changed, 43 insertions(+), 47 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 59d70889e5..3110d34bad 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -286,7 +286,7 @@ int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *m int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk); // SDelFReader int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb); -int32_t tsdbDelFReaderClose(SDelFReader **ppReader); +void tsdbDelFReaderClose(SDelFReader **ppReader); int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer); int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData); int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index 58ab8bca82..a768716413 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -572,7 +572,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { // begin tasks on file set for (int i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); - TAOS_UNUSED(tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset)); + tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset); if (fset) { code = tsdbTFileSetInitCopy(tsdb, fset, &info->fset); if (code) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index dbd79a1f93..baecace7ea 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -105,8 +105,10 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { code = TSDB_CODE_OUT_OF_MEMORY; TSDB_CHECK_CODE(code, lino, _exit); } - (void)tsdbFSToBinary(pData, pFS); - (void)taosCalcChecksumAppend(0, pData, size); + int32_t tsize = tsdbFSToBinary(pData, pFS); + + code = taosCalcChecksumAppend(0, pData, size); + TSDB_CHECK_CODE(code, lino, _exit); // save to file pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 4ccda58903..3684544f14 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -365,7 +365,7 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) { if (tsS3Enabled && fobj->f->lcn > 1) { char fname1[TSDB_FILENAME_LEN]; - (void)tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1); + tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1); if (!taosCheckExistFile(fname1)) { code = TSDB_CODE_FILE_CORRUPTED; tsdbError("vgId:%d %s failed since file:%s does not exist", TD_VID(fs->tsdb->pVnode), __func__, fname1); @@ -648,10 +648,9 @@ _exit: return code; } -static int32_t close_file_system(STFileSystem *fs) { +static void close_file_system(STFileSystem *fs) { TARRAY2_CLEAR(fs->fSetArr, tsdbTFileSetClear); TARRAY2_CLEAR(fs->fSetArrTmp, tsdbTFileSetClear); - return 0; } static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSet *pSet2) { @@ -800,13 +799,13 @@ void tsdbEnableBgTask(STsdb *pTsdb) { (void)taosThreadMutexUnlock(&pTsdb->mutex); } -int32_t tsdbCloseFS(STFileSystem **fs) { - if (fs[0] == NULL) return 0; +void tsdbCloseFS(STFileSystem **fs) { + if (fs[0] == NULL) return; (void)tsdbDisableAndCancelAllBgTask((*fs)->tsdb); - (void)close_file_system(fs[0]); + close_file_system(fs[0]); destroy_fs(fs); - return 0; + return; } int64_t tsdbFSAllocEid(STFileSystem *fs) { @@ -1026,13 +1025,12 @@ int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fse return code; } -int32_t tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr) { +void tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr) { if (fsetArr[0]) { TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear); taosMemoryFreeClear(fsetArr[0]); fsetArr[0] = NULL; } - return 0; } static SHashObj *tsdbFSetRangeArrayToHash(TFileSetRangeArray *pRanges) { @@ -1174,7 +1172,7 @@ _out: void tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr) { tsdbTFileSetRangeArrayDestroy(fsrArr); } -int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { +void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; tsdbFSGetFSet(tsdb->pFS, fid, fset); @@ -1195,8 +1193,6 @@ int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { } tsdbInfo("vgId:%d begin task on file set:%d", TD_VID(tsdb->pVnode), fid); } - - return 0; } int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.h b/source/dnode/vnode/src/tsdb/tsdbFS2.h index 6de2b8ace0..500a214124 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.h @@ -38,13 +38,13 @@ typedef enum { /* Exposed APIs */ // open/close int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback); -int32_t tsdbCloseFS(STFileSystem **fs); +void tsdbCloseFS(STFileSystem **fs); // snapshot int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fsetArr); -int32_t tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr); +void tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr); int32_t tsdbFSCreateCopyRangedSnapshot(STFileSystem *fs, TFileSetRangeArray *pExclude, TFileSetArray **fsetArr, TFileOpArray *fopArr); @@ -61,7 +61,7 @@ int32_t tsdbFSEditAbort(STFileSystem *fs); // other void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid); -int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); +void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); // utils int32_t save_fs(const TFileSetArray *arr, const char *fname); diff --git a/source/dnode/vnode/src/tsdb/tsdbFile2.c b/source/dnode/vnode/src/tsdb/tsdbFile2.c index d5d222eb56..5c832dccda 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile2.c @@ -399,7 +399,7 @@ void tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]) { } } -int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) { +void tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) { SVnode *pVnode = pTsdb->pVnode; STfs *pTfs = pVnode->pTfs; @@ -428,7 +428,6 @@ int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) { f->lcn, // g_tfile_info[f->type].suffix); } - return 0; } bool tsdbIsSameTFile(const STFile *f1, const STFile *f2) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFile2.h b/source/dnode/vnode/src/tsdb/tsdbFile2.h index 8f80d88ba4..6027064c02 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFile2.h @@ -45,7 +45,7 @@ enum { int32_t tsdbTFileToJson(const STFile *f, cJSON *json); int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f); void tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]); -int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]); +void tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]); bool tsdbIsSameTFile(const STFile *f1, const STFile *f2); bool tsdbIsTFileChanged(const STFile *f1, const STFile *f2); diff --git a/source/dnode/vnode/src/tsdb/tsdbIter.c b/source/dnode/vnode/src/tsdb/tsdbIter.c index 1902a51baf..e4218ea4fc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbIter.c +++ b/source/dnode/vnode/src/tsdb/tsdbIter.c @@ -373,7 +373,8 @@ static int32_t tsdbDataIterOpen(STsdbIter *iter) { iter->dataData->brinBlkArrayIdx = 0; // SBrinBlock - (void)tBrinBlockInit(iter->dataData->brinBlock); + code = tBrinBlockInit(iter->dataData->brinBlock); + if (code) return code; iter->dataData->brinBlockIdx = 0; // SBlockData diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index df507251ed..09d5cdbdb3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -86,7 +86,7 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg * _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, lino, tstrerror(code)); - (void)tsdbCloseFS(&pTsdb->pFS); + tsdbCloseFS(&pTsdb->pFS); (void)taosThreadMutexDestroy(&pTsdb->mutex); taosMemoryFree(pTsdb); } else { @@ -109,7 +109,7 @@ int32_t tsdbClose(STsdb **pTsdb) { (*pTsdb)->mem = NULL; (void)taosThreadMutexUnlock(&(*pTsdb)->mutex); - (void)tsdbCloseFS(&(*pTsdb)->pFS); + tsdbCloseFS(&(*pTsdb)->pFS); tsdbCloseCache(*pTsdb); #ifdef TD_ENTERPRISE (void)tsdbCloseCompMonitor(*pTsdb); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 7813716e9f..8f66df1ffb 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -5967,7 +5967,7 @@ void tsdbUntakeReadSnap2(STsdbReader* pReader, STsdbReadSnap* pSnap, bool proact if (pSnap->pNode) taosMemoryFree(pSnap->pNode); if (pSnap->pINode) taosMemoryFree(pSnap->pINode); - (void) tsdbFSDestroyRefSnapshot(&pSnap->pfSetArray); + tsdbFSDestroyRefSnapshot(&pSnap->pfSetArray); taosMemoryFree(pSnap); } diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 2fd123d8d2..1112dcaaae 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -819,7 +819,7 @@ _exit: return code; } -int32_t tsdbDelFReaderClose(SDelFReader **ppReader) { +void tsdbDelFReaderClose(SDelFReader **ppReader) { int32_t code = 0; SDelFReader *pReader = *ppReader; @@ -832,7 +832,6 @@ int32_t tsdbDelFReaderClose(SDelFReader **ppReader) { } *ppReader = NULL; - return code; } int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 070735f079..2409b390c9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -71,8 +71,8 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi char fname_from[TSDB_FILENAME_LEN]; char fname_to[TSDB_FILENAME_LEN]; - (void)tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from); - (void)tsdbTFileLastChunkName(rtner->tsdb, to, fname_to); + tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from); + tsdbTFileLastChunkName(rtner->tsdb, to, fname_to); fdFrom = taosOpenFile(fname_from, TD_FILE_READ); if (fdFrom == NULL) { @@ -316,7 +316,7 @@ static int32_t tsdbRetention(void *arg) { // begin task (void)taosThreadMutexLock(&pTsdb->mutex); - (void)tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset); + tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset); if (fset && (code = tsdbTFileSetInitCopy(pTsdb, fset, &rtner.fset))) { (void)taosThreadMutexUnlock(&pTsdb->mutex); TSDB_CHECK_CODE(code, lino, _exit); @@ -693,7 +693,7 @@ static int32_t tsdbDoS3Migrate(SRTNer *rtner) { TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, &lino, _exit); } char fname1[TSDB_FILENAME_LEN]; - (void)tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1); + tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1); if (taosCheckExistFile(fname1)) { int32_t mtime = 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c index e2cbf37ae4..f86e548321 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c @@ -18,7 +18,7 @@ #include "tsdbFS2.h" #include "tsdbFSetRAW.h" -static int32_t tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader); +static void tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader); // reader typedef struct SDataFileRAWReaderIter { @@ -65,7 +65,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at line %d since %s, sver:0, ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code), ever, type); - (void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); + tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); taosMemoryFree(reader[0]); reader[0] = NULL; } else { @@ -84,7 +84,7 @@ int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) { STsdb* tsdb = reader[0]->tsdb; TARRAY2_DESTROY(reader[0]->dataReaderArr, tsdbDataFileRAWReaderClose); - (void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); + tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); taosMemoryFree(reader[0]); reader[0] = NULL; @@ -141,15 +141,14 @@ static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) { _exit: if (code) { - (void)tsdbSnapRAWReadFileSetCloseReader(reader); + tsdbSnapRAWReadFileSetCloseReader(reader); TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino); } return code; } -static int32_t tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader) { +static void tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader) { TARRAY2_CLEAR(reader->dataReaderArr, tsdbDataFileRAWReaderClose); - return 0; } static int32_t tsdbSnapRAWReadFileSetOpenIter(STsdbSnapRAWReader* reader) { @@ -262,7 +261,7 @@ _exit: static int32_t tsdbSnapRAWReadEnd(STsdbSnapRAWReader* reader) { (void)tsdbSnapRAWReadFileSetCloseIter(reader); - (void)tsdbSnapRAWReadFileSetCloseReader(reader); + tsdbSnapRAWReadFileSetCloseReader(reader); reader->ctx->fset = NULL; return 0; } diff --git a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c index e492ea0f63..6d95ebad28 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c +++ b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c @@ -568,7 +568,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)tsdbDelFReaderClose(&reader); + tsdbDelFReaderClose(&reader); taosArrayDestroy(aDelIdx); return code; } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index ced62ba82e..8fd36c9ac8 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -904,7 +904,7 @@ _EXIT: streamMutexDestroy(&pHandle->mutex); streamMutexDestroy(&pHandle->cfMutex); taosHashCleanup(pHandle->cfInst); - (void)tdListFree(pHandle->list); + pHandle->list = tdListFree(pHandle->list); taosMemoryFree(pHandle); stDebug("failed to init stream backend at %s", backendPath); taosMemoryFree(backendPath); @@ -937,7 +937,7 @@ void streamBackendCleanup(void* arg) { head = tdListPopHead(pHandle->list); } - (void)tdListFree(pHandle->list); + pHandle->list = tdListFree(pHandle->list); streamMutexDestroy(&pHandle->mutex); streamMutexDestroy(&pHandle->cfMutex); diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 32b9b6e18d..7f2f084b9b 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -663,8 +663,8 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { taosArrayDestroy(pBuf->pIdList); - (void)tdListFree(pBuf->lruList); - (void)tdListFree(pBuf->freePgList); + pBuf->lruList = tdListFree(pBuf->lruList); + pBuf->freePgList = tdListFree(pBuf->freePgList); taosArrayDestroy(pBuf->emptyDummyIdList); taosArrayDestroy(pBuf->pFree); diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index e089f8e6e0..1fc0d16d57 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -887,9 +887,9 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) { taosMemoryFree(pNode); } - (void)tdListFree(pPool->workers); - (void)tdListFree(pPool->backupWorkers); - (void)tdListFree(pPool->exitedWorkers); + pPool->workers = tdListFree(pPool->workers); + pPool->backupWorkers = tdListFree(pPool->backupWorkers); + pPool->exitedWorkers = tdListFree(pPool->exitedWorkers); taosMemoryFree(pPool->pCb); (void)taosThreadMutexDestroy(&pPool->poolLock); From 2fa083c82feb626f4ec261d50f73b8ed0f17192a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 10 Sep 2024 19:03:27 +0800 Subject: [PATCH 33/90] opt transport --- source/libs/transport/src/transCli.c | 1 - source/libs/transport/src/transSvr.c | 16 +++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 803e50ce94..a0c7315fe7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2426,7 +2426,6 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosMemoryFree(timer); } - (void)uv_loop_close(pThrd->loop); taosArrayDestroy(pThrd->timerList); taosMemoryFree(pThrd->loop); taosHashCleanup(pThrd->fqdn2ipCache); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 38c7edeeaf..3a597fe6ad 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -188,11 +188,13 @@ static void sendQuitToWorkThrd(SWorkThrd* pThrd); static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); static int32_t addHandleToAcceptloop(void* arg); -#define SRV_RELEASE_UV(loop) \ - do { \ - (void)uv_walk(loop, uvWalkCb, NULL); \ - (void)uv_run(loop, UV_RUN_DEFAULT); \ - (void)uv_loop_close(loop); \ +#define SRV_RELEASE_UV(loop) \ + do { \ + if (loop && uv_loop_alive(loop)) { \ + (void)uv_walk(loop, uvWalkCb, NULL); \ + (void)uv_run(loop, UV_RUN_DEFAULT); \ + (void)uv_loop_close(loop); \ + } \ } while (0); #define ASYNC_ERR_JRET(thrd) \ @@ -1615,7 +1617,6 @@ void destroyWorkThrdObj(SWorkThrd* pThrd) { } transAsyncPoolDestroy(pThrd->asyncPool); uvWhiteListDestroy(pThrd->pWhiteList); - (void)uv_loop_close(pThrd->loop); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } @@ -1648,14 +1649,11 @@ void transCloseServer(void* arg) { (void)taosThreadJoin(srv->thread, NULL); SRV_RELEASE_UV(srv->loop); - (void)uv_loop_close(srv->loop); - for (int i = 0; i < srv->numOfThreads; i++) { destroyWorkThrd(srv->pThreadObj[i]); } } else { SRV_RELEASE_UV(srv->loop); - (void)uv_loop_close(srv->loop); } taosMemoryFree(srv->pThreadObj); From d403a6129adbd22a4f58fd6352cfcda2d61d58d7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 10 Sep 2024 19:14:27 +0800 Subject: [PATCH 34/90] fix mem leak --- source/libs/transport/src/trans.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 1c783f44fe..fa0be7bcd8 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -103,7 +103,7 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->timeToGetConn = 10 * 1000; } pRpc->notWaitAvaliableConn = pInit->notWaitAvaliableConn; - + pRpc->tcphandle = (*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc); @@ -155,10 +155,13 @@ void* rpcReallocCont(void* ptr, int64_t contLen) { char* st = (char*)ptr - TRANS_MSG_OVERHEAD; int64_t sz = contLen + TRANS_MSG_OVERHEAD; - st = taosMemoryRealloc(st, sz); - if (st == NULL) { + char* nst = taosMemoryRealloc(st, sz); + if (nst == NULL) { + taosMemoryFree(st); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; + } else { + st = nst; } return st + TRANS_MSG_OVERHEAD; @@ -168,7 +171,7 @@ int32_t rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64 return transSendRequest(shandle, pEpSet, pMsg, NULL); } int32_t rpcSendRequestWithCtx(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { - if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0|| pRid == NULL) { + if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0 || pRid == NULL) { return transSendRequest(shandle, pEpSet, pMsg, pCtx); } else { return transSendRequestWithId(shandle, pEpSet, pMsg, pRid); From 1519be0282078696ec10fc3a2f55570d9950e7ac Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 10 Sep 2024 19:19:57 +0800 Subject: [PATCH 35/90] fix mem leak --- source/libs/transport/src/trans.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index fa0be7bcd8..0881f91d69 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -140,6 +140,7 @@ void* rpcMallocCont(int64_t contLen) { char* start = taosMemoryCalloc(1, size); if (start == NULL) { tError("failed to malloc msg, size:%" PRId64, size); + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } else { tTrace("malloc mem:%p size:%" PRId64, start, size); From 79de2c52f4990712314d5764a9cc6e85fb8dc356 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 19:36:20 +0800 Subject: [PATCH 36/90] fix: return length --- source/os/src/osFile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index a9cd099d54..94ead5c129 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -1213,7 +1213,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) return -1; } - return 0; + return ret; } int32_t taosFsyncFile(TdFilePtr pFile) { From 25c0b928854a9ee958e0fb83d2bc82fddf796b1b Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 01:11:56 +0000 Subject: [PATCH 37/90] feat:Optimising the duration and keep --- include/libs/command/command.h | 1 + source/dnode/mnode/impl/src/mndDb.c | 20 +++++--- source/libs/command/src/command.c | 52 ++++++--------------- tests/script/tsim/db/create_all_options.sim | 4 +- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/include/libs/command/command.h b/include/libs/command/command.h index b788b03386..284f54e5ae 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -29,5 +29,6 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); void qExplainFreeCtx(SExplainCtx *pCtx); +int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes); #endif diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 20c5d09c9e..9c02fd6e5d 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -34,6 +34,7 @@ #include "systable.h" #include "thttp.h" #include "tjson.h" +#include "command.h" #define DB_VER_NUMBER 1 #define DB_RESERVE_SIZE 27 @@ -2321,18 +2322,25 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, (void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false); char durationVstr[128] = {0}; - int32_t len = sprintf(&durationVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile); + int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], pDb->cfg.daysPerFile); + varDataSetLen(durationVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); (void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false); - char keepVstr[128] = {0}; + char keepVstr[512] = {0}; + char keep0Str[128] = {0}; + char keep1Str[128] = {0}; + char keep2Str[128] = {0}; + + formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0); + formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1); + formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2); + if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { - len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, - pDb->cfg.daysToKeep0); + len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str); } else { - len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, - pDb->cfg.daysToKeep2); + len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep0Str, keep1Str, keep2Str); } varDataSetLen(keepVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 138782495f..0e5f2f4cbd 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -344,27 +344,18 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) { return TSDB_CACHE_MODEL_NONE_STR; } -static int32_t formatDurationOrKeep(char** buffer, int32_t timeInMinutes) { +int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes) { int len = 0; if (timeInMinutes % 1440 == 0) { int days = timeInMinutes / 1440; - len = snprintf(NULL, 0, "%dd", days); - *buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char)); - if(*buffer == NULL) return terrno; - sprintf(*buffer, "%dd", days); + len = sprintf(buffer, "%dd", days); } else if (timeInMinutes % 60 == 0) { int hours = timeInMinutes / 60; - len = snprintf(NULL, 0, "%dh", hours); - *buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char)); - if(*buffer == NULL) return terrno; - sprintf(*buffer, "%dh", hours); + len = sprintf(buffer, "%dh", hours); } else { - len = snprintf(NULL, 0, "%dm", timeInMinutes); - *buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char)); - if(*buffer == NULL) return terrno; - sprintf(*buffer, "%dm", timeInMinutes); + len = sprintf(buffer, "%dm", timeInMinutes); } - return TSDB_CODE_SUCCESS; + return len; } static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) { @@ -404,25 +395,16 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, } else if (pCfg->hashPrefix < 0) { hashPrefix = pCfg->hashPrefix + dbFNameLen + 1; } - char* durationStr = NULL; - char* keep0Str = NULL; - char* keep1Str = NULL; - char* keep2Str = NULL; - int32_t codeDuration = formatDurationOrKeep(&durationStr, pCfg->daysPerFile); - int32_t codeKeep0 = formatDurationOrKeep(&keep0Str, pCfg->daysToKeep0); - int32_t codeKeep1 = formatDurationOrKeep(&keep1Str, pCfg->daysToKeep1); - int32_t codeKeep2 = formatDurationOrKeep(&keep2Str, pCfg->daysToKeep2); - if(codeDuration != TSDB_CODE_SUCCESS || codeKeep0 != TSDB_CODE_SUCCESS || codeKeep1 != TSDB_CODE_SUCCESS || codeKeep2 != TSDB_CODE_SUCCESS) { - int32_t firstErrorCode = codeDuration != TSDB_CODE_SUCCESS ? codeDuration : - codeKeep0 != TSDB_CODE_SUCCESS ? codeKeep0 : - codeKeep1 != TSDB_CODE_SUCCESS ? codeKeep1 : codeKeep2; - taosMemoryFree(pRetentions); - taosMemoryFree(durationStr); - taosMemoryFree(keep0Str); - taosMemoryFree(keep1Str); - taosMemoryFree(keep2Str); - return firstErrorCode; - } + char durationStr[128] = {0}; + char keep0Str[128] = {0}; + char keep1Str[128] = {0}; + char keep2Str[128] = {0}; + + int32_t lenDuration = formatDurationOrKeep(durationStr, pCfg->daysPerFile); + int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pCfg->daysToKeep0); + int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pCfg->daysToKeep1); + int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pCfg->daysToKeep2); + if (IS_SYS_DBNAME(dbName)) { len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName); } else { @@ -449,10 +431,6 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, } taosMemoryFree(pRetentions); - taosMemoryFree(durationStr); - taosMemoryFree(keep0Str); - taosMemoryFree(keep1Str); - taosMemoryFree(keep2Str); (varDataLen(buf2)) = len; diff --git a/tests/script/tsim/db/create_all_options.sim b/tests/script/tsim/db/create_all_options.sim index e4f29cc74e..e402223d93 100644 --- a/tests/script/tsim/db/create_all_options.sim +++ b/tests/script/tsim/db/create_all_options.sim @@ -92,10 +92,10 @@ endi if $data5_db != on then # strict return -1 endi -if $data6_db != 14400m then # duration +if $data6_db != 10d then # duration return -1 endi -if $data7_db != 5256000m,5256000m,5256000m then # keep +if $data7_db != 3650d,3650d,3650d then # keep return -1 endi if $data8_db != 256 then # buffer From fede52d5b7743ec553d10eaac72af5d694f6568d Mon Sep 17 00:00:00 2001 From: Shungang Li Date: Tue, 10 Sep 2024 17:48:47 +0800 Subject: [PATCH 38/90] enh: (last) rm rwritebatch --- source/dnode/vnode/src/inc/tsdb.h | 1 - source/dnode/vnode/src/tsdb/tsdbCache.c | 31 +++++++++++-------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 59d70889e5..c85c376c47 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -342,7 +342,6 @@ typedef struct { rocksdb_writeoptions_t *writeoptions; rocksdb_readoptions_t *readoptions; rocksdb_writebatch_t *writebatch; - rocksdb_writebatch_t *rwritebatch; STSchema *pTSchema; } SRocksCache; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 3a3e20612e..f4a423bfa7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -214,10 +214,8 @@ static int32_t tsdbOpenRocksCache(STsdb *pTsdb) { } rocksdb_writebatch_t *writebatch = rocksdb_writebatch_create(); - rocksdb_writebatch_t *rwritebatch = rocksdb_writebatch_create(); pTsdb->rCache.writebatch = writebatch; - pTsdb->rCache.rwritebatch = rwritebatch; pTsdb->rCache.my_comparator = cmp; pTsdb->rCache.options = options; pTsdb->rCache.writeoptions = writeoptions; @@ -248,7 +246,6 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) { rocksdb_close(pTsdb->rCache.db); rocksdb_flushoptions_destroy(pTsdb->rCache.flushoptions); rocksdb_writebatch_destroy(pTsdb->rCache.writebatch); - rocksdb_writebatch_destroy(pTsdb->rCache.rwritebatch); rocksdb_readoptions_destroy(pTsdb->rCache.readoptions); rocksdb_writeoptions_destroy(pTsdb->rCache.writeoptions); rocksdb_options_destroy(pTsdb->rCache.options); @@ -258,8 +255,8 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) { taosMemoryFree(pTsdb->rCache.pTSchema); } -static void rocksMayWrite(STsdb *pTsdb, bool force, bool read) { - rocksdb_writebatch_t *wb = read ? pTsdb->rCache.rwritebatch : pTsdb->rCache.writebatch; +static void rocksMayWrite(STsdb *pTsdb, bool force) { + rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; int count = rocksdb_writebatch_count(wb); if ((force && count > 0) || count >= ROCKS_BATCH_SIZE) { @@ -516,8 +513,7 @@ int32_t tsdbCacheCommit(STsdb *pTsdb) { taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState); - rocksMayWrite(pTsdb, true, false); - rocksMayWrite(pTsdb, true, true); + rocksMayWrite(pTsdb, true); rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -667,8 +663,7 @@ int32_t tsdbCacheCommitNoLock(STsdb *pTsdb) { taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState); - rocksMayWrite(pTsdb, true, false); - rocksMayWrite(pTsdb, true, true); + rocksMayWrite(pTsdb, true); rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err); if (NULL != err) { @@ -862,7 +857,7 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra taosMemoryFree(pTSchema); } - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -903,7 +898,7 @@ int32_t tsdbCacheDropSubTables(STsdb *pTsdb, SArray *uids, tb_uid_t suid) { taosMemoryFree(pTSchema); - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -934,7 +929,7 @@ int32_t tsdbCacheDropNTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, bool h (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -973,7 +968,7 @@ int32_t tsdbCacheDropSTableColumn(STsdb *pTsdb, SArray *uids, int16_t cid, bool (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); } - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -1243,7 +1238,7 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray taosMemoryFreeClear(pToFree); } - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); taosMemoryFree(keys_list); taosMemoryFree(keys_list_sizes); @@ -1582,7 +1577,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr } // store result back to rocks cache - wb = pTsdb->rCache.rwritebatch; + wb = pTsdb->rCache.writebatch; char *value = NULL; size_t vlen = 0; code = tsdbCacheSerialize(pLastCol, &value, &vlen); @@ -1597,7 +1592,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr } if (wb) { - rocksMayWrite(pTsdb, false, true); + rocksMayWrite(pTsdb, false); } _exit: @@ -1797,6 +1792,8 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache if (remainCols && TARRAY_SIZE(remainCols) > 0) { (void)taosThreadMutexLock(&pTsdb->lruMutex); + rocksMayWrite(pTsdb, false); + for (int i = 0; i < TARRAY_SIZE(remainCols);) { SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[i]; LRUHandle *h = taosLRUCacheLookup(pCache, &idxKey->key, ROCKS_KEY_LEN); @@ -1944,7 +1941,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE taosMemoryFreeClear(pLastCol); } - rocksMayWrite(pTsdb, true, false); + rocksMayWrite(pTsdb, true); _exit: (void)taosThreadMutexUnlock(&pTsdb->lruMutex); From cffa2a496ced1d33c425f36ea5a7577b101cbca9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 09:37:09 +0800 Subject: [PATCH 39/90] fix mem leak --- source/libs/transport/src/transSvr.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 3a597fe6ad..48042b84c1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -188,13 +188,11 @@ static void sendQuitToWorkThrd(SWorkThrd* pThrd); static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); static int32_t addHandleToAcceptloop(void* arg); -#define SRV_RELEASE_UV(loop) \ - do { \ - if (loop && uv_loop_alive(loop)) { \ - (void)uv_walk(loop, uvWalkCb, NULL); \ - (void)uv_run(loop, UV_RUN_DEFAULT); \ - (void)uv_loop_close(loop); \ - } \ +#define SRV_RELEASE_UV(loop) \ + do { \ + (void)uv_walk(loop, uvWalkCb, NULL); \ + (void)uv_run(loop, UV_RUN_DEFAULT); \ + (void)uv_loop_close(loop); \ } while (0); #define ASYNC_ERR_JRET(thrd) \ From 7d5ef92bb22ac2061b53fb8638f8982fd9a3c7e6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 11 Sep 2024 09:42:59 +0800 Subject: [PATCH 40/90] fix: block data shrink issue --- source/common/src/tdatablock.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 6e4162268d..dee9ec2c0c 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -3397,11 +3397,15 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) { } void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { + return; + if (NULL == pDataBlock || pDataBlock->info.rows == 0) { return; } - ASSERT(pDataBlock->info.rows > 0); +#define BLOCK_DATA_CHECK_TRESSA(o) ; + + BLOCK_DATA_CHECK_TRESSA(pDataBlock->info.rows > 0); if (!pDataBlock->info.dataLoad && !forceChk) { return; @@ -3419,35 +3423,35 @@ void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { checkRows = pDataBlock->info.rows; if (isVarType) { - ASSERT(pCol->varmeta.offset); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset); } else { - ASSERT(pCol->nullbitmap); + BLOCK_DATA_CHECK_TRESSA(pCol->nullbitmap); } nextPos = 0; for (int64_t r = 0; r < checkRows; ++r) { if (!colDataIsNull_s(pCol, r)) { - ASSERT(pCol->pData); - ASSERT(pCol->varmeta.length <= pCol->varmeta.allocLen); + BLOCK_DATA_CHECK_TRESSA(pCol->pData); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.length <= pCol->varmeta.allocLen); if (isVarType) { - ASSERT(pCol->varmeta.allocLen > 0); - ASSERT(pCol->varmeta.offset[r] < pCol->varmeta.length); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.allocLen > 0); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] < pCol->varmeta.length); if (pCol->reassigned) { - ASSERT(pCol->varmeta.offset[r] >= 0); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] >= 0); } else { - ASSERT(pCol->varmeta.offset[r] == nextPos); + BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] == nextPos); } colLen = varDataTLen(pCol->pData + pCol->varmeta.offset[r]); - ASSERT(colLen >= VARSTR_HEADER_SIZE); - ASSERT(colLen <= pCol->info.bytes); + BLOCK_DATA_CHECK_TRESSA(colLen >= VARSTR_HEADER_SIZE); + BLOCK_DATA_CHECK_TRESSA(colLen <= pCol->info.bytes); if (pCol->reassigned) { - ASSERT((pCol->varmeta.offset[r] + colLen) <= pCol->varmeta.length); + BLOCK_DATA_CHECK_TRESSA((pCol->varmeta.offset[r] + colLen) <= pCol->varmeta.length); } else { nextPos += colLen; - ASSERT(nextPos <= pCol->varmeta.length); + BLOCK_DATA_CHECK_TRESSA(nextPos <= pCol->varmeta.length); } typeValue = *(char*)(pCol->pData + pCol->varmeta.offset[r] + colLen - 1); From 6cbb0cf17228b14a37163f30dbc0436f902f2399 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 09:58:41 +0800 Subject: [PATCH 41/90] enh:modify error code passing libs/ --- source/libs/planner/src/planLogicCreater.c | 2 +- source/libs/planner/src/planOptimizer.c | 12 ++-- source/libs/planner/src/planScaleOut.c | 2 +- source/libs/qcom/src/queryUtil.c | 2 +- source/libs/qworker/src/qworker.c | 4 +- source/libs/scalar/src/filter.c | 42 +++++++------- source/libs/scalar/src/scalar.c | 11 ++-- source/libs/scalar/src/sclfunc.c | 36 ++++++------ source/libs/scalar/src/sclvector.c | 16 +++--- source/libs/scheduler/src/schJob.c | 2 +- source/libs/scheduler/src/schRemote.c | 30 +++++----- source/libs/scheduler/src/schTask.c | 2 +- source/libs/stream/src/streamBackendRocksdb.c | 56 +++++++++---------- source/libs/stream/src/streamCheckpoint.c | 6 +- source/libs/stream/src/streamDispatch.c | 2 +- source/libs/stream/src/streamHb.c | 2 +- source/libs/stream/src/streamMeta.c | 6 +- source/libs/stream/src/streamQueue.c | 4 +- source/libs/stream/src/streamSnapshot.c | 6 +- source/libs/stream/src/streamStartHistory.c | 2 +- source/libs/stream/src/streamState.c | 2 +- source/libs/stream/src/streamTask.c | 6 +- source/libs/stream/src/streamTaskSm.c | 2 +- source/libs/stream/src/streamUpdate.c | 6 +- source/libs/stream/src/tstreamFileState.c | 2 +- 25 files changed, 130 insertions(+), 133 deletions(-) diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 3d13ad4c62..6886260d0a 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -202,7 +202,7 @@ static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ES if (NULL != pRewriteExprs) { cxt.pOutputs = taosMemoryCalloc(LIST_LENGTH(pExprs), sizeof(bool)); if (NULL == cxt.pOutputs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt); diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 988440227b..1296986e7f 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -2883,7 +2883,7 @@ static int32_t smaIndexOptCreateSmaScan(SScanLogicNode* pScan, STableIndexInfo* pSmaScan->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (!pSmaScan->pVgroupList) { nodesDestroyNode((SNode*)pSmaScan); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = nodesCloneList(pCols, &pSmaScan->node.pTargets); if (NULL == pSmaScan->node.pTargets) { @@ -4297,7 +4297,7 @@ static void lastRowScanOptRemoveUslessTargets(SNodeList* pTargets, SNodeList* pL static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pColNode, int32_t funcType) { SFunctParam* pFuncTypeParam = taosMemoryCalloc(1, sizeof(SFunctParam)); if (NULL == pFuncTypeParam) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pFuncTypeParam->type = funcType; if (NULL == pScan->pFuncTypes) { @@ -4311,7 +4311,7 @@ static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pCo pFuncTypeParam->pCol = taosMemoryCalloc(1, sizeof(SColumn)); if (NULL == pFuncTypeParam->pCol) { taosMemoryFree(pFuncTypeParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pFuncTypeParam->pCol->colId = pColNode->colId; strcpy(pFuncTypeParam->pCol->name, pColNode->colName); @@ -6671,7 +6671,7 @@ static int32_t fillTSMAOptCtx(STSMAOptCtx* pTsmaOptCtx, SScanLogicNode* pScan) { if (nodeType(pTsmaOptCtx->pParent) == QUERY_NODE_LOGIC_PLAN_WINDOW) { pTsmaOptCtx->queryInterval = taosMemoryCalloc(1, sizeof(SInterval)); - if (!pTsmaOptCtx->queryInterval) return TSDB_CODE_OUT_OF_MEMORY; + if (!pTsmaOptCtx->queryInterval) return terrno; SWindowLogicNode* pWindow = (SWindowLogicNode*)pTsmaOptCtx->pParent; pTsmaOptCtx->queryInterval->interval = pWindow->interval; @@ -7076,7 +7076,7 @@ static int32_t tsmaOptRewriteTbname(const STSMAOptCtx* pTsmaOptCtx, SNode** pTbN pValue->node.resType = ((SExprNode*)(*pTbNameNode))->resType; pValue->literal = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN + 1); pValue->datum.p = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN + 1 + VARSTR_HEADER_SIZE); - if (!pValue->literal || !pValue->datum.p) code = TSDB_CODE_OUT_OF_MEMORY; + if (!pValue->literal || !pValue->datum.p) code = terrno; } if (code == TSDB_CODE_SUCCESS) { @@ -7204,7 +7204,7 @@ static int32_t tsmaOptRewriteScan(STSMAOptCtx* pTsmaOptCtx, SScanLogicNode* pNew int32_t len = sizeof(int32_t) + sizeof(SVgroupInfo) * pVgpsInfo->numOfVgroups; pNewScan->pVgroupList = taosMemoryCalloc(1, len); if (!pNewScan->pVgroupList) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } memcpy(pNewScan->pVgroupList, pVgpsInfo, len); diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index bcac7ddd7e..4027056c69 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -47,7 +47,7 @@ static int32_t doSetScanVgroup(SLogicNode* pNode, const SVgroupInfo* pVgroup, bo SScanLogicNode* pScan = (SScanLogicNode*)pNode; pScan->pVgroupList = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); if (NULL == pScan->pVgroupList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pScan->pVgroupList->vgroups, pVgroup, sizeof(SVgroupInfo)); *pFound = true; diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 7c7439eac3..30902269c3 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -623,7 +623,7 @@ int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst) { *pDst = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == *pDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pDst)->flags = pSrc->flags; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 1a9d3e7ba9..9c6ca18d97 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -436,7 +436,7 @@ int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SDeleteRes *pRes output.pData = taosMemoryCalloc(1, len); if (NULL == output.pData) { - QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_RET(terrno); } code = dsGetDataBlock(ctx->sinkHandle, &output); @@ -1324,7 +1324,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const S if (NULL == mgmt) { qError("calloc %d failed", (int32_t)sizeof(SQWorker)); (void)atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); - QW_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_RET(terrno); } mgmt->cfg.maxSchedulerNum = QW_DEFAULT_SCHEDULER_NUMBER; diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index ec48dd50ae..c62833a3f5 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -468,20 +468,20 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { info->unitSize = FILTER_DEFAULT_UNIT_SIZE; info->units = taosMemoryCalloc(info->unitSize, sizeof(SFilterUnit)); if (info->units == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } info->fields[FLD_TYPE_COLUMN].num = 0; info->fields[FLD_TYPE_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; info->fields[FLD_TYPE_COLUMN].fields = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].size, sizeof(SFilterField)); if (info->fields[FLD_TYPE_COLUMN].fields == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } info->fields[FLD_TYPE_VALUE].num = 0; info->fields[FLD_TYPE_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; info->fields[FLD_TYPE_VALUE].fields = taosMemoryCalloc(info->fields[FLD_TYPE_VALUE].size, sizeof(SFilterField)); if (info->fields[FLD_TYPE_VALUE].fields == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; @@ -497,7 +497,7 @@ static FORCE_INLINE int32_t filterNewRange(SFilterRangeCtx *ctx, SFilterRange *r } else { *r = taosMemoryCalloc(1, sizeof(SFilterRangeNode)); if (*r == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -516,7 +516,7 @@ int32_t filterInitRangeCtx(int32_t type, int32_t options, SFilterRangeCtx **ctx) *ctx = taosMemoryCalloc(1, sizeof(SFilterRangeCtx)); if (*ctx == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*ctx)->type = type; (*ctx)->options = options; @@ -961,7 +961,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray *group gp.unitNum = gp1->unitNum + gp2->unitNum; gp.unitIdxs = taosMemoryCalloc(gp.unitNum, sizeof(*gp.unitIdxs)); if (NULL == gp.unitIdxs) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } (void)memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); (void)memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); @@ -1300,7 +1300,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; if (out.columnData == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } out.columnData->info.type = type; out.columnData->info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; // reserved space for simple_copy @@ -1330,7 +1330,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { } else { void *data = taosMemoryCalloc(1, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); // reserved space for simple_copy if (NULL == data) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } (void)memcpy(data, nodesGetValueFromNode(valueNode), tDataTypes[type].bytes); @@ -2203,13 +2203,13 @@ int32_t fltInitValFieldData(SFilterInfo *info) { size_t bufBytes = TMAX(dType->bytes, sizeof(int64_t)); fi->data = taosMemoryCalloc(1, bufBytes); if (fi->data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } assignVal(fi->data, nodesGetValueFromNode(var), dType->bytes, type); } else { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; if (out.columnData == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } out.columnData->info.type = type; out.columnData->info.precision = precision; @@ -2230,7 +2230,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { : TMAX(out.columnData->info.bytes, sizeof(int64_t)); fi->data = taosMemoryCalloc(1, bufBytes); if (fi->data== NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } size_t valBytes = IS_VAR_DATA_TYPE(type) ? varDataTLen(out.columnData->pData) : out.columnData->info.bytes; @@ -2446,7 +2446,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gRes[gResIdx] = taosMemoryCalloc(1, sizeof(SFilterGroupCtx)); if (gRes[gResIdx] == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); if (gRes[gResIdx]->colInfo == NULL) { @@ -2876,7 +2876,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray *group) { info->groups = taosMemoryCalloc(info->groupNum, sizeof(*info->groups)); if (info->groups == NULL) { info->groupNum = 0; - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -2888,7 +2888,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray *group) { pg->unitFlags = taosMemoryCalloc(pg->unitNum, sizeof(*pg->unitFlags)); if (pg->unitFlags == NULL) { pg->unitNum = 0; - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } info->groups[i] = *pg; } @@ -3005,7 +3005,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_ int32_t code = TSDB_CODE_SUCCESS; uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); if (idxNum == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } for (int32_t i = 0; i < gResNum; ++i) { for (uint32_t m = 0; m < gRes[i]->colNum; ++m) { @@ -3031,7 +3031,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_ if (idxs == NULL) { idxs = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxs)); if (idxs == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } } @@ -3044,7 +3044,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_ info->colRange = taosMemoryCalloc(colNum, POINTER_BYTES); if (info->colRange == NULL) { info->colRangeNum = 0; - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } for (int32_t i = 0; i < gResNum; ++i) { @@ -3584,7 +3584,7 @@ int32_t filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *p (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)) { char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); if (newColData == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); if (len < 0) { @@ -3659,7 +3659,7 @@ int32_t filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)) { char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); if (newColData == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); if (len < 0) { @@ -3740,7 +3740,7 @@ int32_t filterPreprocess(SFilterInfo *info) { int32_t gResNum = 0; SFilterGroupCtx **gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); if (gRes == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } FLT_ERR_JRET(filterMergeGroupUnits(info, gRes, &gResNum)); @@ -5218,7 +5218,7 @@ int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) *pInfo = taosMemoryCalloc(1, sizeof(SFilterInfo)); if (NULL == *pInfo) { fltError("taosMemoryCalloc %d failed", (int32_t)sizeof(SFilterInfo)); - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index b9a95a3216..3b2450906a 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -41,7 +41,6 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode *valueNode) { int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarParam *pParam) { SColumnInfoData *pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); if (pColumnData == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } @@ -99,7 +98,7 @@ int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockL int32_t code = TSDB_CODE_SUCCESS; if (NULL == pLeft) { sclError("calloc %d failed", (int32_t)sizeof(SScalarParam)); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } pLeft->numOfRows = pb->info.rows; @@ -131,7 +130,7 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SListCell *cell = nodeList->pNodeList->pHead; SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; if (out.columnData == NULL) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } int32_t len = 0; void *buf = NULL; @@ -485,7 +484,7 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList *pParamList, SScalarC SScalarParam *paramList = taosMemoryCalloc(*paramNum, sizeof(SScalarParam)); if (NULL == paramList) { sclError("calloc %d failed", (int32_t)((*paramNum) * sizeof(SScalarParam))); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } if (pParamList) { @@ -581,7 +580,7 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal SScalarParam *paramList = taosMemoryCalloc(paramNum, sizeof(SScalarParam)); if (NULL == paramList) { sclError("calloc %d failed", (int32_t)(paramNum * sizeof(SScalarParam))); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } SCL_ERR_JRET(sclSetOperatorValueType(node, ctx)); @@ -608,7 +607,7 @@ int32_t sclGetNodeRes(SNode *node, SScalarCtx *ctx, SScalarParam **res) { int32_t rowNum = 0; *res = taosMemoryCalloc(1, sizeof(**res)); if (NULL == *res) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } SCL_ERR_RET(sclInitParam(node, *res, ctx, &rowNum)); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 5fc7c06d57..4e8107a5b2 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -618,7 +618,7 @@ static int32_t trimHelper(char *orgStr, char* remStr, int32_t orgLen, int32_t re static int32_t convVarcharToNchar(char *input, char **output, int32_t inputLen, int32_t *outputLen) { *output = taosMemoryCalloc(inputLen * TSDB_NCHAR_SIZE, 1); if (NULL == *output) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } bool ret = taosMbsToUcs4(input, inputLen, (TdUcs4 *)*output, inputLen * TSDB_NCHAR_SIZE, outputLen); if (!ret) { @@ -631,7 +631,7 @@ static int32_t convVarcharToNchar(char *input, char **output, int32_t inputLen, static int32_t convNcharToVarchar(char *input, char **output, int32_t inputLen, int32_t *outputLen) { *output = taosMemoryCalloc(inputLen, 1); if (NULL == *output) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *outputLen = taosUcs4ToMbs((TdUcs4 *)input, inputLen, *output); if (*outputLen < 0) { @@ -814,7 +814,7 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar, if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) { TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1); if (NULL == newBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t len = varDataLen(input); bool ret = taosMbsToUcs4(varDataVal(input), len, newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, &len); @@ -853,10 +853,10 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu char *outputBuf = NULL; if (NULL == pInputData) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } if (NULL == input) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } int32_t inputLen = 0; @@ -882,7 +882,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu outputBuf = taosMemoryCalloc(outputLen, 1); if (NULL == outputBuf) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } for (int32_t k = 0; k < numOfRows; ++k) { @@ -928,7 +928,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p char *outputBuf = NULL; if (NULL == pInputData) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } int32_t inputLen = 0; @@ -960,7 +960,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p outputBuf = taosMemoryCalloc(outputLen, 1); if (NULL == outputBuf) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } for (int32_t k = 0; k < numOfRows; ++k) { @@ -1016,7 +1016,7 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala int32_t outputLen = pInputData->varmeta.length; char *outputBuf = taosMemoryCalloc(outputLen, 1); if (outputBuf == NULL) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } char *output = outputBuf; @@ -1070,7 +1070,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar } char *outputBuf = taosMemoryCalloc(outputLen, 1); if (outputBuf == NULL) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } char *output = outputBuf; @@ -1528,7 +1528,7 @@ int32_t replaceFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO char *outputBuf = taosMemoryCalloc(outputLen + VARSTR_HEADER_SIZE, 1); if (NULL == outputBuf) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } for (int32_t i = 0; i < numOfRows; ++i) { @@ -1643,7 +1643,7 @@ int32_t substrIdxFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * } char *outputBuf = taosMemoryCalloc(outputLen + VARSTR_HEADER_SIZE, 1); if (NULL == outputBuf) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } for (int32_t k = 0; k < numOfRows; ++k) { @@ -1741,7 +1741,7 @@ int32_t repeatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); char *outputBuf = taosMemoryCalloc(outputLen, 1); if (outputBuf == NULL) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } char *output = outputBuf; @@ -1834,7 +1834,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp char *buf = taosMemoryMalloc(bufSize); if (convBuf == NULL || output == NULL || buf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } @@ -2403,7 +2403,7 @@ int32_t toCharFunction(SScalarParam* pInput, int32_t inputNum, SScalarParam* pOu int32_t code = 0; if (format == NULL || out == NULL) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { if (colDataIsNull_s(pInput[1].columnData, i) || colDataIsNull_s(pInput[0].columnData, i)) { @@ -4230,7 +4230,7 @@ static int32_t getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char * intervals = taosMemoryCalloc(numOfBins, sizeof(double)); if (NULL == intervals) { cJSON_Delete(binDesc); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } if (cJSON_IsNumber(width) && factor == NULL && binType == LINEAR_BIN) { // linear bin process @@ -4295,7 +4295,7 @@ static int32_t getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char * intervals = taosMemoryCalloc(numOfBins, sizeof(double)); if (NULL == intervals) { cJSON_Delete(binDesc); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } cJSON *bin = binDesc->child; if (bin == NULL) { @@ -4327,7 +4327,7 @@ static int32_t getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char * *binNum = numOfBins - 1; *bins = taosMemoryCalloc(numOfBins, sizeof(SHistoFuncBin)); if (NULL == bins) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } for (int32_t i = 0; i < *binNum; ++i) { (*bins)[i].lower = intervals[i] < intervals[i + 1] ? intervals[i] : intervals[i + 1]; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index ead6053505..d8cc620b1e 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -124,7 +124,7 @@ int32_t convertBinaryToDouble(const void *inData, void *outData) { char *tmp = taosMemoryCalloc(1, varDataTLen(inData)); if (tmp == NULL) { *((double *)outData) = 0.; - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } (void)memcpy(tmp, varDataVal(inData), varDataLen(inData)); double ret = taosStr2Double(tmp, NULL); @@ -370,7 +370,7 @@ static FORCE_INLINE int32_t varToVarbinary(char *buf, SScalarParam *pOut, int32_ if (t == NULL) { sclError("Out of memory"); taosMemoryFree(data); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } varDataSetLen(t, size); (void)memcpy(varDataVal(t), data, size); @@ -383,7 +383,7 @@ static FORCE_INLINE int32_t varToVarbinary(char *buf, SScalarParam *pOut, int32_ char *t = taosMemoryCalloc(1, inputLen); if (t == NULL) { sclError("Out of memory"); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } (void)memcpy(t, buf, inputLen); int32_t code = colDataSetVal(pOut->columnData, rowIndex, t, false); @@ -401,7 +401,7 @@ static FORCE_INLINE int32_t varToNchar(char *buf, SScalarParam *pOut, int32_t ro char *t = taosMemoryCalloc(1, outputMaxLen); if (NULL == t) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } int32_t ret = taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t), outputMaxLen - VARSTR_HEADER_SIZE, &len); @@ -424,7 +424,7 @@ static FORCE_INLINE int32_t ncharToVar(char *buf, SScalarParam *pOut, int32_t ro char *t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE); if (NULL == t) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); if (len < 0) { @@ -457,7 +457,7 @@ static FORCE_INLINE int32_t varToGeometry(char *buf, SScalarParam *pOut, int32_t output = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE); if (NULL == output) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } (void)memcpy(output + VARSTR_HEADER_SIZE, t, len); varDataSetLen(output, len); @@ -2155,7 +2155,7 @@ int32_t vectorJsonContains(SScalarParam *pLeft, SScalarParam *pRight, SScalarPar char *pRightData = colDataGetVarData(pRight->columnData, 0); char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); if (NULL == jsonKey) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } (void)memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); for (; i >= 0 && i < pLeft->numOfRows; i += step) { @@ -2189,7 +2189,7 @@ int32_t vectorJsonArrow(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam char *pRightData = colDataGetVarData(pRight->columnData, 0); char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); if (NULL == jsonKey) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } (void)memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); for (; i >= 0 && i < pLeft->numOfRows; i += step) { diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 8e2fbb878d..2dbbdeca44 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -810,7 +810,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); if (NULL == pJob) { qError("qid:0x%" PRIx64 " calloc %d failed", pReq->pDag->queryId, (int32_t)sizeof(SSchJob)); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } pJob->attr.explainMode = pReq->pDag->explainInfo.mode; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index bf88248259..40391cea7e 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -583,7 +583,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam)); if (NULL == param) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchTaskCallbackParam)); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } param->queryId = pJob->queryId; @@ -600,7 +600,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo SSchHbCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchHbCallbackParam)); if (NULL == param) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchHbCallbackParam)); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } param->head.isHbParam = true; @@ -625,7 +625,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam)); if (NULL == param) { qError("calloc SSchTaskCallbackParam failed"); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } param->pTrans = trans->pTrans; @@ -640,7 +640,7 @@ int32_t schGenerateCallBackInfo(SSchJob *pJob, SSchTask *pTask, void *msg, uint3 SMsgSendInfo *msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == msgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } msgSendInfo->paramFreeFp = taosMemoryFree; @@ -797,13 +797,13 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == pMsgSendInfo) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } param = taosMemoryCalloc(1, sizeof(SSchHbCallbackParam)); if (NULL == param) { SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchHbCallbackParam)); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } int32_t msgType = TDMT_SCH_QUERY_HEARTBEAT_RSP; @@ -927,7 +927,7 @@ int32_t schCloneSMsgSendInfo(void *src, void **dst) { SMsgSendInfo *pDst = taosMemoryCalloc(1, sizeof(*pSrc)); if (NULL == pDst) { qError("malloc SMsgSendInfo for rpcCtx failed, len:%d", (int32_t)sizeof(*pSrc)); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } TAOS_MEMCPY(pDst, pSrc, sizeof(*pSrc)); @@ -1059,7 +1059,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction) { void *msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { qError("calloc hb req %d failed", msgSize); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) { @@ -1116,7 +1116,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } TAOS_MEMCPY(msg, pTask->msg, msgSize); @@ -1142,7 +1142,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } msgSize = tSerializeSVDeleteReq(msg, msgSize, &req); @@ -1190,7 +1190,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (tSerializeSSubQueryMsg(msg, msgSize, &qMsg) < 0) { @@ -1228,7 +1228,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (tSerializeSResFetchReq(msg, msgSize, &req) < 0) { @@ -1256,7 +1256,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (tSerializeSTaskDropReq(msg, msgSize, &qMsg) < 0) { @@ -1283,7 +1283,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_JOB_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) { SCH_JOB_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize); @@ -1314,7 +1314,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, msg = taosMemoryCalloc(1, msgSize); if (NULL == msg) { SCH_TASK_ELOG("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (tSerializeSTaskNotifyReq(msg, msgSize, &qMsg) < 0) { diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index 59b8954a48..9ba2c7ea5c 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -1237,7 +1237,7 @@ _return: int32_t schAsyncLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) { SSchTaskCtx *param = taosMemoryCalloc(1, sizeof(SSchTaskCtx)); if (NULL == param) { - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } param->jobRid = pJob->refId; diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index ced62ba82e..845dabcf11 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -213,7 +213,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) { char* state = taosMemoryCalloc(1, cap); if (state == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = snprintf(state, cap, "%s%s%s", path, TD_DIRSEP, "state"); @@ -226,7 +226,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) { char* chkp = taosMemoryCalloc(1, cap); if (chkp == NULL) { taosMemoryFree(state); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = snprintf(chkp, cap, "%s%s%s%scheckpoint%" PRId64 "", path, TD_DIRSEP, "checkpoints", TD_DIRSEP, chkpId); @@ -279,7 +279,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { char* metaPath = taosMemoryCalloc(1, cap); if (metaPath == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t n = snprintf(metaPath, cap, "%s%s%s", path, TD_DIRSEP, "META"); @@ -302,7 +302,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { SSChkpMetaOnS3* p = taosMemoryCalloc(1, sizeof(SSChkpMetaOnS3)); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } n = sscanf(buf, META_ON_S3_FORMATE, p->pCurrName, &p->currChkptId, p->pManifestName, &p->manifestChkptId, @@ -334,7 +334,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch char* src = taosMemoryCalloc(1, cap); char* dst = taosMemoryCalloc(1, cap); if (src == NULL || dst == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } @@ -400,7 +400,7 @@ int32_t remoteChkpGetDelFile(char* path, SArray* toDel) { char* p = taosMemoryCalloc(1, cap); if (p == NULL) { taosMemoryFree(pMeta); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = snprintf(p, cap, "%s_%" PRId64 "", key, pMeta->currChkptId); @@ -494,7 +494,7 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId char* defaultTmp = taosMemoryCalloc(1, cap); if (defaultTmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t nBytes = snprintf(defaultPath, cap, "%s%s", defaultPath, "_tmp"); @@ -592,8 +592,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { if (srcName == NULL || dstName == NULL) { taosMemoryFree(srcName); taosMemoryFree(dstName); - code = TSDB_CODE_OUT_OF_MEMORY; - return code; + return terrno; } // copy file to dst @@ -711,7 +710,7 @@ int32_t restoreCheckpointData(const char* path, const char* key, int64_t chkptId checkpointPath = taosMemoryCalloc(1, cap); checkpointRoot = taosMemoryCalloc(1, cap); if (prefixPath == NULL || defaultPath == NULL || checkpointPath == NULL || checkpointRoot == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } @@ -1343,7 +1342,7 @@ int32_t chkpGetAllDbCfHandle2(STaskDbWrapper* pBackend, rocksdb_column_family_ha rocksdb_column_family_handle_t** ppCf = taosMemoryCalloc(nCf, sizeof(rocksdb_column_family_handle_t*)); if (ppCf == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } for (int i = 0; i < nCf; i++) { ppCf[i] = taosArrayGetP(pHandle, i); @@ -1410,7 +1409,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI char* pChkpDir = taosMemoryCalloc(1, cap); char* pChkpIdDir = taosMemoryCalloc(1, cap); if (pChkpDir == NULL || pChkpIdDir == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } @@ -1587,7 +1586,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) int32_t cap = len + 64; char* pDst = taosMemoryCalloc(1, cap); if (pDst == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; stError("failed to alloc memory to load extra info, dir:%s", pChkpIdDir); goto _EXIT; } @@ -1643,7 +1642,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { int32_t cap = len + 64; char* pDst = taosMemoryCalloc(1, cap); if (pDst == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; stError("failed to alloc memory to add extra info, dir:%s", pChkpIdDir); goto _EXIT; } @@ -2119,7 +2118,7 @@ int32_t valueEncode(void* value, int32_t vlen, int64_t ttl, char** dest) { if (vlen > 512) { dst = taosMemoryCalloc(1, vlen + 128); if (dst == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t dstCap = vlen + 128; int32_t compressedSize = LZ4_compress_default((char*)value, dst, vlen, dstCap); @@ -2134,7 +2133,7 @@ int32_t valueEncode(void* value, int32_t vlen, int64_t ttl, char** dest) { size_t size = sizeof(key.unixTimestamp) + sizeof(key.len) + sizeof(key.rawLen) + sizeof(key.compress) + key.len; char* p = taosMemoryCalloc(1, size); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } char* buf = p; @@ -2210,7 +2209,7 @@ int32_t valueDecode(void* value, int32_t vlen, int64_t* ttl, char** dest) { } pOutput = taosMemoryCalloc(1, key.rawLen); if (pOutput == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXCEPT; } @@ -2530,7 +2529,7 @@ int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** sta int32_t code = 0; char* statePath = taosMemoryCalloc(1, strlen(path) + 128); if (statePath == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(statePath, "%s%s%s", path, TD_DIRSEP, key); @@ -2547,7 +2546,7 @@ int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** sta char* dbPath = taosMemoryCalloc(1, strlen(statePath) + 128); if (dbPath == NULL) { taosMemoryFree(statePath); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sprintf(dbPath, "%s%s%s", statePath, TD_DIRSEP, "state"); @@ -2765,7 +2764,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { (void)taosReleaseRef(taskDbWrapperId, refId); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = @@ -2795,7 +2794,7 @@ int32_t taskDbGenChkpUploadData__s3(STaskDbWrapper* pDb, void* bkdChkpMgt, int64 char* temp = taosMemoryCalloc(1, cap); if (temp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t nBytes = snprintf(temp, cap, "%s%s%s%" PRId64, pDb->path, TD_DIRSEP, "tmp", chkpId); @@ -4555,7 +4554,7 @@ int32_t compareHashTableImpl(SHashObj* p1, SHashObj* p2, SArray* diff) { if (!isBkdDataMeta(name, len) && !taosHashGet(p1, name, len)) { char* fname = taosMemoryCalloc(1, len + 1); if (fname == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)strncpy(fname, name, len); if (taosArrayPush(diff, &fname) == NULL) { @@ -4716,7 +4715,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { char* fname = taosMemoryCalloc(1, len + 1); if (fname == NULL) { (void)taosThreadRwlockUnlock(&p->rwLock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)strncpy(fname, name, len); @@ -4767,7 +4766,7 @@ int32_t dbChkpCreate(char* path, int64_t initChkpId, SDbChkp** ppChkp) { int32_t code = 0; SDbChkp* p = taosMemoryCalloc(1, sizeof(SDbChkp)); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } @@ -4784,7 +4783,7 @@ int32_t dbChkpCreate(char* path, int64_t initChkpId, SDbChkp** ppChkp) { p->len = strlen(path) + 128; p->buf = taosMemoryCalloc(1, p->len); if (p->buf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } @@ -4861,7 +4860,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { char* buffer = taosMemoryCalloc(4, cap); if (buffer == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } @@ -5026,8 +5025,7 @@ int32_t bkdMgtCreate(char* path, SBkdMgt** mgt) { int32_t code = 0; SBkdMgt* p = taosMemoryCalloc(1, sizeof(SBkdMgt)); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - return code; + return terrno; } p->pDbChkpTbl = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); @@ -5081,7 +5079,7 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, char* path = taosMemoryCalloc(1, cap); if (path == NULL) { (void)taosThreadRwlockUnlock(&bm->rwLock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t nBytes = snprintf(path, cap, "%s%s%s", bm->path, TD_DIRSEP, taskId); diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 242e12f591..fa2bc65194 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -49,7 +49,7 @@ int32_t createChkptTriggerBlock(SStreamTask* pTask, int32_t checkpointType, int6 SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); if (pBlock == NULL) { taosFreeQitem(pChkpoint); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pBlock->info.type = STREAM_CHECKPOINT; @@ -704,7 +704,7 @@ static int32_t getCheckpointDataMeta(const char* id, const char* path, SArray* l char* filePath = taosMemoryCalloc(1, cap); if (filePath == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t nBytes = snprintf(filePath, cap, "%s%s%s", path, TD_DIRSEP, "META_TMP"); @@ -1296,7 +1296,7 @@ int32_t downloadCheckpointByNameS3(const char* id, const char* fname, const char char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = snprintf(buf, cap, "%s/%s", id, fname); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 4926dcb69d..9bdb2348ae 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -143,7 +143,7 @@ static int32_t buildStreamRetrieveReq(SStreamTask* pTask, const SSDataBlock* pBl int32_t len = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock) + PAYLOAD_PREFIX_LEN; pRetrieve = taosMemoryCalloc(1, len); - if (pRetrieve == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pRetrieve == NULL) return terrno; int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); pRetrieve->useconds = 0; diff --git a/source/libs/stream/src/streamHb.c b/source/libs/stream/src/streamHb.c index 1fd3106cff..4e35cb718c 100644 --- a/source/libs/stream/src/streamHb.c +++ b/source/libs/stream/src/streamHb.c @@ -314,7 +314,7 @@ int32_t createMetaHbInfo(int64_t* pRid, SMetaHbInfo** pRes) { *pRes = NULL; SMetaHbInfo* pInfo = taosMemoryCalloc(1, sizeof(SMetaHbInfo)); if (pInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pInfo->hbTmr = taosTmrStart(streamMetaHbToMnode, META_HB_CHECK_INTERVAL, pRid, streamTimer); diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 36d0086ac6..bc902ccf29 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -357,13 +357,13 @@ int32_t streamMetaOpen(const char* path, void* ahandle, FTaskBuild buildTaskFn, SStreamMeta* pMeta = taosMemoryCalloc(1, sizeof(SStreamMeta)); if (pMeta == NULL) { stError("vgId:%d failed to prepare stream meta, alloc size:%" PRIzu ", out of memory", vgId, sizeof(SStreamMeta)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t len = strlen(path) + 64; char* tpath = taosMemoryCalloc(1, len); if (tpath == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } @@ -630,7 +630,7 @@ int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask) { buf = taosMemoryCalloc(1, len); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pTask->ver < SSTREAM_TASK_SUBTABLE_CHANGED_VER) { diff --git a/source/libs/stream/src/streamQueue.c b/source/libs/stream/src/streamQueue.c index 3765d0f9d3..cfa49fd92e 100644 --- a/source/libs/stream/src/streamQueue.c +++ b/source/libs/stream/src/streamQueue.c @@ -51,7 +51,7 @@ int32_t streamQueueOpen(int64_t cap, SStreamQueue** pQ) { SStreamQueue* pQueue = taosMemoryCalloc(1, sizeof(SStreamQueue)); if (pQueue == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = taosOpenQueue(&pQueue->pQueue); @@ -372,7 +372,7 @@ int32_t streamTaskPutTranstateIntoInputQ(SStreamTask* pTask) { pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); if (pBlock == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 0390422623..68ca60cbf1 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -347,7 +347,7 @@ int32_t streamBackendSnapInitFile(char* metaPath, SStreamTaskSnap* pSnap, SBacke char* path = taosMemoryCalloc(1, cap); if (path == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nBytes = snprintf(path, cap, "%s%s%s%s%s%" PRId64 "", pSnap->dbPrefixPath, TD_DIRSEP, "checkpoints", TD_DIRSEP, @@ -492,7 +492,7 @@ int32_t streamSnapReaderOpen(void* pMeta, int64_t sver, int64_t chkpId, char* pa // impl later SStreamSnapReader* pReader = taosMemoryCalloc(1, sizeof(SStreamSnapReader)); if (pReader == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = streamSnapHandleInit(&pReader->handle, (char*)path, pMeta); @@ -632,7 +632,7 @@ int32_t streamSnapWriterOpen(void* pMeta, int64_t sver, int64_t ever, char* path int32_t code = 0; SStreamSnapWriter* pWriter = taosMemoryCalloc(1, sizeof(SStreamSnapWriter)); if (pWriter == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SStreamSnapHandle* pHandle = &pWriter->handle; diff --git a/source/libs/stream/src/streamStartHistory.c b/source/libs/stream/src/streamStartHistory.c index a8c76d3f52..941b8f5145 100644 --- a/source/libs/stream/src/streamStartHistory.c +++ b/source/libs/stream/src/streamStartHistory.c @@ -432,7 +432,7 @@ int32_t createHTaskLaunchInfo(SStreamMeta* pMeta, STaskId* pTaskId, int64_t hStr SLaunchHTaskInfo** pInfo) { *pInfo = taosMemoryCalloc(1, sizeof(SLaunchHTaskInfo)); if ((*pInfo) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pInfo)->id.streamId = pTaskId->streamId; diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index c6ecaf9c2b..e6754d7bfd 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -483,7 +483,7 @@ int32_t streamStateGetParName(SStreamState* pState, int64_t groupId, void** pVal } *pVal = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN); if (!(*pVal)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 355a586e52..5d6cf39e40 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -111,7 +111,7 @@ int32_t tNewStreamTask(int64_t streamId, int8_t taskLevel, SEpSet* pEpset, bool if (pTask == NULL) { stError("s-task:0x%" PRIx64 " failed malloc new stream task, size:%d, code:%s", streamId, (int32_t)sizeof(SStreamTask), tstrerror(terrno)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTask->ver = SSTREAM_TASK_VER; @@ -489,7 +489,7 @@ int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, i if (pOutputInfo->pTokenBucket == NULL) { stError("s-task:%s failed to prepare the tokenBucket, code:%s", pTask->id.idStr, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // 2MiB per second for sink task @@ -1196,7 +1196,7 @@ void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t c int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) { SActiveCheckpointInfo* pInfo = taosMemoryCalloc(1, sizeof(SActiveCheckpointInfo)); if (pInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = taosThreadMutexInit(&pInfo->lock, NULL); diff --git a/source/libs/stream/src/streamTaskSm.c b/source/libs/stream/src/streamTaskSm.c index 968a737ec7..c4ab48827c 100644 --- a/source/libs/stream/src/streamTaskSm.c +++ b/source/libs/stream/src/streamTaskSm.c @@ -286,7 +286,7 @@ int32_t streamCreateStateMachine(SStreamTask* pTask) { if (pSM == NULL) { stError("s-task:%s failed to create task stateMachine, size:%d, code:%s", id, (int32_t)sizeof(SStreamTaskSM), tstrerror(terrno)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pSM->pTask = pTask; diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index 58ed50da65..40de393570 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -150,7 +150,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b int32_t lino = 0; SUpdateInfo* pInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); if (pInfo == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pInfo->pTsBuckets = NULL; @@ -203,12 +203,12 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b pInfo->pkColType = pkType; pInfo->pKeyBuff = taosMemoryCalloc(1, sizeof(TSKEY) + sizeof(int64_t) + pkLen); if (!pInfo->pKeyBuff) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pInfo->pValueBuff = taosMemoryCalloc(1, sizeof(TSKEY) + pkLen); if (!pInfo->pValueBuff) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } if (pkLen != 0) { diff --git a/source/libs/stream/src/tstreamFileState.c b/source/libs/stream/src/tstreamFileState.c index cbaaec0964..aa237efd04 100644 --- a/source/libs/stream/src/tstreamFileState.c +++ b/source/libs/stream/src/tstreamFileState.c @@ -626,7 +626,7 @@ int32_t getRowBuffByPos(SStreamFileState* pFileState, SRowBuffPos* pPos, void** if (pFileState->curRowCount < pFileState->maxRowCount) { pPos->pRowBuff = taosMemoryCalloc(1, pFileState->rowSize); if (!pPos->pRowBuff) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pFileState->curRowCount++; From fdd2bbf5fcd68699f4802607c9a691f9d8455333 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 10:10:17 +0800 Subject: [PATCH 42/90] fix(stream): remove delay rsp for dispatch --- source/libs/stream/src/streamDispatch.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 4926dcb69d..e71f6e748a 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1486,8 +1486,6 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i int32_t numOfFailed = 0; bool triggerDispatchRsp = false; - taosMsleep(500); - // we only set the dispatch msg info for current checkpoint trans streamMutexLock(&pTask->lock); triggerDispatchRsp = (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) && From 6b1e12872f422fedb048acf857d73717d6102af4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 10:19:37 +0800 Subject: [PATCH 43/90] test: update test cases. --- tests/system-test/1-insert/database_pre_suf.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/system-test/1-insert/database_pre_suf.py b/tests/system-test/1-insert/database_pre_suf.py index 29a6e27525..bc266671a6 100755 --- a/tests/system-test/1-insert/database_pre_suf.py +++ b/tests/system-test/1-insert/database_pre_suf.py @@ -284,7 +284,6 @@ class TDTestCase: fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) - time.sleep(1) tdSql.query("select count(*) from stable_1;") tdSql.checkData(0,0,10*num_random*n) tdSql.query("select count(*) from hn_table_1_r;") @@ -292,10 +291,6 @@ class TDTestCase: # stream data check tdCom.check_stream_task_status(stream_name,vgroups,90) - print("sleep 30s") - time.sleep(30) - - print("check--------------------------------------------------------------------------") tdSql.query("select startts,wend,max_int from stream_max_stable_1 ;") tdSql.checkRows(20) tdSql.query("select sum(max_int) from stream_max_stable_1 ;") From 064a2715825e6e815ca5124433bc7f15a789391a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 10:21:38 +0800 Subject: [PATCH 44/90] Update streamDispatch.c --- source/libs/stream/src/streamDispatch.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 4926dcb69d..e71f6e748a 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1486,8 +1486,6 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i int32_t numOfFailed = 0; bool triggerDispatchRsp = false; - taosMsleep(500); - // we only set the dispatch msg info for current checkpoint trans streamMutexLock(&pTask->lock); triggerDispatchRsp = (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) && From 9b3cd3fb8dc023198052b9c45c496bcb5afb8ef8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 11 Sep 2024 10:56:40 +0800 Subject: [PATCH 45/90] enh: error code handle --- source/dnode/vnode/src/inc/tsdb.h | 6 +-- source/dnode/vnode/src/tsdb/tsdbCommit2.c | 4 +- source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c | 4 +- source/dnode/vnode/src/tsdb/tsdbDataFileRW.c | 8 +-- source/dnode/vnode/src/tsdb/tsdbFS2.c | 24 ++++----- source/dnode/vnode/src/tsdb/tsdbFS2.h | 6 +-- source/dnode/vnode/src/tsdb/tsdbFSet2.c | 53 ++++++++++++++----- source/dnode/vnode/src/tsdb/tsdbFile2.c | 4 +- source/dnode/vnode/src/tsdb/tsdbIter.c | 5 +- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 6 ++- source/dnode/vnode/src/tsdb/tsdbMerge.c | 11 ++-- source/dnode/vnode/src/tsdb/tsdbOpen.c | 16 +++--- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 9 ++-- source/dnode/vnode/src/tsdb/tsdbRetention.c | 5 +- source/dnode/vnode/src/tsdb/tsdbSnapInfo.c | 24 +++++++-- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 2 +- source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c | 11 ++-- source/dnode/vnode/src/tsdb/tsdbSttFileRW.c | 6 ++- source/dnode/vnode/src/tsdb/tsdbUpgrade.c | 2 +- source/dnode/vnode/src/tsdb/tsdbUtil.c | 2 +- 20 files changed, 133 insertions(+), 75 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 3110d34bad..7c68d31f84 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -280,7 +280,7 @@ void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t); // tsdbReaderWriter.c ============================================================================================== // SDataFReader int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet); -int32_t tsdbDataFReaderClose(SDataFReader **ppReader); +void tsdbDataFReaderClose(SDataFReader **ppReader); int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx); int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk); int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk); @@ -678,8 +678,8 @@ typedef TARRAY2(STFileSet *) TFileSetArray; typedef struct STFileSetRange STFileSetRange; typedef TARRAY2(STFileSetRange *) TFileSetRangeArray; // disjoint ranges -int32_t tsdbTFileSetRangeClear(STFileSetRange **fsr); -void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr); +void tsdbTFileSetRangeClear(STFileSetRange **fsr); +void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr); // fset partition enum { diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index a768716413..d9d951d591 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -710,7 +710,7 @@ int32_t tsdbCommitCommit(STsdb *tsdb) { for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); if (info->fset) { - TAOS_UNUSED(tsdbFinishTaskOnFileSet(tsdb, info->fid)); + tsdbFinishTaskOnFileSet(tsdb, info->fid); } } @@ -741,7 +741,7 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) { for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i); if (info->fset) { - TAOS_UNUSED(tsdbFinishTaskOnFileSet(pTsdb, info->fid)); + tsdbFinishTaskOnFileSet(pTsdb, info->fid); } } (void)taosThreadMutexUnlock(&pTsdb->mutex); diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c index 842730cb71..4ab9d729b6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c @@ -117,7 +117,7 @@ static int32_t tsdbDataFileRAWWriterCloseAbort(SDataFileRAWWriter *writer) { return 0; } -static int32_t tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return 0; } +static void tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return; } static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) { int32_t code = 0; @@ -200,7 +200,7 @@ int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFil } else { TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit); } - (void)tsdbDataFileRAWWriterDoClose(writer[0]); + tsdbDataFileRAWWriterDoClose(writer[0]); } taosMemoryFree(writer[0]); writer[0] = NULL; diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c index 2d54d33105..e965221920 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c @@ -847,7 +847,7 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr for (int i = 0; i < brinBlock->numOfRecords; i++) { SBrinRecord record; - (void)tBrinBlockGet(brinBlock, i, &record); + TAOS_CHECK_RETURN(tBrinBlockGet(brinBlock, i, &record)); if (i == 0) { brinBlk.minTbid.suid = record.suid; brinBlk.minTbid.uid = record.uid; @@ -1160,7 +1160,8 @@ static int32_t tsdbDataFileDoWriteTableOldData(SDataFileWriter *writer, const ST for (; writer->ctx->brinBlockIdx < writer->ctx->brinBlock->numOfRecords; writer->ctx->brinBlockIdx++) { SBrinRecord record; - (void)tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, &record); + code = tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, &record); + TSDB_CHECK_CODE(code, lino, _exit); if (record.uid != writer->ctx->tbid->uid) { writer->ctx->tbHasOldData = false; goto _exit; @@ -1170,7 +1171,8 @@ static int32_t tsdbDataFileDoWriteTableOldData(SDataFileWriter *writer, const ST goto _exit; } else { SBrinRecord record[1]; - (void)tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, record); + code = tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, record); + TSDB_CHECK_CODE(code, lino, _exit); if (tsdbRowKeyCmprNullAsLargest(key, &record->lastKey) > 0) { // key > record->lastKey if (writer->blockData->nRow > 0) { TAOS_CHECK_GOTO(tsdbDataFileDoWriteBlockData(writer, writer->blockData), &lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 3684544f14..d5dff7d5b7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -747,8 +747,8 @@ _exit: return code; } -static void tsdbFSSetBlockCommit(STFileSet *fset, bool block); -extern int32_t tsdbStopAllCompTask(STsdb *tsdb); +static void tsdbFSSetBlockCommit(STFileSet *fset, bool block); +extern void tsdbStopAllCompTask(STsdb *tsdb); int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { STFileSystem *fs = pTsdb->pFS; @@ -783,12 +783,15 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { // destroy all channels for (int32_t i = 0; i < taosArrayGetSize(channelArray); i++) { SVAChannelID *channel = taosArrayGet(channelArray, i); - (void)vnodeAChannelDestroy(channel, true); + int32_t code = vnodeAChannelDestroy(channel, true); + if (code) { + tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code)); + } } taosArrayDestroy(channelArray); #ifdef TD_ENTERPRISE - (void)tsdbStopAllCompTask(pTsdb); + tsdbStopAllCompTask(pTsdb); #endif return 0; } @@ -802,7 +805,7 @@ void tsdbEnableBgTask(STsdb *pTsdb) { void tsdbCloseFS(STFileSystem **fs) { if (fs[0] == NULL) return; - (void)tsdbDisableAndCancelAllBgTask((*fs)->tsdb); + TAOS_UNUSED(tsdbDisableAndCancelAllBgTask((*fs)->tsdb)); close_file_system(fs[0]); destroy_fs(fs); return; @@ -983,13 +986,12 @@ int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) { return code; } -int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr) { +void tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr) { if (fsetArr[0]) { TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear); taosMemoryFree(fsetArr[0]); fsetArr[0] = NULL; } - return 0; } int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr) { @@ -1101,7 +1103,7 @@ _out: return code; } -int32_t tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr) { return tsdbFSDestroyCopySnapshot(fsetArr); } +void tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr) { tsdbFSDestroyCopySnapshot(fsetArr); } int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges, TFileSetRangeArray **fsrArr) { @@ -1157,7 +1159,7 @@ int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ev (void)taosThreadMutexUnlock(&fs->tsdb->mutex); if (code) { - (void)tsdbTFileSetRangeClear(&fsr1); + tsdbTFileSetRangeClear(&fsr1); TARRAY2_DESTROY(fsrArr[0], tsdbTFileSetRangeClear); fsrArr[0] = NULL; } @@ -1195,7 +1197,7 @@ void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { } } -int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { +void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; if (sttTrigger == 1) { STFileSet *fset = NULL; @@ -1208,6 +1210,4 @@ int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { tsdbInfo("vgId:%d finish task on file set:%d", TD_VID(tsdb->pVnode), fid); } } - - return 0; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.h b/source/dnode/vnode/src/tsdb/tsdbFS2.h index 500a214124..9993c1e33d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.h @@ -41,14 +41,14 @@ int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback); void tsdbCloseFS(STFileSystem **fs); // snapshot int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr); -int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr); +void tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fsetArr); void tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr); int32_t tsdbFSCreateCopyRangedSnapshot(STFileSystem *fs, TFileSetRangeArray *pExclude, TFileSetArray **fsetArr, TFileOpArray *fopArr); -int32_t tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr); +void tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr); int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges, TFileSetRangeArray **fsrArr); void tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr); @@ -62,7 +62,7 @@ int32_t tsdbFSEditAbort(STFileSystem *fs); void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid); void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); -int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); +void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); // utils int32_t save_fs(const TFileSetArray *arr, const char *fname); void current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype); diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index 5a07994678..fc78fec2ea 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -64,9 +64,16 @@ static int32_t tsdbSttLvlInitRef(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lv STFileObj *fobj1; TARRAY2_FOREACH(lvl1->fobjArr, fobj1) { - (void)tsdbTFileObjRef(fobj1); + code = tsdbTFileObjRef(fobj1); + if (code) { + tsdbSttLvlClear(lvl); + return code; + } code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj1); - if (code) return code; + if (code) { + tsdbSttLvlClear(lvl); + return code; + } } return 0; } @@ -99,7 +106,12 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64 return 0; } -static void tsdbSttLvlRemoveFObj(void *data) { (void)tsdbTFileObjRemove(*(STFileObj **)data); } +static void tsdbSttLvlRemoveFObj(void *data) { + int32_t code = tsdbTFileObjRemove(*(STFileObj **)data); + if (code) { + tsdbError("failed to remove file obj, code:%d, error:%s", code, tstrerror(code)); + } +} static void tsdbSttLvlRemove(SSttLvl **lvl) { TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj); taosMemoryFree(lvl[0]); @@ -348,7 +360,8 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) { int32_t idx = TARRAY2_SEARCH_IDX(lvl->fobjArr, &tfobjp, tsdbTFileObjCmpr, TD_EQ); TARRAY2_REMOVE(lvl->fobjArr, idx, tsdbSttLvlClearFObj); } else { - (void)tsdbTFileObjUnref(fset->farr[op->of.type]); + code = tsdbTFileObjUnref(fset->farr[op->of.type]); + if (code) return code; fset->farr[op->of.type] = NULL; } } else { @@ -391,9 +404,11 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f } } else { if (fobj1->f->cid != fobj2->f->cid) { - (void)tsdbTFileObjRemove(fobj2); + code = tsdbTFileObjRemove(fobj2); + if (code) return code; } else { - (void)tsdbTFileObjRemoveUpdateLC(fobj2); + code = tsdbTFileObjRemoveUpdateLC(fobj2); + if (code) return code; } code = tsdbTFileObjInit(pTsdb, fobj1->f, &fset2->farr[ftype]); if (code) return code; @@ -404,7 +419,8 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f if (code) return code; } else { // remove the file - (void)tsdbTFileObjRemove(fobj2); + code = tsdbTFileObjRemove(fobj2); + if (code) return code; fset2->farr[ftype] = NULL; } } @@ -570,7 +586,11 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if (fset1->farr[ftype] == NULL) continue; - (void)tsdbTFileObjRef(fset1->farr[ftype]); + code = tsdbTFileObjRef(fset1->farr[ftype]); + if (code) { + tsdbTFileSetClear(fset); + return code; + } fset[0]->farr[ftype] = fset1->farr[ftype]; } @@ -595,13 +615,13 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs return 0; } -int32_t tsdbTFileSetRangeClear(STFileSetRange **fsr) { - if (!fsr[0]) return 0; +void tsdbTFileSetRangeClear(STFileSetRange **fsr) { + if (!fsr[0]) return; tsdbTFileSetClear(&fsr[0]->fset); taosMemoryFree(fsr[0]); fsr[0] = NULL; - return 0; + return; } void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr) { @@ -616,7 +636,11 @@ void tsdbTFileSetClear(STFileSet **fset) { if (fset && *fset) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if ((*fset)->farr[ftype] == NULL) continue; - (void)tsdbTFileObjUnref((*fset)->farr[ftype]); + int32_t code = tsdbTFileObjUnref((*fset)->farr[ftype]); + if (code) { + tsdbError("failed to unref file, fid:%d, ftype:%d", (*fset)->fid, ftype); + } + (*fset)->farr[ftype] = NULL; } TARRAY2_DESTROY((*fset)->lvlArr, tsdbSttLvlClear); @@ -632,7 +656,10 @@ void tsdbTFileSetRemove(STFileSet *fset) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if (fset->farr[ftype] != NULL) { - (void)tsdbTFileObjRemove(fset->farr[ftype]); + int32_t code = tsdbTFileObjRemove(fset->farr[ftype]); + if (code) { + tsdbError("failed to remove file, fid:%d, ftype:%d", fset->fid, ftype); + } fset->farr[ftype] = NULL; } } diff --git a/source/dnode/vnode/src/tsdb/tsdbFile2.c b/source/dnode/vnode/src/tsdb/tsdbFile2.c index 5c832dccda..da78d67db3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile2.c @@ -249,8 +249,8 @@ int32_t tsdbTFileObjRef(STFileObj *fobj) { (void)taosThreadMutexLock(&fobj->mutex); if (fobj->ref <= 0 || fobj->state != TSDB_FSTATE_LIVE) { - (void)taosThreadMutexUnlock(&fobj->mutex); tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref); + (void)taosThreadMutexUnlock(&fobj->mutex); return TSDB_CODE_FAILED; } @@ -335,8 +335,8 @@ static void tsdbTFileObjRemoveLC(STFileObj *fobj, bool remove_all) { int32_t tsdbTFileObjRemove(STFileObj *fobj) { (void)taosThreadMutexLock(&fobj->mutex); if (fobj->state != TSDB_FSTATE_LIVE || fobj->ref <= 0) { - (void)taosThreadMutexUnlock(&fobj->mutex); tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref); + (void)taosThreadMutexUnlock(&fobj->mutex); return TSDB_CODE_FAILED; } fobj->state = TSDB_FSTATE_DEAD; diff --git a/source/dnode/vnode/src/tsdb/tsdbIter.c b/source/dnode/vnode/src/tsdb/tsdbIter.c index e4218ea4fc..4c5a803f22 100644 --- a/source/dnode/vnode/src/tsdb/tsdbIter.c +++ b/source/dnode/vnode/src/tsdb/tsdbIter.c @@ -153,7 +153,8 @@ static int32_t tsdbDataIterNext(STsdbIter *iter, const TABLEID *tbid) { for (; iter->dataData->brinBlockIdx < iter->dataData->brinBlock->numOfRecords; iter->dataData->brinBlockIdx++) { SBrinRecord record[1]; - (void)tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record); + code = tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record); + if (code) return code; if (iter->filterByVersion && (record->maxVer < iter->range[0] || record->minVer > iter->range[1])) { continue; @@ -224,7 +225,7 @@ static int32_t tsdbMemTableIterNext(STsdbIter *iter, const TABLEID *tbid) { iter->row->row = row[0]; - (void)tsdbTbDataIterNext(iter->memtData->tbIter); + TAOS_UNUSED(tsdbTbDataIterNext(iter->memtData->tbIter)); goto _exit; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 11fcb08d89..8b4cdf9367 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -403,7 +403,11 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid pMemTable->aBucket[idx] = pTbData; pMemTable->nTbData++; - (void)tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn); + if (tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn) == NULL) { + taosWUnLockLatch(&pMemTable->latch); + code = TSDB_CODE_INTERNAL_ERROR; + goto _exit; + } taosWUnLockLatch(&pMemTable->latch); diff --git a/source/dnode/vnode/src/tsdb/tsdbMerge.c b/source/dnode/vnode/src/tsdb/tsdbMerge.c index a4965d49eb..61a82d828e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMerge.c +++ b/source/dnode/vnode/src/tsdb/tsdbMerge.c @@ -77,9 +77,8 @@ static int32_t tsdbMergerClose(SMerger *merger) { return 0; } -static int32_t tsdbMergeFileSetEndCloseReader(SMerger *merger) { +static void tsdbMergeFileSetEndCloseReader(SMerger *merger) { TARRAY2_CLEAR(merger->sttReaderArr, tsdbSttFileReaderClose); - return 0; } static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) { @@ -219,7 +218,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(merger->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); - (void)tsdbMergeFileSetEndCloseReader(merger); + tsdbMergeFileSetEndCloseReader(merger); } return code; } @@ -271,7 +270,9 @@ static int32_t tsdbMergeFileSetBeginOpenWriter(SMerger *merger) { TAOS_CHECK_GOTO(tfsAllocDisk(merger->tsdb->pVnode->pTfs, level, &did), &lino, _exit); - (void)tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did); + code = tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did); + TSDB_CHECK_CODE(code, lino, _exit); + SFSetWriterConfig config = { .tsdb = merger->tsdb, .toSttOnly = true, @@ -354,7 +355,7 @@ static int32_t tsdbMergeFileSetEnd(SMerger *merger) { TAOS_CHECK_GOTO(tsdbMergeFileSetEndCloseIter(merger), &lino, _exit); - TAOS_CHECK_GOTO(tsdbMergeFileSetEndCloseReader(merger), &lino, _exit); + tsdbMergeFileSetEndCloseReader(merger); // edit file system TAOS_CHECK_GOTO(tsdbFSEditBegin(merger->tsdb->pFS, merger->fopArr, TSDB_FEDIT_MERGE), &lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index 09d5cdbdb3..1923c8bafc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -17,7 +17,7 @@ #include "tsdbFS2.h" extern int32_t tsdbOpenCompMonitor(STsdb *tsdb); -extern int32_t tsdbCloseCompMonitor(STsdb *tsdb); +extern void tsdbCloseCompMonitor(STsdb *tsdb); void tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) { STsdbKeepCfg *pKeepCfg = &pTsdb->keepCfg; @@ -65,19 +65,23 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg * // create dir if (pVnode->pTfs) { - (void)tfsMkdir(pVnode->pTfs, pTsdb->path); + code = tfsMkdir(pVnode->pTfs, pTsdb->path); + TSDB_CHECK_CODE(code, lino, _exit); } else { - (void)taosMkDir(pTsdb->path); + code = taosMkDir(pTsdb->path); + TSDB_CHECK_CODE(code, lino, _exit); } // open tsdb - TAOS_CHECK_GOTO(tsdbOpenFS(pTsdb, &pTsdb->pFS, rollback), &lino, _exit); + code = tsdbOpenFS(pTsdb, &pTsdb->pFS, rollback); + TSDB_CHECK_CODE(code, lino, _exit); if (pTsdb->pFS->fsstate == TSDB_FS_STATE_INCOMPLETE && force == false) { TAOS_CHECK_GOTO(TSDB_CODE_NEED_RETRY, &lino, _exit); } - TAOS_CHECK_GOTO(tsdbOpenCache(pTsdb), &lino, _exit); + code = tsdbOpenCache(pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); #ifdef TD_ENTERPRISE TAOS_CHECK_GOTO(tsdbOpenCompMonitor(pTsdb), &lino, _exit); @@ -112,7 +116,7 @@ int32_t tsdbClose(STsdb **pTsdb) { tsdbCloseFS(&(*pTsdb)->pFS); tsdbCloseCache(*pTsdb); #ifdef TD_ENTERPRISE - (void)tsdbCloseCompMonitor(*pTsdb); + tsdbCloseCompMonitor(*pTsdb); #endif (void)taosThreadMutexDestroy(&(*pTsdb)->mutex); taosMemoryFreeClear(*pTsdb); diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 1112dcaaae..44b115d1db 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -160,7 +160,8 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } - (void)taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); + code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); + TSDB_CHECK_CODE(code, lino, _exit); if (encryptAlgorithm == DND_CA_SM4) { // if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){ @@ -635,9 +636,8 @@ _exit: return code; } -int32_t tsdbDataFReaderClose(SDataFReader **ppReader) { - int32_t code = 0; - if (*ppReader == NULL) return code; +void tsdbDataFReaderClose(SDataFReader **ppReader) { + if (*ppReader == NULL) return; // head tsdbCloseFile(&(*ppReader)->pHeadFD); @@ -660,7 +660,6 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) { } taosMemoryFree(*ppReader); *ppReader = NULL; - return code; } int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 2409b390c9..dee412114b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -255,7 +255,8 @@ static int32_t tsdbDoRetention(SRTNer *rtner) { SDiskID did; TAOS_CHECK_GOTO(tfsAllocDisk(rtner->tsdb->pVnode->pTfs, expLevel, &did), &lino, _exit); - (void)tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did); + code = tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did); + TSDB_CHECK_CODE(code, lino, _exit); // data for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX && (fobj = fset->farr[ftype], 1); ++ftype) { @@ -337,7 +338,7 @@ static int32_t tsdbRetention(void *arg) { _exit: if (rtner.fset) { (void)taosThreadMutexLock(&pTsdb->mutex); - (void)tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid); + tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid); (void)taosThreadMutexUnlock(&pTsdb->mutex); } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c index d531179f97..53bace9941 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c @@ -102,7 +102,11 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** } count++; SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer}; - (void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + if (code) { + tsdbFSetPartitionClear(&p); + return code; + } } typ = TSDB_FSET_RANGE_TYP_STT; @@ -120,12 +124,20 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition** } count++; SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer}; - (void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + if (code) { + tsdbFSetPartitionClear(&p); + return code; + } } } if (corrupt && count == 0) { SVersionRange vr = {.minVer = VERSION_MIN, .maxVer = fset->maxVerValid}; - (void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); + if (code) { + tsdbFSetPartitionClear(&p); + return code; + } } ppSP[0] = p; return 0; @@ -182,7 +194,11 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray r->sver = maxVerValid + 1; r->ever = VERSION_MAX; tsdbDebug("range diff fid:%" PRId64 ", sver:%" PRId64 ", ever:%" PRId64, part->fid, r->sver, r->ever); - (void)TARRAY2_SORT_INSERT(pDiff, r, tsdbTFileSetRangeCmprFn); + code = TARRAY2_SORT_INSERT(pDiff, r, tsdbTFileSetRangeCmprFn); + if (code) { + taosMemoryFree(r); + goto _err; + } } ppRanges[0] = pDiff; diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 6b9a959157..15930353bf 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -1127,7 +1127,7 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** writer, int8_t rollback) { tsdbDataFileReaderClose(&writer[0]->ctx->dataReader); TARRAY2_DESTROY(writer[0]->fopArr, NULL); - TAOS_UNUSED(tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr)); + tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr); for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); ++i) { tBufferDestroy(writer[0]->buffers + i); diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c index f86e548321..609e2a80e9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c @@ -157,10 +157,9 @@ static int32_t tsdbSnapRAWReadFileSetOpenIter(STsdbSnapRAWReader* reader) { return 0; } -static int32_t tsdbSnapRAWReadFileSetCloseIter(STsdbSnapRAWReader* reader) { +static void tsdbSnapRAWReadFileSetCloseIter(STsdbSnapRAWReader* reader) { reader->dataIter->count = 0; reader->dataIter->idx = 0; - return 0; } static int64_t tsdbSnapRAWReadPeek(SDataFileRAWReader* reader) { @@ -260,7 +259,7 @@ _exit: } static int32_t tsdbSnapRAWReadEnd(STsdbSnapRAWReader* reader) { - (void)tsdbSnapRAWReadFileSetCloseIter(reader); + tsdbSnapRAWReadFileSetCloseIter(reader); tsdbSnapRAWReadFileSetCloseReader(reader); reader->ctx->fset = NULL; return 0; @@ -410,7 +409,9 @@ static int32_t tsdbSnapRAWWriteFileSetBegin(STsdbSnapRAWWriter* writer, int32_t int32_t level = tsdbFidLevel(fid, &writer->tsdb->keepCfg, taosGetTimestampSec()); code = tfsAllocDisk(writer->tsdb->pVnode->pTfs, level, &writer->ctx->did); TSDB_CHECK_CODE(code, lino, _exit); - (void)tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did); + + code = tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did); + TSDB_CHECK_CODE(code, lino, _exit); code = tsdbSnapRAWWriteFileSetOpenWriter(writer); TSDB_CHECK_CODE(code, lino, _exit); @@ -489,7 +490,7 @@ int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** writer, int8_t rollback) { } TARRAY2_DESTROY(writer[0]->fopArr, NULL); - (void)tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr); + tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr); taosMemoryFree(writer[0]); writer[0] = NULL; diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index 3d9ea4ef69..bf941e0383 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -590,11 +590,13 @@ static int32_t tsdbSttFileDoWriteStatisBlock(SSttFileWriter *writer) { statisBlk.cmprAlg = writer->config->cmprAlg; statisBlk.numOfPKs = statisBlock->numOfPKs; - (void)tStatisBlockGet(statisBlock, 0, &record); + code = tStatisBlockGet(statisBlock, 0, &record); + TSDB_CHECK_CODE(code, lino, _exit); statisBlk.minTbid.suid = record.suid; statisBlk.minTbid.uid = record.uid; - (void)tStatisBlockGet(statisBlock, statisBlock->numOfRecords - 1, &record); + code = tStatisBlockGet(statisBlock, statisBlock->numOfRecords - 1, &record); + TSDB_CHECK_CODE(code, lino, _exit); statisBlk.maxTbid.suid = record.suid; statisBlk.maxTbid.uid = record.uid; diff --git a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c index 6d95ebad28..b980bc5f25 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c +++ b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c @@ -356,7 +356,7 @@ static int32_t tsdbUpgradeFileSet(STsdb *tsdb, SDFileSet *pDFileSet, TFileSetArr TAOS_CHECK_GOTO(tsdbUpgradeStt(tsdb, pDFileSet, reader, fset), &lino, _exit); } - (void)tsdbDataFReaderClose(&reader); + tsdbDataFReaderClose(&reader); TAOS_CHECK_GOTO(TARRAY2_APPEND(fileSetArray, fset), &lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 8820a026e9..63141db729 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -106,7 +106,7 @@ _exit: #endif void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { - (void)tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem); + TAOS_UNUSED(tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem)); } #ifdef BUILD_NO_CALL From abbcc4afa087dec2984e5c5b90987ddc81d4b472 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 11 Sep 2024 03:24:59 +0000 Subject: [PATCH 46/90] fix/TS-5404-use-temp-transid-when-timeout --- source/dnode/mnode/impl/src/mndTrans.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 63cab4168a..18ceddb7d0 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -64,6 +64,8 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq); static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter); +int32_t tsMaxTransId = 0; + int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = { .sdbType = SDB_TRANS, @@ -602,7 +604,9 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict, tstrncpy(pTrans->opername, opername, TSDB_TRANS_OPER_LEN); } - pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS); + int32_t sdbMaxId = sdbGetMaxId(pMnode->pSdb, SDB_TRANS); + int32_t oldId = atomic_load_32(&tsMaxTransId); + pTrans->id = TMAX(sdbMaxId, oldId); pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; pTrans->conflict = conflict; @@ -1027,6 +1031,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { mInfo("trans:%d, prepare transaction", pTrans->id); if ((code = mndTransSync(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code)); + atomic_store_32(&tsMaxTransId, pTrans->id); TAOS_RETURN(code); } mInfo("trans:%d, prepare finished", pTrans->id); From 82adb5347878ec8a5d38727634116a5fbb27bbc9 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 11 Sep 2024 13:31:28 +0800 Subject: [PATCH 47/90] fix: correct block check --- source/common/src/tdatablock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index dee9ec2c0c..bd169914df 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -3397,13 +3397,14 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) { } void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { - return; + //return; if (NULL == pDataBlock || pDataBlock->info.rows == 0) { return; } -#define BLOCK_DATA_CHECK_TRESSA(o) ; +//#define BLOCK_DATA_CHECK_TRESSA(o) ; +#define BLOCK_DATA_CHECK_TRESSA(o) ASSERT(o) BLOCK_DATA_CHECK_TRESSA(pDataBlock->info.rows > 0); @@ -3439,6 +3440,8 @@ void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] < pCol->varmeta.length); if (pCol->reassigned) { BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] >= 0); + } else if (0 == r) { + nextPos = pCol->varmeta.offset[r]; } else { BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] == nextPos); } From aecdabe9a4ad0cb9938292b27598f727543fdaeb Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 11 Sep 2024 13:38:24 +0800 Subject: [PATCH 48/90] fix: remove block check --- source/common/src/tdatablock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index bd169914df..08f6842c4b 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -3397,14 +3397,14 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) { } void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) { - //return; + return; if (NULL == pDataBlock || pDataBlock->info.rows == 0) { return; } -//#define BLOCK_DATA_CHECK_TRESSA(o) ; -#define BLOCK_DATA_CHECK_TRESSA(o) ASSERT(o) +#define BLOCK_DATA_CHECK_TRESSA(o) ; +//#define BLOCK_DATA_CHECK_TRESSA(o) A S S E R T(o) BLOCK_DATA_CHECK_TRESSA(pDataBlock->info.rows > 0); From 44a955218cfcedb9b9445e058fcb3a87e4177c95 Mon Sep 17 00:00:00 2001 From: Shungang Li Date: Wed, 11 Sep 2024 13:48:23 +0800 Subject: [PATCH 49/90] fix: (last) call rocksdb_write before rocksdb_multi_get --- source/dnode/vnode/src/inc/tsdb.h | 1 - source/dnode/vnode/src/tsdb/tsdbCache.c | 111 +++++++++--------------- 2 files changed, 40 insertions(+), 72 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index c85c376c47..d4a33a5478 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -362,7 +362,6 @@ struct STsdb { SMemTable *imem; STsdbFS fs; // old SLRUCache *lruCache; - SCacheFlushState flushState; TdThreadMutex lruMutex; SLRUCache *biCache; TdThreadMutex biMutex; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index f4a423bfa7..53e20d459f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -267,7 +267,6 @@ static void rocksMayWrite(STsdb *pTsdb, bool force) { tsdbError("vgId:%d, %s failed at line %d, count: %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, count, err); rocksdb_free(err); - // pTsdb->flushState.flush_count = 0; } rocksdb_writebatch_clear(wb); @@ -456,47 +455,23 @@ static int32_t tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size TAOS_RETURN(TSDB_CODE_SUCCESS); } -static void tsdbCachePutBatch(SLastCol *pLastCol, const void *key, size_t klen, SCacheFlushState *state) { - int32_t code = 0; - STsdb *pTsdb = state->pTsdb; - SRocksCache *rCache = &pTsdb->rCache; - rocksdb_writebatch_t *wb = rCache->writebatch; - char *rocks_value = NULL; - size_t vlen = 0; - - code = tsdbCacheSerialize(pLastCol, &rocks_value, &vlen); - if (code) { - tsdbError("tsdb/cache: vgId:%d, serialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - return; - } - - rocksdb_writebatch_put(wb, (char *)key, klen, rocks_value, vlen); - - taosMemoryFree(rocks_value); - - if (++state->flush_count >= ROCKS_BATCH_SIZE) { - char *err = NULL; - - rocksdb_write(rCache->db, rCache->writeoptions, wb, &err); - if (NULL != err) { - tsdbError("vgId:%d, %s failed at line %d, count: %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, - state->flush_count, err); - rocksdb_free(err); - } - - rocksdb_writebatch_clear(wb); - - state->flush_count = 0; - } -} +static int32_t tsdbCachePutToRocksdb(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLastCol); int tsdbCacheFlushDirty(const void *key, size_t klen, void *value, void *ud) { SLastCol *pLastCol = (SLastCol *)value; if (pLastCol->dirty) { - tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud); + STsdb *pTsdb = (STsdb *)ud; + + int32_t code = tsdbCachePutToRocksdb(pTsdb, (SLastKey *)key, pLastCol); + if (code) { + tsdbError("tsdb/cache: vgId:%d, flush dirty lru failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; + } pLastCol->dirty = 0; + + rocksMayWrite(pTsdb, false); } return 0; @@ -511,7 +486,7 @@ int32_t tsdbCacheCommit(STsdb *pTsdb) { (void)taosThreadMutexLock(&pTsdb->lruMutex); - taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState); + taosLRUCacheApply(pCache, tsdbCacheFlushDirty, pTsdb); rocksMayWrite(pTsdb, true); rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err); @@ -602,7 +577,7 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud SLastCol *pLastCol = (SLastCol *)value; if (pLastCol->dirty) { - tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud); + tsdbCacheFlushDirty(key, klen, pLastCol, ud); } for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) { @@ -639,11 +614,11 @@ static int32_t tsdbCacheNewTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, i SLastKey *pLastKey = &(SLastKey){.lflag = lflag, .uid = uid, .cid = cid}; LRUStatus status = taosLRUCacheInsert(pCache, pLastKey, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL, - TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); + TAOS_LRU_PRIORITY_LOW, pTsdb); if (status != TAOS_LRU_STATUS_OK) { tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status); - tsdbCacheFreeSLastColItem(pLastCol); code = TSDB_CODE_FAILED; + pLastCol = NULL; } _exit: @@ -661,7 +636,7 @@ int32_t tsdbCacheCommitNoLock(STsdb *pTsdb) { SLRUCache *pCache = pTsdb->lruCache; rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; - taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState); + taosLRUCacheApply(pCache, tsdbCacheFlushDirty, pTsdb); rocksMayWrite(pTsdb, true); rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err); @@ -733,6 +708,10 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, char **values_list = NULL; size_t *values_list_sizes = NULL; + + // was written by caller + // rocksMayWrite(pTsdb, true); // flush writebatch cache + TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, 2, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes), NULL, _exit); @@ -857,7 +836,7 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra taosMemoryFree(pTSchema); } - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -898,7 +877,7 @@ int32_t tsdbCacheDropSubTables(STsdb *pTsdb, SArray *uids, tb_uid_t suid) { taosMemoryFree(pTSchema); - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -929,7 +908,7 @@ int32_t tsdbCacheDropNTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, bool h (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -968,7 +947,7 @@ int32_t tsdbCacheDropSTableColumn(STsdb *pTsdb, SArray *uids, int16_t cid, bool (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); } - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -1078,11 +1057,11 @@ static int32_t tsdbCachePutToLRU(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLa TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(pLRULastCol, &charge)); LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter, - NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); + NULL, TAOS_LRU_PRIORITY_LOW, pTsdb); if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) { tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status); - tsdbCacheFreeSLastColItem(pLRULastCol); code = TSDB_CODE_FAILED; + pLRULastCol = NULL; } _exit: @@ -1172,6 +1151,8 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray keys_list_sizes[i] = ROCKS_KEY_LEN; } + rocksMayWrite(pTsdb, true); // flush writebatch cache + code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes); if (code) { @@ -1238,7 +1219,7 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray taosMemoryFreeClear(pToFree); } - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); taosMemoryFree(keys_list); taosMemoryFree(keys_list_sizes); @@ -1568,32 +1549,22 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr } LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL, - TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); + TAOS_LRU_PRIORITY_LOW, pTsdb); if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) { tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status); - tsdbCacheFreeSLastColItem(pLastCol); - taosMemoryFree(pLastCol); + pLastCol = NULL; TAOS_CHECK_EXIT(TSDB_CODE_FAILED); } // store result back to rocks cache - wb = pTsdb->rCache.writebatch; - char *value = NULL; - size_t vlen = 0; - code = tsdbCacheSerialize(pLastCol, &value, &vlen); + code = tsdbCachePutToRocksdb(pTsdb, &idxKey->key, pLastCol); if (code) { - tsdbError("tsdb/cache: vgId:%d, serialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } else { - SLastKey *key = &idxKey->key; - size_t klen = ROCKS_KEY_LEN; - rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen); - taosMemoryFree(value); + tsdbError("vgId:%d, %s failed at line %d since %s.", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code)); + TAOS_CHECK_EXIT(code); } } - if (wb) { - rocksMayWrite(pTsdb, false); - } + rocksMayWrite(pTsdb, false); _exit: taosArrayDestroy(lastrowTmpIndexArray); @@ -1633,6 +1604,8 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA keys_list_sizes[i] = ROCKS_KEY_LEN; } + rocksMayWrite(pTsdb, true); // flush writebatch cache + code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes); if (code) { @@ -1681,11 +1654,9 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA } LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, - NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); + NULL, TAOS_LRU_PRIORITY_LOW, pTsdb); if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) { tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status); - tsdbCacheFreeSLastColItem(pLastCol); - taosMemoryFreeClear(pLastCol); taosMemoryFreeClear(pToFree); TAOS_CHECK_EXIT(TSDB_CODE_FAILED); } @@ -1792,7 +1763,6 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache if (remainCols && TARRAY_SIZE(remainCols) > 0) { (void)taosThreadMutexLock(&pTsdb->lruMutex); - rocksMayWrite(pTsdb, false); for (int i = 0; i < TARRAY_SIZE(remainCols);) { SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[i]; @@ -1907,6 +1877,8 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE keys_list_sizes[i] = klen; } + rocksMayWrite(pTsdb, true); // flush writebatch cache + TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, numKeys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes), NULL, _exit); @@ -1941,7 +1913,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE taosMemoryFreeClear(pLastCol); } - rocksMayWrite(pTsdb, true); + rocksMayWrite(pTsdb, false); _exit: (void)taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -1983,9 +1955,6 @@ int32_t tsdbOpenCache(STsdb *pTsdb) { (void)taosThreadMutexInit(&pTsdb->lruMutex, NULL); - pTsdb->flushState.pTsdb = pTsdb; - pTsdb->flushState.flush_count = 0; - _err: if (code) { tsdbError("tsdb/cache: vgId:%d, open failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tstrerror(code)); From 64bb49e0dbfd2a3087ccdfe54fb28e4af6528e71 Mon Sep 17 00:00:00 2001 From: Jing Sima Date: Mon, 9 Sep 2024 18:44:16 +0800 Subject: [PATCH 50/90] fix:[TS-5839] Fix crash when use last function on a column with all null value with partition subclause. --- include/common/tcommon.h | 2 + source/libs/function/inc/builtinsimpl.h | 1 + source/libs/function/src/builtins.c | 2 +- source/libs/function/src/builtinsimpl.c | 65 +++++++++++++++++++------ tests/script/tsim/query/cache_last.sim | 2 +- 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 5714990dd5..753f84d774 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -110,6 +110,8 @@ typedef struct SFirstLastRes { int32_t pkBytes; int8_t pkType; STuplePos pos; + STuplePos nullTuplePos; + bool nullTupleSaved; char buf[]; } SFirstLastRes; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 16f31321ce..41e2cadace 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -152,6 +152,7 @@ int32_t getIrateInfoSize(int32_t pkBytes); int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx); bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +int32_t firstLastFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t firstFunction(SqlFunctionCtx* pCtx); int32_t firstFunctionMerge(SqlFunctionCtx* pCtx); int32_t lastFunction(SqlFunctionCtx* pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 3ec63a6d34..976d15e7d8 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -3469,7 +3469,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .translateFunc = translateFirstLast, .dynDataRequiredFunc = lastDynDataReq, .getEnvFunc = getFirstLastFuncEnv, - .initFunc = functionSetup, + .initFunc = firstLastFunctionSetup, .processFunc = lastFunction, .sprocessFunc = firstLastScalarFunction, .finalizeFunc = firstLastFinalize, diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 6d655528c7..a84e8b66ad 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2617,6 +2617,22 @@ static FORCE_INLINE TSKEY getRowPTs(SColumnInfoData* pTsColInfo, int32_t rowInde return *(TSKEY*)colDataGetData(pTsColInfo, rowIndex); } +int32_t firstLastFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { + if (pResInfo->initialized) { + return TSDB_CODE_SUCCESS; + } + if (TSDB_CODE_SUCCESS != functionSetup(pCtx, pResInfo)) { + return TSDB_CODE_FUNC_SETUP_ERROR; + } + + SFirstLastRes * pRes = GET_ROWCELL_INTERBUF(pResInfo); + SInputColumnInfoData* pInput = &pCtx->input; + + pRes->nullTupleSaved = false; + pRes->nullTuplePos.pageId = -1; + return TSDB_CODE_SUCCESS; +} + static int32_t prepareBuf(SqlFunctionCtx* pCtx) { if (pCtx->subsidiaries.rowLen == 0) { int32_t rowLen = 0; @@ -2635,7 +2651,7 @@ static int32_t prepareBuf(SqlFunctionCtx* pCtx) { } static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowIndex, SqlFunctionCtx* pCtx, - SFirstLastRes* pInfo) { + SFirstLastRes* pInfo, bool noElements) { int32_t code = TSDB_CODE_SUCCESS; if (pCtx->subsidiaries.num <= 0) { @@ -2643,7 +2659,7 @@ static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowI } if (!pInfo->hasResult) { - code = saveTupleData(pCtx, rowIndex, pSrcBlock, &pInfo->pos); + code = saveTupleData(pCtx, rowIndex, pSrcBlock, noElements ? &pInfo->nullTuplePos : &pInfo->pos); } else { code = updateTupleData(pCtx, rowIndex, pSrcBlock, &pInfo->pos); } @@ -2669,7 +2685,7 @@ static int32_t doSaveCurrentVal(SqlFunctionCtx* pCtx, int32_t rowIndex, int64_t } pInfo->ts = currentTs; - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo, false); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -2708,10 +2724,11 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) && pInputCol->hasNull == true) { // save selectivity value for column consisted of all null values - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved); if (code != TSDB_CODE_SUCCESS) { return code; } + pInfo->nullTupleSaved = true; return TSDB_CODE_SUCCESS; } @@ -2802,10 +2819,11 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { if (numOfElems == 0) { // save selectivity value for column consisted of all null values - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved); if (code != TSDB_CODE_SUCCESS) { return code; } + pInfo->nullTupleSaved = true; } SET_VAL(pResInfo, numOfElems, 1); return TSDB_CODE_SUCCESS; @@ -2841,10 +2859,11 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) && pInputCol->hasNull == true) { // save selectivity value for column consisted of all null values - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved); if (code != TSDB_CODE_SUCCESS) { return code; } + pInfo->nullTupleSaved = true; return TSDB_CODE_SUCCESS; } @@ -2983,10 +3002,11 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { // save selectivity value for column consisted of all null values if (numOfElems == 0) { - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved); if (code != TSDB_CODE_SUCCESS) { return code; } + pInfo->nullTupleSaved = true; } return TSDB_CODE_SUCCESS; @@ -3031,7 +3051,7 @@ static bool firstLastTransferInfoImpl(SFirstLastRes* pInput, SFirstLastRes* pOut static int32_t firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst, int32_t rowIndex) { if (firstLastTransferInfoImpl(pInput, pOutput, isFirst)) { - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pOutput); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pOutput, pOutput->nullTupleSaved); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -3079,6 +3099,14 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer } } + if (numOfElems == 0) { + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + pInfo->nullTupleSaved = true; + } + SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); return TSDB_CODE_SUCCESS; } @@ -3099,6 +3127,11 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo); + + if (pResInfo->isNullRes) { + colDataSetNULL(pCol, pBlock->info.rows); + return setSelectivityValue(pCtx, pBlock, &pRes->nullTuplePos, pBlock->info.rows); + } code = colDataSetVal(pCol, pBlock->info.rows, pRes->buf, pRes->isNull || pResInfo->isNullRes); if (TSDB_CODE_SUCCESS != code) { return code; @@ -3134,12 +3167,16 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return TSDB_CODE_OUT_OF_RANGE; } - code = colDataSetVal(pCol, pBlock->info.rows, res, false); - if (TSDB_CODE_SUCCESS != code) { - return TSDB_CODE_OUT_OF_MEMORY; + if (pEntryInfo->numOfRes == 0) { + colDataSetNULL(pCol, pBlock->info.rows); + code = setSelectivityValue(pCtx, pBlock, &pRes->nullTuplePos, pBlock->info.rows); + } else { + code = colDataSetVal(pCol, pBlock->info.rows, res, false); + if (TSDB_CODE_SUCCESS != code) { + return TSDB_CODE_OUT_OF_MEMORY; + } + code = setSelectivityValue(pCtx, pBlock, &pRes->pos, pBlock->info.rows); } - code = setSelectivityValue(pCtx, pBlock, &pRes->pos, pBlock->info.rows); - taosMemoryFree(res); return code; } @@ -3185,7 +3222,7 @@ static int32_t doSaveLastrow(SqlFunctionCtx* pCtx, char* pData, int32_t rowIndex pInfo->pkData = pInfo->buf + pInfo->bytes; } pInfo->ts = cts; - int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo); + int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo, false); if (code != TSDB_CODE_SUCCESS) { return code; } diff --git a/tests/script/tsim/query/cache_last.sim b/tests/script/tsim/query/cache_last.sim index a06e6e1e6f..0a30bbd325 100644 --- a/tests/script/tsim/query/cache_last.sim +++ b/tests/script/tsim/query/cache_last.sim @@ -89,7 +89,7 @@ if $data10 != @ -> Merge (columns=3 width=24 input_order=unknown output_order= return -1 endi sql explain select count(*), last_row(f1), min(f1) from sta interval(1s); -if $data10 != @ -> Merge (columns=4 width=82 input_order=asc output_order=asc mode=sort)@ then +if $data10 != @ -> Merge (columns=4 width=106 input_order=asc output_order=asc mode=sort)@ then return -1 endi sql explain select distinct count(*), last_row(f1), min(f1) from tba1; From f9126f121187ddc3fabfbd1e876106ad4f72a492 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 14:11:51 +0800 Subject: [PATCH 51/90] enh:modify error code passing --- source/libs/sync/src/syncPipeline.c | 2 +- source/libs/sync/src/syncRespMgr.c | 2 +- source/libs/sync/src/syncSnapshot.c | 10 +++--- source/libs/tfs/src/tfs.c | 4 +-- source/libs/tfs/src/tfsDisk.c | 2 +- source/libs/transport/src/thttp.c | 4 +-- source/libs/transport/src/transCli.c | 52 +++++++++++++-------------- source/libs/transport/src/transComm.c | 16 ++++----- source/libs/transport/src/transSvr.c | 16 ++++----- source/util/src/talgo.c | 6 ++-- source/util/src/tbase58.c | 8 ++--- source/util/src/tbloomfilter.c | 6 ++-- source/util/src/tconfig.c | 4 +-- source/util/src/tgeosctx.c | 2 +- source/util/src/tjson.c | 2 +- source/util/src/tlist.c | 2 +- source/util/src/tlrucache.c | 2 +- source/util/src/tqueue.c | 8 ++--- source/util/src/tref.c | 6 ++-- source/util/src/tscalablebf.c | 4 +-- source/util/src/tworker.c | 10 +++--- 21 files changed, 84 insertions(+), 84 deletions(-) diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c index a6e9c7de32..86d4d83d29 100644 --- a/source/libs/sync/src/syncPipeline.c +++ b/source/libs/sync/src/syncPipeline.c @@ -1279,7 +1279,7 @@ int32_t syncLogBufferCreate(SSyncLogBuffer** ppBuf) { int32_t code = 0; SSyncLogBuffer* pBuf = taosMemoryCalloc(1, sizeof(SSyncLogBuffer)); if (pBuf == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exit); + TAOS_CHECK_GOTO(terrno, NULL, _exit); } pBuf->size = sizeof(pBuf->entries) / sizeof(pBuf->entries[0]); diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index aa7a6da0a2..854d6bc314 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -25,7 +25,7 @@ int32_t syncRespMgrCreate(void *data, int64_t ttl, SSyncRespMgr **ppObj) { *ppObj = NULL; if ((pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr))) == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pObj->pRespHash = diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 2a3b164f03..0b77ab78a6 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -54,7 +54,7 @@ static int32_t syncSnapBufferCreate(SSyncSnapBuffer **ppBuf) { SSyncSnapBuffer *pBuf = taosMemoryCalloc(1, sizeof(SSyncSnapBuffer)); if (pBuf == NULL) { *ppBuf = NULL; - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pBuf->size = sizeof(pBuf->entries) / sizeof(void *); if (pBuf->size != TSDB_SYNC_SNAP_BUFFER_SIZE) return TSDB_CODE_SYN_INTERNAL_ERROR; @@ -74,7 +74,7 @@ int32_t snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex, SSyncSn SSyncSnapshotSender *pSender = taosMemoryCalloc(1, sizeof(SSyncSnapshotSender)); if (pSender == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pSender->start = false; @@ -285,7 +285,7 @@ static int32_t snapshotSend(SSyncSnapshotSender *pSender) { if (pSender->seq > SYNC_SNAPSHOT_SEQ_BEGIN) { pBlk = taosMemoryCalloc(1, sizeof(SyncSnapBlock)); if (pBlk == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OUT; } @@ -422,7 +422,7 @@ int32_t snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId, SSyncSnapsh SSyncSnapshotReceiver *pReceiver = taosMemoryCalloc(1, sizeof(SSyncSnapshotReceiver)); if (pReceiver == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pReceiver->start = false; @@ -697,7 +697,7 @@ static int32_t syncSnapReceiverExchgSnapInfo(SSyncNode *pSyncNode, SSyncSnapshot // copy snap info from leader void *data = taosMemoryCalloc(1, pMsg->dataLen); if (data == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } pInfo->data = data; data = NULL; diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 4954e81837..9727256a58 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -36,7 +36,7 @@ int32_t tfsOpen(SDiskCfg *pCfg, int32_t ndisk, STfs **ppTfs) { pTfs = taosMemoryCalloc(1, sizeof(STfs)); if (pTfs == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosThreadSpinInit(&pTfs->lock, 0) != 0) { @@ -429,7 +429,7 @@ int32_t tfsOpendir(STfs *pTfs, const char *rname, STfsDir **ppDir) { int32_t code = 0; STfsDir *pDir = taosMemoryCalloc(1, sizeof(STfsDir)); if (pDir == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exit); + TAOS_CHECK_GOTO(terrno, NULL, _exit); } SDiskID diskId = {.id = 0, .level = 0}; diff --git a/source/libs/tfs/src/tfsDisk.c b/source/libs/tfs/src/tfsDisk.c index 07fa8d79b9..dfdf1262c9 100644 --- a/source/libs/tfs/src/tfsDisk.c +++ b/source/libs/tfs/src/tfsDisk.c @@ -22,7 +22,7 @@ int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path, STfsDisk *pDisk = NULL; if ((pDisk = taosMemoryCalloc(1, sizeof(STfsDisk))) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if ((pDisk->path = taosStrdup(path)) == NULL) { diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index d19877dbf1..e0e2a0c323 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -446,7 +446,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { int32_t httpSendQuit(SHttpModule* http, int64_t chanId) { SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg)); if (msg == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } msg->seq = atomic_fetch_add_64(&httpSeqNum, 1); msg->quit = 1; @@ -744,7 +744,7 @@ int64_t transInitHttpChanImpl() { int32_t code = 0; SHttpModule* http = taosMemoryCalloc(1, sizeof(SHttpModule)); if (http == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 78320c450c..4dd3346f8b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -874,7 +874,7 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); if (exh == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } exh->refId = transAddExHandle(transGetRefMgt(), exh); @@ -974,7 +974,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { int32_t code = 0; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // read/write stream handle @@ -996,7 +996,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { if (timer == NULL) { timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); if (timer == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _failed); + TAOS_CHECK_GOTO(terrno, NULL, _failed); } tDebug("no available timer, create a timer %p", timer); @@ -1951,7 +1951,7 @@ static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); if (pBatchList == NULL) { tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } QUEUE_INIT(&pBatchList->wq); pBatchList->port = port; @@ -1991,7 +1991,7 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* p SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); if (pBatch == NULL) { tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } QUEUE_INIT(&pBatch->wq); @@ -2315,7 +2315,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd)); if (pThrd == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } QUEUE_INIT(&pThrd->msg); @@ -2323,7 +2323,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); if (pThrd->loop == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } code = uv_loop_init(pThrd->loop); @@ -2362,7 +2362,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { for (int i = 0; i < timerSize; i++) { uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); if (timer == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } (void)uv_timer_init(pThrd->loop, timer); if (taosArrayPush(pThrd->timerList, &timer) == NULL) { @@ -2486,7 +2486,7 @@ int32_t cliSendQuit(SCliThrd* thrd) { int32_t code = 0; SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (msg == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } msg->type = Quit; @@ -2894,7 +2894,7 @@ int32_t transReleaseCliHandle(void* handle) { STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); if (pCtx == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCtx->ahandle = tmsg.info.ahandle; @@ -2902,7 +2902,7 @@ int32_t transReleaseCliHandle(void* handle) { SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cmsg == NULL) { taosMemoryFree(pCtx); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } cmsg->msg = tmsg; cmsg->st = taosGetTimestampUs(); @@ -2923,7 +2923,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); if (pCtx == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } epsetAssign(&pCtx->epSet, pEpSet); @@ -2937,7 +2937,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cliMsg == NULL) { taosMemoryFree(pCtx); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } cliMsg->ctx = pCtx; @@ -3071,7 +3071,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg)); if (pTransRsp == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); @@ -3081,7 +3081,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t)); if (sem == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } code = tsem_init(sem, 0, 0); @@ -3096,7 +3096,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra if (pCtx == NULL) { (void)tsem_destroy(sem); taosMemoryFree(sem); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } epsetAssign(&pCtx->epSet, pEpSet); @@ -3111,7 +3111,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra (void)tsem_destroy(sem); taosMemoryFree(sem); taosMemoryFree(pCtx); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } cliMsg->ctx = pCtx; @@ -3150,7 +3150,7 @@ int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { int32_t code = 0; tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t)); if (sem == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tsem2_init(sem, 0, 0) != 0) { @@ -3159,7 +3159,7 @@ int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { STransSyncMsg* pSyncMsg = taosMemoryCalloc(1, sizeof(STransSyncMsg)); if (pSyncMsg == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _EXIT); + TAOS_CHECK_GOTO(terrno, NULL, _EXIT); } taosInitRWLatch(&pSyncMsg->latch); @@ -3194,7 +3194,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pTransMsg = taosMemoryCalloc(1, sizeof(STransMsg)); if (pTransMsg == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); @@ -3206,7 +3206,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); if (pCtx == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } epsetAssign(&pCtx->epSet, pEpSet); @@ -3229,7 +3229,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cliMsg == NULL) { taosMemoryFree(pCtx); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } cliMsg->ctx = pCtx; @@ -3294,7 +3294,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { for (int8_t i = 0; i < pTransInst->numOfThreads; i++) { STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); if (pCtx == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } @@ -3303,7 +3303,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cliMsg == NULL) { taosMemoryFree(pCtx); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } @@ -3330,7 +3330,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { int32_t transAllocHandle(int64_t* refId) { SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); if (exh == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } exh->refId = transAddExHandle(transGetRefMgt(), exh); @@ -3369,7 +3369,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg)); if (pCli == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } pCli->type = FreeById; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 1329489be6..05244dbce2 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -70,7 +70,7 @@ int32_t transDecompressMsg(char** msg, int32_t len) { char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STransMsgHead* pNewHead = (STransMsgHead*)buf; @@ -106,7 +106,7 @@ int transSockInfo2Str(struct sockaddr* sockname, char* dst) { int32_t transInitBuffer(SConnBuffer* buf) { buf->buf = taosMemoryCalloc(1, BUFFER_CAP); if (buf->buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } buf->cap = BUFFER_CAP; @@ -149,7 +149,7 @@ int32_t transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf) { if (total >= HEADSIZE && !p->invalid) { *buf = taosMemoryCalloc(1, total); if (*buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(*buf, p->buf, total); if ((code = transResetBuffer(connBuf, resetBuf)) < 0) { @@ -249,7 +249,7 @@ int32_t transSetConnOption(uv_tcp_t* stream, int keepalive) { int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAsyncPool** pPool) { SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool)); if (pool == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; // return NULL; } int32_t code = 0; @@ -258,7 +258,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync); if (pool->asyncs == NULL) { taosMemoryFree(pool); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int i = 0, err = 0; @@ -267,7 +267,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem)); if (item == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } item->pThrd = arg; @@ -560,7 +560,7 @@ int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); if (timer == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } heap = heapCreate(timeCompare); @@ -852,7 +852,7 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { int32_t len = 0; char* pBuf = taosMemoryCalloc(1, pList->num * 36); if (pBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < pList->num; i++) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 11aa468b19..f68561fedf 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -260,7 +260,7 @@ int32_t uvWhiteListToStr(SWhiteUserList* plist, char* user, char** ppBuf) { char* pBuf = taosMemoryCalloc(1, tlen + 64); if (pBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t len = sprintf(pBuf, "user: %s, ver: %" PRId64 ", ip: {%s}", user, plist->ver, tmp); @@ -299,7 +299,7 @@ int32_t uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist, if (ppUserList == NULL || *ppUserList == NULL) { SWhiteUserList* pUserList = taosMemoryCalloc(1, sizeof(SWhiteUserList)); if (pUserList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pUserList->ver = ver; @@ -1104,7 +1104,7 @@ static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); if (pThrd->prepare == NULL) { tError("failed to init prepare"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = uv_prepare_init(pThrd->loop, pThrd->prepare); @@ -1155,7 +1155,7 @@ static int32_t addHandleToAcceptloop(void* arg) { srv->pAcceptAsync = taosMemoryCalloc(1, sizeof(uv_async_t)); if (srv->pAcceptAsync == NULL) { tError("failed to create async since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb); @@ -1749,7 +1749,7 @@ int32_t transReleaseSrvHandle(void* handle) { SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (m == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return1; } @@ -1799,7 +1799,7 @@ int32_t transSendResponse(const STransMsg* msg) { SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (m == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return1; } @@ -1844,7 +1844,7 @@ int32_t transRegisterMsg(const STransMsg* msg) { SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (m == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return1; } @@ -1888,7 +1888,7 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (msg == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } diff --git a/source/util/src/talgo.c b/source/util/src/talgo.c index 9c241516ca..f1ee40eccf 100644 --- a/source/util/src/talgo.c +++ b/source/util/src/talgo.c @@ -148,7 +148,7 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, int64_t size, cons int32_t taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) { char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer if (NULL == buf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf); taosMemoryFreeClear(buf); @@ -393,7 +393,7 @@ int32_t taosheapsort(void *base, int32_t size, int32_t len, const void *parcompa char *buf = taosMemoryCalloc(1, size); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (base && size > 0) { @@ -454,7 +454,7 @@ static int32_t taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, c const int32_t THRESHOLD_SIZE = 6; char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t start = 0; start < numOfElem - 1; start += THRESHOLD_SIZE) { diff --git a/source/util/src/tbase58.c b/source/util/src/tbase58.c index b5d873f5ea..84ca86c084 100644 --- a/source/util/src/tbase58.c +++ b/source/util/src/tbase58.c @@ -43,7 +43,7 @@ int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result) { size = (pe - pb) * 69 / 50 + 1; if (size > TBASE_BUF_SIZE) { if (!(pbuf = taosMemoryCalloc(1, size))) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } bfree = true; } @@ -65,7 +65,7 @@ int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result) { uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - pi) + 1); if (!pResult) { if (bfree) taosMemoryFree(pbuf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memset(pResult, '1', nz); while (pi != pbuf + size) pResult[nz++] = basis_58[*pi++]; @@ -117,7 +117,7 @@ int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t size = (int32_t)(pe - pb) * 733 / 1000 + 1; if (size > TBASE_BUF_SIZE) { if (!(pbuf = taosMemoryCalloc(1, size))) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } bfree = true; } @@ -149,7 +149,7 @@ int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - it) + 1); if (!pResult) { if (bfree) taosMemoryFree(pbuf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memset(pResult, 0, nz); diff --git a/source/util/src/tbloomfilter.c b/source/util/src/tbloomfilter.c index c87c482167..841657e628 100644 --- a/source/util/src/tbloomfilter.c +++ b/source/util/src/tbloomfilter.c @@ -44,7 +44,7 @@ int32_t tBloomFilterInit(uint64_t expectedEntries, double errorRate, SBloomFilte } SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter)); if (pBF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } pBF->expectedEntries = expectedEntries; @@ -65,7 +65,7 @@ int32_t tBloomFilterInit(uint64_t expectedEntries, double errorRate, SBloomFilte pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t)); if (pBF->buffer == NULL) { tBloomFilterDestroy(pBF); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } (*ppBF) = pBF; @@ -152,7 +152,7 @@ int32_t tBloomFilterDecode(SDecoder* pDecoder, SBloomFilter** ppBF) { int32_t lino = 0; SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter)); if (!pBF) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } pBF->buffer = NULL; diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index c6da1537f5..d20857453d 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -45,7 +45,7 @@ extern char **environ; int32_t cfgInit(SConfig **ppCfg) { SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig)); if (pCfg == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pCfg->array = taosArrayInit(32, sizeof(SConfigItem)); @@ -1453,7 +1453,7 @@ struct SConfigIter { int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter) { SConfigIter *pIter = taosMemoryCalloc(1, sizeof(SConfigIter)); if (pIter == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pIter->pConf = pConf; diff --git a/source/util/src/tgeosctx.c b/source/util/src/tgeosctx.c index ddd04b1e88..8de8d26fad 100644 --- a/source/util/src/tgeosctx.c +++ b/source/util/src/tgeosctx.c @@ -93,7 +93,7 @@ int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) { SGeosContext *tlGeosCtxObj = (SGeosContext *)taosMemoryCalloc(1, sizeof(SGeosContext)); if (!tlGeosCtxObj) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } if ((taosThreadSetSpecific(tlGeosCtxKey, (const void *)tlGeosCtxObj)) != 0) { taosMemoryFreeClear(tlGeosCtxObj); diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 1d2b3f003c..4cf5917f7c 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -320,7 +320,7 @@ int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, v } *pObj = taosMemoryCalloc(1, objSize); if (NULL == *pObj) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return func(pJsonObj, *pObj); } diff --git a/source/util/src/tlist.c b/source/util/src/tlist.c index 3bc24328cc..0fa73677be 100644 --- a/source/util/src/tlist.c +++ b/source/util/src/tlist.c @@ -84,7 +84,7 @@ int32_t tdListPrepend(SList *list, void *data) { int32_t tdListAppend(SList *list, const void *data) { SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize); if (node == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy((void *)(node->data), data, list->eleSize); diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index 7faff88155..cfbd875890 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -112,7 +112,7 @@ static int taosLRUEntryTableInit(SLRUEntryTable *table, int maxUpperHashBits) { table->lengthBits = 4; table->list = taosMemoryCalloc(1 << table->lengthBits, sizeof(SLRUEntry *)); if (!table->list) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } table->elems = 0; diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 780a6c94f1..de21a61127 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -62,7 +62,7 @@ void taosSetQueueCapacity(STaosQueue *queue, int64_t size) { queue->itemLimit = int32_t taosOpenQueue(STaosQueue **queue) { *queue = taosMemoryCalloc(1, sizeof(STaosQueue)); if (*queue == NULL) { - return (terrno = TSDB_CODE_OUT_OF_MEMORY); + return terrno; } int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL); @@ -162,7 +162,7 @@ int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void ** STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size); if (pNode == NULL) { (void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize); - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pNode->dataSize = dataSize; @@ -260,7 +260,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { int32_t taosAllocateQall(STaosQall **qall) { *qall = taosMemoryCalloc(1, sizeof(STaosQall)); if (*qall == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return 0; } @@ -333,7 +333,7 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { int32_t taosOpenQset(STaosQset **qset) { *qset = taosMemoryCalloc(sizeof(STaosQset), 1); if (*qset == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)taosThreadMutexInit(&(*qset)->mutex, NULL); diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 0eac7b4427..e7161f7284 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -67,13 +67,13 @@ int32_t taosOpenRef(int32_t max, RefFp fp) { nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max); if (nodeList == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max); if (lockedBy == NULL) { taosMemoryFree(nodeList); - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)taosThreadMutexLock(&tsRefMutex); @@ -157,7 +157,7 @@ int64_t taosAddRef(int32_t rsetId, void *p) { pNode = taosMemoryCalloc(sizeof(SRefNode), 1); if (pNode == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } rid = atomic_add_fetch_64(&pSet->rid, 1); diff --git a/source/util/src/tscalablebf.c b/source/util/src/tscalablebf.c index 4fac5a2b4f..ebc076e02e 100644 --- a/source/util/src/tscalablebf.c +++ b/source/util/src/tscalablebf.c @@ -38,7 +38,7 @@ int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf* } SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf)); if (pSBf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } pSBf->maxBloomFilters = DEFAULT_MAX_BLOOMFILTERS; @@ -218,7 +218,7 @@ int32_t tScalableBfDecode(SDecoder* pDecoder, SScalableBf** ppSBf) { int32_t lino = 0; SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf)); if (!pSBf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } pSBf->hashFn1 = HASH_FUNCTION_1; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 1fc0d16d57..a1d2d8e38c 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -31,7 +31,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { pool->workers = taosMemoryCalloc(pool->max, sizeof(SQueueWorker)); if (pool->workers == NULL) { taosCloseQset(pool->qset); - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)taosThreadMutexInit(&pool->mutex, NULL); @@ -310,7 +310,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) { pool->nextId = 0; pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker)); if (pool->workers == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)taosThreadMutexInit(&pool->mutex, NULL); @@ -459,7 +459,7 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) case QWORKER_POOL: { SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool)); if (!pPool) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pPool->name = pCfg->name; pPool->min = pCfg->min; @@ -477,7 +477,7 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) case QUERY_AUTO_QWORKER_POOL: { SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool)); if (!pPool) { - return (terrno = TSDB_CODE_OUT_OF_MEMORY); + return terrno; } pPool->name = pCfg->name; pPool->min = pCfg->min; @@ -812,7 +812,7 @@ int32_t tQueryAutoQWorkerInit(SQueryAutoQWorkerPool *pool) { if (!pool->pCb) { pool->pCb = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPoolCB)); - if (!pool->pCb) return TSDB_CODE_OUT_OF_MEMORY; + if (!pool->pCb) return terrno; pool->pCb->pPool = pool; pool->pCb->beforeBlocking = tQueryAutoQWorkerBeforeBlocking; pool->pCb->afterRecoverFromBlocking = tQueryAutoQWorkerRecoverFromBlocking; From 11b3faee8e5d3fe20d3d7fd488ed9ca056da89f2 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Wed, 11 Sep 2024 08:56:39 +0800 Subject: [PATCH 52/90] remove (void) from parser/planner/nodes/sma --- include/common/tname.h | 2 +- source/client/src/clientMain.c | 2 +- source/client/src/clientRawBlockWrite.c | 16 +-- source/client/src/clientSml.c | 7 +- source/common/src/tname.c | 3 +- source/dnode/mnode/impl/src/mndSma.c | 12 +- source/libs/nodes/src/nodesUtilFuncs.c | 15 ++- source/libs/parser/src/parAuthenticator.c | 5 +- source/libs/parser/src/parTranslater.c | 132 ++++++++++++---------- 9 files changed, 110 insertions(+), 84 deletions(-) diff --git a/include/common/tname.h b/include/common/tname.h index f0a68f28c4..c7c34310b9 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -37,7 +37,7 @@ typedef struct SName { char tname[TSDB_TABLE_NAME_LEN]; } SName; -SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName); +void toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName); int32_t tNameExtractFullName(const SName* name, char* dst); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 1c1fff9b7b..3d72c14fdd 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1526,7 +1526,7 @@ int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); SName tableName; - (void)toName(pTscObj->acctId, db, table, &tableName); + toName(pTscObj->acctId, db, table, &tableName); SVgroupInfo vgInfo; code = catalogGetTableHashVgroup(pCtg, &conn, &tableName, &vgInfo); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index d5785cce6b..0f8f0ec4e7 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -946,7 +946,8 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) { pReq.suid); STscObj* pTscObj = pRequest->pTscObj; SName tableName = {0}; - RAW_RETURN_CHECK(tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name)); + toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName); + RAW_RETURN_CHECK(tNameExtractFullName(&tableName, pReq.name)); SCmdMsgInfo pCmdMsg = {0}; pCmdMsg.epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); pCmdMsg.msgType = TDMT_MND_CREATE_STB; @@ -1021,7 +1022,7 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) { .requestObjRefId = pRequest->self, .mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp)}; SName pName = {0}; - (void)toName(pRequest->pTscObj->acctId, pRequest->pDb, req.name, + toName(pRequest->pTscObj->acctId, pRequest->pDb, req.name, &pName); // ignore the return value, always return pName STableMeta* pTableMeta = NULL; code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta); @@ -1045,7 +1046,8 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) { pReq.suid); STscObj* pTscObj = pRequest->pTscObj; SName tableName = {0}; - if (tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name) != 0) { + toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName); + if (tNameExtractFullName(&tableName, pReq.name) != 0) { code = TSDB_CODE_INVALID_PARA; goto end; } @@ -1150,7 +1152,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) { SVgroupInfo pInfo = {0}; SName pName = {0}; - (void)toName(pTscObj->acctId, pRequest->pDb, pCreateReq->name, &pName); + toName(pTscObj->acctId, pRequest->pDb, pCreateReq->name, &pName); code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo); if (code != TSDB_CODE_SUCCESS) { goto end; @@ -1163,7 +1165,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) { SName sName = {0}; tb_uid_t oldSuid = pCreateReq->ctb.suid; // pCreateReq->ctb.suid = processSuid(pCreateReq->ctb.suid, pRequest->pDb); - (void)toName(pTscObj->acctId, pRequest->pDb, pCreateReq->ctb.stbName, &sName); + toName(pTscObj->acctId, pRequest->pDb, pCreateReq->ctb.stbName, &sName); code = catalogGetTableMeta(pCatalog, &conn, &sName, &pTableMeta); if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) { code = TSDB_CODE_SUCCESS; @@ -1307,7 +1309,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) { SVgroupInfo pInfo = {0}; SName pName = {0}; - (void)toName(pTscObj->acctId, pRequest->pDb, pDropReq->name, &pName); + toName(pTscObj->acctId, pRequest->pDb, pDropReq->name, &pName); RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo)); STableMeta* pTableMeta = NULL; @@ -1451,7 +1453,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) { SVgroupInfo pInfo = {0}; SName pName = {0}; - (void)toName(pTscObj->acctId, pRequest->pDb, req.tbName, &pName); + toName(pTscObj->acctId, pRequest->pDb, req.tbName, &pName); RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo)); pArray = taosArrayInit(1, sizeof(void*)); RAW_NULL_CHECK(pArray); diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 05678e1cbf..ad2655bc94 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -116,7 +116,7 @@ static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo *conn, const char return TSDB_CODE_SML_INVALID_DATA; } } else { - (void)toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName); //ignore + toName(info->taos->acctId, info->pRequest->pDb, pTabName, &pAuth.tbName); //ignore } pAuth.type = type; @@ -1113,7 +1113,10 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, pReq.commentLen = -1; pReq.igExists = true; - (void)tNameExtractFullName(pName, pReq.name); + code = tNameExtractFullName(pName, pReq.name); + if (TSDB_CODE_SUCCESS != code) { + goto end; + } pCmdMsg.epSet = getEpSet_s(&info->taos->pAppInfo->mgmtEp); pCmdMsg.msgType = TDMT_MND_CREATE_STB; diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 8d0f324509..4bb89464d0 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -87,12 +87,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in #endif -SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName) { +void toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName) { pName->type = TSDB_TABLE_NAME_T; pName->acctId = acctId; snprintf(pName->dbname, sizeof(pName->dbname), "%s", pDbName); snprintf(pName->tname, sizeof(pName->tname), "%s", pTableName); - return pName; } int32_t tNameExtractFullName(const SName* name, char* dst) { diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 284d65cd9c..f91f7d49cc 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -368,7 +368,11 @@ static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma, SEncoder encoder = {0}; int32_t contLen; SName name = {0}; - (void)tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + int32_t code = tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + return NULL; + } SVDropTSmaReq req = {0}; req.indexUid = pSma->uid; @@ -1669,8 +1673,7 @@ static int32_t mndSetUpdateDbTsmaVersionPrepareLogs(SMnode *pMnode, STrans *pTra TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); - TAOS_RETURN(code); + TAOS_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY)); } static int32_t mndSetUpdateDbTsmaVersionCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { @@ -1686,8 +1689,7 @@ static int32_t mndSetUpdateDbTsmaVersionCommitLogs(SMnode *pMnode, STrans *pTran TAOS_RETURN(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); - TAOS_RETURN(code); + TAOS_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); } static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 1d6c19346a..8e2b739934 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -235,7 +235,10 @@ void nodesDestroyAllocatorSet() { int64_t refId = 0; while (NULL != pAllocator) { refId = pAllocator->self; - (void)taosRemoveRef(g_allocatorReqRefPool, refId); + int32_t code = taosRemoveRef(g_allocatorReqRefPool, refId); + if (TSDB_CODE_SUCCESS != code) { + nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%"PRId64, __func__, __LINE__, g_allocatorReqRefPool, refId); + } pAllocator = taosIterateRef(g_allocatorReqRefPool, refId); } taosCloseRef(g_allocatorReqRefPool); @@ -328,7 +331,10 @@ void nodesDestroyAllocator(int64_t allocatorId) { return; } - (void)taosRemoveRef(g_allocatorReqRefPool, allocatorId); + int32_t code = taosRemoveRef(g_allocatorReqRefPool, allocatorId); + if (TSDB_CODE_SUCCESS != code) { + nodesError("failed to remove ref at: %s:%d, rsetId:%d, refId:%"PRId64, __func__, __LINE__, g_allocatorReqRefPool, allocatorId); + } } static int32_t makeNode(ENodeType type, int32_t size, SNode** ppNode) { @@ -1090,7 +1096,10 @@ void nodesDestroyNode(SNode* pNode) { pStmt->destroyParseFileCxt(&pStmt->pParFileCxt); } - (void)taosCloseFile(&pStmt->fp); + int32_t code = taosCloseFile(&pStmt->fp); + if (TSDB_CODE_SUCCESS != code) { + nodesError("failed to close file: %s:%d", __func__, __LINE__); + } break; } case QUERY_NODE_CREATE_DATABASE_STMT: diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 60cc1024bf..7fbbd90d40 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -46,7 +46,7 @@ static int32_t setUserAuthInfo(SParseContext* pCxt, const char* pDbName, const c int32_t code = tNameSetDbName(&pAuth->tbName, pCxt->acctId, pDbName, strlen(pDbName)); if (TSDB_CODE_SUCCESS != code) return code; } else { - (void)toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName); + toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName); } pAuth->type = type; pAuth->isView = isView; @@ -171,8 +171,9 @@ static EDealRes authSelectImpl(SNode* pNode, void* pContext) { #ifdef TD_ENTERPRISE SName name; STableMeta* pTableMeta = NULL; + toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name); int32_t code = getTargetMetaImpl( - pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name), &pTableMeta, true); + pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, &name, &pTableMeta, true); if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) { isView = true; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index a0b8c13e58..ebe6c82193 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -526,7 +526,8 @@ static int32_t getTargetMeta(STranslateContext* pCxt, const SName* pName, STable static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const char* pTableName, STableMeta** pMeta) { SName name; - return getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name), pMeta, false); + toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); + return getTargetMeta(pCxt, &name, pMeta, false); } static int32_t getTableCfg(STranslateContext* pCxt, const SName* pName, STableCfg** pCfg) { @@ -557,7 +558,7 @@ static int32_t refreshGetTableMeta(STranslateContext* pCxt, const char* pDbName, STableMeta** pMeta) { SParseContext* pParCxt = pCxt->pParseCxt; SName name; - (void)toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); + toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); int32_t code = TSDB_CODE_SUCCESS; if (pParCxt->async) { code = getTableMetaFromCache(pCxt->pMetaCache, &name, pMeta); @@ -635,7 +636,8 @@ static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pNam static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName, const char* pTableName, SVgroupInfo* pInfo) { SName name; - return getTableHashVgroupImpl(pCxt, toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name), pInfo); + toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name); + return getTableHashVgroupImpl(pCxt, &name, pInfo); } static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, @@ -4016,7 +4018,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo SName tsmaTargetTbName = {0}; SVgroupInfo vgInfo = {0}; bool exists = false; - (void)toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); + toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); int32_t len = snprintf(buf, TSDB_TABLE_FNAME_LEN + TSDB_TABLE_NAME_LEN, "%s.%s_%s", pTsma->dbFName, pTsma->name, pRealTable->table.tableName); len = taosCreateMD5Hash(buf, len); @@ -4678,9 +4680,8 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinPare // The SRealTableNode created through ROLLUP already has STableMeta. if (NULL == pRealTable->pMeta) { SName name; - code = getTargetMeta( - pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), - &(pRealTable->pMeta), true); + toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name); + code = getTargetMeta( pCxt, &name, &(pRealTable->pMeta), true); if (TSDB_CODE_SUCCESS != code) { (void)generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); return code; @@ -6232,7 +6233,7 @@ static void findVgroupsFromEqualTbname(STranslateContext* pCxt, SArray* aTbnames for (int j = 0; j < nTbls; ++j) { SName snameTb; char* tbName = taosArrayGetP(aTbnames, j); - (void)toName(pCxt->pParseCxt->acctId, dbName, tbName, &snameTb); + toName(pCxt->pParseCxt->acctId, dbName, tbName, &snameTb); SVgroupInfo vgInfo = {0}; bool bExists; int32_t code = catalogGetCachedTableHashVgroup(pCxt->pParseCxt->pCatalog, &snameTb, &vgInfo, &bExists); @@ -6261,7 +6262,7 @@ static int32_t replaceToChildTableQuery(STranslateContext* pCxt, SEqCondTbNameTa int32_t code = 0; SRealTableNode* pRealTable = pInfo->pRealTable; char* tbName = taosArrayGetP(pInfo->aTbnames, 0); - (void)toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, tbName, &snameTb); + toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, tbName, &snameTb); STableMeta* pMeta = NULL; TAOS_CHECK_RETURN(catalogGetCachedTableMeta(pCxt->pParseCxt->pCatalog, &snameTb, &pMeta)); @@ -6282,7 +6283,7 @@ static int32_t replaceToChildTableQuery(STranslateContext* pCxt, SEqCondTbNameTa for (int32_t i = 0; i < pRealTable->pTsmas->size; ++i) { STableTSMAInfo* pTsma = taosArrayGetP(pRealTable->pTsmas, i); SName tsmaTargetTbName = {0}; - (void)toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); + toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, "", &tsmaTargetTbName); int32_t len = snprintf(buf, TSDB_TABLE_FNAME_LEN + TSDB_TABLE_NAME_LEN, "%s.%s_%s", pTsma->dbFName, pTsma->name, pRealTable->table.tableName); len = taosCreateMD5Hash(buf, len); @@ -8822,7 +8823,8 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm } if (TSDB_CODE_SUCCESS == code) { pReq->numOfFuncs = taosArrayGetSize(pReq->pFuncs); - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pReq->name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName); + code = tNameExtractFullName(&tableName, pReq->name); } if (TSDB_CODE_SUCCESS == code) code = collectUseTable(&tableName, pCxt->pTables); @@ -8866,19 +8868,20 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt SDropTableClause* pClause = (SDropTableClause*)nodesListGetNode(pStmt->pTables, 0); SName tableName; if (pStmt->withTsma) return TSDB_CODE_SUCCESS; - return doTranslateDropSuperTable( - pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), pClause->ignoreNotExists); + toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName); + return doTranslateDropSuperTable( pCxt, &tableName, pClause->ignoreNotExists); } static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableStmt* pStmt) { SName tableName; - return doTranslateDropSuperTable(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), - pStmt->ignoreNotExists); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName); + return doTranslateDropSuperTable(pCxt, &tableName, pStmt->ignoreNotExists); } static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, SMAlterStbReq* pAlterReq) { SName tableName; - int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pAlterReq->name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName); + int32_t code = tNameExtractFullName(&tableName, pAlterReq->name); if (TSDB_CODE_SUCCESS != code) return code; pAlterReq->alterType = pStmt->alterType; @@ -9394,10 +9397,12 @@ static int32_t getSmaIndexAst(STranslateContext* pCxt, SCreateIndexStmt* pStmt, static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateSmaReq* pReq) { SName name; - int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->name); + toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name); + int32_t code = tNameExtractFullName(&name, pReq->name); if (TSDB_CODE_SUCCESS == code) { memset(&name, 0, sizeof(SName)); - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stb); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + code = tNameExtractFullName(&name, pReq->stb); } if (TSDB_CODE_SUCCESS == code) { pReq->igExists = pStmt->ignoreExists; @@ -9545,10 +9550,12 @@ static int32_t buildCreateFullTextReq(STranslateContext* pCxt, SCreateIndexStmt* static int32_t buildCreateTagIndexReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SCreateTagIndexReq* pReq) { SName name; - int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), pReq->idxName); + toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name); + int32_t code = tNameExtractFullName(&name, pReq->idxName); if (TSDB_CODE_SUCCESS == code) { memset(&name, 0, sizeof(SName)); - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), pReq->stbName); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + code = tNameExtractFullName(&name, pReq->stbName); } if (TSDB_CODE_SUCCESS == code) { memset(&name, 0, sizeof(SName)); @@ -9584,8 +9591,8 @@ static int32_t translateCreateNormalIndex(STranslateContext* pCxt, SCreateIndexS int32_t code = 0; SName name; STableMeta* pMeta = NULL; - - code = getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name), &pMeta, false); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + code = getTargetMeta(pCxt, &name, &pMeta, false); if (code) { taosMemoryFree(pMeta); return code; @@ -9627,7 +9634,8 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) { SMDropSmaReq dropSmaReq = {0}; SName name; - int32_t code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), dropSmaReq.name); + toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name); + int32_t code = tNameExtractFullName(&name, dropSmaReq.name); if (TSDB_CODE_SUCCESS != code) return code; dropSmaReq.igNotExists = pStmt->ignoreNotExists; return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq); @@ -9702,11 +9710,11 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS SName name; if ('\0' != pStmt->subSTbName[0]) { pReq->subType = TOPIC_SUB_TYPE__TABLE; - (void)toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); (void)tNameGetFullDbName(&name, pReq->subDbName); if (TSDB_CODE_SUCCESS == code) { - (void)tNameExtractFullName(&name, pReq->subStbName); - if (pStmt->pQuery != NULL) { + code = tNameExtractFullName(&name, pReq->subStbName); + if (TSDB_CODE_SUCCESS == code && pStmt->pQuery != NULL) { code = nodesNodeToString(pStmt->pQuery, false, &pReq->ast, NULL); } } @@ -9829,8 +9837,8 @@ static int32_t buildQueryForTableTopic(STranslateContext* pCxt, SCreateTopicStmt .mgmtEps = pParCxt->mgmtEpSet}; SName name; STableMeta* pMeta = NULL; - int32_t code = - getTargetMeta(pCxt, toName(pParCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name), &pMeta, false); + toName(pParCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name); + int32_t code = getTargetMeta(pCxt, &name, &pMeta, false); if (code) { taosMemoryFree(pMeta); return code; @@ -9952,7 +9960,7 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { int32_t origCode = code; SName name; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); SViewMeta* pMeta = NULL; code = getViewMetaFromMetaCache(pCxt, &name, &pMeta); if (TSDB_CODE_SUCCESS != code) { @@ -10072,9 +10080,8 @@ static int32_t checkCreateStream(STranslateContext* pCxt, SCreateStreamStmt* pSt SName name; STableMeta* pMeta = NULL; int8_t tableType = 0; - int32_t code = - getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), - &pMeta, true); + toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name); + int32_t code = getTargetMeta(pCxt, &name, &pMeta, true); if (NULL != pMeta) { tableType = pMeta->tableType; taosMemoryFree(pMeta); @@ -11103,10 +11110,11 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt* if ('\0' != pStmt->targetTabName[0]) { strcpy(name.dbname, pStmt->targetDbName); strcpy(name.tname, pStmt->targetTabName); - (void)tNameExtractFullName(&name, pReq->targetStbFullName); + code = tNameExtractFullName(&name, pReq->targetStbFullName); + } + if (TSDB_CODE_SUCCESS == code) { + code = buildCreateStreamQuery(pCxt, pStmt, pReq); } - - code = buildCreateStreamQuery(pCxt, pStmt, pReq); if (TSDB_CODE_SUCCESS == code) { pReq->sql = taosStrdup(pCxt->pParseCxt->pSql); if (NULL == pReq->sql) { @@ -11312,7 +11320,7 @@ static int32_t translateCreateView(STranslateContext* pCxt, SCreateViewStmt* pSt SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA}; SName name; char dbFName[TSDB_DB_FNAME_LEN]; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); (void)tNameGetFullDbName(&name, dbFName); int32_t code = validateCreateView(pCxt, pStmt); @@ -11363,7 +11371,7 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt) return TSDB_CODE_OUT_OF_MEMORY; } dropReq.igNotExists = pStmt->ignoreNotExists; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); code = collectUseTable(&name, pCxt->pTargetTables); } @@ -11399,7 +11407,8 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { int64_t s = taosReadFile(tfile, *buf, *len); if (s != *len) { - (void)taosCloseFile(&tfile); + int32_t code = taosCloseFile(&tfile); + qError("failed to close file: %s in %s:%d, err: %s", pName, __func__, __LINE__, tstrerror(code)); taosMemoryFreeClear(*buf); return TSDB_CODE_APP_ERROR; } @@ -11473,8 +11482,8 @@ static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt, int32_t code = createRealTableForGrantTable(pStmt, &pTable); if (TSDB_CODE_SUCCESS == code) { SName name; - code = getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name), - &(pTable->pMeta), false); + toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name); + code = getTargetMeta(pCxt, &name, &(pTable->pMeta), false); if (code) { nodesDestroyNode((SNode*)pTable); return code; @@ -11516,8 +11525,8 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) { if (0 != pStmt->tabName[0]) { SName name; STableMeta* pTableMeta = NULL; - code = - getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name), &pTableMeta, true); + toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name); + code = getTargetMeta(pCxt, &name, &pTableMeta, true); if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_PAR_TABLE_NOT_EXIST != code) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); @@ -11552,8 +11561,8 @@ static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) { if (0 != pStmt->tabName[0]) { SName name; STableMeta* pTableMeta = NULL; - code = - getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name), &pTableMeta, true); + toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name); + code = getTargetMeta(pCxt, &name, &pTableMeta, true); if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_PAR_TABLE_NOT_EXIST != code) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); @@ -11667,7 +11676,7 @@ static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTabl int32_t code = getDBCfg(pCxt, pStmt->dbName, (SDbCfgInfo*)pStmt->pDbCfg); if (TSDB_CODE_SUCCESS == code) { SName name; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); code = getTableCfg(pCxt, &name, (STableCfg**)&pStmt->pTableCfg); } return code; @@ -11678,7 +11687,7 @@ static int32_t translateShowCreateView(STranslateContext* pCxt, SShowCreateViewS return TSDB_CODE_OPS_NOT_SUPPORT; #else SName name; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name); return getViewMetaFromMetaCache(pCxt, &name, (SViewMeta**)&pStmt->pViewMeta); #endif } @@ -11949,10 +11958,11 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm SName name; SDbCfgInfo pDbInfo = {0}; int32_t code = TSDB_CODE_SUCCESS; - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), pReq->name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name); + code = tNameExtractFullName(&name, pReq->name); if (TSDB_CODE_SUCCESS == code) { memset(&name, 0, sizeof(SName)); - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, useTbName); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, useTbName); code = tNameExtractFullName(useTbName, pReq->stb); } if (TSDB_CODE_SUCCESS == code) { @@ -12025,7 +12035,8 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm if (TSDB_CODE_SUCCESS == code) { memset(useTbName, 0, sizeof(SName)); memcpy(pStmt->originalTbName, pRecursiveTsma->tb, TSDB_TABLE_NAME_LEN); - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pRecursiveTsma->tb, useTbName), pReq->stb); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pRecursiveTsma->tb, useTbName); + code = tNameExtractFullName(useTbName, pReq->stb); } if (TSDB_CODE_SUCCESS == code) { numOfCols = pRecursiveTsma->pUsedCols->size; @@ -12146,7 +12157,7 @@ int32_t translatePostCreateTSMA(SParseContext* pParseCxt, SQuery* pQuery, SSData if (TSDB_CODE_SUCCESS == code) { SName name = {0}; - (void)toName(pParseCxt->acctId, pStmt->dbName, pStmt->originalTbName, &name); + toName(pParseCxt->acctId, pStmt->dbName, pStmt->originalTbName, &name); code = collectUseTable(&name, cxt.pTargetTables); } @@ -12165,13 +12176,14 @@ static int32_t translateDropTSMA(STranslateContext* pCxt, SDropTSMAStmt* pStmt) SMDropSmaReq dropReq = {0}; SName name; STableTSMAInfo* pTsma = NULL; - code = tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name), dropReq.name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tsmaName, &name); + code = tNameExtractFullName(&name, dropReq.name); if (TSDB_CODE_SUCCESS == code) { dropReq.igNotExists = pStmt->ignoreNotExists; code = getTsma(pCxt, &name, &pTsma); } if (code == TSDB_CODE_SUCCESS) { - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pTsma->tb, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pTsma->tb, &name); code = collectUseTable(&name, pCxt->pTargetTables); } if (TSDB_CODE_SUCCESS == code) @@ -13071,10 +13083,8 @@ static int32_t checkShowTags(STranslateContext* pCxt, const SShowStmt* pShow) { int32_t code = 0; SName name; STableMeta* pTableMeta = NULL; - code = getTargetMeta(pCxt, - toName(pCxt->pParseCxt->acctId, ((SValueNode*)pShow->pDbName)->literal, - ((SValueNode*)pShow->pTbName)->literal, &name), - &pTableMeta, true); + toName(pCxt->pParseCxt->acctId, ((SValueNode*)pShow->pDbName)->literal, ((SValueNode*)pShow->pTbName)->literal, &name); + code = getTargetMeta(pCxt, &name, &pTableMeta, true); if (TSDB_CODE_SUCCESS != code) { code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); goto _exit; @@ -13433,7 +13443,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { int32_t code = checkCreateTable(pCxt, pStmt, false); SVgroupInfo info = {0}; SName name; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); if (TSDB_CODE_SUCCESS == code) { code = getTableHashVgroupImpl(pCxt, &name, &info); } @@ -13681,7 +13691,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla } if (TSDB_CODE_SUCCESS == code) { SName name; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); code = collectUseTable(&name, pCxt->pTargetTables); } @@ -14447,7 +14457,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; SName name; - (void)toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); + toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); int32_t code = buildDropTableVgroupHashmap(pCxt, pClause, &name, &tableType, pVgroupHashmap); if (TSDB_CODE_SUCCESS != code) { taosHashCleanup(pVgroupHashmap); @@ -14523,7 +14533,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS SArray* pTsmas = NULL; int32_t code = TSDB_CODE_SUCCESS; if (pCxt->pMetaCache) { - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas); if (code != TSDB_CODE_SUCCESS) return code; if (pTsmas && pTsmas->size > 0) return TSDB_CODE_TSMA_MUST_BE_DROPPED; @@ -14707,7 +14717,7 @@ static int32_t buildRenameColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt SArray* pTsmas = NULL; SName tbName; int32_t code = 0; - (void)toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName); if (pCxt->pMetaCache) code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas); if (TSDB_CODE_SUCCESS != code) return code; if (pTsmas && pTsmas->size > 0) { From b38d9da0e14225acec17a1039e9b18a7a2271b8f Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 06:26:22 +0000 Subject: [PATCH 53/90] feat:add return value --- source/dnode/mnode/impl/src/mndDb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 9c02fd6e5d..6467dfcf11 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -2333,9 +2333,9 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, char keep1Str[128] = {0}; char keep2Str[128] = {0}; - formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0); - formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1); - formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2); + int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0); + int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1); + int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2); if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str); From f5e2a36f2382585af829bb6da0542adbe12c6425 Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 06:29:35 +0000 Subject: [PATCH 54/90] feat:update --- source/libs/command/src/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 0e5f2f4cbd..70a9b39229 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -345,12 +345,12 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) { } int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes) { - int len = 0; + int32_t len = 0; if (timeInMinutes % 1440 == 0) { - int days = timeInMinutes / 1440; + int32_t days = timeInMinutes / 1440; len = sprintf(buffer, "%dd", days); } else if (timeInMinutes % 60 == 0) { - int hours = timeInMinutes / 60; + int32_t hours = timeInMinutes / 60; len = sprintf(buffer, "%dh", hours); } else { len = sprintf(buffer, "%dm", timeInMinutes); From 28df9fe2851243347cb54f9d36c50e0ec4094a04 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 14:30:59 +0800 Subject: [PATCH 55/90] refactor: remove void --- source/libs/stream/src/streamCheckStatus.c | 83 +++++++++++++++------- source/libs/stream/src/streamDispatch.c | 6 +- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index 41124d8543..274ec5043c 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -27,7 +27,7 @@ static void streamTaskInitTaskCheckInfo(STaskCheckInfo* pInfo, STaskOutputInf static int32_t streamTaskStartCheckDownstream(STaskCheckInfo* pInfo, const char* id); static void streamTaskCompleteCheckRsp(STaskCheckInfo* pInfo, bool lock, const char* id); static void streamTaskAddReqInfo(STaskCheckInfo* pInfo, int64_t reqId, int32_t taskId, int32_t vgId, const char* id); -static void doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p); +static int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p); static void handleTimeoutDownstreamTasks(SStreamTask* pTask, SArray* pTimeoutList); static void handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList); static int32_t streamTaskUpdateCheckInfo(STaskCheckInfo* pInfo, int32_t taskId, int32_t status, int64_t rspTs, @@ -83,6 +83,7 @@ void streamTaskSendCheckMsg(SStreamTask* pTask) { SDataRange* pRange = &pTask->dataRange; STimeWindow* pWindow = &pRange->window; const char* idstr = pTask->id.idStr; + int32_t code = 0; SStreamTaskCheckReq req = { .streamId = pTask->id.streamId, @@ -102,11 +103,11 @@ void streamTaskSendCheckMsg(SStreamTask* pTask) { streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pDispatch->taskId, pDispatch->nodeId, idstr); stDebug("s-task:%s (vgId:%d) stage:%" PRId64 " check single downstream task:0x%x(vgId:%d) ver:%" PRId64 "-%" PRId64 - " window:%" PRId64 "-%" PRId64 "QID:0x%" PRIx64, + " window:%" PRId64 "-%" PRId64 " QID:0x%" PRIx64, idstr, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, pRange->range.minVer, pRange->range.maxVer, pWindow->skey, pWindow->ekey, req.reqId); - (void)streamSendCheckMsg(pTask, &req, pTask->outputInfo.fixedDispatcher.nodeId, + code = streamSendCheckMsg(pTask, &req, pTask->outputInfo.fixedDispatcher.nodeId, &pTask->outputInfo.fixedDispatcher.epSet); } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) { @@ -128,15 +129,19 @@ void streamTaskSendCheckMsg(SStreamTask* pTask) { streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pVgInfo->taskId, pVgInfo->vgId, idstr); stDebug("s-task:%s (vgId:%d) stage:%" PRId64 - " check downstream task:0x%x (vgId:%d) (shuffle), idx:%d,QID:0x%" PRIx64, + " check downstream task:0x%x (vgId:%d) (shuffle), idx:%d, QID:0x%" PRIx64, idstr, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, i, req.reqId); - (void)streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); + code = streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); } } else { // for sink task, set it ready directly. stDebug("s-task:%s (vgId:%d) set downstream ready, since no downstream", idstr, pTask->info.nodeId); streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, idstr); processDownstreamReadyRsp(pTask); } + + if (code) { + stError("s-task:%s failed to send check msg to downstream, code:%s", idstr, tstrerror(code)); + } } void streamTaskProcessCheckMsg(SStreamMeta* pMeta, SStreamTaskCheckReq* pReq, SStreamTaskCheckRsp* pRsp) { @@ -243,13 +248,13 @@ int32_t streamTaskProcessCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* int32_t streamTaskSendCheckRsp(const SStreamMeta* pMeta, int32_t vgId, SStreamTaskCheckRsp* pRsp, SRpcHandleInfo* pRpcInfo, int32_t taskId) { SEncoder encoder; - int32_t code; + int32_t code = 0; int32_t len; tEncodeSize(tEncodeStreamTaskCheckRsp, pRsp, len, code); if (code < 0) { stError("vgId:%d failed to encode task check rsp, s-task:0x%x", pMeta->vgId, taskId); - return -1; + return TSDB_CODE_INVALID_MSG; } void* buf = rpcMallocCont(sizeof(SMsgHead) + len); @@ -257,13 +262,13 @@ int32_t streamTaskSendCheckRsp(const SStreamMeta* pMeta, int32_t vgId, SStreamTa void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tEncoderInit(&encoder, (uint8_t*)abuf, len); - (void)tEncodeStreamTaskCheckRsp(&encoder, pRsp); + code = tEncodeStreamTaskCheckRsp(&encoder, pRsp); tEncoderClear(&encoder); SRpcMsg rspMsg = {.code = 0, .pCont = buf, .contLen = sizeof(SMsgHead) + len, .info = *pRpcInfo}; - tmsgSendRsp(&rspMsg); - return 0; + + return code; } void streamTaskStartMonitorCheckRsp(SStreamTask* pTask) { @@ -316,8 +321,11 @@ void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) { pInfo->pList = NULL; if (pInfo->checkRspTmr != NULL) { - (void)taosTmrStop(pInfo->checkRspTmr); + bool succ = taosTmrStop(pInfo->checkRspTmr); pInfo->checkRspTmr = NULL; + if (!succ) { + stError("failed to stop checkrsp tmr"); // todo: add id + } } streamMutexDestroy(&pInfo->checkInfoLock); @@ -326,11 +334,17 @@ void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void processDownstreamReadyRsp(SStreamTask* pTask) { EStreamTaskEvent event = (pTask->info.fillHistory == 0) ? TASK_EVENT_INIT : TASK_EVENT_INIT_SCANHIST; - (void)streamTaskOnHandleEventSuccess(pTask->status.pSM, event, NULL, NULL); + int32_t code = streamTaskOnHandleEventSuccess(pTask->status.pSM, event, NULL, NULL); + if (code) { + stError("s-task:%s failed to set event succ, code:%s", pTask->id.idStr, tstrerror(code)); + } int64_t checkTs = pTask->execInfo.checkTs; int64_t readyTs = pTask->execInfo.readyTs; - (void)streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, checkTs, readyTs, true); + code = streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, checkTs, readyTs, true); + if (code) { + stError("s-task:%s failed to record the downstream task status, code:%s", pTask->id.idStr, tstrerror(code)); + } if (pTask->status.taskStatus == TASK_STATUS__HALT) { if (!HAS_RELATED_FILLHISTORY_TASK(pTask) || (pTask->info.fillHistory != 0)) { @@ -341,9 +355,9 @@ void processDownstreamReadyRsp(SStreamTask* pTask) { // halt it self for count window stream task until the related fill history task completed. stDebug("s-task:%s level:%d initial status is %s from mnode, set it to be halt", pTask->id.idStr, pTask->info.taskLevel, streamTaskGetStatusStr(pTask->status.taskStatus)); - int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_HALT); - if (code != 0) { - // todo: handle error + code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_HALT); + if (code != 0) { // todo: handle error + stError("s-task:%s failed to handle halt event, code:%s", pTask->id.idStr, tstrerror(code)); } } @@ -352,7 +366,10 @@ void processDownstreamReadyRsp(SStreamTask* pTask) { // todo: let's retry if (HAS_RELATED_FILLHISTORY_TASK(pTask)) { stDebug("s-task:%s try to launch related fill-history task", pTask->id.idStr); - (void)streamLaunchFillHistoryTask(pTask); + code = streamLaunchFillHistoryTask(pTask); + if (code) { + stError("s-task:%s failed to launch history task, code:%s", pTask->id.idStr, tstrerror(code)); + } } } @@ -517,8 +534,9 @@ void streamTaskAddReqInfo(STaskCheckInfo* pInfo, int64_t reqId, int32_t taskId, streamMutexUnlock(&pInfo->checkInfoLock); } -void doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) { +int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) { const char* id = pTask->id.idStr; + int32_t code = 0; SStreamTaskCheckReq req = { .streamId = pTask->id.streamId, @@ -536,10 +554,10 @@ void doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) { STaskDispatcherFixed* pDispatch = &pOutputInfo->fixedDispatcher; setCheckDownstreamReqInfo(&req, p->reqId, pDispatch->taskId, pDispatch->nodeId); - stDebug("s-task:%s (vgId:%d) stage:%" PRId64 " re-send check downstream task:0x%x(vgId:%d)QID:0x%" PRIx64, id, + stDebug("s-task:%s (vgId:%d) stage:%" PRId64 " re-send check downstream task:0x%x(vgId:%d) QID:0x%" PRIx64, id, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, req.reqId); - (void)streamSendCheckMsg(pTask, &req, pOutputInfo->fixedDispatcher.nodeId, &pOutputInfo->fixedDispatcher.epSet); + code = streamSendCheckMsg(pTask, &req, pOutputInfo->fixedDispatcher.nodeId, &pOutputInfo->fixedDispatcher.epSet); } else if (pOutputInfo->type == TASK_OUTPUT__SHUFFLE_DISPATCH) { SArray* vgInfo = pOutputInfo->shuffleDispatcher.dbInfo.pVgroupInfos; int32_t numOfVgs = taosArrayGetSize(vgInfo); @@ -554,13 +572,19 @@ void doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) { setCheckDownstreamReqInfo(&req, p->reqId, pVgInfo->taskId, pVgInfo->vgId); stDebug("s-task:%s (vgId:%d) stage:%" PRId64 - " re-send check downstream task:0x%x(vgId:%d) (shuffle), idx:%dQID:0x%" PRIx64, + " re-send check downstream task:0x%x(vgId:%d) (shuffle), idx:%d QID:0x%" PRIx64, id, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, i, p->reqId); - (void)streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); + code = streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); break; } } } + + if (code) { + stError("s-task:%s failed to send check msg to downstream, code:%s", pTask->id.idStr, tstrerror(code)); + } else { + return code; + } } void getCheckRspStatus(STaskCheckInfo* pInfo, int64_t el, int32_t* numOfReady, int32_t* numOfFault, @@ -626,7 +650,7 @@ void handleTimeoutDownstreamTasks(SStreamTask* pTask, SArray* pTimeoutList) { continue; } - doSendCheckMsg(pTask, p); + int32_t code = doSendCheckMsg(pTask, p); } } @@ -676,7 +700,7 @@ void handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList) { if (p != NULL) { p->rspTs = 0; p->status = -1; - doSendCheckMsg(pTask, p); + int32_t code = doSendCheckMsg(pTask, p); } } @@ -723,7 +747,10 @@ void rspMonitorFn(void* param, void* tmrId) { // not record the failed of the current task if try to close current vnode // otherwise, the put of message operation may incur invalid read of message queue. if (!pMeta->closeFlag) { - (void)addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId); + int32_t code = addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId); + if (code) { + stError("s-task:%s failed to create async record start failed task, code:%s", id, tstrerror(code)); + } } streamMetaReleaseTask(pMeta, pTask); @@ -805,7 +832,11 @@ void rspMonitorFn(void* param, void* tmrId) { streamTaskCompleteCheckRsp(pInfo, false, id); streamMutexUnlock(&pInfo->checkInfoLock); - (void)addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId); + int32_t code = addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId); + if (code) { + stError("s-task:%s failed to create async record start failed task, code:%s", id, tstrerror(code)); + } + streamMetaReleaseTask(pMeta, pTask); taosArrayDestroy(pNotReadyList); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 9cac5578a8..e636683f02 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -193,13 +193,13 @@ int32_t streamBroadcastToUpTasks(SStreamTask* pTask, const SSDataBlock* pBlock) // no need to do anything if failed int32_t streamSendCheckMsg(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet) { void* buf = NULL; - int32_t code = -1; + int32_t code = 0; SRpcMsg msg = {0}; int32_t tlen; tEncodeSize(tEncodeStreamTaskCheckReq, pReq, tlen, code); if (code < 0) { - return -1; + return code; } buf = rpcMallocCont(sizeof(SMsgHead) + tlen); @@ -217,8 +217,8 @@ int32_t streamSendCheckMsg(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, tEncoderClear(&encoder); return code; } - tEncoderClear(&encoder); + tEncoderClear(&encoder); initRpcMsg(&msg, TDMT_VND_STREAM_TASK_CHECK, buf, tlen + sizeof(SMsgHead)); stDebug("s-task:%s (level:%d) send check msg to s-task:0x%" PRIx64 ":0x%x (vgId:%d)", pTask->id.idStr, pTask->info.taskLevel, pReq->streamId, pReq->downstreamTaskId, nodeId); From 3821f88e6495e8d36e3f35efb2820c20196e8016 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 14:32:29 +0800 Subject: [PATCH 56/90] fix(stream): fix syntax error. --- source/libs/stream/src/streamCheckStatus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index 274ec5043c..d0604e6d21 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -582,9 +582,8 @@ int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) { if (code) { stError("s-task:%s failed to send check msg to downstream, code:%s", pTask->id.idStr, tstrerror(code)); - } else { - return code; } + return code; } void getCheckRspStatus(STaskCheckInfo* pInfo, int64_t el, int32_t* numOfReady, int32_t* numOfFault, From 6c610e477755b9f4eafdc6bf6a2318224e28067c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 14:45:03 +0800 Subject: [PATCH 57/90] fix mem leak --- source/libs/transport/src/transCli.c | 1 - source/libs/transport/src/transSvr.c | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a0c7315fe7..ce9adc836e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2422,7 +2422,6 @@ static void destroyThrdObj(SCliThrd* pThrd) { tDebug("thread destroy %" PRId64, pThrd->pid); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); - (void)uv_timer_stop(timer); taosMemoryFree(timer); } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 48042b84c1..1db5d0a6d7 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1398,10 +1398,21 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, thrd->quit = false; thrd->pTransInst = shandle; thrd->pWhiteList = uvWhiteListCreate(); + if (thrd->pWhiteList == NULL) { + destroyWorkThrdObj(thrd); + code = TSDB_CODE_OUT_OF_MEMORY; + goto End; + } - srv->pThreadObj[i] = thrd; srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); + if (srv->pipe[i] == NULL) { + destroyWorkThrdObj(thrd); + code = TSDB_CODE_OUT_OF_MEMORY; + goto End; + } + thrd->pipe = &(srv->pipe[i][1]); // init read + srv->pThreadObj[i] = thrd; if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) { goto End; @@ -1415,6 +1426,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, tError("failed to create worker-thread:%d", i); goto End; } + thrd->inited = 1; } #else From d6707788021138a4a41175b822f21d726d2eb63e Mon Sep 17 00:00:00 2001 From: Jing Sima Date: Tue, 10 Sep 2024 09:16:35 +0800 Subject: [PATCH 58/90] fix:[TD-31974] fix memory leak when error occurs after mode function init. --- source/libs/executor/src/executorInt.c | 4 ++++ source/libs/executor/src/operator.c | 10 ++++++---- source/libs/function/src/builtinsimpl.c | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 00138d6871..1659c1fa3e 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -1010,6 +1010,10 @@ static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_ } for (int32_t i = 0; i < numOfOutput; ++i) { + if (pCtx[i].fpSet.cleanup != NULL) { + pCtx[i].fpSet.cleanup(&pCtx[i]); + } + if (pExpr != NULL) { SExprInfo* pExprInfo = &pExpr[i]; for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) { diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c index 6fe270161f..8fe8c6363a 100644 --- a/source/libs/executor/src/operator.c +++ b/source/libs/executor/src/operator.c @@ -659,10 +659,6 @@ void destroyOperator(SOperatorInfo* pOperator) { freeResetOperatorParams(pOperator, OP_GET_PARAM, true); freeResetOperatorParams(pOperator, OP_NOTIFY_PARAM, true); - if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) { - pOperator->fpSet.closeFn(pOperator->info); - } - if (pOperator->pDownstream != NULL) { for (int32_t i = 0; i < pOperator->numOfRealDownstream; ++i) { destroyOperator(pOperator->pDownstream[i]); @@ -673,6 +669,12 @@ void destroyOperator(SOperatorInfo* pOperator) { } cleanupExprSupp(&pOperator->exprSupp); + + // close operator after cleanup exprSupp, since we need to call cleanup of sqlFunctionCtx first to avoid mem leak. + if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) { + pOperator->fpSet.closeFn(pOperator->info); + } + taosMemoryFreeClear(pOperator); } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 6d655528c7..c55839d033 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -6036,9 +6036,10 @@ static void modeFunctionCleanup(SModeInfo * pInfo) { } void modeFunctionCleanupExt(SqlFunctionCtx* pCtx) { - SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SModeInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); - modeFunctionCleanup(pInfo); + if (pCtx == NULL || GET_RES_INFO(pCtx) == NULL || GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)) == NULL) { + return; + } + modeFunctionCleanup(GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx))); } static int32_t saveModeTupleData(SqlFunctionCtx* pCtx, char* data, SModeInfo *pInfo, STuplePos* pPos) { From 5cfe7b8ec9ea5556d335fd66a685677e0fe9b5f8 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 11 Sep 2024 14:58:06 +0800 Subject: [PATCH 59/90] fix(query):fix the issue of return db error when the timestamp is 0 --- source/libs/executor/src/timewindowoperator.c | 8 +---- tests/parallel_test/cases.task | 1 + tests/script/tsim/compute/interval1.sim | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 tests/script/tsim/compute/interval1.sim diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 93b3759c47..640ce5c98b 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -894,13 +894,7 @@ int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo tsCols = (int64_t*)pColDataInfo->pData; if(tsCols[0] == 0) { - pTaskInfo->code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; - T_LONG_JMP(pTaskInfo->env, terrno); - } - - // no data in primary ts - if (tsCols[0] == 0 && tsCols[pBlock->info.rows - 1] == 0) { - return NULL; + qWarn("%s at line %d.block start ts:%" PRId64 ",end ts:%" PRId64, __func__, __LINE__, tsCols[0], tsCols[pBlock->info.rows - 1]); } if (tsCols[0] != 0 && (pBlock->info.window.skey == 0 && pBlock->info.window.ekey == 0)) { diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index c8e0a624d5..76ec6422b9 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -1453,6 +1453,7 @@ ,,y,script,./test.sh -f tsim/compute/diff2.sim ,,y,script,./test.sh -f tsim/compute/first.sim ,,y,script,./test.sh -f tsim/compute/interval.sim +,,y,script,./test.sh -f tsim/compute/interval1.sim ,,y,script,./test.sh -f tsim/compute/last_row.sim ,,y,script,./test.sh -f tsim/compute/last.sim ,,y,script,./test.sh -f tsim/compute/leastsquare.sim diff --git a/tests/script/tsim/compute/interval1.sim b/tests/script/tsim/compute/interval1.sim new file mode 100644 index 0000000000..74af727917 --- /dev/null +++ b/tests/script/tsim/compute/interval1.sim @@ -0,0 +1,33 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c timezone -v UTC +system sh/exec.sh -n dnode1 -s start +sql connect + + +sql CREATE DATABASE `alphacloud_alphaess` BUFFER 512 CACHESIZE 1024 CACHEMODEL 'both' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 KEEP 365000d; + +sql use alphacloud_alphaess; + +sql create stable st(ts TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `uk` VARCHAR(64) ENCODE 'disabled' COMPRESS 'lz4' LEVEL 'medium' PRIMARY KEY ) tags(ta int,tb int,tc int); + +sql create table t1 using st tags(1,1,1); + +sql insert into t1 values ("1970-01-29 05:04:53.000"," 22:: "); + +sql select _wstart, count(*) from st interval(1y); + +if $rows != 1 then + print =====rows=$rows + return -1 +endi + +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 + +if $data01 != 1 then + print =====data00=$data00 + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From c38eb033a998804951e1d5d3577d93d51b6718d7 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 15:57:06 +0800 Subject: [PATCH 60/90] refactor:update logs. --- source/libs/stream/src/streamCheckpoint.c | 2 +- source/libs/stream/src/streamDispatch.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index fa2bc65194..386c0d8222 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -237,7 +237,7 @@ int32_t streamProcessCheckpointTriggerBlock(SStreamTask* pTask, SStreamDataBlock if (pActiveInfo->failedId >= checkpointId) { stError("s-task:%s vgId:%d checkpointId:%" PRId64 " transId:%d, has been marked failed, failedId:%" PRId64 - "discard the checkpoint-trigger block", + " discard the checkpoint-trigger block", id, vgId, checkpointId, transId, pActiveInfo->failedId); streamMutexUnlock(&pTask->lock); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index e636683f02..63411df11a 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1498,8 +1498,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i // follower not handle the dispatch rsp if ((pTask->pMeta->role == NODE_ROLE_FOLLOWER) || (pTask->status.downstreamReady != 1)) { - stError("s-task:%s vgId:%d is follower or task just re-launched, not handle the dispatch rsp, discard it", id, - vgId); + stError("s-task:%s vgId:%d is follower or just re-launched, not handle the dispatch rsp, discard it", id, vgId); streamMutexUnlock(&pMsgInfo->lock); return TSDB_CODE_STREAM_TASK_NOT_EXIST; } From 9b418bee783bd7c53e36819bd408d05b590d6427 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 16:37:06 +0800 Subject: [PATCH 61/90] fix meta dead lock --- source/libs/executor/src/scanoperator.c | 139 ++++++++++++------------ 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 42e7e4ac3b..b0b6a91faa 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -90,7 +90,7 @@ static void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockInfo, int32_t order, bool* overlap) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; STimeWindow w = {0}; // 0 by default, which means it is not a interval operator of the upstream operator. @@ -101,7 +101,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc if (order == TSDB_ORDER_ASC) { w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.skey); - if(w.ekey < pBlockInfo->window.skey) { + if (w.ekey < pBlockInfo->window.skey) { qError("w.ekey:%" PRId64 " < pBlockInfo->window.skey:%" PRId64, w.ekey, pBlockInfo->window.skey); return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } @@ -117,7 +117,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc break; } - if(w.ekey <= pBlockInfo->window.ekey) { + if (w.ekey <= pBlockInfo->window.ekey) { qError("w.ekey:%" PRId64 " <= pBlockInfo->window.ekey:%" PRId64, w.ekey, pBlockInfo->window.ekey); return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } @@ -128,7 +128,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc } } else { w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.ekey); - if(w.skey > pBlockInfo->window.ekey) { + if (w.skey > pBlockInfo->window.ekey) { qError("w.skey:%" PRId64 " > pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.ekey); return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } @@ -144,7 +144,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc break; } - if(w.skey >= pBlockInfo->window.skey){ + if (w.skey >= pBlockInfo->window.skey) { qError("w.skey:%" PRId64 " >= pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.skey); return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } @@ -227,7 +227,7 @@ static int32_t doDynamicPruneDataBlock(SOperatorInfo* pOperator, SDataBlockInfo* SResultRowEntryInfo* pEntry = getResultEntryInfo(pRow, i, pTableScanInfo->base.pdInfo.pExprSup->rowEntryInfoOffset); - EFuncDataRequired reqStatus = fmFuncDynDataRequired(functionId, pEntry, pBlockInfo); + EFuncDataRequired reqStatus = fmFuncDynDataRequired(functionId, pEntry, pBlockInfo); if (reqStatus != FUNC_DATA_REQUIRED_NOT_LOAD) { notLoadBlock = false; break; @@ -399,7 +399,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanBase* pTableSca } } - if(*status != FUNC_DATA_REQUIRED_DATA_LOAD) { + if (*status != FUNC_DATA_REQUIRED_DATA_LOAD) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->dataReader); qError("%s loadDataBlock invalid status:%d", GET_TASKID(pTaskInfo), *status); return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; @@ -588,14 +588,14 @@ static void freeTableCachedValObj(STableCachedVal* pVal) { int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock, int32_t rows, SExecTaskInfo* pTask, STableMetaCacheInfo* pCache) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; - bool freeReader = false; - LRUHandle* h = NULL; - STableCachedVal val = {0}; - SMetaReader mr = {0}; - const char* idStr = pTask->id.str; - int32_t insertRet = TAOS_LRU_STATUS_OK; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool freeReader = false; + LRUHandle* h = NULL; + STableCachedVal val = {0}; + SMetaReader mr = {0}; + const char* idStr = pTask->id.str; + int32_t insertRet = TAOS_LRU_STATUS_OK; STableCachedVal* pVal = NULL; // currently only the tbname pseudo column @@ -625,8 +625,7 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int // append null value before return to caller, since the caller will ignore this error code and proceed doSetNullValue(pBlock, pExpr, numOfExpr); } else { - qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.id.uid, tstrerror(code), - idStr); + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.id.uid, tstrerror(code), idStr); } pHandle->api.metaReaderFn.clearReader(&mr); return code; @@ -743,7 +742,7 @@ _end: if (NULL != pVal) { insertRet = taosLRUCacheInsert(pCache->pTableMetaEntryCache, &pBlock->info.id.uid, sizeof(uint64_t), pVal, - sizeof(STableCachedVal), freeCachedMetaItem, NULL, TAOS_LRU_PRIORITY_LOW, NULL); + sizeof(STableCachedVal), freeCachedMetaItem, NULL, TAOS_LRU_PRIORITY_LOW, NULL); if (insertRet != TAOS_LRU_STATUS_OK) { qWarn("failed to put meta into lru cache, code:%d, %s", insertRet, idStr); } @@ -1416,7 +1415,7 @@ static int32_t getTableScannerExecInfo(struct SOperatorInfo* pOptr, void** pOptr if (!pRecorder) { return terrno; } - STableScanInfo* pTableScanInfo = pOptr->info; + STableScanInfo* pTableScanInfo = pOptr->info; *pRecorder = pTableScanInfo->base.readRecorder; *pOptrExplain = pRecorder; *len = sizeof(SFileBlockLoadRecorder); @@ -1499,7 +1498,7 @@ int32_t createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHa initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pResBlock = createDataBlockFromDescNode(pDescNode); QUERY_CHECK_NULL(pInfo->pResBlock, code, lino, _error, terrno); - + code = prepareDataBlockBuf(pInfo->pResBlock, &pInfo->base.matchInfo); QUERY_CHECK_CODE(code, lino, _error); @@ -1538,7 +1537,7 @@ int32_t createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHa _error: if (pInfo != NULL) { - pInfo->base.pTableListInfo = NULL; // this attribute will be destroy outside of this function + pInfo->base.pTableListInfo = NULL; // this attribute will be destroy outside of this function destroyTableScanOperatorInfo(pInfo); } @@ -1660,7 +1659,7 @@ static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbU SSDataBlock* pBlock = pTableScanInfo->pResBlock; STsdbReader* pReader = NULL; code = pAPI->tsdReader.tsdReaderOpen(pTableScanInfo->base.readHandle.vnode, &cond, &tblInfo, 1, pBlock, - (void**)&pReader, GET_TASKID(pTaskInfo), NULL); + (void**)&pReader, GET_TASKID(pTaskInfo), NULL); QUERY_CHECK_CODE(code, lino, _end); bool hasNext = false; @@ -1813,7 +1812,7 @@ static void prepareRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_ QUERY_CHECK_NULL(pInfo->pUpdateInfo, code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); qDebug("prepare range scan start:%" PRId64 ",end:%" PRId64 ",maxVer:%" PRIu64, win.skey, win.ekey, - pInfo->pUpdateInfo->maxDataVersion); + pInfo->pUpdateInfo->maxDataVersion); resetTableScanInfo(pInfo->pTableScanOp->info, &win, pInfo->pUpdateInfo->maxDataVersion); pInfo->pTableScanOp->status = OP_OPENED; if (pRes) { @@ -2236,9 +2235,9 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS } uint64_t* srcUidData = (uint64_t*)pSrcUidCol->pData; - TSKEY* srcStartTsCol = (TSKEY*)pSrcStartTsCol->pData; - TSKEY* srcEndTsCol = (TSKEY*)pSrcEndTsCol->pData; - int64_t ver = pSrcBlock->info.version - 1; + TSKEY* srcStartTsCol = (TSKEY*)pSrcStartTsCol->pData; + TSKEY* srcEndTsCol = (TSKEY*)pSrcEndTsCol->pData; + int64_t ver = pSrcBlock->info.version - 1; if (pInfo->partitionSup.needCalc && (srcStartTsCol[0] != srcEndTsCol[0] || (hasPrimaryKeyCol(pInfo) && mode == STREAM_DELETE_DATA))) { @@ -2804,8 +2803,8 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock // currently only the tbname pseudo column if (pInfo->numOfPseudoExpr > 0) { - code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, - pInfo->pRes, pBlockInfo->rows, pTaskInfo, &pTableScanInfo->base.metaCache); + code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes, + pBlockInfo->rows, pTaskInfo, &pTableScanInfo->base.metaCache); // ignore the table not exists error, since this table may have been dropped during the scan procedure. if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) { code = 0; @@ -3182,7 +3181,7 @@ void streamScanOperatorDecode(void* pBuff, int32_t len, SStreamScanInfo* pInfo) return; } - void* pUpInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); + void* pUpInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); if (!pUpInfo) { return; } @@ -3471,7 +3470,8 @@ FETCH_NEXT_BLOCK: (*ppRes) = pInfo->pDeleteDataRes; return code; } - qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, lino); + qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, + lino); blockDataCleanup(pInfo->pUpdateDataRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; } break; @@ -3484,7 +3484,8 @@ FETCH_NEXT_BLOCK: (*ppRes) = pInfo->pUpdateRes; return code; } - qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, lino); + qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, + lino); blockDataCleanup(pInfo->pUpdateDataRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; } break; @@ -3671,7 +3672,7 @@ static int32_t extractTableIdList(const STableListInfo* pTableListInfo, SArray** for (int32_t i = 0; i < size; ++i) { STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i); QUERY_CHECK_NULL(pkeyInfo, code, lino, _end, terrno); - void* tmp = taosArrayPush(tableIdList, &pkeyInfo->uid); + void* tmp = taosArrayPush(tableIdList, &pkeyInfo->uid); QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); } @@ -4066,7 +4067,7 @@ int32_t createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList); pColIds = taosArrayInit(numOfOutput, sizeof(int16_t)); QUERY_CHECK_NULL(pColIds, code, lino, _error, terrno); - + for (int32_t i = 0; i < numOfOutput; ++i) { SColMatchItem* id = taosArrayGet(pInfo->matchInfo.pList, i); QUERY_CHECK_NULL(id, code, lino, _error, terrno); @@ -4268,7 +4269,7 @@ _error: } static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, int32_t count, SMetaReader* mr, - SStorageAPI* pAPI) { + SStorageAPI* pAPI) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -4280,7 +4281,6 @@ static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pR qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno), GET_TASKID(pTaskInfo)); tDecoderClear(&(*mr).coder); - pAPI->metaReaderFn.clearReader(mr); goto _end; } @@ -4289,7 +4289,6 @@ static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pR if (code != TSDB_CODE_SUCCESS) { qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno), GET_TASKID(pTaskInfo)); - pAPI->metaReaderFn.clearReader(mr); goto _end; } @@ -4697,6 +4696,12 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) { code = doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI); + if (code == TSDB_CODE_OUT_OF_MEMORY) { + break; + } else { + // ignore other error + } + ++count; if (++pInfo->curPos >= size) { setOperatorCompleted(pOperator); @@ -4814,7 +4819,7 @@ int32_t createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* p nodesRewriteExprPostOrder(&pTagCond, tagScanRewriteTagColumn, (void*)&pInfo->filterCtx); } } - //TODO wjm check pInfo->filterCtx.code + // TODO wjm check pInfo->filterCtx.code __optr_fn_t tagScanNextFn = (pTagScanNode->onlyMetaCtbIdx) ? doTagScanFromCtbIdxNext : doTagScanFromMetaEntryNext; pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, tagScanNextFn, NULL, destroyTagScanOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); @@ -4925,7 +4930,7 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu pInfo->base.dataReader = pInput->pReader; while (true) { - bool hasNext = false; + bool hasNext = false; code = pAPI->tsdReader.tsdNextDataBlock(pInfo->base.dataReader, &hasNext); if (code != 0) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pInfo->base.dataReader); @@ -5036,7 +5041,7 @@ static int32_t openSubTablesMergeSort(STmsSubTablesMergeInfo* pSubTblsInfo) { static int32_t initSubTablesMergeInfo(STableMergeScanInfo* pInfo) { int32_t code = setGroupStartEndIndex(pInfo); if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); return code; } STmsSubTablesMergeInfo* pSubTblsInfo = taosMemoryCalloc(1, sizeof(STmsSubTablesMergeInfo)); @@ -5065,8 +5070,7 @@ static int32_t initSubTablesMergeInfo(STableMergeScanInfo* pInfo) { } int32_t bufPageSize = pInfo->bufPageSize; int32_t inMemSize = (pSubTblsInfo->numSubTables - pSubTblsInfo->numTableBlocksInMem) * bufPageSize; - code = - createDiskbasedBuf(&pSubTblsInfo->pBlocksBuf, pInfo->bufPageSize, inMemSize, "blocksExternalBuf", tsTempDir); + code = createDiskbasedBuf(&pSubTblsInfo->pBlocksBuf, pInfo->bufPageSize, inMemSize, "blocksExternalBuf", tsTempDir); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(pSubTblsInfo->aInputs); taosMemoryFree(pSubTblsInfo); @@ -5199,7 +5203,7 @@ static int32_t appendChosenRowToDataBlock(STmsSubTablesMergeInfo* pSubTblsInfo, SColumnInfoData* pSrcColInfo = taosArrayGet(pInputBlock->pDataBlock, i); QUERY_CHECK_NULL(pSrcColInfo, code, lino, _end, terrno); - bool isNull = colDataIsNull(pSrcColInfo, pInputBlock->info.rows, pInput->rowIdx, NULL); + bool isNull = colDataIsNull(pSrcColInfo, pInputBlock->info.rows, pInput->rowIdx, NULL); if (isNull) { code = colDataSetVal(pColInfo, pBlock->info.rows, NULL, true); @@ -5223,7 +5227,8 @@ _end: return code; } -static int32_t getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t capacity, SSDataBlock** pResBlock) { +static int32_t getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t capacity, + SSDataBlock** pResBlock) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; STableMergeScanInfo* pInfo = pOperator->info; @@ -5580,9 +5585,9 @@ static int32_t getBlockForTableMergeScan(void* param, SSDataBlock** ppBlock) { } int32_t generateSortByTsPkInfo(SArray* colMatchInfo, int32_t order, SArray** ppSortArray) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; - SArray* pSortInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SArray* pSortInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); QUERY_CHECK_NULL(pSortInfo, code, lino, _end, terrno); SBlockOrderInfo biTs = {0}; SBlockOrderInfo biPk = {0}; @@ -5983,7 +5988,7 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla if (!execInfo) { return terrno; } - STableMergeScanInfo* pInfo = pOptr->info; + STableMergeScanInfo* pInfo = pOptr->info; execInfo->blockRecorder = pInfo->base.readRecorder; execInfo->sortExecInfo = pInfo->sortExecInfo; @@ -6126,24 +6131,24 @@ _error: // ==================================================================================================================== // TableCountScanOperator -static void destoryTableCountScanOperator(void* param); -static int32_t buildVnodeGroupedStbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, - SSDataBlock* pRes, char* dbName, tb_uid_t stbUid, SStorageAPI* pAPI); -static int32_t buildVnodeGroupedNtbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, - SSDataBlock* pRes, char* dbName, SStorageAPI* pAPI); -static int32_t buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName); -static int32_t buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName); -static int32_t buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes); -static void buildSysDbGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes, size_t infodbTableNum, - size_t perfdbTableNum); -static void buildSysDbFilterTableCount(SOperatorInfo* pOperator, STableCountScanSupp* pSupp, SSDataBlock* pRes, - size_t infodbTableNum, size_t perfdbTableNum); -static const char* GROUP_TAG_DB_NAME = "db_name"; -static const char* GROUP_TAG_STABLE_NAME = "stable_name"; +static void destoryTableCountScanOperator(void* param); +static int32_t buildVnodeGroupedStbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, + SSDataBlock* pRes, char* dbName, tb_uid_t stbUid, SStorageAPI* pAPI); +static int32_t buildVnodeGroupedNtbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, + SSDataBlock* pRes, char* dbName, SStorageAPI* pAPI); +static int32_t buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, + STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName); +static int32_t buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, + STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName); +static int32_t buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, + STableCountScanSupp* pSupp, SSDataBlock* pRes); +static void buildSysDbGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, + STableCountScanSupp* pSupp, SSDataBlock* pRes, size_t infodbTableNum, + size_t perfdbTableNum); +static void buildSysDbFilterTableCount(SOperatorInfo* pOperator, STableCountScanSupp* pSupp, SSDataBlock* pRes, + size_t infodbTableNum, size_t perfdbTableNum); +static const char* GROUP_TAG_DB_NAME = "db_name"; +static const char* GROUP_TAG_STABLE_NAME = "stable_name"; int32_t tblCountScanGetGroupTagsSlotId(const SNodeList* scanCols, STableCountScanSupp* supp) { if (scanCols != NULL) { @@ -6478,7 +6483,7 @@ _end: } static int32_t buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName) { + STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -6526,7 +6531,7 @@ _end: } static int32_t buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName) { + STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; From 88250653642f48176eb25e3a84b03ba69f5f6862 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 16:58:29 +0800 Subject: [PATCH 62/90] refactor: update logs. --- source/libs/stream/src/streamDispatch.c | 29 +++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 63411df11a..b5c265af0d 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1477,20 +1477,25 @@ int32_t getFailedDispatchInfo(SDispatchMsgInfo* pMsgInfo, int64_t now) { } int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code) { - const char* id = pTask->id.idStr; - int32_t vgId = pTask->pMeta->vgId; - SDispatchMsgInfo* pMsgInfo = &pTask->msgInfo; - int64_t now = taosGetTimestampMs(); - bool allRsp = false; - int32_t notRsp = 0; - int32_t numOfFailed = 0; - bool triggerDispatchRsp = false; + const char* id = pTask->id.idStr; + int32_t vgId = pTask->pMeta->vgId; + SDispatchMsgInfo* pMsgInfo = &pTask->msgInfo; + int64_t now = taosGetTimestampMs(); + bool allRsp = false; + int32_t notRsp = 0; + int32_t numOfFailed = 0; + bool triggerDispatchRsp = false; + SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo; // we only set the dispatch msg info for current checkpoint trans + int64_t tmpCheckpointId = -1; + int32_t tmpTranId = -1; + streamMutexLock(&pTask->lock); triggerDispatchRsp = (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) && - (pTask->chkInfo.pActiveInfo->activeId == pMsgInfo->checkpointId) && - (pTask->chkInfo.pActiveInfo->transId != pMsgInfo->transId); + (pInfo->activeId == pMsgInfo->checkpointId) && (pInfo->transId != pMsgInfo->transId); + tmpCheckpointId = pInfo->activeId; + tmpTranId = pInfo->transId; streamMutexUnlock(&pTask->lock); streamMutexLock(&pMsgInfo->lock); @@ -1556,8 +1561,8 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i streamTaskSetTriggerDispatchConfirmed(pTask, pRsp->downstreamNodeId); } else { stWarn("s-task:%s checkpoint-trigger msg rsp for checkpointId:%" PRId64 - " transId:%d discard, since expired", - pTask->id.idStr, pMsgInfo->checkpointId, pMsgInfo->transId); + " transId:%d discard, current active checkpointId:%" PRId64 " active transId:%d, since expired", + pTask->id.idStr, pMsgInfo->checkpointId, pMsgInfo->transId, tmpCheckpointId, tmpTranId); } } } From 1e388cace72d5f432165ed05439f9bc6bf7e8144 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 17:01:18 +0800 Subject: [PATCH 63/90] refactor: update logs. --- source/libs/stream/src/streamDispatch.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index b5c265af0d..eb6c9c1a66 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1486,16 +1486,18 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i int32_t numOfFailed = 0; bool triggerDispatchRsp = false; SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo; + int64_t tmpCheckpointId = -1; + int32_t tmpTranId = -1; + const char* pStatus = NULL; // we only set the dispatch msg info for current checkpoint trans - int64_t tmpCheckpointId = -1; - int32_t tmpTranId = -1; - streamMutexLock(&pTask->lock); - triggerDispatchRsp = (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) && - (pInfo->activeId == pMsgInfo->checkpointId) && (pInfo->transId != pMsgInfo->transId); + SStreamTaskState s = streamTaskGetStatus(pTask); + triggerDispatchRsp = (s.state == TASK_STATUS__CK) && (pInfo->activeId == pMsgInfo->checkpointId) && + (pInfo->transId != pMsgInfo->transId); tmpCheckpointId = pInfo->activeId; tmpTranId = pInfo->transId; + pStatus = s.name; streamMutexUnlock(&pTask->lock); streamMutexLock(&pMsgInfo->lock); @@ -1561,8 +1563,9 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i streamTaskSetTriggerDispatchConfirmed(pTask, pRsp->downstreamNodeId); } else { stWarn("s-task:%s checkpoint-trigger msg rsp for checkpointId:%" PRId64 - " transId:%d discard, current active checkpointId:%" PRId64 " active transId:%d, since expired", - pTask->id.idStr, pMsgInfo->checkpointId, pMsgInfo->transId, tmpCheckpointId, tmpTranId); + " transId:%d discard, current status:%s, active checkpointId:%" PRId64 + " active transId:%d, since expired", + pTask->id.idStr, pMsgInfo->checkpointId, pMsgInfo->transId, pStatus, tmpCheckpointId, tmpTranId); } } } From 0b6a934586e7d07b51b04d6054be096efc10faf7 Mon Sep 17 00:00:00 2001 From: dmchen Date: Wed, 11 Sep 2024 09:15:20 +0000 Subject: [PATCH 64/90] fix/TS-5404-use-temp-transid-when-timeout-lock --- source/dnode/mnode/impl/src/mndTrans.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 18ceddb7d0..724c9637e6 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -64,7 +64,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq); static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter); -int32_t tsMaxTransId = 0; +static int32_t tsMaxTransId = 0; int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = { @@ -605,8 +605,9 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict, } int32_t sdbMaxId = sdbGetMaxId(pMnode->pSdb, SDB_TRANS); - int32_t oldId = atomic_load_32(&tsMaxTransId); - pTrans->id = TMAX(sdbMaxId, oldId); + sdbReadLock(pMnode->pSdb, SDB_TRANS); + pTrans->id = TMAX(sdbMaxId, tsMaxTransId + 1); + sdbUnLock(pMnode->pSdb, SDB_TRANS); pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; pTrans->conflict = conflict; @@ -1031,7 +1032,9 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { mInfo("trans:%d, prepare transaction", pTrans->id); if ((code = mndTransSync(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code)); - atomic_store_32(&tsMaxTransId, pTrans->id); + sdbReadLock(pMnode->pSdb, SDB_TRANS); + tsMaxTransId = TMAX(pTrans->id, tsMaxTransId); + sdbUnLock(pMnode->pSdb, SDB_TRANS); TAOS_RETURN(code); } mInfo("trans:%d, prepare finished", pTrans->id); From cf35e31289b86d885ae1cdd2812f6c0f13ce8fab Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Wed, 11 Sep 2024 09:43:55 +0000 Subject: [PATCH 65/90] modify test case --- tests/script/tsim/db/alter_option.sim | 6 +++--- tests/script/tsim/db/basic6.sim | 6 +++--- tests/script/tsim/db/keep.sim | 4 ++-- tests/script/tsim/parser/alter.sim | 14 +++++++------- .../tsim/parser/alter__for_community_version.sim | 12 ++++++------ tests/script/tsim/parser/create_db.sim | 16 ++++++++-------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim index 749b956a9a..4c18fe171c 100644 --- a/tests/script/tsim/db/alter_option.sim +++ b/tests/script/tsim/db/alter_option.sim @@ -72,10 +72,10 @@ endi if $data5_db != on then # strict return -1 endi -if $data6_db != 345600m then # duration +if $data6_db != 240d then # duration return -1 endi -if $data7_db != 1440000m,1440000m,1440000m then # keep +if $data7_db != 1000d,1000d,1000d then # keep return -1 endi if $data8_db != 256 then # buffer @@ -220,7 +220,7 @@ print ============== modify keep sql alter database db keep 2400 sql select * from information_schema.ins_databases print keep $data7_db -if $data7_db != 3456000m,3456000m,3456000m then +if $data7_db != 2400d,2400d,2400d then return -1 endi diff --git a/tests/script/tsim/db/basic6.sim b/tests/script/tsim/db/basic6.sim index 5043574787..8d16c3e975 100644 --- a/tests/script/tsim/db/basic6.sim +++ b/tests/script/tsim/db/basic6.sim @@ -34,10 +34,10 @@ endi if $data24 != 1 then return -1 endi -if $data26 != 2880m then +if $data26 != 2d then return -1 endi -if $data27 != 14400m,14400m,14400m then +if $data27 != 10d,10d,10d then return -1 endi #if $data28 != 32 then @@ -78,7 +78,7 @@ endi if $data24 != 1 then return -1 endi -if $data26 != 21600m then +if $data26 != 15d then return -1 endi diff --git a/tests/script/tsim/db/keep.sim b/tests/script/tsim/db/keep.sim index f0653c4801..28c595cd21 100644 --- a/tests/script/tsim/db/keep.sim +++ b/tests/script/tsim/db/keep.sim @@ -45,7 +45,7 @@ print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 if $data22 != 2 then return -1 endi -if $data27 != 86400m,86400m,86400m then +if $data27 != 60d,60d,60d then return -1 endi @@ -86,7 +86,7 @@ sql select * from information_schema.ins_databases if $data22 != 2 then return -1 endi -if $data27 != 43200m,43200m,43200m then +if $data27 != 30d,30d,30d then return -1 endi diff --git a/tests/script/tsim/parser/alter.sim b/tests/script/tsim/parser/alter.sim index 99e014a011..ceeb5df34f 100644 --- a/tests/script/tsim/parser/alter.sim +++ b/tests/script/tsim/parser/alter.sim @@ -40,7 +40,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 30240m,30240m,30240m then +if $data27 != 21d,21d,21d then return -1 endi sql alter database $db keep 11,12 @@ -48,7 +48,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,17280m,17280m then +if $data27 != 11d,12d,12d then return -1 endi sql alter database $db keep 20,20,20 @@ -56,7 +56,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 28800m,28800m,28800m then +if $data27 != 20d,20d,20d then return -1 endi sql alter database $db keep 10,10,10 @@ -64,7 +64,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 14400m,14400m,14400m then +if $data27 != 10d,10d,10d then return -1 endi sql alter database $db keep 10,10,11 @@ -72,7 +72,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 14400m,14400m,15840m then +if $data27 != 10d,10d,11d then return -1 endi sql alter database $db keep 11,12,13 @@ -80,7 +80,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,17280m,18720m then +if $data27 != 11d,12d,13d then return -1 endi sql alter database $db keep 365000,365000,365000 @@ -88,7 +88,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 525600000m,525600000m,525600000m then +if $data27 != 365000d,365000d,365000d then return -1 endi diff --git a/tests/script/tsim/parser/alter__for_community_version.sim b/tests/script/tsim/parser/alter__for_community_version.sim index 29c748d441..b3534204fc 100644 --- a/tests/script/tsim/parser/alter__for_community_version.sim +++ b/tests/script/tsim/parser/alter__for_community_version.sim @@ -23,7 +23,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 28800m,28800m,28800m then +if $data27 != 20d,20d,20d then return -1 endi @@ -49,7 +49,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 28800m,28800m,28800m then +if $data27 != 20d,20d,20d then return -1 endi sql alter database $db keep 10 @@ -57,7 +57,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 14400m,14400m,14400m then +if $data27 != 10d,10d,10d then return -1 endi sql alter database $db keep 11 @@ -65,7 +65,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,15840m,15840m then +if $data27 != 11d,11d,11d then return -1 endi sql alter database $db keep 13 @@ -73,7 +73,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 18720m,18720m,18720m then +if $data27 != 13d,13d,13d then return -1 endi sql alter database $db keep 365000 @@ -81,7 +81,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 525600000m,525600000m,525600000m then +if $data27 != 365000d,365000d,365000d then return -1 endi diff --git a/tests/script/tsim/parser/create_db.sim b/tests/script/tsim/parser/create_db.sim index 5cb659586c..1057e0b465 100644 --- a/tests/script/tsim/parser/create_db.sim +++ b/tests/script/tsim/parser/create_db.sim @@ -118,10 +118,10 @@ endi if $data24 != $replica then return -1 endi -if $data26 != 14400m then +if $data26 != 10d then return -1 endi -if $data27 != 525600m,525600m,525600m then +if $data27 != 365d,365d,365d then return -1 endi @@ -155,7 +155,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 56160m,56160m,56160m then +if $data27 != 39d,39d,39d then return -1 endi sql drop database dbk0 @@ -164,7 +164,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 56160m,57600m,57600m then +if $data27 != 39d,40d,40d then return -1 endi sql drop database dbka @@ -174,7 +174,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,15840m,15840m then +if $data27 != 11d,11d,11d then return -1 endi sql drop database dbk1 @@ -183,7 +183,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,17280m,18720m then +if $data27 != 11d,12d,13d then return -1 endi sql drop database dbk2 @@ -192,7 +192,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,15840m,18720m then +if $data27 != 11d,11d,13d then return -1 endi sql drop database dbk3 @@ -201,7 +201,7 @@ sql select * from information_schema.ins_databases if $rows != 3 then return -1 endi -if $data27 != 15840m,18720m,18720m then +if $data27 != 11d,13d,13d then return -1 endi sql drop database dbk4 From 2bb9dc609a2cc25b3e99afe64b90249749e04dcb Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 18:18:44 +0800 Subject: [PATCH 66/90] fix(query): fix race condition for table group list. --- source/libs/executor/src/scanoperator.c | 36 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 42e7e4ac3b..f30329889a 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1241,6 +1241,29 @@ _end: return code; } +static int32_t doInitReader(STableScanInfo* pInfo, SExecTaskInfo* pTaskInfo, SStorageAPI* pAPI, int32_t* pNum, + STableKeyInfo** pList) { + const char* idStr = GET_TASKID(pTaskInfo); + int32_t code = initNextGroupScan(pInfo, pList, pNum); + if (code) { + qError("%s failed to init groupScan Info, code:%s at line:%d", idStr, tstrerror(code), __LINE__); + return code; + } + + if (pInfo->base.dataReader != NULL) { + qError("%s tsdb reader should be null", idStr); + return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + } + + code = pAPI->tsdReader.tsdReaderOpen(pInfo->base.readHandle.vnode, &pInfo->base.cond, *pList, *pNum, pInfo->pResBlock, + (void**)&pInfo->base.dataReader, idStr, &pInfo->pIgnoreTables); + if (code) { + qError("%s failed to open tsdbReader, code:%s at line:%d", idStr, tstrerror(code), __LINE__); + } + + return code; +} + static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1250,6 +1273,7 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo int32_t num = 0; STableKeyInfo* pList = NULL; SSDataBlock* pResult = NULL; + const char* idStr = GET_TASKID(pTaskInfo); QRY_PARAM_CHECK(pResBlock); @@ -1260,17 +1284,10 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo } taosRLockLatch(&pTaskInfo->lock); - code = initNextGroupScan(pInfo, &pList, &num); - + code = doInitReader(pInfo, pTaskInfo, pAPI, &num, &pList); taosRUnLockLatch(&pTaskInfo->lock); QUERY_CHECK_CODE(code, lino, _end); - QUERY_CHECK_CONDITION((pInfo->base.dataReader == NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); - - code = pAPI->tsdReader.tsdReaderOpen(pInfo->base.readHandle.vnode, &pInfo->base.cond, pList, num, pInfo->pResBlock, - (void**)&pInfo->base.dataReader, GET_TASKID(pTaskInfo), &pInfo->pIgnoreTables); - QUERY_CHECK_CODE(code, lino, _end); - if (pInfo->filesetDelimited) { pAPI->tsdReader.tsdSetFilesetDelimited(pInfo->base.dataReader); } @@ -1280,7 +1297,6 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo } } - pResult = NULL; code = doGroupedTableScan(pOperator, &pResult); QUERY_CHECK_CODE(code, lino, _end); @@ -1305,7 +1321,7 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo _end: if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + qError("%s %s failed at line %d since %s", idStr, __func__, lino, tstrerror(code)); pTaskInfo->code = code; } From 4319cacdc3871bf260a8b3945f42de9280f01141 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 Sep 2024 19:09:17 +0800 Subject: [PATCH 67/90] fix(query):fix invalid read. --- source/dnode/vnode/src/inc/tsdb.h | 2 +- source/dnode/vnode/src/tsdb/tsdbCacheRead.c | 2 +- source/dnode/vnode/src/tsdb/tsdbRead2.c | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 7c68d31f84..294874b94a 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -292,7 +292,7 @@ int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx); // tsdbRead.c ============================================================================================== -int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap); +int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char* id); void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive); int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid); diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index c3364231e0..b24aa6fb1d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -473,7 +473,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 } (void)taosThreadMutexLock(&pr->readerMutex); - code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap); + code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap, pr->idstr); if (code != TSDB_CODE_SUCCESS) { goto _end; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 8f66df1ffb..c48e37c65d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -5016,7 +5016,7 @@ int32_t tsdbReaderResume2(STsdbReader* pReader) { int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); if (numOfTables > 0) { tsdbTrace("tsdb/reader: %p, take snapshot", pReader); - code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap); + code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap, pReader->idStr); if (code != TSDB_CODE_SUCCESS) { goto _err; } @@ -5862,7 +5862,7 @@ int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_ return code; } -int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap) { +int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap, const char* id) { int32_t code = 0; STsdb* pTsdb = pReader->pTsdb; SVersionRange* pRange = &pReader->info.verRange; @@ -5872,7 +5872,7 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs // lock code = taosThreadMutexLock(&pTsdb->mutex); if (code != TSDB_CODE_SUCCESS) { - tsdbError("failed to lock tsdb, code:%s", tstrerror(code)); + tsdbError("%s failed to lock tsdb, code:%s", id, tstrerror(code)); return code; } @@ -5932,18 +5932,19 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs } (void) taosThreadMutexUnlock(&pTsdb->mutex); - TSDB_CHECK_CODE(code, lino, _exit);} + TSDB_CHECK_CODE(code, lino, _exit); + } // unlock (void) taosThreadMutexUnlock(&pTsdb->mutex); *ppSnap = pSnap; - tsdbTrace("vgId:%d, take read snapshot", TD_VID(pTsdb->pVnode)); + tsdbTrace("%s vgId:%d, take read snapshot", id, TD_VID(pTsdb->pVnode)); return code; _exit: - tsdbError("%s vgId:%d take read snapshot failed, line:%d code:%s", pReader->idStr, TD_VID(pTsdb->pVnode), lino, - tstrerror(code)); + tsdbError("%s vgId:%d take read snapshot failed, line:%d code:%s", id, TD_VID(pTsdb->pVnode), lino, tstrerror(code)); + if (pSnap) { if (pSnap->pNode) taosMemoryFree(pSnap->pNode); if (pSnap->pINode) taosMemoryFree(pSnap->pINode); From 4d103c09d490f67fd5b6fb836d91449a8731433c Mon Sep 17 00:00:00 2001 From: Shungang Li Date: Wed, 11 Sep 2024 19:22:04 +0800 Subject: [PATCH 68/90] fix: ignore tsdbCacheFlushDirty errcode --- source/dnode/vnode/src/tsdb/tsdbCache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 53e20d459f..74bd837775 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -577,7 +577,7 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud SLastCol *pLastCol = (SLastCol *)value; if (pLastCol->dirty) { - tsdbCacheFlushDirty(key, klen, pLastCol, ud); + (void)tsdbCacheFlushDirty(key, klen, pLastCol, ud); } for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) { From 9923079693fb3eb24186812bed79f7519980ea95 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Wed, 11 Sep 2024 19:57:47 +0800 Subject: [PATCH 69/90] TD-31198: add 32/64 bit ODBC driver into Windows packages --- cmake/taosadapter_CMakeLists.txt.in | 2 +- packaging/tools/tdengine.iss | 41 +++++++++++++---------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/cmake/taosadapter_CMakeLists.txt.in b/cmake/taosadapter_CMakeLists.txt.in index 13826a1a74..ef6ed4af1d 100644 --- a/cmake/taosadapter_CMakeLists.txt.in +++ b/cmake/taosadapter_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taosadapter ExternalProject_Add(taosadapter GIT_REPOSITORY https://github.com/taosdata/taosadapter.git - GIT_TAG main + GIT_TAG 3.0 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/packaging/tools/tdengine.iss b/packaging/tools/tdengine.iss index ca6b5a3e5f..8085c55e3e 100644 --- a/packaging/tools/tdengine.iss +++ b/packaging/tools/tdengine.iss @@ -55,7 +55,8 @@ Source: favicon.ico; DestDir: "{app}\include"; Flags: igNoreversion; Source: {#MyAppSourceDir}{#MyAppDLLName}; DestDir: "{win}\System32"; Flags: igNoreversion recursesubdirs createallsubdirs 64bit;Check:IsWin64; Source: {#MyAppSourceDir}{#MyAppCfgName}; DestDir: "{app}\cfg"; Flags: igNoreversion recursesubdirs createallsubdirs onlyifdoesntexist uninsneveruninstall Source: {#MyAppSourceDir}{#MyAppDriverName}; DestDir: "{app}\driver"; Flags: igNoreversion recursesubdirs createallsubdirs -Source: {#MyAppSourceDir}\taos_odbc\*; DestDir: "{app}\taos_odbc\"; Flags: igNoreversion recursesubdirs createallsubdirs +Source: {#MyAppSourceDir}\taos_odbc\*; DestDir: "{app}\taos_odbc"; Flags: igNoreversion recursesubdirs createallsubdirs +Source: {#MyAppSourceDir}\*.dll; DestDir: "{app}"; Flags: igNoreversion recursesubdirs createallsubdirs ;Source: {#MyAppSourceDir}{#MyAppConnectorName}; DestDir: "{app}\connector"; Flags: igNoreversion recursesubdirs createallsubdirs ;Source: {#MyAppSourceDir}{#MyAppExamplesName}; DestDir: "{app}\examples"; Flags: igNoreversion recursesubdirs createallsubdirs Source: {#MyAppSourceDir}{#MyAppIncludeName}; DestDir: "{app}\include"; Flags: igNoreversion recursesubdirs createallsubdirs @@ -69,7 +70,9 @@ Source: {#MyAppSourceDir}\taosdump.exe; DestDir: "{app}"; DestName: "{#CusPrompt [run] Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\TDengine\\taosd.exe --win_service""" ; Flags: runhidden Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\TDengine\\taosadapter.exe""" ; Flags: runhidden -Filename: "{cmd}"; Parameters: "/c odbcconf /F ""C:\TDengine\taos_odbc\win_odbcinst.in"""; WorkingDir: "{app}"; Flags: runhidden; StatusMsg: "Configuring ODBC" + +Filename: "C:\Windows\System32\odbcconf.exe"; Parameters: "/S /F win_odbcinst.ini"; WorkingDir: "{app}\taos_odbc\x64"; Flags: runhidden; StatusMsg: "Configuring ODBC x64" +Filename: "C:\Windows\SysWOW64\odbcconf.exe"; Parameters: "/S /F win_odbcinst.ini"; WorkingDir: "{app}\taos_odbc\x86"; Flags: runhidden; StatusMsg: "Configuring ODBC x86" [UninstallRun] RunOnceId: "stoptaosd"; Filename: {sys}\sc.exe; Parameters: "stop taosd" ; Flags: runhidden @@ -100,32 +103,26 @@ begin end; function DeleteOdbcDsnRegistry: Boolean; -var - Names: TArrayOfString; - I: Integer; - Value: String; begin - if RegGetValueNames(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', Names) then - begin - for I := 0 to GetArrayLength(Names) - 1 do - begin - if RegQueryStringValue(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', Names[I], Value) then - begin - if Value = 'TDengine' then - begin - RegDeleteKeyIncludingSubkeys(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\' + Names[I]); - RegDeleteValue(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\', Names[I]); - end; - end; - end; - end; + RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\ODBC\ODBC.INI\TAOS_ODBC_DSN'); + RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\ODBC\ODBC.INI\TAOS_ODBC_WS_DSN') + + RegDeleteValue(HKCU, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', 'TAOS_ODBC_DSN'); + RegDeleteValue(HKCU, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', 'TAOS_ODBC_WS_DSN'); + Result := True; end; function DeleteOdbcDriverRegistry: Boolean; begin - RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\TDengine'); - RegDeleteValue(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers', 'TDengine'); + // Delete 64-bit ODBC driver registry + RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\TAOS_ODBC_DRIVER'); + RegDeleteValue(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers', 'TAOS_ODBC_DRIVER'); + + // Delete 32-bit ODBC driver registry + RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\TAOS_ODBC_DRIVER'); + RegDeleteValue(HKLM64, 'SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers', 'TAOS_ODBC_DRIVER'); + Result := True; end; From f9d38ef7bae2dc05f3187b95d5e194d05387d512 Mon Sep 17 00:00:00 2001 From: Jing Sima Date: Thu, 12 Sep 2024 09:36:37 +0800 Subject: [PATCH 70/90] fix:[TD-32041] Fix rand function wrong behaviour. --- source/libs/scalar/src/sclfunc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 4e8107a5b2..3b9cad68ad 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2888,13 +2888,16 @@ int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut } int32_t randFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (!IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) { - int32_t seed; - GET_TYPED_DATA(seed, int32_t, GET_PARAM_TYPE(&pInput[0]), pInput[0].columnData->pData); - taosSeedRand(seed); - } + int32_t seed; int32_t numOfRows = inputNum == 1 ? pInput[0].numOfRows : TMAX(pInput[0].numOfRows, pInput[1].numOfRows); for (int32_t i = 0; i < numOfRows; ++i) { + // for constant seed, only set seed once + if ((pInput[0].numOfRows == 1 && i == 0) || (pInput[0].numOfRows != 1)) { + if (!IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) && !colDataIsNull_s(pInput[0].columnData, i)) { + GET_TYPED_DATA(seed, int32_t, GET_PARAM_TYPE(&pInput[0]), colDataGetData(pInput[0].columnData, i)); + taosSeedRand(seed); + } + } double random_value = (double)(taosRand() % RAND_MAX) / RAND_MAX; colDataSetDouble(pOutput->columnData, i, &random_value); } From 28b3c92dddd0f9d3f91ef3b77e8d051e5abb2494 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 12 Sep 2024 02:36:07 +0000 Subject: [PATCH 71/90] fix/TS-5404-use-write-lock --- source/dnode/mnode/impl/src/mndTrans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 724c9637e6..43f8ffe61b 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -1032,7 +1032,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { mInfo("trans:%d, prepare transaction", pTrans->id); if ((code = mndTransSync(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code)); - sdbReadLock(pMnode->pSdb, SDB_TRANS); + sdbWriteLock(pMnode->pSdb, SDB_TRANS); tsMaxTransId = TMAX(pTrans->id, tsMaxTransId); sdbUnLock(pMnode->pSdb, SDB_TRANS); TAOS_RETURN(code); From 41dfc643b768f9ca1e8538a3b5cd6512f8737dda Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Thu, 12 Sep 2024 13:45:17 +0800 Subject: [PATCH 72/90] enh:modify error code pass --- source/client/src/clientHb.c | 16 +++--- source/client/src/clientImpl.c | 29 +++++------ source/client/src/clientMain.c | 2 +- source/client/src/clientMsgHandler.c | 30 +++++------ source/client/src/clientSml.c | 74 ++++++++++++++-------------- source/client/src/clientSmlJson.c | 8 +-- source/client/src/clientSmlLine.c | 16 +++--- source/client/src/clientSmlTelnet.c | 2 +- source/client/src/clientStmt.c | 33 ++++++------- source/client/src/clientStmt2.c | 25 +++++----- source/client/src/clientTmq.c | 22 ++++----- 11 files changed, 126 insertions(+), 131 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 47b80c03d1..8297ac362e 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -180,7 +180,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); if (NULL == vgInfo->vgHash) { tscError("hash init[%d] failed", rsp->vgNum); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } @@ -188,7 +188,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) { SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j); if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) { tscError("hash push failed, errno:%d", errno); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } } @@ -689,7 +689,7 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) { (void)releaseRequest(*rid); if (NULL == taosArrayPush(hbBasic->queryDesc, &desc)) { taosArrayDestroy(desc.subDesc); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pIter = taosHashIterate(pObj->pRequests, pIter); @@ -777,7 +777,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient pKv->value = qUserAuth; pKv->valueLen += sizeof(SUserAuthVersion); } else { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } goto _return; } @@ -785,7 +785,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient // key/user not exist, add user SUserAuthVersion *user = taosMemoryMalloc(sizeof(SUserAuthVersion)); if (!user) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } tstrncpy(user->user, pTscObj->user, TSDB_USER_LEN); @@ -1436,7 +1436,7 @@ int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMg TSC_ERR_RET(hbMgrInit()); *pAppHbMgr = taosMemoryMalloc(sizeof(SAppHbMgr)); if (*pAppHbMgr == NULL) { - TSC_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + TSC_ERR_JRET(terrno); } // init stat (*pAppHbMgr)->startTime = taosGetTimestampMs(); @@ -1456,14 +1456,14 @@ int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMg (*pAppHbMgr)->activeInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK); if ((*pAppHbMgr)->activeInfo == NULL) { - TSC_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + TSC_ERR_JRET(terrno); } // taosHashSetFreeFp(pAppHbMgr->activeInfo, tFreeClientHbReq); TSC_ERR_JRET(taosThreadMutexLock(&clientHbMgr.lock)); if (taosArrayPush(clientHbMgr.appHbMgrs, &(*pAppHbMgr)) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; (void)taosThreadMutexUnlock(&clientHbMgr.lock); goto _return; } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index d77b8dcbb7..484d9bb7e5 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -228,7 +228,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, tscError("0x%" PRIx64 " failed to prepare sql string buffer, %s", (*pRequest)->self, sql); destroyRequest(*pRequest); *pRequest = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen); @@ -247,7 +247,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, (*pRequest)->self, (*pRequest)->requestId, pTscObj->id, sql); destroyRequest(*pRequest); *pRequest = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*pRequest)->allocatorRefId = -1; @@ -258,7 +258,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, (*pRequest)->requestId, pTscObj->id, sql); destroyRequest(*pRequest); *pRequest = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -595,7 +595,7 @@ int32_t buildVnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr if (NULL == taosArrayPush(nodeList, &load)) { taosArrayDestroy(nodeList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -619,7 +619,7 @@ int32_t buildVnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr } if (NULL == taosArrayAddBatch(nodeList, pData, mnodeNum)) { taosArrayDestroy(nodeList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tscDebug("0x%" PRIx64 " %s policy, use mnode list, num:%d", pRequest->requestId, policy, mnodeNum); @@ -646,7 +646,7 @@ int32_t buildQnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr } if (NULL == taosArrayAddBatch(nodeList, pData, qNodeNum)) { taosArrayDestroy(nodeList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tscDebug("0x%" PRIx64 " qnode policy, use qnode list, num:%d", pRequest->requestId, qNodeNum); goto _return; @@ -665,7 +665,7 @@ int32_t buildQnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr } if (NULL == taosArrayAddBatch(nodeList, pData, mnodeNum)) { taosArrayDestroy(nodeList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tscDebug("0x%" PRIx64 " qnode policy, use mnode list, num:%d", pRequest->requestId, mnodeNum); @@ -699,7 +699,7 @@ int32_t buildAsyncExecNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray } if (NULL == taosArrayPush(pDbVgList, &pRes->pRes)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } } @@ -791,7 +791,7 @@ int32_t buildSyncExecNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* } if (NULL == taosArrayPush(pDbVgList, &pVgList)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } } @@ -903,8 +903,7 @@ int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, pArray = taosArrayInit(tbNum, sizeof(STbSVersion)); if (NULL == pArray) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < tbNum; ++i) { @@ -915,7 +914,7 @@ int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, } STbSVersion tbSver = {.tbFName = tbInfo->tbFName, .sver = tbInfo->sversion, .tver = tbInfo->tversion}; if (NULL == taosArrayPush(pArray, &tbSver)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } } @@ -1662,7 +1661,7 @@ static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInf void* pReq = taosMemoryMalloc(contLen); if (NULL == pReq) { taosMemoryFree(*pMsgSendInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (-1 == tSerializeSConnectReq(pReq, contLen, &connectReq)) { @@ -2050,7 +2049,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); if (p == NULL) { taosReleaseConv(idx, conv, C2M); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pResultInfo->convertBuf[i] = p; @@ -2441,7 +2440,6 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR if (pResultInfo->decompBuf == NULL) { pResultInfo->decompBuf = taosMemoryMalloc(payloadLen); if (pResultInfo->decompBuf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; tscError("failed to prepare the decompress buffer, size:%d", payloadLen); return terrno; } @@ -2450,7 +2448,6 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR if (pResultInfo->decompBufSize < payloadLen) { char* p = taosMemoryRealloc(pResultInfo->decompBuf, payloadLen); if (p == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; tscError("failed to prepare the decompress buffer, size:%d", payloadLen); return terrno; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 1c1fff9b7b..4cd8afe880 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -216,7 +216,7 @@ int32_t fetchWhiteListCallbackFn(void *param, SDataBuf *pMsg, int32_t code) { taosMemoryFree(pMsg->pEpSet); taosMemoryFree(pInfo); tFreeSGetUserWhiteListRsp(&wlRsp); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < wlRsp.numWhiteLists; ++i) { diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 54020b77ef..f8d443aaad 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -511,19 +511,19 @@ static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(SHOW_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); - TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, terrno); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD1_LEN; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD2_LEN; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD3_LEN; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); int32_t numOfCfg = taosArrayGetSize(pVars); code = blockDataEnsureCapacity(pBlock, numOfCfg); @@ -531,26 +531,26 @@ static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { SVariablesInfo* pInfo = taosArrayGet(pVars, i); - TSDB_CHECK_NULL(pInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pInfo, code, line, END, terrno); char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(name, pInfo->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pColInfo, code, line, END, terrno); code = colDataSetVal(pColInfo, i, name, false); TSDB_CHECK_CODE(code, line, END); char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(value, pInfo->value, TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pColInfo, code, line, END, terrno); code = colDataSetVal(pColInfo, i, value, false); TSDB_CHECK_CODE(code, line, END); char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(scope, pInfo->scope, TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pColInfo, code, line, END, terrno); code = colDataSetVal(pColInfo, i, scope, false); TSDB_CHECK_CODE(code, line, END); } @@ -662,29 +662,29 @@ static int32_t buildCompactDbBlock(SCompactDbRsp* pRsp, SSDataBlock** block) { pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(COMPACT_DB_RESULT_COLS, sizeof(SColumnInfoData)); - TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, terrno); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = COMPACT_DB_RESULT_FIELD1_LEN; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); infoData.info.type = TSDB_DATA_TYPE_INT; infoData.info.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = COMPACT_DB_RESULT_FIELD3_LEN; - TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); code = blockDataEnsureCapacity(pBlock, 1); TSDB_CHECK_CODE(code, line, END); SColumnInfoData* pResultCol = taosArrayGet(pBlock->pDataBlock, 0); - TSDB_CHECK_NULL(pResultCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pResultCol, code, line, END, terrno); SColumnInfoData* pIdCol = taosArrayGet(pBlock->pDataBlock, 1); - TSDB_CHECK_NULL(pIdCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pIdCol, code, line, END, terrno); SColumnInfoData* pReasonCol = taosArrayGet(pBlock->pDataBlock, 2); - TSDB_CHECK_NULL(pReasonCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + TSDB_CHECK_NULL(pReasonCol, code, line, END, terrno); char result[COMPACT_DB_RESULT_FIELD1_LEN] = {0}; char reason[COMPACT_DB_RESULT_FIELD3_LEN] = {0}; diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 05678e1cbf..fa6a00b197 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -178,7 +178,7 @@ int32_t smlBuildTableInfo(int numRows, const char *measure, int32_t measureLen, if (tag->cols == NULL) { uError("SML:smlBuildTableInfo failed to allocate memory"); taosMemoryFree(tag); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *tInfo = tag; @@ -210,7 +210,7 @@ int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSml if (currElement->measureEscaped) { measure = (char *)taosMemoryMalloc(measureLen); if (measure == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(measure, currElement->measure, measureLen); PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen); @@ -251,11 +251,11 @@ int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSml if (i < pTableMeta->tableInfo.numOfColumns) { if(taosArrayPush((*sMeta)->cols, &kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } else { if(taosArrayPush((*sMeta)->tags, &kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -328,7 +328,7 @@ END: int32_t smlJoinMeasureTag(SSmlLineInfo *elements) { elements->measureTag = (char *)taosMemoryMalloc(elements->measureLen + elements->tagsLen); if (elements->measureTag == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(elements->measureTag, elements->measure, elements->measureLen); (void)memcpy(elements->measureTag + elements->measureLen, elements->tags, elements->tagsLen); @@ -455,14 +455,14 @@ int32_t smlParseEndTelnetJson(SSmlHandle *info, SSmlLineInfo *elements, SSmlKv * if (elements->colArray == NULL) { elements->colArray = taosArrayInit(16, sizeof(SSmlKv)); if (elements->colArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } if (taosArrayPush(elements->colArray, kvTs) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(elements->colArray, kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } info->preLine = *elements; @@ -937,7 +937,7 @@ static int32_t smlCheckMeta(SSchema *schema, int32_t length, SArray *cols, bool int32_t code = TSDB_CODE_SUCCESS; SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (hashTmp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } int32_t i = 0; @@ -997,7 +997,7 @@ static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashO field.bytes = getBytes(kv->type, kv->length); (void)memcpy(field.name, kv->key, kv->keyLen); if (taosArrayPush(results, &field) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } else if (action == SCHEMA_ACTION_CHANGE_COLUMN_SIZE || action == SCHEMA_ACTION_CHANGE_TAG_SIZE) { uint16_t *index = (uint16_t *)taosHashGet(schemaHash, kv->key, kv->keyLen); @@ -1046,7 +1046,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions)); if (pReq.pColumns == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } for (int32_t i = 0; i < pReq.numOfColumns; ++i) { @@ -1059,7 +1059,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, setFieldWithOptions(&fieldWithOption, pField); setDefaultOptionsForField(&fieldWithOption); if (taosArrayPush(pReq.pColumns, &fieldWithOption) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1106,7 +1106,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; tstrncpy(field.name, tsSmlTagName, sizeof(field.name)); if (taosArrayPush(pReq.pTags, &field) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1124,7 +1124,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, } pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen); if (NULL == pCmdMsg.pMsg) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -1185,7 +1185,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { void *superTable = taosHashGetKey(tmp, &superTableLen); char *measure = taosMemoryMalloc(superTableLen); if (measure == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } (void)memcpy(measure, superTable, superTableLen); @@ -1205,12 +1205,12 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { uDebug("SML:0x%" PRIx64 " smlModifyDBSchemas create table:%s", info->id, pName.tname); SArray *pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols), sizeof(SField)); if (pColumns == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } SArray *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField)); if (pTags == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosArrayDestroy(pColumns); goto end; } @@ -1252,7 +1252,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { hashTmp = taosHashInit(pTableMeta->tableInfo.numOfTags, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (hashTmp == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } for (uint16_t i = pTableMeta->tableInfo.numOfColumns; @@ -1278,14 +1278,14 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { SArray *pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols) + pTableMeta->tableInfo.numOfColumns, sizeof(SField)); if (pColumns == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } SArray *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField)); if (pTags == NULL){ taosArrayDestroy(pColumns); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } for (uint16_t i = 0; i < pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags; i++) { @@ -1297,14 +1297,14 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { if (taosArrayPush(pColumns, &field) == NULL){ taosArrayDestroy(pColumns); taosArrayDestroy(pTags); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } else { if (taosArrayPush(pTags, &field) == NULL){ taosArrayDestroy(pColumns); taosArrayDestroy(pTags); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1374,14 +1374,14 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { SArray *pColumns = taosArrayInit(taosArrayGetSize(sTableData->cols) + pTableMeta->tableInfo.numOfColumns, sizeof(SField)); if (pColumns == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } SArray *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField)); if (pTags == NULL){ taosArrayDestroy(pColumns); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } for (uint16_t i = 0; i < pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags; i++) { @@ -1393,14 +1393,14 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { if (taosArrayPush(pColumns, &field) == NULL){ taosArrayDestroy(pColumns); taosArrayDestroy(pTags); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } else { if (taosArrayPush(pTags, &field) == NULL){ taosArrayDestroy(pColumns); taosArrayDestroy(pTags); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1497,7 +1497,7 @@ static int32_t smlInsertMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &i, SHORT_BYTES); if (ret == 0) { if (taosArrayPush(metaArray, kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if(taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) { return TSDB_CODE_PAR_DUPLICATED_COLUMN; @@ -1547,7 +1547,7 @@ static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols int ret = taosHashPut(metaHash, kv->key, kv->keyLen, &size, SHORT_BYTES); if (ret == 0) { if(taosArrayPush(metaArray, kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if(taosHashGet(checkDuplicate, kv->key, kv->keyLen) != NULL) { return TSDB_CODE_PAR_DUPLICATED_COLUMN; @@ -1646,7 +1646,7 @@ int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) { info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (info->pVgHash == NULL || info->childTables == NULL || info->superTables == NULL || info->tableUids == NULL) { uError("create SSmlHandle hash obj failed"); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAILED; } taosHashSetFreeFp(info->superTables, smlDestroySTableMeta); @@ -1665,7 +1665,7 @@ int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle) { if (info->tagJsonArray == NULL || info->valueJsonArray == NULL || info->preLineTagKV == NULL) { uError("SML:0x%" PRIx64 " failed to allocate memory", info->id); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAILED; } @@ -1681,7 +1681,7 @@ static int32_t smlPushCols(SArray *colsArray, SArray *cols) { SHashObj *kvHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (!kvHash) { uError("SML:smlDealCols failed to allocate memory"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (size_t i = 0; i < taosArrayGetSize(cols); i++) { SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i); @@ -1703,7 +1703,7 @@ static int32_t smlPushCols(SArray *colsArray, SArray *cols) { if (taosArrayPush(colsArray, &kvHash) == NULL) { taosHashCleanup(kvHash); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -1799,12 +1799,12 @@ static int32_t smlInsertData(SSmlHandle *info) { if (info->pRequest->dbList == NULL) { info->pRequest->dbList = taosArrayInit(1, TSDB_DB_FNAME_LEN); if (info->pRequest->dbList == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } char *data = (char *)taosArrayReserve(info->pRequest->dbList, 1); if (data == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}}; tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname)); @@ -1817,7 +1817,7 @@ static int32_t smlInsertData(SSmlHandle *info) { int measureLen = tableData->sTableNameLen; char *measure = (char *)taosMemoryMalloc(tableData->sTableNameLen); if (measure == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(measure, tableData->sTableName, tableData->sTableNameLen); PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen); @@ -1828,11 +1828,11 @@ static int32_t smlInsertData(SSmlHandle *info) { if (info->pRequest->tableList == NULL) { info->pRequest->tableList = taosArrayInit(1, sizeof(SName)); if (info->pRequest->tableList == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } if (taosArrayPush(info->pRequest->tableList, &pName) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tstrncpy(pName.tname, tableData->childTableName, sizeof(pName.tname)); diff --git a/source/client/src/clientSmlJson.c b/source/client/src/clientSmlJson.c index 10ff234552..ece1ddf61f 100644 --- a/source/client/src/clientSmlJson.c +++ b/source/client/src/clientSmlJson.c @@ -526,7 +526,7 @@ static int32_t smlProcessTagJson(SSmlHandle *info, cJSON *tags){ return ret; } if (taosArrayPush(preLineKV, &kv) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) { @@ -873,7 +873,7 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo * if (taosArrayPush(info->tagJsonArray, &valueJson) == NULL){ cJSON_Delete(valueJson); elements->cols[elements->colsLen] = tmp; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ret = smlParseValueFromJSONObj(valueJson, &kv); if (ret != TSDB_CODE_SUCCESS) { @@ -901,7 +901,7 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo * if (taosArrayPush(info->tagJsonArray, &tagsJson) == NULL){ cJSON_Delete(tagsJson); uError("SML:0x%" PRIx64 " taosArrayPush failed", info->id); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ret = smlParseTagsFromJSON(info, tagsJson, elements); if (unlikely(ret)) { @@ -965,7 +965,7 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) { payloadNum = payloadNum << 1; void *tmp = taosMemoryRealloc(info->lines, payloadNum * sizeof(SSmlLineInfo)); if (tmp == NULL) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; return ret; } info->lines = (SSmlLineInfo *)tmp; diff --git a/source/client/src/clientSmlLine.c b/source/client/src/clientSmlLine.c index 14a334e54c..e620ca9b0c 100644 --- a/source/client/src/clientSmlLine.c +++ b/source/client/src/clientSmlLine.c @@ -150,7 +150,7 @@ int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) { } void *data = taosMemoryMalloc(pVal->length); if(data == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(data, pVal->value + (NCHAR_ADD_LEN - 1), pVal->length); pVal->value = data; @@ -271,7 +271,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){ if (keyEscaped) { char *tmp = (char *)taosMemoryMalloc(keyLen); if (tmp == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(tmp, key, keyLen); PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, keyLen); @@ -280,7 +280,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){ if (valueEscaped) { char *tmp = (char *)taosMemoryMalloc(valueLen); if (tmp == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(tmp, value, valueLen); PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, valueLen); @@ -294,7 +294,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){ .keyEscaped = keyEscaped, .valueEscaped = valueEscaped}; if(taosArrayPush(preLineKV, &kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) { @@ -422,7 +422,7 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL if (keyEscaped) { char *tmp = (char *)taosMemoryMalloc(kv.keyLen); if (tmp == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(tmp, key, kv.keyLen); PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, kv.keyLen); @@ -433,7 +433,7 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL if (valueEscaped) { char *tmp = (char *)taosMemoryMalloc(kv.length); if (tmp == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(tmp, kv.value, kv.length); PROCESS_SLASH_IN_FIELD_VALUE(tmp, kv.length); @@ -459,11 +459,11 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL if (currElement->colArray == NULL) { currElement->colArray = taosArrayInit_s(sizeof(SSmlKv), 1); if (currElement->colArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } if (taosArrayPush(currElement->colArray, &kv) == NULL){ // reserve for timestamp - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/client/src/clientSmlTelnet.c b/source/client/src/clientSmlTelnet.c index a25ef4ec95..e8601e33bc 100644 --- a/source/client/src/clientSmlTelnet.c +++ b/source/client/src/clientSmlTelnet.c @@ -132,7 +132,7 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){ .keyEscaped = false, .valueEscaped = false}; if (taosArrayPush(preLineKV, &kv) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) { return TSDB_CODE_SML_INVALID_DATA; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 52b56abb91..175628cc7d 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -15,7 +15,7 @@ static FORCE_INLINE int32_t stmtAllocQNodeFromBuf(STableBufInfo* pTblBuf, void** } else if (pTblBuf->buffIdx < taosArrayGetSize(pTblBuf->pBufList)) { pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, pTblBuf->buffIdx++); if (NULL == pTblBuf->pCurBuff) { - return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + return TAOS_GET_TERRNO(terrno); } *pBuf = pTblBuf->pCurBuff; pTblBuf->buffOffset = pTblBuf->buffUnit; @@ -186,7 +186,7 @@ int32_t stmtBackupQueryFields(STscStmt* pStmt) { pRes->fields = taosMemoryMalloc(size); pRes->userFields = taosMemoryMalloc(size); if (NULL == pRes->fields || NULL == pRes->userFields) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } (void)memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size); (void)memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size); @@ -204,7 +204,7 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) { if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { pStmt->exec.pRequest->body.resInfo.fields = taosMemoryMalloc(size); if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } (void)memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size); } @@ -212,7 +212,7 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) { if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { pStmt->exec.pRequest->body.resInfo.userFields = taosMemoryMalloc(size); if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } (void)memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size); } @@ -306,7 +306,7 @@ int32_t stmtCacheBlock(STscStmt* pStmt) { }; if (taosHashPut(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid), &cache, sizeof(cache))) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pStmt->sql.autoCreateTbl) { @@ -369,7 +369,7 @@ int32_t stmtParseSql(STscStmt* pStmt) { if (NULL == pStmt->sql.pBindInfo) { pStmt->sql.pBindInfo = taosMemoryMalloc(pTableCtx->boundColsInfo.numOfBound * sizeof(*pStmt->sql.pBindInfo)); if (NULL == pStmt->sql.pBindInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -612,7 +612,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, POINTER_BYTES)) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } pStmt->exec.pCurrBlock = pNewBlock; @@ -702,7 +702,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, POINTER_BYTES)) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } pStmt->exec.pCurrBlock = pNewBlock; @@ -722,7 +722,6 @@ int32_t stmtResetStmt(STscStmt* pStmt) { pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (NULL == pStmt->sql.pTableCache) { - terrno = TSDB_CODE_OUT_OF_MEMORY; STMT_ERR_RET(terrno); } @@ -739,7 +738,7 @@ int32_t stmtAsyncOutput(STscStmt* pStmt, void* param) { SArray** p = (SArray**)TARRAY_GET_ELEM(pStmt->sql.siInfo.pTableCols, i); *p = taosArrayInit(20, POINTER_BYTES); if (*p == NULL) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } } @@ -812,15 +811,15 @@ int32_t stmtInitTableBuf(STableBufInfo* pTblBuf) { pTblBuf->buffSize = pTblBuf->buffUnit * 1000; pTblBuf->pBufList = taosArrayInit(100, POINTER_BYTES); if (NULL == pTblBuf->pBufList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* buff = taosMemoryMalloc(pTblBuf->buffSize); if (NULL == buff) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTblBuf->pCurBuff = buff; @@ -948,11 +947,11 @@ int32_t stmtInitStbInterlaceTableInfo(STscStmt* pStmt) { for (int32_t i = 0; i < STMT_TABLE_COLS_NUM; i++) { pTblCols = taosArrayInit(20, POINTER_BYTES); if (NULL == pTblCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -1184,11 +1183,11 @@ static FORCE_INLINE int32_t stmtGetTableColsFromCache(STscStmt* pStmt, SArray** for (int32_t i = 0; i < 100; i++) { pTblCols = taosArrayInit(20, POINTER_BYTES); if (NULL == pTblCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index e7e08c0982..01a7c4be4c 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -643,7 +643,6 @@ static int32_t stmtResetStmt(STscStmt2* pStmt) { pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (NULL == pStmt->sql.pTableCache) { - terrno = TSDB_CODE_OUT_OF_MEMORY; STMT_ERR_RET(terrno); } @@ -660,7 +659,7 @@ static int32_t stmtAsyncOutput(STscStmt2* pStmt, void* param) { SArray** p = (SArray**)TARRAY_GET_ELEM(pStmt->sql.siInfo.pTableCols, i); *p = taosArrayInit(20, POINTER_BYTES); if (*p == NULL) { - STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + STMT_ERR_RET(terrno); } } @@ -733,15 +732,15 @@ static int32_t stmtInitTableBuf(STableBufInfo* pTblBuf) { pTblBuf->buffSize = pTblBuf->buffUnit * 1000; pTblBuf->pBufList = taosArrayInit(100, POINTER_BYTES); if (NULL == pTblBuf->pBufList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* buff = taosMemoryMalloc(pTblBuf->buffSize); if (NULL == buff) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTblBuf->pCurBuff = buff; @@ -796,7 +795,7 @@ TAOS_STMT2* stmtInit2(STscObj* taos, TAOS_STMT2_OPTION* pOptions) { } pStmt->sql.siInfo.pTableCols = taosArrayInit(STMT_TABLE_COLS_NUM, POINTER_BYTES); if (NULL == pStmt->sql.siInfo.pTableCols) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + terrno = terrno; (void)stmtClose(pStmt); return NULL; } @@ -889,11 +888,11 @@ static int32_t stmtInitStbInterlaceTableInfo(STscStmt2* pStmt) { for (int32_t i = 0; i < STMT_TABLE_COLS_NUM; i++) { pTblCols = taosArrayInit(20, POINTER_BYTES); if (NULL == pTblCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -1121,11 +1120,11 @@ static FORCE_INLINE int32_t stmtGetTableColsFromCache(STscStmt2* pStmt, SArray** for (int32_t i = 0; i < 100; i++) { pTblCols = taosArrayInit(20, POINTER_BYTES); if (NULL == pTblCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -1160,7 +1159,7 @@ static int32_t stmtCacheBlock(STscStmt2* pStmt) { }; if (taosHashPut(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid), &cache, sizeof(cache))) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pStmt->sql.autoCreateTbl) { @@ -1554,7 +1553,7 @@ static int32_t createParseContext(const SRequestObj* pRequest, SParseContext** p *pCxt = taosMemoryCalloc(1, sizeof(SParseContext)); if (*pCxt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } **pCxt = (SParseContext){.requestId = pRequest->requestId, @@ -1671,7 +1670,7 @@ int stmtExec2(TAOS_STMT2* stmt, int* affected_rows) { } else { SSqlCallbackWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper)); if (pWrapper == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pWrapper->pRequest = pRequest; pRequest->pWrapper = pWrapper; diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 783815d97f..cd443f88e5 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -1094,7 +1094,7 @@ int32_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) { if (*topics == NULL) { *topics = tmq_list_new(); if (*topics == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } taosRLockLatch(&tmq->lock); @@ -1353,7 +1353,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { req.topicNames = taosArrayInit(sz, sizeof(void*)); if (req.topicNames == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAIL; } @@ -1394,7 +1394,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { } if (taosArrayPush(req.topicNames, &topicFName) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(topicFName); goto FAIL; } @@ -1404,7 +1404,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { int32_t tlen = tSerializeSCMSubscribeReq(NULL, &req); buf = taosMemoryMalloc(tlen); if (buf == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto FAIL; } @@ -2017,7 +2017,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p pParam = taosMemoryMalloc(sizeof(SMqPollCbParam)); if (pParam == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFreeClear(msg); return code; } @@ -2713,7 +2713,7 @@ int32_t tmq_commit_sync(tmq_t* tmq, const TAOS_RES* pRes) { SSyncCommitInfo* pInfo = taosMemoryMalloc(sizeof(SSyncCommitInfo)); if (pInfo == NULL) { tscError("failed to allocate memory for sync commit"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tsem2_init(&pInfo->sem, 0, 0) != 0) { tscError("failed to init sem for sync commit"); @@ -2785,7 +2785,7 @@ int32_t tmq_commit_offset_sync(tmq_t* tmq, const char* pTopicName, int32_t vgId, SSyncCommitInfo* pInfo = taosMemoryMalloc(sizeof(SSyncCommitInfo)); if (pInfo == NULL) { tscError("consumer:0x%" PRIx64 " failed to prepare seek operation", tmq->consumerId); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tsem2_init(&pInfo->sem, 0, 0) != 0) { @@ -2922,7 +2922,7 @@ FAIL: int32_t syncAskEp(tmq_t* pTmq) { SAskEpInfo* pInfo = taosMemoryMalloc(sizeof(SAskEpInfo)); - if (pInfo == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pInfo == NULL) return terrno; if (tsem2_init(&pInfo->sem, 0, 0) != 0) { taosMemoryFree(pInfo); return TSDB_CODE_TSC_INTERNAL_ERROR; @@ -3427,7 +3427,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a pCommon->pList = taosArrayInit(4, sizeof(tmq_topic_assignment)); if (pCommon->pList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (tsem2_init(&pCommon->rsp, 0, 0) != 0) { @@ -3445,7 +3445,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a } SMqVgWalInfoParam* pParam = taosMemoryMalloc(sizeof(SMqVgWalInfoParam)); if (pParam == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -3649,7 +3649,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_ if (pParam == NULL) { taosMemoryFree(msg); taosMemoryFree(sendInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (tsem2_init(&pParam->sem, 0, 0) != 0) { taosMemoryFree(msg); From 2c53c08726de3fb3171437a027ca2fcd54831533 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Thu, 12 Sep 2024 11:31:10 +0800 Subject: [PATCH 73/90] fix(stream):fix issue when ts less than 0 --- source/libs/stream/src/streamUpdate.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index 40de393570..9a1a30ac7b 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -155,7 +155,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b } pInfo->pTsBuckets = NULL; pInfo->pTsSBFs = NULL; - pInfo->minTS = -1; + pInfo->minTS = INT64_MIN; pInfo->interval = adjustInterval(interval, precision); pInfo->watermark = adjustWatermark(pInfo->interval, interval, watermark); pInfo->numSBFs = 0; @@ -181,7 +181,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b QUERY_CHECK_CODE(code, lino, _end); } - TSKEY dumy = 0; + TSKEY dumy = INT64_MIN; for (uint64_t i = 0; i < DEFAULT_BUCKET_SIZE; ++i) { void* tmp = taosArrayPush(pInfo->pTsBuckets, &dumy); if (!tmp) { @@ -231,11 +231,7 @@ _end: static int32_t getSBf(SUpdateInfo* pInfo, TSKEY ts, SScalableBf** ppSBf) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; - if (ts < 0) { - code = TSDB_CODE_FAILED; - QUERY_CHECK_CODE(code, lino, _end); - } - if (pInfo->minTS < 0) { + if (pInfo->minTS == INT64_MIN) { pInfo->minTS = (TSKEY)(ts / pInfo->interval * pInfo->interval); } int64_t index = (int64_t)((ts - pInfo->minTS) / pInfo->interval); @@ -349,7 +345,7 @@ bool updateInfoIsUpdated(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* p void** pMapMaxTs = taosHashGet(pInfo->pMap, &tableId, sizeof(uint64_t)); uint64_t index = ((uint64_t)tableId) % pInfo->numBuckets; TSKEY maxTs = *(TSKEY*)taosArrayGet(pInfo->pTsBuckets, index); - if (ts < maxTs - pInfo->watermark) { + if (ts < maxTs - pInfo->watermark && maxTs != INT64_MIN) { // this window has been closed. if (pInfo->pCloseWinSBF) { code = tScalableBfPut(pInfo->pCloseWinSBF, pInfo->pKeyBuff, buffLen, &res); From d01670d49a8ec2fb4891d1ff1476ee3786df39b3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 12 Sep 2024 14:06:25 +0800 Subject: [PATCH 74/90] fix(stream): fix the error in the checkpoint-trigger confirm condition. --- source/libs/stream/src/streamDispatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index eb6c9c1a66..32fb67dd98 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -1494,7 +1494,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i streamMutexLock(&pTask->lock); SStreamTaskState s = streamTaskGetStatus(pTask); triggerDispatchRsp = (s.state == TASK_STATUS__CK) && (pInfo->activeId == pMsgInfo->checkpointId) && - (pInfo->transId != pMsgInfo->transId); + (pInfo->transId == pMsgInfo->transId); tmpCheckpointId = pInfo->activeId; tmpTranId = pInfo->transId; pStatus = s.name; From a7269e4536caba4b31b0c7b2932ff5a925a85090 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 12 Sep 2024 14:17:14 +0800 Subject: [PATCH 75/90] fix: remove void function call --- include/util/tqueue.h | 2 +- source/client/src/clientMonitor.c | 2 +- source/libs/catalog/src/catalog.c | 22 +++++-- source/libs/catalog/src/ctgAsync.c | 12 +++- source/libs/catalog/src/ctgCache.c | 31 ++++++--- source/libs/catalog/src/ctgRemote.c | 58 +++++++++++++---- source/libs/catalog/src/ctgUtil.c | 27 ++++++-- source/libs/executor/src/dataDeleter.c | 4 +- source/libs/executor/src/dataDispatcher.c | 4 +- source/libs/executor/src/dataInserter.c | 10 ++- .../libs/executor/src/dynqueryctrloperator.c | 27 ++++++-- source/libs/executor/src/groupcacheoperator.c | 63 ++++++++++++++++--- source/libs/executor/src/mergejoin.c | 5 +- source/libs/executor/src/mergejoinoperator.c | 4 +- source/libs/qworker/src/qwUtil.c | 5 +- source/libs/qworker/src/qworker.c | 13 +++- source/libs/scheduler/inc/schInt.h | 4 +- source/libs/scheduler/src/schJob.c | 29 +++++++-- source/libs/scheduler/src/schTask.c | 12 +++- source/libs/scheduler/src/schUtil.c | 11 +++- source/libs/scheduler/src/scheduler.c | 6 +- source/util/src/thash.c | 4 +- source/util/src/tqueue.c | 6 +- source/util/src/tref.c | 2 +- source/util/src/tsimplehash.c | 2 +- source/util/src/ttimer.c | 3 + 26 files changed, 287 insertions(+), 81 deletions(-) diff --git a/include/util/tqueue.h b/include/util/tqueue.h index f7eaf794b0..5ae642b69f 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -79,7 +79,7 @@ void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp); int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item); void taosFreeQitem(void *pItem); int32_t taosWriteQitem(STaosQueue *queue, void *pItem); -int32_t taosReadQitem(STaosQueue *queue, void **ppItem); +void taosReadQitem(STaosQueue *queue, void **ppItem); bool taosQueueEmpty(STaosQueue *queue); void taosUpdateItemSize(STaosQueue *queue, int32_t items); int32_t taosQueueItemSize(STaosQueue *queue); diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 9ed6512352..6904ea850c 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -730,7 +730,7 @@ static void* monitorThreadFunc(void* param) { } MonitorSlowLogData* slowLogData = NULL; - (void)taosReadQitem(monitorQueue, (void**)&slowLogData); + taosReadQitem(monitorQueue, (void**)&slowLogData); if (slowLogData != NULL) { if (slowLogData->type == SLOW_LOG_READ_BEGINNIG && quitCnt == 0) { if (slowLogData->pFile != NULL) { diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 0b0cb6dc91..43c12f8164 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -706,7 +706,9 @@ void ctgProcessTimerEvent(void *param, void *tmrId) { int32_t code = ctgClearCacheEnqueue(NULL, true, false, false, false); if (code) { qError("clear cache enqueue failed, error:%s", tstrerror(code)); - (void)taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer); + if (taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer)) { + qError("reset catalog cache monitor timer error, timer stoppped"); + } } goto _return; @@ -714,7 +716,9 @@ void ctgProcessTimerEvent(void *param, void *tmrId) { } qTrace("reset catalog timer"); - (void)taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer); + if (taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer)) { + qError("reset catalog cache monitor timer error, timer stoppped"); + } _return: @@ -1517,10 +1521,16 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SC _return: if (pJob) { - (void)taosReleaseRef(gCtgMgmt.jobPool, pJob->refId); + int32_t code2 = taosReleaseRef(gCtgMgmt.jobPool, pJob->refId); + if (TSDB_CODE_SUCCESS) { + qError("release catalog job refId %" PRId64 "falied, error:%s", pJob->refId, tstrerror(code2)); + } if (code) { - (void)taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); + code2 = taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); + if (TSDB_CODE_SUCCESS) { + qError("remove catalog job refId %" PRId64 "falied, error:%s", pJob->refId, tstrerror(code2)); + } } } @@ -1967,7 +1977,9 @@ void catalogDestroy(void) { } if (gCtgMgmt.cacheTimer) { - (void)taosTmrStop(gCtgMgmt.cacheTimer); + if (taosTmrStop(gCtgMgmt.cacheTimer)) { + qTrace("stop catalog cache timer may failed"); + } gCtgMgmt.cacheTimer = NULL; taosTmrCleanUp(gCtgMgmt.timer); gCtgMgmt.timer = NULL; diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index e35aaeb0b1..9940474891 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -1007,7 +1007,11 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const CTG_ERR_JRET(terrno); } - (void)taosAcquireRef(gCtgMgmt.jobPool, pJob->refId); + void* p = taosAcquireRef(gCtgMgmt.jobPool, pJob->refId); + if (NULL == p) { + ctgError("acquire job from ref failed, refId:%" PRId64 ", error: %s", pJob->refId, tstrerror(terrno)); + CTG_ERR_JRET(terrno); + } double el = (taosGetTimestampUs() - st) / 1000.0; qDebug("qid:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d, elapsed time:%.2f ms", @@ -1406,7 +1410,11 @@ int32_t ctgCallUserCb(void* param) { qDebug("qid:0x%" PRIx64 " ctg end to call user cb", pJob->queryId); - (void)taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); + int64_t refId = pJob->refId; + int32_t code = taosRemoveRef(gCtgMgmt.jobPool, refId); + if (code) { + qError("qid:0x%" PRIx64 " remove ctg job %" PRId64 " from jobPool failed, error:%s", pJob->queryId, refId, tstrerror(code)); + } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 01201a2480..0e54ac77a2 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -2915,21 +2915,27 @@ void ctgClearMetaCache(SCtgCacheOperation *operation) { if (CTG_CACHE_LOW(remainSize, cacheMaxSize)) { qDebug("catalog finish meta clear, remainSize:%" PRId64 ", cacheMaxSize:%dMB", remainSize, cacheMaxSize); - (void)taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer); + if (taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer)) { + qError("reset catalog cache monitor timer error, timer stoppped"); + } return; } if (!roundDone) { qDebug("catalog all meta cleared, remainSize:%" PRId64 ", cacheMaxSize:%dMB, to clear handle", remainSize, cacheMaxSize); ctgClearFreeCache(operation); - (void)taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer); + if (taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer)) { + qError("reset catalog cache monitor timer error, timer stoppped"); + } return; } int32_t code = ctgClearCacheEnqueue(NULL, true, false, false, false); if (code) { qError("clear cache enqueue failed, error:%s", tstrerror(code)); - (void)taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer); + if (taosTmrReset(ctgProcessTimerEvent, CTG_DEFAULT_CACHE_MON_MSEC, NULL, gCtgMgmt.timer, &gCtgMgmt.cacheTimer)) { + qError("reset catalog cache monitor timer error, timer stoppped"); + } } } @@ -2993,7 +2999,10 @@ int32_t ctgOpDropTbTSMA(SCtgCacheOperation *operation) { pCtgCache->pTsmas = NULL; ctgDebug("all tsmas for table dropped: %s.%s", msg->dbFName, msg->tbName); - (void)taosHashRemove(dbCache->tsmaCache, msg->tbName, TSDB_TABLE_NAME_LEN); + code = taosHashRemove(dbCache->tsmaCache, msg->tbName, TSDB_TABLE_NAME_LEN); + if (TSDB_CODE_SUCCESS != code) { + ctgError("remove table %s.%s from tsmaCache failed, error:%s", msg->dbFName, msg->tbName, tstrerror(code)); + } CTG_UNLOCK(CTG_WRITE, &pCtgCache->tsmaLock); } else { @@ -3191,6 +3200,7 @@ void ctgCleanupCacheQueue(void) { SCtgQNode *nodeNext = NULL; SCtgCacheOperation *op = NULL; bool stopQueue = false; + int32_t code = 0; while (true) { node = gCtgMgmt.queue.head->next; @@ -3209,7 +3219,10 @@ void ctgCleanupCacheQueue(void) { } if (op->syncOp) { - (void)tsem_post(&op->rspSem); + code = tsem_post(&op->rspSem); + if (code) { + qError("tsem_post failed when cleanup cache queue, error:%s", tstrerror(code)); + } } else { taosMemoryFree(op); } @@ -3234,12 +3247,13 @@ void ctgCleanupCacheQueue(void) { void *ctgUpdateThreadFunc(void *param) { setThreadName("catalog"); + int32_t code = 0; qInfo("catalog update thread started"); while (true) { if (tsem_wait(&gCtgMgmt.queue.reqSem)) { - qError("ctg tsem_wait failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); + qError("ctg tsem_wait failed, error:%s", tstrerror(terrno)); } if (atomic_load_8((int8_t *)&gCtgMgmt.queue.stopQueue)) { @@ -3256,7 +3270,10 @@ void *ctgUpdateThreadFunc(void *param) { (void)(*gCtgCacheOperation[operation->opId].func)(operation); // ignore any error if (operation->syncOp) { - (void)tsem_post(&operation->rspSem); + code = tsem_post(&operation->rspSem); + if (code) { + ctgError("tsem_post failed for syncOp update, error:%s", tstrerror(code)); + } } else { taosMemoryFreeClear(operation); } diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 00b1d7ad79..c9114ce90e 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -470,7 +470,10 @@ _return: taosMemoryFree(pMsg->pEpSet); if (pJob) { - (void)taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId); + int32_t code2 = taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId); + if (code2) { + qError("release ctg job refId:%" PRId64 " failed, error:%s", cbParam->refId, tstrerror(code2)); + } } CTG_API_LEAVE(code); @@ -1087,11 +1090,16 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* n int32_t reqType = TDMT_MND_GET_TABLE_INDEX; void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char tbFName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(name, tbFName); ctgDebug("try to get tb index from mnode, tbFName:%s", tbFName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp); + int32_t code = tNameExtractFullName(name, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), name->type, name->dbname, name->tname); + CTG_ERR_RET(code); + } + + code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build get index msg failed, code:%s, tbFName:%s", tstrerror(code), tbFName); CTG_ERR_RET(code); @@ -1403,17 +1411,23 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S int32_t msgLen = 0; int32_t reqType = TDMT_VND_TABLE_CFG; char tbFName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(pTableName, tbFName); + void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char dbFName[TSDB_DB_FNAME_LEN]; (void)tNameGetFullDbName(pTableName, dbFName); SBuildTableInput bInput = {.vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char*)pTableName->tname}; + int32_t code = tNameExtractFullName(pTableName, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), pTableName->type, pTableName->dbname, pTableName->tname); + CTG_ERR_RET(code); + } + SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse]; ctgDebug("try to get table cfg from vnode, vgId:%d, ep num:%d, ep %s:%d, tbFName:%s", vgroupInfo->vgId, vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp); + code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build get tb cfg msg failed, code:%s, tbFName:%s", tstrerror(code), tbFName); CTG_ERR_RET(code); @@ -1471,15 +1485,20 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S int32_t msgLen = 0; int32_t reqType = TDMT_MND_TABLE_CFG; char tbFName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(pTableName, tbFName); void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char dbFName[TSDB_DB_FNAME_LEN]; (void)tNameGetFullDbName(pTableName, dbFName); SBuildTableInput bInput = {.vgId = 0, .dbFName = dbFName, .tbName = (char*)pTableName->tname}; + int32_t code = tNameExtractFullName(pTableName, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), pTableName->type, pTableName->dbname, pTableName->tname); + CTG_ERR_RET(code); + } + ctgDebug("try to get table cfg from mnode, tbFName:%s", tbFName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp); + code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build get tb cfg msg failed, code:%s, tbFName:%s", tstrerror(code), tbFName); CTG_ERR_RET(code); @@ -1583,11 +1602,15 @@ int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* SCtgTask* pTask = tReq ? tReq->pTask : NULL; void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char fullName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(pName, fullName); + int32_t code = tNameExtractFullName(pName, fullName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), pName->type, pName->dbname, pName->tname); + CTG_ERR_RET(code); + } ctgDebug("try to get view info from mnode, viewFName:%s", fullName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](fullName, &msg, 0, &msgLen, mallocFp); + code = queryBuildMsg[TMSG_INDEX(reqType)](fullName, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build view-meta msg failed, code:%x, viewFName:%s", code, fullName); CTG_ERR_RET(code); @@ -1640,11 +1663,15 @@ int32_t ctgGetTbTSMAFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa SCtgTask* pTask = tReq ? tReq->pTask : NULL; void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char tbFName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(name, tbFName); + int32_t code = tNameExtractFullName(name, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), name->type, name->dbname, name->tname); + CTG_ERR_RET(code); + } ctgDebug("try to get tb index from mnode, tbFName:%s", tbFName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp); + code = queryBuildMsg[TMSG_INDEX(reqType)]((void*)tbFName, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build get index msg failed, code:%s, tbFName:%s", tstrerror(code), tbFName); CTG_ERR_RET(code); @@ -1697,7 +1724,12 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c int32_t msgLen = 0; int32_t reqType = TDMT_VND_GET_STREAM_PROGRESS; char tbFName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(pTbName, tbFName); + int32_t code = tNameExtractFullName(pTbName, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, code:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), pTbName->type, pTbName->dbname, pTbName->tname); + CTG_ERR_RET(code); + } + SCtgTask* pTask = tReq ? tReq->pTask : NULL; void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; @@ -1705,7 +1737,7 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c ctgDebug("try to get stream progress from vnode, vgId:%d, ep num:%d, ep %s:%d, target:%s", vgroupInfo->vgId, vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName); - int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](bInput, &msg, 0, &msgLen, mallocFp); + code = queryBuildMsg[TMSG_INDEX(reqType)](bInput, &msg, 0, &msgLen, mallocFp); if (code) { ctgError("Build get stream progress failed, code:%s, tbFName:%s", tstrerror(code), tbFName); CTG_ERR_RET(code); diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index daa2199421..545e3e1371 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -433,6 +433,7 @@ void ctgFreeHandle(SCatalog* pCtg) { void ctgClearHandleMeta(SCatalog* pCtg, int64_t* pClearedSize, int64_t* pCleardNum, bool* roundDone) { int64_t cacheSize = 0; + int32_t code = 0; void* pIter = taosHashIterate(pCtg->dbCache, NULL); while (pIter) { SCtgDBCache* dbCache = pIter; @@ -447,7 +448,10 @@ void ctgClearHandleMeta(SCatalog* pCtg, int64_t* pClearedSize, int64_t* pCleardN continue; } - (void)taosHashRemove(dbCache->tbCache, key, len); + code = taosHashRemove(dbCache->tbCache, key, len); + if (code) { + qError("taosHashRemove table cache failed, key:%s, len:%d, error:%s", (char*)key, (int32_t)len, tstrerror(code)); + } cacheSize = len + sizeof(SCtgTbCache) + ctgGetTbMetaCacheSize(pCache->pMeta) + ctgGetTbIndexCacheSize(pCache->pIndex); @@ -1201,8 +1205,12 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SEpSet* pMgmtEps, SDBVgInfo* d SVgroupInfo* vgInfo = NULL; char tbFullName[TSDB_TABLE_FNAME_LEN]; - (void)tNameExtractFullName(pTableName, tbFullName); - + code = tNameExtractFullName(pTableName, tbFullName); + if (code) { + ctgError("tNameExtractFullName failed, error:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), pTableName->type, pTableName->dbname, pTableName->tname); + CTG_ERR_RET(code); + } + uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, dbInfo->hashPrefix, dbInfo->hashSuffix); @@ -1965,7 +1973,12 @@ int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) { char tbFName[TSDB_TABLE_FNAME_LEN]; char dbFName[TSDB_DB_FNAME_LEN]; - (void)tNameExtractFullName(&req->pRawReq->tbName, tbFName); + code = tNameExtractFullName(&req->pRawReq->tbName, tbFName); + if (code) { + ctgError("tNameExtractFullName failed, error:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), req->pRawReq->tbName.type, req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname); + CTG_ERR_RET(code); + } + (void)tNameGetFullDbName(&req->pRawReq->tbName, dbFName); while (true) { @@ -2151,7 +2164,11 @@ int32_t ctgChkSetViewAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) if (IS_SYS_DBNAME(req->pRawReq->tbName.dbname)) { (void)snprintf(viewFName, sizeof(viewFName), "%s.%s", req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname); } else { - (void)tNameExtractFullName(&req->pRawReq->tbName, viewFName); + code = tNameExtractFullName(&req->pRawReq->tbName, viewFName); + if (code) { + ctgError("tNameExtractFullName failed, error:%s, type:%d, dbName:%s, tname:%s", tstrerror(code), req->pRawReq->tbName.type, req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname); + CTG_ERR_RET(code); + } } int32_t len = strlen(viewFName) + 1; diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c index 60bfb58ef5..57f4289ebf 100644 --- a/source/libs/executor/src/dataDeleter.c +++ b/source/libs/executor/src/dataDeleter.c @@ -190,7 +190,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRaw } SDataDeleterBuf* pBuf = NULL; - (void)taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); if (pBuf != NULL) { TAOS_MEMCPY(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf)); taosFreeQitem(pBuf); @@ -248,7 +248,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { taosMemoryFree(pDeleter->pParam); while (!taosQueueEmpty(pDeleter->pDataBlocks)) { SDataDeleterBuf* pBuf = NULL; - (void)taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); if (pBuf != NULL) { taosMemoryFreeClear(pBuf->pData); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 9bbc5a94eb..8acd569358 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -233,7 +233,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRow } SDataDispatchBuf* pBuf = NULL; - (void)taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); + taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); if (pBuf != NULL) { TAOS_MEMCPY(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf)); taosFreeQitem(pBuf); @@ -291,7 +291,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { while (!taosQueueEmpty(pDispatcher->pDataBlocks)) { SDataDispatchBuf* pBuf = NULL; - (void)taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); + taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); if (pBuf != NULL) { taosMemoryFreeClear(pBuf->pData); taosFreeQitem(pBuf); diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index 5ed97c8db6..b29bef1f1e 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -57,6 +57,7 @@ typedef struct SSubmitRspParam { int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { SSubmitRspParam* pParam = (SSubmitRspParam*)param; SDataInserterHandle* pInserter = pParam->pInserter; + int32_t code2 = 0; if (code) { pInserter->submitRes.code = code; @@ -106,7 +107,14 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { _return: - (void)tsem_post(&pInserter->ready); + code2 = tsem_post(&pInserter->ready); + if (code2 < 0) { + qError("tsem_post inserter ready failed, error:%s", tstrerror(code2)); + if (TSDB_CODE_SUCCESS == code) { + pInserter->submitRes.code = code2; + } + } + taosMemoryFree(pMsg->pData); return TSDB_CODE_SUCCESS; diff --git a/source/libs/executor/src/dynqueryctrloperator.c b/source/libs/executor/src/dynqueryctrloperator.c index 44e8a3cb8a..3d23130e13 100644 --- a/source/libs/executor/src/dynqueryctrloperator.c +++ b/source/libs/executor/src/dynqueryctrloperator.c @@ -561,7 +561,8 @@ static int32_t notifySeqJoinTableCacheEnd(SOperatorInfo* pOperator, SStbJoinPost static int32_t handleSeqJoinCurrRetrieveEnd(SOperatorInfo* pOperator, SStbJoinDynCtrlInfo* pStbJoin) { SStbJoinPostJoinCtx* pPost = &pStbJoin->ctx.post; - + int32_t code = 0; + pPost->isStarted = false; if (pStbJoin->basic.batchFetch) { @@ -571,7 +572,11 @@ static int32_t handleSeqJoinCurrRetrieveEnd(SOperatorInfo* pOperator, SStbJoinDy if (pPost->leftNeedCache) { uint32_t* num = tSimpleHashGet(pStbJoin->ctx.prev.leftCache, &pPost->leftCurrUid, sizeof(pPost->leftCurrUid)); if (num && --(*num) <= 0) { - (void)tSimpleHashRemove(pStbJoin->ctx.prev.leftCache, &pPost->leftCurrUid, sizeof(pPost->leftCurrUid)); + code = tSimpleHashRemove(pStbJoin->ctx.prev.leftCache, &pPost->leftCurrUid, sizeof(pPost->leftCurrUid)); + if (code) { + qError("tSimpleHashRemove leftCurrUid %" PRId64 " from leftCache failed, error:%s", pPost->leftCurrUid, tstrerror(code)); + QRY_ERR_RET(code); + } QRY_ERR_RET(notifySeqJoinTableCacheEnd(pOperator, pPost, true)); } } @@ -579,7 +584,11 @@ static int32_t handleSeqJoinCurrRetrieveEnd(SOperatorInfo* pOperator, SStbJoinDy if (!pPost->rightNeedCache) { void* v = tSimpleHashGet(pStbJoin->ctx.prev.rightCache, &pPost->rightCurrUid, sizeof(pPost->rightCurrUid)); if (NULL != v) { - (void)tSimpleHashRemove(pStbJoin->ctx.prev.rightCache, &pPost->rightCurrUid, sizeof(pPost->rightCurrUid)); + code = tSimpleHashRemove(pStbJoin->ctx.prev.rightCache, &pPost->rightCurrUid, sizeof(pPost->rightCurrUid)); + if (code) { + qError("tSimpleHashRemove rightCurrUid %" PRId64 " from rightCache failed, error:%s", pPost->rightCurrUid, tstrerror(code)); + QRY_ERR_RET(code); + } QRY_ERR_RET(notifySeqJoinTableCacheEnd(pOperator, pPost, false)); } } @@ -660,7 +669,11 @@ static FORCE_INLINE int32_t addToJoinTableHash(SSHashObj* pHash, SSHashObj* pOnc break; default: if (1 == (*pNum)) { - (void)tSimpleHashRemove(pOnceHash, pKey, keySize); + code = tSimpleHashRemove(pOnceHash, pKey, keySize); + if (code) { + qError("tSimpleHashRemove failed in addToJoinTableHash, error:%s", tstrerror(code)); + QRY_ERR_RET(code); + } } (*pNum)++; break; @@ -811,8 +824,12 @@ static void postProcessStbJoinTableHash(SOperatorInfo* pOperator) { uint64_t* pUid = NULL; int32_t iter = 0; + int32_t code = 0; while (NULL != (pUid = tSimpleHashIterate(pStbJoin->ctx.prev.onceTable, pUid, &iter))) { - (void)tSimpleHashRemove(pStbJoin->ctx.prev.leftCache, pUid, sizeof(*pUid)); + code = tSimpleHashRemove(pStbJoin->ctx.prev.leftCache, pUid, sizeof(*pUid)); + if (code) { + qError("tSimpleHashRemove failed in postProcessStbJoinTableHash, error:%s", tstrerror(code)); + } } pStbJoin->execInfo.leftCacheNum = tSimpleHashGetSize(pStbJoin->ctx.prev.leftCache); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 1796aa7b64..2540579413 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -30,7 +30,9 @@ static void removeGroupCacheFile(SGroupCacheFileInfo* pFileInfo) { if (pFileInfo->fd.fd) { - (void)taosCloseFile(&pFileInfo->fd.fd); + if (taosCloseFile(&pFileInfo->fd.fd) < 0) { + qError("close group cache file failed, fd:%p, error:%s", pFileInfo->fd.fd, tstrerror(terrno)); + } pFileInfo->fd.fd = NULL; (void)taosThreadMutexDestroy(&pFileInfo->fd.mutex); } @@ -92,7 +94,9 @@ static void logGroupCacheExecInfo(SGroupCacheOperatorInfo* pGrpCacheOperator) { static void freeSGcSessionCtx(void* p) { SGcSessionCtx* pSession = p; if (pSession->semInit) { - (void)tsem_destroy(&pSession->waitSem); + if (tsem_destroy(&pSession->waitSem) < 0) { + qError("tsem_destroy session waitSem failed, error:%s", tstrerror(terrno)); + } } } @@ -262,6 +266,9 @@ static int32_t acquireFdFromFileCtx(SGcFileCacheCtx* pFileCtx, int32_t fileId, S } static FORCE_INLINE void releaseFdToFileCtx(SGroupCacheFileFd* pFd) { + if (NULL == pFd) { + return; + } (void)taosThreadMutexUnlock(&pFd->mutex); } @@ -274,6 +281,8 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC SGroupCacheData* pGroup = NULL; while (NULL != pHead) { + pFd = NULL; + if (pGCache->batchFetch) { pFileCtx = &pHead->pCtx->fileCtx; } else { @@ -290,7 +299,11 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC int64_t blkId = pHead->basic.blkId; pHead = pHead->next; - (void)taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + code = taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + if (code) { + qError("taosHashRemove blk %" PRId64 " from diryBlk failed, error:%s", blkId, tstrerror(code)); + goto _return; + } continue; } @@ -304,13 +317,19 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC } if (deleted) { + releaseFdToFileCtx(pFd); + qTrace("FileId:%d-%d-%d already be deleted, skip write", pCtx->id, pGroup ? pGroup->vgId : GROUP_CACHE_DEFAULT_VGID, pHead->basic.fileId); int64_t blkId = pHead->basic.blkId; pHead = pHead->next; - (void)taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + code = taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + if (code) { + qError("taosHashRemove blk %" PRId64 " from diryBlk failed, error:%s", blkId, tstrerror(code)); + goto _return; + } continue; } @@ -336,7 +355,11 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC int64_t blkId = pHead->basic.blkId; pHead = pHead->next; - (void)taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + code = taosHashRemove(pGCache->blkCache.pDirtyBlk, &blkId, sizeof(blkId)); + if (code) { + qError("taosHashRemove blk %" PRId64 " from diryBlk failed, error:%s", blkId, tstrerror(code)); + goto _return; + } } _return: @@ -1036,7 +1059,11 @@ static int32_t getCacheBlkFromDownstreamOperator(struct SOperatorInfo* pOperator } SGcSessionCtx* pWaitCtx = *ppWaitCtx; pWaitCtx->newFetch = true; - (void)taosHashRemove(pCtx->pWaitSessions, pSessionId, sizeof(*pSessionId)); + code = taosHashRemove(pCtx->pWaitSessions, pSessionId, sizeof(*pSessionId)); + if (code) { + qError("taosHashRemove session %" PRId64 " from waitSession failed, error: %s", pSessionId, tstrerror(code)); + return code; + } QRY_ERR_RET(tsem_post(&pWaitCtx->waitSem)); return code; @@ -1125,14 +1152,22 @@ static int32_t groupCacheSessionWait(struct SOperatorInfo* pOperator, SGcDownstr QRY_ERR_JRET(taosHashPut(pCtx->pWaitSessions, &sessionId, sizeof(sessionId), &pSession, POINTER_BYTES)); - (void)tsem_wait(&pSession->waitSem); + code = tsem_wait(&pSession->waitSem); + if (code) { + qError("tsem_wait failed, error:%s", tstrerror(code)); + QRY_ERR_JRET(code); + } if (pSession->newFetch) { pSession->newFetch = false; return getCacheBlkFromDownstreamOperator(pOperator, pCtx, sessionId, pSession, ppRes); } - (void)taosHashRemove(pCtx->pWaitSessions, &sessionId, sizeof(sessionId)); + code = taosHashRemove(pCtx->pWaitSessions, &sessionId, sizeof(sessionId)); + if (code) { + qError("taosHashRemove session %" PRId64 " from waitSession failed, error: %s", sessionId, tstrerror(code)); + QRY_ERR_JRET(code); + } bool got = false; return getBlkFromSessionCacheImpl(pOperator, sessionId, pSession, ppRes, &got); @@ -1278,14 +1313,22 @@ static int32_t getBlkFromGroupCache(struct SOperatorInfo* pOperator, SSDataBlock SSDataBlock** ppBlock = taosHashGet(pGCache->blkCache.pReadBlk, &pGcParam->sessionId, sizeof(pGcParam->sessionId)); if (ppBlock) { QRY_ERR_RET(releaseBaseBlockToList(pCtx, *ppBlock)); - (void)taosHashRemove(pGCache->blkCache.pReadBlk, &pGcParam->sessionId, sizeof(pGcParam->sessionId)); + code = taosHashRemove(pGCache->blkCache.pReadBlk, &pGcParam->sessionId, sizeof(pGcParam->sessionId)); + if (code) { + qError("taosHashRemove session %" PRId64 " from pReadBlk failed, error: %s", pGcParam->sessionId, tstrerror(code)); + QRY_ERR_RET(code); + } } } code = getBlkFromSessionCache(pOperator, pGcParam->sessionId, pSession, ppRes); if (NULL == *ppRes) { qDebug("session %" PRId64 " in downstream %d total got %" PRId64 " rows", pGcParam->sessionId, pCtx->id, pSession->resRows); - (void)taosHashRemove(pCtx->pSessions, &pGcParam->sessionId, sizeof(pGcParam->sessionId)); + code = taosHashRemove(pCtx->pSessions, &pGcParam->sessionId, sizeof(pGcParam->sessionId)); + if (code) { + qError("taosHashRemove session %" PRId64 " from pSessions failed, error: %s", pGcParam->sessionId, tstrerror(code)); + QRY_ERR_RET(code); + } } else { pSession->resRows += (*ppRes)->info.rows; qDebug("session %" PRId64 " in downstream %d got %" PRId64 " rows in one block", pGcParam->sessionId, pCtx->id, (*ppRes)->info.rows); diff --git a/source/libs/executor/src/mergejoin.c b/source/libs/executor/src/mergejoin.c index 302dd31788..61809b99e0 100755 --- a/source/libs/executor/src/mergejoin.c +++ b/source/libs/executor/src/mergejoin.c @@ -2413,7 +2413,10 @@ int32_t mAsofForwardChkFillGrpCache(SMJoinWindowCtx* pCtx) { pGrp->readIdx = 0; //pGrp->endIdx = pGrp->blk->info.rows - 1; } else { - (void)taosArrayPop(pCache->grps); + if (NULL == taosArrayPop(pCache->grps)) { + MJ_ERR_RET(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); + } + pGrp = taosArrayGet(pCache->grps, 0); if (NULL == pGrp) { MJ_ERR_RET(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); diff --git a/source/libs/executor/src/mergejoinoperator.c b/source/libs/executor/src/mergejoinoperator.c index 90c2248c12..d0354c12d5 100644 --- a/source/libs/executor/src/mergejoinoperator.c +++ b/source/libs/executor/src/mergejoinoperator.c @@ -1375,7 +1375,9 @@ int32_t mJoinBuildEqGroups(SMJoinTableCtx* pTable, int64_t timestamp, bool* whol _return: if (pTable->noKeepEqGrpRows || !keepGrp || (!pTable->multiEqGrpRows && !restart)) { - (void)taosArrayPop(pTable->eqGrps); + if (NULL == taosArrayPop(pTable->eqGrps)) { + code = terrno; + } } else { pTable->grpTotalRows += pGrp->endIdx - pGrp->beginIdx + 1; } diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 4b9067a191..aef348827a 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -581,7 +581,10 @@ void qwDestroyImpl(void *pMgmt) { int32_t schStatusCount = 0; qDebug("start to destroy qworker, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt); - (void)taosTmrStop(mgmt->hbTimer); //ignore error + if (taosTmrStop(mgmt->hbTimer)) { + qTrace("stop qworker hb timer may failed"); + } + mgmt->hbTimer = NULL; taosTmrCleanUp(mgmt->timer); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 1a9d3e7ba9..041347791e 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1187,7 +1187,9 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) { int32_t schNum = taosHashGetSize(mgmt->schHash); if (schNum <= 0) { QW_UNLOCK(QW_READ, &mgmt->schLock); - (void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error + if (taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer)) { + qError("reset qworker hb timer error, timer stoppped"); + } (void)qwRelease(refId); // ignore error return; } @@ -1199,7 +1201,9 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) { taosMemoryFree(rspList); taosArrayDestroy(pExpiredSch); QW_ELOG("calloc %d SQWHbInfo failed, code:%x", schNum, terrno); - (void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error + if (taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer)) { + qError("reset qworker hb timer error, timer stoppped"); + } (void)qwRelease(refId); // ignore error return; } @@ -1255,7 +1259,10 @@ _return: taosMemoryFreeClear(rspList); taosArrayDestroy(pExpiredSch); - (void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error + if (taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer)) { + qError("reset qworker hb timer error, timer stoppped"); + } + (void)qwRelease(refId); // ignore error } diff --git a/source/libs/scheduler/inc/schInt.h b/source/libs/scheduler/inc/schInt.h index 3a25f37895..a3be94d4c8 100644 --- a/source/libs/scheduler/inc/schInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -414,7 +414,9 @@ extern SSchedulerMgmt schMgmt; #define SCH_LOG_TASK_START_TS(_task) \ do { \ int64_t us = taosGetTimestampUs(); \ - (void)taosArrayPush((_task)->profile.execTime, &us); \ + if (NULL == taosArrayPush((_task)->profile.execTime, &us)) { \ + qError("taosArrayPush task execTime failed, error:%s", tstrerror(terrno)); \ + } \ if (0 == (_task)->execId) { \ (_task)->profile.startTs = us; \ } \ diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 8e2fbb878d..57a21643ef 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -512,6 +512,7 @@ int32_t schNotifyUserFetchRes(SSchJob *pJob) { } void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { + int32_t code = 0; SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock); if (SCH_OP_NULL == pJob->opStatus.op) { @@ -526,7 +527,10 @@ void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { if (SCH_JOB_IN_SYNC_OP(pJob)) { SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); - (void)tsem_post(&pJob->rspSem); // ignore error + code = tsem_post(&pJob->rspSem); + if (code) { + ctgError("tsem_post failed for syncOp, error:%s", tstrerror(code)); + } } else if (SCH_JOB_IN_ASYNC_EXEC_OP(pJob)) { SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); (void)schNotifyUserExecRes(pJob); // ignore error @@ -771,7 +775,10 @@ void schFreeJobImpl(void *job) { taosMemoryFreeClear(pJob->userRes.execRes); taosMemoryFreeClear(pJob->fetchRes); taosMemoryFreeClear(pJob->sql); - (void)tsem_destroy(&pJob->rspSem); // ignore error + int32_t code = tsem_destroy(&pJob->rspSem); + if (code) { + qError("tsem_destroy failed, error:%s", tstrerror(code)); + } taosMemoryFree(pJob); int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1); @@ -790,7 +797,12 @@ int32_t schJobFetchRows(SSchJob *pJob) { if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) { SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); - (void)tsem_wait(&pJob->rspSem); // ignore error + code = tsem_wait(&pJob->rspSem); + if (code) { + qError("tsem_wait for fetch rspSem failed, error:%s", tstrerror(code)); + SCH_RET(code); + } + SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); } } else { @@ -895,7 +907,10 @@ _return: } else if (pJob->refId < 0) { schFreeJobImpl(pJob); } else { - (void)taosRemoveRef(schMgmt.jobRef, pJob->refId); // ignore error + code = taosRemoveRef(schMgmt.jobRef, pJob->refId); + if (code) { + SCH_JOB_DLOG("taosRemoveRef job refId:0x%" PRIx64 " from jobRef, error:%s", pJob->refId, tstrerror(code)); + } } SCH_RET(code); @@ -909,7 +924,11 @@ int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq) { if (pReq->syncReq) { SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); - (void)tsem_wait(&pJob->rspSem); // ignore error + code = tsem_wait(&pJob->rspSem); + if (code) { + qError("qid:0x%" PRIx64 " tsem_wait sync rspSem failed, error:%s", pReq->pDag->queryId, tstrerror(code)); + SCH_ERR_RET(code); + } } SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId); diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index 59b8954a48..8e9d46de31 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -422,7 +422,9 @@ void schResetTaskForRetry(SSchJob *pJob, SSchTask *pTask) { schDropTaskOnExecNode(pJob, pTask); if (pTask->delayTimer) { - (void)taosTmrStopA(&pTask->delayTimer); // ignore error + if (!taosTmrStopA(&pTask->delayTimer)) { + SCH_TASK_WLOG("stop task delayTimer failed, may stopped, status:%d", pTask->status); + } } taosHashClear(pTask->execNodes); (void)schRemoveTaskFromExecList(pJob, pTask); // ignore error @@ -1319,7 +1321,9 @@ int32_t schDelayLaunchTask(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - (void)taosTmrReset(schHandleTimerEvent, pTask->delayExecMs, (void *)param, schMgmt.timer, &pTask->delayTimer); + if (taosTmrReset(schHandleTimerEvent, pTask->delayExecMs, (void *)param, schMgmt.timer, &pTask->delayTimer)) { + SCH_TASK_ELOG("taosTmrReset delayExec timer failed, handle:%p", schMgmt.timer); + } return TSDB_CODE_SUCCESS; } @@ -1350,7 +1354,9 @@ void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) { SCH_LOCK_TASK(pTask); if (pTask->delayTimer) { - (void)taosTmrStopA(&pTask->delayTimer); + if (!taosTmrStopA(&pTask->delayTimer)) { + SCH_TASK_WLOG("stop delayTimer failed, status:%d", pTask->delayTimer); + } } schDropTaskOnExecNode(pJob, pTask); SCH_UNLOCK_TASK(pTask); diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index 3f610ed387..612486c806 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -86,6 +86,7 @@ void schFreeHbTrans(SSchHbTrans *pTrans) { } void schCleanClusterHb(void *pTrans) { + int32_t code = 0; SCH_LOCK(SCH_WRITE, &schMgmt.hbLock); SSchHbTrans *hb = taosHashIterate(schMgmt.hbConnections, NULL); @@ -93,7 +94,10 @@ void schCleanClusterHb(void *pTrans) { if (hb->trans.pTrans == pTrans) { SQueryNodeEpId *pEpId = taosHashGetKey(hb, NULL); schFreeHbTrans(hb); - (void)taosHashRemove(schMgmt.hbConnections, pEpId, sizeof(SQueryNodeEpId)); + code = taosHashRemove(schMgmt.hbConnections, pEpId, sizeof(SQueryNodeEpId)); + if (code) { + qError("taosHashRemove hb connection failed, error:%s", tstrerror(code)); + } } hb = taosHashIterate(schMgmt.hbConnections, hb); @@ -116,7 +120,10 @@ int32_t schRemoveHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *ep int64_t taskNum = atomic_load_64(&hb->taskNum); if (taskNum <= 0) { schFreeHbTrans(hb); - (void)taosHashRemove(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId)); + code = taosHashRemove(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId)); + if (code) { + SCH_TASK_WLOG("taosHashRemove hb connection failed, error:%s", tstrerror(code)); + } } SCH_UNLOCK(SCH_WRITE, &schMgmt.hbLock); diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 3ce5cd5714..a62c59e547 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -184,6 +184,7 @@ void schedulerFreeJob(int64_t *jobId, int32_t errCode) { } void schedulerDestroy(void) { + int32_t code = 0; atomic_store_8((int8_t *)&schMgmt.exit, 1); if (schMgmt.jobRef >= 0) { @@ -195,7 +196,10 @@ void schedulerDestroy(void) { if (refId == 0) { break; } - (void)taosRemoveRef(schMgmt.jobRef, pJob->refId); // ignore error + code = taosRemoveRef(schMgmt.jobRef, pJob->refId); + if (code) { + qWarn("taosRemoveRef job refId:%" PRId64 " failed, error:%s", pJob->refId, tstrerror(code)); + } pJob = taosIterateRef(schMgmt.jobRef, refId); } diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 7780be3fb7..758e283bc3 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -488,10 +488,10 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) { if (pe->num == 0) { taosHashEntryWUnlock(pHashObj, pe); taosHashRUnlock(pHashObj); - return -1; + return TSDB_CODE_NOT_FOUND; } - int code = -1; + int code = TSDB_CODE_NOT_FOUND; SHashNode *pNode = pe->next; SHashNode *prevNode = NULL; diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 780a6c94f1..a802737461 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -229,9 +229,8 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { return code; } -int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { +void taosReadQitem(STaosQueue *queue, void **ppItem) { STaosQnode *pNode = NULL; - int32_t code = 0; (void)taosThreadMutexLock(&queue->mutex); @@ -247,14 +246,11 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { if (queue->qset) { (void)atomic_sub_fetch_32(&queue->qset->numOfItems, 1); } - code = 1; uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems, queue->memOfItems); } (void)taosThreadMutexUnlock(&queue->mutex); - - return code; } int32_t taosAllocateQall(STaosQall **qall) { diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 0eac7b4427..a1c161a42c 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -426,7 +426,7 @@ static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove) { } else { uTrace("rsetId:%d rid:%" PRId64 " is not there, failed to release/remove", rsetId, rid); terrno = TSDB_CODE_REF_NOT_EXIST; - code = -1; + code = terrno; } taosUnlockList(pSet->lockedBy + hash); diff --git a/source/util/src/tsimplehash.c b/source/util/src/tsimplehash.c index d14e72822f..b16fde86cf 100644 --- a/source/util/src/tsimplehash.c +++ b/source/util/src/tsimplehash.c @@ -297,7 +297,7 @@ void *tSimpleHashGet(SSHashObj *pHashObj, const void *key, size_t keyLen) { } int32_t tSimpleHashRemove(SSHashObj *pHashObj, const void *key, size_t keyLen) { - int32_t code = TSDB_CODE_FAILED; + int32_t code = TSDB_CODE_INVALID_PARA; if (!pHashObj || !key) { return code; } diff --git a/source/util/src/ttimer.c b/source/util/src/ttimer.c index 60edb2f045..d5310b2e7e 100644 --- a/source/util/src/ttimer.c +++ b/source/util/src/ttimer.c @@ -492,6 +492,9 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* han if (timer == NULL) { *pTmrId = taosTmrStart(fp, mseconds, param, handle); + if (NULL == *pTmrId) { + stopped = true; + } return stopped; } From fba5560f1bfb29e33bbdf43da8b8d22072eacf68 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 12 Sep 2024 14:24:11 +0800 Subject: [PATCH 76/90] fix(stmt2/close): wait asnyc cb completed to free itself --- source/client/src/clientStmt2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index e7e08c0982..e716e06005 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1667,7 +1667,6 @@ int stmtExec2(TAOS_STMT2* stmt, int* affected_rows) { STMT_ERR_RET(stmtCleanExecInfo(pStmt, (code ? false : true), false)); ++pStmt->sql.runTimes; - } else { SSqlCallbackWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper)); if (pWrapper == NULL) { @@ -1718,6 +1717,7 @@ int stmtClose2(TAOS_STMT2* stmt) { STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); if (pStmt->options.asyncExecFn) { + (void)tsem_wait(&pStmt->asyncQuerySem); (void)tsem_destroy(&pStmt->asyncQuerySem); } taosMemoryFree(stmt); From e0a275f1d41ee12853b502b3375f671c1b791d47 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 12 Sep 2024 14:49:35 +0800 Subject: [PATCH 77/90] fix(stream): do some internal refactor and rewrite the error code for encode. --- source/dnode/vnode/src/tqCommon/tqCommon.c | 13 ++++++++----- source/libs/stream/src/streamCheckStatus.c | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/tqCommon/tqCommon.c b/source/dnode/vnode/src/tqCommon/tqCommon.c index c00d9a93bb..c05e9f7b60 100644 --- a/source/dnode/vnode/src/tqCommon/tqCommon.c +++ b/source/dnode/vnode/src/tqCommon/tqCommon.c @@ -586,6 +586,10 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve bool isLeader, bool restored) { int32_t code = 0; int32_t vgId = pMeta->vgId; + int32_t numOfTasks = 0; + int32_t taskId = -1; + int64_t streamId = -1; + bool added = false; if (tsDisableStream) { tqInfo("vgId:%d stream disabled, not deploy stream tasks", vgId); @@ -613,13 +617,12 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve } // 2.save task, use the latest commit version as the initial start version of stream task. - int32_t taskId = pTask->id.taskId; - int64_t streamId = pTask->id.streamId; - bool added = false; + taskId = pTask->id.taskId; + streamId = pTask->id.streamId; streamMetaWLock(pMeta); code = streamMetaRegisterTask(pMeta, sversion, pTask, &added); - int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta); + numOfTasks = streamMetaGetNumOfTasks(pMeta); streamMetaWUnLock(pMeta); if (code < 0) { @@ -654,7 +657,7 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve tqDebug("vgId:%d not leader, not launch stream task s-task:0x%x", vgId, taskId); } } else { - tqWarn("vgId:%d failed to add s-task:0x%x, since already exists in meta store", vgId, taskId); + tqWarn("vgId:%d failed to add s-task:0x%x, since already exists in meta store, total:%d", vgId, taskId, numOfTasks); tFreeStreamTask(pTask); } diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index d0604e6d21..31d1bddd01 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -268,6 +268,7 @@ int32_t streamTaskSendCheckRsp(const SStreamMeta* pMeta, int32_t vgId, SStreamTa SRpcMsg rspMsg = {.code = 0, .pCont = buf, .contLen = sizeof(SMsgHead) + len, .info = *pRpcInfo}; tmsgSendRsp(&rspMsg); + code = (code >= 0)? 0:code; return code; } From 9ad2b9d96a21ba3c98da904e0c13c41b290b9fc9 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 12 Sep 2024 14:58:05 +0800 Subject: [PATCH 78/90] move sem to client main to wait for set tbname etc. --- source/client/src/clientMain.c | 13 +++++++++---- source/client/src/clientStmt2.c | 9 ++++----- tests/script/api/stmt2-nohole.c | 12 ++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 1c1fff9b7b..a28c17cb25 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1317,8 +1317,8 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d,QID:0x%" PRIx64, pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId); if (TSDB_CODE_SUCCESS != refreshMeta(pRequest->pTscObj, pRequest)) { - tscWarn("0x%" PRIx64 " refresh meta failed, code:%d - %s,QID:0x%" PRIx64, pRequest->self, code, - tstrerror(code), pRequest->requestId); + tscWarn("0x%" PRIx64 " refresh meta failed, code:%d - %s,QID:0x%" PRIx64, pRequest->self, code, tstrerror(code), + pRequest->requestId); } pRequest->prevCode = code; doAsyncQuery(pRequest, true); @@ -1369,7 +1369,7 @@ typedef struct SAsyncFetchParam { void *param; } SAsyncFetchParam; -static int32_t doAsyncFetch(void* pParam) { +static int32_t doAsyncFetch(void *pParam) { SAsyncFetchParam *param = pParam; taosAsyncFetchImpl(param->pReq, param->fp, param->param); taosMemoryFree(param); @@ -1393,7 +1393,7 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { return; } - SAsyncFetchParam* pParam = taosMemoryCalloc(1, sizeof(SAsyncFetchParam)); + SAsyncFetchParam *pParam = taosMemoryCalloc(1, sizeof(SAsyncFetchParam)); if (!pParam) { fp(param, res, terrno); return; @@ -1983,6 +1983,11 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col return terrno; } + STscStmt2 *pStmt = (STscStmt2 *)stmt; + if (pStmt->options.asyncExecFn) { + (void)tsem_wait(&pStmt->asyncQuerySem); + } + int32_t code = 0; for (int i = 0; i < bindv->count; ++i) { if (bindv->tbnames && bindv->tbnames[i]) { diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index e716e06005..51533fc56c 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1263,10 +1263,6 @@ int stmtBindBatch2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* bind, int32_t colIdx) { STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); - if (pStmt->options.asyncExecFn) { - (void)tsem_wait(&pStmt->asyncQuerySem); - } - if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { pStmt->bInfo.needParse = false; @@ -1703,6 +1699,10 @@ int stmtClose2(TAOS_STMT2* stmt) { pStmt->bindThreadInUse = false; } + if (pStmt->options.asyncExecFn) { + (void)tsem_wait(&pStmt->asyncQuerySem); + } + STMT_DLOG("stmt %p closed, stbInterlaceMode: %d, statInfo: ctgGetTbMetaNum=>%" PRId64 ", getCacheTbInfo=>%" PRId64 ", parseSqlNum=>%" PRId64 ", pStmt->stat.bindDataNum=>%" PRId64 ", settbnameAPI:%u, bindAPI:%u, addbatchAPI:%u, execAPI:%u" @@ -1717,7 +1717,6 @@ int stmtClose2(TAOS_STMT2* stmt) { STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); if (pStmt->options.asyncExecFn) { - (void)tsem_wait(&pStmt->asyncQuerySem); (void)tsem_destroy(&pStmt->asyncQuerySem); } taosMemoryFree(stmt); diff --git a/tests/script/api/stmt2-nohole.c b/tests/script/api/stmt2-nohole.c index b29dd3e826..5954f3660b 100644 --- a/tests/script/api/stmt2-nohole.c +++ b/tests/script/api/stmt2-nohole.c @@ -14,12 +14,12 @@ int64_t genReqid() { return count; } -sem_t sem; +// sem_t sem; void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) { int affected_rows = taos_affected_rows(pRes); printf("\033[31maffected rows:%d\033[0m\n", affected_rows); - (void)sem_post(&sem); + //(void)sem_post(&sem); return; /* SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)param; @@ -319,7 +319,7 @@ _bind_again: taos_stmt2_free_fields(stmt, fields); */ // if (taos_stmt_execute(stmt) != 0) { - (void)sem_init(&sem, 0, 0); + //(void)sem_init(&sem, 0, 0); start = clock(); // if (taos_stmt2_exec(stmt, NULL, stmtAsyncQueryCb, NULL) != 0) { if (taos_stmt2_exec(stmt, NULL) != 0) { @@ -330,9 +330,9 @@ _bind_again: end = clock(); printf("exec time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); - sem_wait(&sem); - (void)sem_destroy(&sem); - if (++run_time < 2) { + // sem_wait(&sem); + //(void)sem_destroy(&sem); + if (++run_time < 20) { goto _bind_again; } taos_stmt2_close(stmt); From e7cfe21e7213e0e10213b297ecbfd9b3b86e3918 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 12 Sep 2024 15:17:09 +0800 Subject: [PATCH 79/90] stmt2/async: new flag semWaited for the current batch --- source/client/inc/clientStmt2.h | 8 ++++---- source/client/src/clientMain.c | 3 ++- source/client/src/clientStmt2.c | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/client/inc/clientStmt2.h b/source/client/inc/clientStmt2.h index 74eb198930..4e9a09c082 100644 --- a/source/client/inc/clientStmt2.h +++ b/source/client/inc/clientStmt2.h @@ -150,10 +150,10 @@ typedef struct { SStmtExecInfo exec; SStmtBindInfo bInfo; - int64_t reqid; - int32_t errCode; - tsem_t asyncQuerySem; - + int64_t reqid; + int32_t errCode; + tsem_t asyncQuerySem; + bool semWaited; SStmtStatInfo stat; } STscStmt2; /* diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index a28c17cb25..7cfbeb1372 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1984,8 +1984,9 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col } STscStmt2 *pStmt = (STscStmt2 *)stmt; - if (pStmt->options.asyncExecFn) { + if (pStmt->options.asyncExecFn && !pStmt->semWaited) { (void)tsem_wait(&pStmt->asyncQuerySem); + pStmt->semWaited = true; } int32_t code = 0; diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index 51533fc56c..1739dced8f 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -819,6 +819,7 @@ TAOS_STMT2* stmtInit2(STscObj* taos, TAOS_STMT2_OPTION* pOptions) { if (pStmt->options.asyncExecFn) { (void)tsem_init(&pStmt->asyncQuerySem, 0, 1); } + pStmt->semWaited = false; STMT_LOG_SEQ(STMT_INIT); @@ -1678,6 +1679,7 @@ int stmtExec2(TAOS_STMT2* stmt, int* affected_rows) { pRequest->body.queryFp = asyncQueryCb; ((SSyncQueryParam*)(pRequest)->body.interParam)->userParam = pStmt; + pStmt->semWaited = false; launchAsyncQuery(pRequest, pStmt->sql.pQuery, NULL, pWrapper); } From aecab6e2caf2b4d71567bfaa66e6457918db5861 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 12 Sep 2024 15:27:11 +0800 Subject: [PATCH 80/90] stmt2/close: wait only when !semWaited (i.e. execed current batch) --- source/client/src/clientStmt2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index 1739dced8f..ae59319cec 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1701,7 +1701,7 @@ int stmtClose2(TAOS_STMT2* stmt) { pStmt->bindThreadInUse = false; } - if (pStmt->options.asyncExecFn) { + if (pStmt->options.asyncExecFn && !pStmt->semWaited) { (void)tsem_wait(&pStmt->asyncQuerySem); } From aa80aa39bcfa818cd70302e5716c7ad2bc053638 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Thu, 12 Sep 2024 15:34:57 +0800 Subject: [PATCH 81/90] fix(query):use window start key when ts column is null --- include/libs/function/functionMgt.h | 1 + source/libs/executor/src/timewindowoperator.c | 10 ++++++++-- source/libs/function/src/functionMgt.c | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 233e201ac3..519207377b 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -280,6 +280,7 @@ bool fmIsSkipScanCheckFunc(int32_t funcId); bool fmIsPrimaryKeyFunc(int32_t funcId); bool fmIsProcessByRowFunc(int32_t funcId); bool fmisSelectGroupConstValueFunc(int32_t funcId); +bool fmIsElapsedFunc(int32_t funcId); void getLastCacheDataType(SDataType* pType, int32_t pkBytes); int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** pFunc); diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 640ce5c98b..0cd506d15a 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -293,7 +293,9 @@ void doTimeWindowInterpolation(SArray* pPrevValues, SArray* pDataBlock, TSKEY pr SPoint point2 = (SPoint){.key = curTs, .val = &v2}; SPoint point = (SPoint){.key = windowKey, .val = &v}; - taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); + if (!fmIsElapsedFunc(pCtx[k].functionId)) { + taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); + } if (type == RESULT_ROW_START_INTERP) { pCtx[k].start.key = point.key; @@ -639,7 +641,11 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num int64_t prevTs = *(int64_t*)pTsKey->pData; if (groupId == pBlock->info.id.groupId) { - doTimeWindowInterpolation(pInfo->pPrevValues, pBlock->pDataBlock, prevTs, -1, tsCols[startPos], startPos, w.ekey, + TSKEY curTs = pBlock->info.window.skey; + if (tsCols != NULL) { + curTs = tsCols[startPos]; + } + doTimeWindowInterpolation(pInfo->pPrevValues, pBlock->pDataBlock, prevTs, -1, curTs, startPos, w.ekey, RESULT_ROW_END_INTERP, pSup); } diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 1a927a1576..886772b36c 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -276,6 +276,13 @@ bool fmisSelectGroupConstValueFunc(int32_t funcId) { return FUNCTION_TYPE_GROUP_CONST_VALUE == funcMgtBuiltins[funcId].type; } +bool fmIsElapsedFunc(int32_t funcId) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNCTION_TYPE_ELAPSED == funcMgtBuiltins[funcId].type; +} + bool fmIsBlockDistFunc(int32_t funcId) { if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { return false; From 726b13372192d298a61791dadbaf9d1e2877919d Mon Sep 17 00:00:00 2001 From: lyh250-666 Date: Thu, 12 Sep 2024 07:46:30 +0000 Subject: [PATCH 82/90] modify error code passing --- source/dnode/mnode/impl/src/mndArbGroup.c | 2 +- source/dnode/mnode/impl/src/mndConsumer.c | 12 +-- source/dnode/mnode/impl/src/mndDb.c | 4 +- source/dnode/mnode/impl/src/mndDef.c | 18 ++--- source/dnode/mnode/impl/src/mndDnode.c | 30 +++---- source/dnode/mnode/impl/src/mndFunc.c | 16 ++-- source/dnode/mnode/impl/src/mndInfoSchema.c | 2 +- source/dnode/mnode/impl/src/mndMain.c | 2 +- source/dnode/mnode/impl/src/mndPerfSchema.c | 4 +- source/dnode/mnode/impl/src/mndPrivilege.c | 2 +- source/dnode/mnode/impl/src/mndProfile.c | 10 +-- source/dnode/mnode/impl/src/mndQnode.c | 8 +- source/dnode/mnode/impl/src/mndQuery.c | 4 +- source/dnode/mnode/impl/src/mndScheduler.c | 4 +- source/dnode/mnode/impl/src/mndShow.c | 2 +- source/dnode/mnode/impl/src/mndSma.c | 32 ++++---- source/dnode/mnode/impl/src/mndSnode.c | 6 +- source/dnode/mnode/impl/src/mndStb.c | 32 ++++---- source/dnode/mnode/impl/src/mndStream.c | 6 +- source/dnode/mnode/impl/src/mndStreamHb.c | 2 +- source/dnode/mnode/impl/src/mndSubscribe.c | 4 +- source/dnode/mnode/impl/src/mndSync.c | 4 +- source/dnode/mnode/impl/src/mndTrans.c | 2 +- source/dnode/mnode/impl/src/mndUser.c | 88 ++++++++++----------- source/dnode/mnode/impl/src/mndVgroup.c | 6 +- source/dnode/mnode/sdb/src/sdb.c | 2 +- source/dnode/mnode/sdb/src/sdbFile.c | 8 +- source/dnode/mnode/sdb/src/sdbHash.c | 1 - 28 files changed, 156 insertions(+), 157 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndArbGroup.c b/source/dnode/mnode/impl/src/mndArbGroup.c index 3860f10f8f..1c9dc4c77c 100644 --- a/source/dnode/mnode/impl/src/mndArbGroup.c +++ b/source/dnode/mnode/impl/src/mndArbGroup.c @@ -678,7 +678,7 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) { mndArbGroupSetAssignedLeader(&newGroup, candidateIndex); if (taosArrayPush(pUpdateArray, &newGroup) == NULL) { taosArrayDestroy(pUpdateArray); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } sdbRelease(pSdb, pArbGroup); diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 606b93035f..f71ab95d03 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -216,7 +216,7 @@ static int32_t buildMqHbRsp(SRpcMsg *pMsg, SMqHbRsp *rsp){ } void *buf = rpcMallocCont(tlen); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if(tSerializeSMqHbRsp(buf, tlen, rsp) <= 0){ @@ -261,7 +261,7 @@ static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t e rsp->topics = taosArrayInit(numOfTopics, sizeof(SMqSubTopicEp)); if (rsp->topics == NULL) { taosRUnLockLatch(&pConsumer->lock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // handle all topics subscribed by this consumer @@ -318,7 +318,7 @@ static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t e taosRUnLockLatch(&pConsumer->lock); taosRUnLockLatch(&pSub->lock); mndReleaseSubscribe(pMnode, pSub); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t j = 0; j < vgNum; j++) { @@ -339,7 +339,7 @@ static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t e taosRUnLockLatch(&pConsumer->lock); taosRUnLockLatch(&pSub->lock); mndReleaseSubscribe(pMnode, pSub); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } if (taosArrayPush(rsp->topics, &topicEp) == NULL) { @@ -347,7 +347,7 @@ static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t e taosRUnLockLatch(&pConsumer->lock); taosRUnLockLatch(&pSub->lock); mndReleaseSubscribe(pMnode, pSub); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosRUnLockLatch(&pSub->lock); mndReleaseSubscribe(pMnode, pSub); @@ -362,7 +362,7 @@ static int32_t buildAskEpRsp(SRpcMsg *pMsg, SMqAskEpRsp *rsp, int32_t serverEpoc int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqAskEpRsp(NULL, rsp); void *buf = rpcMallocCont(tlen); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SMqRspHead *pHead = buf; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 6467dfcf11..efa98e3b40 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1558,7 +1558,7 @@ static int32_t mndBuildDropDbRsp(SDbObj *pDb, int32_t *pRspLen, void **ppRsp, bo } if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -1729,7 +1729,7 @@ int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUs int32_t code = 0; pRsp->pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); if (pRsp->pVgroupInfos == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index d93b275e48..61606b0364 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -137,7 +137,7 @@ int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) { if (sz != 0) { pObj->tasks = taosArrayInit(sz, sizeof(void *)); if (pObj->tasks == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -161,14 +161,14 @@ int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) { if (taosArrayPush(pArray, &pTask) == NULL) { taosMemoryFree(pTask); taosArrayDestroy(pArray); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } } } if (taosArrayPush(pObj->tasks, &pArray) == NULL) { taosArrayDestroy(pArray); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } } @@ -297,24 +297,24 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, if (updateType == CONSUMER_ADD_REB){ pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *)); if(pConsumer->rebNewTopics == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } char* topicTmp = taosStrdup(topic); if (taosArrayPush(pConsumer->rebNewTopics, &topicTmp) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } }else if (updateType == CONSUMER_REMOVE_REB) { pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *)); if(pConsumer->rebRemovedTopics == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } char* topicTmp = taosStrdup(topic); if (taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } }else if (updateType == CONSUMER_INSERT_SUB){ @@ -330,7 +330,7 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup); if (pConsumer->rebNewTopics == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } pConsumer->assignedTopics = subscribe->topicNames; @@ -612,7 +612,7 @@ int32_t tCloneSubscribeObj(const SMqSubscribeObj *pSub, SMqSubscribeObj **ppSub) int32_t code = 0; SMqSubscribeObj *pSubNew = taosMemoryMalloc(sizeof(SMqSubscribeObj)); if (pSubNew == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } (void)memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 71952b3bb8..a432df60a5 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -461,7 +461,7 @@ int32_t mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) { } if(taosArrayPush(pDnodeInfo, &dInfo) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; sdbCancelFetch(pSdb, pIter); break; } @@ -618,7 +618,7 @@ static int32_t mndUpdateDnodeObj(SMnode *pMnode, SDnodeObj *pDnode) { } pReq = rpcMallocCont(contLen); if (pReq == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } (void)tSerializeSDnodeInfoReq(pReq, contLen, &infoReq); @@ -980,7 +980,7 @@ static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { rsp.dnodeList = taosArrayInit(5, sizeof(SEpSet)); if (NULL == rsp.dnodeList) { mError("failed to alloc epSet while process dnode list req"); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1006,7 +1006,7 @@ static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1064,7 +1064,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { rsp.variables = taosArrayInit(16, sizeof(SVariablesInfo)); if (NULL == rsp.variables) { mError("failed to alloc SVariablesInfo array while process show variables req"); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1074,7 +1074,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1082,7 +1082,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr); (void)strcpy(info.scope, "both"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1090,7 +1090,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsLocale); (void)strcpy(info.scope, "both"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1098,7 +1098,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsCharset); (void)strcpy(info.scope, "both"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1106,7 +1106,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsEnableMonitor); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1114,7 +1114,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsMonitorInterval); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1122,7 +1122,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogThreshold); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1130,7 +1130,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogMaxLen); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1140,14 +1140,14 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", scopeStr); (void)strcpy(info.scope, "server"); if (taosArrayPush(rsp.variables, &info) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 326f2ffa95..9a617fb894 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -265,7 +265,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SRpcMsg *pReq, SCreateFuncReq *pCre func.codeSize = pCreate->codeLen; func.pCode = taosMemoryMalloc(func.codeSize); if (func.pCode == NULL || func.pCode == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -528,13 +528,13 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { retrieveRsp.numOfFuncs = retrieveReq.numOfFuncs; retrieveRsp.pFuncInfos = taosArrayInit(retrieveReq.numOfFuncs, sizeof(SFuncInfo)); if (retrieveRsp.pFuncInfos == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto RETRIEVE_FUNC_OVER; } retrieveRsp.pFuncExtraInfos = taosArrayInit(retrieveReq.numOfFuncs, sizeof(SFuncExtraInfo)); if (retrieveRsp.pFuncExtraInfos == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto RETRIEVE_FUNC_OVER; } @@ -563,28 +563,28 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { funcInfo.codeSize = pFunc->codeSize; funcInfo.pCode = taosMemoryCalloc(1, funcInfo.codeSize); if (funcInfo.pCode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + terrno = terrno; goto RETRIEVE_FUNC_OVER; } (void)memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize); if (funcInfo.commentSize > 0) { funcInfo.pComment = taosMemoryCalloc(1, funcInfo.commentSize); if (funcInfo.pComment == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + terrno = terrno; goto RETRIEVE_FUNC_OVER; } (void)memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize); } } if (taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + terrno = terrno; goto RETRIEVE_FUNC_OVER; } SFuncExtraInfo extraInfo = {0}; extraInfo.funcVersion = pFunc->funcVersion; extraInfo.funcCreatedTime = pFunc->createdTime; if (taosArrayPush(retrieveRsp.pFuncExtraInfos, &extraInfo) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + terrno = terrno; goto RETRIEVE_FUNC_OVER; } @@ -594,7 +594,7 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { int32_t contLen = tSerializeSRetrieveFuncRsp(NULL, 0, &retrieveRsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto RETRIEVE_FUNC_OVER; } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index eb7cb7d505..f72f17684e 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -60,7 +60,7 @@ static int32_t mndInsInitMeta(SHashObj *hash) { TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas)); if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index aa03fbf2d9..a0dd30f11a 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -559,7 +559,7 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle step.initFp = initFp; step.cleanupFp = cleanupFp; if (taosArrayPush(pMnode->pSteps, &step) == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_RETURN(0); diff --git a/source/dnode/mnode/impl/src/mndPerfSchema.c b/source/dnode/mnode/impl/src/mndPerfSchema.c index da5e201c05..f36ddf7493 100644 --- a/source/dnode/mnode/impl/src/mndPerfSchema.c +++ b/source/dnode/mnode/impl/src/mndPerfSchema.c @@ -58,7 +58,7 @@ int32_t mndPerfsInitMeta(SHashObj *hash) { TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas)); if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } } @@ -129,7 +129,7 @@ int32_t mndInitPerfs(SMnode *pMnode) { int32_t code = 0; pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (pMnode->perfsMeta == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index ce082ad45d..a13fe5d69f 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -36,7 +36,7 @@ int32_t mndSetUserWhiteListRsp(SMnode *pMnode, SUserObj *pUser, SGetUserWhiteLis pWhiteListRsp->numWhiteLists = 1; pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); if (pWhiteListRsp->pWhiteLists == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memset(pWhiteListRsp->pWhiteLists, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 3bdfa236d1..04c474dd56 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -318,7 +318,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { } void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER); + TAOS_CHECK_GOTO(terrno, NULL, _OVER); } contLen = tSerializeSConnectRsp(pRsp, contLen, &connectRsp); @@ -555,7 +555,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb hbRsp.info = taosArrayInit(kvNum, sizeof(SKv)); if (NULL == hbRsp.info) { mError("taosArrayInit %d rsp kv failed", kvNum); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tFreeClientHbRsp(&hbRsp); TAOS_RETURN(code); } @@ -699,7 +699,7 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { batchRsp.svrTimestamp = taosGetTimestampSec(); batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp)); if (batchRsp.rsps == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } batchRsp.monitorParas.tsEnableMonitor = tsEnableMonitor; batchRsp.monitorParas.tsMonitorInterval = tsMonitorInterval; @@ -732,7 +732,7 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { } void *buf = rpcMallocCont(tlen); if (!buf) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } tlen = tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp); if (tlen < 0) { @@ -820,7 +820,7 @@ static int32_t mndProcessSvrVerReq(SRpcMsg *pReq) { } void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } contLen = tSerializeSServerVerRsp(pRsp, contLen, &rsp); if (contLen < 0) { diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 54052590a1..41d292a62f 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -249,7 +249,7 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); @@ -380,7 +380,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); @@ -483,7 +483,7 @@ int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) { SArray *qnodeList = taosArrayInit(5, sizeof(SQueryNodeLoad)); if (NULL == qnodeList) { mError("failed to alloc epSet while process qnode list req"); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -532,7 +532,7 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) { int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp); void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index c743aafd13..4816df6323 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -103,7 +103,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg)); if (NULL == batchRsp.pRsps) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -147,7 +147,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { } pRsp = rpcMallocCont(rspSize); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) { diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 93cd351543..4f72b26a5e 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -846,13 +846,13 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); if (pVgEp == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup); pVgEp->vgId = pVgroup->vgId; if (taosArrayPush(pSub->unassignedVgs, &pVgEp) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(pVgEp); goto END; } diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index b8d44da8c4..55687c00ba 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -243,7 +243,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pShow = mndCreateShowObj(pMnode, &retrieveReq); if (pShow == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; mError("failed to process show-meta req since %s", tstrerror(code)); TAOS_RETURN(code); } diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 284d65cd9c..f7948764dd 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -1279,7 +1279,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool info.expr = taosMemoryMalloc(pSma->exprLen + 1); if (info.expr == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); return code; @@ -1289,7 +1289,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool info.expr[pSma->exprLen] = 0; if (NULL == taosArrayPush(rsp->pIndex, &info)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(info.expr); sdbRelease(pSdb, pSma); sdbCancelFetch(pSdb, pIter); @@ -1326,7 +1326,7 @@ static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { int32_t contLen = tSerializeSUserIndexRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1361,7 +1361,7 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { rsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo)); if (NULL == rsp.pIndex) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1376,7 +1376,7 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -1699,7 +1699,7 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { STrans *pTrans = mndTransCreate(pCxt->pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pCxt->pRpcReq, "create-tsma"); if (!pTrans) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } mndTransSetDbName(pTrans, pCxt->pDb->name, NULL); @@ -1797,14 +1797,14 @@ static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) { if (pCxt->pCreateSmaReq->pVgroupVerList) { pCxt->pCreateStreamReq->pVgroupVerList = taosArrayDup(pCxt->pCreateSmaReq->pVgroupVerList, NULL); if (!pCxt->pCreateStreamReq->pVgroupVerList) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } } if (LIST_LENGTH(pProjects) > 0) { createStreamReq.pCols = taosArrayInit(LIST_LENGTH(pProjects), sizeof(SField)); if (!createStreamReq.pCols) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } } @@ -1978,7 +1978,7 @@ static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { STransAction dropStreamRedoAction = {0}; STrans *pTrans = mndTransCreate(pCxt->pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pCxt->pRpcReq, "drop-tsma"); if (!pTrans) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } SMDropStreamReq dropStreamReq = {0}; @@ -2337,7 +2337,7 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa funcInfo.funcId = pFuncNode->funcId; funcInfo.colId = ((SColumnNode *)pFuncNode->pParameterList->pHead->pNode)->colId; if (!taosArrayPush(pInfo->pFuncs, &funcInfo)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosArrayDestroy(pInfo->pFuncs); nodesDestroyNode(pNode); return code; @@ -2351,7 +2351,7 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa if (code == TSDB_CODE_SUCCESS && pDestStb->numOfTags > 0) { pInfo->pTags = taosArrayInit(pDestStb->numOfTags, sizeof(SSchema)); if (!pInfo->pTags) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { for (int32_t i = 0; i < pDestStb->numOfTags; ++i) { if (NULL == taosArrayPush(pInfo->pTags, &pDestStb->pTags[i])) { @@ -2364,7 +2364,7 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa if (code == TSDB_CODE_SUCCESS) { pInfo->pUsedCols = taosArrayInit(pDestStb->numOfColumns - 3, sizeof(SSchema)); if (!pInfo->pUsedCols) - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; else { // skip _wstart, _wend, _duration for (int32_t i = 1; i < pDestStb->numOfColumns - 2; ++i) { @@ -2438,7 +2438,7 @@ static int32_t mndGetTSMA(SMnode *pMnode, char *tsmaFName, STableTSMAInfoRsp *rs TAOS_RETURN(code); } if (NULL == taosArrayPush(rsp->pTsmas, &pTsma)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tFreeAndClearTableTSMAInfo(pTsma); } *exist = true; @@ -2524,7 +2524,7 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt TAOS_RETURN(code); } if (NULL == taosArrayPush(pRsp->pTsmas, &pTsma)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tFreeAndClearTableTSMAInfo(pTsma); sdbCancelFetch(pSdb, pIter); TAOS_RETURN(code); @@ -2566,7 +2566,7 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { rsp.pTsmas = taosArrayInit(4, POINTER_BYTES); if (NULL == rsp.pTsmas) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -2588,7 +2588,7 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { int32_t contLen = tSerializeTableTSMAInfoRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index c5e38ed048..4616f50a79 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -220,7 +220,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); @@ -248,7 +248,7 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); @@ -380,7 +380,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 03ff6d425f..d46726fd31 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -2964,7 +2964,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -3015,7 +3015,7 @@ static int32_t mndProcessTableCfgReq(SRpcMsg *pReq) { void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -3041,14 +3041,14 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t SSTbHbRsp hbRsp = {0}; hbRsp.pMetaRsp = taosArrayInit(numOfStbs, sizeof(STableMetaRsp)); if (hbRsp.pMetaRsp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } hbRsp.pIndexRsp = taosArrayInit(numOfStbs, sizeof(STableIndexRsp)); if (NULL == hbRsp.pIndexRsp) { taosArrayDestroy(hbRsp.pMetaRsp); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -3104,7 +3104,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t STableIndexRsp indexRsp = {0}; indexRsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo)); if (NULL == indexRsp.pIndex) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -3136,7 +3136,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t void *pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { tFreeSSTbHbRsp(&hbRsp); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_RETURN(code); } @@ -4066,20 +4066,20 @@ static int32_t mndInitDropTbsWithTsmaCtx(SMndDropTbsWithTsmaCtx **ppCtx) { if (!pCtx) return terrno; pCtx->pTsmaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); if (!pCtx->pTsmaMap) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } pCtx->pDbMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (!pCtx->pDbMap) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } pCtx->pResTbNames = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); pCtx->pVgMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (!pCtx->pVgMap) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } *ppCtx = pCtx; @@ -4203,17 +4203,17 @@ static int32_t mndDropTbAdd(SMnode *pMnode, SHashObj *pVgHashMap, const SVgroupI reqs.info = *pVgInfo; reqs.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq)); if (reqs.req.pArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(reqs.req.pArray, &req) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosHashPut(pVgHashMap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &reqs, sizeof(reqs)) != 0) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } else { if (taosArrayPush(pReqs->req.pArray, &req) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return 0; @@ -4229,7 +4229,7 @@ static int32_t mndGetDbVgInfoForTsma(SMnode *pMnode, const char *dbname, SMDropT pInfo->dbInfo.dbVgInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); if (!pInfo->dbInfo.dbVgInfos) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } mndBuildDBVgroupInfo(pDb, pMnode, pInfo->dbInfo.dbVgInfos); @@ -4284,11 +4284,11 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith SMDropTbTsmaInfos infos = {0}; infos.pTsmaInfos = taosArrayInit(2, sizeof(SMDropTbTsmaInfo)); if (!infos.pTsmaInfos) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } if (taosHashPut(pCtx->pTsmaMap, &pTb->suid, sizeof(pTb->suid), &infos, sizeof(infos)) != 0) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 0c57f8466d..cbe631912c 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -1993,7 +1993,7 @@ static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeLis if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { mndDestroyVgroupChangeInfo(pInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); @@ -2164,7 +2164,7 @@ static int32_t refreshNodeListFromExistedStreams(SMnode *pMnode, SArray *pNodeLi SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (pHash == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } while (1) { @@ -2215,7 +2215,7 @@ static int32_t refreshNodeListFromExistedStreams(SMnode *pMnode, SArray *pNodeLi if (p == NULL) { mError("failed to put entry into node list, nodeId:%d, code: out of memory", pEntry->nodeId); if (code == 0) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } continue; } diff --git a/source/dnode/mnode/impl/src/mndStreamHb.c b/source/dnode/mnode/impl/src/mndStreamHb.c index d31d0dad65..43f9d8d055 100644 --- a/source/dnode/mnode/impl/src/mndStreamHb.c +++ b/source/dnode/mnode/impl/src/mndStreamHb.c @@ -349,7 +349,7 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { if (pFailedChkpt == NULL || pOrphanTasks == NULL) { taosArrayDestroy(pFailedChkpt); taosArrayDestroy(pOrphanTasks); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } streamMutexLock(&execInfo.lock); diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index e3bef61bc0..1c6474d787 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -201,7 +201,7 @@ static int32_t mndGetOrCreateRebSub(SHashObj *pHash, const char *key, SMqRebInfo if (pRebInfo == NULL) { pRebInfo = tNewSMqRebSubscribe(key); if (pRebInfo == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } code = taosHashPut(pHash, key, strlen(key) + 1, pRebInfo, sizeof(SMqRebInfo)); @@ -412,7 +412,7 @@ static int32_t processSubOffsetRows(SMnode *pMnode, const SMqRebInputObj *pInput pOutput->pSub->offsetRows = taosArrayInit(4, sizeof(OffsetRows)); if(pOutput->pSub->offsetRows == NULL) { taosRUnLockLatch(&pSub->lock); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index d669994128..66c0fec273 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -546,10 +546,10 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; SRpcMsg req = {.msgType = TDMT_MND_APPLY_MSG, .contLen = sdbGetRawTotalSize(pRaw)}; - if (req.contLen <= 0) return TSDB_CODE_OUT_OF_MEMORY; + if (req.contLen <= 0) return terrno; req.pCont = rpcMallocCont(req.contLen); - if (req.pCont == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (req.pCont == NULL) return terrno; memcpy(req.pCont, pRaw, req.contLen); (void)taosThreadMutexLock(&pMgmt->lock); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 43f8ffe61b..cc880aa4de 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -674,7 +674,7 @@ static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) { void *ptr = taosArrayPush(pArray, pAction); if (ptr == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } return 0; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 2d979c3327..41ddc2ab32 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -139,7 +139,7 @@ const static SIpV4Range defaultIpRange = {.ip = 16777343, .mask = 32}; static int32_t ipWhiteMgtInit() { ipWhiteMgt.pIpWhiteTab = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 1, HASH_ENTRY_LOCK); if (ipWhiteMgt.pIpWhiteTab == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } ipWhiteMgt.ver = 0; (void)taosThreadRwlockInit(&ipWhiteMgt.rw, NULL); @@ -558,11 +558,11 @@ int32_t mndFetchAllIpWhite(SMnode *pMnode, SHashObj **ppIpWhiteTab) { pIpWhiteTab = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 1, HASH_ENTRY_LOCK); if (pIpWhiteTab == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } pUserNames = taosArrayInit(8, sizeof(void *)); if (pUserNames == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } while (1) { @@ -593,7 +593,7 @@ int32_t mndFetchAllIpWhite(SMnode *pMnode, SHashObj **ppIpWhiteTab) { taosMemoryFree(name); sdbRelease(pSdb, pUser); sdbCancelFetch(pSdb, pIter); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } sdbRelease(pSdb, pUser); @@ -614,7 +614,7 @@ int32_t mndFetchAllIpWhite(SMnode *pMnode, SHashObj **ppIpWhiteTab) { } if (taosArrayPush(pUserNames, &name) == NULL) { taosMemoryFree(name); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } } @@ -1011,7 +1011,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) { pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size); if (pRaw == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } int32_t dataPos = 0; @@ -1155,7 +1155,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) { int32_t num = pUser->pIpWhiteList->num; int32_t tlen = sizeof(SIpWhiteList) + num * sizeof(SIpV4Range) + 4; if ((buf = taosMemoryCalloc(1, tlen)) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER); + TAOS_CHECK_GOTO(terrno, NULL, _OVER); } int32_t len = 0; TAOS_CHECK_GOTO(tSerializeIpWhiteList(buf, tlen, pUser->pIpWhiteList, &len), &lino, _OVER); @@ -1201,12 +1201,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { pRow = sdbAllocRow(sizeof(SUserObj)); if (pRow == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } pUser = sdbGetRowObj(pRow); if (pUser == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } int32_t dataPos = 0; @@ -1239,7 +1239,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); pUser->topics = taosHashInit(numOfTopics, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->readDbs == NULL || pUser->writeDbs == NULL || pUser->topics == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); goto _OVER; } @@ -1302,7 +1302,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { if (pUser->readTbs == NULL || pUser->writeTbs == NULL || pUser->alterTbs == NULL || pUser->readViews == NULL || pUser->writeViews == NULL || pUser->alterViews == NULL || pUser->useDbs == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); goto _OVER; } @@ -1312,7 +1312,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1321,7 +1321,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1335,7 +1335,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1344,7 +1344,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1359,7 +1359,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1368,7 +1368,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1382,7 +1382,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1391,7 +1391,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1405,7 +1405,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1414,7 +1414,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1428,7 +1428,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1437,7 +1437,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER); TAOS_MEMORY_REALLOC(value, valuelen * sizeof(char)); if (value == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(value, 0, valuelen); SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER) @@ -1452,7 +1452,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, keyLen * sizeof(char)); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } (void)memset(key, 0, keyLen); SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER); @@ -1470,7 +1470,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { TAOS_MEMORY_REALLOC(key, len); if (key == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } SDB_GET_BINARY(pRaw, dataPos, key, len, _OVER); @@ -1535,7 +1535,7 @@ int32_t mndDupTableHash(SHashObj *pOld, SHashObj **ppNew) { *ppNew = taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (*ppNew == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } char *tb = taosHashIterate(pOld, NULL); @@ -1560,7 +1560,7 @@ int32_t mndDupUseDbHash(SHashObj *pOld, SHashObj **ppNew) { *ppNew = taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (*ppNew == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } int32_t *db = taosHashIterate(pOld, NULL); @@ -1661,7 +1661,7 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) { TAOS_MEMORY_REALLOC(pOld->pIpWhiteList, sz); if (pOld->pIpWhiteList == NULL) { taosWUnLockLatch(&pOld->lock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(pOld->pIpWhiteList, pNew->pIpWhiteList, sz); pOld->ipWhiteListVer = pNew->ipWhiteListVer; @@ -1715,7 +1715,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate } else { SHashObj *pUniqueTab = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); if (pUniqueTab == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } int32_t dummpy = 0; for (int i = 0; i < pCreate->numIpRanges; i++) { @@ -1764,7 +1764,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate if (pTrans == NULL) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); taosMemoryFree(userObj.pIpWhiteList); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } mInfo("trans:%d, used to create user:%s", pTrans->id, pCreate->user); @@ -1905,7 +1905,7 @@ int32_t mndProcessGetUserWhiteListReq(SRpcMsg *pReq) { } pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } contLen = tSerializeSGetUserWhiteListRsp(pRsp, contLen, &wlRsp); @@ -1952,7 +1952,7 @@ int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) { pRsp = rpcMallocCont(len); if (!pRsp) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } len = tSerializeSUpdateIpWhite(pRsp, len, &ipWhite); if (len < 0) { @@ -2579,7 +2579,7 @@ static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) { } pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } contLen = tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp); @@ -2655,7 +2655,7 @@ static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl TAOS_MEMORY_REALLOC(varstr, VARSTR_HEADER_SIZE + tlen); if (varstr == NULL) { sdbRelease(pSdb, pUser); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } varDataSetLen(varstr, tlen); (void)memcpy(varDataVal(varstr), buf, tlen); @@ -2820,12 +2820,12 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i if (bufSz < 5) bufSz = 5; TAOS_MEMORY_REALLOC(*sql, bufSz + 1); if (*sql == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } TAOS_MEMORY_REALLOC(*condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if ((*condition) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -2852,7 +2852,7 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i } else { TAOS_MEMORY_REALLOC(*condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if ((*condition) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } STR_WITH_MAXSIZE_TO_VARSTR((*condition), "", pShow->pMeta->pSchemas[cols].bytes); @@ -2952,7 +2952,7 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock TAOS_MEMORY_REALLOC(condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if (condition == NULL) { sdbRelease(pSdb, pUser); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -2995,7 +2995,7 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock TAOS_MEMORY_REALLOC(condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if (condition == NULL) { sdbRelease(pSdb, pUser); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -3039,7 +3039,7 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock TAOS_MEMORY_REALLOC(condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if (condition == NULL) { sdbRelease(pSdb, pUser); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -3093,7 +3093,7 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock TAOS_MEMORY_REALLOC(condition, TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE); if (condition == NULL) { sdbRelease(pSdb, pUser); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -3137,7 +3137,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ batchRsp.pArray = taosArrayInit(numOfUses, sizeof(SGetUserAuthRsp)); if (batchRsp.pArray == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } for (int32_t i = 0; i < numOfUses; ++i) { @@ -3169,7 +3169,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ } if (!(taosArrayPush(batchRsp.pArray, &rsp))) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; mndReleaseUser(pMnode, pUser); tFreeSGetUserAuthRsp(&rsp); TAOS_CHECK_GOTO(code, &lino, _OVER); @@ -3191,7 +3191,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ } pRsp = taosMemoryMalloc(rspLen); if (pRsp == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } rspLen = tSerializeSUserAuthBatchRsp(pRsp, rspLen, &batchRsp); if (rspLen < 0) { diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 2483c7f0d1..0cb4a45f29 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -1445,7 +1445,7 @@ int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD int32_t contLen = sizeof(SMsgHead); SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pHead->contLen = htonl(contLen); @@ -1484,7 +1484,7 @@ int32_t mndAddChangeConfigAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SV SMsgHead *pHead = taosMemoryMalloc(totallen); if (pHead == NULL) { taosMemoryFree(pReq); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pHead->contLen = htonl(totallen); @@ -3067,7 +3067,7 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro if (dbObj.cfg.pRetensions != NULL) { dbObj.cfg.pRetensions = taosArrayDup(pDb->cfg.pRetensions, NULL); if (dbObj.cfg.pRetensions == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 576ba736b5..03098d93e0 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -140,7 +140,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK); if (hash == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pSdb->maxId[sdbType] = 0; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index fd4819dadd..34a017a907 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -226,7 +226,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100); if (pRaw == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; mError("failed read sdb file since %s", tstrerror(code)); TAOS_RETURN(code); } @@ -278,7 +278,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { bufLen = pRaw->dataLen * 2; SSdbRaw *pNewRaw = taosMemoryMalloc(bufLen + 100); if (pNewRaw == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; mError("failed read sdb file since malloc new sdbRaw size:%d failed", bufLen); goto _OVER; } @@ -306,7 +306,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { char *plantContent = taosMemoryMalloc(ENCRYPTED_LEN(pRaw->dataLen)); if (plantContent == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -444,7 +444,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { newDataLen = ENCRYPTED_LEN(pRaw->dataLen); newData = taosMemoryMalloc(newDataLen); if (newData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 5a2d1c981c..b83554c6f9 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -165,7 +165,6 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) { sdbUnLock(pSdb, type); sdbFreeRow(pSdb, pRow, false); - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } From 007b64a3c188278b757542c754ddd8fed84418cd Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 12 Sep 2024 15:48:07 +0800 Subject: [PATCH 83/90] fix: void function call issue --- source/libs/executor/src/groupcacheoperator.c | 2 +- source/libs/scheduler/src/schJob.c | 2 +- source/libs/scheduler/src/schTask.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 2540579413..9f92679ad5 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -1061,7 +1061,7 @@ static int32_t getCacheBlkFromDownstreamOperator(struct SOperatorInfo* pOperator pWaitCtx->newFetch = true; code = taosHashRemove(pCtx->pWaitSessions, pSessionId, sizeof(*pSessionId)); if (code) { - qError("taosHashRemove session %" PRId64 " from waitSession failed, error: %s", pSessionId, tstrerror(code)); + qError("taosHashRemove session %" PRId64 " from waitSession failed, error: %s", *pSessionId, tstrerror(code)); return code; } QRY_ERR_RET(tsem_post(&pWaitCtx->waitSem)); diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 57a21643ef..744a58b866 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -529,7 +529,7 @@ void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); code = tsem_post(&pJob->rspSem); if (code) { - ctgError("tsem_post failed for syncOp, error:%s", tstrerror(code)); + SCH_JOB_ELOG("tsem_post failed for syncOp, error:%s", tstrerror(code)); } } else if (SCH_JOB_IN_ASYNC_EXEC_OP(pJob)) { SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index 8e9d46de31..d1908b7c02 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -1355,7 +1355,7 @@ void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) { SCH_LOCK_TASK(pTask); if (pTask->delayTimer) { if (!taosTmrStopA(&pTask->delayTimer)) { - SCH_TASK_WLOG("stop delayTimer failed, status:%d", pTask->delayTimer); + SCH_TASK_WLOG("stop delayTimer failed, status:%d", pTask->status); } } schDropTaskOnExecNode(pJob, pTask); From 3d50df7191157fde34651dd9dbf570889dec619c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 12 Sep 2024 16:05:07 +0800 Subject: [PATCH 84/90] refactor: remove void. --- source/dnode/vnode/src/tqCommon/tqCommon.c | 4 + source/libs/stream/src/streamCheckStatus.c | 2 +- source/libs/stream/src/streamHb.c | 2 +- source/libs/stream/src/streamMeta.c | 202 +++++++++++++++----- source/libs/stream/src/streamStartHistory.c | 5 +- source/libs/stream/src/streamStartTask.c | 38 ++-- source/libs/stream/src/streamTask.c | 5 +- 7 files changed, 192 insertions(+), 66 deletions(-) diff --git a/source/dnode/vnode/src/tqCommon/tqCommon.c b/source/dnode/vnode/src/tqCommon/tqCommon.c index c00d9a93bb..bde7e23318 100644 --- a/source/dnode/vnode/src/tqCommon/tqCommon.c +++ b/source/dnode/vnode/src/tqCommon/tqCommon.c @@ -1235,6 +1235,10 @@ int32_t tqStreamTaskProcessConsenChkptIdReq(SStreamMeta* pMeta, SRpcMsg* pMsg) { pMeta->vgId, req.taskId); // ignore this code to avoid error code over write int32_t ret = streamMetaAddFailedTask(pMeta, req.streamId, req.taskId); + if (ret) { + tqError("s-task:0x%x failed add check downstream failed, core:%s", req.taskId, tstrerror(ret)); + } + return code; } diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index 41124d8543..48ca2b32e4 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -316,7 +316,7 @@ void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) { pInfo->pList = NULL; if (pInfo->checkRspTmr != NULL) { - (void)taosTmrStop(pInfo->checkRspTmr); + streamTmrStop(pInfo->checkRspTmr); pInfo->checkRspTmr = NULL; } diff --git a/source/libs/stream/src/streamHb.c b/source/libs/stream/src/streamHb.c index 4e35cb718c..703e6a3256 100644 --- a/source/libs/stream/src/streamHb.c +++ b/source/libs/stream/src/streamHb.c @@ -331,7 +331,7 @@ void destroyMetaHbInfo(SMetaHbInfo* pInfo) { tCleanupStreamHbMsg(&pInfo->hbMsg); if (pInfo->hbTmr != NULL) { - (void) taosTmrStop(pInfo->hbTmr); + streamTmrStop(pInfo->hbTmr); pInfo->hbTmr = NULL; } diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index bc902ccf29..abeb03bb1c 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -62,7 +62,12 @@ static void streamMetaEnvInit() { } } -void streamMetaInit() { (void)taosThreadOnce(&streamMetaModuleInit, streamMetaEnvInit); } +void streamMetaInit() { + int32_t code = taosThreadOnce(&streamMetaModuleInit, streamMetaEnvInit); + if (code) { + stError("failed to init stream Meta model, code:%s", tstrerror(code)); + } +} void streamMetaCleanup() { taosCloseRef(streamBackendId); @@ -114,13 +119,17 @@ int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid) { p = taosHashGet(gMetaRefMgt.pTable, &vgId, sizeof(vgId)); if (p == NULL) { - SArray* list = taosArrayInit(8, sizeof(void*)); - p = taosArrayPush(list, &rid); + SArray* pList = taosArrayInit(8, POINTER_BYTES); + if (pList == NULL) { + return terrno; + } + + p = taosArrayPush(pList, &rid); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - code = taosHashPut(gMetaRefMgt.pTable, &vgId, sizeof(vgId), &list, sizeof(void*)); + code = taosHashPut(gMetaRefMgt.pTable, &vgId, sizeof(vgId), &pList, sizeof(void*)); if (code) { stError("vgId:%d failed to put into metaRef table, rid:%" PRId64, (int32_t)vgId, *rid); return code; @@ -180,8 +189,13 @@ int32_t streamMetaCheckBackendCompatible(SStreamMeta* pMeta) { code = tdbTbcMoveToFirst(pCur); if (code) { - (void)tdbTbcClose(pCur); - stError("vgId:%d failed to open stream meta file cursor, not perform compatible check", pMeta->vgId); + stError("vgId:%d failed to open stream meta file cursor, not perform compatible check, code:%s", pMeta->vgId, + tstrerror(code)); + code = tdbTbcClose(pCur); + if (code) { + stError("vgId:%d failed to close meta file cursor, code:%s", pMeta->vgId, tstrerror(code)); + } + return ret; } @@ -209,7 +223,10 @@ int32_t streamMetaCheckBackendCompatible(SStreamMeta* pMeta) { tdbFree(pKey); tdbFree(pVal); - (void)tdbTbcClose(pCur); + code = tdbTbcClose(pCur); + if (code != 0) { + stError("vgId:%d failed to close meta file cursor, code:%s", pMeta->vgId, tstrerror(code)); + } return ret; } @@ -351,8 +368,8 @@ void streamMetaRemoveDB(void* arg, char* key) { int32_t streamMetaOpen(const char* path, void* ahandle, FTaskBuild buildTaskFn, FTaskExpand expandTaskFn, int32_t vgId, int64_t stage, startComplete_fn_t fn, SStreamMeta** p) { - *p = NULL; int32_t code = 0; + QRY_PARAM_CHECK(p); SStreamMeta* pMeta = taosMemoryCalloc(1, sizeof(SStreamMeta)); if (pMeta == NULL) { @@ -484,9 +501,26 @@ _err: taosMemoryFree(pMeta->path); if (pMeta->pTasksMap) taosHashCleanup(pMeta->pTasksMap); if (pMeta->pTaskList) taosArrayDestroy(pMeta->pTaskList); - if (pMeta->pTaskDb) (void)tdbTbClose(pMeta->pTaskDb); - if (pMeta->pCheckpointDb) (void)tdbTbClose(pMeta->pCheckpointDb); - if (pMeta->db) (void)tdbClose(pMeta->db); + if (pMeta->pTaskDb) { + int32_t ret = tdbTbClose(pMeta->pTaskDb); + if (ret) { + stError("vgId:%d tdb failed close task db, code:%s", pMeta->vgId, tstrerror(ret)); + } + pMeta->pTaskDb = NULL; + } + if (pMeta->pCheckpointDb) { + int32_t ret = tdbTbClose(pMeta->pCheckpointDb); + if (ret) { + stError("vgId:%d tdb failed close task checkpointDb, code:%s", pMeta->vgId, tstrerror(ret)); + } + } + if (pMeta->db) { + int32_t ret = tdbClose(pMeta->db); + if (ret) { + stError("vgId:%d tdb failed close meta db, code:%s", pMeta->vgId, tstrerror(ret)); + } + } + if (pMeta->pHbInfo) taosMemoryFreeClear(pMeta->pHbInfo); if (pMeta->updateInfo.pTasks) taosHashCleanup(pMeta->updateInfo.pTasks); if (pMeta->startInfo.pReadyTaskSet) taosHashCleanup(pMeta->startInfo.pReadyTaskSet); @@ -532,7 +566,7 @@ void streamMetaClear(SStreamMeta* pMeta) { // release the ref by timer if (p->info.delaySchedParam != 0 && p->info.fillHistory == 0) { // one more ref in timer stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", p->id.idStr, p->refCnt); - (void)taosTmrStop(p->schedInfo.pDelayTimer); + streamTmrStop(p->schedInfo.pDelayTimer); p->info.delaySchedParam = 0; streamMetaReleaseTask(pMeta, p); } @@ -567,7 +601,10 @@ void streamMetaClose(SStreamMeta* pMeta) { if (pMeta == NULL) { return; } - (void)taosRemoveRef(streamMetaId, pMeta->rid); + int32_t code = taosRemoveRef(streamMetaId, pMeta->rid); + if (code) { + stError("vgId:%d failed to remove ref:%d, code:%s", pMeta->vgId, pMeta->rid, tstrerror(code)); + } } void streamMetaCloseImpl(void* arg) { @@ -576,6 +613,7 @@ void streamMetaCloseImpl(void* arg) { return; } + int32_t code = 0; int32_t vgId = pMeta->vgId; stDebug("vgId:%d start to do-close stream meta", vgId); @@ -584,10 +622,22 @@ void streamMetaCloseImpl(void* arg) { streamMetaWUnLock(pMeta); // already log the error, ignore here - (void)tdbAbort(pMeta->db, pMeta->txn); - (void)tdbTbClose(pMeta->pTaskDb); - (void)tdbTbClose(pMeta->pCheckpointDb); - (void)tdbClose(pMeta->db); + code = tdbAbort(pMeta->db, pMeta->txn); + if (code) { + stError("vgId:%d failed to jump of trans for tdb, code:%s", vgId, tstrerror(code)); + } + code = tdbTbClose(pMeta->pTaskDb); + if (code) { + stError("vgId:%d failed to close taskDb, code:%s", vgId, tstrerror(code)); + } + code = tdbTbClose(pMeta->pCheckpointDb); + if (code) { + stError("vgId:%d failed to close checkpointDb, code:%s", vgId, tstrerror(code)); + } + code = tdbClose(pMeta->db); + if (code) { + stError("vgId:%d failed to close db, code:%s", vgId, tstrerror(code)); + } taosArrayDestroy(pMeta->pTaskList); taosArrayDestroy(pMeta->chkpSaved); @@ -611,7 +661,10 @@ void streamMetaCloseImpl(void* arg) { bkdMgtDestroy(pMeta->bkdChkptMgt); pMeta->role = NODE_ROLE_UNINIT; - (void)taosThreadRwlockDestroy(&pMeta->lock); + code = taosThreadRwlockDestroy(&pMeta->lock); + if (code) { + stError("vgId:%d destroy rwlock, code:%s", vgId, tstrerror(code)); + } taosMemoryFree(pMeta); stDebug("vgId:%d end to close stream meta", vgId); @@ -711,7 +764,7 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa } if (pTask->info.fillHistory == 0) { - (void)atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); + int32_t val = atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); } *pAdded = true; @@ -786,20 +839,26 @@ static void doRemoveIdFromList(SArray* pTaskList, int32_t num, SStreamTaskId* id } static int32_t streamTaskSendTransSuccessMsg(SStreamTask* pTask, void* param) { + int32_t code = 0; if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { - (void)streamTaskSendCheckpointSourceRsp(pTask); + code = streamTaskSendCheckpointSourceRsp(pTask); + if (code) { + stError("s-task:%s vgId:%d failed to send checkpoint-source rsp, code:%s", pTask->id.idStr, pTask->pMeta->vgId, + tstrerror(code)); + } } - return 0; + return code; } int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId) { SStreamTask* pTask = NULL; int32_t vgId = pMeta->vgId; + int32_t code = 0; + STaskId id = {.streamId = streamId, .taskId = taskId}; // pre-delete operation streamMetaWLock(pMeta); - STaskId id = {.streamId = streamId, .taskId = taskId}; SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id)); if (ppTask) { pTask = *ppTask; @@ -811,12 +870,16 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t } // handle the dropping event - (void)streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_DROPPING, streamTaskSendTransSuccessMsg, NULL); + code = streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_DROPPING, streamTaskSendTransSuccessMsg, NULL); + if (code) { + stError("s-task:0x%" PRIx64 " failed to handle dropping event async, code:%s", id.taskId, tstrerror(code)); + } } else { stDebug("vgId:%d failed to find the task:0x%x, it may be dropped already", vgId, taskId); streamMetaWUnLock(pMeta); return 0; } + streamMetaWUnLock(pMeta); stDebug("s-task:0x%x vgId:%d set task status:dropping and start to unregister it", taskId, vgId); @@ -850,12 +913,15 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t pTask = *ppTask; // it is an fill-history task, remove the related stream task's id that points to it if (pTask->info.fillHistory == 0) { - (void)atomic_sub_fetch_32(&pMeta->numOfStreamTasks, 1); + int32_t ret = atomic_sub_fetch_32(&pMeta->numOfStreamTasks, 1); } - int32_t code = taosHashRemove(pMeta->pTasksMap, &id, sizeof(id)); + code = taosHashRemove(pMeta->pTasksMap, &id, sizeof(id)); doRemoveIdFromList(pMeta->pTaskList, (int32_t)taosArrayGetSize(pMeta->pTaskList), &pTask->id); - (void)streamMetaRemoveTask(pMeta, &id); + code = streamMetaRemoveTask(pMeta, &id); + if (code) { + stError("vgId:%d failed to remove task:0x%" PRIx64 ", code:%s", pMeta->vgId, id.taskId, tstrerror(code)); + } int32_t size = (int32_t) taosHashGetSize(pMeta->pTasksMap); int32_t sizeInList = taosArrayGetSize(pMeta->pTaskList); @@ -871,7 +937,7 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t if (pTask->info.delaySchedParam != 0 && pTask->info.fillHistory == 0) { stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", pTask->id.idStr, pTask->refCnt); - (void)taosTmrStop(pTask->schedInfo.pDelayTimer); + streamTmrStop(pTask->schedInfo.pDelayTimer); pTask->info.delaySchedParam = 0; streamMetaReleaseTask(pMeta, pTask); } @@ -936,8 +1002,11 @@ int64_t streamMetaGetLatestCheckpointId(SStreamMeta* pMeta) { code = tdbTbcMoveToFirst(pCur); if (code) { - (void)tdbTbcClose(pCur); - stError("failed to open stream meta file cursor, the latest checkpointId is 0, vgId:%d", pMeta->vgId); + stError("failed to move stream meta file cursor, the latest checkpointId is 0, vgId:%d", pMeta->vgId); + int32_t ret = tdbTbcClose(pCur); + if (ret != 0) { + stError("vgId:%d failed to close meta file cursor, code:%s", pMeta->vgId, tstrerror(ret)); + } return checkpointId; } @@ -960,7 +1029,11 @@ int64_t streamMetaGetLatestCheckpointId(SStreamMeta* pMeta) { tdbFree(pKey); tdbFree(pVal); - (void)tdbTbcClose(pCur); + int32_t ret = tdbTbcClose(pCur); + if (ret != 0) { + stError("vgId:%d failed to close meta file cursor, code:%s", pMeta->vgId, tstrerror(ret)); + } + return checkpointId; } @@ -981,6 +1054,10 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { } pRecycleList = taosArrayInit(4, sizeof(STaskId)); + if (pRecycleList == NULL) { + stError("vgId:%d failed prepare load all tasks, code:out of memory", vgId); + return; + } vgId = pMeta->vgId; stInfo("vgId:%d load stream tasks from meta files", vgId); @@ -996,7 +1073,10 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { if (code) { stError("vgId:%d failed to open stream meta cursor, code:%s, not load any stream tasks", vgId, tstrerror(terrno)); taosArrayDestroy(pRecycleList); - (void)tdbTbcClose(pCur); + int32_t ret = tdbTbcClose(pCur); + if (ret != 0) { + stError("vgId:%d failed to close meta file cursor, code:%s", pMeta->vgId, tstrerror(ret)); + } return; } @@ -1072,11 +1152,11 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { } if (pTask->info.fillHistory == 0) { - (void)atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); + int32_t val = atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); } if (streamTaskShouldPause(pTask)) { - (void)atomic_add_fetch_32(&pMeta->numOfPausedTasks, 1); + int32_t val = atomic_add_fetch_32(&pMeta->numOfPausedTasks, 1); } } @@ -1090,7 +1170,10 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { if (taosArrayGetSize(pRecycleList) > 0) { for (int32_t i = 0; i < taosArrayGetSize(pRecycleList); ++i) { STaskId* pId = taosArrayGet(pRecycleList, i); - (void)streamMetaRemoveTask(pMeta, pId); + code = streamMetaRemoveTask(pMeta, pId); + if (code) { + stError("s-task:0x%" PRIx64 " failed to remove task, code:%s", pId->taskId, tstrerror(code)); + } } } @@ -1099,8 +1182,10 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { pMeta->numOfStreamTasks, pMeta->numOfPausedTasks); taosArrayDestroy(pRecycleList); - - (void)streamMetaCommit(pMeta); + code = streamMetaCommit(pMeta); + if (code) { + stError("vgId:%d failed to commit, code:%s", pMeta->vgId, tstrerror(code)); + } } bool streamMetaTaskInTimer(SStreamMeta* pMeta) { @@ -1117,7 +1202,10 @@ bool streamMetaTaskInTimer(SStreamMeta* pMeta) { SStreamTask* pTask = *(SStreamTask**)pIter; if (pTask->status.timerActive >= 1) { stDebug("s-task:%s in timer, blocking tasks in vgId:%d restart, set closing again", pTask->id.idStr, pMeta->vgId); - (void)streamTaskStop(pTask); + int32_t code = streamTaskStop(pTask); + if (code) { + stError("s-task:%s failed to stop task, code:%s", pTask->id.idStr, tstrerror(code)); + } inTimer = true; } } @@ -1150,7 +1238,10 @@ void streamMetaNotifyClose(SStreamMeta* pMeta) { SStreamTask* pTask = *(SStreamTask**)pIter; stDebug("vgId:%d s-task:%s set task closing flag", vgId, pTask->id.idStr); - (void)streamTaskStop(pTask); + int32_t code = streamTaskStop(pTask); + if (code) { + stError("vgId:%d failed to stop task:0x%x, code:%s", vgId, pTask->id.taskId, tstrerror(code)); + } } streamMetaWUnLock(pMeta); @@ -1168,7 +1259,6 @@ void streamMetaNotifyClose(SStreamMeta* pMeta) { SArray* pTaskList = NULL; int32_t code = streamMetaSendMsgBeforeCloseTasks(pMeta, &pTaskList); if (code != TSDB_CODE_SUCCESS) { -// return code; } streamMetaRUnLock(pMeta); @@ -1199,14 +1289,17 @@ void streamMetaStartHb(SStreamMeta* pMeta) { void streamMetaRLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-rlock", pMeta->vgId); - (void)taosThreadRwlockRdlock(&pMeta->lock); + int32_t code = taosThreadRwlockRdlock(&pMeta->lock); + if (code) { + stError("vgId:%d meta-rlock failed, code:%s", pMeta->vgId, tstrerror(code)); + } } void streamMetaRUnLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-runlock", pMeta->vgId); int32_t code = taosThreadRwlockUnlock(&pMeta->lock); if (code != TSDB_CODE_SUCCESS) { - stError("vgId:%d meta-runlock failed, code:%d", pMeta->vgId, code); + stError("vgId:%d meta-runlock failed, code:%s", pMeta->vgId, tstrerror(code)); } else { // stTrace("vgId:%d meta-runlock completed", pMeta->vgId); } @@ -1214,13 +1307,18 @@ void streamMetaRUnLock(SStreamMeta* pMeta) { void streamMetaWLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-wlock", pMeta->vgId); - (void)taosThreadRwlockWrlock(&pMeta->lock); - // stTrace("vgId:%d meta-wlock completed", pMeta->vgId); + int32_t code = taosThreadRwlockWrlock(&pMeta->lock); + if (code) { + stError("vgId:%d failed to apply wlock, code:%s", pMeta->vgId, tstrerror(code)); + } } void streamMetaWUnLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-wunlock", pMeta->vgId); - (void)taosThreadRwlockUnlock(&pMeta->lock); + int32_t code = taosThreadRwlockUnlock(&pMeta->lock); + if (code) { + stError("vgId:%d failed to apply wunlock, code:%s", pMeta->vgId, tstrerror(code)); + } } int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { @@ -1258,7 +1356,7 @@ int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { streamMetaReleaseTask(pMeta, pTask); } - (void)streamMetaSendHbHelper(pMeta); + code = streamMetaSendHbHelper(pMeta); pMeta->sendMsgBeforeClosing = false; return TSDB_CODE_SUCCESS; // always return true } @@ -1348,9 +1446,9 @@ int32_t streamMetaAddFailedTask(SStreamMeta* pMeta, int64_t streamId, int32_t ta streamMetaRUnLock(pMeta); // add the failed task info, along with the related fill-history task info into tasks list. - (void)streamMetaAddTaskLaunchResult(pMeta, streamId, taskId, startTs, now, false); + code = streamMetaAddTaskLaunchResult(pMeta, streamId, taskId, startTs, now, false); if (hasFillhistoryTask) { - (void)streamMetaAddTaskLaunchResult(pMeta, hId.streamId, hId.taskId, startTs, now, false); + code = streamMetaAddTaskLaunchResult(pMeta, hId.streamId, hId.taskId, startTs, now, false); } } else { streamMetaRUnLock(pMeta); @@ -1365,12 +1463,18 @@ int32_t streamMetaAddFailedTask(SStreamMeta* pMeta, int64_t streamId, int32_t ta void streamMetaAddFailedTaskSelf(SStreamTask* pTask, int64_t failedTs) { int32_t startTs = pTask->execInfo.checkTs; - (void)streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, startTs, failedTs, false); + int32_t code = streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, startTs, failedTs, false); + if (code) { + stError("s-task:%s failed to add self task failed to start", pTask->id.idStr, tstrerror(code)); + } // automatically set the related fill-history task to be failed. if (HAS_RELATED_FILLHISTORY_TASK(pTask)) { STaskId* pId = &pTask->hTaskInfo.id; - (void)streamMetaAddTaskLaunchResult(pTask->pMeta, pId->streamId, pId->taskId, startTs, failedTs, false); + code = streamMetaAddTaskLaunchResult(pTask->pMeta, pId->streamId, pId->taskId, startTs, failedTs, false); + if (code) { + stError("s-task:0x%" PRIx64 " failed to add self task failed to start", pId->taskId, tstrerror(code)); + } } } diff --git a/source/libs/stream/src/streamStartHistory.c b/source/libs/stream/src/streamStartHistory.c index 941b8f5145..ca2da9ef8e 100644 --- a/source/libs/stream/src/streamStartHistory.c +++ b/source/libs/stream/src/streamStartHistory.c @@ -459,7 +459,10 @@ int32_t launchNotBuiltFillHistoryTask(SStreamTask* pTask) { int32_t code = createHTaskLaunchInfo(pMeta, &id, hStreamId, hTaskId, &pInfo); if (code) { stError("s-task:%s failed to launch related fill-history task, since Out Of Memory", idStr); - (void)streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, false); + int32_t ret = streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, false); + if (ret) { + stError("s-task:%s add task check downstream result failed, code:%s", idStr, tstrerror(ret)); + } return code; } diff --git a/source/libs/stream/src/streamStartTask.c b/source/libs/stream/src/streamStartTask.c index c2e8a523e5..168a8adc2d 100644 --- a/source/libs/stream/src/streamStartTask.c +++ b/source/libs/stream/src/streamStartTask.c @@ -62,9 +62,12 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { SStreamTaskId* pTaskId = taosArrayGet(pTaskList, i); SStreamTask* pTask = NULL; code = streamMetaAcquireTask(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask); - if (pTask == NULL) { - stError("vgId:%d failed to acquire task:0x%x during start tasks", pMeta->vgId, pTaskId->taskId); - (void)streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + if ((pTask == NULL) || (code != 0)) { + stError("vgId:%d failed to acquire task:0x%x during start task, it may be dropped", pMeta->vgId, pTaskId->taskId); + int32_t ret = streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + if (ret) { + stError("s-task:0x%x add check downstream failed, core:%s", pTaskId->taskId, tstrerror(ret)); + } continue; } @@ -85,9 +88,13 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { SStreamTask* pTask = NULL; code = streamMetaAcquireTask(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask); - if (pTask == NULL) { + if ((pTask == NULL )|| (code != 0)) { stError("vgId:%d failed to acquire task:0x%x during start tasks", pMeta->vgId, pTaskId->taskId); - (void)streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + int32_t ret = streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + if (ret) { + stError("s-task:0x%x failed add check downstream failed, core:%s", pTaskId->taskId, tstrerror(ret)); + } + continue; } @@ -105,11 +112,11 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { if (HAS_RELATED_FILLHISTORY_TASK(pTask)) { stDebug("s-task:%s downstream ready, no need to check downstream, check only related fill-history task", pTask->id.idStr); - (void)streamLaunchFillHistoryTask(pTask); // todo: how about retry launch fill-history task? + code = streamLaunchFillHistoryTask(pTask); // todo: how about retry launch fill-history task? } - (void)streamMetaAddTaskLaunchResult(pMeta, pTaskId->streamId, pTaskId->taskId, pInfo->checkTs, pInfo->readyTs, - true); + code = streamMetaAddTaskLaunchResult(pMeta, pTaskId->streamId, pTaskId->taskId, pInfo->checkTs, pInfo->readyTs, + true); streamMetaReleaseTask(pMeta, pTask); continue; } @@ -333,9 +340,13 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas stInfo("vgId:%d start task:0x%x by checking it's downstream status", vgId, taskId); code = streamMetaAcquireTask(pMeta, streamId, taskId, &pTask); - if (pTask == NULL) { + if ((pTask == NULL) || (code != 0)) { stError("vgId:%d failed to acquire task:0x%x when starting task", vgId, taskId); - (void)streamMetaAddFailedTask(pMeta, streamId, taskId); + int32_t ret = streamMetaAddFailedTask(pMeta, streamId, taskId); + if (ret) { + stError("s-task:0x%x add check downstream failed, core:%s", taskId, tstrerror(ret)); + } + return TSDB_CODE_STREAM_TASK_IVLD_STATUS; } @@ -431,7 +442,10 @@ int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) { continue; } - (void)streamTaskStop(pTask); + int32_t ret = streamTaskStop(pTask); + if (ret) { + stError("s-task:0x%x failed to stop task, code:%s", pTaskId->taskId, tstrerror(ret)); + } streamMetaReleaseTask(pMeta, pTask); } @@ -441,7 +455,7 @@ int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) { stDebug("vgId:%d stop all %d task(s) completed, elapsed time:%.2f Sec.", pMeta->vgId, num, el); streamMetaRUnLock(pMeta); - return 0; + return code; } int32_t streamTaskCheckIfReqConsenChkptId(SStreamTask* pTask, int64_t ts) { diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 5d6cf39e40..79c87f942c 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -687,13 +687,14 @@ int32_t streamTaskStop(SStreamTask* pTask) { int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_STOP); if (code) { - stError("failed to handle STOP event, s-task:%s", id); + stError("failed to handle STOP event, s-task:%s, code:%s", id, tstrerror(code)); + return code; } if (pTask->info.taskLevel != TASK_LEVEL__SINK && pTask->exec.pExecutor != NULL) { code = qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS); if (code != TSDB_CODE_SUCCESS) { - stError("s-task:%s failed to kill task related query handle", id); + stError("s-task:%s failed to kill task related query handle, code:%s", id, tstrerror(code)); } } From b35a435704bd9377fbd4fa58c7feb3485c4d350c Mon Sep 17 00:00:00 2001 From: Bo Ding Date: Thu, 12 Sep 2024 16:12:50 +0800 Subject: [PATCH 85/90] docs(taosx): update pi document --- docs/zh/06-advanced/05-data-in/03-pi.md | 151 +++++++++++++++++++++--- 1 file changed, 134 insertions(+), 17 deletions(-) diff --git a/docs/zh/06-advanced/05-data-in/03-pi.md b/docs/zh/06-advanced/05-data-in/03-pi.md index 2cffb4ce0d..6b65b1337f 100644 --- a/docs/zh/06-advanced/05-data-in/03-pi.md +++ b/docs/zh/06-advanced/05-data-in/03-pi.md @@ -7,21 +7,29 @@ sidebar_label: "PI" ## 功能概述 -PI 系统是一套用于数据收集、查找、分析、传递和可视化的软件产品,可以作为管理实时数据和事件的企业级系统的基础架构。 +PI 系统是一套用于数据收集、查找、分析、传递和可视化的软件产品,可以作为管理实时数据和事件的企业级系统的基础架构。taosX 可以 PI 连接器插件从 PI 系统中提取实时数据或历史数据。 -taosX 可以通过 PI 连接器插件从 PI 系统中提取实时数据。 +从数据的实时性角度来看 PI 数据源任务分为两类:**实时任务**和**回填任务**。在任务类型下拉列表两类任务分别对应名称: **PI** 和 **PI backfill**。 + +从数据模型角度来看, PI 数据源任务分为**单列模型**任务和**多列模型**任务: +1. **单列模型**任务将一个 PI Point 映射为 TDengine 一张表 +2. **多列模型**任务将一个 PI AF 元素映射为一张表 -有两类 PI 任务: 实时同步任务和历史数据迁移任务,在任务下拉列表的名称分别对应 “PI” 和 “PI backfill”。 +从连接的数据源类型来讲,PI 数据源任务又分为 **Archive Server** 数据源和 **AF Server** 数据源。对于 **Archive Server** 数据源,只能使用**单列模型**。对于 **AF Server** 数据源,既可以选择**单列模型**,又可以选择**多列模型**。 + +用户通过一个 CSV 文件配置从 PI 到 TDengine 的数据映射规则,这个 CSV 文件称为**模型配置文件**: +1. 对于使用 AF Server 单列模型的任务,taosX 会自动识别元素的哪些属性是引用 PI Point 的数据,并把一个 PI Point 属性对应到一张表。 +2. 对于使用 AF Server 的多列模型任务,一个元素对应一张表。taosX 默认会把 PI Point 属性映射到 TDengine Metric 列,把其它属性映射到 TDengine TAG 列。 ## 创建任务 -### 1. 新增数据源 +### 新增数据源 在数据写入页面中,点击 **+新增数据源** 按钮,进入新增数据源页面。 ![kafka-01.png](./kafka-01.png) -### 2. 配置基本信息 +### 基本配置 在 **名称** 中输入任务名称,如:“test”; @@ -33,7 +41,7 @@ taosX 可以通过 PI 连接器插件从 PI 系统中提取实时数据。 ![basic.png](./pic/pi-01-agent.png) -### 3. 配置连接信息 +### 连接配置 PI 连接器支持两种连接方式: @@ -46,21 +54,130 @@ PI 连接器支持两种连接方式: 点击 **连通性检查** 按钮,检查数据源是否可用。 -### 4. 配置数据模型 +### 数据模型配置 -这一部分,我们用一个 csv 文件配置 PI 的数据模型到 TDengine 的数据模型的映射规则。这里所说的映射规则包含 3 方面内容: +这一部分有两个 Tab,分别对应单列模型的配置和多列模型的配置。如果你是第一次配置,无论选择单列模型还是多列模型,请务必点击“下载默认配置”按钮。这个操作会触发生成默认的**模型配置文件**,同时也会把**模型配置文件**下载到本地,你可以查看或编辑。编辑后还可以再上传,来覆盖默认的配置。 -1. 定义源数据范围,即哪些点或哪些模板需要同步到 TDengine。 -2. 定义过滤规则,即符合什么条件的数据才需要同步到 TDengine。 -3. 定义转换规则,即对原始数据做什么样的变换后再写入 TDengine。 +如果你想同步所有点位或所有模板的元素,那么用默认的配置就好了。如果你想要过滤特定命名模式的点位或元素模板,那么需要先填写过滤条件再点击“下载默认配置”。 -如果您不知道具体怎么操作,可以点击“下载默认配置”按钮,下载得到的 csv 文件有详细的使用说明。 +#### 多列模型配置文件 -### 5. 其他配置 +下面是一个多列模型配置文件的示例。这个配置文件包含两个超级表的配置:一个是 metertemplate 表,它的数据来自模板 MeterTemplate 的元素;另一个是 farm 表,它的数据来自 Farm 模板的元素。 -其余的配置,比较重要的是: +```csv +SuperTable,metertemplate +SubTable,${element_name}_${element_id} +Template,MeterTemplate +Filter, +ts,KEY,TIMESTAMP,$ts +voltage,COLUMN,DOUBLE,$voltage +voltage_status,COLUMN,INT,$voltage_status +current,COLUMN,DOUBLE,$current +current_status,COLUMN,INT,$current_status +element_id,TAG,VARCHAR(100),$element_id +element_name,TAG,VARCHAR(100),$element_name +path,TAG,VARCHAR(100),$path +categories,TAG,VARCHAR(100),$categories -1. 对于 PI 任务,配置“重启补偿时间”,如果任务意外中断,重启时配置这个参数非常有用,它会让 taosX 自动 backfill 一段时间的数据。 -2. 对于 PI backfill 任务,需要配置 backfill 的开始和结束时间。 +SuperTable,farm +SubTable,${element_name}_${element_id} +Template,Farm +Filter, +ts,KEY,TIMESTAMP,$ts +wind_speed,COLUMN,FLOAT,$wind_speed +wind_speed_status,COLUMN,INT,$wind_speed_status +power_production,COLUMN,FLOAT,$power_production +power_production_status,COLUMN,INT,$power_production_status +lost_power,COLUMN,FLOAT,$lost_power +lost_power_status,COLUMN,INT,$lost_power_status +farm_lifetime_production__weekly_,COLUMN,FLOAT,$farm_lifetime_production__weekly_ +farm_lifetime_production__weekly__status,COLUMN,INT,$farm_lifetime_production__weekly__status +farm_lifetime_production__hourly_,COLUMN,FLOAT,$farm_lifetime_production__hourly_ +farm_lifetime_production__hourly__status,COLUMN,INT,$farm_lifetime_production__hourly__status +element_id,TAG,VARCHAR(100),$element_id +element_name,TAG,VARCHAR(100),$element_name +path,TAG,VARCHAR(100),$path +categories,TAG,VARCHAR(100),$categories +``` + +多列模型配置文件由一个或多个超级表的定义组成。每个超级表的配置都包括: + +1. 超级表和模板的对应关系 +2. 属性和 TDengine Metric 列的对应关系 +3. 属性和 TDengine TAG 列的对应关系 +4. 源数据过滤条件 +5. 对于每一列,无论是 Metrics 列还是 TAG 列,都可以配置一个映射规则,详见[零代码第三方数据接入](../)“数据提取、过滤和转换”部分 + +#### 单列模型配置文件 + +下面是一个单列模型配置文件的示例。 + +```csv +SuperTable,volt_float32 +SubTable,${point_name} +Filter, +ts,KEY,TIMESTAMP,$ts +value,COLUMN,FLOAT,$value +status,COLUMN,INT,$status +path,TAG,VARCHAR(200),$path +point_name,TAG,VARCHAR(100),$point_name +ptclassname,TAG,VARCHAR(100),$ptclassname +sourcetag,TAG,VARCHAR(100),$sourcetag +tag,TAG,VARCHAR(100),$tag +descriptor,TAG,VARCHAR(100),$descriptor +exdesc,TAG,VARCHAR(100),$exdesc +engunits,TAG,VARCHAR(100),$engunits +pointsource,TAG,VARCHAR(100),$pointsource +step,TAG,VARCHAR(100),$step +future,TAG,VARCHAR(100),$future +element_paths,TAG,VARCHAR(512),`$element_paths.replace("\\", ".")` + +SuperTable,milliampere_float32 +SubTable,${point_name} +Filter, +ts,KEY,TIMESTAMP,$ts +value,COLUMN,FLOAT,$value +status,COLUMN,INT,$status +path,TAG,VARCHAR(200),$path +point_name,TAG,VARCHAR(100),$point_name +ptclassname,TAG,VARCHAR(100),$ptclassname +sourcetag,TAG,VARCHAR(100),$sourcetag +tag,TAG,VARCHAR(100),$tag +descriptor,TAG,VARCHAR(100),$descriptor +exdesc,TAG,VARCHAR(100),$exdesc +engunits,TAG,VARCHAR(100),$engunits +pointsource,TAG,VARCHAR(100),$pointsource +step,TAG,VARCHAR(100),$step +future,TAG,VARCHAR(100),$future +element_paths,TAG,VARCHAR(512),`$element_paths.replace("\\", ".")` + +Meter_1000004_Voltage,POINT,volt_float32 +Meter_1000004_Current,POINT,milliampere_float32 +Meter_1000001_Voltage,POINT,volt_float32 +Meter_1000001_Current,POINT,milliampere_float32 +Meter_1000474_Voltage,POINT,volt_float32 +Meter_1000474_Current,POINT,milliampere_float32 +``` + +单列模型配置文件分为两个部分,第一部分通多列模型配置文件,由若干个超级表的定义组成。第二部分是点位列表,这一部分配置了点位和超级表的映射关系。默认生成的配置把 UOM 相同且数据类型相同的点映射到同一个超级表。 + +### Backfill 配置 + +1. 对于 PI 任务,可配置“重启补偿时间”,如果任务意外中断,重启时配置这个参数非常有用,它会让 taosX 自动回填一段时间的数据。 +2. 对于 PI backfill 任务,必须配置 backfill 的开始和结束时间。 + +### 高级选项 + +对于不同的任务类型高级选项部分有所不同。通用的高级选项有: +1. 连接器日志级别 +2. 连接器查询和发送数据的批次大小 +3. 单次读取最大延迟 + +对于**多列模型的实时任务**,还有以下开关选项: + +1. 是否同步新增的元素。如果打开,则 PI 连接器会监听模板下新增的元素,无需重启任务,即可自动同步新增元素的数据。 +2. 是否同步静态属性的变化。如果打开,PI 连接器会同步所有静态属性(非 PI Point 属性)的变化。也就是说如果在 PI AF Server 一个元素的静态属性值做了修改,那么 TDengine 表相应 TAG 的值也会修改。 +3. 是否同步删除元素的操作。如果打开,则 PI 连接器会监听配置的模板下删除元素的事件,并同步删除 TDengine 对应子表。 +4. 是否同步删除历史数据。如果打开,则对于某个元素的时序数据,如果在 PI 中某个时间的数据被删除了,TDengine 对应时间对应列的数据会被置空。 +5. 是否同步修改历史数据。如果打开,则对于某个元素的时序数据,如果在 PI 中历史数据被修改了,TDengine 对应时间的数据也会更新。 -高级配置部分可以配置连接器日志的级别、批次大小、和批次延迟。用于 Debug 和 性能优化。 \ No newline at end of file From 4785d977f530e4b2a5aed9f1aa003c17c21f4ce6 Mon Sep 17 00:00:00 2001 From: t_max <1172915550@qq.com> Date: Thu, 12 Sep 2024 16:36:28 +0800 Subject: [PATCH 86/90] docs: add taosAdapter connection pool configuration description --- .../01-components/03-taosadapter.md | 196 ++++++++++-------- .../01-components/03-taosadapter.md | 196 ++++++++++-------- 2 files changed, 213 insertions(+), 179 deletions(-) diff --git a/docs/en/14-reference/01-components/03-taosadapter.md b/docs/en/14-reference/01-components/03-taosadapter.md index 50b4019fd7..00a8aa65c3 100644 --- a/docs/en/14-reference/01-components/03-taosadapter.md +++ b/docs/en/14-reference/01-components/03-taosadapter.md @@ -54,95 +54,102 @@ Command-line arguments take precedence over environment variables over configura ```shell Usage of taosAdapter: - --collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd") - --collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true) - --collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata") - --collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045) - --collectd.ttl int collectd data ttl. Env "TAOS_ADAPTER_COLLECTD_TTL" - --collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root") - --collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10) - -c, --config string config path default /etc/taos/taosadapter.toml - --cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true) - --cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials" - --cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS" - --cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS" - --cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets" - --cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers" - --debug enable debug mode. Env "TAOS_ADAPTER_DEBUG" (default true) - --help Print this help message and exit - --httpCodeServerError Use a non-200 http status code when server returns an error. Env "TAOS_ADAPTER_HTTP_CODE_SERVER_ERROR" - --influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true) - --log.enableRecordHttpSql whether to record http sql. Env "TAOS_ADAPTER_LOG_ENABLE_RECORD_HTTP_SQL" - --log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos") --log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30) - --log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB") - --log.rotationTime duration log rotation time. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s) - --log.sqlRotationCount uint record sql log rotation count. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_COUNT" (default 2) - --log.sqlRotationSize string record sql log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_SIZE" (default "1GB") - --log.sqlRotationTime duration record sql log rotation time. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_TIME" (default 24h0m0s) - --logLevel string log level (panic fatal error warn warning info debug trace). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") - --monitor.collectDuration duration Set monitor duration. Env "TAOS_ADAPTER_MONITOR_COLLECT_DURATION" (default 3s) - --monitor.disable Whether to disable monitoring. Env "TAOS_ADAPTER_MONITOR_DISABLE" - --monitor.disableCollectClientIP Whether to disable collecting clientIP. Env "TAOS_ADAPTER_MONITOR_DISABLE_COLLECT_CLIENT_IP" - --monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_ADAPTER_MONITOR_IDENTITY" - --monitor.incgroup Whether running in cgroup. Env "TAOS_ADAPTER_MONITOR_INCGROUP" - --monitor.password string TDengine password. Env "TAOS_ADAPTER_MONITOR_PASSWORD" (default "taosdata") - --monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_ADAPTER_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80) - --monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_ADAPTER_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70) - --monitor.user string TDengine user. Env "TAOS_ADAPTER_MONITOR_USER" (default "root") - --monitor.writeInterval duration Set write to TDengine interval. Env "TAOS_ADAPTER_MONITOR_WRITE_INTERVAL" (default 30s) - --monitor.writeToTD Whether write metrics to TDengine. Env "TAOS_ADAPTER_MONITOR_WRITE_TO_TD" - --node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE" - --node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE" - --node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter") - --node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE" - --node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s) - --node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING" - --node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD" - --node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME" - --node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true) - --node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE" - --node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata") - --node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s) - --node_exporter.ttl int node_exporter data ttl. Env "TAOS_ADAPTER_NODE_EXPORTER_TTL" - --node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [http://localhost:9100]) - --node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root") - --opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true) - --opentsdb_telnet.batchSize int opentsdb_telnet batch size. Env "TAOS_ADAPTER_OPENTSDB_TELNET_BATCH_SIZE" (default 1) - --opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb]) - --opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE" - --opentsdb_telnet.flushInterval duration opentsdb_telnet flush interval (0s means not valid) . Env "TAOS_ADAPTER_OPENTSDB_TELNET_FLUSH_INTERVAL" - --opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250) - --opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata") - --opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049]) - --opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE" - --opentsdb_telnet.ttl int opentsdb_telnet data ttl. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TTL" - --opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root") - --pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" - --pool.maxConnect int max connections to server. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" - --pool.maxIdle int max idle connections to server. Env "TAOS_ADAPTER_POOL_MAX_IDLE" - -P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041) - --prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true) - --restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1) - --smlAutoCreateDB Whether to automatically create db when writing with schemaless. Env "TAOS_ADAPTER_SML_AUTO_CREATE_DB" - --statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000) - --statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd") - --statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true) - --statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true) - --statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true) - --statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true) - --statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" (default true) - --statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s) - --statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250) - --statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata") - --statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044) - --statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp") - --statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE" - --statsd.ttl int statsd data ttl. Env "TAOS_ADAPTER_STATSD_TTL" - --statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root") - --statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10) - --taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE" - --tmq.releaseIntervalMultiplierForAutocommit int When set to autocommit, the interval for message release is a multiple of the autocommit interval, with a default value of 2 and a minimum value of 1 and a maximum value of 10. Env "TAOS_ADAPTER_TMQ_RELEASE_INTERVAL_MULTIPLIER_FOR_AUTOCOMMIT" (default 2) - --version Print the version and exit + --collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd") + --collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true) + --collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata") + --collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045) + --collectd.ttl int collectd data ttl. Env "TAOS_ADAPTER_COLLECTD_TTL" + --collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root") + --collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10) + -c, --config string config path default /etc/taos/taosadapter.toml + --cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true) + --cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials" + --cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS" + --cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS" + --cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets" + --cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers" + --debug enable debug mode. Env "TAOS_ADAPTER_DEBUG" (default true) + --help Print this help message and exit + --httpCodeServerError Use a non-200 http status code when server returns an error. Env "TAOS_ADAPTER_HTTP_CODE_SERVER_ERROR" + --influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true) + --instanceId int instance ID. Env "TAOS_ADAPTER_INSTANCE_ID" (default 32) + --log.compress whether to compress old log. Env "TAOS_ADAPTER_LOG_COMPRESS" + --log.enableRecordHttpSql whether to record http sql. Env "TAOS_ADAPTER_LOG_ENABLE_RECORD_HTTP_SQL" + --log.level string log level (trace debug info warning error). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") + --log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos") + --log.reservedDiskSize string reserved disk size for log dir (KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_RESERVED_DISK_SIZE" (default "1GB") + --log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30) + --log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB") + --log.rotationTime duration deprecated: log rotation time always 24 hours. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s) + --log.sqlRotationCount uint record sql log rotation count. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_COUNT" (default 2) + --log.sqlRotationSize string record sql log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_SIZE" (default "1GB") + --log.sqlRotationTime duration record sql log rotation time. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_TIME" (default 24h0m0s) + --logLevel string log level (trace debug info warning error). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") + --monitor.collectDuration duration Set monitor duration. Env "TAOS_ADAPTER_MONITOR_COLLECT_DURATION" (default 3s) + --monitor.disable Whether to disable monitoring. Env "TAOS_ADAPTER_MONITOR_DISABLE" (default true) + --monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_ADAPTER_MONITOR_IDENTITY" + --monitor.incgroup Whether running in cgroup. Env "TAOS_ADAPTER_MONITOR_INCGROUP" + --monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_ADAPTER_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80) + --monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_ADAPTER_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70) + --node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE" + --node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE" + --node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter") + --node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE" + --node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s) + --node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING" + --node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD" + --node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME" + --node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true) + --node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE" + --node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata") + --node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s) + --node_exporter.ttl int node_exporter data ttl. Env "TAOS_ADAPTER_NODE_EXPORTER_TTL" + --node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [http://localhost:9100]) + --node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root") + --opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true) + --opentsdb_telnet.batchSize int opentsdb_telnet batch size. Env "TAOS_ADAPTER_OPENTSDB_TELNET_BATCH_SIZE" (default 1) + --opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb]) + --opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE" + --opentsdb_telnet.flushInterval duration opentsdb_telnet flush interval (0s means not valid) . Env "TAOS_ADAPTER_OPENTSDB_TELNET_FLUSH_INTERVAL" + --opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250) + --opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata") + --opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049]) + --opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE" + --opentsdb_telnet.ttl int opentsdb_telnet data ttl. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TTL" + --opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root") + --pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" + --pool.maxConnect int max connections to server. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" + --pool.maxIdle int max idle connections to server. Env "TAOS_ADAPTER_POOL_MAX_IDLE" + --pool.maxWait int max count of waiting for connection. Env "TAOS_ADAPTER_POOL_MAX_WAIT" + --pool.waitTimeout int wait for connection timeout seconds. Env "TAOS_ADAPTER_POOL_WAIT_TIMEOUT" (default 60) + -P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041) + --prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true) + --restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1) + --smlAutoCreateDB Whether to automatically create db when writing with schemaless. Env "TAOS_ADAPTER_SML_AUTO_CREATE_DB" + --statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000) + --statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd") + --statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true) + --statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true) + --statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true) + --statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true) + --statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" + --statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s) + --statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250) + --statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata") + --statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044) + --statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp4") + --statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE" + --statsd.ttl int statsd data ttl. Env "TAOS_ADAPTER_STATSD_TTL" + --statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root") + --statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10) + --taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE" + --uploadKeeper.enable Whether to enable sending metrics to keeper. Env "TAOS_ADAPTER_UPLOAD_KEEPER_ENABLE" (default true) + --uploadKeeper.interval duration send to Keeper interval. Env "TAOS_ADAPTER_UPLOAD_KEEPER_INTERVAL" (default 15s) + --uploadKeeper.retryInterval duration retry interval. Env "TAOS_ADAPTER_UPLOAD_KEEPER_RETRY_INTERVAL" (default 5s) + --uploadKeeper.retryTimes uint retry times. Env "TAOS_ADAPTER_UPLOAD_KEEPER_RETRY_TIMES" (default 3) + --uploadKeeper.timeout duration send to Keeper timeout. Env "TAOS_ADAPTER_UPLOAD_KEEPER_TIMEOUT" (default 5s) + --uploadKeeper.url string Keeper url. Env "TAOS_ADAPTER_UPLOAD_KEEPER_URL" (default "http://127.0.0.1:6043/adapter_report") + -V, --version Print the version and exit ``` Note: @@ -163,6 +170,17 @@ For details on the CORS protocol, please refer to: [https://www.w3.org/wiki/CORS See [example/config/taosadapter.toml](https://github.com/taosdata/taosadapter/blob/3.0/example/config/taosadapter.toml) for sample configuration files. +### Connection Pool Parameters + +When using the RESTful interface, TDengine connections are managed through a connection pool. The pool can be configured with the following parameters: + +- **`pool.maxConnect`**: The maximum number of connections allowed in the pool. The default value is 2 times the number of CPU cores. It is recommended to keep the default setting. +- **`pool.maxIdle`**: The maximum number of idle connections allowed in the pool. By default, this is the same as `pool.maxConnect`. It is recommended to keep the default setting. +- **`pool.idleTimeout`**: The idle timeout duration for connections. By default, connections never time out. It is recommended to keep the default setting. +- **`pool.waitTimeout`**: The timeout for acquiring a connection from the pool. The default value is 60 seconds. If a connection cannot be acquired within the timeout, an HTTP 503 status code will be returned. This parameter is available starting from version 3.3.3.0. +- **`pool.maxWait`**: The maximum number of requests waiting to acquire a connection from the pool. The default value is 0, meaning there is no limit. If the number of queued requests exceeds this value, new requests will return an HTTP 503 status code. This parameter is available starting from version 3.3.3.0. + + ## Feature List - RESTful interface diff --git a/docs/zh/14-reference/01-components/03-taosadapter.md b/docs/zh/14-reference/01-components/03-taosadapter.md index ed90f54bca..443b769dde 100644 --- a/docs/zh/14-reference/01-components/03-taosadapter.md +++ b/docs/zh/14-reference/01-components/03-taosadapter.md @@ -54,96 +54,102 @@ taosAdapter 支持通过命令行参数、环境变量和配置文件来进行 ```shell Usage of taosAdapter: - --collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd") - --collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true) - --collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata") - --collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045) - --collectd.ttl int collectd data ttl. Env "TAOS_ADAPTER_COLLECTD_TTL" - --collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root") - --collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10) - -c, --config string config path default /etc/taos/taosadapter.toml - --cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true) - --cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials" - --cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS" - --cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS" - --cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets" - --cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers" - --debug enable debug mode. Env "TAOS_ADAPTER_DEBUG" (default true) - --help Print this help message and exit - --httpCodeServerError Use a non-200 http status code when server returns an error. Env "TAOS_ADAPTER_HTTP_CODE_SERVER_ERROR" - --influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true) - --log.enableRecordHttpSql whether to record http sql. Env "TAOS_ADAPTER_LOG_ENABLE_RECORD_HTTP_SQL" - --log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos") - --log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30) - --log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB") - --log.rotationTime duration log rotation time. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s) - --log.sqlRotationCount uint record sql log rotation count. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_COUNT" (default 2) - --log.sqlRotationSize string record sql log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_SIZE" (default "1GB") - --log.sqlRotationTime duration record sql log rotation time. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_TIME" (default 24h0m0s) - --logLevel string log level (panic fatal error warn warning info debug trace). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") - --monitor.collectDuration duration Set monitor duration. Env "TAOS_ADAPTER_MONITOR_COLLECT_DURATION" (default 3s) - --monitor.disable Whether to disable monitoring. Env "TAOS_ADAPTER_MONITOR_DISABLE" - --monitor.disableCollectClientIP Whether to disable collecting clientIP. Env "TAOS_ADAPTER_MONITOR_DISABLE_COLLECT_CLIENT_IP" - --monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_ADAPTER_MONITOR_IDENTITY" - --monitor.incgroup Whether running in cgroup. Env "TAOS_ADAPTER_MONITOR_INCGROUP" - --monitor.password string TDengine password. Env "TAOS_ADAPTER_MONITOR_PASSWORD" (default "taosdata") - --monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_ADAPTER_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80) - --monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_ADAPTER_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70) - --monitor.user string TDengine user. Env "TAOS_ADAPTER_MONITOR_USER" (default "root") - --monitor.writeInterval duration Set write to TDengine interval. Env "TAOS_ADAPTER_MONITOR_WRITE_INTERVAL" (default 30s) - --monitor.writeToTD Whether write metrics to TDengine. Env "TAOS_ADAPTER_MONITOR_WRITE_TO_TD" - --node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE" - --node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE" - --node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter") - --node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE" - --node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s) - --node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING" - --node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD" - --node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME" - --node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true) - --node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE" - --node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata") - --node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s) - --node_exporter.ttl int node_exporter data ttl. Env "TAOS_ADAPTER_NODE_EXPORTER_TTL" - --node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [http://localhost:9100]) - --node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root") - --opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true) - --opentsdb_telnet.batchSize int opentsdb_telnet batch size. Env "TAOS_ADAPTER_OPENTSDB_TELNET_BATCH_SIZE" (default 1) - --opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb]) - --opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE" - --opentsdb_telnet.flushInterval duration opentsdb_telnet flush interval (0s means not valid) . Env "TAOS_ADAPTER_OPENTSDB_TELNET_FLUSH_INTERVAL" - --opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250) - --opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata") - --opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049]) - --opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE" - --opentsdb_telnet.ttl int opentsdb_telnet data ttl. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TTL" - --opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root") - --pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" - --pool.maxConnect int max connections to server. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" - --pool.maxIdle int max idle connections to server. Env "TAOS_ADAPTER_POOL_MAX_IDLE" - -P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041) - --prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true) - --restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1) - --smlAutoCreateDB Whether to automatically create db when writing with schemaless. Env "TAOS_ADAPTER_SML_AUTO_CREATE_DB" - --statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000) - --statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd") - --statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true) - --statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true) - --statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true) - --statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true) - --statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" (default true) - --statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s) - --statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250) - --statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata") - --statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044) - --statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp") - --statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE" - --statsd.ttl int statsd data ttl. Env "TAOS_ADAPTER_STATSD_TTL" - --statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root") - --statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10) - --taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE" - --tmq.releaseIntervalMultiplierForAutocommit int When set to autocommit, the interval for message release is a multiple of the autocommit interval, with a default value of 2 and a minimum value of 1 and a maximum value of 10. Env "TAOS_ADAPTER_TMQ_RELEASE_INTERVAL_MULTIPLIER_FOR_AUTOCOMMIT" (default 2) - --version Print the version and exit + --collectd.db string collectd db name. Env "TAOS_ADAPTER_COLLECTD_DB" (default "collectd") + --collectd.enable enable collectd. Env "TAOS_ADAPTER_COLLECTD_ENABLE" (default true) + --collectd.password string collectd password. Env "TAOS_ADAPTER_COLLECTD_PASSWORD" (default "taosdata") + --collectd.port int collectd server port. Env "TAOS_ADAPTER_COLLECTD_PORT" (default 6045) + --collectd.ttl int collectd data ttl. Env "TAOS_ADAPTER_COLLECTD_TTL" + --collectd.user string collectd user. Env "TAOS_ADAPTER_COLLECTD_USER" (default "root") + --collectd.worker int collectd write worker. Env "TAOS_ADAPTER_COLLECTD_WORKER" (default 10) + -c, --config string config path default /etc/taos/taosadapter.toml + --cors.allowAllOrigins cors allow all origins. Env "TAOS_ADAPTER_CORS_ALLOW_ALL_ORIGINS" (default true) + --cors.allowCredentials cors allow credentials. Env "TAOS_ADAPTER_CORS_ALLOW_Credentials" + --cors.allowHeaders stringArray cors allow HEADERS. Env "TAOS_ADAPTER_ALLOW_HEADERS" + --cors.allowOrigins stringArray cors allow origins. Env "TAOS_ADAPTER_ALLOW_ORIGINS" + --cors.allowWebSockets cors allow WebSockets. Env "TAOS_ADAPTER_CORS_ALLOW_WebSockets" + --cors.exposeHeaders stringArray cors expose headers. Env "TAOS_ADAPTER_Expose_Headers" + --debug enable debug mode. Env "TAOS_ADAPTER_DEBUG" (default true) + --help Print this help message and exit + --httpCodeServerError Use a non-200 http status code when server returns an error. Env "TAOS_ADAPTER_HTTP_CODE_SERVER_ERROR" + --influxdb.enable enable influxdb. Env "TAOS_ADAPTER_INFLUXDB_ENABLE" (default true) + --instanceId int instance ID. Env "TAOS_ADAPTER_INSTANCE_ID" (default 32) + --log.compress whether to compress old log. Env "TAOS_ADAPTER_LOG_COMPRESS" + --log.enableRecordHttpSql whether to record http sql. Env "TAOS_ADAPTER_LOG_ENABLE_RECORD_HTTP_SQL" + --log.level string log level (trace debug info warning error). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") + --log.path string log path. Env "TAOS_ADAPTER_LOG_PATH" (default "/var/log/taos") + --log.reservedDiskSize string reserved disk size for log dir (KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_RESERVED_DISK_SIZE" (default "1GB") + --log.rotationCount uint log rotation count. Env "TAOS_ADAPTER_LOG_ROTATION_COUNT" (default 30) + --log.rotationSize string log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_ROTATION_SIZE" (default "1GB") + --log.rotationTime duration deprecated: log rotation time always 24 hours. Env "TAOS_ADAPTER_LOG_ROTATION_TIME" (default 24h0m0s) + --log.sqlRotationCount uint record sql log rotation count. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_COUNT" (default 2) + --log.sqlRotationSize string record sql log rotation size(KB MB GB), must be a positive integer. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_SIZE" (default "1GB") + --log.sqlRotationTime duration record sql log rotation time. Env "TAOS_ADAPTER_LOG_SQL_ROTATION_TIME" (default 24h0m0s) + --logLevel string log level (trace debug info warning error). Env "TAOS_ADAPTER_LOG_LEVEL" (default "info") + --monitor.collectDuration duration Set monitor duration. Env "TAOS_ADAPTER_MONITOR_COLLECT_DURATION" (default 3s) + --monitor.disable Whether to disable monitoring. Env "TAOS_ADAPTER_MONITOR_DISABLE" (default true) + --monitor.identity string The identity of the current instance, or 'hostname:port' if it is empty. Env "TAOS_ADAPTER_MONITOR_IDENTITY" + --monitor.incgroup Whether running in cgroup. Env "TAOS_ADAPTER_MONITOR_INCGROUP" + --monitor.pauseAllMemoryThreshold float Memory percentage threshold for pause all. Env "TAOS_ADAPTER_MONITOR_PAUSE_ALL_MEMORY_THRESHOLD" (default 80) + --monitor.pauseQueryMemoryThreshold float Memory percentage threshold for pause query. Env "TAOS_ADAPTER_MONITOR_PAUSE_QUERY_MEMORY_THRESHOLD" (default 70) + --node_exporter.caCertFile string node_exporter ca cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CA_CERT_FILE" + --node_exporter.certFile string node_exporter cert file path. Env "TAOS_ADAPTER_NODE_EXPORTER_CERT_FILE" + --node_exporter.db string node_exporter db name. Env "TAOS_ADAPTER_NODE_EXPORTER_DB" (default "node_exporter") + --node_exporter.enable enable node_exporter. Env "TAOS_ADAPTER_NODE_EXPORTER_ENABLE" + --node_exporter.gatherDuration duration node_exporter gather duration. Env "TAOS_ADAPTER_NODE_EXPORTER_GATHER_DURATION" (default 5s) + --node_exporter.httpBearerTokenString string node_exporter http bearer token. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_BEARER_TOKEN_STRING" + --node_exporter.httpPassword string node_exporter http password. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_PASSWORD" + --node_exporter.httpUsername string node_exporter http username. Env "TAOS_ADAPTER_NODE_EXPORTER_HTTP_USERNAME" + --node_exporter.insecureSkipVerify node_exporter skip ssl check. Env "TAOS_ADAPTER_NODE_EXPORTER_INSECURE_SKIP_VERIFY" (default true) + --node_exporter.keyFile string node_exporter cert key file path. Env "TAOS_ADAPTER_NODE_EXPORTER_KEY_FILE" + --node_exporter.password string node_exporter password. Env "TAOS_ADAPTER_NODE_EXPORTER_PASSWORD" (default "taosdata") + --node_exporter.responseTimeout duration node_exporter response timeout. Env "TAOS_ADAPTER_NODE_EXPORTER_RESPONSE_TIMEOUT" (default 5s) + --node_exporter.ttl int node_exporter data ttl. Env "TAOS_ADAPTER_NODE_EXPORTER_TTL" + --node_exporter.urls strings node_exporter urls. Env "TAOS_ADAPTER_NODE_EXPORTER_URLS" (default [http://localhost:9100]) + --node_exporter.user string node_exporter user. Env "TAOS_ADAPTER_NODE_EXPORTER_USER" (default "root") + --opentsdb.enable enable opentsdb. Env "TAOS_ADAPTER_OPENTSDB_ENABLE" (default true) + --opentsdb_telnet.batchSize int opentsdb_telnet batch size. Env "TAOS_ADAPTER_OPENTSDB_TELNET_BATCH_SIZE" (default 1) + --opentsdb_telnet.dbs strings opentsdb_telnet db names. Env "TAOS_ADAPTER_OPENTSDB_TELNET_DBS" (default [opentsdb_telnet,collectd_tsdb,icinga2_tsdb,tcollector_tsdb]) + --opentsdb_telnet.enable enable opentsdb telnet,warning: without auth info(default false). Env "TAOS_ADAPTER_OPENTSDB_TELNET_ENABLE" + --opentsdb_telnet.flushInterval duration opentsdb_telnet flush interval (0s means not valid) . Env "TAOS_ADAPTER_OPENTSDB_TELNET_FLUSH_INTERVAL" + --opentsdb_telnet.maxTCPConnections int max tcp connections. Env "TAOS_ADAPTER_OPENTSDB_TELNET_MAX_TCP_CONNECTIONS" (default 250) + --opentsdb_telnet.password string opentsdb_telnet password. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PASSWORD" (default "taosdata") + --opentsdb_telnet.ports ints opentsdb telnet tcp port. Env "TAOS_ADAPTER_OPENTSDB_TELNET_PORTS" (default [6046,6047,6048,6049]) + --opentsdb_telnet.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TCP_KEEP_ALIVE" + --opentsdb_telnet.ttl int opentsdb_telnet data ttl. Env "TAOS_ADAPTER_OPENTSDB_TELNET_TTL" + --opentsdb_telnet.user string opentsdb_telnet user. Env "TAOS_ADAPTER_OPENTSDB_TELNET_USER" (default "root") + --pool.idleTimeout duration Set idle connection timeout. Env "TAOS_ADAPTER_POOL_IDLE_TIMEOUT" + --pool.maxConnect int max connections to server. Env "TAOS_ADAPTER_POOL_MAX_CONNECT" + --pool.maxIdle int max idle connections to server. Env "TAOS_ADAPTER_POOL_MAX_IDLE" + --pool.maxWait int max count of waiting for connection. Env "TAOS_ADAPTER_POOL_MAX_WAIT" + --pool.waitTimeout int wait for connection timeout seconds. Env "TAOS_ADAPTER_POOL_WAIT_TIMEOUT" (default 60) + -P, --port int http port. Env "TAOS_ADAPTER_PORT" (default 6041) + --prometheus.enable enable prometheus. Env "TAOS_ADAPTER_PROMETHEUS_ENABLE" (default true) + --restfulRowLimit int restful returns the maximum number of rows (-1 means no limit). Env "TAOS_ADAPTER_RESTFUL_ROW_LIMIT" (default -1) + --smlAutoCreateDB Whether to automatically create db when writing with schemaless. Env "TAOS_ADAPTER_SML_AUTO_CREATE_DB" + --statsd.allowPendingMessages int statsd allow pending messages. Env "TAOS_ADAPTER_STATSD_ALLOW_PENDING_MESSAGES" (default 50000) + --statsd.db string statsd db name. Env "TAOS_ADAPTER_STATSD_DB" (default "statsd") + --statsd.deleteCounters statsd delete counter cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_COUNTERS" (default true) + --statsd.deleteGauges statsd delete gauge cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_GAUGES" (default true) + --statsd.deleteSets statsd delete set cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_SETS" (default true) + --statsd.deleteTimings statsd delete timing cache after gather. Env "TAOS_ADAPTER_STATSD_DELETE_TIMINGS" (default true) + --statsd.enable enable statsd. Env "TAOS_ADAPTER_STATSD_ENABLE" + --statsd.gatherInterval duration statsd gather interval. Env "TAOS_ADAPTER_STATSD_GATHER_INTERVAL" (default 5s) + --statsd.maxTCPConnections int statsd max tcp connections. Env "TAOS_ADAPTER_STATSD_MAX_TCP_CONNECTIONS" (default 250) + --statsd.password string statsd password. Env "TAOS_ADAPTER_STATSD_PASSWORD" (default "taosdata") + --statsd.port int statsd server port. Env "TAOS_ADAPTER_STATSD_PORT" (default 6044) + --statsd.protocol string statsd protocol [tcp or udp]. Env "TAOS_ADAPTER_STATSD_PROTOCOL" (default "udp4") + --statsd.tcpKeepAlive enable tcp keep alive. Env "TAOS_ADAPTER_STATSD_TCP_KEEP_ALIVE" + --statsd.ttl int statsd data ttl. Env "TAOS_ADAPTER_STATSD_TTL" + --statsd.user string statsd user. Env "TAOS_ADAPTER_STATSD_USER" (default "root") + --statsd.worker int statsd write worker. Env "TAOS_ADAPTER_STATSD_WORKER" (default 10) + --taosConfigDir string load taos client config path. Env "TAOS_ADAPTER_TAOS_CONFIG_FILE" + --uploadKeeper.enable Whether to enable sending metrics to keeper. Env "TAOS_ADAPTER_UPLOAD_KEEPER_ENABLE" (default true) + --uploadKeeper.interval duration send to Keeper interval. Env "TAOS_ADAPTER_UPLOAD_KEEPER_INTERVAL" (default 15s) + --uploadKeeper.retryInterval duration retry interval. Env "TAOS_ADAPTER_UPLOAD_KEEPER_RETRY_INTERVAL" (default 5s) + --uploadKeeper.retryTimes uint retry times. Env "TAOS_ADAPTER_UPLOAD_KEEPER_RETRY_TIMES" (default 3) + --uploadKeeper.timeout duration send to Keeper timeout. Env "TAOS_ADAPTER_UPLOAD_KEEPER_TIMEOUT" (default 5s) + --uploadKeeper.url string Keeper url. Env "TAOS_ADAPTER_UPLOAD_KEEPER_URL" (default "http://127.0.0.1:6043/adapter_report") + -V, --version Print the version and exit ``` 备注: @@ -164,6 +170,16 @@ AllowWebSockets 示例配置文件参见 [example/config/taosadapter.toml](https://github.com/taosdata/taosadapter/blob/3.0/example/config/taosadapter.toml)。 +### 连接池参数说明 + +在使用 RESTful 接口请求时,系统将通过连接池管理 TDengine 连接。连接池可通过以下参数进行配置: + +- **`pool.maxConnect`**:连接池允许的最大连接数,默认值为 2 倍 CPU 核心数。建议保持默认设置。 +- **`pool.maxIdle`**:连接池中允许的最大空闲连接数,默认与 `pool.maxConnect` 相同。建议保持默认设置。 +- **`pool.idleTimeout`**:连接空闲超时时间,默认永不超时。建议保持默认设置。 +- **`pool.waitTimeout`**:从连接池获取连接的超时时间,默认设置为 60 秒。如果在超时时间内未能获取连接,将返回 HTTP 状态码 503。该参数从版本 3.3.3.0 开始提供。 +- **`pool.maxWait`**:连接池中等待获取连接的请求数上限,默认值为 0,表示不限制。当排队请求数超过此值时,新的请求将返回 HTTP 状态码 503。该参数从版本 3.3.3.0 开始提供。 + ## 功能列表 - RESTful 接口 From a167815a3a290b059695f1b228d46165641170bb Mon Sep 17 00:00:00 2001 From: Jinqing Kuang Date: Tue, 10 Sep 2024 09:00:31 +0800 Subject: [PATCH 87/90] fix(query)[TD-31955]. Fix memory leak in exceptional scenarios --- source/util/src/tpagedbuf.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 32b9b6e18d..331afe06e5 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -411,7 +411,7 @@ _error: return TSDB_CODE_OUT_OF_MEMORY; } -static char* doExtractPage(SDiskbasedBuf* pBuf, bool* newPage) { +static char* doExtractPage(SDiskbasedBuf* pBuf) { char* availablePage = NULL; if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) { availablePage = evictBufPage(pBuf); @@ -425,7 +425,6 @@ static char* doExtractPage(SDiskbasedBuf* pBuf, bool* newPage) { if (availablePage == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; } - *newPage = true; } return availablePage; @@ -434,8 +433,7 @@ static char* doExtractPage(SDiskbasedBuf* pBuf, bool* newPage) { void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) { pBuf->statis.getPages += 1; - bool newPage = false; - char* availablePage = doExtractPage(pBuf, &newPage); + char* availablePage = doExtractPage(pBuf); if (availablePage == NULL) { return NULL; } @@ -451,9 +449,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) { code = lruListPushFront(pBuf->lruList, pi); if (TSDB_CODE_SUCCESS != code) { taosMemoryFree(pi); - if (newPage) { - taosMemoryFree(availablePage); - } + taosMemoryFree(availablePage); terrno = code; return NULL; } @@ -464,9 +460,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) { // register page id info pi = registerNewPageInfo(pBuf, *pageId); if (pi == NULL) { - if (newPage) { - taosMemoryFree(availablePage); - } + taosMemoryFree(availablePage); return NULL; } @@ -480,7 +474,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) { if (TSDB_CODE_SUCCESS == code) { pBuf->totalBufSize += pBuf->pageSize; } else { - if (newPage) taosMemoryFree(availablePage); + taosMemoryFree(availablePage); (void)taosArrayPop(pBuf->pIdList); (void)tSimpleHashRemove(pBuf->all, pageId, sizeof(int32_t)); taosMemoryFree(pi); @@ -538,8 +532,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { return (void*)(GET_PAYLOAD_DATA(*pi)); } else { // not in memory - bool newPage = false; - (*pi)->pData = doExtractPage(pBuf, &newPage); + (*pi)->pData = doExtractPage(pBuf); // failed to evict buffer page, return with error code. if ((*pi)->pData == NULL) { @@ -551,7 +544,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { int32_t code = lruListPushFront(pBuf->lruList, *pi); if (TSDB_CODE_SUCCESS != code) { - if (newPage) taosMemoryFree((*pi)->pData); + taosMemoryFree((*pi)->pData); terrno = code; return NULL; } @@ -561,9 +554,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { if (HAS_DATA_IN_DISK(*pi)) { int32_t code = loadPageFromDisk(pBuf, *pi); if (code != 0) { - if (newPage) { - taosMemoryFree((*pi)->pData); - } + taosMemoryFree((*pi)->pData); terrno = code; return NULL; From 55efe1b92b2656c123b58a07bb0969f6f303d61a Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 12 Sep 2024 10:34:32 +0000 Subject: [PATCH 88/90] fix/restore-2-replica --- source/dnode/mnode/impl/inc/mndVgroup.h | 4 +-- source/dnode/mnode/impl/src/mndVgroup.c | 33 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index 444c16083c..682a51a687 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -55,8 +55,8 @@ void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *p void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid); bool mndVgroupInDnode(SVgObj *pVgroup, int32_t dnodeId); -int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup, - SDnodeObj *pDnode); +int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup, SDnodeObj *pDnode, + SDnodeObj *pAnotherDnode); int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 2483c7f0d1..dd1af7ef90 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -2847,8 +2847,8 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO TAOS_RETURN(code); } -int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup, - SDnodeObj *pDnode) { +int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup, SDnodeObj *pDnode, + SDnodeObj *pAnotherDnode) { int32_t code = 0; SVgObj newVgroup = {0}; memcpy(&newVgroup, pVgroup, sizeof(SVgObj)); @@ -2864,7 +2864,33 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj } } TAOS_CHECK_RETURN(mndAddCreateVnodeAction(pMnode, pTrans, db, &newVgroup, &newVgroup.vnodeGid[selected])); - } else if (newVgroup.replica == 2 || newVgroup.replica == 3) { + } else if (newVgroup.replica == 2) { + for (int i = 0; i < newVgroup.replica; i++) { + if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) { + newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_LEARNER; + } else { + newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER; + } + } + TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pAnotherDnode)); + + for (int i = 0; i < newVgroup.replica; i++) { + if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) { + newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_LEARNER; + } else { + newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER; + } + } + TAOS_CHECK_RETURN(mndRestoreAddCreateVnodeAction(pMnode, pTrans, db, &newVgroup, pDnode)); + + for (int i = 0; i < newVgroup.replica; i++) { + newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER; + if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) { + } + } + TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pDnode)); + TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pDnode)); + } else if (newVgroup.replica == 3) { for (int i = 0; i < newVgroup.replica; i++) { if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) { newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_LEARNER; @@ -2881,7 +2907,6 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj } TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pDnode)); } - SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup); if (pVgRaw == NULL) { code = TSDB_CODE_MND_RETURN_VALUE_NULL; From 6202f13feefd666bfdc4d5341ca6755fc3f089f2 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 12 Sep 2024 11:37:48 +0000 Subject: [PATCH 89/90] fix/restore-2-replica --- source/dnode/mnode/impl/src/mndVgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index dd1af7ef90..c9ce57c204 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -2889,7 +2889,7 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj } } TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pDnode)); - TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pDnode)); + TAOS_CHECK_RETURN(mndRestoreAddAlterVnodeTypeAction(pMnode, pTrans, db, &newVgroup, pAnotherDnode)); } else if (newVgroup.replica == 3) { for (int i = 0; i < newVgroup.replica; i++) { if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) { From 7b4116b28e0bd0efc1a035db376d610d7bdf7c46 Mon Sep 17 00:00:00 2001 From: Jinqing Kuang Date: Wed, 11 Sep 2024 18:08:39 +0800 Subject: [PATCH 90/90] fix(query)[TD-32027]. Fix null pointer access in exceptional cases --- source/dnode/vnode/src/tsdb/tsdbRead2.c | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 8f66df1ffb..29871c1089 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -4035,26 +4035,30 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArra return code; } -static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowIndex, SRowKey* pKey, SRowMerger* pMerger, +static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t* rowIndex, SRowKey* pKey, SRowMerger* pMerger, SVersionRange* pVerRange, int32_t step) { - while (rowIndex < pBlockData->nRow && rowIndex >= 0) { + int32_t code = 0; + while ((*rowIndex) < pBlockData->nRow && (*rowIndex) >= 0) { SRowKey cur; - tColRowGetKey(pBlockData, rowIndex, &cur); + tColRowGetKey(pBlockData, (*rowIndex), &cur); if (pkCompEx(&cur, pKey) != 0) { break; } - if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) { - rowIndex += step; + if (pBlockData->aVersion[(*rowIndex)] > pVerRange->maxVer || + pBlockData->aVersion[(*rowIndex)] < pVerRange->minVer) { + (*rowIndex) += step; continue; } - TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex); - int32_t code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - rowIndex += step; + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, (*rowIndex)); + code = tsdbRowMergerAdd(pMerger, &fRow, NULL); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + (*rowIndex) += step; } - - return rowIndex; + return code; } typedef enum { @@ -4076,7 +4080,10 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn *state = CHECK_FILEBLOCK_QUIT; if (loadNeighbor && (code == TSDB_CODE_SUCCESS)) { - pDumpInfo->rowIndex = doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, pKey, pMerger, pVerRange, step); + code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pVerRange, step); + if (code != TSDB_CODE_SUCCESS) { + return code; + } if ((pDumpInfo->rowIndex >= pDumpInfo->totalRows && asc) || (pDumpInfo->rowIndex < 0 && !asc)) { *state = CHECK_FILEBLOCK_CONT; } @@ -4096,7 +4103,10 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc pDumpInfo->rowIndex += step; if ((pDumpInfo->rowIndex <= pBlockData->nRow - 1 && asc) || (pDumpInfo->rowIndex >= 0 && !asc)) { - pDumpInfo->rowIndex = doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, pKey, pMerger, pRange, step); + code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pRange, step); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } // all rows are consumed, let's try next file block