Bug 5504: Fix IllegalStateException handling from commit 44/40044/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 8 Jun 2016 06:45:20 +0000 (02:45 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 8 Jun 2016 07:34:46 +0000 (03:34 -0400)
https://git.opendaylight.org/gerrit/#/c/36172 attempted to
handle/workaround IllegalStateException thrown from commit to re-apply
the transaction. However the change wasn't correct - the commit call
actually throws an ExecutionException which the IllegalStateException as
the cause. So we need to catch ExecutionException and check it the cause
is IllegalStateException.

Change-Id: I65b2d646a60a700d070dea822d20b0e649290643
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java

index 1bd06146dec85490cd6d3820d7aef69cfc60e08d..ea6a41130132ffc045d3888c1016a3df5fb9ec34 100644 (file)
@@ -20,6 +20,7 @@ import com.google.common.base.Preconditions;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.cluster.common.actor.CommonConfig;
@@ -349,7 +350,11 @@ public class Shard extends RaftActor {
         try {
             try {
                 cohortEntry.commit();
-            } catch(IllegalStateException e) {
+            } catch(ExecutionException e) {
+                if(!(e.getCause() instanceof IllegalStateException)) {
+                    throw e;
+                }
+
                 // We may get a "store tree and candidate base differ" IllegalStateException from commit under
                 // certain edge case scenarios so we'll try to re-apply the candidate from scratch as a last
                 // resort. Eg, we're a follower and a tx payload is replicated but the leader goes down before
@@ -358,7 +363,7 @@ public class Shard extends RaftActor {
                 // candidate via applyState prior to the second tx. Since the second tx has already been
                 // pre-committed, when the it gets here to commit it will get an IllegalStateException.
 
-                LOG.debug("{}: commit failed for transaction {} - retrying as foreign candidate", persistenceId(),
+                LOG.warn("{}: commit failed for transaction {} - retrying as foreign candidate", persistenceId(),
                         transactionID, e);
 
                 store.applyForeignCandidate(transactionID, cohortEntry.getCandidate());