Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
4c85e9f4
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,发现更多精彩内容 >>
提交
4c85e9f4
编写于
8月 09, 2019
作者:
N
Nikita Mikhaylov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
atomic drop table
上级
508934fa
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
102 addition
and
5 deletion
+102
-5
dbms/src/Databases/DatabaseOrdinary.cpp
dbms/src/Databases/DatabaseOrdinary.cpp
+25
-2
dbms/src/Interpreters/InterpreterDropQuery.cpp
dbms/src/Interpreters/InterpreterDropQuery.cpp
+18
-3
dbms/tests/integration/test_atomic_drop_table/__init__.py
dbms/tests/integration/test_atomic_drop_table/__init__.py
+0
-0
dbms/tests/integration/test_atomic_drop_table/configs/config.d/zookeeper_session_timeout.xml
...drop_table/configs/config.d/zookeeper_session_timeout.xml
+6
-0
dbms/tests/integration/test_atomic_drop_table/configs/remote_servers.xml
...gration/test_atomic_drop_table/configs/remote_servers.xml
+14
-0
dbms/tests/integration/test_atomic_drop_table/test.py
dbms/tests/integration/test_atomic_drop_table/test.py
+39
-0
未找到文件。
dbms/src/Databases/DatabaseOrdinary.cpp
浏览文件 @
4c85e9f4
...
...
@@ -135,7 +135,25 @@ void DatabaseOrdinary::loadTables(
if
(
endsWith
(
dir_it
.
name
(),
".sql.bak"
))
continue
;
/// There are files .sql.tmp - delete.
// There are files that we tried to delete previously
const
std
::
string
tmp_drop_ext
=
".sql.tmp_drop"
;
if
(
endsWith
(
dir_it
.
name
(),
".sql.tmp_drop"
))
{
const
std
::
string
table_name
=
dir_it
.
name
().
substr
(
0
,
dir_it
.
name
().
size
()
-
tmp_drop_ext
.
size
());
if
(
Poco
::
File
(
data_path
+
'/'
+
table_name
).
exists
())
{
Poco
::
File
(
dir_it
->
path
()).
renameTo
(
table_name
+
".sql"
);
LOG_WARNING
(
log
,
"Table was not dropped previously"
);
}
else
{
LOG_INFO
(
log
,
"Removing file "
<<
dir_it
->
path
());
Poco
::
File
(
dir_it
->
path
()).
remove
();
}
continue
;
}
/// There are files .sql.tmp and .sql.tmp_drop - delete
if
(
endsWith
(
dir_it
.
name
(),
".sql.tmp"
))
{
LOG_INFO
(
log
,
"Removing file "
<<
dir_it
->
path
());
...
...
@@ -302,6 +320,12 @@ void DatabaseOrdinary::removeTable(
}
catch
(...)
{
try
{
Poco
::
File
(
table_metadata_path
+
".tmp_drop"
).
remove
();
return
;
}
catch
(...)
{}
attachTable
(
table_name
,
res
);
throw
;
}
...
...
@@ -363,7 +387,6 @@ void DatabaseOrdinary::renameTable(
throw
Exception
(
"Moving tables between databases of different engines is not supported"
,
ErrorCodes
::
NOT_IMPLEMENTED
);
StoragePtr
table
=
tryGetTable
(
context
,
table_name
);
if
(
!
table
)
throw
Exception
(
"Table "
+
name
+
"."
+
table_name
+
" doesn't exist."
,
ErrorCodes
::
UNKNOWN_TABLE
);
...
...
dbms/src/Interpreters/InterpreterDropQuery.cpp
浏览文件 @
4c85e9f4
...
...
@@ -90,11 +90,26 @@ BlockIO InterpreterDropQuery::executeToTable(String & database_name_, String & t
/// If table was already dropped by anyone, an exception will be thrown
auto
table_lock
=
database_and_table
.
second
->
lockExclusively
(
context
.
getCurrentQueryId
());
/// Delete table metadata and table itself from memory
const
auto
prev_metadata_name
=
database_and_table
.
first
->
getMetadataPath
()
+
database_and_table
.
second
->
getTableName
()
+
".sql"
;
const
auto
drop_metadata_name
=
database_and_table
.
first
->
getMetadataPath
()
+
database_and_table
.
second
->
getTableName
()
+
".sql.tmp_drop"
;
try
{
Poco
::
File
(
prev_metadata_name
).
renameTo
(
drop_metadata_name
);
std
::
cout
<<
"RENAMED"
<<
std
::
endl
;
/// Delete table data
database_and_table
.
second
->
drop
();
}
catch
(...)
{
Poco
::
File
(
drop_metadata_name
).
renameTo
(
prev_metadata_name
);
std
::
cout
<<
"RENAMED BACK"
<<
std
::
endl
;
throw
;
}
/// Delete table metadata and table itself from memory
database_and_table
.
first
->
removeTable
(
context
,
database_and_table
.
second
->
getTableName
());
/// Delete table data
database_and_table
.
second
->
drop
();
database_and_table
.
second
->
is_dropped
=
true
;
String
database_data_path
=
database_and_table
.
first
->
getDataPath
();
...
...
dbms/tests/integration/test_atomic_drop_table/__init__.py
0 → 100644
浏览文件 @
4c85e9f4
dbms/tests/integration/test_atomic_drop_table/configs/config.d/zookeeper_session_timeout.xml
0 → 100644
浏览文件 @
4c85e9f4
<yandex>
<zookeeper>
<!-- Required for correct timing in current test case -->
<session_timeout_ms
replace=
"1"
>
3000
</session_timeout_ms>
</zookeeper>
</yandex>
dbms/tests/integration/test_atomic_drop_table/configs/remote_servers.xml
0 → 100644
浏览文件 @
4c85e9f4
<yandex>
<remote_servers>
<test_cluster>
<shard>
<internal_replication>
true
</internal_replication>
<replica>
<default_database>
shard_0
</default_database>
<host>
node1
</host>
<port>
9000
</port>
</replica>
</shard>
</test_cluster>
</remote_servers>
</yandex>
dbms/tests/integration/test_atomic_drop_table/test.py
0 → 100644
浏览文件 @
4c85e9f4
import
time
import
pytest
from
helpers.network
import
PartitionManager
from
helpers.cluster
import
ClickHouseCluster
cluster
=
ClickHouseCluster
(
__file__
)
node1
=
cluster
.
add_instance
(
'node1'
,
config_dir
=
"configs"
,
with_zookeeper
=
True
)
@
pytest
.
fixture
(
scope
=
"module"
)
def
start_cluster
():
try
:
cluster
.
start
()
node1
.
query
(
"CREATE DATABASE zktest;"
)
node1
.
query
(
'''
CREATE TABLE zktest.atomic_drop_table (n UInt32)
ENGINE = ReplicatedMergeTree('/clickhouse/zktest/tables/atomic_drop_table', 'node1')
PARTITION BY n ORDER BY n
'''
)
yield
cluster
finally
:
cluster
.
shutdown
()
def
test_atomic_delete_with_stopped_zookeeper
(
start_cluster
):
node1
.
query
(
"select * from zktest.atomic_drop_table"
)
node1
.
query
(
"insert into zktest.atomic_drop_table values (8192)"
)
with
PartitionManager
()
as
pm
:
pm
.
drop_instance_zk_connections
(
node1
)
error
=
node1
.
query_and_get_error
(
"DROP TABLE zktest.atomic_drop_table"
)
assert
error
!=
""
time
.
sleep
(
5
)
assert
'8192'
in
node1
.
query
(
"select * from zktest.atomic_drop_table"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录