From 1c253df3006667eebb3938566959044989d87458 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 1 Feb 2021 06:54:38 +0000 Subject: [PATCH 1/3] TD-2568 --- src/client/src/tscLocal.c | 7 ++++++- src/client/src/tscSQLParser.c | 27 ++++++++++++++++++++------- src/common/src/tglobal.c | 35 +++++++++++++++++++++++++++++------ src/query/src/qExecutor.c | 2 +- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index bb015bce3d..820572859e 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -892,7 +892,12 @@ int tscProcessLocalCmd(SSqlObj *pSql) { SSqlRes *pRes = &pSql->res; if (pCmd->command == TSDB_SQL_CFG_LOCAL) { - pRes->code = (uint8_t)taosCfgDynamicOptions(pCmd->payload); + if (taosCfgDynamicOptions(pCmd->payload)) { + pRes->code = TSDB_CODE_SUCCESS; + } else { + pRes->code = TSDB_CODE_COM_INVALID_CFG_MSG; + } + pRes->numOfRows = 0; } else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) { pRes->code = (uint8_t)tscProcessDescribeTable(pSql); } else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4811a3b35d..161b837192 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -129,6 +129,7 @@ static int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index); static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pSqlExpr, SQueryInfo* pQueryInfo, SArray* pCols, int64_t *uid); +static bool validateDebugFlag(int32_t flag); int16_t getNewResColId(SQueryInfo* pQueryInfo) { return pQueryInfo->resColumnId--; @@ -173,6 +174,18 @@ static uint8_t convertOptr(SStrToken *pToken) { } } +static bool validateDebugFlag(int32_t v) { + const int validFlag[] = {131, 135, 143}; + bool ret = false; + + for (int i = 0; i < tListLen(validFlag); i++) { + if (v == validFlag[i]) { + ret = true; + break; + } + } + return ret; +} /* * Used during parsing query sql. Since the query sql usually small in length, error position * is not needed in the final error message. @@ -565,16 +578,16 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } int32_t numOfToken = (int32_t) taosArrayGetSize(pMiscInfo->a); - SStrToken* t = taosArrayGet(pMiscInfo->a, 0); - SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1); + assert(numOfToken >= 1 && numOfToken <= 2); + SStrToken* t = taosArrayGet(pMiscInfo->a, 0); strncpy(pCmd->payload, t->z, t->n); if (numOfToken == 2) { + SStrToken* t1 = taosArrayGet(pMiscInfo->a, 1); pCmd->payload[t->n] = ' '; // add sep strncpy(&pCmd->payload[t->n + 1], t1->z, t1->n); - } - - break; + } + return TSDB_CODE_SUCCESS; } case TSDB_SQL_CREATE_TABLE: { @@ -5382,6 +5395,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}}; + SStrToken* pOptionToken = taosArrayGet(pOptions->a, 0); if (numOfToken == 1) { @@ -5396,8 +5410,7 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { SStrToken* pValToken = taosArrayGet(pOptions->a, 1); int32_t val = strtol(pValToken->z, NULL, 10); - if (val < 131 || val > 199) { - // options value is out of valid range + if (!validateDebugFlag(val)) { return TSDB_CODE_TSC_INVALID_SQL; } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index a2d02be683..d7981ac545 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -258,6 +258,33 @@ void taosSetAllDebugFlag() { uInfo("all debug flag are set to %d", debugFlag); } } +typedef struct { + char *name; + int32_t len; + void *flag; +} SDynCfgLog; + +bool taosDynCfgDebugFlag(const char *str, int32_t slen, int32_t flag) { + const SDynCfgLog cfgLog[] = { + {"debugFlag", 9, NULL}, {"monDebugFlag", 12, &mDebugFlag}, {"vDebugFlag", 10, &vDebugFlag}, {"mDebugFlag", 10, &mDebugFlag}, + {"cDebugFlag", 10, &cDebugFlag}, {"httpDebugFlag", 13, &httpDebugFlag}, {"qDebugflag", 10, &qDebugFlag}, {"sdbDebugFlag", 12, &sdbDebugFlag}, + {"uDebugFlag", 10, &uDebugFlag}, {"tsdbDebugFlag", 13, &tsdbDebugFlag}, {"sDebugflag", 10, &sDebugFlag}, {"rpcDebugFlag", 12, &rpcDebugFlag}, + {"dDebugFlag", 10, &dDebugFlag}, {"mqttDebugFlag", 13, &mqttDebugFlag}, {"wDebugFlag", 10, &wDebugFlag}, {"tmrDebugFlag", 12, &tmrDebugFlag}, + {"cqDebugFlag", 11, &cqDebugFlag}, + }; + for (int i = 0; i < tListLen(cfgLog); i++) { + if (slen == cfgLog[i].len && strncasecmp(cfgLog[i].name, str, slen) == 0) { + if (cfgLog[i].flag == NULL) { + debugFlag = flag; + taosSetAllDebugFlag(); + } else { + *((int32_t *)(cfgLog[i].flag)) = flag; + } + return true; + } + } + return false; +} bool taosCfgDynamicOptions(char *msg) { char *option, *value; @@ -265,7 +292,7 @@ bool taosCfgDynamicOptions(char *msg) { int32_t vint = 0; paGetToken(msg, &option, &olen); - if (olen == 0) return TSDB_CODE_COM_INVALID_CFG_MSG; + if (olen == 0) return false;; paGetToken(option + olen + 1, &value, &vlen); if (vlen == 0) @@ -309,11 +336,7 @@ bool taosCfgDynamicOptions(char *msg) { return true; } - if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { - taosSetAllDebugFlag(); - } - - return true; + return taosDynCfgDebugFlag(cfg->option, olen, vint); } if (strncasecmp(option, "resetlog", 8) == 0) { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 38ba6b5400..10456062a9 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -4498,7 +4498,7 @@ static void generateBlockDistResult(STableBlockDist *pTableBlockDist) { if (pTableBlockDist == NULL) { return; } - int64_t min = INT64_MAX, max = INT64_MIN, avg = 0; + int64_t min = 0, max = 0, avg = 0; SArray* blockInfos= pTableBlockDist->dataBlockInfos; int64_t totalRows = 0, totalBlocks = taosArrayGetSize(blockInfos); for (size_t i = 0; i < taosArrayGetSize(blockInfos); i++) { From 992842ff513a2caae484e39ac2eb1d8b219c5544 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 4 Feb 2021 06:06:29 +0000 Subject: [PATCH 2/3] fix crash at some case --- src/client/src/tscSQLParser.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d97e0169df..3b248a6281 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -175,16 +175,14 @@ static uint8_t convertOptr(SStrToken *pToken) { } static bool validateDebugFlag(int32_t v) { - const int validFlag[] = {131, 135, 143}; - bool ret = false; + const static int validFlag[] = {131, 135, 143}; for (int i = 0; i < tListLen(validFlag); i++) { if (v == validFlag[i]) { - ret = true; - break; + return true; } } - return ret; + return false; } /* * Used during parsing query sql. Since the query sql usually small in length, error position @@ -5377,7 +5375,8 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { // reset log does not need value for (int32_t i = 0; i < 1; ++i) { SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; - if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { + if ((pOption->len == pOptionToken->n) && + (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) { return TSDB_CODE_SUCCESS; } } @@ -5391,8 +5390,8 @@ int32_t validateLocalConfig(SMiscInfo* pOptions) { for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { SDNodeDynConfOption* pOption = &LOCAL_DYNAMIC_CFG_OPTIONS[i]; - if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { - // options is valid + if ((pOption->len == pOptionToken->n) + && (strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0)) { return TSDB_CODE_SUCCESS; } } From dabf6f9579f2bc1bd9620a979313237ff6bd76a5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 4 Feb 2021 06:35:31 +0000 Subject: [PATCH 3/3] revert some code --- src/common/src/tglobal.c | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index f3ed35d0e3..fb6d745931 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -266,33 +266,6 @@ void taosSetAllDebugFlag() { uInfo("all debug flag are set to %d", debugFlag); } } -typedef struct { - char *name; - int32_t len; - void *flag; -} SDynCfgLog; - -bool taosDynCfgDebugFlag(const char *str, int32_t slen, int32_t flag) { - const SDynCfgLog cfgLog[] = { - {"debugFlag", 9, NULL}, {"monDebugFlag", 12, &mDebugFlag}, {"vDebugFlag", 10, &vDebugFlag}, {"mDebugFlag", 10, &mDebugFlag}, - {"cDebugFlag", 10, &cDebugFlag}, {"httpDebugFlag", 13, &httpDebugFlag}, {"qDebugflag", 10, &qDebugFlag}, {"sdbDebugFlag", 12, &sdbDebugFlag}, - {"uDebugFlag", 10, &uDebugFlag}, {"tsdbDebugFlag", 13, &tsdbDebugFlag}, {"sDebugflag", 10, &sDebugFlag}, {"rpcDebugFlag", 12, &rpcDebugFlag}, - {"dDebugFlag", 10, &dDebugFlag}, {"mqttDebugFlag", 13, &mqttDebugFlag}, {"wDebugFlag", 10, &wDebugFlag}, {"tmrDebugFlag", 12, &tmrDebugFlag}, - {"cqDebugFlag", 11, &cqDebugFlag}, - }; - for (int i = 0; i < tListLen(cfgLog); i++) { - if (slen == cfgLog[i].len && strncasecmp(cfgLog[i].name, str, slen) == 0) { - if (cfgLog[i].flag == NULL) { - debugFlag = flag; - taosSetAllDebugFlag(); - } else { - *((int32_t *)(cfgLog[i].flag)) = flag; - } - return true; - } - } - return false; -} bool taosCfgDynamicOptions(char *msg) { char *option, *value; @@ -343,8 +316,10 @@ bool taosCfgDynamicOptions(char *msg) { } return true; } - - return taosDynCfgDebugFlag(cfg->option, olen, vint); + if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { + taosSetAllDebugFlag(); + } + return true; } if (strncasecmp(option, "resetlog", 8) == 0) {