diff --git a/src/main/java/org/tikv/common/util/ConcreteBackOffer.java b/src/main/java/org/tikv/common/util/ConcreteBackOffer.java index eb4e28f1214..a101831fd44 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) {