/**
* Decrements the value of the follower's next index.
*
- * @return the new value of nextIndex,
+ * @return true if the next index was decremented, ie it was previously >= 0, false otherwise.
*/
- long decrNextIndex();
+ boolean decrNextIndex();
/**
* Sets the index of the follower's next log entry.
// The follower's log conflicts with leader's log so decrement follower's next index by 1
// in an attempt to find where the logs match.
- followerLogInformation.decrNextIndex();
- updated = true;
+ if (followerLogInformation.decrNextIndex()) {
+ updated = true;
- log.info("{}: follower {} last log term {} conflicts with the leader's {} - dec next index to {}",
- logName(), followerId, appendEntriesReply.getLogLastTerm(), followersLastLogTermInLeadersLog,
- followerLogInformation.getNextIndex());
+ log.info("{}: follower {} last log term {} conflicts with the leader's {} - dec next index to {}",
+ logName(), followerId, appendEntriesReply.getLogLastTerm(),
+ followersLastLogTermInLeadersLog, followerLogInformation.getNextIndex());
+ }
}
}
*/
package org.opendaylight.controller.cluster.raft;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
followerLogInformation.markFollowerActive();
assertTrue(followerLogInformation.isFollowerActive());
}
+
+ @Test
+ public void testDecrNextIndex() {
+ MockRaftActorContext context = new MockRaftActorContext();
+ context.setCommitIndex(1);
+ FollowerLogInformation followerLogInformation =
+ new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 1, context);
+
+ assertTrue(followerLogInformation.decrNextIndex());
+ assertEquals("getNextIndex", 0, followerLogInformation.getNextIndex());
+
+ assertTrue(followerLogInformation.decrNextIndex());
+ assertEquals("getNextIndex", -1, followerLogInformation.getNextIndex());
+
+ assertFalse(followerLogInformation.decrNextIndex());
+ assertEquals("getNextIndex", -1, followerLogInformation.getNextIndex());
+ }
}