use of com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer in project atlasdb by palantir.
the class GetSuspectedLeaderWithUuid method accept.
@Override
public void accept(List<BatchElement<UUID, Optional<ClientAwareLeaderPinger>>> batchElements) {
Multimap<UUID, DisruptorFuture<Optional<ClientAwareLeaderPinger>>> uuidsToRequests = batchElements.stream().collect(ImmutableListMultimap.toImmutableListMultimap(BatchElement::argument, BatchElement::result));
KeyedStream.of(uuidsToRequests.keySet()).filterKeys(cache::containsKey).map(cache::get).forEach((cachedUuid, pingable) -> completeRequest(uuidsToRequests.get(cachedUuid), Optional.of(clientAwareLeaders.get(pingable))));
Set<UUID> uncachedUuids = uuidsToRequests.keySet().stream().filter(uuid -> !cache.containsKey(uuid)).collect(toSet());
if (uncachedUuids.isEmpty()) {
return;
}
PaxosResponsesWithRemote<LeaderPingerContext<BatchPingableLeader>, PaxosContainer<UUID>> results = PaxosQuorumChecker.collectUntil(ImmutableList.copyOf(executors.keySet()), pingable -> PaxosContainer.of(pingable.pinger().uuid()), executors, leaderPingResponseWait, state -> state.responses().values().stream().map(PaxosContainer::get).collect(toSet()).containsAll(uncachedUuids), PaxosConstants.CANCEL_REMAINING_CALLS);
for (Map.Entry<LeaderPingerContext<BatchPingableLeader>, PaxosContainer<UUID>> resultEntries : results.responses().entrySet()) {
LeaderPingerContext<BatchPingableLeader> pingable = resultEntries.getKey();
UUID uuid = resultEntries.getValue().get();
LeaderPingerContext<BatchPingableLeader> oldCachedEntry = cache.putIfAbsent(uuid, pingable);
throwIfInvalidSetup(oldCachedEntry, pingable, uuid);
completeRequest(uuidsToRequests.get(uuid), Optional.of(clientAwareLeaders.get(pingable)));
}
Set<UUID> missingUuids = Sets.difference(uncachedUuids, results.withoutRemotes().stream().map(PaxosContainer::get).collect(toSet()));
missingUuids.forEach(missingUuid -> completeRequest(uuidsToRequests.get(missingUuid), Optional.empty()));
}
use of com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer in project atlasdb by palantir.
the class LearnedValuesCoalescingFunctionTests method canProcessBatch.
@Test
public void canProcessBatch() {
Set<WithSeq<Client>> remoteRequest = ImmutableSet.of(WithSeq.of(CLIENT_1, 10), WithSeq.of(CLIENT_1, 12), WithSeq.of(CLIENT_1, 15), WithSeq.of(CLIENT_2, 10), WithSeq.of(CLIENT_2, 15));
PaxosValue paxosValue1 = paxosValue(10);
PaxosValue paxosValue2 = paxosValue(12);
SetMultimap<Client, PaxosValue> remoteResponse = ImmutableSetMultimap.<Client, PaxosValue>builder().putAll(CLIENT_1, paxosValue1, paxosValue2).put(CLIENT_2, paxosValue1).build();
when(remote.getLearnedValues(remoteRequest)).thenReturn(remoteResponse);
LearnedValuesCoalescingFunction function = new LearnedValuesCoalescingFunction(remote);
Map<WithSeq<Client>, PaxosContainer<Optional<PaxosValue>>> results = function.apply(remoteRequest);
assertThat(results).containsOnly(entry(WithSeq.of(CLIENT_2, 10), asResult(paxosValue1)), entry(WithSeq.of(CLIENT_1, 12), asResult(paxosValue2)), entry(WithSeq.of(CLIENT_1, 10), asResult(paxosValue1)), entry(WithSeq.of(CLIENT_1, 15), EMPTY_RESULT), entry(WithSeq.of(CLIENT_2, 15), EMPTY_RESULT));
}
use of com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer in project atlasdb by palantir.
the class TestableTimelockCluster method currentLeaders.
SetMultimap<String, TestableTimelockServer> currentLeaders(Iterable<String> namespaces) {
Set<String> namespacesIterable = ImmutableSet.copyOf(namespaces);
KeyedStream<TestableTimelockServer, PaxosContainer<Set<String>>> responses = PaxosQuorumChecker.collectUntil(ImmutableList.copyOf(servers), server -> PaxosContainer.of(server.pinger().ping(namespaces)), Maps.toMap(servers, unused -> new CheckedRejectionExecutorService(executorService)), Duration.ofSeconds(2), untilAllNamespacesAreSeen(namespacesIterable), true).stream();
return responses.filter(PaxosContainer::isSuccessful).map(PaxosContainer::get).flatMap(Collection::stream).mapEntries((server, namespace) -> Maps.immutableEntry(namespace, server)).collectToSetMultimap();
}
Aggregations