This is purely-internal DTO, make it a record.
Change-Id: I4570d9a78362f4dff7d4aceb4b469652396d3643
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
private void onApplySnapshot(final ApplySnapshot message) {
- log.info("{}: Applying snapshot on follower: {}", context.getId(), message.getSnapshot());
+ log.info("{}: Applying snapshot on follower: {}", context.getId(), message.snapshot());
context.getSnapshotManager().apply(message);
}
log.debug("lastSequenceNumber prior to persisting applied snapshot: {}", lastSequenceNumber);
- context.getPersistenceProvider().saveSnapshot(toApply.getSnapshot());
+ context.getPersistenceProvider().saveSnapshot(toApply.snapshot());
currentState = PERSISTING;
}
if (applySnapshot != null) {
try {
- Snapshot snapshot = applySnapshot.getSnapshot();
+ Snapshot snapshot = applySnapshot.snapshot();
//clears the followers log, sets the snapshot index to ensure adjusted-index works
context.setReplicatedLog(ReplicatedLogImpl.newInstance(snapshot, context));
snapshotCohort.applySnapshot(snapshot.getState());
}
- applySnapshot.getCallback().onSuccess();
+ applySnapshot.callback().onSuccess();
} catch (Exception e) {
log.error("{}: Error applying snapshot", context.getId(), e);
}
context.getReplicatedLog().getSnapshotTerm(),
context.getReplicatedLog().size());
} else {
- applySnapshot.getCallback().onFailure();
+ applySnapshot.callback().onFailure();
}
snapshotComplete();
import static java.util.Objects.requireNonNull;
import org.apache.pekko.dispatch.ControlMessage;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
/**
* Internal message, issued by follower to its actor.
*/
-public class ApplySnapshot implements ControlMessage {
+@NonNullByDefault
+public record ApplySnapshot(Snapshot snapshot, Callback callback) implements ControlMessage {
+
+ public interface Callback {
+
+ void onSuccess();
+
+ void onFailure();
+ }
+
private static final Callback NOOP_CALLBACK = new Callback() {
@Override
public void onSuccess() {
}
};
- private final Snapshot snapshot;
- private final Callback callback;
-
- public ApplySnapshot(@NonNull Snapshot snapshot) {
- this(snapshot, NOOP_CALLBACK);
+ public ApplySnapshot {
+ requireNonNull(snapshot);
+ requireNonNull(callback);
}
- public ApplySnapshot(@NonNull Snapshot snapshot, @NonNull Callback callback) {
- this.snapshot = requireNonNull(snapshot);
- this.callback = requireNonNull(callback);
- }
-
- public @NonNull Snapshot getSnapshot() {
- return snapshot;
- }
-
- public @NonNull Callback getCallback() {
- return callback;
- }
-
- public interface Callback {
- void onSuccess();
-
- void onFailure();
+ public ApplySnapshot(final Snapshot snapshot) {
+ this(snapshot, NOOP_CALLBACK);
}
}
// Leader should install snapshot - capture and verify ApplySnapshot contents
ApplySnapshot applySnapshot = expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class);
- List<Object> snapshotState = MockRaftActor.fromState(applySnapshot.getSnapshot().getState());
+ List<Object> snapshotState = MockRaftActor.fromState(applySnapshot.snapshot().getState());
assertEquals("Snapshot state", snapshotState, leaderRaftActor.getState());
AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class);
// Leader should install snapshot - capture and verify ApplySnapshot contents
ApplySnapshot applySnapshot = expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class);
- List<Object> snapshotState = MockRaftActor.fromState(applySnapshot.getSnapshot().getState());
+ List<Object> snapshotState = MockRaftActor.fromState(applySnapshot.snapshot().getState());
assertEquals("Snapshot state", snapshotState, leaderRaftActor.getState());
AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class);
// Verify follower 2 applies the snapshot.
ApplySnapshot applySnapshot = MessageCollectorActor.expectFirstMatching(follower2CollectorActor,
ApplySnapshot.class);
- verifySnapshot("Follower 2", applySnapshot.getSnapshot(), currentTerm, lastAppliedIndex, currentTerm,
+ verifySnapshot("Follower 2", applySnapshot.snapshot(), currentTerm, lastAppliedIndex, currentTerm,
lastAppliedIndex);
assertEquals("Persisted Snapshot getUnAppliedEntries size", 0,
- applySnapshot.getSnapshot().getUnAppliedEntries().size());
+ applySnapshot.snapshot().getUnAppliedEntries().size());
// Wait for the snapshot to complete.
MessageCollectorActor.expectFirstMatching(leaderCollectorActor, SaveSnapshotSuccess.class);
Set.copyOf(persistedSnapshot.getServerConfiguration().getServerConfig()));
assertEquals("Follower 2 snapshot server config", expServerInfo,
- Set.copyOf(applySnapshot.getSnapshot().getServerConfiguration().getServerConfig()));
+ Set.copyOf(applySnapshot.snapshot().getServerConfiguration().getServerConfig()));
ServerConfigurationPayload follower2ServerConfig = follower2Context.getPeerServerInfo(true);
assertNotNull("Follower 2 server config is null", follower2ServerConfig);
ApplySnapshot applySnapshot = MessageCollectorActor.expectFirstMatching(followerActor,
ApplySnapshot.class);
- Snapshot snapshot = applySnapshot.getSnapshot();
+ Snapshot snapshot = applySnapshot.snapshot();
assertNotNull(lastInstallSnapshot);
assertEquals("getLastIndex", lastInstallSnapshot.getLastIncludedIndex(), snapshot.getLastIndex());
assertEquals("getLastIncludedTerm", lastInstallSnapshot.getLastIncludedTerm(),
assertEquals("getState type", ByteState.class, snapshot.getState().getClass());
assertArrayEquals("getState", bsSnapshot.toByteArray(), ((ByteState)snapshot.getState()).getBytes());
assertEquals(new TermInfo(1, "leader"), snapshot.termInfo());
- applySnapshot.getCallback().onSuccess();
+ applySnapshot.callback().onSuccess();
List<InstallSnapshotReply> replies = MessageCollectorActor.getAllMatching(
leaderActor, InstallSnapshotReply.class);