- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("FollowerLogInformationImpl [id=").append(id).append(", nextIndex=").append(nextIndex)
- .append(", matchIndex=").append(matchIndex).append(", stopwatch=")
- .append(stopwatch.elapsed(TimeUnit.MILLISECONDS))
- .append(", followerTimeoutMillis=")
- .append(context.getConfigParams().getElectionTimeOutInterval().toMillis()).append("]");
- return builder.toString();
+ public boolean okToReplicate() {
+ if (peerInfo.getVotingState() == VotingState.VOTING_NOT_INITIALIZED) {
+ return false;
+ }
+
+ // Return false if we are trying to send duplicate data before the heartbeat interval
+ if (getNextIndex() == lastReplicatedIndex && lastReplicatedStopwatch.elapsed(TimeUnit.MILLISECONDS)
+ < context.getConfigParams().getHeartBeatInterval().toMillis()) {
+ return false;
+ }
+
+ resetLastReplicated();
+ return true;
+ }
+
+ private void resetLastReplicated() {
+ lastReplicatedIndex = getNextIndex();
+ if (lastReplicatedStopwatch.isRunning()) {
+ lastReplicatedStopwatch.reset();
+ }
+ lastReplicatedStopwatch.start();
+ }
+
+ @Override
+ public short getPayloadVersion() {
+ return payloadVersion;
+ }
+
+ @Override
+ public void setPayloadVersion(short payloadVersion) {
+ this.payloadVersion = payloadVersion;
+ }
+
+ @Override
+ public short getRaftVersion() {
+ return raftVersion;
+ }
+
+ @Override
+ public void setRaftVersion(short raftVersion) {
+ this.raftVersion = raftVersion;
+ }
+
+ @Override
+ @Nullable
+ public LeaderInstallSnapshotState getInstallSnapshotState() {
+ return installSnapshotState;