-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
SYSTEM UNFREEZE query that deletes the whole backup #36424
Conversation
auto store_path = backup_path / "store"; | ||
|
||
for (auto disk: disks) { | ||
if (!disk->exists(store_path)) |
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.
Also check and remove backup_path
if exists.
continue; | ||
for (auto it = disk->iterateDirectory(store_path); it->isValid(); it->next()) { | ||
const auto & prefix_directory = it->name(); | ||
auto absolute_prefix_directory = store_path / prefix_directory; |
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.
Name absolute_...
may confuse here, it's relative to disk root.
disk->removeRecursive(backup_path); | ||
} | ||
|
||
LOG_ERROR(&Poco::Logger::get("AwesomeClass"), "Unfreezing{}", "b"); |
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.
InterpreterSystemQuery has a log
member, use it - LOG_ERROR(log, ...)
In other case, use class name, like LOG_ERROR(&Poco::Logger::get("InterpreterSystemQuery"), ...)
And what is last "b"
?
for (auto it = disk->iterateDirectory(absolute_prefix_directory); it->isValid(); it->next()) { | ||
const auto & table_directory = it->name(); | ||
auto absolute_table_directory = absolute_prefix_directory / table_directory; | ||
MergeTreeData::unfreezePartitionsFromTableDirectory([] (const String &) { return true; }, query.backup_name, disks, absolute_table_directory, &Poco::Logger::get("AwesomeClass"), getContext()); |
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.
MergeTreeData
has own log
member, not necessary to send log object from here (and in common case do not send it from class to class, use own log
in each class).
case Type::UNFREEZE: | ||
{ | ||
LOG_ERROR(&Poco::Logger::get("AwesomeClass"), "getrequiredlalal{}", "b"); | ||
exit(0); |
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.
exit???
PartitionCommandsResultInfo MergeTreeData::unfreezePartitionsByMatcher(MatcherFn matcher, const String & backup_name, ContextPtr) | ||
// copy and some edits from StorageReplicatedMergeTree::removeSharedDetachedPart | ||
bool removeSharedDetachedPart(DiskPtr disk, const String & path, const String & part_name, const String & table_uuid, | ||
const String &, const String & detached_replica_name, const String & detached_zookeeper_path, Poco::Logger * log, ContextPtr local_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.
This code (removeSharedDetachedPart
, removeDetachedPart
and may be unfreezePartitionsFromTableDirectory
) should be moved in some new separate class, I think. FreezeMetaData
struct too.
Non-replicated MergeTreeData
should know nothing about ZooKeeper.
struct FreezeMetaData | ||
{ | ||
public: | ||
void fill(const StorageReplicatedMergeTree & storage) |
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.
Leave methods definitions in cpp file.
src/Parsers/ParserSystemQuery.cpp
Outdated
@@ -5,6 +5,7 @@ | |||
#include <Parsers/ASTIdentifier.h> | |||
#include <Parsers/ASTLiteral.h> | |||
#include <Parsers/parseDatabaseAndTableName.h> | |||
#include <base/logger_useful.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.
Is log used somewhere here?
src/Access/Common/AccessType.h
Outdated
@@ -162,6 +162,7 @@ enum class AccessType | |||
M(SYSTEM_FLUSH_LOGS, "FLUSH LOGS", GLOBAL, SYSTEM_FLUSH) \ | |||
M(SYSTEM_FLUSH, "", GROUP, SYSTEM) \ | |||
M(SYSTEM_THREAD_FUZZER, "SYSTEM START THREAD FUZZER, SYSTEM STOP THREAD FUZZER, START THREAD FUZZER, STOP THREAD FUZZER", GLOBAL, SYSTEM) \ | |||
M(SYSTEM_UNFREEZE, "RESTART REPLICA", GLOBAL, SYSTEM) \ |
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.
Strange permission
case Type::UNFREEZE: | ||
{ | ||
getContext()->checkAccess(AccessType::SYSTEM_UNFREEZE); | ||
result = Unfreezer().unfreeze(query.backup_name, getContext()); |
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 is the only one place in this method where some result returned. I thing here should be a comment with explanation, why.
300ad63
to
4b581dc
Compare
Comments from GrigoryPervakov and ianton-ru are fixed |
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.
Please merge the latest master
81c00f2
to
bc45ebc
Compare
@antonio2368 all comments have been addressed |
bc45ebc
to
0e40c5f
Compare
3dff44e
to
781acbd
Compare
@antonio2368 thank you, all comments have been addressed |
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.
Very nice tests
a530b47
to
637d293
Compare
The new test |
Ok, I will fix the test, thank you @tavplubix |
const auto & partition_directory = it->name(); | ||
|
||
/// Partition ID is prefix of part directory name: <partition id>_<rest of part directory name> | ||
auto found = partition_directory.find('_'); | ||
if (found == std::string::npos) | ||
continue; | ||
auto partition_id = partition_directory.substr(0, found); | ||
|
||
if (!matcher(partition_id)) | ||
continue; |
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 does not work correctly if table was created with old syntax. It's ok to drop support for UNFREEZE in this case, but we should throw an exception at least.
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.
forgot about that
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.
Do you mean to match old syntax and if there is an old syntax, throw an exception? How do I match old syntax? What if user wants to unfreeze just something but instead gets an exception and no unfreezed data?
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.
Do you mean to match old syntax and if there is an old syntax, throw an exception?
Yep, it's enough (but you can add support for old syntax if you want).
How do I match old syntax?
When unfreezePartitionsFromTableDirectory
is called from MergeTreeData
you can pass format_version
as an argument. And when it's called Unfreezer::unfreeze
you don't need to parse partition id at all.
{ | ||
bool keep_shared = false; | ||
|
||
zkutil::ZooKeeperPtr zookeeper = getZooKeeper(); | ||
zkutil::ZooKeeperPtr zookeeper = local_context->getZooKeeper(); |
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 looks absolutely incorrect. Usually all operations with zk during a query/task execution must be done in single session.
@tavplubix fixed everything except zookeeper here #38262 (review) |
The query sounds dangerous. What protection do we have to disallow it by default? |
Sound like a good idea |
Why does that sound dangerous? There is already a query to unfreeze partition or a table. Is it because of recursive deletion? |
Zookeeper and server config fixed here #38262 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added
SYSTEM UNFREEZE
query that deletes the whole backup regardless if the corresponding table is deleted or not.#34794
Code to be deduplicated, tests and docs to be added later in this PR.