BUG-5626: remove CompositeModification(ByteString)Payload 87/38987/5
authorRobert Varga <rovarga@cisco.com>
Tue, 17 May 2016 16:01:53 +0000 (18:01 +0200)
committerRobert Varga <rovarga@cisco.com>
Fri, 20 May 2016 08:41:47 +0000 (10:41 +0200)
These payloads have not been emitted since before Lithium and Lithium
codebase performs snapshot on recovery, hence we should not be seeing
these in any supported upgrade scenario. Remove them and related bits
of code.

Change-Id: Ib96fb2d4a516d1235485e2a12c2398c593bfaaba
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationByteStringPayload.java [deleted file]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationPayload.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinator.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/CompositeModificationByteStringPayloadTest.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java

diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationByteStringPayload.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationByteStringPayload.java
deleted file mode 100644 (file)
index 1dae675..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2014 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.raft.protobuff.client.messages;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.protobuf.ByteString;
-import com.google.protobuf.InvalidProtocolBufferException;
-import java.io.IOException;
-import java.io.Serializable;
-import java.lang.ref.SoftReference;
-import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Deprecated
-public class CompositeModificationByteStringPayload extends Payload implements
-        Serializable {
-    private static final long serialVersionUID = 1L;
-
-    private ByteString byteString;
-    private SoftReference<PersistentMessages.CompositeModification> modificationReference;
-    private static final Logger LOG = LoggerFactory.getLogger(CompositeModificationByteStringPayload.class);
-
-    public CompositeModificationByteStringPayload(){
-        byteString = null;
-    }
-    public CompositeModificationByteStringPayload(Object modification){
-        this(((PersistentMessages.CompositeModification) modification).toByteString());
-        this.modificationReference = new SoftReference<>((PersistentMessages.CompositeModification) modification);
-    }
-
-    private CompositeModificationByteStringPayload(ByteString byteString){
-        this.byteString = Preconditions.checkNotNull(byteString, "byteString should not be null");
-    }
-
-    public Object getModification(){
-        return getModificationInternal();
-    }
-
-    private PersistentMessages.CompositeModification getModificationInternal(){
-        if(this.modificationReference != null && this.modificationReference.get() != null){
-            return this.modificationReference.get();
-        }
-        try {
-            PersistentMessages.CompositeModification compositeModification = PersistentMessages.CompositeModification.parseFrom(this.byteString);
-            this.modificationReference = new SoftReference<>(compositeModification);
-            return compositeModification;
-        } catch (InvalidProtocolBufferException e) {
-            LOG.error("Unexpected exception occurred when parsing byteString to CompositeModification", e);
-        }
-
-        return null;
-    }
-
-    @Override
-    public int size(){
-        return byteString.size();
-    }
-
-    private void writeObject(java.io.ObjectOutputStream stream)
-            throws IOException {
-        byteString.writeTo(stream);
-    }
-
-    private void readObject(java.io.ObjectInputStream stream)
-            throws IOException, ClassNotFoundException {
-        byteString = ByteString.readFrom(stream);
-    }
-
-    @VisibleForTesting
-    public void clearModificationReference(){
-        if(this.modificationReference != null) {
-            this.modificationReference.clear();
-        }
-    }
-}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationPayload.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/CompositeModificationPayload.java
deleted file mode 100644 (file)
index bcb45d3..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2014 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.raft.protobuff.client.messages;
-
-import com.google.common.base.Preconditions;
-import java.io.Serializable;
-import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
-
-@Deprecated
-public class CompositeModificationPayload extends Payload implements
-    Serializable {
-
-    private final PersistentMessages.CompositeModification modification;
-
-    public CompositeModificationPayload(){
-        modification = null;
-    }
-    public CompositeModificationPayload(Object modification){
-        this.modification = (PersistentMessages.CompositeModification) Preconditions.checkNotNull(modification, "modification should not be null");
-    }
-
-    public Object getModification(){
-        return this.modification;
-    }
-
-    @Override
-    public int size(){
-        return this.modification.getSerializedSize();
-    }
-}
index 2251944..250e3f8 100644 (file)
@@ -64,8 +64,6 @@ import org.opendaylight.controller.cluster.raft.RaftState;
 import org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus;
 import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
 import org.opendaylight.controller.cluster.raft.messages.ServerRemoved;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload;
 import org.opendaylight.yangtools.concepts.Identifier;
 import org.opendaylight.yangtools.util.StringIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
@@ -683,18 +681,9 @@ public class Shard extends RaftActor {
                 // Replication consensus reached, proceed to commit
                 finishCommit(clientActor, identifier);
             }
