Update DataPersistenceProvider 84/115884/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Mar 2025 09:03:39 +0000 (10:03 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Mar 2025 09:06:41 +0000 (10:06 +0100)
All arguments are required to be non-null, let's annotate that.
Furthermore we know we are always saving a Snapshot, not a plain Object.

JIRA: CONTROLLER-2134
Change-Id: I9411cc6bdcea19ae4d6113485aed925f1bca3674
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/NonPersistentDataProvider.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/PersistentDataProvider.java
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/RaftActorDataPersistenceProvider.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/spi/DataPersistenceProvider.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java

index d70ad92e366795f9b8aa93146928e1f1699a4646..58260cbb218c7d755ed7fdb9bcc60f8c4b98c59b 100644 (file)
@@ -14,6 +14,7 @@ import org.apache.pekko.persistence.JournalProtocol;
 import org.apache.pekko.persistence.SnapshotProtocol;
 import org.apache.pekko.persistence.SnapshotSelectionCriteria;
 import org.opendaylight.controller.cluster.common.actor.ExecuteInSelfActor;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.spi.DataPersistenceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,7 +47,7 @@ class NonPersistentDataProvider implements DataPersistenceProvider {
     }
 
     @Override
-    public void saveSnapshot(final Object snapshot) {
+    public void saveSnapshot(final Snapshot snapshot) {
         // no-op
     }
 
index a6fbd38ddfe5ecfcbb54fc328f36bc68a29f5803..ed1316cc171d7dcccf1a61e86da7cc26d1533bc6 100644 (file)
@@ -16,6 +16,7 @@ import org.apache.pekko.persistence.DeleteSnapshotsSuccess;
 import org.apache.pekko.persistence.JournalProtocol;
 import org.apache.pekko.persistence.SnapshotProtocol;
 import org.apache.pekko.persistence.SnapshotSelectionCriteria;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.spi.DataPersistenceProvider;
 
 /**
@@ -45,7 +46,7 @@ class PersistentDataProvider implements DataPersistenceProvider {
     }
 
     @Override
-    public void saveSnapshot(final Object snapshot) {
+    public void saveSnapshot(final Snapshot snapshot) {
         persistentActor.saveSnapshot(snapshot);
     }
 
index b0d691f69652d4d795535f8972b9db57a501cd6c..0d141a2eed1a20bb0fa67a33f527770bb71aef81 100644 (file)
@@ -54,6 +54,7 @@ import org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries;
 import org.opendaylight.controller.cluster.raft.persisted.ClusterConfig;
 import org.opendaylight.controller.cluster.raft.persisted.NoopPayload;
 import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.spi.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.raft.spi.TermInfo;
 import org.opendaylight.yangtools.concepts.Identifier;
@@ -794,7 +795,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
                  * </ol>
                  */
                 @Override
-                public void saveSnapshot(final Object object) {
+                public void saveSnapshot(final Snapshot object) {
                     // Make saving Snapshot successful
                     // Committing the snapshot here would end up calling commit in the creating state which would
                     // be a state violation. That's why now we send a message to commit the snapshot.
index 995868634ef32774f0fc2963e547d6738b72df84..7d81c1cfaa9f63153e4ace7edc8636ab18282a4d 100644 (file)
@@ -14,6 +14,7 @@ import org.apache.pekko.persistence.JournalProtocol;
 import org.apache.pekko.persistence.SnapshotProtocol;
 import org.apache.pekko.persistence.SnapshotSelectionCriteria;
 import org.opendaylight.controller.cluster.raft.persisted.ClusterConfig;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.spi.DataPersistenceProvider;
 
 /**
@@ -79,7 +80,7 @@ final class RaftActorDataPersistenceProvider implements DataPersistenceProvider
     }
 
     @Override
-    public void saveSnapshot(final Object entry) {
+    public void saveSnapshot(final Snapshot entry) {
         delegate.saveSnapshot(entry);
     }
 
index f1abc6c08784b8361ed0fea6359e12139809fa32..df84e06d2192d4eed2763d59e65e51038d38ad23 100644 (file)
@@ -5,42 +5,43 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.raft.spi;
 
 import org.apache.pekko.japi.Procedure;
 import org.apache.pekko.persistence.JournalProtocol;
 import org.apache.pekko.persistence.SnapshotProtocol;
 import org.apache.pekko.persistence.SnapshotSelectionCriteria;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 
 /**
  * This interface provides methods to persist data and is an abstraction of the akka-persistence persistence API.
  */
+@NonNullByDefault
 public interface DataPersistenceProvider {
     /**
      * Returns whether or not persistence recovery is applicable/enabled.
      *
-     * @return true if recovery is applicable, otherwise false, in which case the provider is not persistent and may
-     *         not have anything to be recovered
+     * @return {@code true} if recovery is applicable, otherwise false, in which case the provider is not persistent and
+     *         may not have anything to be recovered
      */
     boolean isRecoveryApplicable();
 
     /**
      * Persists an entry to the applicable journal synchronously.
      *
+     * @param <T> the type of the journal entry
      * @param entry the journal entry to persist
      * @param procedure the callback when persistence is complete
-     * @param <T> the type of the journal entry
      */
     <T> void persist(T entry, Procedure<T> procedure);
 
     /**
      * Persists an entry to the applicable journal asynchronously.
      *
+     * @param <T> the type of the journal entry
      * @param entry the journal entry to persist
      * @param procedure the callback when persistence is complete
-     * @param <T> the type of the journal entry
      */
     <T> void persistAsync(T entry, Procedure<T> procedure);
 
@@ -49,7 +50,7 @@ public interface DataPersistenceProvider {
      *
      * @param snapshot the snapshot object to save
      */
-    void saveSnapshot(Object snapshot);
+    void saveSnapshot(Snapshot snapshot);
 
     /**
      * Deletes snapshots based on the given criteria.
@@ -78,7 +79,7 @@ public interface DataPersistenceProvider {
      * @param response A {@link JournalProtocol} response
      * @return {@code true} if the response was handled
      */
-    boolean handleJournalResponse(JournalProtocol.@NonNull Response response);
+    boolean handleJournalResponse(JournalProtocol.Response response);
 
     /**
      * Receive and potentially handle a {@link SnapshotProtocol} response.
@@ -86,5 +87,5 @@ public interface DataPersistenceProvider {
      * @param response A {@link SnapshotProtocol} response
      * @return {@code true} if the response was handled
      */
-    boolean handleSnapshotResponse(SnapshotProtocol.@NonNull Response response);
+    boolean handleSnapshotResponse(SnapshotProtocol.Response response);
 }
index 37e72ce430cbe0933c4dc6ca99d4ad96b04a1ebb..4a9180c26d8a34f24ed535e3fba81991388e9bca 100644 (file)
@@ -1493,7 +1493,7 @@ public class ShardTest extends AbstractShardTest {
             }
 
             @Override
-            public void saveSnapshot(final Object entry) {
+            public void saveSnapshot(final Snapshot entry) {
                 savedSnapshot.set(entry);
                 delegate.saveSnapshot(entry);
             }
@@ -1522,7 +1522,6 @@ public class ShardTest extends AbstractShardTest {
             public boolean handleSnapshotResponse(final SnapshotProtocol.Response response) {
                 return delegate.handleSnapshotResponse(response);
             }
-
         }
 
         dataStoreContextBuilder.persistent(persistent);