Search in sources :

Example 1 with PaxosUpdate

use of com.palantir.paxos.PaxosUpdate in project atlasdb by palantir.

the class PaxosLeaderElectionService method updateLearnedStateFromPeers.

/**
 * Queries all other learners for unknown learned values
 *
 * @returns true if new state was learned, otherwise false
 */
public boolean updateLearnedStateFromPeers(Optional<PaxosValue> greatestLearned) {
    final long nextToLearnSeq = greatestLearned.map(value -> value.getRound()).orElse(PaxosAcceptor.NO_LOG_ENTRY) + 1;
    List<PaxosUpdate> updates = PaxosQuorumChecker.<PaxosLearner, PaxosUpdate>collectQuorumResponses(learners, new Function<PaxosLearner, PaxosUpdate>() {

        @Override
        @Nullable
        public PaxosUpdate apply(@Nullable PaxosLearner learner) {
            return new PaxosUpdate(copyOf(learner.getLearnedValuesSince(nextToLearnSeq)));
        }
    }, proposer.getQuorumSize(), executor, PaxosQuorumChecker.DEFAULT_REMOTE_REQUESTS_TIMEOUT_IN_SECONDS);
    // learn the state accumulated from peers
    boolean learned = false;
    for (PaxosUpdate update : updates) {
        ImmutableCollection<PaxosValue> values = update.getValues();
        for (PaxosValue value : values) {
            PaxosValue currentLearnedValue = knowledge.getLearnedValue(value.getRound());
            if (currentLearnedValue == null) {
                knowledge.learn(value.getRound(), value);
                learned = true;
            }
        }
    }
    return learned;
}
Also used : PaxosUpdate(com.palantir.paxos.PaxosUpdate) PaxosLearner(com.palantir.paxos.PaxosLearner) Nullable(javax.annotation.Nullable) PaxosValue(com.palantir.paxos.PaxosValue)

Aggregations

PaxosLearner (com.palantir.paxos.PaxosLearner)1 PaxosUpdate (com.palantir.paxos.PaxosUpdate)1 PaxosValue (com.palantir.paxos.PaxosValue)1 Nullable (javax.annotation.Nullable)1