Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
5bc6bd55
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,发现更多精彩内容 >>
提交
5bc6bd55
编写于
2月 19, 2018
作者:
A
Alexey Zatelepin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow PreCommitted parts to contain each other, clean up code
上级
958a6f09
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
228 addition
and
274 deletion
+228
-274
dbms/src/Storages/MergeTree/MergeTreeData.cpp
dbms/src/Storages/MergeTree/MergeTreeData.cpp
+174
-234
dbms/src/Storages/MergeTree/MergeTreeData.h
dbms/src/Storages/MergeTree/MergeTreeData.h
+47
-38
dbms/src/Storages/MergeTree/MergeTreePartInfo.h
dbms/src/Storages/MergeTree/MergeTreePartInfo.h
+5
-0
dbms/src/Storages/StorageReplicatedMergeTree.cpp
dbms/src/Storages/StorageReplicatedMergeTree.cpp
+2
-2
未找到文件。
dbms/src/Storages/MergeTree/MergeTreeData.cpp
浏览文件 @
5bc6bd55
此差异已折叠。
点击以展开。
dbms/src/Storages/MergeTree/MergeTreeData.h
浏览文件 @
5bc6bd55
...
...
@@ -145,20 +145,24 @@ public:
using
DataParts
=
std
::
set
<
DataPartPtr
,
LessDataPart
>
;
using
DataPartsVector
=
std
::
vector
<
DataPartPtr
>
;
/// Some operations on the set of parts return a Transaction object.
/// Auxiliary object to add a set of parts into the working set in two steps:
/// * First, as PreCommitted parts (the parts are ready, but not yet in the active set).
/// * Next, if commit() is called, the parts are added to the active set and the parts that are
/// covered by them are marked Outdated.
/// If neither commit() nor rollback() was called, the destructor rollbacks the operation.
class
Transaction
:
private
boost
::
noncopyable
{
public:
Transaction
()
{}
void
commit
();
/// Return parts marked Obsolete as a result of the transaction commit.
DataPartsVector
commit
();
void
rollback
();
bool
isEmpty
()
const
{
return
p
arts_to_add_on_rollback
.
empty
()
&&
parts_to_remove_on_rollback
.
empty
();
return
p
recommitted_parts
.
empty
();
}
~
Transaction
()
...
...
@@ -172,23 +176,18 @@ public:
tryLogCurrentException
(
"~MergeTreeData::Transaction"
);
}
}
private:
friend
class
MergeTreeData
;
MergeTreeData
*
data
=
nullptr
;
/// What to do on rollback.
DataPartsVector
parts_to_remove_on_rollback
;
DataPartsVector
parts_to_add_on_rollback
;
DataParts
precommitted_parts
;
void
clear
()
{
data
=
nullptr
;
parts_to_remove_on_rollback
.
clear
();
parts_to_add_on_rollback
.
clear
();
precommitted_parts
.
clear
();
}
void
replaceParts
(
DataPartState
move_precommitted_to
,
DataPartState
move_committed_to
,
bool
remove_without_delay
);
};
/// An object that stores the names of temporary files created in the part directory during ALTER of its
...
...
@@ -368,14 +367,17 @@ public:
/// If until is non-null, wake up from the sleep earlier if the event happened.
void
delayInsertIfNeeded
(
Poco
::
Event
*
until
=
nullptr
);
/// Renames temporary part to a permanent part and adds it to the working set.
/// If increment != nullptr, part index is determing using increment. Otherwise part index remains unchanged.
/// Renames temporary part to a permanent part and adds it to the parts set.
/// It is assumed that the part does not intersect with existing parts.
/// If out_transaction != nullptr, sets it to an object allowing to rollback part addition (but not the renaming).
/// If increment != nullptr, part index is determing using increment. Otherwise part index remains unchanged.
/// If out_transaction != nullptr, adds the part in the PreCommitted state (the part will be added to the
/// active set later with out_transaction->commit()).
/// Else, commits the part immediately.
void
renameTempPartAndAdd
(
MutableDataPartPtr
&
part
,
SimpleIncrement
*
increment
=
nullptr
,
Transaction
*
out_transaction
=
nullptr
);
/// The same as renameTempPartAndAdd but the part can intersect existing parts.
/// Deletes and returns all parts covered by the added part (in ascending order).
/// The same as renameTempPartAndAdd but the block range of the part can contain existing parts.
/// Returns all parts covered by the added part (in ascending order).
/// If out_transaction == nullptr, marks covered parts as Outdated.
DataPartsVector
renameTempPartAndReplace
(
MutableDataPartPtr
&
part
,
SimpleIncrement
*
increment
=
nullptr
,
Transaction
*
out_transaction
=
nullptr
);
...
...
@@ -573,8 +575,8 @@ private:
/// Work with data parts
struct
TagBy
Name
{};
struct
TagByStateAnd
Name
{};
struct
TagBy
Info
{};
struct
TagByStateAnd
Info
{};
static
const
MergeTreePartInfo
&
dataPartPtrToInfo
(
const
DataPartPtr
&
part
)
{
...
...
@@ -588,14 +590,14 @@ private:
using
DataPartsIndexes
=
boost
::
multi_index_container
<
DataPartPtr
,
boost
::
multi_index
::
indexed_by
<
/// Index by
Name
/// Index by
Info
boost
::
multi_index
::
ordered_unique
<
boost
::
multi_index
::
tag
<
TagBy
Name
>
,
boost
::
multi_index
::
tag
<
TagBy
Info
>
,
boost
::
multi_index
::
global_fun
<
const
DataPartPtr
&
,
const
MergeTreePartInfo
&
,
dataPartPtrToInfo
>
>
,
/// Index by (State,
Name
), is used to obtain ordered slices of parts with the same state
/// Index by (State,
Info
), is used to obtain ordered slices of parts with the same state
boost
::
multi_index
::
ordered_unique
<
boost
::
multi_index
::
tag
<
TagByStateAnd
Name
>
,
boost
::
multi_index
::
tag
<
TagByStateAnd
Info
>
,
boost
::
multi_index
::
global_fun
<
const
DataPartPtr
&
,
DataPartStateAndInfo
,
dataPartPtrToStateAndInfo
>
,
LessStateDataPart
>
...
...
@@ -605,16 +607,16 @@ private:
/// Current set of data parts.
mutable
std
::
mutex
data_parts_mutex
;
DataPartsIndexes
data_parts_indexes
;
DataPartsIndexes
::
index
<
TagBy
Name
>::
type
&
data_parts_by_name
;
DataPartsIndexes
::
index
<
TagByStateAnd
Name
>::
type
&
data_parts_by_state_and_name
;
DataPartsIndexes
::
index
<
TagBy
Info
>::
type
&
data_parts_by_info
;
DataPartsIndexes
::
index
<
TagByStateAnd
Info
>::
type
&
data_parts_by_state_and_info
;
using
DataPartIteratorBy
AndName
=
DataPartsIndexes
::
index
<
TagByName
>::
type
::
iterator
;
using
DataPartIteratorByStateAnd
Name
=
DataPartsIndexes
::
index
<
TagByStateAndName
>::
type
::
iterator
;
using
DataPartIteratorBy
Info
=
DataPartsIndexes
::
index
<
TagByInfo
>::
type
::
iterator
;
using
DataPartIteratorByStateAnd
Info
=
DataPartsIndexes
::
index
<
TagByStateAndInfo
>::
type
::
iterator
;
boost
::
iterator_range
<
DataPartIteratorByStateAnd
Name
>
getDataPartsStateRange
(
DataPartState
state
)
const
boost
::
iterator_range
<
DataPartIteratorByStateAnd
Info
>
getDataPartsStateRange
(
DataPartState
state
)
const
{
auto
begin
=
data_parts_by_state_and_
name
.
lower_bound
(
state
,
LessStateDataPart
());
auto
end
=
data_parts_by_state_and_
name
.
upper_bound
(
state
,
LessStateDataPart
());
auto
begin
=
data_parts_by_state_and_
info
.
lower_bound
(
state
,
LessStateDataPart
());
auto
end
=
data_parts_by_state_and_
info
.
upper_bound
(
state
,
LessStateDataPart
());
return
{
begin
,
end
};
}
...
...
@@ -623,25 +625,25 @@ private:
return
[
state
]
(
const
DataPartPtr
&
part
)
{
part
->
state
=
state
;
};
}
void
modifyPartState
(
DataPartIteratorByStateAnd
Name
it
,
DataPartState
state
)
void
modifyPartState
(
DataPartIteratorByStateAnd
Info
it
,
DataPartState
state
)
{
if
(
!
data_parts_by_state_and_
name
.
modify
(
it
,
getStateModifier
(
state
)))
if
(
!
data_parts_by_state_and_
info
.
modify
(
it
,
getStateModifier
(
state
)))
throw
Exception
(
"Can't modify "
+
(
*
it
)
->
getNameWithState
(),
ErrorCodes
::
LOGICAL_ERROR
);
}
void
modifyPartState
(
DataPartIteratorBy
AndName
it
,
DataPartState
state
)
void
modifyPartState
(
DataPartIteratorBy
Info
it
,
DataPartState
state
)
{
if
(
!
data_parts_by_state_and_
name
.
modify
(
data_parts_indexes
.
project
<
TagByStateAndName
>
(
it
),
getStateModifier
(
state
)))
if
(
!
data_parts_by_state_and_
info
.
modify
(
data_parts_indexes
.
project
<
TagByStateAndInfo
>
(
it
),
getStateModifier
(
state
)))
throw
Exception
(
"Can't modify "
+
(
*
it
)
->
getNameWithState
(),
ErrorCodes
::
LOGICAL_ERROR
);
}
void
modifyPartState
(
const
DataPartPtr
&
part
,
DataPartState
state
)
{
auto
it
=
data_parts_by_
name
.
find
(
part
->
info
);
if
(
it
==
data_parts_by_
name
.
end
()
||
(
*
it
).
get
()
!=
part
.
get
())
throw
Exception
(
"Part "
+
part
->
name
+
"
is not exists
"
,
ErrorCodes
::
LOGICAL_ERROR
);
auto
it
=
data_parts_by_
info
.
find
(
part
->
info
);
if
(
it
==
data_parts_by_
info
.
end
()
||
(
*
it
).
get
()
!=
part
.
get
())
throw
Exception
(
"Part "
+
part
->
name
+
"
doesn't exist
"
,
ErrorCodes
::
LOGICAL_ERROR
);
if
(
!
data_parts_by_state_and_
name
.
modify
(
data_parts_indexes
.
project
<
TagByStateAndName
>
(
it
),
getStateModifier
(
state
)))
if
(
!
data_parts_by_state_and_
info
.
modify
(
data_parts_indexes
.
project
<
TagByStateAndInfo
>
(
it
),
getStateModifier
(
state
)))
throw
Exception
(
"Can't modify "
+
(
*
it
)
->
getNameWithState
(),
ErrorCodes
::
LOGICAL_ERROR
);
}
...
...
@@ -672,7 +674,14 @@ private:
void
removePartContributionToColumnSizes
(
const
DataPartPtr
&
part
);
/// If there is no part in the partition with ID `partition_id`, returns empty ptr. Should be called under the lock.
DataPartPtr
getAnyPartInPartition
(
const
String
&
partition_id
,
std
::
unique_lock
<
std
::
mutex
>
&
data_parts_lock
);
DataPartPtr
getAnyPartInPartition
(
const
String
&
partition_id
,
std
::
lock_guard
<
std
::
mutex
>
&
data_parts_lock
);
/// Return parts in the Committed set that are covered by the new_part_info or the part that covers it.
/// Will check that the new part doesn't already exist and that it doesn't intersect existing part.
DataPartsVector
getActivePartsToReplace
(
const
MergeTreePartInfo
&
new_part_info
,
DataPartPtr
&
out_covering_part
,
std
::
lock_guard
<
std
::
mutex
>
&
data_parts_lock
)
const
;
/// Checks whether the column is in the primary key.
bool
isPrimaryKeyColumn
(
const
ASTPtr
&
node
)
const
;
...
...
dbms/src/Storages/MergeTree/MergeTreePartInfo.h
浏览文件 @
5bc6bd55
...
...
@@ -29,6 +29,11 @@ struct MergeTreePartInfo
<
std
::
forward_as_tuple
(
rhs
.
partition_id
,
rhs
.
min_block
,
rhs
.
max_block
,
rhs
.
level
);
}
bool
operator
==
(
const
MergeTreePartInfo
&
rhs
)
const
{
return
!
(
*
this
<
rhs
||
rhs
<
*
this
);
}
/// Contains another part (obtained after merging another part with some other)
bool
contains
(
const
MergeTreePartInfo
&
rhs
)
const
{
...
...
dbms/src/Storages/StorageReplicatedMergeTree.cpp
浏览文件 @
5bc6bd55
...
...
@@ -2259,13 +2259,13 @@ bool StorageReplicatedMergeTree::fetchPart(const String & part_name, const Strin
checkPartAndAddToZooKeeper
(
part
,
ops
,
part_name
);
MergeTreeData
::
Transaction
transaction
;
replaced_parts
=
data
.
renameTempPartAndReplace
(
part
,
nullptr
,
&
transaction
);
data
.
renameTempPartAndReplace
(
part
,
nullptr
,
&
transaction
);
/// Do not commit if the part is obsolete
if
(
!
transaction
.
isEmpty
())
{
getZooKeeper
()
->
multi
(
ops
);
transaction
.
commit
();
replaced_parts
=
transaction
.
commit
();
}
/** If a quorum is tracked for this part, you must update it.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录