From e73f6ba47e44159d606a8cd1f3b32d0554e7760f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 27 Jun 2024 16:05:49 +0800 Subject: [PATCH] fix:[TD-30769]make monitorInterval effect right now --- source/client/src/clientHb.c | 8 ++++++++ source/client/src/clientMonitor.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 19b6655af1..0a480e1cbd 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -19,6 +19,7 @@ #include "scheduler.h" #include "trpc.h" #include "tglobal.h" +#include "clientMonitor.h" typedef struct { union { @@ -546,7 +547,14 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) { } SAppInstInfo *pInst = pAppHbMgr->pAppInstInfo; + int32_t oldInterval = pInst->monitorParas.tsMonitorInterval; pInst->monitorParas = pRsp.monitorParas; + if(oldInterval > pInst->monitorParas.tsMonitorInterval){ + char* value = taosStrdup(""); + if(monitorPutData2MonitorQueue(pInst->clusterId, value) < 0){ + taosMemoryFree(value); + } + } tscDebug("[monitor] paras from hb, clusterId:%" PRIx64 " monitorParas threshold:%d scope:%d", pInst->clusterId, pRsp.monitorParas.tsSlowLogThreshold, pRsp.monitorParas.tsSlowLogScope); diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 3067961696..260a0ebbaa 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -221,8 +221,8 @@ static void reportSendProcess(void* param, void* tmrId) { SEpSet ep = getEpSet_s(&pInst->mgmtEp); generateClusterReport(pMonitor->registry, pInst->pTransporter, &ep); - taosRUnLockLatch(&monitorLock); taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId); + taosRUnLockLatch(&monitorLock); } static void sendAllSlowLog(){ @@ -450,7 +450,7 @@ static void monitorFreeSlowLogData(MonitorSlowLogData* pData) { static void monitorThreadFuncUnexpectedStopped(void) { atomic_store_32(&slowLogFlag, -1); } static void reportSlowLog(void* param, void* tmrId) { - taosRLockLatch(&monitorLock); + taosWLockLatch(&monitorLock); if (atomic_load_32(&monitorFlag) == 1) { taosRUnLockLatch(&monitorLock); return; @@ -471,9 +471,11 @@ static void reportSlowLog(void* param, void* tmrId) { SEpSet ep = getEpSet_s(&pInst->mgmtEp); monitorReadSendSlowLog((*(SlowLogClient**)tmp)->pFile, pInst->pTransporter, &ep); - taosRUnLockLatch(&monitorLock); - taosTmrReset(reportSlowLog, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId); + if((*(SlowLogClient**)tmp)->timer == tmrId){ + taosTmrReset(reportSlowLog, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &(*(SlowLogClient**)tmp)->timer); + } + taosWUnLockLatch(&monitorLock); } static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char *tmpPath){ @@ -535,6 +537,23 @@ FAILED: taosWUnLockLatch(&monitorLock); } +static void restartReportTimer(int64_t clusterId){ + taosWLockLatch(&monitorLock); + + void* tmp = taosHashGet(monitorSlowLogHash, &clusterId, LONG_BYTES); + if(tmp){ + taosTmrStopA(&(*(SlowLogClient**)tmp)->timer); + SAppInstInfo* pInst = getAppInstByClusterId(clusterId); + if(pInst == NULL){ + uError("failed to get app inst, clusterId:%"PRIx64, clusterId); + return; + } + (*(SlowLogClient**)tmp)->timer = taosTmrStart(reportSlowLog, pInst->monitorParas.tsMonitorInterval * 1000, (void*)clusterId, monitorTimer); + + } + taosWUnLockLatch(&monitorLock); +} + static void* monitorThreadFunc(void *param){ setThreadName("client-monitor-slowlog"); @@ -579,7 +598,9 @@ static void* monitorThreadFunc(void *param){ uDebug("[monitor] read slow log data from queue, clusterId:%" PRIx64 " value:%s", slowLogData->clusterId, slowLogData->value); if (slowLogData->value == NULL){ monitorSendAllSlowLogFromTempDir(slowLogData->clusterId); - }else{ + } else if(strlen(slowLogData->value) == 0){ + restartReportTimer(slowLogData->clusterId); + } else{ monitorWriteSlowLog2File(slowLogData, tmpPath); } }