Address review comments 75/43775/2
authorTom Pantelis <tpanteli@brocade.com>
Fri, 12 Aug 2016 06:00:36 +0000 (02:00 -0400)
committerRobert Varga <rovarga@cisco.com>
Fri, 12 Aug 2016 12:08:05 +0000 (14:08 +0200)
For https://git.opendaylight.org/gerrit/#/c/42974/.

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

index 164e7a9..6a04674 100644 (file)
@@ -53,7 +53,7 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
     }
 
     @Override
     }
 
     @Override
-    FrontendShardDataTreeSnapshotMetadata toStapshot() {
+    FrontendShardDataTreeSnapshotMetadata toSnapshot() {
         return new FrontendShardDataTreeSnapshotMetadata(Collections2.transform(clients.values(),
             FrontendClientMetadataBuilder::build));
     }
         return new FrontendShardDataTreeSnapshotMetadata(Collections2.transform(clients.values(),
             FrontendClientMetadataBuilder::build));
     }
index d43602a..72ca1ae 100644 (file)
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import com.google.common.primitives.UnsignedLong;
+import java.io.File;
 import java.io.IOException;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayDeque;
 import java.io.IOException;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayDeque;
@@ -42,6 +43,7 @@ import org.opendaylight.controller.cluster.datastore.persisted.CommitTransaction
 import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata;
 import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata;
+import org.opendaylight.controller.cluster.datastore.utils.DataTreeModificationOutput;
 import org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
@@ -160,7 +162,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
                 ImmutableMap.builder();
 
         for (ShardDataTreeMetadata<?> m : metadata) {
                 ImmutableMap.builder();
 
         for (ShardDataTreeMetadata<?> m : metadata) {
-            final ShardDataTreeSnapshotMetadata<?> meta = m.toStapshot();
+            final ShardDataTreeSnapshotMetadata<?> meta = m.toSnapshot();
             if (meta != null) {
                 metaBuilder.put(meta.getType(), meta);
             }
             if (meta != null) {
                 metaBuilder.put(meta.getType(), meta);
             }
@@ -252,8 +254,17 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         final DataTreeModification unwrapped = mod.delegate();
         LOG.trace("{}: Applying recovery modification {}", logContext, unwrapped);
 
         final DataTreeModification unwrapped = mod.delegate();
         LOG.trace("{}: Applying recovery modification {}", logContext, unwrapped);
 
-        dataTree.validate(unwrapped);
-        dataTree.commit(dataTree.prepare(unwrapped));
+        try {
+            dataTree.validate(unwrapped);
+            dataTree.commit(dataTree.prepare(unwrapped));
+        } catch (Exception e) {
+            File file = new File(System.getProperty("karaf.data", "."),
+                    "failed-recovery-payload-" + logContext + ".out");
+            DataTreeModificationOutput.toFile(file, unwrapped);
+            throw new IllegalStateException(String.format(
+                    "%s: Failed to apply recovery payload. Modification data was written to file %s",
+                    logContext, file), e);
+        }
     }
 
     /**
     }
 
     /**
index 1fce144..d10a44d 100644 (file)
@@ -27,7 +27,7 @@ abstract class ShardDataTreeMetadata<T extends ShardDataTreeSnapshotMetadata<T>>
 
     abstract @Nonnull Class<T> getSupportedType();
 
 
     abstract @Nonnull Class<T> getSupportedType();
 
-    abstract @Nullable T toStapshot();
+    abstract @Nullable T toSnapshot();
 
     // Lifecycle events
     abstract void onTransactionCommitted(TransactionIdentifier txId);
 
     // Lifecycle events
     abstract void onTransactionCommitted(TransactionIdentifier txId);
index 70a7010..5b7f289 100644 (file)
@@ -72,7 +72,7 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
 
     private File writeRoot(final String kind, final NormalizedNode<?, ?> node) {
         final File file = new File(System.getProperty("karaf.data", "."),
 
     private File writeRoot(final String kind, final NormalizedNode<?, ?> node) {
         final File file = new File(System.getProperty("karaf.data", "."),
-            "failed-" + kind + "-snapshot-" + shardName + ".xml");
+            "failed-recovery-" + kind + "-" + shardName + ".xml");
         NormalizedNodeXMLOutput.toFile(file, node);
         return file;
     }
         NormalizedNodeXMLOutput.toFile(file, node);
         return file;
     }
@@ -97,11 +97,10 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
         try {
             store.applyRecoverySnapshot(snapshot);
         } catch (Exception e) {
         try {
             store.applyRecoverySnapshot(snapshot);
         } catch (Exception e) {
-            log.error("{}: failed to apply snapshot {}", shardName, snapshot, e);
-
-            final File f = writeRoot("recovery", snapshot.getRootNode().orElse(null));
+            final File f = writeRoot("snapshot", snapshot.getRootNode().orElse(null));
             throw new IllegalStateException(String.format(
             throw new IllegalStateException(String.format(
-                    "%s: Failed to apply recovery snapshot. Node data was written to file %s", shardName, f), e);
+                    "%s: Failed to apply recovery snapshot %s. Node data was written to file %s",
+                    shardName, snapshot, f), e);
         }
     }
 
         }
     }
 

©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.