X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FPayloadVersion.java;h=921c9fca96cfc505f17a6b3be25564f3cad69163;hp=0f52dacc5b8bbbf3dfcc0d8eafb0aeb5ec7dade6;hb=422ac9fbe65c02f942c1fed41ff4aa96545f4224;hpb=925cb4a228d0fda99c7bfeb432eb25285a223887 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PayloadVersion.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PayloadVersion.java index 0f52dacc5b..921c9fca96 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PayloadVersion.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PayloadVersion.java @@ -7,21 +7,26 @@ */ package org.opendaylight.controller.cluster.datastore.persisted; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.annotations.Beta; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion; import org.opendaylight.yangtools.concepts.WritableObject; /** * Enumeration of all ABI versions supported by this implementation of persistence. An ABI version has to be bumped * whenever: - * - a new event is defined - * - serialization format is changed - *

+ *

+ * + *

* This version effectively defines the protocol version between actors participating on a particular shard. A shard * participant instance should oppose RAFT candidates which produce persistence of an unsupported version. If a follower * encounters an unsupported version it must not become fully-operational, as it does not have an accurate view @@ -31,30 +36,78 @@ import org.opendaylight.yangtools.concepts.WritableObject; */ @Beta public enum PayloadVersion implements WritableObject { - // NOTE: enumeration values need to be sorted in asceding order of their version to keep Comparable working + // NOTE: enumeration values need to be sorted in ascending order of their version to keep Comparable working /** * Version which is older than any other version. This version exists purely for testing purposes. */ @VisibleForTesting - TEST_PAST_VERSION(0), + TEST_PAST_VERSION(0) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + throw new UnsupportedOperationException(); + } + }, /** * Initial ABI version, as shipped with Boron Simultaneous release. */ - // We seed the initial version to be the same as DataStoreVersions.BORON-VERSION for compatibility reasons. - BORON(5), + // We seed the initial version to be the same as DataStoreVersions.BORON_VERSION for compatibility reasons. + BORON(5) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.LITHIUM; + } + }, + + /** + * Revised payload version. Payloads remain the same as {@link #BORON}, but messages bearing QNames in any shape + * are using {@link NormalizedNodeStreamVersion#NEON_SR2}, which improves encoding. + */ + NEON_SR2(6) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.NEON_SR2; + } + }, + + /** + * Revised payload version. Payloads remain the same as {@link #NEON_SR2}, but messages bearing QNames in any shape + * are using {@link NormalizedNodeStreamVersion#SODIUM_SR1}, which improves encoding. + */ + SODIUM_SR1(7) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.SODIUM_SR1; + } + }, + + /** + * Revised payload version. Payloads remain the same as {@link #SODIUM_SR1}, but messages bearing QNames in any + * shape are using {@link NormalizedNodeStreamVersion#MAGNESIUM}, which improves encoding. + */ + MAGNESIUM(8) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + return NormalizedNodeStreamVersion.MAGNESIUM; + } + }, /** * Version which is newer than any other version. This version exists purely for testing purposes. */ @VisibleForTesting - TEST_FUTURE_VERSION(65535); + TEST_FUTURE_VERSION(65535) { + @Override + public NormalizedNodeStreamVersion getStreamVersion() { + throw new UnsupportedOperationException(); + } + }; private final short value; PayloadVersion(final int intVersion) { - Preconditions.checkArgument(intVersion >= 0 && intVersion <= 65535); + checkArgument(intVersion >= 0 && intVersion <= 65535); value = (short) intVersion; } @@ -67,15 +120,21 @@ public enum PayloadVersion implements WritableObject { return value; } + /** + * Return the NormalizedNode stream version corresponding to this particular ABI. + * + * @return Stream Version to use for this ABI version + */ + public abstract @NonNull NormalizedNodeStreamVersion getStreamVersion(); + /** * Return the codebase-native persistence version. This version is the default version allocated to messages * at runtime. Conversion to previous versions may incur additional overhead (such as object allocation). * * @return Current {@link PayloadVersion} */ - @Nonnull - public static PayloadVersion current() { - return BORON; + public static @NonNull PayloadVersion current() { + return NEON_SR2; } /** @@ -87,8 +146,8 @@ public enum PayloadVersion implements WritableObject { * @throws FutureVersionException if the specified integer identifies a future version * @throws PastVersionException if the specified integer identifies a past version which is no longer supported */ - @Nonnull - public static PayloadVersion valueOf(final short version) throws FutureVersionException, PastVersionException { + public static @NonNull PayloadVersion valueOf(final short version) + throws FutureVersionException, PastVersionException { switch (Short.toUnsignedInt(version)) { case 0: case 1: @@ -98,8 +157,14 @@ public enum PayloadVersion implements WritableObject { throw new PastVersionException(version, BORON); case 5: return BORON; + case 6: + return NEON_SR2; + case 7: + return SODIUM_SR1; + case 8: + return MAGNESIUM; default: - throw new FutureVersionException(version, BORON); + throw new FutureVersionException(version, MAGNESIUM); } } @@ -116,8 +181,7 @@ public enum PayloadVersion implements WritableObject { * @return An {@link PayloadVersion} * @throws IOException If read fails or an unsupported version is encountered */ - @Nonnull - public static PayloadVersion readFrom(@Nonnull final DataInput in) throws IOException { + public static @NonNull PayloadVersion readFrom(final @NonNull DataInput in) throws IOException { final short s = in.readShort(); try { return valueOf(s); @@ -125,5 +189,4 @@ public enum PayloadVersion implements WritableObject { throw new IOException("Unsupported version", e); } } - }