Merge pull request #61105 from ClickHouse/fix_rdb_active

Fix removing is_active node after re-creation
This commit is contained in:
Alexander Tokmakov 2024-03-21 15:29:59 +01:00 committed by GitHub
commit 2be2ca4605
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -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);
@ -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");
}
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)

View File

@ -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)