Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
47aca0aa
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
47aca0aa
编写于
11月 25, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-11379]<fix>: Fix potential memory violation in monitor
上级
8e69edf4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
33 addition
and
21 deletion
+33
-21
src/plugins/monitor/src/monMain.c
src/plugins/monitor/src/monMain.c
+33
-21
未找到文件。
src/plugins/monitor/src/monMain.c
浏览文件 @
47aca0aa
...
...
@@ -43,6 +43,8 @@
#define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000
#define SQL_STR_FMT "\"%s\""
static
SMonHttpStatus
monHttpStatusTable
[]
=
{
{
"HTTP_CODE_CONTINUE"
,
100
},
{
"HTTP_CODE_SWITCHING_PROTOCOL"
,
101
},
...
...
@@ -611,11 +613,11 @@ static int32_t monGetRowElemCharLen(TAOS_FIELD field, char *rowElem) {
}
static
int32_t
monBuildFirstEpSql
(
char
*
sql
)
{
return
snprintf
(
sql
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
tsFirst
);
return
snprintf
(
sql
,
SQL_LENGTH
,
",
"
SQL_STR_FMT
,
tsFirst
);
}
static
int32_t
monBuildVersionSql
(
char
*
sql
)
{
return
snprintf
(
sql
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
version
);
return
snprintf
(
sql
,
SQL_LENGTH
,
",
"
SQL_STR_FMT
,
version
);
}
static
int32_t
monBuildMasterUptimeSql
(
char
*
sql
)
{
...
...
@@ -628,7 +630,8 @@ static int32_t monBuildMasterUptimeSql(char *sql) {
while
((
row
=
taos_fetch_row
(
result
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"role"
)
==
0
&&
strcmp
((
char
*
)
row
[
i
],
"master"
)
==
0
)
{
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strcmp
(
fields
[
i
].
name
,
"role"
)
==
0
&&
strncmp
((
char
*
)
row
[
i
],
"master"
,
charLen
)
==
0
)
{
if
(
strcmp
(
fields
[
i
+
1
].
name
,
"role_time"
)
==
0
)
{
int64_t
now
=
taosGetTimestamp
(
TSDB_TIME_PRECISION_MILLI
);
//master uptime in seconds
...
...
@@ -768,11 +771,11 @@ static int32_t monGetVnodesTotalStats(char *ep, int32_t *totalVnodes,
int32_t
*
totalVnodesAlive
)
{
char
subsql
[
TSDB_EP_LEN
+
15
];
memset
(
subsql
,
0
,
sizeof
(
subsql
));
snprintf
(
subsql
,
TSDB_EP_LEN
,
"show vnodes
\"
%s
\"
"
,
ep
);
snprintf
(
subsql
,
TSDB_EP_LEN
,
"show vnodes
"
SQL_STR_FMT
,
ep
);
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
subsql
);
int32_t
code
=
taos_errno
(
result
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
monError
(
"failed to execute cmd: show vnodes
\"
%s
\
"
, reason:%s"
,
ep
,
tstrerror
(
code
));
monError
(
"failed to execute cmd: show vnodes
"
SQL_STR_FMT
", reason:%s"
,
ep
,
tstrerror
(
code
));
}
TAOS_ROW
row
;
...
...
@@ -931,11 +934,11 @@ static int32_t monBuildDnodeVnodesSql(char *sql) {
int32_t
vnodeNum
=
0
,
masterNum
=
0
;
char
sqlStr
[
TSDB_EP_LEN
+
15
];
memset
(
sqlStr
,
0
,
sizeof
(
sqlStr
));
snprintf
(
sqlStr
,
TSDB_EP_LEN
+
14
,
"show vnodes
\"
%s
\"
"
,
tsLocalEp
);
snprintf
(
sqlStr
,
TSDB_EP_LEN
+
14
,
"show vnodes
"
SQL_STR_FMT
,
tsLocalEp
);
TAOS_RES
*
result
=
taos_query
(
tsMonitor
.
conn
,
sqlStr
);
int32_t
code
=
taos_errno
(
result
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
monError
(
"failed to execute cmd: show vnodes
\"
%s
\
"
, reason:%s"
,
tsLocalEp
,
tstrerror
(
code
));
monError
(
"failed to execute cmd: show vnodes
"
SQL_STR_FMT
", reason:%s"
,
tsLocalEp
,
tstrerror
(
code
));
}
TAOS_ROW
row
;
...
...
@@ -970,17 +973,18 @@ static int32_t monBuildDnodeMnodeSql(char *sql) {
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int32_t
charLen
;
while
((
row
=
taos_fetch_row
(
result
)))
{
has_mnode_row
=
false
;
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"end_point"
)
==
0
)
{
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
tsLocalEp
,
charLen
)
==
0
)
{
has_mnode
=
true
;
has_mnode_row
=
true
;
}
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"role"
)
==
0
)
{
int32_t
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
if
(
strncmp
((
char
*
)
row
[
i
],
"master"
,
charLen
)
==
0
)
{
if
(
has_mnode_row
)
{
monHasMnodeMaster
=
true
;
...
...
@@ -1107,7 +1111,7 @@ static int32_t checkCreateVgroupTable(int32_t vgId) {
}
static
uint32_t
monBuildVgroupsInfoSql
(
char
*
sql
,
char
*
dbName
)
{
char
v_dnode_ids
[
256
]
,
v_dnode_status
[
1024
]
;
char
v_dnode_ids
[
256
]
=
{
0
},
v_dnode_status
[
1024
]
=
{
0
}
;
int64_t
ts
=
taosGetTimestampUs
();
memset
(
sql
,
0
,
SQL_LENGTH
+
1
);
...
...
@@ -1122,6 +1126,7 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) {
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int32_t
charLen
;
while
((
row
=
taos_fetch_row
(
result
)))
{
int32_t
vgId
;
int32_t
pos
=
0
;
...
...
@@ -1132,25 +1137,26 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) {
vgId
=
*
(
int32_t
*
)
row
[
i
];
if
(
checkCreateVgroupTable
(
vgId
)
==
TSDB_CODE_SUCCESS
)
{
memset
(
sql
,
0
,
SQL_LENGTH
+
1
);
pos
+=
snprintf
(
sql
,
SQL_LENGTH
,
"insert into %s.vgroup_%d values(%"
PRId64
",
\"
%s
\"
"
,
pos
+=
snprintf
(
sql
,
SQL_LENGTH
,
"insert into %s.vgroup_%d values(%"
PRId64
",
"
SQL_STR_FMT
,
tsMonitorDbName
,
vgId
,
ts
,
dbName
);
}
else
{
return
TSDB_CODE_SUCCESS
;
}
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"tables"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
", %d"
,
*
(
int32_t
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"status"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
+
1
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"onlines"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
", %d"
,
*
(
int32_t
*
)
row
[
i
]);
}
else
if
(
v_dnode_str
&&
strcmp
(
v_dnode_str
,
"_dnode"
)
==
0
)
{
snprintf
(
v_dnode_ids
,
sizeof
(
v_dnode_ids
),
"%d;"
,
*
(
int16_t
*
)
row
[
i
]);
}
else
if
(
v_dnode_str
&&
strcmp
(
v_dnode_str
,
"_status"
)
==
0
)
{
snprintf
(
v_dnode_status
,
sizeof
(
v_dnode_status
),
"%s;"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
snprintf
(
v_dnode_status
,
charLen
+
1
,
"%s;"
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"compacting"
)
==
0
)
{
//flush dnode_ids and dnode_role in to sql
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
,
\"
%s
\
"
)"
,
v_dnode_ids
,
v_dnode_status
);
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
"
SQL_STR_FMT
", "
SQL_STR_FMT
")"
,
v_dnode_ids
,
v_dnode_status
);
}
}
monDebug
(
"save vgroups, sql:%s"
,
sql
);
...
...
@@ -1209,15 +1215,19 @@ static void monSaveSlowQueryInfo() {
int32_t
num_fields
=
taos_num_fields
(
result
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int32_t
charLen
;
while
((
row
=
taos_fetch_row
(
result
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
{
if
(
strcmp
(
fields
[
i
].
name
,
"query_id"
)
==
0
)
{
has_slowquery
=
true
;
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"user"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"qid"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"created_time"
)
==
0
)
{
int64_t
create_time
=
*
(
int64_t
*
)
row
[
i
];
create_time
=
convertTimePrecision
(
create_time
,
TSDB_TIME_PRECISION_MILLI
,
TSDB_TIME_PRECISION_MICRO
);
...
...
@@ -1225,9 +1235,11 @@ static void monSaveSlowQueryInfo() {
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"time"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
", %"
PRId64
""
,
*
(
int64_t
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"ep"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
,
", "
SQL_STR_FMT
,
(
char
*
)
row
[
i
]);
}
else
if
(
strcmp
(
fields
[
i
].
name
,
"sql"
)
==
0
)
{
pos
+=
snprintf
(
sql
+
pos
,
SQL_LENGTH
,
",
\"
%s
\"
)"
,
(
char
*
)
row
[
i
]);
charLen
=
monGetRowElemCharLen
(
fields
[
i
],
(
char
*
)
row
[
i
]);
pos
+=
snprintf
(
sql
+
pos
,
strlen
(
SQL_STR_FMT
)
+
charLen
+
1
,
", "
SQL_STR_FMT
")"
,
(
char
*
)
row
[
i
]);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录