Merge pull request #19849 from taosdata/fix/TS-2582
fix: setting logKeepDays to -1 result in empty compressed logs.
This commit is contained in:
commit
442c7657ff
|
@ -110,6 +110,8 @@ bool taosValidFile(TdFilePtr pFile);
|
|||
|
||||
int32_t taosGetErrorFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,9 @@ if(CHECK_STR2INT_ERROR)
|
|||
add_definitions(-DTD_CHECK_STR_TO_INT_ERROR)
|
||||
endif()
|
||||
target_link_libraries(
|
||||
os PUBLIC pthread
|
||||
os
|
||||
PUBLIC pthread
|
||||
PUBLIC zlibstatic
|
||||
)
|
||||
if(TD_WINDOWS)
|
||||
target_link_libraries(
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define ALLOW_FORBID_FUNC
|
||||
#include "os.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include <io.h>
|
||||
|
@ -830,3 +831,48 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
|
|||
}
|
||||
|
||||
bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); };
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||
int32_t compressSize = 163840;
|
||||
int32_t ret = 0;
|
||||
int32_t len = 0;
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
gzFile dstFp = NULL;
|
||||
|
||||
TdFilePtr pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (pSrcFile == NULL) {
|
||||
ret = -1;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
ret = -2;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
dstFp = gzdopen(pFile->fd, "wb6f");
|
||||
if (dstFp == NULL) {
|
||||
ret = -3;
|
||||
taosCloseFile(&pFile);
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
while (!feof(pSrcFile->fp)) {
|
||||
len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp);
|
||||
(void)gzwrite(dstFp, data, len);
|
||||
}
|
||||
|
||||
cmp_end:
|
||||
if (pSrcFile) {
|
||||
taosCloseFile(&pSrcFile);
|
||||
}
|
||||
|
||||
if (dstFp) {
|
||||
gzclose(dstFp);
|
||||
}
|
||||
|
||||
taosMemoryFree(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,6 @@ static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t m
|
|||
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
||||
static void taosCloseLogByFd(TdFilePtr pFile);
|
||||
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
|
||||
static int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
static FORCE_INLINE void taosUpdateDaylight() {
|
||||
struct tm Tm, *ptm;
|
||||
|
@ -748,50 +747,6 @@ static void *taosAsyncOutputLog(void *param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||
int32_t compressSize = 163840;
|
||||
int32_t ret = 0;
|
||||
int32_t len = 0;
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
// gzFile dstFp = NULL;
|
||||
|
||||
// srcFp = fopen(srcFileName, "r");
|
||||
TdFilePtr pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ);
|
||||
if (pSrcFile == NULL) {
|
||||
ret = -1;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
ret = -2;
|
||||
goto cmp_end;
|
||||
}
|
||||
|
||||
// dstFp = gzdopen(fd, "wb6f");
|
||||
// if (dstFp == NULL) {
|
||||
// ret = -3;
|
||||
// close(fd);
|
||||
// goto cmp_end;
|
||||
// }
|
||||
//
|
||||
// while (!feof(srcFp)) {
|
||||
// len = (int32_t)fread(data, 1, compressSize, srcFp);
|
||||
// (void)gzwrite(dstFp, data, len);
|
||||
// }
|
||||
|
||||
cmp_end:
|
||||
if (pSrcFile) {
|
||||
taosCloseFile(&pSrcFile);
|
||||
}
|
||||
// if (dstFp) {
|
||||
// gzclose(dstFp);
|
||||
// }
|
||||
taosMemoryFree(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool taosAssertDebug(bool condition, const char *file, int32_t line, const char *format, ...) {
|
||||
if (condition) return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue