fix:[TS-4921]refactor reporting logic for slow log

This commit is contained in:
wangmm0220 2024-07-02 15:07:29 +08:00
parent 65696ce97f
commit 595c3f8e07
1 changed files with 19 additions and 13 deletions

View File

@ -529,7 +529,7 @@ static bool monitorSendSlowLogAtQuit(int64_t clusterId) {
} }
return false; return false;
} }
static void monitorSendAllSlowLogAtQuit(){ static void monitorSendAllSlowLogAtQuit(){
void* pIter = NULL; void* pIter = NULL;
while ((pIter = taosHashIterate(monitorSlowLogHash, pIter))) { while ((pIter = taosHashIterate(monitorSlowLogHash, pIter))) {
SlowLogClient* pClient = (*(SlowLogClient**)pIter); SlowLogClient* pClient = (*(SlowLogClient**)pIter);
@ -537,20 +537,26 @@ static void monitorSendAllSlowLogAtQuit(){
taosHashCancelIterate(monitorSlowLogHash, pIter); taosHashCancelIterate(monitorSlowLogHash, pIter);
return; return;
} }
int64_t* clusterId = (int64_t*)taosHashGetKey(pIter, NULL);
SAppInstInfo* pInst = getAppInstByClusterId(*clusterId);
if(pInst == NULL) {
taosHashCancelIterate(monitorSlowLogHash, pIter);
return;
}
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
int64_t offset = 0;
int64_t size = getFileSize(pClient->path); int64_t size = getFileSize(pClient->path);
char* data = readFile(pClient->pFile, &offset, size); if(size <= pClient->offset){
if(data != NULL && sendSlowLog(*clusterId, data, NULL, offset, SLOW_LOG_READ_QUIT, NULL, pInst->pTransporter, &ep) == 0){ taosUnLockFile(pClient->pFile);
quitCnt ++; taosCloseFile(&(pClient->pFile));
taosRemoveFile(pClient->path);
}else{
int64_t* clusterId = (int64_t*)taosHashGetKey(pIter, NULL);
SAppInstInfo* pInst = getAppInstByClusterId(*clusterId);
if(pInst == NULL) {
taosHashCancelIterate(monitorSlowLogHash, pIter);
return;
}
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
int64_t offset = 0;
char* data = readFile(pClient->pFile, &offset, size);
if(data != NULL && sendSlowLog(*clusterId, data, NULL, offset, SLOW_LOG_READ_QUIT, NULL, pInst->pTransporter, &ep) == 0){
quitCnt ++;
}
uDebug("[monitor] monitorSendAllSlowLogAtQuit send slow log :%s", data);
} }
uDebug("[monitor] monitorSendAllSlowLogAtQuit send slow log :%s", data);
} }
} }