Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46246346
TDengine
提交
755fdb05
TDengine
项目概览
weixin_46246346
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
755fdb05
编写于
6月 05, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-464] kill query and kill stream
上级
5ed28feb
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
75 addition
and
65 deletion
+75
-65
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+44
-34
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+3
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+4
-13
src/mnode/src/mnodeProfile.c
src/mnode/src/mnodeProfile.c
+24
-14
未找到文件。
src/client/src/tscProfile.c
浏览文件 @
755fdb05
...
...
@@ -199,68 +199,78 @@ void tscKillStream(STscObj *pObj, uint32_t killId) {
if
(
pStream
)
{
tscTrace
(
"%p stream:%p is killed, streamId:%d"
,
pStream
->
pSql
,
pStream
,
killId
);
}
if
(
pStream
->
callback
)
{
pStream
->
callback
(
pStream
->
param
);
}
taos_close_stream
(
pStream
);
}
else
{
tscError
(
"failed to kill stream, streamId:%d not exist"
,
killId
);
}
}
int
tscBuildQueryStreamDesc
(
void
*
pMsg
,
STscObj
*
pObj
)
{
SCMHeartBeatMsg
*
pHeartbeat
=
pMsg
;
pHeartbeat
->
connId
=
htonl
(
pObj
->
connId
);
int
allocedQueriesNum
=
pHeartbeat
->
numOfQueries
;
int
allocedStreamsNum
=
pHeartbeat
->
numOfStreams
;
pHeartbeat
->
numOfQueries
=
0
;
SQueryDesc
*
pQdesc
=
(
SQueryDesc
*
)
pHeartbeat
->
pData
;
// We extract the lock to tscBuildHeartBeatMsg function.
//
SSqlObj *pSql = pObj->sqlList;
//
while (pSql) {
SSqlObj
*
pSql
=
pObj
->
sqlList
;
while
(
pSql
)
{
/*
* avoid sqlobj may not be correctly removed from sql list
* e.g., forgetting to free the sql result may cause the sql object still in sql list
*/
//
if (pSql->sqlstr == NULL) {
//
pSql = pSql->next;
//
continue;
//
}
if
(
pSql
->
sqlstr
==
NULL
)
{
pSql
=
pSql
->
next
;
continue
;
}
strncpy
(
pQdesc
->
sql
,
"select * from d1.t1"
,
TSDB_SHOW_SQL_LEN
-
1
);
strncpy
(
pQdesc
->
sql
,
pSql
->
sqlstr
,
TSDB_SHOW_SQL_LEN
-
1
);
pQdesc
->
sql
[
TSDB_SHOW_SQL_LEN
-
1
]
=
0
;
pQdesc
->
stime
=
htobe64
(
taosGetTimestampMs
()
);
pQdesc
->
queryId
=
htonl
(
12
);
pQdesc
->
useconds
=
hto
nl
(
34567
);
pQdesc
->
stime
=
htobe64
(
pSql
->
stime
);
pQdesc
->
queryId
=
htonl
(
pSql
->
queryId
);
pQdesc
->
useconds
=
hto
be64
(
pSql
->
res
.
useconds
);
pHeartbeat
->
numOfQueries
++
;
pQdesc
++
;
//pSql = pSql->next;
//}
pSql
=
pSql
->
next
;
if
(
pHeartbeat
->
numOfQueries
>=
allocedQueriesNum
)
break
;
}
pHeartbeat
->
numOfStreams
=
0
;
SStreamDesc
*
pSdesc
=
(
SStreamDesc
*
)
pQdesc
;
//
SSqlStream *pStream = pObj->streamList;
//
while (pStream) {
strncpy
(
pSdesc
->
sql
,
"select * from d1.s1"
,
TSDB_SHOW_SQL_LEN
-
1
);
SSqlStream
*
pStream
=
pObj
->
streamList
;
while
(
pStream
)
{
strncpy
(
pSdesc
->
sql
,
pStream
->
pSql
->
sqlstr
,
TSDB_SHOW_SQL_LEN
-
1
);
pSdesc
->
sql
[
TSDB_SHOW_SQL_LEN
-
1
]
=
0
;
pSdesc
->
streamId
=
htonl
(
98
);
pSdesc
->
num
=
htobe64
(
76543
);
pSdesc
->
streamId
=
htonl
(
pStream
->
streamId
);
pSdesc
->
num
=
htobe64
(
pStream
->
num
);
pSdesc
->
useconds
=
htobe64
(
21
);
pSdesc
->
stime
=
htobe64
(
taosGetTimestampMs
()
-
1000
);
pSdesc
->
ctime
=
htobe64
(
taosGetTimestampMs
()
);
pSdesc
->
useconds
=
htobe64
(
pStream
->
useconds
);
pSdesc
->
stime
=
htobe64
(
pStream
->
stime
-
pStream
->
interval
);
pSdesc
->
ctime
=
htobe64
(
pStream
->
ctime
);
pSdesc
->
slidingTime
=
htobe64
(
567
);
pSdesc
->
interval
=
htobe64
(
89
);
pSdesc
->
slidingTime
=
htobe64
(
pStream
->
slidingTime
);
pSdesc
->
interval
=
htobe64
(
pStream
->
interval
);
pHeartbeat
->
numOfStreams
++
;
pSdesc
++
;
//pStream = pStream->next;
//}
pStream
=
pStream
->
next
;
if
(
pHeartbeat
->
numOfStreams
>=
allocedStreamsNum
)
break
;
}
int32_t
msgLen
=
pHeartbeat
->
numOfQueries
*
sizeof
(
SQueryDesc
)
+
pHeartbeat
->
numOfStreams
*
sizeof
(
SStreamDesc
)
+
sizeof
(
SCMHeartBeatMsg
);
pHeartbeat
->
connId
=
htonl
(
pObj
->
connId
);
pHeartbeat
->
numOfQueries
=
htonl
(
pHeartbeat
->
numOfQueries
);
pHeartbeat
->
numOfStreams
=
htonl
(
pHeartbeat
->
numOfStreams
);
return
pHeartbeat
->
numOfQueries
*
sizeof
(
SQueryDesc
)
+
pHeartbeat
->
numOfStreams
*
sizeof
(
SStreamDesc
)
+
sizeof
(
SCMHeartBeatMsg
)
;
return
msgLen
;
}
void
tscKillConnection
(
STscObj
*
pObj
)
{
...
...
src/client/src/tscSQLParser.c
浏览文件 @
755fdb05
...
...
@@ -2245,6 +2245,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) {
}
strncpy
(
pCmd
->
payload
,
idStr
->
z
,
idStr
->
n
);
const
char
delim
=
':'
;
char
*
connIdStr
=
strtok
(
idStr
->
z
,
&
delim
);
char
*
queryIdStr
=
strtok
(
NULL
,
&
delim
);
...
...
@@ -2256,7 +2257,6 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) {
}
if
(
killType
==
TSDB_SQL_KILL_CONNECTION
)
{
strncpy
(
pCmd
->
payload
,
idStr
->
z
,
idStr
->
n
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -2270,7 +2270,6 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) {
}
}
strncpy
(
pCmd
->
payload
,
idStr
->
z
,
idStr
->
n
);
return
TSDB_CODE_SUCCESS
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
755fdb05
...
...
@@ -1140,13 +1140,6 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
payloadLen
=
sizeof
(
SCMKillQueryMsg
);
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
pCmd
->
payloadLen
))
{
tscError
(
"%p failed to malloc for query msg"
,
pSql
);
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
}
SCMKillQueryMsg
*
pKill
=
(
SCMKillQueryMsg
*
)
pCmd
->
payload
;
strncpy
(
pKill
->
queryId
,
pInfo
->
pDCLInfo
->
ip
.
z
,
pInfo
->
pDCLInfo
->
ip
.
n
);
switch
(
pCmd
->
command
)
{
case
TSDB_SQL_KILL_QUERY
:
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_KILL_QUERY
;
...
...
@@ -1767,10 +1760,6 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
numOfStreams
++
;
}
// ==>
numOfQueries
=
1
;
numOfStreams
=
1
;
int
size
=
numOfQueries
*
sizeof
(
SQueryDesc
)
+
numOfStreams
*
sizeof
(
SStreamDesc
)
+
sizeof
(
SCMHeartBeatMsg
)
+
100
;
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
pthread_mutex_unlock
(
&
pObj
->
mutex
);
...
...
@@ -1779,6 +1768,8 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
SCMHeartBeatMsg
*
pHeartbeat
=
(
SCMHeartBeatMsg
*
)
pCmd
->
payload
;
pHeartbeat
->
numOfQueries
=
numOfQueries
;
pHeartbeat
->
numOfStreams
=
numOfStreams
;
int
msgLen
=
tscBuildQueryStreamDesc
(
pHeartbeat
,
pObj
);
pthread_mutex_unlock
(
&
pObj
->
mutex
);
...
...
src/mnode/src/mnodeProfile.c
浏览文件 @
755fdb05
...
...
@@ -269,8 +269,8 @@ int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) {
memcpy
(
pConn
->
pQueries
,
pHBMsg
->
pData
,
pConn
->
numOfQueries
*
sizeof
(
SQueryDesc
));
}
pConn
->
numOf
Queries
=
htonl
(
pHBMsg
->
numOfQuerie
s
);
if
(
pConn
->
numOf
Querie
s
>
0
)
{
pConn
->
numOf
Streams
=
htonl
(
pHBMsg
->
numOfStream
s
);
if
(
pConn
->
numOf
Stream
s
>
0
)
{
pConn
->
pStreams
=
calloc
(
sizeof
(
SStreamDesc
),
pConn
->
numOfStreams
);
memcpy
(
pConn
->
pStreams
,
pHBMsg
->
pData
+
pConn
->
numOfQueries
*
sizeof
(
SQueryDesc
),
pConn
->
numOfStreams
*
sizeof
(
SStreamDesc
));
...
...
@@ -504,7 +504,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
htonl
(
pDesc
->
num
);
*
(
int32_t
*
)
pWrite
=
(
int32_t
)
htobe64
(
pDesc
->
num
);
cols
++
;
numOfRows
++
;
...
...
@@ -522,13 +522,18 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
SCMKillQueryMsg
*
pKill
=
pMsg
->
rpcMsg
.
pCont
;
char
*
connIdStr
=
pKill
->
queryId
;
mPrint
(
"kill query msg is received, queryId:%s"
,
pKill
->
queryId
);
const
char
delim
=
':'
;
char
*
connIdStr
=
strtok
(
pKill
->
queryId
,
&
delim
);
char
*
queryIdStr
=
strtok
(
NULL
,
&
delim
);
char
*
chr
=
strchr
(
connIdStr
,
':'
);
if
(
chr
==
NULL
)
return
TSDB_CODE_INVALID_QUERY_ID
;
*
chr
=
0
;
if
(
queryIdStr
==
NULL
||
connIdStr
==
NULL
)
{
mPrint
(
"failed to kill query, queryId:%s"
,
pKill
->
queryId
);
return
TSDB_CODE_INVALID_QUERY_ID
;
}
uint32_t
queryId
=
atoi
(
chr
+
1
);
int32_t
queryId
=
(
int32_t
)
strtol
(
queryIdStr
,
NULL
,
10
);
SConnObj
*
pConn
=
taosCacheAcquireByName
(
tsMnodeConnCache
,
connIdStr
);
if
(
pConn
==
NULL
)
{
...
...
@@ -547,13 +552,18 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
return
TSDB_CODE_NO_RIGHTS
;
SCMKillQueryMsg
*
pKill
=
pMsg
->
rpcMsg
.
pCont
;
char
*
connIdStr
=
pKill
->
queryId
;
mPrint
(
"kill stream msg is received, streamId:%s"
,
pKill
->
queryId
);
const
char
delim
=
':'
;
char
*
connIdStr
=
strtok
(
pKill
->
queryId
,
&
delim
);
char
*
streamIdStr
=
strtok
(
NULL
,
&
delim
);
char
*
chr
=
strchr
(
connIdStr
,
':'
);
if
(
chr
==
NULL
)
return
TSDB_CODE_INVALID_QUERY_ID
;
*
chr
=
0
;
if
(
streamIdStr
==
NULL
||
connIdStr
==
NULL
)
{
mPrint
(
"failed to kill stream, streamId:%s"
,
pKill
->
queryId
);
return
TSDB_CODE_INVALID_STREAM_ID
;
}
uint32_t
streamId
=
atoi
(
chr
+
1
);
int32_t
streamId
=
(
int32_t
)
strtol
(
streamIdStr
,
NULL
,
10
);
SConnObj
*
pConn
=
taosCacheAcquireByName
(
tsMnodeConnCache
,
connIdStr
);
if
(
pConn
==
NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录