From 76e7a93ea5c8fa321fbf003574493364cb812b4a Mon Sep 17 00:00:00 2001 From: Liangliang Gu Date: Fri, 24 Dec 2021 16:54:18 +0800 Subject: [PATCH] cherry pick #443 to release-3.1 Signed-off-by: ti-srebot --- src/main/java/org/tikv/common/util/ConcreteBackOffer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/tikv/common/util/ConcreteBackOffer.java b/src/main/java/org/tikv/common/util/ConcreteBackOffer.java index 50abeae00fc..b550b9fdd98 100644 --- a/src/main/java/org/tikv/common/util/ConcreteBackOffer.java +++ b/src/main/java/org/tikv/common/util/ConcreteBackOffer.java @@ -168,6 +168,8 @@ public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType) { } public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType, long maxSleepMs) { + Histogram.Timer backOffTimer = BACKOFF_DURATION.labels(funcType.name()).startTimer(); + SlowLogSpan slowLogSpan = getSlowLog().start("backoff " + funcType.name()); BackOffFunction backOffFunction = backOffFunctionMap.computeIfAbsent(funcType, this::createBackOffFunc); @@ -179,12 +181,12 @@ public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType, long long currentMs = System.currentTimeMillis(); if (currentMs + sleep >= deadline) { logger.warn(String.format("Deadline %d is exceeded, errors:", deadline)); + slowLogSpan.end(); + backOffTimer.observeDuration(); return false; } } - Histogram.Timer backOffTimer = BACKOFF_DURATION.labels(funcType.name()).startTimer(); - SlowLogSpan slowLogSpan = getSlowLog().start("backoff " + funcType.name()); try { Thread.sleep(sleep); } catch (InterruptedException e) {