You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/09/26 09:41:47 UTC

[bookkeeper] branch master updated: Issue #1700: fixed: TimedRunnable does not anticipate exception from wrapped runnable

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new d8e0a9a  Issue #1700: fixed: TimedRunnable does not anticipate exception from wrapped runnable
d8e0a9a is described below

commit d8e0a9aa6097eacd13afc2898f89627a15e59e02
Author: Andrey Yegorov <dl...@users.noreply.github.com>
AuthorDate: Wed Sep 26 02:41:42 2018 -0700

    Issue #1700: fixed: TimedRunnable does not anticipate exception from wrapped runnable
    
    Descriptions of the changes in this PR:
    
    added try/finally around runnable.run()
    
    ### Motivation
    
    To correctly track (metrics/log) runnable that throw unexpected exception.
    
    ### Changes
    
    added try/finally around runnable.run()
    
    Master Issue: #1700
    
    
    
    
    Author: Qi Wang <42...@users.noreply.github.com>
    Author: Charan Reddy Guttapalem <re...@gmail.com>
    Author: Sijie Guo <gu...@gmail.com>
    Author: Andrey Yegorov <ay...@salesforce.com>
    
    Reviewers: Sijie Guo <si...@apache.org>, Enrico Olivelli <eo...@gmail.com>
    
    This closes #1702 from dlg99/fix/issue_1700_timedrunnable, closes #1700
---
 .../apache/bookkeeper/common/util/OrderedExecutor.java    | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 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 520787b..ab62a68 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,12 +187,15 @@ public class OrderedExecutor implements ExecutorService {
         public void run() {
             taskPendingStats.registerSuccessfulEvent(MathUtils.elapsedNanos(initNanos), TimeUnit.NANOSECONDS);
             long startNanos = MathUtils.nowInNano();
-            this.runnable.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(),
-                        elapsedMicroSec);
+            try {
+                this.runnable.run();
+            } finally {
+                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(),
+                            elapsedMicroSec);
+                }
             }
         }
     }