Search in sources :

Example 1 with PaxosResponsesWithRemote

use of com.palantir.paxos.PaxosResponsesWithRemote 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()));
}
Also used : DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) Throwables(com.palantir.common.base.Throwables) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) PaxosContainer(com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) SafeLogger(com.palantir.logsafe.logger.SafeLogger) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Map(java.util.Map) PaxosQuorumChecker(com.palantir.paxos.PaxosQuorumChecker) Collectors.toSet(java.util.stream.Collectors.toSet) BiMap(com.google.common.collect.BiMap) KeyedStream(com.palantir.common.streams.KeyedStream) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Sets(com.google.common.collect.Sets) Consumer(java.util.function.Consumer) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) PaxosResponsesWithRemote(com.palantir.paxos.PaxosResponsesWithRemote) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Optional(java.util.Optional) PaxosConstants(com.palantir.paxos.PaxosConstants) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) PaxosContainer(com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap) DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture)

Aggregations

BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)1 DisruptorFuture (com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture)1 PaxosContainer (com.palantir.atlasdb.timelock.paxos.PaxosQuorumCheckingCoalescingFunction.PaxosContainer)1 Throwables (com.palantir.common.base.Throwables)1 CheckedRejectionExecutorService (com.palantir.common.concurrent.CheckedRejectionExecutorService)1 KeyedStream (com.palantir.common.streams.KeyedStream)1 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)1 SafeLogger (com.palantir.logsafe.logger.SafeLogger)1 SafeLoggerFactory (com.palantir.logsafe.logger.SafeLoggerFactory)1 LeaderPingerContext (com.palantir.paxos.LeaderPingerContext)1 PaxosConstants (com.palantir.paxos.PaxosConstants)1 PaxosQuorumChecker (com.palantir.paxos.PaxosQuorumChecker)1 PaxosResponsesWithRemote (com.palantir.paxos.PaxosResponsesWithRemote)1 Duration (java.time.Duration)1