From cbaf9f899ad9efa1f988eeb5dfc60a4ec02b25d3 Mon Sep 17 00:00:00 2001 From: lin chen <1572139390@qq.com> Date: Wed, 23 Feb 2022 18:16:56 +0800 Subject: [PATCH] fix checkAllLedgersDuration compute (#2970) (cherry picked from commit dc2be020eb87c777b9ef9a9e89cbe5f225de07ae) --- .../java/org/apache/bookkeeper/replication/Auditor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java index d30eb32a20c..25d72c3dcab 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java @@ -763,18 +763,20 @@ private void scheduleCheckAllLedgersTask(){ executor.scheduleAtFixedRate(safeRun(new Runnable() { @Override public void run() { + Stopwatch stopwatch = Stopwatch.createStarted(); + boolean checkSuccess = false; try { if (!ledgerUnderreplicationManager.isLedgerReplicationEnabled()) { LOG.info("Ledger replication disabled, skipping checkAllLedgers"); return; } - Stopwatch stopwatch = Stopwatch.createStarted(); LOG.info("Starting checkAllLedgers"); checkAllLedgers(); long checkAllLedgersDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS); LOG.info("Completed checkAllLedgers in {} milliSeconds", checkAllLedgersDuration); checkAllLedgersTime.registerSuccessfulEvent(checkAllLedgersDuration, TimeUnit.MILLISECONDS); + checkSuccess = true; } catch (InterruptedException ie) { Thread.currentThread().interrupt(); LOG.error("Interrupted while running periodic check", ie); @@ -787,6 +789,11 @@ public void run() { submitShutdownTask(); } catch (ReplicationException.UnavailableException ue) { LOG.error("Underreplication manager unavailable running periodic check", ue); + } finally { + if (!checkSuccess) { + long checkAllLedgersDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS); + checkAllLedgersTime.registerFailedEvent(checkAllLedgersDuration, TimeUnit.MILLISECONDS); + } } } }), initialDelay, interval, TimeUnit.SECONDS);