Do not declare unneeded Exception throw
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / Shard.java
index 7b34f5df6097ce4ea00c49233f3f4a4a8e5c7728..dabad41aff97b81ba83dcdf1626dca26e987a1b1 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionR
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
 import org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction;
+import org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree;
 import org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved;
 import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction;
 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
@@ -257,6 +258,8 @@ public class Shard extends RaftActor {
                 context().parent().tell(message, self());
             } else if(GET_SHARD_MBEAN_MESSAGE.equals(message)){
                 sender().tell(getShardMBean(), self());
+            } else if(message instanceof GetShardDataTree){
+                sender().tell(store.getDataTree(), self());
             } else {
                 super.onReceiveCommand(message);
             }
@@ -319,7 +322,7 @@ public class Shard extends RaftActor {
         return ModificationType.UNMODIFIED.equals(candidate.getRootNode().getModificationType());
     }
 
-    void continueCommit(final CohortEntry cohortEntry) throws Exception {
+    void continueCommit(final CohortEntry cohortEntry) {
         final DataTreeCandidate candidate = cohortEntry.getCandidate();
 
         // If we do not have any followers and we are not using persistence
@@ -408,6 +411,16 @@ public class Shard extends RaftActor {
         getSender().tell(new akka.actor.Status.Failure(new NoShardLeaderException(errMessage, persistenceId())), getSelf());
     }
 
+    protected void handleBatchedModificationsLocal(BatchedModifications batched, ActorRef sender) {
+        try {
+            commitCoordinator.handleBatchedModifications(batched, sender, this);
+        } catch (Exception e) {
+            LOG.error("{}: Error handling BatchedModifications for Tx {}", persistenceId(),
+                    batched.getTransactionID(), e);
+            sender.tell(new akka.actor.Status.Failure(e), getSelf());
+        }
+    }
+
     private void handleBatchedModifications(BatchedModifications batched) {
         // This message is sent to prepare the modifications transaction directly on the Shard as an
         // optimization to avoid the extra overhead of a separate ShardTransaction actor. On the last
@@ -424,13 +437,7 @@ public class Shard extends RaftActor {
         if(isLeader()) {
             failIfIsolatedLeader(getSender());
 
-            try {
-                commitCoordinator.handleBatchedModifications(batched, getSender(), this);
-            } catch (Exception e) {
-                LOG.error("{}: Error handling BatchedModifications for Tx {}", persistenceId(),
-                        batched.getTransactionID(), e);
-                getSender().tell(new akka.actor.Status.Failure(e), getSelf());
-            }
+            handleBatchedModificationsLocal(batched, getSender());
         } else {
             ActorSelection leader = getLeader();
             if(leader != null) {
@@ -446,7 +453,7 @@ public class Shard extends RaftActor {
     }
 
     private boolean failIfIsolatedLeader(ActorRef sender) {
-        if(getRaftState() == RaftState.IsolatedLeader) {
+        if(isIsolatedLeader()) {
             sender.tell(new akka.actor.Status.Failure(new NoShardLeaderException(String.format(
                     "Shard %s was the leader but has lost contact with all of its followers. Either all" +
                     " other follower nodes are down or this node is isolated by a network partition.",
@@ -457,6 +464,10 @@ public class Shard extends RaftActor {
         return false;
     }
 
+    protected boolean isIsolatedLeader() {
+        return getRaftState() == RaftState.IsolatedLeader;
+    }
+
     private void handleReadyLocalTransaction(final ReadyLocalTransaction message) {
         if (isLeader()) {
             failIfIsolatedLeader(getSender());
@@ -684,6 +695,10 @@ public class Shard extends RaftActor {
         return commitCoordinator;
     }
 
+    public DatastoreContext getDatastoreContext() {
+        return datastoreContext;
+    }
+
     protected abstract static class AbstractShardCreator implements Creator<Shard> {
         private static final long serialVersionUID = 1L;