From eae0f9957cfa836be89590557cf74f6cd9a19152 Mon Sep 17 00:00:00 2001 From: mateng0915 Date: Wed, 11 Jan 2023 16:25:24 +0800 Subject: [PATCH 1/4] Feature: Optimize the replica delay api logic Description: ============ Currently if in the Whole CK instance has one table is read only status then the API /replicas_status will throw error, xxx table is read only For make this monitor can work in prod env, we can catch the read only status instead of directly throw error Solution: ========= Return other normal table's delay value even if the CK instance has readonly Replicatedxxx table Please enter the commit message for your changes. Lines starting --- src/Server/ReplicasStatusHandler.cpp | 20 ++++++++++++++------ src/Storages/StorageReplicatedMergeTree.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Server/ReplicasStatusHandler.cpp b/src/Server/ReplicasStatusHandler.cpp index 4818362c939..a31a368e83d 100644 --- a/src/Server/ReplicasStatusHandler.cpp +++ b/src/Server/ReplicasStatusHandler.cpp @@ -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(!table_replicated->isTableReadOnly()) + { + table_replicated->getReplicaDelays(absolute_delay, relative_delay); - if ((settings.min_absolute_delay_to_close && absolute_delay >= static_cast(settings.min_absolute_delay_to_close)) - || (settings.min_relative_delay_to_close && relative_delay >= static_cast(settings.min_relative_delay_to_close))) - ok = false; + if ((settings.min_absolute_delay_to_close && absolute_delay >= static_cast(settings.min_absolute_delay_to_close)) + || (settings.min_relative_delay_to_close && relative_delay >= static_cast(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"; + } - message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name()) - << ":\tAbsolute delay: " << absolute_delay << ". Relative delay: " << relative_delay << ".\n"; } } diff --git a/src/Storages/StorageReplicatedMergeTree.h b/src/Storages/StorageReplicatedMergeTree.h index 218b9d0e31a..8fd6d46c6d3 100644 --- a/src/Storages/StorageReplicatedMergeTree.h +++ b/src/Storages/StorageReplicatedMergeTree.h @@ -322,6 +322,8 @@ public: 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}; From 6e9dc2527fe00c2960492b8bf2bfc93281136218 Mon Sep 17 00:00:00 2001 From: mateng0915 Date: Mon, 13 Feb 2023 11:43:01 +0800 Subject: [PATCH 2/4] fixed review comments --- src/Server/ReplicasStatusHandler.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Server/ReplicasStatusHandler.cpp b/src/Server/ReplicasStatusHandler.cpp index a31a368e83d..8c0ab0c1a3b 100644 --- a/src/Server/ReplicasStatusHandler.cpp +++ b/src/Server/ReplicasStatusHandler.cpp @@ -59,7 +59,7 @@ void ReplicasStatusHandler::handleRequest(HTTPServerRequest & request, HTTPServe time_t absolute_delay = 0; time_t relative_delay = 0; - if(!table_replicated->isTableReadOnly()) + if (!table_replicated->isTableReadOnly()) { table_replicated->getReplicaDelays(absolute_delay, relative_delay); @@ -69,12 +69,12 @@ void ReplicasStatusHandler::handleRequest(HTTPServerRequest & request, HTTPServe message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name()) << ":\tAbsolute delay: " << absolute_delay << ". Relative delay: " << relative_delay << ".\n"; - - } else { + } + else + { message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name()) << ":\tis readonly. \n"; } - } } From 4290df27c6bf13678e463e908debb40c6bf34579 Mon Sep 17 00:00:00 2001 From: pufit Date: Tue, 14 Feb 2023 00:35:40 +0000 Subject: [PATCH 3/4] try to fix ci From c7105c60f57c24c1399f66090675cff6c821f0fa Mon Sep 17 00:00:00 2001 From: pufit Date: Tue, 14 Feb 2023 00:40:27 +0000 Subject: [PATCH 4/4] try to fix ci