fix: write crash log

This commit is contained in:
factosea 2025-01-09 16:02:11 +08:00
parent 1e269c8dd6
commit 852f5b6fa4
3 changed files with 15 additions and 15 deletions

View File

@ -815,12 +815,6 @@ static void *tscCrashReportThreadFp(void *param) {
int32_t reportPeriodNum = 3600 * 1000 / sleepTime;
int32_t loopTimes = reportPeriodNum;
code = initCrashLogWriter();
if (code) {
tscError("failed to init crash log writer, code:%s", tstrerror(code));
return NULL;
}
#ifdef WINDOWS
if (taosCheckCurrentInDll()) {
atexit(crashReportThreadFuncUnexpectedStopped);
@ -837,6 +831,12 @@ static void *tscCrashReportThreadFp(void *param) {
return NULL;
}
code = initCrashLogWriter();
if (code) {
tscError("failed to init crash log writer, code:%s", tstrerror(code));
return NULL;
}
while (1) {
checkAndPrepareCrashInfo();
if (clientStop > 0) break;

View File

@ -231,6 +231,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t
TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashSig", signum), NULL, _exit);
TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs()), NULL, _exit);
#if 0
#ifdef _TD_DARWIN_64
taosLogTraceToBuf(tmp, sizeof(tmp), 4);
#elif !defined(WINDOWS)
@ -240,7 +241,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t
#endif
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "stackInfo", tmp), NULL, _exit);
#endif
char* pCont = tjsonToString(pJson);
if (pCont == NULL) {
code = terrno;

View File

@ -1317,29 +1317,28 @@ void checkAndPrepareCrashInfo() {
}
int32_t initCrashLogWriter() {
gCrashBasicInfo.init = true;
gCrashBasicInfo.isCrash = false;
int32_t code = tsem_init(&gCrashBasicInfo.sem, 0, 0);
uInfo("crashLogWriter init finished.");
if (code != 0) {
uError("failed to init sem for crashLogWriter, code:%d", code);
return code;
}
gCrashBasicInfo.isCrash = false;
gCrashBasicInfo.init = true;
return code;
}
void writeCrashLogToFile(int signum, void *sigInfo, char *nodeType, int64_t clusterId, int64_t startTime) {
if (!gCrashBasicInfo.init) {
uInfo("crashLogWriter has not init!");
return;
}
uInfo("write crash log to file, signum:%d, nodeType:%s, clusterId:%" PRId64, signum, nodeType, clusterId);
gCrashBasicInfo.isCrash = true;
gCrashBasicInfo.clusterId = clusterId;
gCrashBasicInfo.startTime = startTime;
gCrashBasicInfo.nodeType = nodeType;
gCrashBasicInfo.signum = signum;
gCrashBasicInfo.sigInfo = sigInfo;
gCrashBasicInfo.isCrash = true;
tsem_wait(&gCrashBasicInfo.sem);
uInfo("write crash log to file done, signum:%d, nodeType:%s, clusterId:%" PRId64, signum, nodeType, clusterId);
}
void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd) {