Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5fe99c5a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5fe99c5a
编写于
4月 23, 2023
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support log long query
上级
1b2c5a50
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
4 deletion
+98
-4
include/common/tglobal.h
include/common/tglobal.h
+8
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+1
-1
source/common/src/tglobal.c
source/common/src/tglobal.c
+44
-0
source/util/src/tlog.c
source/util/src/tlog.c
+45
-3
未找到文件。
include/common/tglobal.h
浏览文件 @
5fe99c5a
...
...
@@ -24,6 +24,12 @@
extern
"C"
{
#endif
#define SLOW_LOG_TYPE_QUERY 0x1
#define SLOW_LOG_TYPE_INSERT 0x2
#define SLOW_LOG_TYPE_OTHERS 0x4
#define SLOW_LOG_TYPE_ALL 0xFFFFFFFF
// cluster
extern
char
tsFirst
[];
extern
char
tsSecond
[];
...
...
@@ -118,6 +124,8 @@ extern int32_t tsRedirectFactor;
extern
int32_t
tsRedirectMaxPeriod
;
extern
int32_t
tsMaxRetryWaitTime
;
extern
bool
tsUseAdapter
;
extern
int32_t
tsSlowLogThreshold
;
extern
int32_t
tsSlowLogScope
;
// client
extern
int32_t
tsMinSlidingTime
;
...
...
source/client/src/clientImpl.c
浏览文件 @
5fe99c5a
...
...
@@ -1257,7 +1257,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
const
char
*
errorMsg
=
(
pRequest
->
code
==
TSDB_CODE_RPC_FQDN_ERROR
)
?
taos_errstr
(
pRequest
)
:
tstrerror
(
pRequest
->
code
);
fprintf
(
stderr
,
"failed to connect to server, reason: %s
\n\n
"
,
errorMsg
);
tscError
(
"failed to connect to server, reason: %s
"
,
errorMsg
);
terrno
=
pRequest
->
code
;
destroyRequest
(
pRequest
);
...
...
source/common/src/tglobal.c
浏览文件 @
5fe99c5a
...
...
@@ -117,6 +117,10 @@ int32_t tsRedirectFactor = 2;
int32_t
tsRedirectMaxPeriod
=
1000
;
int32_t
tsMaxRetryWaitTime
=
10000
;
bool
tsUseAdapter
=
false
;
int32_t
tsSlowLogThreshold
=
3
;
// seconds
int32_t
tsSlowLogScope
=
SLOW_LOG_TYPE_ALL
;
/*
...
...
@@ -345,6 +349,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
if
(
cfgAddBool
(
pCfg
,
"useAdapter"
,
tsUseAdapter
,
true
)
!=
0
)
return
-
1
;
if
(
cfgAddBool
(
pCfg
,
"crashReporting"
,
tsEnableCrashReport
,
true
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"queryMaxConcurrentTables"
,
tsQueryMaxConcurrentTables
,
INT64_MIN
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"slowLogThreshold"
,
tsSlowLogThreshold
,
0
,
INT32_MAX
,
true
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"slowLogScope"
,
""
,
true
)
!=
0
)
return
-
1
;
tsNumOfRpcThreads
=
tsNumOfCores
/
2
;
tsNumOfRpcThreads
=
TRANGE
(
tsNumOfRpcThreads
,
2
,
TSDB_MAX_RPC_THREADS
);
...
...
@@ -692,6 +698,36 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
metaDebugFlag
=
cfgGetItem
(
pCfg
,
"metaDebugFlag"
)
->
i32
;
}
static
int32_t
taosSetSlowLogScope
(
char
*
pScope
)
{
if
(
NULL
==
pScope
||
0
==
strlen
(
pScope
))
{
tsSlowLogScope
=
SLOW_LOG_TYPE_ALL
;
return
0
;
}
if
(
0
==
strcasecmp
(
pScope
,
"all"
))
{
tsSlowLogScope
=
SLOW_LOG_TYPE_ALL
;
return
0
;
}
if
(
0
==
strcasecmp
(
pScope
,
"query"
))
{
tsSlowLogScope
=
SLOW_LOG_TYPE_QUERY
;
return
0
;
}
if
(
0
==
strcasecmp
(
pScope
,
"insert"
))
{
tsSlowLogScope
=
SLOW_LOG_TYPE_INSERT
;
return
0
;
}
if
(
0
==
strcasecmp
(
pScope
,
"others"
))
{
tsSlowLogScope
=
SLOW_LOG_TYPE_OTHERS
;
return
0
;
}
uError
(
"Invalid slowLog scope value:%s"
,
pScope
);
return
-
1
;
}
static
int32_t
taosSetClientCfg
(
SConfig
*
pCfg
)
{
tstrncpy
(
tsLocalFqdn
,
cfgGetItem
(
pCfg
,
"fqdn"
)
->
str
,
TSDB_FQDN_LEN
);
tsServerPort
=
(
uint16_t
)
cfgGetItem
(
pCfg
,
"serverPort"
)
->
i32
;
...
...
@@ -742,6 +778,10 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
tsUseAdapter
=
cfgGetItem
(
pCfg
,
"useAdapter"
)
->
bval
;
tsEnableCrashReport
=
cfgGetItem
(
pCfg
,
"crashReporting"
)
->
bval
;
tsQueryMaxConcurrentTables
=
cfgGetItem
(
pCfg
,
"queryMaxConcurrentTables"
)
->
i64
;
tsSlowLogThreshold
=
cfgGetItem
(
pCfg
,
"slowLogThreshold"
)
->
i32
;
if
(
taosSetSlowLogScope
(
cfgGetItem
(
pCfg
,
"slowLogScope"
)
->
str
))
{
return
-
1
;
}
tsMaxRetryWaitTime
=
cfgGetItem
(
pCfg
,
"maxRetryWaitTime"
)
->
i32
;
...
...
@@ -1156,6 +1196,10 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
sDebugFlag
=
cfgGetItem
(
pCfg
,
"sDebugFlag"
)
->
i32
;
}
else
if
(
strcasecmp
(
"smaDebugFlag"
,
name
)
==
0
)
{
smaDebugFlag
=
cfgGetItem
(
pCfg
,
"smaDebugFlag"
)
->
i32
;
}
else
if
(
strcasecmp
(
"slowLogThreshold"
,
name
)
==
0
)
{
tsSlowLogThreshold
=
cfgGetItem
(
pCfg
,
"slowLogThreshold"
)
->
i32
;
}
else
if
(
strcasecmp
(
"slowLogScope"
,
name
)
==
0
)
{
taosSetSlowLogScope
(
cfgGetItem
(
pCfg
,
"slowLogScope"
)
->
str
)
}
break
;
}
...
...
source/util/src/tlog.c
浏览文件 @
5fe99c5a
...
...
@@ -28,6 +28,7 @@
#define LOG_FILE_NAME_LEN 300
#define LOG_DEFAULT_BUF_SIZE (20 * 1024 * 1024) // 20MB
#define LOG_SLOW_BUF_SIZE (10 * 1024 * 1024) // 10MB
#define LOG_DEFAULT_INTERVAL 25
#define LOG_INTERVAL_STEP 5
...
...
@@ -62,6 +63,7 @@ typedef struct {
pid_t
pid
;
char
logName
[
LOG_FILE_NAME_LEN
];
SLogBuff
*
logHandle
;
SLogBuff
*
slowHandle
;
TdThreadMutex
logMutex
;
}
SLogObj
;
...
...
@@ -136,6 +138,34 @@ static int32_t taosStartLog() {
return
0
;
}
int32_t
taosInitSlowLog
()
{
char
fullName
[
PATH_MAX
]
=
{
0
};
char
logFileName
[
64
]
=
{
0
};
#ifdef CUS_PROMPT
snprintf
(
logFileName
,
64
,
"%sSlowLog"
,
CUS_PROMPT
);
#else
snprintf
(
logFileName
,
64
,
"taosSlowLog"
);
#endif
if
(
strlen
(
tsLogDir
)
!=
0
)
{
snprintf
(
fullName
,
PATH_MAX
,
"%s"
TD_DIRSEP
"%s"
,
tsLogDir
,
logFileName
);
}
else
{
snprintf
(
fullName
,
PATH_MAX
,
"%s"
,
logFileName
);
}
tsLogObj
.
slowHandle
=
taosLogBuffNew
(
LOG_SLOW_BUF_SIZE
);
if
(
tsLogObj
.
slowHandle
==
NULL
)
return
-
1
;
taosUmaskFile
(
0
);
tsLogObj
.
slowHandle
->
pFile
=
taosOpenFile
(
fullName
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
tsLogObj
.
slowHandle
->
pFile
==
NULL
)
{
printf
(
"
\n
failed to open slow log file:%s, reason:%s
\n
"
,
fullName
,
strerror
(
errno
));
return
-
1
;
}
return
0
;
}
int32_t
taosInitLog
(
const
char
*
logName
,
int32_t
maxFiles
)
{
if
(
atomic_val_compare_exchange_8
(
&
tsLogInited
,
0
,
1
)
!=
0
)
return
0
;
osUpdate
();
...
...
@@ -151,6 +181,8 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles) {
tsLogObj
.
logHandle
=
taosLogBuffNew
(
LOG_DEFAULT_BUF_SIZE
);
if
(
tsLogObj
.
logHandle
==
NULL
)
return
-
1
;
if
(
taosOpenLogFile
(
fullName
,
tsNumOfLogLines
,
maxFiles
)
<
0
)
return
-
1
;
if
(
taosInitSlowLog
()
<
0
)
return
-
1
;
if
(
taosStartLog
()
<
0
)
return
-
1
;
return
0
;
}
...
...
@@ -159,11 +191,23 @@ static void taosStopLog() {
if
(
tsLogObj
.
logHandle
)
{
tsLogObj
.
logHandle
->
stop
=
1
;
}
if
(
tsLogObj
.
slowHandle
)
{
tsLogObj
.
slowHandle
->
stop
=
1
;
}
}
void
taosCloseLog
()
{
taosStopLog
();
if
(
tsLogObj
.
slowHandle
!=
NULL
)
{
taosThreadMutexDestroy
(
&
tsLogObj
.
slowHandle
->
buffMutex
);
taosCloseFile
(
&
tsLogObj
.
slowHandle
->
pFile
);
taosMemoryFreeClear
(
tsLogObj
.
slowHandle
->
buffer
);
memset
(
&
tsLogObj
.
slowHandle
->
buffer
,
0
,
sizeof
(
tsLogObj
.
slowHandle
->
buffer
));
taosMemoryFreeClear
(
tsLogObj
.
slowHandle
);
}
if
(
tsLogObj
.
logHandle
!=
NULL
)
{
taosStopLog
();
if
(
tsLogObj
.
logHandle
!=
NULL
&&
taosCheckPthreadValid
(
tsLogObj
.
logHandle
->
asyncThread
))
{
taosThreadJoin
(
tsLogObj
.
logHandle
->
asyncThread
,
NULL
);
taosThreadClear
(
&
tsLogObj
.
logHandle
->
asyncThread
);
...
...
@@ -176,8 +220,6 @@ void taosCloseLog() {
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
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录