-        } else if (data instanceof CompositeModificationPayload) {
-            Object modification = ((CompositeModificationPayload) data).getModification();
-
-            applyModificationToState(clientActor, identifier, modification);
-        } else if(data instanceof CompositeModificationByteStringPayload ){
-            Object modification = ((CompositeModificationByteStringPayload) data).getModification();
-
-            applyModificationToState(clientActor, identifier, modification);
         } else {
-            LOG.error("{}: Unknown state received {} Class loader = {} CompositeNodeMod.ClassLoader = {}",
-                    persistenceId(), data, data.getClass().getClassLoader(),
-                    CompositeModificationPayload.class.getClassLoader());
+            LOG.error("{}: Unknown state received {} ClassLoader {}", persistenceId(), data,
+                data.getClass().getClassLoader());
         }
     }
 
index 776ab27..dae3383 100644 (file)
@@ -9,12 +9,9 @@ package org.opendaylight.controller.cluster.datastore;
 
 import com.google.common.base.Preconditions;
 import java.io.IOException;
-import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
 import org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification;
 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
 import org.opendaylight.controller.cluster.raft.RaftActorRecoveryCohort;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -65,14 +62,6 @@ class ShardRecoveryCoordinator implements RaftActorRecoveryCohort {
             if (payload instanceof DataTreeCandidatePayload) {
                 DataTreeCandidates.applyToModification(transaction, ((DataTreeCandidatePayload)payload).getCandidate());
                 size++;
-            } else if (payload instanceof CompositeModificationPayload) {
-                MutableCompositeModification.fromSerializable(
-                    ((CompositeModificationPayload) payload).getModification()).apply(transaction);
-                size++;
-            } else if (payload instanceof CompositeModificationByteStringPayload) {
-                MutableCompositeModification.fromSerializable(
-                        ((CompositeModificationByteStringPayload) payload).getModification()).apply(transaction);
-                size++;
             } else {
                 log.error("{}: Unknown payload {} received during recovery", shardName, payload);
             }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/CompositeModificationByteStringPayloadTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/CompositeModificationByteStringPayloadTest.java
deleted file mode 100644 (file)
index e1e968c..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2014 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;
-
-import static junit.framework.Assert.assertTrue;
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
-import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-
-@Deprecated
-public class CompositeModificationByteStringPayloadTest {
-
-    @Test
-    public void testSerialization(){
-        WriteModification writeModification =
-                new WriteModification(TestModel.TEST_PATH, ImmutableNodes
-                        .containerNode(TestModel.TEST_QNAME));
-
-        MutableCompositeModification compositeModification =
-                new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
-
-        compositeModification.addModification(writeModification);
-
-        CompositeModificationByteStringPayload compositeModificationByteStringPayload
-                = new CompositeModificationByteStringPayload(compositeModification.toSerializable());
-
-        byte[] bytes = SerializationUtils.serialize(compositeModificationByteStringPayload);
-
-        Object deserialize = SerializationUtils.deserialize(bytes);
-
-        assertTrue(deserialize instanceof CompositeModificationByteStringPayload);
-
-    }
-}
index f4468b0..5cb7409 100644 (file)
@@ -11,14 +11,9 @@ package org.opendaylight.controller.cluster.datastore;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 import com.google.common.base.Optional;
-import java.io.IOException;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
-import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload;
 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
 import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel;
 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
@@ -62,36 +57,6 @@ public class ShardRecoveryCoordinatorTest {
         coordinator.applyCurrentLogRecoveryBatch();
     }
 
-    @Test
-    public void testAppendRecoveredLogEntryCompositeModificationPayload() throws IOException {
-        final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree,
-                peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo"));
-        coordinator.startLogRecoveryBatch(10);
-        try {
-            final MutableCompositeModification modification  = new MutableCompositeModification((short) 1);
-            modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create()));
-            coordinator.appendRecoveredLogEntry(new CompositeModificationPayload(modification.toSerializable()));
-        } catch(final SchemaValidationFailedException e){
-            fail("SchemaValidationFailedException should not happen if pruning is done");
-        }
-    }
-
-    @Test
-    public void testAppendRecoveredLogEntryCompositeModificationByteStringPayload() throws IOException {
-        final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree,
-                peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo"));
-        coordinator.startLogRecoveryBatch(10);
-        try {
-            final MutableCompositeModification modification  = new MutableCompositeModification((short) 1);
-            modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create()));
-            coordinator.appendRecoveredLogEntry(new CompositeModificationByteStringPayload(modification.toSerializable()));
-        } catch(final SchemaValidationFailedException e){
-            fail("SchemaValidationFailedException should not happen if pruning is done");
-        }
-
-        assertEquals(false, readCars(peopleDataTree).isPresent());
-    }
-
     @Test
     public void testApplyRecoverySnapshot(){
         final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree,
@@ -171,7 +136,5 @@ public class ShardRecoveryCoordinatorTest {
         final byte[] bytes = SerializationUtils.serializeNormalizedNode(optional.get());
 
         return bytes;
-
-
     }
 }
