Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d627ab2a
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d627ab2a
编写于
9月 23, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1574
上级
96553e78
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
63 addition
and
8 deletion
+63
-8
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-1
src/os/inc/osDir.h
src/os/inc/osDir.h
+1
-0
src/os/src/detail/CMakeLists.txt
src/os/src/detail/CMakeLists.txt
+1
-0
src/os/src/detail/osDir.c
src/os/src/detail/osDir.c
+49
-4
src/util/CMakeLists.txt
src/util/CMakeLists.txt
+1
-1
src/util/src/tlog.c
src/util/src/tlog.c
+10
-2
未找到文件。
src/common/src/tglobal.c
浏览文件 @
d627ab2a
...
...
@@ -1014,7 +1014,7 @@ static void doInitGlobalConfig(void) {
cfg
.
ptr
=
&
tsLogKeepDays
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_LOG
|
TSDB_CFG_CTYPE_B_CLIENT
;
cfg
.
minValue
=
0
;
cfg
.
minValue
=
-
36500
0
;
cfg
.
maxValue
=
365000
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
...
...
src/os/inc/osDir.h
浏览文件 @
d627ab2a
...
...
@@ -25,6 +25,7 @@ void taosRemoveDir(char *rootDir);
int
taosMkDir
(
const
char
*
pathname
,
mode_t
mode
);
void
taosRename
(
char
*
oldName
,
char
*
newName
);
void
taosRemoveOldLogFiles
(
char
*
rootDir
,
int32_t
keepDays
);
int32_t
taosCompressFile
(
char
*
srcFileName
,
char
*
destFileName
);
#ifdef __cplusplus
}
...
...
src/os/src/detail/CMakeLists.txt
浏览文件 @
d627ab2a
...
...
@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT
(
TDengine
)
INCLUDE_DIRECTORIES
(
.
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/deps/zlib-1.2.11/inc
)
AUX_SOURCE_DIRECTORY
(
. SRC
)
SET_SOURCE_FILES_PROPERTIES
(
osSysinfo.c PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
osCoredump.c PROPERTIES COMPILE_FLAGS -w
)
...
...
src/os/src/detail/osDir.c
浏览文件 @
d627ab2a
...
...
@@ -17,6 +17,9 @@
#include "os.h"
#include "tglobal.h"
#include "tulog.h"
#include "zlib.h"
#define COMPRESS_STEP_SIZE 163840
void
taosRemoveDir
(
char
*
rootDir
)
{
DIR
*
dir
=
opendir
(
rootDir
);
...
...
@@ -73,11 +76,11 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
if
(
de
->
d_type
&
DT_DIR
)
{
continue
;
}
else
{
// struct stat fState;
// if (stat(fname, &fState) < 0) {
// continue;
// }
int32_t
len
=
(
int32_t
)
strlen
(
filename
);
if
(
len
>
3
&&
strcmp
(
filename
+
len
-
3
,
".gz"
)
==
0
)
{
len
-=
3
;
}
int64_t
fileSec
=
0
;
for
(
int
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
if
(
filename
[
i
]
==
'.'
)
{
...
...
@@ -100,3 +103,45 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
closedir
(
dir
);
rmdir
(
rootDir
);
}
int32_t
taosCompressFile
(
char
*
srcFileName
,
char
*
destFileName
)
{
int32_t
ret
=
0
;
int32_t
len
=
0
;
char
*
data
=
malloc
(
COMPRESS_STEP_SIZE
);
FILE
*
srcFp
=
NULL
;
gzFile
dstFp
=
NULL
;
srcFp
=
fopen
(
srcFileName
,
"r"
);
if
(
srcFp
==
NULL
)
{
ret
=
-
1
;
goto
cmp_end
;
}
int32_t
fd
=
open
(
destFileName
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
ret
=
-
2
;
goto
cmp_end
;
}
dstFp
=
gzdopen
(
fd
,
"wb6f"
);
if
(
dstFp
==
NULL
)
{
ret
=
-
3
;
goto
cmp_end
;
}
while
(
!
feof
(
srcFp
))
{
len
=
(
uLong
)
fread
(
data
,
1
,
COMPRESS_STEP_SIZE
,
srcFp
);
gzwrite
(
dstFp
,
data
,
len
);
}
cmp_end:
if
(
srcFp
)
{
fclose
(
srcFp
);
}
if
(
dstFp
)
{
gzclose
(
dstFp
);
}
free
(
data
);
return
ret
;
}
src/util/CMakeLists.txt
浏览文件 @
d627ab2a
...
...
@@ -3,7 +3,7 @@ PROJECT(TDengine)
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_LIBRARY
(
tutil
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tutil pthread osdetail lz4
)
TARGET_LINK_LIBRARIES
(
tutil pthread osdetail lz4
z
)
IF
(
TD_LINUX
)
TARGET_LINK_LIBRARIES
(
tutil m rt
)
...
...
src/util/src/tlog.c
浏览文件 @
d627ab2a
...
...
@@ -139,14 +139,22 @@ static void taosUnLockFile(int32_t fd) {
}
static
void
taosKeepOldLog
(
char
*
oldName
)
{
if
(
tsLogKeepDays
<
=
0
)
return
;
if
(
tsLogKeepDays
=
=
0
)
return
;
int64_t
fileSec
=
taosGetTimestampSec
();
char
fileName
[
LOG_FILE_NAME_LEN
+
20
];
snprintf
(
fileName
,
LOG_FILE_NAME_LEN
+
20
,
"%s.%"
PRId64
,
tsLogObj
.
logName
,
fileSec
);
taosRename
(
oldName
,
fileName
);
taosRemoveOldLogFiles
(
tsLogDir
,
tsLogKeepDays
);
if
(
tsLogKeepDays
<
0
)
{
char
compressFileName
[
LOG_FILE_NAME_LEN
+
20
];
snprintf
(
compressFileName
,
LOG_FILE_NAME_LEN
+
20
,
"%s.%"
PRId64
".gz"
,
tsLogObj
.
logName
,
fileSec
);
if
(
taosCompressFile
(
fileName
,
compressFileName
)
==
0
)
{
(
void
)
remove
(
fileName
);
}
}
taosRemoveOldLogFiles
(
tsLogDir
,
ABS
(
tsLogKeepDays
));
}
static
void
*
taosThreadToOpenNewFile
(
void
*
param
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录