Bug 2948: Store DataPersistenceProvider in RaftActorContext 04/17804/5
authorTom Pantelis <tpanteli@brocade.com>
Sat, 4 Apr 2015 03:27:51 +0000 (23:27 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 10 Apr 2015 22:52:19 +0000 (18:52 -0400)
This will make the DataPersistenceProvider accessible to callers that
don't have access to the RaftActor. In particular, the SnapshotManager
will need access from the capture method (subsequent patch). The
DataPersistenceProvider can't be passed to capture b/c it is also
called from AbstractLeader which doesn't have access to the
DataPersistenceProvider.

With thus change we no longer have to pass the DataPersistenceProvider to
the persist and commit methods either.

Change-Id: I187901476f2728e4b7f72238e72006c95c188b55
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContext.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorContextImpl.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupportTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImplTest.java

index 2185ffd..157a53e 100644 (file)
@@ -124,7 +124,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
         context = new RaftActorContextImpl(this.getSelf(),
             this.getContext(), id, new ElectionTermImpl(delegatingPersistenceProvider, id, LOG),
             -1, -1, peerAddresses,
-            (configParams.isPresent() ? configParams.get(): new DefaultConfigParamsImpl()), LOG);
+            (configParams.isPresent() ? configParams.get(): new DefaultConfigParamsImpl()),
+            delegatingPersistenceProvider, LOG);
 
         context.setReplicatedLog(ReplicatedLogImpl.newInstance(context, delegatingPersistenceProvider, currentBehavior));
     }
index 9f4b7cb..7198876 100644 (file)
@@ -15,6 +15,7 @@ import akka.actor.Props;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Supplier;
 import java.util.Map;
+import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.slf4j.Logger;
 
 /**
@@ -170,6 +171,8 @@ public interface RaftActorContext {
 
     SnapshotManager getSnapshotManager();
 
+    DataPersistenceProvider getPersistenceProvider();
+
     boolean hasFollowers();
 
     long getTotalMemory();
index 684845c..049b91c 100644 (file)
@@ -17,6 +17,7 @@ import akka.actor.UntypedActorContext;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Supplier;
 import java.util.Map;
+import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.slf4j.Logger;
 
 public class RaftActorContextImpl implements RaftActorContext {
@@ -48,9 +49,11 @@ public class RaftActorContextImpl implements RaftActorContext {
     // be passed to it in the constructor
     private SnapshotManager snapshotManager;
 
+    private final DataPersistenceProvider persistenceProvider;
+
     public RaftActorContextImpl(ActorRef actor, UntypedActorContext context, String id,
             ElectionTerm termInformation, long commitIndex, long lastApplied, Map<String, String> peerAddresses,
-            ConfigParams configParams, Logger logger) {
+            ConfigParams configParams, DataPersistenceProvider persistenceProvider, Logger logger) {
         this.actor = actor;
         this.context = context;
         this.id = id;
@@ -59,6 +62,7 @@ public class RaftActorContextImpl implements RaftActorContext {
         this.lastApplied = lastApplied;
         this.peerAddresses = peerAddresses;
         this.configParams = configParams;
+        this.persistenceProvider = persistenceProvider;
         this.LOG = logger;
     }
 
@@ -182,4 +186,9 @@ public class RaftActorContextImpl implements RaftActorContext {
     public boolean hasFollowers() {
         return getPeerAddresses().keySet().size() > 0;
     }
+
+    @Override
+    public DataPersistenceProvider getPersistenceProvider() {
+        return persistenceProvider;
+    }
 }
index bab4a33..adf7778 100644 (file)
@@ -19,6 +19,8 @@ import com.google.protobuf.GeneratedMessage;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import org.opendaylight.controller.cluster.DataPersistenceProvider;
+import org.opendaylight.controller.cluster.NonPersistentDataProvider;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages;
 import org.opendaylight.controller.protobuff.messages.cluster.raft.test.MockPayloadMessages;
@@ -38,6 +40,7 @@ public class MockRaftActorContext implements RaftActorContext {
     private ConfigParams configParams;
     private boolean snapshotCaptureInitiated;
     private SnapshotManager snapshotManager;
+    private DataPersistenceProvider persistenceProvider = new NonPersistentDataProvider();
 
     public MockRaftActorContext(){
         electionTerm = new ElectionTerm() {
@@ -219,6 +222,15 @@ public class MockRaftActorContext implements RaftActorContext {
         return getPeerAddresses().keySet().size() > 0;
     }
 
+    @Override
+    public DataPersistenceProvider getPersistenceProvider() {
+        return persistenceProvider;
+    }
+
+    public void setPersistenceProvider(DataPersistenceProvider persistenceProvider) {
+        this.persistenceProvider = persistenceProvider;
+    }
+
     public static class SimpleReplicatedLog extends AbstractReplicatedLogImpl {
         @Override public void appendAndPersist(
             ReplicatedLogEntry replicatedLogEntry) {
index 7420fc4..c4e0ef8 100644 (file)
@@ -60,7 +60,7 @@ public class RaftActorRecoverySupportTest {
         MockitoAnnotations.initMocks(this);
 
         context = new RaftActorContextImpl(null, null, "test", new ElectionTermImpl(mockPersistence, "test", LOG),
-                -1, -1, Collections.<String,String>emptyMap(), configParams, LOG);
+                -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG);
 
         support = new RaftActorRecoverySupport(mockPersistence, context , mockBehavior, mockCohort);
 
index 86b90d8..2ced72c 100644 (file)
@@ -69,7 +69,7 @@ public class RaftActorSnapshotMessageSupportTest {
 
         context = new RaftActorContextImpl(mockRaftActorRef, null, "test",
                 new ElectionTermImpl(mockPersistence, "test", LOG),
-                -1, -1, Collections.<String,String>emptyMap(), configParams, LOG) {
+                -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG) {
             @Override
             public SnapshotManager getSnapshotManager() {
                 return mockSnapshotManager;
index 72ccae7..92e384e 100644 (file)
@@ -31,7 +31,7 @@ import org.mockito.internal.matchers.Same;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.RaftActor.DeleteEntries;
+import org.opendaylight.controller.cluster.raft.base.messages.DeleteEntries;
 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -62,7 +62,7 @@ public class ReplicatedLogImplTest {
 
         context = new RaftActorContextImpl(null, null, "test",
                 new ElectionTermImpl(mockPersistence, "test", LOG),
-                -1, -1, Collections.<String,String>emptyMap(), configParams, LOG)  {
+                -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG)  {
             @Override
             public SnapshotManager getSnapshotManager() {
                 return mockSnapshotManager;

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.