Skip to content

Commit d1b1b44

Browse files
Backport ClickHouse#88671 to 25.8: Don't try to mark non-existing entries as finished when recovering a Replicated database replica
1 parent 35b8f5b commit d1b1b44

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Databases/DatabaseReplicated.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,16 @@ void DatabaseReplicated::recoverLostReplica(const ZooKeeperPtr & current_zookeep
16201620
/// It's a very rare case, and it's okay if some queries throw TIMEOUT_EXCEEDED when waiting for all replicas
16211621
if (first_entry_to_mark_finished)
16221622
{
1623+
/// Skip non-existing entries that were removed a long time ago (if the replica was offline for a long time)
1624+
Strings all_nodes = current_zookeeper->getChildren(fs::path(zookeeper_path) / "log");
1625+
std::erase_if(all_nodes, [] (const String & s) { return !startsWith(s, "query-"); });
1626+
auto oldest_node = std::min_element(all_nodes.begin(), all_nodes.end());
1627+
if (oldest_node != all_nodes.end())
1628+
{
1629+
UInt32 oldest_entry = DDLTaskBase::getLogEntryNumber(*oldest_node);
1630+
first_entry_to_mark_finished = std::max(oldest_entry, first_entry_to_mark_finished);
1631+
}
1632+
16231633
/// If the replica is new and some of the queries applied during recovery
16241634
/// where issued after the replica was created, then other nodes might be
16251635
/// waiting for this node to notify them that the query was applied.

0 commit comments

Comments
 (0)