X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fpersisted%2FSnapshot.java;h=0acede1086ef20f3de26531cb7baf95a5f850507;hb=8f7f6ed83f1ab21aa9ba1fb2f4f9fbad3a9bfa56;hp=42a4a8de810bd5a2b4d04d872b2e00620ff9bd07;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/Snapshot.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/Snapshot.java index 42a4a8de81..0acede1086 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/Snapshot.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/Snapshot.java @@ -15,28 +15,51 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; -import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload; +import org.opendaylight.controller.cluster.raft.messages.Payload; /** * Represents a snapshot of the raft data. * * @author Thomas Pantelis */ -// Not final for mocking +// Not final and non-sealed for mocking public class Snapshot implements Serializable { - /** * Implementations of this interface are used as the state payload for a snapshot. * * @author Thomas Pantelis */ public interface State extends Serializable { + /** + * Indicate whether the snapshot requires migration, i.e. a new snapshot should be created after recovery. + * Default implementation returns false, i.e. do not re-snapshot. + * + * @return True if complete recovery based upon this snapshot should trigger a new snapshot. + */ + default boolean needsMigration() { + return false; + } } + @Deprecated(since = "7.0.0", forRemoval = true) + private static final class Legacy extends Snapshot implements LegacySerializable { + @java.io.Serial + private static final long serialVersionUID = 1L; + + Legacy(final State state, final List unAppliedEntries, final long lastIndex, + final long lastTerm, final long lastAppliedIndex, final long lastAppliedTerm, final long electionTerm, + final String electionVotedFor, final ServerConfigurationPayload serverConfig) { + super(state, unAppliedEntries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, electionTerm, + electionVotedFor, serverConfig); + } + } + + @Deprecated(since = "7.0.0", forRemoval = true) private static final class Proxy implements Externalizable { + @java.io.Serial private static final long serialVersionUID = 1L; - private Snapshot snapshot; + private Snapshot snapshot = null; // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection. @@ -45,10 +68,6 @@ public class Snapshot implements Serializable { // For Externalizable } - Proxy(final Snapshot snapshot) { - this.snapshot = snapshot; - } - @Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeLong(snapshot.lastIndex); @@ -80,7 +99,7 @@ public class Snapshot implements Serializable { ServerConfigurationPayload serverConfig = (ServerConfigurationPayload) in.readObject(); int size = in.readInt(); - List unAppliedEntries = new ArrayList<>(size); + var unAppliedEntries = new ArrayList(size); for (int i = 0; i < size; i++) { unAppliedEntries.add(new SimpleReplicatedLogEntry(in.readLong(), in.readLong(), (Payload) in.readObject())); @@ -88,15 +107,17 @@ public class Snapshot implements Serializable { State state = (State) in.readObject(); - snapshot = Snapshot.create(state, unAppliedEntries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, + snapshot = new Legacy(state, unAppliedEntries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm, electionTerm, electionVotedFor, serverConfig); } + @java.io.Serial private Object readResolve() { return snapshot; } } + @java.io.Serial private static final long serialVersionUID = 1L; private final State state; @@ -151,7 +172,7 @@ public class Snapshot implements Serializable { } public long getLastIndex() { - return this.lastIndex; + return lastIndex; } public long getElectionTerm() { @@ -166,12 +187,13 @@ public class Snapshot implements Serializable { return serverConfig; } - private Object writeReplace() { - return new Proxy(this); + @java.io.Serial + public final Object writeReplace() { + return new SS(this); } @Override - public String toString() { + public final String toString() { return "Snapshot [lastIndex=" + lastIndex + ", lastTerm=" + lastTerm + ", lastAppliedIndex=" + lastAppliedIndex + ", lastAppliedTerm=" + lastAppliedTerm + ", unAppliedEntries size=" + unAppliedEntries.size() + ", state=" + state + ", electionTerm=" + electionTerm + ", electionVotedFor="