From e91014f807b6f2981ee6d9cc43985fdf1912b953 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Tue, 25 Feb 2025 18:21:32 +0800 Subject: [PATCH 1/8] feat: show variables like --- include/common/tcommon.h | 2 +- include/common/tmsg.h | 7 ++-- include/util/tcompare.h | 1 + source/client/src/clientMsgHandler.c | 40 +++++++++++---------- source/common/src/msg/tmsg.c | 32 ++++++++++++++++- source/common/src/tmisce.c | 6 +++- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 2 +- source/dnode/mnode/impl/src/mndConfig.c | 21 ++++++++--- source/libs/command/src/command.c | 28 ++++++++++----- source/libs/parser/inc/parAst.h | 1 + source/libs/parser/inc/sql.y | 6 ++-- source/libs/parser/src/parAstCreater.c | 16 +++++++++ source/libs/parser/src/parTranslater.c | 7 ++++ source/util/src/tcompare.c | 13 +++++++ 14 files changed, 141 insertions(+), 41 deletions(-) diff --git a/include/common/tcommon.h b/include/common/tcommon.h index bd5bdb927d..dae9eab31e 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -414,7 +414,7 @@ typedef struct STUidTagInfo { #define NOTIFY_EVENT_STR_COLUMN_INDEX 0 int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime); -int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol); +int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol, char* likePattern); #define TSMA_RES_STB_POSTFIX "_tsma_res_stb_" #define MD5_OUTPUT_LEN 32 diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 6d58748a3b..305e6f02ed 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2247,11 +2247,14 @@ typedef struct { } STagData; typedef struct { - int32_t useless; // useless + int32_t opType; + uint32_t valLen; + char* val; } SShowVariablesReq; int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); -// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); +int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); +void tFreeSShowVariablesReq(SShowVariablesReq* pReq); typedef struct { char name[TSDB_CONFIG_OPTION_LEN + 1]; diff --git a/include/util/tcompare.h b/include/util/tcompare.h index c7a29cad57..09b35bbc8c 100644 --- a/include/util/tcompare.h +++ b/include/util/tcompare.h @@ -47,6 +47,7 @@ typedef struct SPatternCompareInfo { int32_t InitRegexCache(); void DestroyRegexCache(); +int32_t rawStrPatternMatch(const char *pattern, const char *str); int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo); int32_t checkRegexPattern(const char *pPattern); void DestoryThreadLocalRegComp(); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 58ba39864d..d3a0aaca18 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -628,26 +628,30 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) { (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS); - int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, SHOW_VARIABLES_RESULT_COLS); - if (len < 0) { - uError("buildShowVariablesRsp error, len:%d", len); - code = terrno; - goto _exit; + int32_t len = 0; + if ((*pRsp)->numOfRows > 0) { + len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, SHOW_VARIABLES_RESULT_COLS); + if (len < 0) { + uError("buildShowVariablesRsp error, len:%d", len); + code = terrno; + goto _exit; + } + SET_PAYLOAD_LEN((*pRsp)->data, len, len); + + int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; + (*pRsp)->payloadLen = htonl(payloadLen); + (*pRsp)->compLen = htonl(payloadLen); + + if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) { + uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len, + (uint64_t)(rspSize - sizeof(SRetrieveTableRsp))); + code = TSDB_CODE_TSC_INVALID_INPUT; + goto _exit; + } } + blockDataDestroy(pBlock); - - SET_PAYLOAD_LEN((*pRsp)->data, len, len); - - int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; - (*pRsp)->payloadLen = htonl(payloadLen); - (*pRsp)->compLen = htonl(payloadLen); - - if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) { - uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len, - (uint64_t)(rspSize - sizeof(SRetrieveTableRsp))); - code = TSDB_CODE_TSC_INVALID_INPUT; - goto _exit; - } + pBlock = NULL; return TSDB_CODE_SUCCESS; _exit: diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index 6a3e1948c8..ea7d332344 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -5807,7 +5807,11 @@ int32_t tSerializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq tEncoderInit(&encoder, buf, bufLen); TAOS_CHECK_EXIT(tStartEncode(&encoder)); - TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->useless)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->opType)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->valLen)); + if (pReq->valLen > 0) { + TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->val, pReq->valLen)); + } tEndEncode(&encoder); _exit: @@ -5820,6 +5824,32 @@ _exit: return tlen; } +int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) { + SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); + + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->opType)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pReq->valLen)); + if (pReq->valLen > 0) { + TAOS_CHECK_EXIT(tDecodeBinary(&decoder, (uint8_t **)&pReq->val, &pReq->valLen)); + } + + tEndDecode(&decoder); +_exit: + tDecoderClear(&decoder); + return code; +} + +void tFreeSShowVariablesReq(SShowVariablesReq *pReq) { + if (NULL != pReq && NULL != pReq->val) { + taosMemoryFree(pReq->val); + pReq->val = NULL; + } +} + int32_t tEncodeSVariablesInfo(SEncoder *pEncoder, SVariablesInfo *pInfo) { TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->name)); TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->value)); diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index a966513629..fbe3cba4c4 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -18,6 +18,7 @@ #include "tglobal.h" #include "tjson.h" #include "tmisce.h" +#include "tcompare.h" int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) { pEp->port = 0; @@ -257,7 +258,7 @@ _exit: TAOS_RETURN(code); } -int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { +int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol, char* likePattern) { int32_t code = 0; SConfig* pConf = taosGetCfg(); if (pConf == NULL) { @@ -291,6 +292,9 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { // GRANT_CFG_SKIP; char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; + if (likePattern && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) { + continue; + } STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 0a3543ac07..0bf18525fa 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -660,7 +660,7 @@ _exit: } int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) { - int32_t code = dumpConfToDataBlock(pBlock, 1); + int32_t code = dumpConfToDataBlock(pBlock, 1, NULL); if (code != 0) { return code; } diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 099fff7aee..844cd74b6a 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -23,6 +23,7 @@ #include "mndTrans.h" #include "mndUser.h" #include "tutil.h" +#include "tcompare.h" #define CFG_VER_NUMBER 1 #define CFG_RESERVE_SIZE 63 @@ -807,7 +808,7 @@ static void cfgObjArrayCleanUp(SArray *array) { taosArrayDestroy(array); } -SArray *initVariablesFromItems(SArray *pItems) { +static SArray *initVariablesFromItems(SArray *pItems, const char* likePattern) { if (pItems == NULL) { return NULL; } @@ -823,6 +824,9 @@ SArray *initVariablesFromItems(SArray *pItems) { SConfigItem *pItem = taosArrayGet(pItems, i); SVariablesInfo info = {0}; tstrncpy(info.name, pItem->name, sizeof(info.name)); + if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) { + continue; + } // init info value switch (pItem->dtype) { @@ -889,15 +893,23 @@ SArray *initVariablesFromItems(SArray *pItems) { static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { SShowVariablesRsp rsp = {0}; - int32_t code = -1; + int32_t code = TSDB_CODE_SUCCESS; + SShowVariablesReq req = {0}; + SArray *array = NULL; + + code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req); + if (code != 0) { + mError("failed to deserialize config req, since %s", terrstr()); + goto _OVER; + } if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) { goto _OVER; } SVariablesInfo info = {0}; - - rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg)); + char *likePattern = req.opType == OP_TYPE_LIKE ? req.val : NULL; + rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg), likePattern); if (rsp.variables == NULL) { code = terrno; goto _OVER; @@ -924,7 +936,6 @@ _OVER: if (code != 0) { mError("failed to get show variables info since %s", tstrerror(code)); } - tFreeSShowVariablesRsp(&rsp); TAOS_RETURN(code); } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index e0a917ace9..243f85ff47 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -20,6 +20,7 @@ #include "systable.h" #include "taosdef.h" #include "tdatablock.h" +#include "tdataformat.h" #include "tglobal.h" #include "tgrant.h" @@ -53,13 +54,16 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfCols = htonl(numOfCols); - int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); - if (len < 0) { - taosMemoryFree(*pRsp); - *pRsp = NULL; - return terrno; + int32_t len = 0; + if ((*pRsp)->numOfRows > 0) { + len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); + if (len < 0) { + taosMemoryFree(*pRsp); + *pRsp = NULL; + return terrno; + } + SET_PAYLOAD_LEN((*pRsp)->data, len, len); } - SET_PAYLOAD_LEN((*pRsp)->data, len, len); int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; (*pRsp)->payloadLen = htonl(payloadLen); @@ -985,11 +989,17 @@ _exit: return terrno; } -static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { +static int32_t execShowLocalVariables(SShowStmt* pStmt, SRetrieveTableRsp** pRsp) { SSDataBlock* pBlock = NULL; + char* likePattern = NULL; int32_t code = buildLocalVariablesResultDataBlock(&pBlock); if (TSDB_CODE_SUCCESS == code) { - code = dumpConfToDataBlock(pBlock, 0); + if (pStmt->tableCondType == OP_TYPE_LIKE) { + likePattern = ((SValueNode*)pStmt->pTbName)->literal; + } + } + if (TSDB_CODE_SUCCESS == code) { + code = dumpConfToDataBlock(pBlock, 0, likePattern); } if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp); @@ -1091,7 +1101,7 @@ int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieve case QUERY_NODE_ALTER_LOCAL_STMT: return execAlterLocal((SAlterLocalStmt*)pStmt); case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: - return execShowLocalVariables(pRsp); + return execShowLocalVariables((SShowStmt*)pStmt, pRsp); case QUERY_NODE_SELECT_STMT: return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp); default: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 65274f85e1..7d102d85fb 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -241,6 +241,7 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type); SNode* createShowStmtWithFull(SAstCreateContext* pCxt, ENodeType type); +SNode* createShowStmtWithLike(SAstCreateContext* pCxt, ENodeType type, SNode* pLikePattern); SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, EOperatorType tableCondType); SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName, diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 42d2e95d24..ef2d57f1d6 100755 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -593,9 +593,9 @@ cmd ::= SHOW ENCRYPTIONS. cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } -cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } -cmd ::= SHOW CLUSTER VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } -cmd ::= SHOW LOCAL VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } +cmd ::= SHOW VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT, B); } +cmd ::= SHOW CLUSTER VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT, B); } +cmd ::= SHOW LOCAL VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT, B); } cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A), B); } cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 341fc7e603..bd93dc2fea 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2747,6 +2747,22 @@ static bool needDbShowStmt(ENodeType type) { QUERY_NODE_SHOW_VIEWS_STMT == type || QUERY_NODE_SHOW_TSMAS_STMT == type || QUERY_NODE_SHOW_USAGE_STMT == type; } +SNode* createShowStmtWithLike(SAstCreateContext* pCxt, ENodeType type, SNode* pLikePattern) { + CHECK_PARSER_STATUS(pCxt); + SShowStmt* pStmt = NULL; + pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt); + CHECK_MAKE_NODE(pStmt); + pStmt->withFull = false; + pStmt->pTbName = pLikePattern; + if (pLikePattern) { + pStmt->tableCondType = OP_TYPE_LIKE; + } + return (SNode*)pStmt; +_err: + nodesDestroyNode(pLikePattern); + return NULL; +} + SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) { CHECK_PARSER_STATUS(pCxt); SShowStmt* pStmt = NULL; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 2fdba9bad9..0815b443a7 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -13244,6 +13244,13 @@ static int32_t translateSplitVgroup(STranslateContext* pCxt, SSplitVgroupStmt* p static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) { SShowVariablesReq req = {0}; + req.opType = pStmt->tableCondType; + if (req.opType == OP_TYPE_LIKE && pStmt->pTbName) { + req.valLen = strlen(((SValueNode*)pStmt->pTbName)->literal); + if (req.valLen > 0) { + req.val = taosStrdupi(((SValueNode*)pStmt->pTbName)->literal); + } + } return buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req); } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index c95030b06e..a253c58415 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1123,6 +1123,19 @@ int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t return (j >= ssize || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; } +int32_t rawStrPatternMatch(const char *str, const char *pattern) { + SPatternCompareInfo pInfo = PATTERN_COMPARE_INFO_INITIALIZER; + + size_t pLen = strlen(pattern); + size_t sz = strlen(str); + if (pLen > TSDB_MAX_FIELD_LEN) { + return 1; + } + + int32_t ret = patternMatch(pattern, pLen, str, sz, &pInfo); + return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; +} + int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize, const SPatternCompareInfo *pInfo) { TdUcs4 c, c1; From 36bec2c9585fc016d95e7bb9b963dbc0db23ebd4 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Tue, 25 Feb 2025 23:18:13 +0800 Subject: [PATCH 2/8] fix: rows --- source/libs/command/src/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 243f85ff47..1458164e28 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -55,7 +55,7 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe (*pRsp)->numOfCols = htonl(numOfCols); int32_t len = 0; - if ((*pRsp)->numOfRows > 0) { + if (pBlock->info.rows > 0) { len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); if (len < 0) { taosMemoryFree(*pRsp); From 6da2e6f54722a0386d7a60b4c66c43cd5890cec2 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Sun, 2 Mar 2025 22:45:58 +0800 Subject: [PATCH 3/8] fix: test case --- source/common/src/msg/tmsg.c | 7 ++- source/dnode/mnode/impl/src/mndConfig.c | 1 + source/libs/parser/src/parTranslater.c | 4 +- tests/system-test/2-query/db.py | 60 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index ea7d332344..85a5c8dbeb 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -5833,8 +5833,13 @@ int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesR TAOS_CHECK_EXIT(tStartDecode(&decoder)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->opType)); TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pReq->valLen)); + if (pReq->valLen > 0) { - TAOS_CHECK_EXIT(tDecodeBinary(&decoder, (uint8_t **)&pReq->val, &pReq->valLen)); + pReq->val = taosMemoryCalloc(1, pReq->valLen + 1); + if (pReq->val == NULL) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->val)); } tEndDecode(&decoder); diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 844cd74b6a..16d1bb5a5f 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -936,6 +936,7 @@ _OVER: if (code != 0) { mError("failed to get show variables info since %s", tstrerror(code)); } + tFreeSShowVariablesReq(&req); tFreeSShowVariablesRsp(&rsp); TAOS_RETURN(code); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 0815b443a7..edbf724a75 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -13251,7 +13251,9 @@ static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) req.val = taosStrdupi(((SValueNode*)pStmt->pTbName)->literal); } } - return buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req); + int32_t code = buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req); + tFreeSShowVariablesReq(&req); + return code; } static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) { diff --git a/tests/system-test/2-query/db.py b/tests/system-test/2-query/db.py index f380fdf00b..3408f02e8b 100644 --- a/tests/system-test/2-query/db.py +++ b/tests/system-test/2-query/db.py @@ -85,7 +85,59 @@ class TDTestCase: tdSql.checkData(0, 0, 1) tdSql.checkData(0, 1, 's3UploadDelaySec') tdSql.checkData(0, 2, 60) + + def show_local_variables_like(self): + tdSql.query("show local variables") + tdSql.checkRows(85) + tdSql.query("show local variables like 'debugFlag'") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'debugFlag') + tdSql.checkData(0, 1, 0) + + tdSql.query("show local variables like '%debugFlag'") + tdSql.checkRows(9) + + tdSql.query("show local variables like '____debugFlag'") + tdSql.checkRows(0) + + tdSql.query("show local variables like 's3MigrateEnab%'") + tdSql.checkRows(0) + + tdSql.query("show local variables like 'mini%'") + tdSql.checkRows(3) + tdSql.checkData(0, 0, 'minimalTmpDirGB') + + tdSql.query("show local variables like '%info'") + tdSql.checkRows(2) + + def show_cluster_variables_like(self): + zones = ["", "cluster"] + for zone in zones: + tdLog.info(f"show {zone} variables") + tdSql.query(f"show {zone} variables") + tdSql.checkRows(87) + + tdLog.info(f"show {zone} variables like 'debugFlag'") + #tdSql.query(f"show {zone} variables like 'debugFlag'") + #tdSql.checkRows(0) + + tdSql.query(f"show {zone} variables like 's3%'") + tdSql.checkRows(6) + + tdSql.query(f"show {zone} variables like 'Max%'") + tdSql.checkRows(3) + + tdSql.query(f"show {zone} variables like 'ttl%'") + tdSql.checkRows(5) + + tdSql.query(f"show {zone} variables like 'ttl34343434%'") + tdSql.checkRows(0) + + tdSql.query(f"show {zone} variables like 'jdlkfdjdfkdfnldlfdnfkdkfdmfdlfmnnnnnjkjk'") + tdSql.checkRows(0) + + def threadTest(self, threadID): print(f"Thread {threadID} starting...") tdsqln = tdCom.newTdSql() @@ -127,6 +179,14 @@ class TDTestCase: tdLog.printNoPrefix("==========start case3 run ...............") self.case3() tdLog.printNoPrefix("==========end case3 run ...............") + + tdLog.printNoPrefix("==========start show_local_variables_like run ...............") + self.show_local_variables_like() + tdLog.printNoPrefix("==========end show_local_variables_like run ...............") + + tdLog.printNoPrefix("==========start show_cluster_variables_like run ...............") + self.show_cluster_variables_like() + tdLog.printNoPrefix("==========end show_cluster_variables_like run ...............") def stop(self): tdSql.close() From 2e64d8578e2889523f5e24c8bafdde10e027f849 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Thu, 6 Mar 2025 15:59:58 +0800 Subject: [PATCH 4/8] feat: doc desc --- docs/en/14-reference/03-taos-sql/24-show.md | 9 +++++---- docs/zh/14-reference/03-taos-sql/24-show.md | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/en/14-reference/03-taos-sql/24-show.md b/docs/en/14-reference/03-taos-sql/24-show.md index b46fb41fa0..589caab39d 100644 --- a/docs/en/14-reference/03-taos-sql/24-show.md +++ b/docs/en/14-reference/03-taos-sql/24-show.md @@ -127,10 +127,11 @@ Displays created indexes. ## SHOW LOCAL VARIABLES ```sql -SHOW LOCAL VARIABLES; +SHOW LOCAL VARIABLES [like pattern]; ``` Displays the runtime values of configuration parameters for the current client. +You can use the like pattern to filter by name. ## SHOW MNODES @@ -320,11 +321,11 @@ Displays information about all users in the current system, including user-defin ## SHOW CLUSTER VARIABLES (before version 3.0.1.6 it was SHOW VARIABLES) ```sql -SHOW CLUSTER VARIABLES; -SHOW DNODE dnode_id VARIABLES; +SHOW CLUSTER VARIABLES [like pattern]; +SHOW DNODE dnode_id VARIABLES [like pattern]; ``` -Displays the runtime values of configuration parameters that need to be the same across nodes in the current system, or you can specify a DNODE to view its configuration parameters. +Displays the runtime values of configuration parameters that need to be the same across nodes in the current system, or you can specify a DNODE to view its configuration parameters. And you can use the like pattern to filter by name. ## SHOW VGROUPS diff --git a/docs/zh/14-reference/03-taos-sql/24-show.md b/docs/zh/14-reference/03-taos-sql/24-show.md index 3898920e65..622cc544b2 100644 --- a/docs/zh/14-reference/03-taos-sql/24-show.md +++ b/docs/zh/14-reference/03-taos-sql/24-show.md @@ -128,10 +128,10 @@ SHOW INDEXES FROM [db_name.]tbl_name; ## SHOW LOCAL VARIABLES ```sql -SHOW LOCAL VARIABLES; +SHOW LOCAL VARIABLES [like pattern]; ``` -显示当前客户端配置参数的运行值。 +显示当前客户端配置参数的运行值,可使用 like pattern 根据 name 进行过滤。 ## SHOW MNODES @@ -322,11 +322,12 @@ SHOW USERS; ## SHOW CLUSTER VARIABLES(3.0.1.6 之前为 SHOW VARIABLES) ```sql -SHOW CLUSTER VARIABLES; -SHOW DNODE dnode_id VARIABLES; +SHOW CLUSTER VARIABLES [like pattern];; +SHOW DNODE dnode_id VARIABLES [like pattern];; ``` 显示当前系统中各节点需要相同的配置参数的运行值,也可以指定 DNODE 来查看其的配置参数。 +可使用 like pattern 根据 name 进行过滤。 ## SHOW VGROUPS From 22be5e642e9aa7d9d558455fd7d4a649fc837086 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 6 Mar 2025 17:52:15 +0800 Subject: [PATCH 5/8] feat: TS-5927-fix-review --- source/common/src/msg/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index bda197e93d..d4989bb27d 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -627,7 +627,7 @@ int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchR if (!tDecodeIsEnd(&decoder)) { TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pBatchRsp->enableStrongPass)); } else { - pBatchRsp->enableStrongPass = 1; + pBatchRsp->enableStrongPass = 0; } tEndDecode(&decoder); From f6ac51b184f67a5271fc039e87210a617781a54f Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 6 Mar 2025 19:19:02 +0800 Subject: [PATCH 6/8] feat: TS-5927-add-doc --- docs/en/14-reference/01-components/01-taosd.md | 1 + docs/zh/14-reference/01-components/01-taosd.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docs/en/14-reference/01-components/01-taosd.md b/docs/en/14-reference/01-components/01-taosd.md index b3230fac32..4527a7fcac 100644 --- a/docs/en/14-reference/01-components/01-taosd.md +++ b/docs/en/14-reference/01-components/01-taosd.md @@ -231,6 +231,7 @@ The effective value of charset is UTF-8. |udf | |Supported, effective after restart|Whether to start UDF service; 0: do not start, 1: start; default value 0 | |udfdResFuncs | |Supported, effective after restart|Internal parameter, for setting UDF result sets| |udfdLdLibPath | |Supported, effective after restart|Internal parameter, indicates the library path for loading UDF| +|enableStrongPassword | After 3.3.5.0 |Supported, effective after restart|The password include at least three types of characters from the following: uppercase letters, lowercase letters, numbers, and special characters, special characters include `! @ # $ % ^ & * ( ) - _ + = [ ] { } : ; > < ? \| ~ , .`; 0: disable, 1: enable; default value 1 | ### Stream Computing Parameters diff --git a/docs/zh/14-reference/01-components/01-taosd.md b/docs/zh/14-reference/01-components/01-taosd.md index 5ae2640541..2216cab915 100644 --- a/docs/zh/14-reference/01-components/01-taosd.md +++ b/docs/zh/14-reference/01-components/01-taosd.md @@ -1017,6 +1017,13 @@ charset 的有效值是 UTF-8。 - 动态修改:支持通过 SQL 修改,重启生效 - 支持版本:v3.1.0.0 引入 +#### enableStrongPassword +- 说明:密码要符合一个要求:至少包含大写字母、小写字母、数字、特殊字符中的三类。特殊字符包括 `! @ # $ % ^ & * ( ) - _ + = [ ] { } : ; > < ? | ~ , .` +- 类型:整数;0:不启用,1:启用 +- 默认值:1 +- 动态修改:支持通过 SQL 修改,重启生效 +- 支持版本:v3.3.5.0 引入 + ### 流计算参数 #### disableStream From c27662cf09a5b6c35aa58182fb921e0e9333f879 Mon Sep 17 00:00:00 2001 From: facetosea <285808407@qq.com> Date: Fri, 7 Mar 2025 09:51:05 +0800 Subject: [PATCH 7/8] fix: show variables rows check --- tests/pytest/util/sql.py | 11 +++++++++++ tests/system-test/2-query/db.py | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 3c79c22bee..fca3eb70e5 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -704,6 +704,17 @@ class TDSql: tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm)) return True self.print_error_frame_info(elm, expect_elm) + + def checkGreater(self, elm, expect_elm): + if elm > expect_elm: + tdLog.info("sql:%s, elm:%s > expect_elm:%s" % (self.sql, elm, expect_elm)) + return True + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, self.sql, elm, expect_elm) + tdLog.info("%s(%d) failed: sql:%s, elm:%s <= expect_elm:%s" % args) + self.print_error_frame_info(elm, expect_elm) + return False def checkNotEqual(self, elm, expect_elm): if elm != expect_elm: diff --git a/tests/system-test/2-query/db.py b/tests/system-test/2-query/db.py index 3408f02e8b..2a63249bcc 100644 --- a/tests/system-test/2-query/db.py +++ b/tests/system-test/2-query/db.py @@ -46,8 +46,8 @@ class TDTestCase: tdSql.checkRows(2) def case2(self): - tdSql.query("show variables") - tdSql.checkRows(87) + tdSql.query("show variables") + tdSql.checkGreater(tdSql.getRows(), 80) for i in range(self.replicaVar): tdSql.query("show dnode %d variables like 'debugFlag'" % (i + 1)) @@ -88,7 +88,7 @@ class TDTestCase: def show_local_variables_like(self): tdSql.query("show local variables") - tdSql.checkRows(85) + tdSql.checkGreater(tdSql.getRows(), 80) tdSql.query("show local variables like 'debugFlag'") tdSql.checkRows(1) @@ -116,7 +116,7 @@ class TDTestCase: for zone in zones: tdLog.info(f"show {zone} variables") tdSql.query(f"show {zone} variables") - tdSql.checkRows(87) + tdSql.checkGreater(tdSql.getRows(), 80) tdLog.info(f"show {zone} variables like 'debugFlag'") #tdSql.query(f"show {zone} variables like 'debugFlag'") From 609ff730c46b0b1ab1e6c632fd2f11d1aeaff7a7 Mon Sep 17 00:00:00 2001 From: Simon Guan Date: Fri, 7 Mar 2025 10:03:43 +0800 Subject: [PATCH 8/8] refactor: jemalloc options --- README-CN.md | 168 +++++++++++++++---------------- cmake/cmake.define | 7 +- source/dnode/mgmt/CMakeLists.txt | 24 ++--- source/os/CMakeLists.txt | 47 +++++---- tools/shell/CMakeLists.txt | 18 ++-- 5 files changed, 129 insertions(+), 135 deletions(-) diff --git a/README-CN.md b/README-CN.md index ad622b3896..8c78bb14ee 100644 --- a/README-CN.md +++ b/README-CN.md @@ -8,30 +8,30 @@

-简体中文 | [English](README.md) | [TDengine 云服务](https://cloud.taosdata.com/?utm_medium=cn&utm_source=github) | 很多职位正在热招中,请看[这里](https://www.taosdata.com/careers/) +简体中文 | [English](README.md) | [TDengine 云服务](https://cloud.taosdata.com/?utm_medium=cn&utm_source=github) | 很多职位正在热招中,请看 [这里](https://www.taosdata.com/careers/) # 目录 1. [TDengine 简介](#1-tdengine-简介) 1. [文档](#2-文档) 1. [必备工具](#3-必备工具) - - [3.1 Linux预备](#31-linux系统) - - [3.2 macOS预备](#32-macos系统) - - [3.3 Windows预备](#33-windows系统) + - [3.1 Linux 预备](#31-Linux系统) + - [3.2 macOS 预备](#32-macOS系统) + - [3.3 Windows 预备](#3.3-Windows系统) - [3.4 克隆仓库](#34-克隆仓库) 1. [构建](#4-构建) - - [4.1 Linux系统上构建](#41-linux系统上构建) - - [4.2 macOS系统上构建](#42-macos系统上构建) - - [4.3 Windows系统上构建](#43-windows系统上构建) + - [4.1 Linux 系统上构建](#41-Linux系统上构建) + - [4.2 macOS 系统上构建](#42-macOS系统上构建) + - [4.3 Windows 系统上构建](#43-Windows系统上构建) 1. [打包](#5-打包) 1. [安装](#6-安装) - - [6.1 Linux系统上安装](#61-linux系统上安装) - - [6.2 macOS系统上安装](#62-macos系统上安装) - - [6.3 Windows系统上安装](#63-windows系统上安装) + - [6.1 Linux 系统上安装](#61-Linux系统上安装) + - [6.2 macOS 系统上安装](#62-macOS系统上安装) + - [6.3 Windows 系统上安装](#63-Windows系统上安装) 1. [快速运行](#7-快速运行) - - [7.1 Linux系统上运行](#71-linux系统上运行) - - [7.2 macOS系统上运行](#72-macos系统上运行) - - [7.3 Windows系统上运行](#73-windows系统上运行) + - [7.1 Linux 系统上运行](#71-Linux系统上运行) + - [7.2 macOS 系统上运行](#72-macOS系统上运行) + - [7.3 Windows 系统上运行](#73-Windows系统上运行) 1. [测试](#8-测试) 1. [版本发布](#9-版本发布) 1. [工作流](#10-工作流) @@ -43,9 +43,9 @@ TDengine 是一款开源、高性能、云原生的时序数据库 (Time-Series Database, TSDB)。TDengine 能被广泛运用于物联网、工业互联网、车联网、IT 运维、金融等领域。除核心的时序数据库功能外,TDengine 还提供缓存、数据订阅、流式计算等功能,是一极简的时序数据处理平台,最大程度的减小系统设计的复杂度,降低研发和运营成本。与其他时序数据库相比,TDengine 的主要优势如下: -- **高性能**:通过创新的存储引擎设计,无论是数据写入还是查询,TDengine 的性能比通用数据库快 10 倍以上,也远超其他时序数据库,存储空间不及通用数据库的1/10。 +- **高性能**:通过创新的存储引擎设计,无论是数据写入还是查询,TDengine 的性能比通用数据库快 10 倍以上,也远超其他时序数据库,存储空间不及通用数据库的 1/10。 -- **云原生**:通过原生分布式的设计,充分利用云平台的优势,TDengine 提供了水平扩展能力,具备弹性、韧性和可观测性,支持k8s部署,可运行在公有云、私有云和混合云上。 +- **云原生**:通过原生分布式的设计,充分利用云平台的优势,TDengine 提供了水平扩展能力,具备弹性、韧性和可观测性,支持 k8s 部署,可运行在公有云、私有云和混合云上。 - **极简时序数据平台**:TDengine 内建消息队列、缓存、流式计算等功能,应用无需再集成 Kafka/Redis/HBase/Spark 等软件,大幅降低系统的复杂度,降低应用开发和运营成本。 @@ -53,29 +53,29 @@ TDengine 是一款开源、高性能、云原生的时序数据库 (Time-Series - **简单易用**:无任何依赖,安装、集群几秒搞定;提供REST以及各种语言连接器,与众多第三方工具无缝集成;提供命令行程序,便于管理和即席查询;提供各种运维工具。 -- **核心开源**:TDengine 的核心代码包括集群功能全部开源,截止到2022年8月1日,全球超过 135.9k 个运行实例,GitHub Star 18.7k,Fork 4.4k,社区活跃。 +- **核心开源**:TDengine 的核心代码包括集群功能全部开源,截止到 2022 年 8 月 1 日,全球超过 135.9k 个运行实例,GitHub Star 18.7k,Fork 4.4k,社区活跃。 -了解TDengine高级功能的完整列表,请 [点击](https://tdengine.com/tdengine/)。体验TDengine最简单的方式是通过[TDengine云平台](https://cloud.tdengine.com)。 +了解TDengine高级功能的完整列表,请 [点击](https://tdengine.com/tdengine/)。体验 TDengine 最简单的方式是通过 [TDengine云平台](https://cloud.tdengine.com)。 # 2. 文档 关于完整的使用手册,系统架构和更多细节,请参考 [TDengine](https://www.taosdata.com/) 或者 [TDengine 官方文档](https://docs.taosdata.com)。 -用户可根据需求选择通过[容器](https://docs.taosdata.com/get-started/docker/)、[安装包](https://docs.taosdata.com/get-started/package/)、[Kubernetes](https://docs.taosdata.com/deployment/k8s/)来安装或直接使用无需安装部署的[云服务](https://cloud.taosdata.com/)。本快速指南是面向想自己编译、打包、测试的开发者的。 +用户可根据需求选择通过 [容器](https://docs.taosdata.com/get-started/docker/)、[安装包](https://docs.taosdata.com/get-started/package/)、[Kubernetes](https://docs.taosdata.com/deployment/k8s/) 来安装或直接使用无需安装部署的 [云服务](https://cloud.taosdata.com/)。本快速指南是面向想自己编译、打包、测试的开发者的。 -如果想编译或测试TDengine连接器,请访问以下仓库: [JDBC连接器](https://github.com/taosdata/taos-connector-jdbc), [Go连接器](https://github.com/taosdata/driver-go), [Python连接器](https://github.com/taosdata/taos-connector-python), [Node.js连接器](https://github.com/taosdata/taos-connector-node), [C#连接器](https://github.com/taosdata/taos-connector-dotnet), [Rust连接器](https://github.com/taosdata/taos-connector-rust). +如果想编译或测试 TDengine 连接器,请访问以下仓库:[JDBC连接器](https://github.com/taosdata/taos-connector-jdbc)、[Go连接器](https://github.com/taosdata/driver-go)、[Python连接器](https://github.com/taosdata/taos-connector-python)、[Node.js连接器](https://github.com/taosdata/taos-connector-node)、[C#连接器](https://github.com/taosdata/taos-connector-dotnet)、[Rust连接器](https://github.com/taosdata/taos-connector-rust)。 # 3. 前置条件 -TDengine 目前可以在 Linux、 Windows、macOS 等平台上安装和运行。任何 OS 的应用也可以选择 taosAdapter 的 RESTful 接口连接服务端 taosd。CPU 支持 X64/ARM64,后续会支持 MIPS64、Alpha64、ARM32、RISC-V 等 CPU 架构。目前不支持使用交叉编译器构建。 +TDengine 目前可以在 Linux、 Windows、macOS 等平台上安装和运行。任何 OS 的应用也可以选择 taosAdapter 的 RESTful 接口连接服务端 taosd。CPU 支持 X64、ARM64,后续会支持 MIPS64、Alpha64、ARM32、RISC-V 等 CPU 架构。目前不支持使用交叉编译器构建。 如果你想要编译 taosAdapter 或者 taosKeeper,需要安装 Go 1.18 及以上版本。 -## 3.1 Linux系统 +## 3.1 Linux 系统
-安装Linux必备工具 +安装 Linux 必备工具 ### Ubuntu 18.04、20.04、22.04 @@ -96,13 +96,13 @@ yum install -y zlib-static xz-devel snappy-devel jansson-devel pkgconfig libatom
-## 3.2 macOS系统 +## 3.2 macOS 系统
-安装macOS必备工具 +安装 macOS 必备工具 -根据提示安装依赖工具 [brew](https://brew.sh/). +根据提示安装依赖工具 [brew](https://brew.sh/) ```bash brew install argp-standalone gflags pkgconfig @@ -110,11 +110,11 @@ brew install argp-standalone gflags pkgconfig
-## 3.3 Windows系统 +## 3.3 Windows 系统
-安装Windows必备工具 +安装 Windows 必备工具 进行中。 @@ -122,7 +122,7 @@ brew install argp-standalone gflags pkgconfig ## 3.4 克隆仓库 -通过如下命令将TDengine仓库克隆到指定计算机: +通过如下命令将 TDengine 仓库克隆到指定计算机: ```bash git clone https://github.com/taosdata/TDengine.git @@ -131,23 +131,23 @@ cd TDengine # 4. 构建 -TDengine 还提供一组辅助工具软件 taosTools,目前它包含 taosBenchmark(曾命名为 taosdemo)和 taosdump 两个软件。默认 TDengine 编译不包含 taosTools, 您可以在编译 TDengine 时使用`cmake .. -DBUILD_TOOLS=true` 来同时编译 taosTools。 +TDengine 还提供一组辅助工具软件 taosTools,目前它包含 taosBenchmark(曾命名为 taosdemo)和 taosdump 两个软件。默认 TDengine 编译不包含 taosTools,您可以在编译 TDengine 时使用 `cmake .. -DBUILD_TOOLS=true` 来同时编译 taosTools。 -为了构建TDengine, 请使用 [CMake](https://cmake.org/) 3.13.0 或者更高版本。 +为了构建 TDengine,请使用 [CMake](https://cmake.org/) 3.13.0 或者更高版本。 -## 4.1 Linux系统上构建 +## 4.1 Linux 系统上构建
-Linux系统上构建步骤 +Linux 系统上构建步骤 -可以通过以下命令使用脚本 `build.sh` 编译TDengine和taosTools,包括taosBenchmark和taosdump: +可以通过以下命令使用脚本 `build.sh` 编译 TDengine 和 taosTools,包括 taosBenchmark 和 taosdump。 ```bash ./build.sh ``` -也可以通过以下命令进行构建: +也可以通过以下命令进行构建: ```bash mkdir debug && cd debug @@ -157,15 +157,15 @@ make 如果你想要编译 taosAdapter,需要添加 `-DBUILD_HTTP=false` 选项。 -如果你想要编译 taosKeeper,需要添加 `--DBUILD_KEEPER=true` 选项。 +如果你想要编译 taosKeeper,需要添加 `-DBUILD_KEEPER=true` 选项。 -可以使用Jemalloc作为内存分配器,而不是使用glibc: +可以使用 Jemalloc 作为内存分配器,而不是使用 glibc: ```bash cmake .. -DJEMALLOC_ENABLED=ON ``` -TDengine构建脚本可以自动检测 x86、x86-64、arm64 平台上主机的体系结构。 -您也可以通过 CPUTYPE 选项手动指定架构: +TDengine 构建脚本可以自动检测 x86、x86-64、arm64 平台上主机的体系结构。 +您也可以通过 CPUTYPE 选项手动指定架构: ```bash cmake .. -DCPUTYPE=aarch64 && cmake --build . @@ -173,13 +173,13 @@ cmake .. -DCPUTYPE=aarch64 && cmake --build .
-## 4.2 macOS系统上构建 +## 4.2 macOS 系统上构建
-macOS系统上构建步骤 +macOS 系统上构建步骤 -请安装XCode命令行工具和cmake。使用XCode 11.4+在Catalina和Big Sur上完成验证。 +请安装 XCode 命令行工具和 cmake。使用 XCode 11.4+ 在 Catalina 和 Big Sur 上完成验证。 ```shell mkdir debug && cd debug @@ -192,14 +192,14 @@ cmake .. && cmake --build .
-## 4.3 Windows系统上构建 +## 4.3 Windows 系统上构建
-Windows系统上构建步骤 +Windows 系统上构建步骤 -如果您使用的是Visual Studio 2013,请执行“cmd.exe”打开命令窗口执行如下命令。 -执行vcvarsall.bat时,64位的Windows请指定“amd64”,32位的Windows请指定“x86”。 +如果您使用的是 Visual Studio 2013,请执行 “cmd.exe” 打开命令窗口执行如下命令。 +执行 vcvarsall.bat 时,64 位的 Windows 请指定 “amd64”,32 位的 Windows 请指定 “x86”。 ```cmd mkdir debug && cd debug @@ -208,19 +208,19 @@ cmake .. -G "NMake Makefiles" nmake ``` -如果您使用Visual Studio 2019或2017: +如果您使用 Visual Studio 2019 或 2017: -请执行“cmd.exe”打开命令窗口执行如下命令。 -执行vcvarsall.bat时,64位的Windows请指定“x64”,32位的Windows请指定“x86”。 +请执行 “cmd.exe” 打开命令窗口执行如下命令。 +执行 vcvarsall.bat 时,64 位的 Windows 请指定 “x64”,32 位的 Windows 请指定 “x86”。 ```cmd mkdir debug && cd debug -"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" < x64 | x86 > +"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" < x64 | x86 > cmake .. -G "NMake Makefiles" nmake ``` -或者,您可以通过点击Windows开始菜单打开命令窗口->“Visual Studio < 2019 | 2017 >”文件夹->“x64原生工具命令提示符VS < 2019 | 2017 >”或“x86原生工具命令提示符VS < 2019 | 2017 >”取决于你的Windows是什么架构,然后执行命令如下: +或者,您可以通过点击 Windows 开始菜单打开命令窗口 -> `Visual Studio < 2019 | 2017 >` 文件夹 -> `x64 原生工具命令提示符 VS < 2019 | 2017 >` 或 `x86 原生工具命令提示符 < 2019 | 2017 >` 取决于你的 Windows 是什么架构,然后执行命令如下: ```cmd mkdir debug && cd debug @@ -231,33 +231,33 @@ nmake # 5. 打包 -由于一些组件依赖关系,TDengine社区安装程序不能仅由该存储库创建。我们仍在努力改进。 +由于一些组件依赖关系,TDengine 社区安装程序不能仅由该存储库创建。我们仍在努力改进。 # 6. 安装 -## 6.1 Linux系统上安装 +## 6.1 Linux 系统上安装
-Linux系统上安装详细步骤 +Linux 系统上安装详细步骤 -构建成功后,TDengine可以通过以下命令进行安装: +构建成功后,TDengine 可以通过以下命令进行安装: ```bash sudo make install ``` -从源代码安装还将为TDengine配置服务管理。用户也可以使用[TDengine安装包](https://docs.taosdata.com/get-started/package/)进行安装。 +从源代码安装还将为 TDengine 配置服务管理。用户也可以使用 [TDengine安装包](https://docs.taosdata.com/get-started/package/)进行安装。
-## 6.2 macOS系统上安装 +## 6.2 macOS 系统上安装
-macOS系统上安装详细步骤 +macOS 系统上安装详细步骤 -构建成功后,TDengine可以通过以下命令进行安装: +构建成功后,TDengine可以通过以下命令进行安装: ```bash sudo make install @@ -265,13 +265,13 @@ sudo make install
-## 6.3 Windows系统上安装 +## 6.3 Windows 系统上安装
-Windows系统上安装详细步骤 +Windows 系统上安装详细步骤 -构建成功后,TDengine可以通过以下命令进行安装: +构建成功后,TDengine 可以通过以下命令进行安装: ```cmd nmake install @@ -281,32 +281,32 @@ nmake install # 7. 快速运行 -## 7.1 Linux系统上运行 +## 7.1 Linux 系统上运行
-Linux系统上运行详细步骤 +Linux 系统上运行详细步骤 -在Linux系统上安装TDengine完成后,在终端运行如下命令启动服务: +在Linux 系统上安装 TDengine 完成后,在终端运行如下命令启动服务: ```bash sudo systemctl start taosd ``` -然后用户可以通过如下命令使用TDengine命令行连接TDengine服务: +然后用户可以通过如下命令使用 TDengine 命令行连接 TDengine 服务: ```bash taos ``` -如果TDengine 命令行连接服务器成功,系统将打印欢迎信息和版本信息。否则,将显示连接错误信息。 +如果 TDengine 命令行连接服务器成功,系统将打印欢迎信息和版本信息。否则,将显示连接错误信息。 -如果您不想将TDengine作为服务运行,您可以在当前终端中运行它。例如,要在构建完成后快速启动TDengine服务器,在终端中运行以下命令:(我们以Linux为例,Windows上的命令为 `taosd.exe`) +如果您不想将 TDengine 作为服务运行,您可以在当前终端中运行它。例如,要在构建完成后快速启动 TDengine 服务器,在终端中运行以下命令:(以 Linux 为例,Windows 上的命令为 `taosd.exe`) ```bash ./build/bin/taosd -c test/cfg ``` -在另一个终端上,使用TDengine命令行连接服务器: +在另一个终端上,使用 TDengine 命令行连接服务器: ```bash ./build/bin/taos -c test/cfg @@ -316,42 +316,42 @@ taos
-## 7.2 macOS系统上运行 +## 7.2 macOS 系统上运行
-macOS系统上运行详细步骤 +macOS 系统上运行详细步骤 -在macOS上安装完成后启动服务,双击/applications/TDengine启动程序,或者在终端中执行如下命令: +在 macOS 上安装完成后启动服务,双击 `/applications/TDengine` 启动程序,或者在终端中执行如下命令: ```bash sudo launchctl start com.tdengine.taosd ``` -然后在终端中使用如下命令通过TDengine命令行连接TDengine服务器: +然后在终端中使用如下命令通过 TDengine 命令行连接 TDengine 服务器: ```bash taos ``` -如果TDengine命令行连接服务器成功,系统将打印欢迎信息和版本信息。否则,将显示错误信息。 +如果 TDengine 命令行连接服务器成功,系统将打印欢迎信息和版本信息。否则,将显示错误信息。
-## 7.3 Windows系统上运行 +## 7.3 Windows 系统上运行
-Windows系统上运行详细步骤 +Windows 系统上运行详细步骤 -您可以使用以下命令在Windows平台上启动TDengine服务器: +您可以使用以下命令在 Windows 平台上启动 TDengine 服务器: ```cmd .\build\bin\taosd.exe -c test\cfg ``` -在另一个终端上,使用TDengine命令行连接服务器: +在另一个终端上,使用 TDengine 命令行连接服务器: ```cmd .\build\bin\taos.exe -c test\cfg @@ -363,25 +363,25 @@ taos # 8. 测试 -有关如何在TDengine上运行不同类型的测试,请参考 [TDengine测试](./tests/README-CN.md) +有关如何在 TDengine 上运行不同类型的测试,请参考 [TDengine测试](./tests/README-CN.md) # 9. 版本发布 -TDengine发布版本的完整列表,请参考 [版本列表](https://github.com/taosdata/TDengine/releases) +TDengine 发布版本的完整列表,请参考 [版本列表](https://github.com/taosdata/TDengine/releases) # 10. 工作流 -TDengine构建检查工作流可以在参考 [Github Action](https://github.com/taosdata/TDengine/actions/workflows/taosd-ci-build.yml), 更多的工作流正在创建中,将很快可用。 +TDengine 构建检查工作流可以在参考 [Github Action](https://github.com/taosdata/TDengine/actions/workflows/taosd-ci-build.yml),更多的工作流正在创建中,将很快可用。 # 11. 覆盖率 -最新的TDengine测试覆盖率报告可参考 [coveralls.io](https://coveralls.io/github/taosdata/TDengine) +最新的 TDengine 测试覆盖率报告可参考 [coveralls.io](https://coveralls.io/github/taosdata/TDengine)
如何在本地运行测试覆盖率报告? -在本地创建测试覆盖率报告(HTML格式),请运行以下命令: +在本地创建测试覆盖率报告(HTML 格式),请运行以下命令: ```bash cd tests @@ -389,8 +389,8 @@ bash setup-lcov.sh -v 1.16 && ./run_local_coverage.sh -b main -c task # on main branch and run cases in longtimeruning_cases.task # for more infomation about options please refer to ./run_local_coverage.sh -h ``` -> **注意:** -> 请注意,-b和-i选项将使用-DCOVER=true选项重新编译TDengine,这可能需要花费一些时间。 +> **注意**: +> 请注意,-b 和 -i 选项将使用 -DCOVER=true 选项重新编译 TDengine,这可能需要花费一些时间。
diff --git a/cmake/cmake.define b/cmake/cmake.define index 72c9e84f78..3770f1f3b0 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -116,8 +116,6 @@ ELSE() set(VAR_TSZ "TSZ" CACHE INTERNAL "global variant tsz") ENDIF() -# SET(JEMALLOC_ENABLED OFF) - IF(TD_WINDOWS) MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}") @@ -259,12 +257,15 @@ ELSE() ENDIF() -IF(TD_LINUX) +IF(TD_LINUX_64) IF(${JEMALLOC_ENABLED}) MESSAGE(STATUS "JEMALLOC Enabled") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=attributes") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=attributes") + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib) ELSE() MESSAGE(STATUS "JEMALLOC Disabled") + SET(LINK_JEMALLOC "") ENDIF() ENDIF() \ No newline at end of file diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 5d356e06b1..ac89c35db5 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -14,24 +14,12 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/node_mgmt/inc" ) -IF(TD_ENTERPRISE) - IF(${BUILD_WITH_S3}) +if(TD_ENTERPRISE) + if(${BUILD_WITH_S3}) add_definitions(-DUSE_S3) - ELSEIF(${BUILD_WITH_COS}) + elseif(${BUILD_WITH_COS}) add_definitions(-DUSE_COS) - ENDIF() -ENDIF() + endif() +endif() -IF(TD_LINUX_64 AND JEMALLOC_ENABLED) - ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) - SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") -ELSE() - SET(LINK_JEMALLOC "") -ENDIF() - -IF(TD_LINUX_64 AND JEMALLOC_ENABLED) - ADD_DEPENDENCIES(taosd jemalloc) - target_link_libraries(taosd dnode crypt ${LINK_JEMALLOC}) -ELSE() - target_link_libraries(taosd dnode crypt) -ENDIF() +target_link_libraries(taosd dnode crypt) diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index 6b33e68377..01103e7bd0 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -1,4 +1,5 @@ aux_source_directory(src OS_SRC) + if(NOT ${TD_WINDOWS}) add_definitions(-DTHREAD_SAFE=1) aux_source_directory(src/timezone OS_TZ) @@ -6,6 +7,7 @@ if(NOT ${TD_WINDOWS}) else() add_library(os STATIC ${OS_SRC}) endif(NOT ${TD_WINDOWS}) + target_include_directories( os PUBLIC "${TD_SOURCE_DIR}/include/os" @@ -16,21 +18,26 @@ target_include_directories( PUBLIC "${TD_SOURCE_DIR}/contrib/msvcregex" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + # iconv if(TD_WINDOWS) find_path(IconvApiIncludes iconv.h "${TD_SOURCE_DIR}/contrib/iconv") else() find_path(IconvApiIncludes iconv.h PATHS) endif(TD_WINDOWS) + if(NOT IconvApiIncludes) - add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) -endif () + add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) +endif() + if(USE_TD_MEMORY) - add_definitions(-DUSE_TD_MEMORY) -endif () + add_definitions(-DUSE_TD_MEMORY) +endif() + if(BUILD_WITH_RAND_ERR) - add_definitions(-DBUILD_WITH_RAND_ERR) -endif () + add_definitions(-DBUILD_WITH_RAND_ERR) +endif() + if(BUILD_ADDR2LINE) if(NOT TD_WINDOWS) target_include_directories( @@ -41,31 +48,36 @@ if(BUILD_ADDR2LINE) os PUBLIC addr2line dl z ) endif() + add_definitions(-DUSE_ADDR2LINE) -endif () +endif() + if(CHECK_STR2INT_ERROR) add_definitions(-DTD_CHECK_STR_TO_INT_ERROR) endif() + target_link_libraries( os PUBLIC pthread PUBLIC zlibstatic + PUBLIC ${LINK_JEMALLOC} ) + if(TD_WINDOWS) target_link_libraries( os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump dbghelp version KtmW32 ) elseif(TD_DARWIN_64) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) - target_link_libraries(os PUBLIC ${CORE_FOUNDATION_FRAMEWORK}) + target_link_libraries(os PUBLIC ${CORE_FOUNDATION_FRAMEWORK}) find_library(SYSTEM_CONFIGURATION_FRAMEWORK SystemConfiguration) - target_link_libraries(os PUBLIC ${SYSTEM_CONFIGURATION_FRAMEWORK}) + target_link_libraries(os PUBLIC ${SYSTEM_CONFIGURATION_FRAMEWORK}) target_link_libraries( os PUBLIC dl m iconv ) elseif(TD_ALPINE) target_link_libraries( - os PUBLIC dl m rt unwind + os PUBLIC dl m rt unwind ) else() target_link_libraries( @@ -73,15 +85,14 @@ else() ) endif() -IF (JEMALLOC_ENABLED) - target_link_libraries(os PUBLIC -L${CMAKE_BINARY_DIR}/build/lib -ljemalloc) -ENDIF () - -#if(NOT ${TD_WINDOWS}) -# find_library(tz libtz.a "${TD_SOURCE_DIR}/contrib/tz") -# target_link_libraries(os PUBLIC ${tz}) -#endif(NOT ${TD_WINDOWS}) +if(JEMALLOC_ENABLED) + add_dependencies(os jemalloc) +endif() +# if(NOT ${TD_WINDOWS}) +# find_library(tz libtz.a "${TD_SOURCE_DIR}/contrib/tz") +# target_link_libraries(os PUBLIC ${tz}) +# endif(NOT ${TD_WINDOWS}) if(${BUILD_TEST}) add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 2301f33803..ac901f5ca2 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -2,14 +2,6 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) -IF(TD_LINUX_64 AND JEMALLOC_ENABLED) - ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) - SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") - ADD_DEPENDENCIES(shell jemalloc) -ELSE() - SET(LINK_JEMALLOC "") -ENDIF() - IF(TD_LINUX AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include -ltaosws) SET(LINK_WEBSOCKET "-L${CMAKE_BINARY_DIR}/build/lib -ltaosws") @@ -33,13 +25,14 @@ ELSE() ENDIF() if(TD_WINDOWS) - target_link_libraries(shell PUBLIC ${TAOS_LIB_STATIC} ${LINK_WEBSOCKET}) + target_link_libraries(shell PUBLIC ${TAOS_LIB_STATIC}) else() - target_link_libraries(shell PUBLIC ${TAOS_LIB} ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) + target_link_libraries(shell PUBLIC ${TAOS_LIB} ${LINK_ARGP}) endif() target_link_libraries( shell + PUBLIC ${LINK_WEBSOCKET} PRIVATE os common transport geometry util ) @@ -53,16 +46,17 @@ SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) # # generator library shell_ut for uint test # - IF(TD_LINUX) # include include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + # shell_ut library add_library(shell_ut STATIC ${SHELL_SRC}) IF(TD_WEBSOCKET) ADD_DEPENDENCIES(shell_ut taosws-rs) ENDIF() + target_link_libraries(shell_ut PUBLIC ${TAOS_LIB} ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) target_link_libraries(shell_ut PRIVATE os common transport geometry util) @@ -76,5 +70,5 @@ IF(TD_LINUX) # unit test IF(${BUILD_TEST}) ADD_SUBDIRECTORY(test) - ENDIF(${BUILD_TEST}) + ENDIF(${BUILD_TEST}) ENDIF()