public static final short BORON_VERSION = 3;
public static final short FLUORINE_VERSION = 4;
public static final short ARGON_VERSION = 5;
- public static final short CURRENT_VERSION = FLUORINE_VERSION;
+ public static final short CURRENT_VERSION = ARGON_VERSION;
private RaftVersions() {
*
* @author Thomas Pantelis
*/
+@Deprecated(since = "7.0.0", forRemoval = true)
public abstract class EmptyExternalizableProxy implements Externalizable {
private static final long serialVersionUID = 1L;
return INSTANCE;
}
- @java.io.Serial
- private Object writeReplace() {
- return new Proxy();
- }
-
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy extends EmptyExternalizableProxy {
@java.io.Serial
private static final long serialVersionUID = 1L;
* @author Thomas Pantelis
*/
class FollowerIdentifier extends AbstractStringIdentifier<FollowerIdentifier> {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- FollowerIdentifier(String followerId) {
+ FollowerIdentifier(final String followerId) {
super(followerId);
}
+ @java.io.Serial
private Object writeReplace() {
- return new Proxy(this);
+ return new FI(getValue());
}
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private FollowerIdentifier identifier;
public Proxy() {
}
- Proxy(FollowerIdentifier identifier) {
+ Proxy(final FollowerIdentifier identifier) {
this.identifier = identifier;
}
@Override
- public void writeExternal(ObjectOutput out) throws IOException {
+ public void writeExternal(final ObjectOutput out) throws IOException {
out.writeObject(identifier.getValue());
}
@Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
identifier = new FollowerIdentifier((String) in.readObject());
}
+ @java.io.Serial
private Object readResolve() {
return identifier;
}
return INSTANCE;
}
- @java.io.Serial
- private Object writeReplace() {
- return new Proxy();
- }
-
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy extends EmptyExternalizableProxy {
@java.io.Serial
private static final long serialVersionUID = 1L;
@Override
Object writeReplace() {
- return new Proxy(this);
+ return new IR(this);
}
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private InstallSnapshotReply installSnapshotReply;
installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, success);
}
+ @java.io.Serial
private Object readResolve() {
return installSnapshotReply;
}
@Override
Object writeReplace() {
- return new Proxy(this);
+ return new RV(this);
}
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private RequestVote requestVote;
requestVote = new RequestVote(term, candidateId, lastLogIndex, lastLogTerm);
}
+ @java.io.Serial
private Object readResolve() {
return requestVote;
}
@Override
Object writeReplace() {
- return new Proxy(this);
+ return new VR(this);
}
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private RequestVoteReply requestVoteReply;
requestVoteReply = new RequestVoteReply(term, voteGranted);
}
+ @java.io.Serial
private Object readResolve() {
return requestVoteReply;
}
* @author Thomas Pantelis
*/
public class ApplyJournalEntries implements Serializable, ControlMessage {
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static final class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private ApplyJournalEntries applyEntries;
applyEntries = new ApplyJournalEntries(in.readLong());
}
+ @java.io.Serial
private Object readResolve() {
return applyEntries;
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private final long toIndex;
}
private Object writeReplace() {
- return new Proxy(this);
+ return new AJE(this);
}
@Override
* @author Thomas Pantelis
*/
public class DeleteEntries implements Serializable {
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static final class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private DeleteEntries deleteEntries;
deleteEntries = new DeleteEntries(in.readLong());
}
+ @java.io.Serial
private Object readResolve() {
return deleteEntries;
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private final long fromIndex;
}
private Object writeReplace() {
- return new Proxy(this);
+ return new DE(this);
}
@Override
// For Externalizable
}
+ // For size estimation only, use full bit size
+ LE(final Void dummy) {
+ index = Long.MIN_VALUE;
+ term = Long.MIN_VALUE;
+ data = null;
+ }
+
LE(final SimpleReplicatedLogEntry logEntry) {
index = logEntry.getIndex();
term = logEntry.getTerm();
public static final NoopPayload INSTANCE = new NoopPayload();
// There is no need for Externalizable
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static final class Proxy implements Serializable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
+ @java.io.Serial
private Object readResolve() {
return INSTANCE;
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- private static final Proxy PROXY = new Proxy();
+ private static final NP PROXY = new NP();
// Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative
private static final int PROXY_SIZE = SerializationUtils.serialize(PROXY).length;
* @author Thomas Pantelis
*/
public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static final class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private long index;
data = (Payload) in.readObject();
}
+ @java.io.Serial
private Object readResolve() {
return new SimpleReplicatedLogEntry(index, term, data);
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- // Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative
- private static final int PROXY_SIZE = SerializationUtils.serialize(new Proxy()).length;
+ // Estimate to how big the proxy is. Note this includes object stream overhead, so it is a bit conservative.
+ private static final int PROXY_SIZE = SerializationUtils.serialize(new LE((Void) null)).length;
private final long index;
private final long term;
}
private Object writeReplace() {
- return new Proxy(this);
+ return new LE(this);
}
@Override
if (this == obj) {
return true;
}
-
if (obj == null || getClass() != obj.getClass()) {
return false;
}
- SimpleReplicatedLogEntry other = (SimpleReplicatedLogEntry) obj;
+ var other = (SimpleReplicatedLogEntry) obj;
return index == other.index && term == other.term && payload.equals(other.payload);
}
}
}
+ @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;
electionTerm, electionVotedFor, serverConfig);
}
+ @java.io.Serial
private Object readResolve() {
return snapshot;
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private final State state;
}
public long getLastIndex() {
- return this.lastIndex;
+ return lastIndex;
}
public long getElectionTerm() {
return serverConfig;
}
+ @java.io.Serial
private Object writeReplace() {
- return new Proxy(this);
+ return new SS(this);
}
@Override
* Message class to persist election term information.
*/
public class UpdateElectionTerm implements Serializable {
+ @Deprecated(since = "7.0.0", forRemoval = true)
private static final class Proxy implements Externalizable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private UpdateElectionTerm updateElectionTerm;
updateElectionTerm = new UpdateElectionTerm(in.readLong(), (String) in.readObject());
}
+ @java.io.Serial
private Object readResolve() {
return updateElectionTerm;
}
}
+ @java.io.Serial
private static final long serialVersionUID = 1L;
private final long currentTerm;
return votedFor;
}
+ @java.io.Serial
private Object writeReplace() {
- return new Proxy(this);
+ return new UT(this);
}
@Override
@Test
public void test() {
final var bytes = SerializationUtils.serialize(TimeoutNow.INSTANCE);
- assertEquals(187, bytes.length);
+ assertEquals(86, bytes.length);
final var cloned = SerializationUtils.deserialize(bytes);
assertSame("Cloned instance", TimeoutNow.INSTANCE, cloned);
}
public void testSerialization() {
final var expected = new FollowerIdentifier("follower1");
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(109, bytes.length);
+ assertEquals(87, bytes.length);
final var cloned = (FollowerIdentifier) SerializationUtils.deserialize(bytes);
assertEquals("cloned", expected, cloned);
}
@Test
public void test() {
final var bytes = SerializationUtils.serialize(Shutdown.INSTANCE);
- assertEquals(187, bytes.length);
+ assertEquals(86, bytes.length);
final var cloned = SerializationUtils.deserialize(bytes);
assertSame("Cloned instance", Shutdown.INSTANCE, cloned);
}
RaftVersions.CURRENT_VERSION);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(143, bytes.length);
+ assertEquals(98, bytes.length);
final var cloned = (AppendEntriesReply) SerializationUtils.deserialize(bytes);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
RaftVersions.CURRENT_VERSION, null);
var bytes = SerializationUtils.serialize(expected);
- assertEquals(355, bytes.length);
+ assertEquals(285, bytes.length);
var cloned = (AppendEntries) SerializationUtils.deserialize(bytes);
verifyAppendEntries(expected, cloned, RaftVersions.CURRENT_VERSION);
RaftVersions.CURRENT_VERSION, "leader address");
bytes = SerializationUtils.serialize(expected);
- assertEquals(371, bytes.length);
+ assertEquals(301, bytes.length);
cloned = (AppendEntries) SerializationUtils.deserialize(bytes);
verifyAppendEntries(expected, cloned, RaftVersions.CURRENT_VERSION);
public void testSerialization() {
final var expected = new InstallSnapshotReply(5L, "follower", 1, true);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(126, bytes.length);
+ assertEquals(95, bytes.length);
final var cloned = (InstallSnapshotReply) SerializationUtils.deserialize(bytes);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
*/
public class InstallSnapshotTest {
@Test
- public void testSerialization() {
+ public void testCurrentSerialization() {
+ testSerialization(RaftVersions.CURRENT_VERSION, 1262, 1125);
+ }
+
+ @Test
+ public void testFluorineSerialization() {
+ testSerialization(RaftVersions.FLUORINE_VERSION, 1302, 1165);
+ }
+
+ private static void testSerialization(final short raftVersion, final int fullSize, final int emptySize) {
byte[] data = new byte[1000];
for (int i = 0, j = 0; i < data.length; i++) {
data[i] = (byte)j;
}
}
- ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(List.of(
+ var serverConfig = new ServerConfigurationPayload(List.of(
new ServerInfo("leader", true), new ServerInfo("follower", false)));
- assertInstallSnapshot(1302, new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, OptionalInt.of(54321),
- Optional.of(serverConfig), RaftVersions.CURRENT_VERSION));
+ assertInstallSnapshot(fullSize, new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, OptionalInt.of(54321),
+ Optional.of(serverConfig), raftVersion));
- assertInstallSnapshot(1165, new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, OptionalInt.empty(),
- Optional.empty(), RaftVersions.CURRENT_VERSION));
+ assertInstallSnapshot(emptySize, new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, OptionalInt.empty(),
+ Optional.empty(), raftVersion));
}
private static void assertInstallSnapshot(final int expectedSize, final InstallSnapshot expected) {
public void testSerialization() {
final var expected = new RequestVoteReply(5, true);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(105, bytes.length);
+ assertEquals(78, bytes.length);
final var cloned = (RequestVoteReply) SerializationUtils.deserialize(bytes);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
public void testSerialization() {
final var expected = new RequestVote(4, "candidateId", 3, 2);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(131, bytes.length);
+ assertEquals(97, bytes.length);
final var cloned = (RequestVote) SerializationUtils.deserialize(bytes);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
public void testSerialization() {
final var expected = new ApplyJournalEntries(5);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(108, bytes.length);
+ assertEquals(80, bytes.length);
final var cloned = (ApplyJournalEntries) SerializationUtils.deserialize(bytes);
assertEquals("getFromIndex", expected.getToIndex(), cloned.getToIndex());
public void testSerialization() {
final var expected = new DeleteEntries(5);
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(102, bytes.length);
+ assertEquals(79, bytes.length);
final var cloned = (DeleteEntries) SerializationUtils.deserialize(bytes);
assertEquals("getFromIndex", expected.getFromIndex(), cloned.getFromIndex());
@Test
public void testSerialization() {
final var bytes = SerializationUtils.serialize(NoopPayload.INSTANCE);
- assertEquals(89, bytes.length);
+ assertEquals(74, bytes.length);
assertSame(NoopPayload.INSTANCE, SerializationUtils.deserialize(bytes));
}
}
public void testSerialization() {
final var expected = new SimpleReplicatedLogEntry(0, 1, new MockRaftActorContext.MockPayload("A"));
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(260, bytes.length);
+ assertEquals(218, bytes.length);
final var cloned = (SimpleReplicatedLogEntry) SerializationUtils.deserialize(bytes);
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
@Test
public void testSerialization() {
testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7}, List.of(
- new SimpleReplicatedLogEntry(6, 2, new MockPayload("payload"))), 548);
- testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, List.of(), 389);
+ new SimpleReplicatedLogEntry(6, 2, new MockPayload("payload"))), 491);
+ testSerialization(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, List.of(), 345);
}
private static void testSerialization(final byte[] state, final List<ReplicatedLogEntry> unapplied,
public void testSerialization() {
final var expected = new UpdateElectionTerm(5, "leader");
final var bytes = SerializationUtils.serialize(expected);
- assertEquals(116, bytes.length);
+ assertEquals(88, bytes.length);
final var cloned = (UpdateElectionTerm) SerializationUtils.deserialize(bytes);
assertEquals("getCurrentTerm", expected.getCurrentTerm(), cloned.getCurrentTerm());