From d14713a96176e6d6033eb81d6e6f442f5d76add7 Mon Sep 17 00:00:00 2001 From: Liangliang Gu Date: Fri, 24 Dec 2021 16:54:18 +0800 Subject: [PATCH] fix slowlog in ConcreteBackOffer (#443) Signed-off-by: marsishandsome --- 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 eb4e28f121..a101831fd4 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 class ConcreteBackOffer implements BackOffer { } 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 class ConcreteBackOffer implements BackOffer { 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) {