From 8e8437ad4a5ba79bbff5103921502b5de5fdf4d0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 24 Feb 2021 17:22:14 +0800 Subject: [PATCH] [TD-3068]: When the creation of log file fails, the length of old log grows infinitely --- src/os/src/detail/osFile.c | 9 ++++++--- src/sync/src/syncRetrieve.c | 5 +++-- src/util/src/tlog.c | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 0b7b5ca487..538ed37879 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -25,7 +25,8 @@ void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { char tmpPath[PATH_MAX]; int32_t len = strlen(tsTempDir); memcpy(tmpPath, tsTempDir, len); - + static uint64_t seqId = 0; + if (tmpPath[len - 1] != '/') { tmpPath[len++] = '/'; } @@ -36,8 +37,10 @@ void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { strcat(tmpPath, "-%d-%s"); } - char rand[8] = {0}; - taosRandStr(rand, tListLen(rand) - 1); + char rand[32] = {0}; + + sprintf(rand, "%"PRIu64, atomic_add_fetch_64(&seqId, 1)); + snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); } diff --git a/src/sync/src/syncRetrieve.c b/src/sync/src/syncRetrieve.c index ec4bbb33a5..17513258b1 100644 --- a/src/sync/src/syncRetrieve.c +++ b/src/sync/src/syncRetrieve.c @@ -202,7 +202,7 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi break; } - sDebug("%s, last wal is forwarded, hver:%" PRIu64, pPeer->id, pHead->version); + sTrace("%s, last wal is forwarded, hver:%" PRIu64, pPeer->id, pHead->version); int32_t wsize = code; int32_t ret = taosWriteMsg(pPeer->syncFd, pHead, wsize); @@ -245,7 +245,7 @@ static int32_t syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index) int32_t bytes = syncRetrieveLastWal(pPeer, fname, fversion, offset); if (bytes < 0) { - sDebug("%s, failed to retrieve last wal", pPeer->id); + sDebug("%s, failed to retrieve last wal, bytes:%d", pPeer->id, bytes); return bytes; } @@ -309,6 +309,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) { if (code == 0) { // last wal code = syncProcessLastWal(pPeer, wname, index); + sInfo("%s, last wal processed, code:%d", pPeer->id, code); break; } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index e0fe51e22a..ae12e25d56 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -171,7 +171,9 @@ static void *taosThreadToOpenNewFile(void *param) { int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { - uError("open new log file fail! fd:%d reason:%s", fd, strerror(errno)); + tsLogObj.openInProgress = 0; + tsLogObj.lines = tsLogObj.maxLines - 1000; + uError("open new log file fail! fd:%d reason:%s, reuse lastlog", fd, strerror(errno)); return NULL; } -- GitLab