use of org.opendaylight.controller.cluster.raft.ClientRequestTracker in project controller by opendaylight.
the class AbstractRaftActorBehavior method applyLogToStateMachine.
/**
* Applies the log entries up to the specified index that is known to be committed to the state machine.
*
* @param index the log index
*/
protected void applyLogToStateMachine(final long index) {
// Now maybe we apply to the state machine
for (long i = context.getLastApplied() + 1; i < index + 1; i++) {
ReplicatedLogEntry replicatedLogEntry = 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)
final ApplyState applyState;
final ClientRequestTracker tracker = removeClientRequestTracker(i);
if (tracker != null) {
applyState = new ApplyState(tracker.getClientActor(), tracker.getIdentifier(), replicatedLogEntry);
} else {
applyState = new ApplyState(null, null, replicatedLogEntry);
}
log.debug("{}: Setting last applied to {}", logName(), i);
context.setLastApplied(i);
context.getApplyStateConsumer().accept(applyState);
} else {
// if one index is not present in the log, no point in looping
// around as the rest wont be present either
log.warn("{}: Missing index {} from log. Cannot apply state. Ignoring {} to {}", logName(), i, i, index);
break;
}
}
// send a message to persist a ApplyLogEntries marker message into akka's persistent journal
// will be used during recovery
// in case if the above code throws an error and this message is not sent, it would be fine
// as the append entries received later would initiate add this message to the journal
actor().tell(new ApplyJournalEntries(context.getLastApplied()), actor());
}
Aggregations