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

Feature: Optimize the replica delay api logic #45148

Merged
merged 17 commits into from
Feb 14, 2023
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
24 changes: 16 additions & 8 deletions src/Server/ReplicasStatusHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,22 @@ void ReplicasStatusHandler::handleRequest(HTTPServerRequest & request, HTTPServe
time_t absolute_delay = 0;
time_t relative_delay = 0;

table_replicated->getReplicaDelays(absolute_delay, relative_delay);

if ((settings.min_absolute_delay_to_close && absolute_delay >= static_cast<time_t>(settings.min_absolute_delay_to_close))
|| (settings.min_relative_delay_to_close && relative_delay >= static_cast<time_t>(settings.min_relative_delay_to_close)))
ok = false;

message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name())
<< ":\tAbsolute delay: " << absolute_delay << ". Relative delay: " << relative_delay << ".\n";
if (!table_replicated->isTableReadOnly())
{
table_replicated->getReplicaDelays(absolute_delay, relative_delay);

if ((settings.min_absolute_delay_to_close && absolute_delay >= static_cast<time_t>(settings.min_absolute_delay_to_close))
|| (settings.min_relative_delay_to_close && relative_delay >= static_cast<time_t>(settings.min_relative_delay_to_close)))
ok = false;

message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name())
<< ":\tAbsolute delay: " << absolute_delay << ". Relative delay: " << relative_delay << ".\n";
}
else
{
message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name())
<< ":\tis readonly. \n";
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Storages/StorageReplicatedMergeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class StorageReplicatedMergeTree final : public MergeTreeData
const String & replica_name, const String & zookeeper_path, const ContextPtr & local_context, const zkutil::ZooKeeperPtr & zookeeper);

bool canUseZeroCopyReplication() const;

bool isTableReadOnly () { return is_readonly; }
private:
std::atomic_bool are_restoring_replica {false};

Expand Down