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;
}
Aggregations