use of com.palantir.leader.LeaderElectionServiceBuilder in project atlasdb by palantir.
the class PaxosConsensusTestUtils method setup.
public static PaxosTestState setup(int numLeaders, int quorumSize) {
List<LeaderElectionService> leaders = new ArrayList<>();
List<PaxosAcceptor> acceptors = new ArrayList<>();
List<PaxosLearner> learners = new ArrayList<>();
List<AtomicBoolean> failureToggles = new ArrayList<>();
ExecutorService executor = PTExecutors.newCachedThreadPool();
DataSource sqliteDataSource = SqliteConnections.getDefaultConfiguredPooledDataSource(getSqlitePath());
RuntimeException exception = new SafeRuntimeException("mock server failure");
SplittingPaxosStateLog.LegacyOperationMarkers noop = ImmutableLegacyOperationMarkers.builder().markLegacyRead(() -> {
}).markLegacyWrite(() -> {
}).build();
for (int i = 0; i < numLeaders; i++) {
failureToggles.add(new AtomicBoolean(false));
PaxosLearner learner = PaxosLearnerImpl.newSplittingLearner(getLearnerStorageParameters(i, sqliteDataSource), noop, PaxosKnowledgeEventRecorder.NO_OP);
learners.add(ToggleableExceptionProxy.newProxyInstance(PaxosLearner.class, learner, failureToggles.get(i), exception));
PaxosAcceptor acceptor = PaxosAcceptorImpl.newSplittingAcceptor(getAcceptorStorageParameters(i, sqliteDataSource), noop, Optional.empty());
acceptors.add(ToggleableExceptionProxy.newProxyInstance(PaxosAcceptor.class, acceptor, failureToggles.get(i), exception));
}
PaxosAcceptorNetworkClient acceptorNetworkClient = SingleLeaderAcceptorNetworkClient.createLegacy(acceptors, quorumSize, Maps.toMap(acceptors, $ -> executor), PaxosConstants.CANCEL_REMAINING_CALLS);
for (int i = 0; i < numLeaders; i++) {
UUID leaderUuid = UUID.randomUUID();
PaxosLearner ourLearner = learners.get(i);
List<PaxosLearner> remoteLearners = learners.stream().filter(learner -> !learner.equals(ourLearner)).collect(ImmutableList.toImmutableList());
PaxosLearnerNetworkClient learnerNetworkClient = SingleLeaderLearnerNetworkClient.createLegacy(ourLearner, remoteLearners, quorumSize, Maps.toMap(learners, $ -> executor), PaxosConstants.CANCEL_REMAINING_CALLS);
LeaderElectionService leader = new LeaderElectionServiceBuilder().leaderUuid(leaderUuid).pingRate(Duration.ZERO).randomWaitBeforeProposingLeadership(Duration.ZERO).leaderAddressCacheTtl(Duration.ZERO).knowledge(ourLearner).acceptorClient(acceptorNetworkClient).learnerClient(learnerNetworkClient).leaderPinger(SingleLeaderPinger.createForTests(ImmutableMap.of(), Duration.ZERO, leaderUuid, true, Optional.empty())).build();
leaders.add(SimulatingFailingServerProxy.newProxyInstance(LeaderElectionService.class, leader, SERVER_DELAY_TIME_MS, failureToggles.get(i)));
}
return new PaxosTestState(leaders, learners, failureToggles, executor);
}
use of com.palantir.leader.LeaderElectionServiceBuilder 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