fix:[TD-30769]make monitorInterval effect right now

This commit is contained in:
wangmm0220 2024-06-27 16:05:49 +08:00
parent 4d77d321df
commit e73f6ba47e
2 changed files with 34 additions and 5 deletions

View File

@ -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);

View File

@ -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);
}
}