Remove deprecated PreBoronShardDataTreeSnapshot 99/57999/2
authorTom Pantelis <tompantelis@gmail.com>
Tue, 30 May 2017 00:27:33 +0000 (20:27 -0400)
committerRobert Varga <nite@hq.sk>
Tue, 30 May 2017 06:53:26 +0000 (06:53 +0000)
Since Carbon will migrate all pre-Carbon snapshots, we can remove
support for pre-Boron snaphot compatibility.

Change-Id: I74ee98f013e15c5abf24412671e4ac20bcdda66e
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PreBoronShardDataTreeSnapshot.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshot.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java

diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PreBoronShardDataTreeSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PreBoronShardDataTreeSnapshot.java
deleted file mode 100644 (file)
index 2454249..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.datastore.persisted;
-
-import com.google.common.annotations.Beta;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.util.Optional;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * Legacy data tree snapshot used in versions prior to Boron, which contains only the data.
- *
- * @author Robert Varga
- */
-@Beta
-public final class PreBoronShardDataTreeSnapshot extends ShardDataTreeSnapshot {
-    private final NormalizedNode<?, ?> rootNode;
-
-    @Deprecated
-    public PreBoronShardDataTreeSnapshot(final @Nullable NormalizedNode<?, ?> rootNode) {
-        this.rootNode = rootNode;
-    }
-
-    @Override
-    public Optional<NormalizedNode<?, ?>> getRootNode() {
-        return Optional.ofNullable(rootNode);
-    }
-
-    @Override
-    public void serialize(ObjectOutput out) throws IOException {
-        SerializationUtils.serializeNormalizedNode(rootNode, out);
-    }
-}
index 85d1143a891f743fdc652f1847f4b047c412e8aa..1dbab16c7ba118586040e196d43dc4cdeef636a8 100644 (file)
@@ -15,7 +15,6 @@ import java.io.InputStream;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Optional;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,39 +34,19 @@ public abstract class ShardDataTreeSnapshot {
 
     @Deprecated
     public static ShardDataTreeSnapshot deserializePreCarbon(final byte[] bytes) throws IOException {
-        /**
-         * Unfortunately versions prior to Boron did not include any way to evolve the snapshot format and contained
-         * only the raw data stored in the datastore. Furthermore utilities involved do not check if the array is
-         * completely consumed, which has a nasty side-effect when coupled with the fact that PayloadVersion writes
-         * a short value.
-         *
-         * Since our versions fit into a single byte, we end up writing the 0 as the first byte, which would be
-         * interpreted as 'not present' by the old snapshot format, which uses writeBoolean/readBoolean. A further
-         * complication is that readBoolean interprets any non-zero value as true, hence we cannot use a wild value
-         * to cause it to fail.
-         */
-        if (isLegacyStream(bytes)) {
-            return deserializeLegacy(bytes);
-        }
-
-        try {
-            try (InputStream is = new ByteArrayInputStream(bytes)) {
-                try (DataInputStream dis = new DataInputStream(is)) {
-                    final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserializePreCarbon(dis);
-
-                    // Make sure we consume all bytes, otherwise something went very wrong
-                    final int bytesLeft = dis.available();
-                    if (bytesLeft != 0) {
-                        throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
-                    }
+        try (InputStream is = new ByteArrayInputStream(bytes)) {
+            try (DataInputStream dis = new DataInputStream(is)) {
+                final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserializePreCarbon(dis);
+
+                // Make sure we consume all bytes, otherwise something went very wrong
+                final int bytesLeft = dis.available();
+                if (bytesLeft != 0) {
+                    throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
+                }
 
 
-                    return ret;
-                }
+                return ret;
             }
-        } catch (IOException e) {
-            LOG.debug("Failed to deserialize versioned stream, attempting pre-Lithium ProtoBuf", e);
-            return deserializeLegacy(bytes);
         }
     }
 
@@ -92,29 +71,5 @@ public abstract class ShardDataTreeSnapshot {
     public abstract Optional<NormalizedNode<?, ?>> getRootNode();
 
     public abstract void serialize(ObjectOutput out) throws IOException;
-
-    @Deprecated
-    private static boolean isLegacyStream(final byte[] bytes) {
-        if (bytes.length < 2) {
-            // Versioned streams have at least two bytes
-            return true;
-        }
-
-        /*
-         * The stream could potentially be a versioned stream. Here we rely on the signature marker available
-         * in org.opendaylight.controller.cluster.datastore.node.utils.stream.TokenTypes.
-         *
-         * For an old stream to be this long, the first byte has to be non-zero and the second byte has to be 0xAB.
-         *
-         * For a versioned stream, that translates to at least version 427 -- giving us at least 421 further versions
-         * before this check breaks.
-         */
-        return bytes[0] != 0 && bytes[1] == (byte)0xAB;
-    }
-
-    @Deprecated
-    private static ShardDataTreeSnapshot deserializeLegacy(final byte[] bytes) {
-        return new PreBoronShardDataTreeSnapshot(SerializationUtils.deserializeNormalizedNode(bytes));
-    }
 }
 
index 05d9943622301212c4c1f222a834ef7eb181a81b..1c8686c1b1daac3b34d546fc3fe40b1cbdfe2f72 100644 (file)
@@ -55,7 +55,7 @@ import org.opendaylight.controller.cluster.datastore.modification.MergeModificat
 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload;
-import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot;
+import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
 import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
 import org.opendaylight.controller.cluster.raft.TestActorFactory;
@@ -346,7 +346,7 @@ public abstract class AbstractShardTest extends AbstractActorTest {
         final NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.EMPTY);
 
         InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(
-                new ShardSnapshotState(new PreBoronShardDataTreeSnapshot(root)),
+                new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)),
                 Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1, 1, null, null));
         return testStore;
     }
index 1912c21db52c8a8db2f22c0250ec8fae2b9721dd..ddc0ea2c8eb58ef6000ba1858bc01b4286af61cb 100644 (file)
@@ -21,7 +21,6 @@ import java.io.ObjectOutputStream;
 import java.util.Map;
 import java.util.Optional;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -85,23 +84,6 @@ public class ShardDataTreeSnapshotTest {
         assertEquals("Metadata", expMetadata, ((MetadataShardDataTreeSnapshot)deserialized).getMetadata());
     }
 
-    @Test
-    @Deprecated
-    public void testPreBoronShardDataTreeSnapshot() throws Exception {
-        NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
-                .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
-
-        byte[] serialized = SerializationUtils.serializeNormalizedNode(expectedNode);
-
-        ShardDataTreeSnapshot deserialized = ShardDataTreeSnapshot.deserializePreCarbon(serialized);
-
-        Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
-        assertEquals("rootNode present", true, actualNode.isPresent());
-        assertEquals("rootNode", expectedNode, actualNode.get());
-        assertEquals("Deserialized type", PreBoronShardDataTreeSnapshot.class, deserialized.getClass());
-    }
-
     static class TestShardDataTreeSnapshotMetadata
             extends ShardDataTreeSnapshotMetadata<TestShardDataTreeSnapshotMetadata> {
         private static final long serialVersionUID = 1L;