Skip to content
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

Merged
merged 4 commits into from
Jun 14, 2022

Conversation

PolyProgrammist
Copy link
Contributor

@PolyProgrammist PolyProgrammist commented Apr 19, 2022

Changelog category (leave one):

  • New Feature

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.

Information about CI checks: https://clickhouse.tech/docs/en/development/continuous-integration/

#34794

Code to be deduplicated, tests and docs to be added later in this PR.

@CLAassistant
Copy link

CLAassistant commented Apr 19, 2022

CLA assistant check
All committers have signed the CLA.

@robot-ch-test-poll robot-ch-test-poll added the pr-feature Pull request with new product feature label Apr 19, 2022
@PolyProgrammist PolyProgrammist changed the title R1unfreeze SYSTEM UNFREEZE query that deletes the whole backup Apr 19, 2022
auto store_path = backup_path / "store";

for (auto disk: disks) {
if (!disk->exists(store_path))
Copy link
Contributor

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;
Copy link
Contributor

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");
Copy link
Contributor

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());
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

@@ -5,6 +5,7 @@
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/parseDatabaseAndTableName.h>
#include <base/logger_useful.h>
Copy link
Contributor

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?

@@ -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) \
Copy link
Contributor

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());
Copy link
Contributor

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.

@PolyProgrammist
Copy link
Contributor Author

Comments from GrigoryPervakov and ianton-ru are fixed

@antonio2368 antonio2368 self-assigned this May 20, 2022
Copy link
Member

@antonio2368 antonio2368 left a 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

src/Storages/Freeze.h Outdated Show resolved Hide resolved
src/Storages/Freeze.h Outdated Show resolved Hide resolved
src/Storages/Freeze.h Outdated Show resolved Hide resolved
src/Storages/Freeze.h Outdated Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
@PolyProgrammist PolyProgrammist force-pushed the r1unfreeze branch 2 times, most recently from 81c00f2 to bc45ebc Compare May 27, 2022 18:49
@PolyProgrammist
Copy link
Contributor Author

@antonio2368 all comments have been addressed

src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
src/Storages/Freeze.h Outdated Show resolved Hide resolved
@PolyProgrammist
Copy link
Contributor Author

@antonio2368 thank you, all comments have been addressed

Copy link
Member

@antonio2368 antonio2368 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice tests

src/Storages/Freeze.cpp Show resolved Hide resolved
src/Storages/Freeze.cpp Outdated Show resolved Hide resolved
@antonio2368 antonio2368 merged commit dded528 into ClickHouse:master Jun 14, 2022
@tavplubix
Copy link
Member

The new test 01417_freeze_partition_verbose fails in check ClickHouse Stateless Tests (release, Databaseordinary, Actions) (we run this check only in master, so checks in this PR were OK). I disabled this test for Ordinary database (dcfe4ee), please fix it if it was supposed to work with Ordinary database as well (and ignore this comment if it was not).

@PolyProgrammist
Copy link
Contributor Author

Ok, I will fix the test, thank you @tavplubix

@PolyProgrammist
Copy link
Contributor Author

@tavplubix #38262 (review)

Comment on lines +170 to +179
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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot about that

Copy link
Contributor Author

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?

Copy link
Member

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();
Copy link
Member

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.

@PolyProgrammist
Copy link
Contributor Author

@tavplubix fixed everything except zookeeper here #38262 (review)

@alexey-milovidov
Copy link
Member

@PolyProgrammist

The query sounds dangerous. What protection do we have to disallow it by default?
Maybe add a server configuration option?

@PolyProgrammist
Copy link
Contributor Author

@PolyProgrammist

The query sounds dangerous. What protection do we have to disallow it by default? Maybe add a server configuration option?

Sound like a good idea

@PolyProgrammist
Copy link
Contributor Author

@PolyProgrammist

The query sounds dangerous. What protection do we have to disallow it by default? Maybe add a server configuration option?

Why does that sound dangerous? There is already a query to unfreeze partition or a table. Is it because of recursive deletion?

@PolyProgrammist
Copy link
Contributor Author

Zookeeper and server config fixed here #38262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants