From c69edbd4425d67050687cfe90794df44381b35da Mon Sep 17 00:00:00 2001 From: houxiaoyu Date: Sun, 9 Jun 2024 22:47:22 +0800 Subject: [PATCH 1/2] Fix TimedRunnable log warn NPE --- .../bookkeeper/common/util/OrderedExecutor.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java index f856a4ea329..b97ec1bf623 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java @@ -187,10 +187,14 @@ public T build() { protected class TimedRunnable implements Runnable { final Runnable runnable; final long initNanos; + final String runnableString; + final Class runnableClass; TimedRunnable(Runnable runnable) { this.runnable = runnable; this.initNanos = MathUtils.nowInNano(); + this.runnableString = runnable.toString(); + this.runnableClass = runnable.getClass(); } @Override @@ -203,7 +207,7 @@ public void run() { long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos); taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS); if (elapsedMicroSec >= warnTimeMicroSec) { - log.warn("Runnable {}:{} took too long {} micros to execute.", runnable, runnable.getClass(), + log.warn("Runnable {}:{} took too long {} micros to execute.", runnableString, runnableClass, elapsedMicroSec); } } @@ -216,10 +220,14 @@ public void run() { protected class TimedCallable implements Callable { final Callable callable; final long initNanos; + final String callableleString; + final Class callableClass; TimedCallable(Callable callable) { this.callable = callable; this.initNanos = MathUtils.nowInNano(); + this.callableleString = callable.toString(); + this.callableClass = callable.getClass(); } @Override @@ -232,7 +240,7 @@ public T call() throws Exception { long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos); taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS); if (elapsedMicroSec >= warnTimeMicroSec) { - log.warn("Callable {}:{} took too long {} micros to execute.", callable, callable.getClass(), + log.warn("Callable {}:{} took too long {} micros to execute.", callableleString, callableClass, elapsedMicroSec); } } From 91c719dc8a9e776c609db3ab8b78047c380af71e Mon Sep 17 00:00:00 2001 From: houxiaoyu Date: Mon, 10 Jun 2024 10:28:31 +0800 Subject: [PATCH 2/2] Address comments --- .../apache/bookkeeper/common/util/OrderedExecutor.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java index b97ec1bf623..a6f137f4aaa 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java @@ -187,13 +187,11 @@ public T build() { protected class TimedRunnable implements Runnable { final Runnable runnable; final long initNanos; - final String runnableString; final Class runnableClass; TimedRunnable(Runnable runnable) { this.runnable = runnable; this.initNanos = MathUtils.nowInNano(); - this.runnableString = runnable.toString(); this.runnableClass = runnable.getClass(); } @@ -207,8 +205,7 @@ public void run() { long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos); taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS); if (elapsedMicroSec >= warnTimeMicroSec) { - log.warn("Runnable {}:{} took too long {} micros to execute.", runnableString, runnableClass, - elapsedMicroSec); + log.warn("Runnable {} took too long {} micros to execute.", runnableClass, elapsedMicroSec); } } } @@ -220,13 +217,11 @@ public void run() { protected class TimedCallable implements Callable { final Callable callable; final long initNanos; - final String callableleString; final Class callableClass; TimedCallable(Callable callable) { this.callable = callable; this.initNanos = MathUtils.nowInNano(); - this.callableleString = callable.toString(); this.callableClass = callable.getClass(); } @@ -240,8 +235,7 @@ public T call() throws Exception { long elapsedMicroSec = MathUtils.elapsedMicroSec(startNanos); taskExecutionStats.registerSuccessfulEvent(elapsedMicroSec, TimeUnit.MICROSECONDS); if (elapsedMicroSec >= warnTimeMicroSec) { - log.warn("Callable {}:{} took too long {} micros to execute.", callableleString, callableClass, - elapsedMicroSec); + log.warn("Callable {} took too long {} micros to execute.", callableClass, elapsedMicroSec); } } }