Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0d262b87
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d262b87
编写于
4月 18, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: definite lost in tlog.c found by valgrind
上级
884bf377
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
92 addition
and
85 deletion
+92
-85
include/os/osMemory.h
include/os/osMemory.h
+6
-6
source/client/src/clientMain.c
source/client/src/clientMain.c
+1
-1
source/util/src/tlog.c
source/util/src/tlog.c
+85
-78
未找到文件。
include/os/osMemory.h
浏览文件 @
0d262b87
...
...
@@ -39,7 +39,7 @@ int32_t taosMemorySize(void *ptr);
#define taosMemoryFreeClear(ptr) \
do { \
if (ptr) { \
taosMemoryFree((void
*)ptr);
\
taosMemoryFree((void
*)ptr);
\
(ptr) = NULL; \
} \
} while (0)
...
...
source/client/src/clientMain.c
浏览文件 @
0d262b87
...
...
@@ -69,9 +69,9 @@ void taos_cleanup(void) {
rpcCleanup
();
catalogDestroy
();
schedulerDestroy
();
taosCloseLog
();
tscInfo
(
"all local resources released"
);
taosCloseLog
();
}
setConfRet
taos_set_config
(
const
char
*
config
)
{
...
...
source/util/src/tlog.c
浏览文件 @
0d262b87
...
...
@@ -47,7 +47,6 @@ typedef struct {
int32_t
stop
;
TdThread
asyncThread
;
TdThreadMutex
buffMutex
;
tsem_t
buffNotEmpty
;
}
SLogBuff
;
typedef
struct
{
...
...
@@ -100,7 +99,7 @@ int64_t dbgBigWN = 0;
int64_t
dbgWSize
=
0
;
static
void
*
taosAsyncOutputLog
(
void
*
param
);
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuf
f
,
const
char
*
msg
,
int32_t
msgLen
);
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
pLogBu
f
,
const
char
*
msg
,
int32_t
msgLen
);
static
SLogBuff
*
taosLogBuffNew
(
int32_t
bufSize
);
static
void
taosCloseLogByFd
(
TdFilePtr
pFile
);
static
int32_t
taosOpenLogFile
(
char
*
fn
,
int32_t
maxLines
,
int32_t
maxFileNum
);
...
...
@@ -136,16 +135,24 @@ static void taosStopLog() {
}
}
static
void
taosLogBuffDestroy
()
{
taosThreadMutexDestroy
(
&
tsLogObj
.
logHandle
->
buffMutex
);
taosCloseFile
(
&
tsLogObj
.
logHandle
->
pFile
);
taosMemoryFreeClear
(
tsLogObj
.
logHandle
->
buffer
);
memset
(
&
tsLogObj
.
logHandle
->
buffer
,
0
,
sizeof
(
tsLogObj
.
logHandle
->
buffer
));
taosThreadMutexDestroy
(
&
tsLogObj
.
logMutex
);
taosMemoryFreeClear
(
tsLogObj
.
logHandle
);
memset
(
&
tsLogObj
.
logHandle
,
0
,
sizeof
(
tsLogObj
.
logHandle
));
tsLogObj
.
logHandle
=
NULL
;
}
void
taosCloseLog
()
{
taosStopLog
();
if
(
taosCheckPthreadValid
(
tsLogObj
.
logHandle
->
asyncThread
))
{
taosThreadJoin
(
tsLogObj
.
logHandle
->
asyncThread
,
NULL
);
}
tsLogInited
=
0
;
// In case that other threads still use log resources causing invalid write in valgrind
// we comment two lines below.
// taosLogBuffDestroy(tsLogObj.logHandle);
// taosCloseLog();
taosLogBuffDestroy
(
tsLogObj
.
logHandle
);
}
static
bool
taosLockLogFile
(
TdFilePtr
pFile
)
{
...
...
@@ -506,45 +513,45 @@ static void taosCloseLogByFd(TdFilePtr pFile) {
}
static
SLogBuff
*
taosLogBuffNew
(
int32_t
bufSize
)
{
SLogBuff
*
tLogBuf
f
=
NULL
;
SLogBuff
*
pLogBu
f
=
NULL
;
tLogBuf
f
=
taosMemoryCalloc
(
1
,
sizeof
(
SLogBuff
));
if
(
tLogBuf
f
==
NULL
)
return
NULL
;
pLogBu
f
=
taosMemoryCalloc
(
1
,
sizeof
(
SLogBuff
));
if
(
pLogBu
f
==
NULL
)
return
NULL
;
LOG_BUF_BUFFER
(
tLogBuf
f
)
=
taosMemoryMalloc
(
bufSize
);
if
(
LOG_BUF_BUFFER
(
tLogBuf
f
)
==
NULL
)
goto
_err
;
LOG_BUF_BUFFER
(
pLogBu
f
)
=
taosMemoryMalloc
(
bufSize
);
if
(
LOG_BUF_BUFFER
(
pLogBu
f
)
==
NULL
)
goto
_err
;
LOG_BUF_START
(
tLogBuff
)
=
LOG_BUF_END
(
tLogBuf
f
)
=
0
;
LOG_BUF_SIZE
(
tLogBuf
f
)
=
bufSize
;
tLogBuf
f
->
minBuffSize
=
bufSize
/
10
;
tLogBuf
f
->
stop
=
0
;
LOG_BUF_START
(
pLogBuf
)
=
LOG_BUF_END
(
pLogBu
f
)
=
0
;
LOG_BUF_SIZE
(
pLogBu
f
)
=
bufSize
;
pLogBu
f
->
minBuffSize
=
bufSize
/
10
;
pLogBu
f
->
stop
=
0
;
if
(
taosThreadMutexInit
(
&
LOG_BUF_MUTEX
(
tLogBuf
f
),
NULL
)
<
0
)
goto
_err
;
// tsem_init(&(
tLogBuf
f->buffNotEmpty), 0, 0);
if
(
taosThreadMutexInit
(
&
LOG_BUF_MUTEX
(
pLogBu
f
),
NULL
)
<
0
)
goto
_err
;
// tsem_init(&(
pLogBu
f->buffNotEmpty), 0, 0);
return
tLogBuf
f
;
return
pLogBu
f
;
_err:
taosMemoryFreeClear
(
LOG_BUF_BUFFER
(
tLogBuf
f
));
taosMemoryFreeClear
(
tLogBuf
f
);
taosMemoryFreeClear
(
LOG_BUF_BUFFER
(
pLogBu
f
));
taosMemoryFreeClear
(
pLogBu
f
);
return
NULL
;
}
static
void
taosCopyLogBuffer
(
SLogBuff
*
tLogBuf
f
,
int32_t
start
,
int32_t
end
,
const
char
*
msg
,
int32_t
msgLen
)
{
static
void
taosCopyLogBuffer
(
SLogBuff
*
pLogBu
f
,
int32_t
start
,
int32_t
end
,
const
char
*
msg
,
int32_t
msgLen
)
{
if
(
start
>
end
)
{
memcpy
(
LOG_BUF_BUFFER
(
tLogBuf
f
)
+
end
,
msg
,
msgLen
);
memcpy
(
LOG_BUF_BUFFER
(
pLogBu
f
)
+
end
,
msg
,
msgLen
);
}
else
{
if
(
LOG_BUF_SIZE
(
tLogBuf
f
)
-
end
<
msgLen
)
{
memcpy
(
LOG_BUF_BUFFER
(
tLogBuff
)
+
end
,
msg
,
LOG_BUF_SIZE
(
tLogBuf
f
)
-
end
);
memcpy
(
LOG_BUF_BUFFER
(
tLogBuff
),
msg
+
LOG_BUF_SIZE
(
tLogBuff
)
-
end
,
msgLen
-
LOG_BUF_SIZE
(
tLogBuf
f
)
+
end
);
if
(
LOG_BUF_SIZE
(
pLogBu
f
)
-
end
<
msgLen
)
{
memcpy
(
LOG_BUF_BUFFER
(
pLogBuf
)
+
end
,
msg
,
LOG_BUF_SIZE
(
pLogBu
f
)
-
end
);
memcpy
(
LOG_BUF_BUFFER
(
pLogBuf
),
msg
+
LOG_BUF_SIZE
(
pLogBuf
)
-
end
,
msgLen
-
LOG_BUF_SIZE
(
pLogBu
f
)
+
end
);
}
else
{
memcpy
(
LOG_BUF_BUFFER
(
tLogBuf
f
)
+
end
,
msg
,
msgLen
);
memcpy
(
LOG_BUF_BUFFER
(
pLogBu
f
)
+
end
,
msg
,
msgLen
);
}
}
LOG_BUF_END
(
tLogBuff
)
=
(
LOG_BUF_END
(
tLogBuff
)
+
msgLen
)
%
LOG_BUF_SIZE
(
tLogBuf
f
);
LOG_BUF_END
(
pLogBuf
)
=
(
LOG_BUF_END
(
pLogBuf
)
+
msgLen
)
%
LOG_BUF_SIZE
(
pLogBu
f
);
}
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuf
f
,
const
char
*
msg
,
int32_t
msgLen
)
{
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
pLogBu
f
,
const
char
*
msg
,
int32_t
msgLen
)
{
int32_t
start
=
0
;
int32_t
end
=
0
;
int32_t
remainSize
=
0
;
...
...
@@ -552,13 +559,13 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
char
tmpBuf
[
40
]
=
{
0
};
int32_t
tmpBufLen
=
0
;
if
(
tLogBuff
==
NULL
||
tLogBuf
f
->
stop
)
return
-
1
;
if
(
pLogBuf
==
NULL
||
pLogBu
f
->
stop
)
return
-
1
;
taosThreadMutexLock
(
&
LOG_BUF_MUTEX
(
tLogBuf
f
));
start
=
LOG_BUF_START
(
tLogBuf
f
);
end
=
LOG_BUF_END
(
tLogBuf
f
);
taosThreadMutexLock
(
&
LOG_BUF_MUTEX
(
pLogBu
f
));
start
=
LOG_BUF_START
(
pLogBu
f
);
end
=
LOG_BUF_END
(
pLogBu
f
);
remainSize
=
(
start
>
end
)
?
(
start
-
end
-
1
)
:
(
start
+
LOG_BUF_SIZE
(
tLogBuf
f
)
-
end
-
1
);
remainSize
=
(
start
>
end
)
?
(
start
-
end
-
1
)
:
(
start
+
LOG_BUF_SIZE
(
pLogBu
f
)
-
end
-
1
);
if
(
lostLine
>
0
)
{
sprintf
(
tmpBuf
,
"...Lost %"
PRId64
" lines here...
\n
"
,
lostLine
);
...
...
@@ -568,47 +575,47 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms
if
(
remainSize
<=
msgLen
||
((
lostLine
>
0
)
&&
(
remainSize
<=
(
msgLen
+
tmpBufLen
))))
{
lostLine
++
;
tsAsyncLogLostLines
++
;
taosThreadMutexUnlock
(
&
LOG_BUF_MUTEX
(
tLogBuf
f
));
taosThreadMutexUnlock
(
&
LOG_BUF_MUTEX
(
pLogBu
f
));
return
-
1
;
}
if
(
lostLine
>
0
)
{
taosCopyLogBuffer
(
tLogBuf
f
,
start
,
end
,
tmpBuf
,
tmpBufLen
);
taosCopyLogBuffer
(
pLogBu
f
,
start
,
end
,
tmpBuf
,
tmpBufLen
);
lostLine
=
0
;
}
taosCopyLogBuffer
(
tLogBuff
,
LOG_BUF_START
(
tLogBuff
),
LOG_BUF_END
(
tLogBuf
f
),
msg
,
msgLen
);
taosCopyLogBuffer
(
pLogBuf
,
LOG_BUF_START
(
pLogBuf
),
LOG_BUF_END
(
pLogBu
f
),
msg
,
msgLen
);
// int32_t w = atomic_sub_fetch_32(&waitLock, 1);
/*
if (w <= 0 || ((remainSize - msgLen - tmpBufLen) < (LOG_BUF_SIZE(
tLogBuf
f) * 4 /5))) {
tsem_post(&(
tLogBuf
f->buffNotEmpty));
if (w <= 0 || ((remainSize - msgLen - tmpBufLen) < (LOG_BUF_SIZE(
pLogBu
f) * 4 /5))) {
tsem_post(&(
pLogBu
f->buffNotEmpty));
dbgPostN++;
} else {
dbgNoPostN++;
}
*/
taosThreadMutexUnlock
(
&
LOG_BUF_MUTEX
(
tLogBuf
f
));
taosThreadMutexUnlock
(
&
LOG_BUF_MUTEX
(
pLogBu
f
));
return
0
;
}
static
int32_t
taosGetLogRemainSize
(
SLogBuff
*
tLogBuf
f
,
int32_t
start
,
int32_t
end
)
{
static
int32_t
taosGetLogRemainSize
(
SLogBuff
*
pLogBu
f
,
int32_t
start
,
int32_t
end
)
{
int32_t
rSize
=
end
-
start
;
return
rSize
>=
0
?
rSize
:
LOG_BUF_SIZE
(
tLogBuf
f
)
+
rSize
;
return
rSize
>=
0
?
rSize
:
LOG_BUF_SIZE
(
pLogBu
f
)
+
rSize
;
}
static
void
taosWriteLog
(
SLogBuff
*
tLogBuf
f
)
{
static
void
taosWriteLog
(
SLogBuff
*
pLogBu
f
)
{
static
int32_t
lastDuration
=
0
;
int32_t
remainChecked
=
0
;
int32_t
start
,
end
,
pollSize
;
do
{
if
(
remainChecked
==
0
)
{
start
=
LOG_BUF_START
(
tLogBuf
f
);
end
=
LOG_BUF_END
(
tLogBuf
f
);
start
=
LOG_BUF_START
(
pLogBu
f
);
end
=
LOG_BUF_END
(
pLogBu
f
);
if
(
start
==
end
)
{
dbgEmptyW
++
;
...
...
@@ -616,8 +623,8 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
return
;
}
pollSize
=
taosGetLogRemainSize
(
tLogBuf
f
,
start
,
end
);
if
(
pollSize
<
tLogBuf
f
->
minBuffSize
)
{
pollSize
=
taosGetLogRemainSize
(
pLogBu
f
,
start
,
end
);
if
(
pollSize
<
pLogBu
f
->
minBuffSize
)
{
lastDuration
+=
tsWriteInterval
;
if
(
lastDuration
<
LOG_MAX_WAIT_MSEC
)
{
break
;
...
...
@@ -628,38 +635,38 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
}
if
(
start
<
end
)
{
taosWriteFile
(
tLogBuff
->
pFile
,
LOG_BUF_BUFFER
(
tLogBuf
f
)
+
start
,
pollSize
);
taosWriteFile
(
pLogBuf
->
pFile
,
LOG_BUF_BUFFER
(
pLogBu
f
)
+
start
,
pollSize
);
}
else
{
int32_t
tsize
=
LOG_BUF_SIZE
(
tLogBuf
f
)
-
start
;
taosWriteFile
(
tLogBuff
->
pFile
,
LOG_BUF_BUFFER
(
tLogBuf
f
)
+
start
,
tsize
);
int32_t
tsize
=
LOG_BUF_SIZE
(
pLogBu
f
)
-
start
;
taosWriteFile
(
pLogBuf
->
pFile
,
LOG_BUF_BUFFER
(
pLogBu
f
)
+
start
,
tsize
);
taosWriteFile
(
tLogBuff
->
pFile
,
LOG_BUF_BUFFER
(
tLogBuf
f
),
end
);
taosWriteFile
(
pLogBuf
->
pFile
,
LOG_BUF_BUFFER
(
pLogBu
f
),
end
);
}
dbgWN
++
;
dbgWSize
+=
pollSize
;
if
(
pollSize
<
tLogBuf
f
->
minBuffSize
)
{
if
(
pollSize
<
pLogBu
f
->
minBuffSize
)
{
dbgSmallWN
++
;
if
(
tsWriteInterval
<
LOG_MAX_INTERVAL
)
{
tsWriteInterval
+=
LOG_INTERVAL_STEP
;
}
}
else
if
(
pollSize
>
LOG_BUF_SIZE
(
tLogBuf
f
)
/
3
)
{
}
else
if
(
pollSize
>
LOG_BUF_SIZE
(
pLogBu
f
)
/
3
)
{
dbgBigWN
++
;
tsWriteInterval
=
LOG_MIN_INTERVAL
;
}
else
if
(
pollSize
>
LOG_BUF_SIZE
(
tLogBuf
f
)
/
4
)
{
}
else
if
(
pollSize
>
LOG_BUF_SIZE
(
pLogBu
f
)
/
4
)
{
if
(
tsWriteInterval
>
LOG_MIN_INTERVAL
)
{
tsWriteInterval
-=
LOG_INTERVAL_STEP
;
}
}
LOG_BUF_START
(
tLogBuff
)
=
(
LOG_BUF_START
(
tLogBuff
)
+
pollSize
)
%
LOG_BUF_SIZE
(
tLogBuf
f
);
LOG_BUF_START
(
pLogBuf
)
=
(
LOG_BUF_START
(
pLogBuf
)
+
pollSize
)
%
LOG_BUF_SIZE
(
pLogBu
f
);
start
=
LOG_BUF_START
(
tLogBuf
f
);
end
=
LOG_BUF_END
(
tLogBuf
f
);
start
=
LOG_BUF_START
(
pLogBu
f
);
end
=
LOG_BUF_END
(
pLogBu
f
);
pollSize
=
taosGetLogRemainSize
(
tLogBuf
f
,
start
,
end
);
if
(
pollSize
<
tLogBuf
f
->
minBuffSize
)
{
pollSize
=
taosGetLogRemainSize
(
pLogBu
f
,
start
,
end
);
if
(
pollSize
<
pLogBu
f
->
minBuffSize
)
{
break
;
}
...
...
@@ -670,16 +677,16 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
}
static
void
*
taosAsyncOutputLog
(
void
*
param
)
{
SLogBuff
*
tLogBuf
f
=
(
SLogBuff
*
)
param
;
SLogBuff
*
pLogBu
f
=
(
SLogBuff
*
)
param
;
setThreadName
(
"log"
);
while
(
1
)
{
taosMsleep
(
tsWriteInterval
);
// Polling the buffer
taosWriteLog
(
tLogBuf
f
);
taosWriteLog
(
pLogBu
f
);
if
(
tLogBuf
f
->
stop
)
break
;
if
(
pLogBu
f
->
stop
)
break
;
}
return
NULL
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录