Search in sources :

Example 1 with PeerInfo

use of org.opendaylight.controller.cluster.raft.PeerInfo in project controller by opendaylight.

the class AbstractLeader method possiblyUpdateCommitIndex.

private void possiblyUpdateCommitIndex() {
    // set commitIndex = N (§5.3, §5.4).
    for (long index = context.getCommitIndex() + 1; ; index++) {
        ReplicatedLogEntry replicatedLogEntry = context.getReplicatedLog().get(index);
        if (replicatedLogEntry == null) {
            log.trace("{}: ReplicatedLogEntry not found for index {} - snapshotIndex: {}, journal size: {}", logName(), index, context.getReplicatedLog().getSnapshotIndex(), context.getReplicatedLog().size());
            break;
        }
        // Count our entry if it has been persisted.
        int replicatedCount = replicatedLogEntry.isPersistencePending() ? 0 : 1;
        if (replicatedCount == 0) {
            // amongst the followers w/o the local persistence ack.
            break;
        }
        log.trace("{}: checking Nth index {}", logName(), index);
        for (FollowerLogInformation info : followerToLog.values()) {
            final PeerInfo peerInfo = context.getPeerInfo(info.getId());
            if (info.getMatchIndex() >= index && peerInfo != null && peerInfo.isVoting()) {
                replicatedCount++;
            } else if (log.isTraceEnabled()) {
                log.trace("{}: Not counting follower {} - matchIndex: {}, {}", logName(), info.getId(), info.getMatchIndex(), peerInfo);
            }
        }
        if (log.isTraceEnabled()) {
            log.trace("{}: replicatedCount {}, minReplicationCount: {}", logName(), replicatedCount, minReplicationCount);
        }
        if (replicatedCount >= minReplicationCount) {
            // counting replicas, then all prior entries are committed indirectly".
            if (replicatedLogEntry.getTerm() == currentTerm()) {
                log.trace("{}: Setting commit index to {}", logName(), index);
                context.setCommitIndex(index);
            } else {
                log.debug("{}: Not updating commit index to {} - retrieved log entry with index {}, " + "term {} does not match the current term {}", logName(), index, replicatedLogEntry.getIndex(), replicatedLogEntry.getTerm(), currentTerm());
            }
        } else {
            log.trace("{}: minReplicationCount not reached, actual {} - breaking", logName(), replicatedCount);
            break;
        }
    }
    // Apply the change to the state machine
    if (context.getCommitIndex() > context.getLastApplied()) {
        log.debug("{}: Applying to log - commitIndex: {}, lastAppliedIndex: {}", logName(), context.getCommitIndex(), context.getLastApplied());
        applyLogToStateMachine(context.getCommitIndex());
    }
    if (!context.getSnapshotManager().isCapturing()) {
        purgeInMemoryLog();
    }
}
Also used : ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) FollowerLogInformation(org.opendaylight.controller.cluster.raft.FollowerLogInformation) PeerInfo(org.opendaylight.controller.cluster.raft.PeerInfo)

Example 2 with PeerInfo

use of org.opendaylight.controller.cluster.raft.PeerInfo in project controller by opendaylight.

the class AbstractLeader method updateMinReplicaCount.

public void updateMinReplicaCount() {
    int numVoting = 0;
    for (PeerInfo peer : context.getPeers()) {
        if (peer.isVoting()) {
            numVoting++;
        }
    }
    minReplicationCount = getMajorityVoteCount(numVoting);
}
Also used : PeerInfo(org.opendaylight.controller.cluster.raft.PeerInfo)

Aggregations

PeerInfo (org.opendaylight.controller.cluster.raft.PeerInfo)2 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)1 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)1