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