Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
b0ac7292
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0ac7292
编写于
11月 01, 2018
作者:
A
alesapin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CLICKHOUSE-4094: Add ability to kill pending queries
上级
63c6647b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
53 addition
and
6 deletion
+53
-6
dbms/src/Interpreters/InterpreterKillQueryQuery.cpp
dbms/src/Interpreters/InterpreterKillQueryQuery.cpp
+11
-2
dbms/src/Interpreters/ProcessList.cpp
dbms/src/Interpreters/ProcessList.cpp
+3
-2
dbms/src/Interpreters/ProcessList.h
dbms/src/Interpreters/ProcessList.h
+2
-0
dbms/src/Interpreters/executeQuery.cpp
dbms/src/Interpreters/executeQuery.cpp
+9
-2
dbms/tests/queries/0_stateless/00417_kill_query.reference
dbms/tests/queries/0_stateless/00417_kill_query.reference
+1
-0
dbms/tests/queries/0_stateless/00417_kill_query.sh
dbms/tests/queries/0_stateless/00417_kill_query.sh
+27
-0
未找到文件。
dbms/src/Interpreters/InterpreterKillQueryQuery.cpp
浏览文件 @
b0ac7292
...
...
@@ -23,6 +23,7 @@ namespace ErrorCodes
{
extern
const
int
READONLY
;
extern
const
int
LOGICAL_ERROR
;
extern
const
int
CANNOT_KILL
;
}
...
...
@@ -138,13 +139,16 @@ public:
auto
code
=
process_list
.
sendCancelToQuery
(
curr_process
.
query_id
,
curr_process
.
user
,
true
);
if
(
code
!=
CancellationCode
::
QueryIsNotInitializedYet
&&
code
!=
CancellationCode
::
CancelSent
)
/// Raise exception if this query is immortal, user have to know
if
(
code
==
CancellationCode
::
CancelCannotBeSent
)
throw
Exception
(
"Can't kill query '"
+
curr_process
.
query_id
+
"' it consits of unkillable stages"
,
ErrorCodes
::
CANNOT_KILL
);
else
if
(
code
!=
CancellationCode
::
QueryIsNotInitializedYet
&&
code
!=
CancellationCode
::
CancelSent
)
{
curr_process
.
processed
=
true
;
insertResultRow
(
curr_process
.
source_num
,
code
,
processes_block
,
res_sample_block
,
columns
);
++
num_processed_queries
;
}
/// Wait if
QueryIsNotInitializedYet or
CancelSent
/// Wait if CancelSent
}
/// KILL QUERY could be killed also
...
...
@@ -194,6 +198,11 @@ BlockIO InterpreterKillQueryQuery::execute()
for
(
const
auto
&
query_desc
:
queries_to_stop
)
{
auto
code
=
(
query
.
test
)
?
CancellationCode
::
Unknown
:
process_list
.
sendCancelToQuery
(
query_desc
.
query_id
,
query_desc
.
user
,
true
);
/// Raise exception if this query is immortal, user have to know
if
(
code
==
CancellationCode
::
CancelCannotBeSent
)
throw
Exception
(
"Can't kill query '"
+
query_desc
.
query_id
+
"' it consits of unkillable stages"
,
ErrorCodes
::
CANNOT_KILL
);
insertResultRow
(
query_desc
.
source_num
,
code
,
processes_block
,
header
,
res_columns
);
}
...
...
dbms/src/Interpreters/ProcessList.cpp
浏览文件 @
b0ac7292
...
...
@@ -396,8 +396,9 @@ ProcessList::CancellationCode ProcessList::sendCancelToQuery(const String & curr
}
return
CancellationCode
::
CancelCannotBeSent
;
}
return
CancellationCode
::
QueryIsNotInitializedYet
;
/// Query is not even started
elem
->
is_killed
.
store
(
true
);
return
CancellationCode
::
CancelSent
;
}
...
...
dbms/src/Interpreters/ProcessList.h
浏览文件 @
b0ac7292
...
...
@@ -191,6 +191,8 @@ public:
/// Get query in/out pointers from BlockIO
bool
tryGetQueryStreams
(
BlockInputStreamPtr
&
in
,
BlockOutputStreamPtr
&
out
)
const
;
bool
isKilled
()
const
{
return
is_killed
;
}
};
...
...
dbms/src/Interpreters/executeQuery.cpp
浏览文件 @
b0ac7292
...
...
@@ -33,6 +33,7 @@ namespace ErrorCodes
extern
const
int
LOGICAL_ERROR
;
extern
const
int
QUERY_IS_TOO_LARGE
;
extern
const
int
INTO_OUTFILE_NOT_ALLOWED
;
extern
const
int
QUERY_WAS_CANCELLED
;
}
...
...
@@ -204,9 +205,15 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
auto
interpreter
=
InterpreterFactory
::
get
(
ast
,
context
,
stage
);
res
=
interpreter
->
execute
();
/// Delayed initialization of query streams (required for KILL QUERY purposes)
if
(
process_list_entry
)
(
*
process_list_entry
)
->
setQueryStreams
(
res
);
{
/// Query was killed before execution
if
((
*
process_list_entry
)
->
isKilled
())
throw
Exception
(
"Query '"
+
(
*
process_list_entry
)
->
getInfo
().
client_info
.
current_query_id
+
"' is killed in pending state"
,
ErrorCodes
::
QUERY_WAS_CANCELLED
);
else
(
*
process_list_entry
)
->
setQueryStreams
(
res
);
}
/// Hold element of process list till end of query execution.
res
.
process_list_entry
=
process_list_entry
;
...
...
dbms/tests/queries/0_stateless/00417_kill_query.reference
浏览文件 @
b0ac7292
SELECT sleep(1) FROM system.numbers LIMIT 4
SELECT sleep(1) FROM system.numbers LIMIT 5
0
dbms/tests/queries/0_stateless/00417_kill_query.sh
浏览文件 @
b0ac7292
...
...
@@ -19,3 +19,30 @@ $CLICKHOUSE_CLIENT -q "KILL QUERY WHERE 0 ASYNC"
$CLICKHOUSE_CLIENT
-q
"KILL QUERY WHERE 0 FORMAT TabSeparated"
$CLICKHOUSE_CLIENT
-q
"KILL QUERY WHERE 0 SYNC FORMAT TabSeparated"
$CLICKHOUSE_CLIENT
-q
"KILL QUERY WHERE 1 TEST"
&>/dev/null
$CLICKHOUSE_CLIENT
-q
"DROP TABLE IF EXISTS test.cannot_kill_query"
$CLICKHOUSE_CLIENT
-q
"CREATE TABLE test.cannot_kill_query (x UInt64) ENGINE = MergeTree ORDER BY x"
&> /dev/null
$CLICKHOUSE_CLIENT
-q
"INSERT INTO test.cannot_kill_query SELECT * FROM numbers(10000000)"
&> /dev/null
query_for_pending
=
"SELECT count() FROM test.cannot_kill_query WHERE NOT ignore(sleep(1)) SETTINGS max_threads=1"
$CLICKHOUSE_CLIENT
-q
"
$query_for_pending
"
&>/dev/null &
$CLICKHOUSE_CLIENT
-q
"ALTER TABLE test.cannot_kill_query MODIFY COLUMN x UInt64"
&>/dev/null &
query_to_kill
=
"SELECT sum(1) FROM test.cannot_kill_query WHERE NOT ignore(sleep(1)) SETTINGS max_threads=1"
$CLICKHOUSE_CLIENT
-q
"
$query_to_kill
"
&>/dev/null &
sleep
1
# just to be sure that 'KILL ...' will be executed after 'SELECT ... WHERE NOT ignore(sleep(1))'
$CLICKHOUSE_CLIENT
-q
"KILL QUERY WHERE query='
$query_to_kill
'"
&>/dev/null &
# 'SELECT ... WHERE NOT ignore(sleep(1))' is executing much longer than 3 secs, so this sleep doesn't fail test logic
# but guarantees to eliminate flaps, when SELECT from system.process is executed before KILL is completed
sleep
3
$CLICKHOUSE_CLIENT
-q
"SELECT count() FROM system.processes where query='
$query_to_kill
'"
$CLICKHOUSE_CLIENT
-q
"KILL QUERY WHERE query='
$query_for_pending
'"
&>/dev/null &
# kill pending query
$CLICKHOUSE_CLIENT
-q
"DROP TABLE IF EXISTS test.cannot_kill_query"
&>/dev/null
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录