\ No newline at end of file
index 0631b1b..1830523 100644 (file)
@@ -12,30 +12,14 @@ import akka.actor.ActorRef;
 import akka.actor.PoisonPill;
 import akka.testkit.TestActorRef;
 import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
-import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
 import org.opendaylight.controller.cluster.datastore.Shard;
-import org.opendaylight.controller.cluster.datastore.ShardTestKit;
-import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
-import org.opendaylight.controller.cluster.datastore.modification.Modification;
-import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
-import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.ReplicatedLogImplEntry;
 import org.opendaylight.controller.cluster.raft.Snapshot;
-import org.opendaylight.controller.cluster.raft.base.messages.ApplyLogEntries;
-import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload;
-import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
-import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.util.StringIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
@@ -49,25 +33,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFac
  * @author Thomas Pantelis
  */
 public class PreLithiumShardTest extends AbstractShardTest {
-
-    private static CompositeModificationPayload newLegacyPayload(final Modification... mods) {
-        MutableCompositeModification compMod = new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
-        for(Modification mod: mods) {
-            compMod.addModification(mod);
-        }
-
-        return new CompositeModificationPayload(compMod.toSerializable());
-    }
-
-    private static CompositeModificationByteStringPayload newLegacyByteStringPayload(final Modification... mods) {
-        MutableCompositeModification compMod = new MutableCompositeModification(DataStoreVersions.HELIUM_2_VERSION);
-        for(Modification mod: mods) {
-            compMod.addModification(mod);
-        }
-
-        return new CompositeModificationByteStringPayload(compMod.toSerializable());
-    }
-
     @Test
     public void testApplyHelium2VersionSnapshot() throws Exception {
         TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
@@ -96,82 +61,4 @@ public class PreLithiumShardTest extends AbstractShardTest {
 
         shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
     }
-
-    @Test
-    public void testHelium2VersionApplyStateLegacy() throws Exception {
-        new ShardTestKit(getSystem()) {{
-            TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
-                    "testHelium2VersionApplyStateLegacy");
-
-            waitUntilLeader(shard);
-
-            NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-
-            ApplyState applyState = new ApplyState(null, new StringIdentifier("test"),
-                new ReplicatedLogImplEntry(1, 2,
-                    newLegacyByteStringPayload(new WriteModification(TestModel.TEST_PATH, node))));
-
-            shard.underlyingActor().onReceiveCommand(applyState);
-
-            NormalizedNode<?,?> actual = readStore(shard, TestModel.TEST_PATH);
-            assertEquals("Applied state", node, actual);
-
-            shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
-        }};
-    }
-
-    @Test
-    public void testHelium2VersionRecovery() throws Exception {
-
-        DataTree testStore = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        testStore.setSchemaContext(SCHEMA_CONTEXT);
-
-        writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
-        NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.builder().build());
-
-        InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(
-                new NormalizedNodeToNodeCodec(SCHEMA_CONTEXT).encode(root).
-                                getNormalizedNode().toByteString().toByteArray(),
-                                Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1));
-
-        InMemoryJournal.addEntry(shardID.toString(), 0, new String("Dummy data as snapshot sequence number is " +
-                "set to 0 in InMemorySnapshotStore and journal recovery seq number will start from 1"));
-
-        // Set up the InMemoryJournal.
-
-        InMemoryJournal.addEntry(shardID.toString(), 1, new ReplicatedLogImplEntry(0, 1, newLegacyPayload(
-                  new WriteModification(TestModel.OUTER_LIST_PATH,
-                          ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()))));
-
-        int nListEntries = 16;
-        Set<Integer> listEntryKeys = new HashSet<>();
-        int i = 1;
-
-        // Add some CompositeModificationPayload entries
-        for(; i <= 8; i++) {
-            listEntryKeys.add(Integer.valueOf(i));
-            YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
-                    .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i).build();
-            Modification mod = new MergeModification(path,
-                    ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i));
-            InMemoryJournal.addEntry(shardID.toString(), i+1, new ReplicatedLogImplEntry(i, 1,
-                    newLegacyPayload(mod)));
-        }
-
-        // Add some CompositeModificationByteStringPayload entries
-        for(; i <= nListEntries; i++) {
-            listEntryKeys.add(Integer.valueOf(i));
-            YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
-                    .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i).build();
-            Modification mod = new MergeModification(path,
-                    ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i));
-            InMemoryJournal.addEntry(shardID.toString(), i+1, new ReplicatedLogImplEntry(i, 1,
-                    newLegacyByteStringPayload(mod)));
-        }
-
-        InMemoryJournal.addEntry(shardID.toString(), nListEntries + 2, new ApplyLogEntries(nListEntries));
-
-        testRecovery(listEntryKeys);
-    }
 }