Search in sources :

Example 1 with LeaderPingerContext

use of com.palantir.paxos.LeaderPingerContext 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)

Example 2 with LeaderPingerContext

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

the class GetSuspectedLeaderWithUuidTests method functionForRemotes.

private GetSuspectedLeaderWithUuid functionForRemotes(ClientAwareLeaderPinger... remotes) {
    Set<ClientAwareLeaderPinger> clientAwareLeaders = ImmutableSet.copyOf(remotes);
    Set<LeaderPingerContext<BatchPingableLeader>> rpcClients = clientAwareLeaders.stream().map(ClientAwareLeaderPinger::underlyingRpcClient).collect(Collectors.toSet());
    Map<LeaderPingerContext<BatchPingableLeader>, CheckedRejectionExecutorService> executors = Maps.toMap(ImmutableList.copyOf(rpcClients), $ -> new CheckedRejectionExecutorService(executorService));
    return new GetSuspectedLeaderWithUuid(executors, clientAwareLeaders, LOCAL_UUID, Duration.ofSeconds(1));
}
Also used : LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) CheckedRejectionExecutorService(com.palantir.common.concurrent.CheckedRejectionExecutorService)

Example 3 with LeaderPingerContext

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

the class Leaders method createInstrumentedLocalServices.

public static LocalPaxosServices createInstrumentedLocalServices(MetricsManager metricsManager, LeaderConfig config, RemotePaxosServerSpec remotePaxosServerSpec, Supplier<RemotingClientConfig> remotingClientConfig, UserAgent userAgent, LeadershipObserver leadershipObserver) {
    UUID leaderUuid = UUID.randomUUID();
    PaxosLeadershipEventRecorder leadershipEventRecorder = PaxosLeadershipEventRecorder.create(metricsManager.getTaggedRegistry(), leaderUuid.toString(), leadershipObserver, ImmutableList.of());
    PaxosAcceptor ourAcceptor = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), PaxosAcceptor.class, PaxosAcceptorImpl.newAcceptor(config.acceptorLogDir().getPath()));
    PaxosLearner ourLearner = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), PaxosLearner.class, PaxosLearnerImpl.newLearner(config.learnerLogDir().getPath(), leadershipEventRecorder));
    Optional<TrustContext> trustContext = ServiceCreator.createTrustContext(config.sslConfiguration());
    List<PaxosLearner> learners = createProxyAndLocalList(ourLearner, remotePaxosServerSpec.remoteLearnerUris(), remotingClientConfig, trustContext, PaxosLearner.class, userAgent);
    List<PaxosLearner> remoteLearners = learners.stream().filter(learner -> !learner.equals(ourLearner)).collect(ImmutableList.toImmutableList());
    PaxosLearnerNetworkClient learnerNetworkClient = SingleLeaderLearnerNetworkClient.createLegacy(ourLearner, remoteLearners, config.quorumSize(), createExecutorsForService(metricsManager, learners, "knowledge-update"), PaxosConstants.CANCEL_REMAINING_CALLS);
    List<PaxosAcceptor> acceptors = createProxyAndLocalList(ourAcceptor, remotePaxosServerSpec.remoteAcceptorUris(), remotingClientConfig, trustContext, PaxosAcceptor.class, userAgent);
    PaxosAcceptorNetworkClient acceptorNetworkClient = SingleLeaderAcceptorNetworkClient.createLegacy(acceptors, config.quorumSize(), createExecutorsForService(metricsManager, acceptors, "latest-round-verifier"), PaxosConstants.CANCEL_REMAINING_CALLS);
    List<LeaderPingerContext<PingableLeader>> otherLeaders = generatePingables(remotePaxosServerSpec.remoteLeaderUris(), remotingClientConfig, trustContext, userAgent);
    LeaderPinger leaderPinger = SingleLeaderPinger.createLegacy(createExecutorsForService(metricsManager, otherLeaders, "leader-ping"), config.leaderPingResponseWait(), leaderUuid, PaxosConstants.CANCEL_REMAINING_CALLS);
    LeaderElectionService uninstrumentedLeaderElectionService = new LeaderElectionServiceBuilder().leaderUuid(leaderUuid).knowledge(ourLearner).eventRecorder(leadershipEventRecorder).randomWaitBeforeProposingLeadership(config.randomWaitBeforeProposingLeadership()).pingRate(config.pingRate()).leaderPinger(leaderPinger).acceptorClient(acceptorNetworkClient).learnerClient(learnerNetworkClient).decorateProposer(proposer -> AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), PaxosProposer.class, proposer)).leaderAddressCacheTtl(config.leaderAddressCacheTtl()).build();
    LeaderElectionService leaderElectionService = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), LeaderElectionService.class, uninstrumentedLeaderElectionService);
    PingableLeader pingableLeader = AtlasDbMetrics.instrumentTimed(metricsManager.getRegistry(), PingableLeader.class, new LocalPingableLeader(ourLearner, leaderUuid));
    List<PingableLeader> remotePingableLeaders = otherLeaders.stream().map(LeaderPingerContext::pinger).collect(Collectors.toList());
    BatchingLeaderElectionService batchingLeaderElectionService = new BatchingLeaderElectionService(leaderElectionService);
    return ImmutableLocalPaxosServices.builder().ourAcceptor(ourAcceptor).ourLearner(ourLearner).leaderElectionService(batchingLeaderElectionService).leadershipCoordinator(LeadershipCoordinator.create(batchingLeaderElectionService)).localPingableLeader(pingableLeader).remotePingableLeaders(remotePingableLeaders).build();
}
Also used : PaxosLearnerImpl(com.palantir.paxos.PaxosLearnerImpl) LeaderConfig(com.palantir.atlasdb.config.LeaderConfig) PaxosLearner(com.palantir.paxos.PaxosLearner) BatchingLeaderElectionService(com.palantir.leader.BatchingLeaderElectionService) TrustContext(com.palantir.conjure.java.config.ssl.TrustContext) MetricsManager(com.palantir.atlasdb.util.MetricsManager) PTExecutors(com.palantir.common.concurrent.PTExecutors) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Map(java.util.Map) NotCurrentLeaderExceptionMapper(com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper) PaxosAcceptor(com.palantir.paxos.PaxosAcceptor) PaxosLeadershipEventRecorder(com.palantir.leader.PaxosLeadershipEventRecorder) URI(java.net.URI) SingleLeaderLearnerNetworkClient(com.palantir.paxos.SingleLeaderLearnerNetworkClient) LeaderElectionService(com.palantir.leader.LeaderElectionService) LeaderElectionServiceBuilder(com.palantir.leader.LeaderElectionServiceBuilder) LeaderPinger(com.palantir.paxos.LeaderPinger) ImmutableSet(com.google.common.collect.ImmutableSet) SingleLeaderPinger(com.palantir.paxos.SingleLeaderPinger) KeyedStream(com.palantir.common.streams.KeyedStream) Collection(java.util.Collection) AtlasDbHttpClients(com.palantir.atlasdb.http.AtlasDbHttpClients) ImmutableLeaderPingerContext(com.palantir.paxos.ImmutableLeaderPingerContext) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Optional(java.util.Optional) RemotingClientConfigs(com.palantir.atlasdb.config.RemotingClientConfigs) LeadershipCoordinator(com.palantir.leader.proxy.LeadershipCoordinator) Iterables(com.google.common.collect.Iterables) AtlasDbMetrics(com.palantir.atlasdb.util.AtlasDbMetrics) LocalPingableLeader(com.palantir.leader.LocalPingableLeader) HashMap(java.util.HashMap) LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) PaxosLearnerNetworkClient(com.palantir.paxos.PaxosLearnerNetworkClient) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) AuxiliaryRemotingParameters(com.palantir.atlasdb.config.AuxiliaryRemotingParameters) ExecutorService(java.util.concurrent.ExecutorService) HostAndPort(com.google.common.net.HostAndPort) SingleLeaderAcceptorNetworkClient(com.palantir.paxos.SingleLeaderAcceptorNetworkClient) Consumer(java.util.function.Consumer) PaxosAcceptorImpl(com.palantir.paxos.PaxosAcceptorImpl) PaxosProposer(com.palantir.paxos.PaxosProposer) PaxosAcceptorNetworkClient(com.palantir.paxos.PaxosAcceptorNetworkClient) RemotingClientConfig(com.palantir.atlasdb.config.RemotingClientConfig) LeadershipObserver(com.palantir.leader.LeadershipObserver) PaxosConstants(com.palantir.paxos.PaxosConstants) PingableLeader(com.palantir.leader.PingableLeader) PaxosAcceptor(com.palantir.paxos.PaxosAcceptor) ImmutableLeaderPingerContext(com.palantir.paxos.ImmutableLeaderPingerContext) LeaderPingerContext(com.palantir.paxos.LeaderPingerContext) PaxosAcceptorNetworkClient(com.palantir.paxos.PaxosAcceptorNetworkClient) PaxosProposer(com.palantir.paxos.PaxosProposer) LeaderPinger(com.palantir.paxos.LeaderPinger) SingleLeaderPinger(com.palantir.paxos.SingleLeaderPinger) LocalPingableLeader(com.palantir.leader.LocalPingableLeader) PaxosLearner(com.palantir.paxos.PaxosLearner) PaxosLearnerNetworkClient(com.palantir.paxos.PaxosLearnerNetworkClient) LeaderElectionServiceBuilder(com.palantir.leader.LeaderElectionServiceBuilder) BatchingLeaderElectionService(com.palantir.leader.BatchingLeaderElectionService) LocalPingableLeader(com.palantir.leader.LocalPingableLeader) PingableLeader(com.palantir.leader.PingableLeader) BatchingLeaderElectionService(com.palantir.leader.BatchingLeaderElectionService) LeaderElectionService(com.palantir.leader.LeaderElectionService) PaxosLeadershipEventRecorder(com.palantir.leader.PaxosLeadershipEventRecorder) UUID(java.util.UUID) TrustContext(com.palantir.conjure.java.config.ssl.TrustContext)

Aggregations

LeaderPingerContext (com.palantir.paxos.LeaderPingerContext)3 ImmutableList (com.google.common.collect.ImmutableList)2 Sets (com.google.common.collect.Sets)2 CheckedRejectionExecutorService (com.palantir.common.concurrent.CheckedRejectionExecutorService)2 KeyedStream (com.palantir.common.streams.KeyedStream)2 PaxosConstants (com.palantir.paxos.PaxosConstants)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 HostAndPort (com.google.common.net.HostAndPort)1 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)1 DisruptorFuture (com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture)1 AuxiliaryRemotingParameters (com.palantir.atlasdb.config.AuxiliaryRemotingParameters)1 LeaderConfig (com.palantir.atlasdb.config.LeaderConfig)1 RemotingClientConfig (com.palantir.atlasdb.config.RemotingClientConfig)1 RemotingClientConfigs (com.palantir.atlasdb.config.RemotingClientConfigs)1 AtlasDbHttpClients (com.palantir.atlasdb.http.AtlasDbHttpClients)1