diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index bb015bce3d1a8ea9d92f3915d1edccd7f31539a3..820572859e88540656b8ce42dc3a6e77467c1423 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 4811a3b35d3fc15be5af78cff8d420868637da9b..161b8371928e6b3ea4acfc316b4097de375b2b37 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 a2d02be683cd9b78e518d9630d604d8874035d68..d7981ac545327704a58bd88c82cf659b205cff66 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 38ba6b54008bc91c83b6a3be9b74ad287b52604c..10456062a95a66df0c01476a2d5864c0d1bf94b0 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++) {