From 7fceb5a7092a980e09063ebcd321954ab1b1323e Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 2 Jun 2022 10:22:34 +0800 Subject: [PATCH] other: code optimization and do more check --- include/common/taosdef.h | 1 + include/common/tdataformat.h | 3 ++- source/common/src/tdataformat.c | 22 +++++++++++++++++++--- source/dnode/vnode/src/meta/metaEntry.c | 2 ++ source/libs/executor/src/scanoperator.c | 4 ++-- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index d39c7a1215..516df71b0b 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -97,6 +97,7 @@ extern char *qtypeStr[]; #undef TD_DEBUG_PRINT_ROW #undef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS +#undef TD_DEBUG_PRINT_TAG #ifdef __cplusplus } diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 867115d16d..10bc6a6176 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -70,7 +70,8 @@ char* tTagValToData(const STagVal *pTagVal, bool isJson); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag); int32_t tTagToValArray(const STag *pTag, SArray **ppArray); -void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); +void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove +void debugCheckTags(STag *pTag); // TODO: remove // STRUCT ================= struct STColumn { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 77fc156492..636eeb6d61 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -1008,6 +1008,21 @@ void debugPrintSTag(STag *pTag, const char *tag, int32_t ln) { printf("\n"); } +void debugCheckTags(STag *pTag) { + switch (pTag->flags) { + case 0x0: + case 0x20: + case 0x40: + case 0x60: + break; + default: + ASSERT(0); + } + + ASSERT(pTag->nTag <= 128 && pTag->nTag >= 0); + ASSERT(pTag->ver <= 512 && pTag->ver >= 0); // temp condition for pTag->ver +} + static int32_t tPutTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) { int32_t n = 0; @@ -1114,9 +1129,11 @@ int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) { } n += tPutTagVal(p + n, (STagVal *)taosArrayGet(pArray, iTag), isJson); } - +#ifdef TD_DEBUG_PRINT_TAG debugPrintSTag(*ppTag, __func__, __LINE__); +#endif + debugCheckTags(*ppTag); // TODO: remove this line after debug return code; _err: @@ -1199,8 +1216,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) { } int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) { - uint32_t len = 0; - return tDecodeBinary(pDecoder, (uint8_t **)ppTag, &len); + return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL); } int32_t tTagToValArray(const STag *pTag, SArray **ppArray) { diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c index a003494457..db99257ea7 100644 --- a/source/dnode/vnode/src/meta/metaEntry.c +++ b/source/dnode/vnode/src/meta/metaEntry.c @@ -30,6 +30,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) { if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1; if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1; + debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1; } else if (pME->type == TSDB_NORMAL_TABLE) { if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1; @@ -62,6 +63,7 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1; if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1; if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO) + debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug } else if (pME->type == TSDB_NORMAL_TABLE) { if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index c5d19981cf..0e682682a1 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -327,8 +327,8 @@ void addTagPseudoColumnData(SReadHandle *pHandle, SExprInfo* pPseudoExpr, int32_ for (int32_t i = 0; i < pBlock->info.rows; ++i) { colDataAppend(pColInfoData, i, data, (data == NULL)); } - if(pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL && - IS_VAR_DATA_TYPE(((const STagVal *)p)->type) && data){ + if (data && (pColInfoData->info.type != TSDB_DATA_TYPE_JSON) && p != NULL && + IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) { taosMemoryFree(data); } }