Fix Javadoc
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / ShardRecoveryCoordinator.java
index 5e0d3407fb99baa3d6ff39a598f0de2ecc70b975..a916ea6dead760219d536e0061ac01c35c99a879 100644 (file)
@@ -10,9 +10,13 @@ package org.opendaylight.controller.cluster.datastore;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import java.io.File;
+import java.io.IOException;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
+import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
 import org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeXMLOutput;
 import org.opendaylight.controller.cluster.raft.RaftActorRecoveryCohort;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
+import org.opendaylight.controller.cluster.raft.persisted.Snapshot.State;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -30,11 +34,11 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
     private final ShardDataTree store;
     private final String shardName;
     private final Logger log;
-    private final byte[] restoreFromSnapshot;
+    private final Snapshot restoreFromSnapshot;
 
     private boolean open;
 
-    ShardRecoveryCoordinator(final ShardDataTree store,  final byte[] restoreFromSnapshot, final String shardName,
+    ShardRecoveryCoordinator(final ShardDataTree store,  final Snapshot restoreFromSnapshot, final String shardName,
             final Logger log) {
         this.store = Preconditions.checkNotNull(store);
         this.shardName = Preconditions.checkNotNull(shardName);
@@ -82,33 +86,41 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
     /**
      * Applies a recovered snapshot to the data store.
      *
-     * @param snapshotBytes the serialized snapshot
+     * @param snapshotState the serialized snapshot
      */
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public void applyRecoverySnapshot(final byte[] snapshotBytes) {
-        log.debug("{}: Applying recovered snapshot", shardName);
-
-        final ShardDataTreeSnapshot snapshot;
-        try {
-            snapshot = ShardDataTreeSnapshot.deserialize(snapshotBytes);
-        } catch (Exception e) {
-            log.error("{}: failed to deserialize snapshot", shardName, e);
-            throw Throwables.propagate(e);
+    public void applyRecoverySnapshot(final Snapshot.State snapshotState) {
+        if (!(snapshotState instanceof ShardSnapshotState)) {
+            log.debug("{}: applyRecoverySnapshot ignoring snapshot: {}", snapshotState);
         }
 
+        log.debug("{}: Applying recovered snapshot", shardName);
+
+        ShardDataTreeSnapshot shardSnapshot = ((ShardSnapshotState)snapshotState).getSnapshot();
         try {
-            store.applyRecoverySnapshot(snapshot);
+            store.applyRecoverySnapshot(shardSnapshot);
         } catch (Exception e) {
-            final File f = writeRoot("snapshot", snapshot.getRootNode().orElse(null));
+            final File f = writeRoot("snapshot", shardSnapshot.getRootNode().orElse(null));
             throw new IllegalStateException(String.format(
                     "%s: Failed to apply recovery snapshot %s. Node data was written to file %s",
-                    shardName, snapshot, f), e);
+                    shardName, shardSnapshot, f), e);
         }
     }
 
     @Override
-    public byte[] getRestoreFromSnapshot() {
+    public Snapshot getRestoreFromSnapshot() {
         return restoreFromSnapshot;
     }
+
+    @Override
+    @Deprecated
+    public State deserializePreCarbonSnapshot(final byte[] from) {
+        try {
+            return new ShardSnapshotState(ShardDataTreeSnapshot.deserializePreCarbon(from));
+        } catch (IOException e) {
+            log.error("{}: failed to deserialize snapshot", shardName, e);
+            throw Throwables.propagate(e);
+        }
+    }
 }