From e517db64621685f21cb8e674fdd3b9e51a16341c Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 24 Jun 2024 19:19:46 +0800 Subject: [PATCH] fix:add db configuration that not reportted --- include/common/tmsg.h | 2 ++ include/util/taoserror.h | 1 + source/client/src/clientEnv.c | 22 +++++++++++++++++++-- source/common/src/tglobal.c | 7 ++++--- source/common/src/tmsg.c | 4 ++++ source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 2 ++ source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/src/mndDnode.c | 11 +++++++++-- source/dnode/mnode/impl/src/mndProfile.c | 4 ++++ source/util/src/terror.c | 1 + 10 files changed, 48 insertions(+), 7 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 32b307a75c..a7eae9f19c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -660,6 +660,8 @@ typedef struct { int32_t tsSlowLogThreshold; int32_t tsSlowLogMaxLen; int32_t tsSlowLogScope; + int32_t tsSlowLogThresholdTest; + char tsSlowLogExceptDb[TSDB_DB_NAME_LEN]; } SMonitorParas; typedef struct { diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 2e407d26b0..a5688ca04b 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -456,6 +456,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_DNODE_INVALID_LOCALE TAOS_DEF_ERROR_CODE(0, 0x0426) #define TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR TAOS_DEF_ERROR_CODE(0, 0x0427) #define TSDB_CODE_DNODE_INVALID_EN_WHITELIST TAOS_DEF_ERROR_CODE(0, 0x0428) +#define TSDB_CODE_DNODE_INVALID_MONITOR_PARAS TAOS_DEF_ERROR_CODE(0, 0x0429) // mnode-sma #define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index ea8874302e..15568669f1 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -175,6 +175,24 @@ static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_ cJSON_Delete(json); } +static bool checkSlowLogExceptDb(SRequestObj *pRequest, char* exceptDb) { + if (pRequest->pDb != NULL) { + return strcmp(pRequest->pDb, exceptDb) != 0; + } + + for (int i = 0; i < taosArrayGetSize(pRequest->dbList); i++) { + char *db = taosArrayGet(pRequest->dbList, i); + char *dot = strchr(db, '.'); + if (dot != NULL) { + db = dot + 1; + } + if(strcmp(db, exceptDb) == 0){ + return false; + } + } + return true; +} + static void deregisterRequest(SRequestObj *pRequest) { if (pRequest == NULL) { tscError("pRequest == NULL"); @@ -228,8 +246,8 @@ static void deregisterRequest(SRequestObj *pRequest) { } } - if ((duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThreshold * 1000000UL || duration >= tsSlowLogThresholdTest * 1000000UL) && - (pRequest->pDb == NULL || strcmp(pRequest->pDb, tsSlowLogExceptDb) != 0)) { + if ((duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThreshold * 1000000UL || duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThresholdTest * 1000000UL) && + checkSlowLogExceptDb(pRequest, pTscObj->pAppInfo->monitorParas.tsSlowLogExceptDb)) { atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1); if (pTscObj->pAppInfo->monitorParas.tsSlowLogScope & reqType) { taosPrintSlowLog("PID:%d, Conn:%u, QID:0x%" PRIx64 ", Start:%" PRId64 " us, Duration:%" PRId64 "us, SQL:%s", diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 0b152abf5f..bf0d9bc16b 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -181,7 +181,7 @@ bool tsUseAdapter = false; int32_t tsMetaCacheMaxSize = -1; // MB int32_t tsSlowLogThreshold = 10; // seconds int32_t tsSlowLogThresholdTest = 10; // seconds -char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = "log"; // seconds +char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = ""; // seconds int32_t tsSlowLogScope = SLOW_LOG_TYPE_QUERY; char* tsSlowLogScopeString = "query"; int32_t tsSlowLogMaxLen = 4096; @@ -703,11 +703,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 86400, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; - if (cfgAddInt32(pCfg, "slowLogThresholdTest", tsSlowLogThresholdTest, 0, INT32_MAX, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) != 0) return -1; + if (cfgAddInt32(pCfg, "slowLogThresholdTest", tsSlowLogThresholdTest, 0, INT32_MAX, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "slowLogThreshold", tsSlowLogThreshold, 1, INT32_MAX, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; if (cfgAddInt32(pCfg, "slowLogMaxLen", tsSlowLogMaxLen, 1, 16384, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; if (cfgAddString(pCfg, "slowLogScope", tsSlowLogScopeString, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; - if (cfgAddString(pCfg, "slowLogExceptDb", tsSlowLogExceptDb, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) != 0) return -1; + if (cfgAddString(pCfg, "slowLogExceptDb", tsSlowLogExceptDb, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1; if (cfgAddInt32(pCfg, "monitorPort", tsMonitorPort, 1, 65056, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1; @@ -1549,6 +1549,7 @@ static int32_t taosCfgDynamicOptionsForServer(SConfig *pCfg, const char *name) { {"monitor", &tsEnableMonitor}, {"monitorInterval", &tsMonitorInterval}, {"slowLogThreshold", &tsSlowLogThreshold}, + {"slowLogThresholdTest", &tsSlowLogThresholdTest}, {"slowLogMaxLen", &tsSlowLogMaxLen}, {"mndSdbWriteDelta", &tsMndSdbWriteDelta}, diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index bb61fdc4a5..65ac34c390 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -75,6 +75,8 @@ static int32_t tSerializeSMonitorParas(SEncoder *encoder, const SMonitorParas* p if (tEncodeI32(encoder, pMonitorParas->tsSlowLogScope) < 0) return -1; if (tEncodeI32(encoder, pMonitorParas->tsSlowLogMaxLen) < 0) return -1; if (tEncodeI32(encoder, pMonitorParas->tsSlowLogThreshold) < 0) return -1; + if (tEncodeI32(encoder, pMonitorParas->tsSlowLogThresholdTest) < 0) return -1; + if (tEncodeCStr(encoder, pMonitorParas->tsSlowLogExceptDb) < 0) return -1; return 0; } @@ -84,6 +86,8 @@ static int32_t tDeserializeSMonitorParas(SDecoder *decoder, SMonitorParas* pMoni if (tDecodeI32(decoder, &pMonitorParas->tsSlowLogScope) < 0) return -1; if (tDecodeI32(decoder, &pMonitorParas->tsSlowLogMaxLen) < 0) return -1; if (tDecodeI32(decoder, &pMonitorParas->tsSlowLogThreshold) < 0) return -1; + if (tDecodeI32(decoder, &pMonitorParas->tsSlowLogThresholdTest) < 0) return -1; + if (tDecodeCStrTo(decoder, pMonitorParas->tsSlowLogExceptDb) < 0) return -1; return 0; } diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index cb0bc6102c..3e1a633752 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -121,6 +121,8 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { req.clusterCfg.monitorParas.tsSlowLogScope = tsSlowLogScope; req.clusterCfg.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen; req.clusterCfg.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold; + req.clusterCfg.monitorParas.tsSlowLogThresholdTest = tsSlowLogThresholdTest; + tstrncpy(req.clusterCfg.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN); char timestr[32] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 46e606d3ea..dd577f8908 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -143,6 +143,7 @@ typedef enum { DND_REASON_TTL_CHANGE_ON_WRITE_NOT_MATCH, DND_REASON_ENABLE_WHITELIST_NOT_MATCH, DND_REASON_ENCRYPTION_KEY_NOT_MATCH, + DND_REASON_STATUS_MONITOR_NOT_MATCH, DND_REASON_OTHERS } EDndReason; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index ca6e1cd21b..f5ab56c1f2 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -441,17 +441,24 @@ void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) { #define CHECK_MONITOR_PARA(para) \ if (pCfg->monitorParas.para != para) { \ mError("dnode:%d, para:%d inconsistent with cluster:%d", pDnode->id, pCfg->monitorParas.para, para); \ - terrno = TSDB_CODE_DNODE_INVALID_STATUS_INTERVAL; \ - return DND_REASON_STATUS_INTERVAL_NOT_MATCH;\ + terrno = TSDB_CODE_DNODE_INVALID_MONITOR_PARAS; \ + return DND_REASON_STATUS_MONITOR_NOT_MATCH;\ } static int32_t mndCheckClusterCfgPara(SMnode *pMnode, SDnodeObj *pDnode, const SClusterCfg *pCfg) { CHECK_MONITOR_PARA(tsEnableMonitor); CHECK_MONITOR_PARA(tsMonitorInterval); CHECK_MONITOR_PARA(tsSlowLogThreshold); + CHECK_MONITOR_PARA(tsSlowLogThresholdTest); CHECK_MONITOR_PARA(tsSlowLogMaxLen); CHECK_MONITOR_PARA(tsSlowLogScope); + if (0 != strcasecmp(pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb)) { + mError("dnode:%d, tsSlowLogExceptDb:%s inconsistent with cluster:%s", pDnode->id, pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb); + terrno = TSDB_CODE_DNODE_INVALID_MONITOR_PARAS; + return DND_REASON_STATUS_MONITOR_NOT_MATCH; + } + if (pCfg->statusInterval != tsStatusInterval) { mError("dnode:%d, statusInterval:%d inconsistent with cluster:%d", pDnode->id, pCfg->statusInterval, tsStatusInterval); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 0838b44990..4224d79391 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -305,6 +305,8 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { connectRsp.monitorParas.tsSlowLogScope = tsSlowLogScope; connectRsp.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen; connectRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold; + connectRsp.monitorParas.tsSlowLogThresholdTest = tsSlowLogThresholdTest; + tstrncpy(connectRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN); connectRsp.whiteListVer = pUser->ipWhiteListVer; strcpy(connectRsp.sVer, version); @@ -667,6 +669,8 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { batchRsp.monitorParas.tsEnableMonitor = tsEnableMonitor; batchRsp.monitorParas.tsMonitorInterval = tsMonitorInterval; batchRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold; + batchRsp.monitorParas.tsSlowLogThresholdTest = tsSlowLogThresholdTest; + tstrncpy(batchRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN); batchRsp.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen; batchRsp.monitorParas.tsSlowLogScope = tsSlowLogScope; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 80de20f5f5..978dd8ec78 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -371,6 +371,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_ENCRYPTKEY, "invalid encryption ke TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED, "encryption key was changed") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_ENCRYPT_KLEN, "Invalid encryption key length") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_STATUS_INTERVAL,"statusInterval not match") +TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_MONITOR_PARAS, "monitor paras not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_TIMEZONE, "timezone not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_CHARSET, "charset not match") TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_INVALID_LOCALE, "locale not match")