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

Fix removing is_active node after re-creation #61105

Merged
merged 5 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Databases/DatabaseReplicatedWorker.cpp
Expand Up @@ -75,10 +75,9 @@ void DatabaseReplicatedDDLWorker::initializeReplication()
String active_path = fs::path(database->replica_path) / "active";
String active_id = toString(ServerUUID::get());
zookeeper->deleteEphemeralNodeIfContentMatches(active_path, active_id);
zookeeper->create(active_path, active_id, zkutil::CreateMode::Ephemeral);
if (active_node_holder)
active_node_holder->setAlreadyRemoved();
active_node_holder.reset();
active_node_holder_zookeeper = zookeeper;
active_node_holder = zkutil::EphemeralNodeHolder::existing(active_path, *active_node_holder_zookeeper);

String log_ptr_str = zookeeper->get(database->replica_path + "/log_ptr");
UInt32 our_log_ptr = parse<UInt32>(log_ptr_str);
Expand Down Expand Up @@ -127,9 +126,15 @@ void DatabaseReplicatedDDLWorker::initializeReplication()
initializeLogPointer(log_entry_name);
}

std::lock_guard lock{database->metadata_mutex};
if (!database->checkDigestValid(context, false))
throw Exception(ErrorCodes::LOGICAL_ERROR, "Inconsistent database metadata after reconnection to ZooKeeper");
{
std::lock_guard lock{database->metadata_mutex};
if (!database->checkDigestValid(context, false))
throw Exception(ErrorCodes::LOGICAL_ERROR, "Inconsistent database metadata after reconnection to ZooKeeper");
}

zookeeper->create(active_path, active_id, zkutil::CreateMode::Ephemeral);
active_node_holder_zookeeper = zookeeper;
active_node_holder = zkutil::EphemeralNodeHolder::existing(active_path, *active_node_holder_zookeeper);
}

String DatabaseReplicatedDDLWorker::enqueueQuery(DDLLogEntry & entry)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_replicated_database/test.py
Expand Up @@ -1138,6 +1138,10 @@ def test_sync_replica(started_cluster):

dummy_node.query("SYSTEM SYNC DATABASE REPLICA test_sync_database")

assert "2\n" == main_node.query(
"SELECT sum(is_active) FROM system.clusters WHERE cluster='test_sync_database'"
)

assert dummy_node.query(
"SELECT count() FROM system.tables where database='test_sync_database'"
).strip() == str(number_of_tables)
Expand Down