fix(tsdb/commit): make commit failing core in release buildings

This commit is contained in:
Minglei Jin 2024-07-03 16:40:54 +08:00
parent 71af880554
commit 0fa44fe8cf
3 changed files with 25 additions and 17 deletions

View File

@ -88,11 +88,11 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
void taosPrintSlowLog(const char *format, ...) void taosPrintSlowLog(const char *format, ...)
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 1, 2))) __attribute__((format(printf, 1, 2)))
#endif #endif
; ;
bool taosAssertDebug(bool condition, const char *file, int32_t line, const char *format, ...); bool taosAssertDebug(bool condition, const char *file, int32_t line, bool core, const char *format, ...);
bool taosAssertRelease(bool condition); bool taosAssertRelease(bool condition);
// Disable all asserts that may compromise the performance. // Disable all asserts that may compromise the performance.
@ -100,7 +100,9 @@ bool taosAssertRelease(bool condition);
#define ASSERT(condition) #define ASSERT(condition)
#define ASSERTS(condition, ...) (0) #define ASSERTS(condition, ...) (0)
#else #else
#define ASSERTS(condition, ...) ((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, __VA_ARGS__)) #define ASSERT_CORE(condition, ...) \
((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 1, __VA_ARGS__))
#define ASSERTS(condition, ...) ((condition) ? false : taosAssertDebug(condition, __FILE__, __LINE__, 0, __VA_ARGS__))
#ifdef NDEBUG #ifdef NDEBUG
#define ASSERT(condition) taosAssertRelease(condition) #define ASSERT(condition) taosAssertRelease(condition)
#else #else
@ -108,9 +110,9 @@ bool taosAssertRelease(bool condition);
#endif #endif
#endif #endif
void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo); void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo);
void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd); void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd);
void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile); void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile);
// clang-format off // clang-format off
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} #define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}

View File

@ -715,7 +715,7 @@ _exit:
int32_t tsdbPreCommit(STsdb *tsdb) { int32_t tsdbPreCommit(STsdb *tsdb) {
taosThreadMutexLock(&tsdb->mutex); taosThreadMutexLock(&tsdb->mutex);
ASSERT(tsdb->imem == NULL); ASSERT_CORE(tsdb->imem == NULL, "imem should be null to commit mem");
tsdb->imem = tsdb->mem; tsdb->imem = tsdb->mem;
tsdb->mem = NULL; tsdb->mem = NULL;
taosThreadMutexUnlock(&tsdb->mutex); taosThreadMutexUnlock(&tsdb->mutex);
@ -825,4 +825,4 @@ _exit:
tsdbInfo("vgId:%d %s done", TD_VID(pTsdb->pVnode), __func__); tsdbInfo("vgId:%d %s done", TD_VID(pTsdb->pVnode), __func__);
} }
return code; return code;
} }

View File

@ -164,7 +164,10 @@ int32_t taosInitSlowLog() {
if (strlen(tsLogDir) != 0) { if (strlen(tsLogDir) != 0) {
char lastC = tsLogDir[strlen(tsLogDir) - 1]; char lastC = tsLogDir[strlen(tsLogDir) - 1];
if (lastC == '\\' || lastC == '/') { if (lastC == '\\' || lastC == '/') {
snprintf(fullName, PATH_MAX, "%s" "%s", tsLogDir, logFileName); snprintf(fullName, PATH_MAX,
"%s"
"%s",
tsLogDir, logFileName);
} else { } else {
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logFileName); snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logFileName);
} }
@ -193,7 +196,10 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles) {
if (strlen(tsLogDir) != 0) { if (strlen(tsLogDir) != 0) {
char lastC = tsLogDir[strlen(tsLogDir) - 1]; char lastC = tsLogDir[strlen(tsLogDir) - 1];
if (lastC == '\\' || lastC == '/') { if (lastC == '\\' || lastC == '/') {
snprintf(fullName, PATH_MAX, "%s" "%s", tsLogDir, logName); snprintf(fullName, PATH_MAX,
"%s"
"%s",
tsLogDir, logName);
} else { } else {
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName); snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName);
} }
@ -344,9 +350,9 @@ static OldFileKeeper *taosOpenNewFile() {
return oldFileKeeper; return oldFileKeeper;
} }
static void *taosThreadToCloseOldFile(void* param) { static void *taosThreadToCloseOldFile(void *param) {
if(!param) return NULL; if (!param) return NULL;
OldFileKeeper* oldFileKeeper = (OldFileKeeper*)param; OldFileKeeper *oldFileKeeper = (OldFileKeeper *)param;
taosSsleep(20); taosSsleep(20);
taosCloseLogByFd(oldFileKeeper->pOldFile); taosCloseLogByFd(oldFileKeeper->pOldFile);
taosKeepOldLog(oldFileKeeper->keepName); taosKeepOldLog(oldFileKeeper->keepName);
@ -366,7 +372,7 @@ static int32_t taosOpenNewLogFile() {
taosThreadAttrInit(&attr); taosThreadAttrInit(&attr);
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED); taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED);
OldFileKeeper* oldFileKeeper = taosOpenNewFile(); OldFileKeeper *oldFileKeeper = taosOpenNewFile();
taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper); taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper);
taosThreadAttrDestroy(&attr); taosThreadAttrDestroy(&attr);
} }
@ -856,7 +862,7 @@ static void *taosAsyncOutputLog(void *param) {
return NULL; return NULL;
} }
bool taosAssertDebug(bool condition, const char *file, int32_t line, const char *format, ...) { bool taosAssertDebug(bool condition, const char *file, int32_t line, bool core, const char *format, ...) {
if (condition) return false; if (condition) return false;
const char *flags = "UTL FATAL "; const char *flags = "UTL FATAL ";
@ -876,7 +882,7 @@ bool taosAssertDebug(bool condition, const char *file, int32_t line, const char
taosPrintLog(flags, level, dflag, "tAssert at file %s:%d exit:%d", file, line, tsAssert); taosPrintLog(flags, level, dflag, "tAssert at file %s:%d exit:%d", file, line, tsAssert);
taosPrintTrace(flags, level, dflag, -1); taosPrintTrace(flags, level, dflag, -1);
if (tsAssert) { if (tsAssert || core) {
taosCloseLog(); taosCloseLog();
taosMsleep(300); taosMsleep(300);