-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ISSUES-2259 support truncate syntax #2260
ISSUES-2259 support truncate syntax #2260
Conversation
@@ -126,6 +126,13 @@ void StorageMergeTree::drop() | |||
data.dropAllData(); | |||
} | |||
|
|||
void StorageMergeTree::truncate() | |||
{ | |||
shutdown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexey-milovidov shutdown
is synchronous? What would I do if it wasn't ? Because I need to know when the merge task is terminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's synchronous.
13cb9f3
to
ba84566
Compare
Please check for ReplicatedMergeTree tables. The implementation shouldn't be trivial for them. |
ba84566
to
7c5784b
Compare
The current idea is based on the ReplicatedMergeTreeLogEntryData::TRUNCATE_TABLE command |
8debac1
to
f567adb
Compare
a7b8106
to
ad40fcf
Compare
00588d4
to
f7fb7ab
Compare
fbdfa12
to
9db8f35
Compare
b3e4aa4
to
2464f64
Compare
I'm done. Please help review the changes. @alexey-milovidov @ztlpn |
31c0789
to
8936d88
Compare
dbms/src/Common/ZooKeeper/Types.h
Outdated
@@ -54,6 +54,9 @@ using SetResponse = ZooKeeperImpl::ZooKeeper::SetResponse; | |||
using ListResponse = ZooKeeperImpl::ZooKeeper::ListResponse; | |||
using CheckResponse = ZooKeeperImpl::ZooKeeper::CheckResponse; | |||
|
|||
template <typename R> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comment.
dbms/src/Common/ZooKeeper/Types.h
Outdated
@@ -54,6 +54,9 @@ using SetResponse = ZooKeeperImpl::ZooKeeper::SetResponse; | |||
using ListResponse = ZooKeeperImpl::ZooKeeper::ListResponse; | |||
using CheckResponse = ZooKeeperImpl::ZooKeeper::CheckResponse; | |||
|
|||
template <typename R> | |||
using MultiAsyncResponse = std::vector<std::pair<std::string, std::future<R>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad name. It shouldn't mess up with "multi" operation in ZooKeeper.
More correct name: AsyncResponses.
82bf137
to
3afb335
Compare
/// Delete metadata, the deletion of which differs from the recursive deletion of the directory, if any. | ||
virtual void drop() = 0; | ||
/// Delete database metadata, if exists. | ||
virtual void drop(Context & context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method body should be in .cpp
This method is not quite correct, because only Ordinary databases have metadata for tables as files in metadata directory. Other databases doesn't require removal of metadata from filesystem.
Creating and removing database.sql
files is not the responsibility of Database itself.
For example, database doesn't create this file, so it shouldn't remove it.
Another example: tables (Storage
s) are not responsible for creating and removing .sql
files - it is the responsibility of Database. By the same principle, Database is not responsible for creating and removing its .sql
files - this is the responsibility of caller.
If this method removes internal metadata directory, why it doesn't remove internal data directory?
Fixed.
@@ -0,0 +1,68 @@ | |||
#include <Interpreters/ClusterProxy/TruncateStreamFactory.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't proxy TRUNCATE
query for Distributed table, because query ON CLUSTER
already do it.
String current_table_name = table.first->getTableName(); | ||
|
||
if (drop.detach) | ||
else if (kind == ASTDropQuery::Kind::Truncate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkTableCanBeDropped
should be called for truncate, because it is equally dangerous operation.
String getID() const override { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; }; | ||
String getID() const override | ||
{ | ||
if (kind == ASTDropQuery::Kind::Drop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-trivial methods should be in .cpp.
<< (detach ? "DETACH TABLE " : "DROP TABLE ") | ||
<< (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "") | ||
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table); | ||
settings.ostr << (settings.hilite ? hilite_keyword : ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste.
/** Delete the table data. Called before deleting the directory with the data. | ||
* If you do not need any action other than deleting the directory with data, you can leave this method blank. | ||
*/ | ||
virtual void truncate(const ASTPtr & /*query*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is a copy-paste of the above. This may lead to confusion.
I've totally rewrite this comment.
@@ -797,7 +797,16 @@ void MergeTreeData::dropAllData() | |||
|
|||
LOG_TRACE(log, "dropAllData: removing data from filesystem."); | |||
|
|||
Poco::File(full_path).remove(true); | |||
std::vector<Poco::File> data_dirs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation is unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comments.
} | ||
} | ||
|
||
ClusterProxy::TruncateStreamFactory truncate_stream_factory(cluster); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this.
|
||
void StorageMergeTree::truncate(const ASTPtr & /*query*/) | ||
{ | ||
merger.merges_blocker.cancelForever(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How the merges are supposed to work after truncate?
|
||
if (fake_part_name.empty()) | ||
if (dropBlocksInPartition(*zookeeper, partition_id, entry, detach)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropParts, not Blocks.
@@ -3808,14 +3802,18 @@ void ReplicatedMergeTreeMergeSelectingThread::clearState() | |||
{ | |||
deduplicate = false; /// TODO: read deduplicate option from table config | |||
|
|||
uncached_merging_predicate = [this](const MergeTreeData::DataPartPtr & left, const MergeTreeData::DataPartPtr & right) | |||
uncached_merging_predicate = [this](const MergeTreeData::DataPartPtr &left, const MergeTreeData::DataPartPtr &right) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification.
{ | ||
return canMergePartsAccordingToZooKeeperInfo(left, right, storage->getZooKeeper(), storage->zookeeper_path, storage->data); | ||
return canMergePartsAccordingToZooKeeperInfo(left, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification.
}; | ||
|
||
merging_predicate_args_to_key = [](const MergeTreeData::DataPartPtr & left, const MergeTreeData::DataPartPtr & right) | ||
merging_predicate_args_to_key = [](const MergeTreeData::DataPartPtr &left, const MergeTreeData::DataPartPtr &right) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification.
{ | ||
return std::make_pair(left->name, right->name); | ||
return std::make_pair(left->name, right->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification. Wrong indentation.
@@ -3824,11 +3822,49 @@ void ReplicatedMergeTreeMergeSelectingThread::clearState() | |||
|
|||
now = std::chrono::steady_clock::time_point(); | |||
|
|||
can_merge = [&] (const MergeTreeData::DataPartPtr & left, const MergeTreeData::DataPartPtr & right, String *) | |||
can_merge = [&](const MergeTreeData::DataPartPtr &left, const MergeTreeData::DataPartPtr &right, String *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification.
return partsWillNotBeMergedOrDisabled(left, right, storage->queue) | ||
&& cached_merging_predicate->get(now, uncached_merging_predicate, merging_predicate_args_to_key, left, right); | ||
return partsWillNotBeMergedOrDisabled(left, right, storage->queue) | ||
&& cached_merging_predicate->get(now, uncached_merging_predicate, merging_predicate_args_to_key, left, right); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidential modification.
I would like to prefer different method of implementation: There is default implementation for truncate, that simply do drop and create table under lock. Cons:
Pros:
|
Thank you! This is definitely useful feature. This should be done atomically (from the client point of view). It can be done under global (context) lock. |
@alexey-milovidov Thank for you review, I have learned a lot. |
#2259
CheckList
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en