protected RaftState requestVote(ActorRef sender,
RequestVote requestVote) {
+
+ context.getLogger().debug(requestVote.toString());
+
boolean grantVote = false;
// Reply false if term < currentTerm (ยง5.1)
*
* @param index a log index that is known to be committed
*/
- protected void applyLogToStateMachine(long index) {
+ protected void applyLogToStateMachine(final long index) {
+ long newLastApplied = context.getLastApplied();
// Now maybe we apply to the state machine
for (long i = context.getLastApplied() + 1;
i < index + 1; i++) {
context.getReplicatedLog().get(i);
if (replicatedLogEntry != null) {
+ // Send a local message to the local RaftActor (it's derived class to be
+ // specific to apply the log to it's index)
actor().tell(new ApplyState(clientActor, identifier,
replicatedLogEntry), actor());
+ newLastApplied = i;
} else {
- context.getLogger().error(
- "Missing index " + i + " from log. Cannot apply state.");
+ //if one index is not present in the log, no point in looping
+ // around as the rest wont be present either
+ context.getLogger().warning(
+ "Missing index {} from log. Cannot apply state. Ignoring {} to {}", i, i, index );
+ break;
}
}
- // Send a local message to the local RaftActor (it's derived class to be
- // specific to apply the log to it's index)
- context.setLastApplied(index);
+ context.getLogger().debug("Setting last applied to {}", newLastApplied);
+ context.setLastApplied(newLastApplied);
}
protected Object fromSerializableMessage(Object serializable){