import com.google.common.base.Stopwatch;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
shouldCaptureSnapshot.compareAndSet(false,
context.getReplicatedLog().shouldCaptureSnapshot(entry.getIndex()));
- if (entry.getData() instanceof ServerConfigurationPayload) {
- context.updatePeerIds((ServerConfigurationPayload)entry.getData());
+ if (entry.getData() instanceof ServerConfigurationPayload serverConfiguration) {
+ context.updatePeerIds(serverConfiguration);
}
}
return this;
}
- if (!(message instanceof RaftRPC)) {
+ if (!(message instanceof RaftRPC rpc)) {
// The rest of the processing requires the message to be a RaftRPC
return null;
}
- final RaftRPC rpc = (RaftRPC) message;
// If RPC request or response contains term T > currentTerm:
// set currentTerm = T, convert to follower (ยง5.1)
// This applies to all RPC messages and responses
context.getTermInformation().updateAndPersist(rpc.getTerm(), null);
}
- if (rpc instanceof InstallSnapshot) {
- handleInstallSnapshot(sender, (InstallSnapshot) rpc);
+ if (rpc instanceof InstallSnapshot installSnapshot) {
+ handleInstallSnapshot(sender, installSnapshot);
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
return this;
}
- if (!(rpc instanceof RequestVote) || canGrantVote((RequestVote) rpc)) {
+ if (!(rpc instanceof RequestVote requestVote) || canGrantVote(requestVote)) {
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
}
+ "all members {} self member: {}", logName(), unreachable, members, selfMember);
// no unreachable peers means we cannot be isolated
- if (unreachable.size() == 0) {
+ if (unreachable.isEmpty()) {
return false;
}
membersToCheck.removeAll(unreachable);
// check if the only member not unreachable is us
- if (membersToCheck.size() == 1 && membersToCheck.iterator().next().equals(selfMember)) {
- return true;
- }
-
- return false;
+ return membersToCheck.size() == 1 && membersToCheck.iterator().next().equals(selfMember);
}
private void handleInstallSnapshot(final ActorRef sender, final InstallSnapshot installSnapshot) {
Snapshot snapshot = Snapshot.create(
context.getSnapshotManager().convertSnapshot(snapshotTracker.getSnapshotBytes()),
- new ArrayList<>(),
+ List.of(),
installSnapshot.getLastIncludedIndex(),
installSnapshot.getLastIncludedTerm(),
installSnapshot.getLastIncludedIndex(),
} catch (IOException e) {
log.debug("{}: Exception in InstallSnapshot of follower", logName(), e);
- sender.tell(new InstallSnapshotReply(currentTerm(), context.getId(),
- -1, false), actor());
+ sender.tell(new InstallSnapshotReply(currentTerm(), context.getId(), -1, false), actor());
closeSnapshotTracker();
}