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

This commit is contained in:
wangmm0220 2024-07-01 19:20:06 +08:00
parent a17ff3dbf5
commit ce77caa663
1 changed files with 9 additions and 3 deletions

View File

@ -401,7 +401,7 @@ static char* readFile(TdFilePtr pFile, int64_t *offset, bool* isEnd){
if (readLen <= 0) { if (readLen <= 0) {
if (readLen < 0) { if (readLen < 0) {
uError("failed to read len from file:%p since %s", pFile, terrstr()); uError("failed to read len from file:%p since %s", pFile, terrstr());
}else{ }else if(totalSize == 0){
*isEnd = true; *isEnd = true;
} }
break; break;
@ -414,6 +414,10 @@ static char* readFile(TdFilePtr pFile, int64_t *offset, bool* isEnd){
strcat(pCont, "]"); strcat(pCont, "]");
uDebug("[monitor] monitorReadSendSlowLog slow log:%s", pCont); uDebug("[monitor] monitorReadSendSlowLog slow log:%s", pCont);
*offset += totalSize; *offset += totalSize;
if(*isEnd){
taosMemoryFree(pCont);
return NULL;
}
return pCont; return pCont;
} }
@ -450,7 +454,9 @@ static void monitorSendSlowLogAtBeginning(int64_t clusterId, char* fileName, TdF
taosRemoveFile(fileName); taosRemoveFile(fileName);
uDebug("[monitor] monitorSendSlowLogAtBeginning delete file:%s", fileName); uDebug("[monitor] monitorSendSlowLogAtBeginning delete file:%s", fileName);
}else{ }else{
sendSlowLog(clusterId, data, pFile, offset, SLOW_LOG_READ_BEGINNIG, taosStrdup(fileName), pTransporter, epSet); if(data != NULL){
sendSlowLog(clusterId, data, pFile, offset, SLOW_LOG_READ_BEGINNIG, taosStrdup(fileName), pTransporter, epSet);
}
uDebug("[monitor] monitorSendSlowLogAtBeginning send slow log file:%p", pFile); uDebug("[monitor] monitorSendSlowLogAtBeginning send slow log file:%p", pFile);
} }
} }
@ -534,7 +540,7 @@ static void monitorSendAllSlowLog(){
bool isEnd = false; bool isEnd = false;
int64_t offset = 0; int64_t offset = 0;
char* data = readFile(pClient->pFile, &offset, &isEnd); char* data = readFile(pClient->pFile, &offset, &isEnd);
if(data){ if(data != NULL){
sendSlowLog(*clusterId, data, NULL, offset, SLOW_LOG_READ_RUNNING, NULL, pInst->pTransporter, &ep); sendSlowLog(*clusterId, data, NULL, offset, SLOW_LOG_READ_RUNNING, NULL, pInst->pTransporter, &ep);
} }
uDebug("[monitor] monitorSendAllSlowLog send slow log :%s", data); uDebug("[monitor] monitorSendAllSlowLog send slow log :%s", data);