use of com.palantir.leader.PaxosLeaderElectionServiceBuilder in project atlasdb by palantir.
the class PaxosConsensusTestUtils method setup.
public static PaxosTestState setup(int numLeaders, int quorumSize) {
List<LeaderElectionService> leaders = Lists.newArrayList();
List<PaxosAcceptor> acceptors = Lists.newArrayList();
List<PaxosLearner> learners = Lists.newArrayList();
List<AtomicBoolean> failureToggles = Lists.newArrayList();
ExecutorService executor = PTExecutors.newCachedThreadPool();
RuntimeException e = new RuntimeException("mock server failure");
for (int i = 0; i < numLeaders; i++) {
failureToggles.add(new AtomicBoolean(false));
PaxosLearner learner = PaxosLearnerImpl.newLearner(getLearnerLogDir(i));
learners.add(ToggleableExceptionProxy.newProxyInstance(PaxosLearner.class, learner, failureToggles.get(i), e));
PaxosAcceptor acceptor = PaxosAcceptorImpl.newAcceptor(getAcceptorLogDir(i));
acceptors.add(ToggleableExceptionProxy.newProxyInstance(PaxosAcceptor.class, acceptor, failureToggles.get(i), e));
}
for (int i = 0; i < numLeaders; i++) {
PaxosProposer proposer = PaxosProposerImpl.newProposer(learners.get(i), ImmutableList.<PaxosAcceptor>copyOf(acceptors), ImmutableList.<PaxosLearner>copyOf(learners), quorumSize, UUID.randomUUID(), executor);
PaxosLeaderElectionService leader = new PaxosLeaderElectionServiceBuilder().proposer(proposer).knowledge(learners.get(i)).potentialLeadersToHosts(ImmutableMap.<PingableLeader, HostAndPort>of()).acceptors(acceptors).learners(learners).executor(executor).pingRateMs(0L).randomWaitBeforeProposingLeadershipMs(0L).leaderPingResponseWaitMs(0L).onlyLogOnQuorumFailure(() -> true).build();
leaders.add(SimulatingFailingServerProxy.newProxyInstance(LeaderElectionService.class, leader, SERVER_DELAY_TIME_MS, failureToggles.get(i)));
}
return new PaxosTestState(leaders, acceptors, learners, failureToggles, executor);
}
use of com.palantir.leader.PaxosLeaderElectionServiceBuilder in project atlasdb by palantir.
the class Leaders method createInstrumentedLocalServices.
public static LocalPaxosServices createInstrumentedLocalServices(LeaderConfig config, Supplier<LeaderRuntimeConfig> runtime, RemotePaxosServerSpec remotePaxosServerSpec, String userAgent) {
UUID leaderUuid = UUID.randomUUID();
PaxosLeadershipEventRecorder leadershipEventRecorder = PaxosLeadershipEventRecorder.create(AtlasDbMetrics.getMetricRegistry(), leaderUuid.toString());
PaxosAcceptor ourAcceptor = AtlasDbMetrics.instrument(PaxosAcceptor.class, PaxosAcceptorImpl.newAcceptor(config.acceptorLogDir().getPath()));
PaxosLearner ourLearner = AtlasDbMetrics.instrument(PaxosLearner.class, PaxosLearnerImpl.newLearner(config.learnerLogDir().getPath(), leadershipEventRecorder));
Optional<SSLSocketFactory> sslSocketFactory = ServiceCreator.createSslSocketFactory(config.sslConfiguration());
List<PaxosLearner> learners = createProxyAndLocalList(ourLearner, remotePaxosServerSpec.remoteLearnerUris(), sslSocketFactory, PaxosLearner.class, userAgent);
List<PaxosAcceptor> acceptors = createProxyAndLocalList(ourAcceptor, remotePaxosServerSpec.remoteAcceptorUris(), sslSocketFactory, PaxosAcceptor.class, userAgent);
Map<PingableLeader, HostAndPort> otherLeaders = generatePingables(remotePaxosServerSpec.remoteLeaderUris(), sslSocketFactory, userAgent);
InstrumentedExecutorService proposerExecutorService = new InstrumentedExecutorService(PTExecutors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("atlas-proposer-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), MetricRegistry.name(PaxosProposer.class, "executor"));
PaxosProposer proposer = AtlasDbMetrics.instrument(PaxosProposer.class, PaxosProposerImpl.newProposer(ourLearner, acceptors, learners, config.quorumSize(), leaderUuid, proposerExecutorService));
InstrumentedExecutorService leaderElectionExecutor = new InstrumentedExecutorService(PTExecutors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("atlas-leaders-election-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), MetricRegistry.name(PaxosLeaderElectionService.class, "executor"));
PaxosLeaderElectionService paxosLeaderElectionService = new PaxosLeaderElectionServiceBuilder().proposer(proposer).knowledge(ourLearner).potentialLeadersToHosts(otherLeaders).acceptors(acceptors).learners(learners).executor(leaderElectionExecutor).pingRateMs(config.pingRateMs()).randomWaitBeforeProposingLeadershipMs(config.randomWaitBeforeProposingLeadershipMs()).leaderPingResponseWaitMs(config.leaderPingResponseWaitMs()).eventRecorder(leadershipEventRecorder).onlyLogOnQuorumFailure(JavaSuppliers.compose(LeaderRuntimeConfig::onlyLogOnQuorumFailure, runtime)).build();
LeaderElectionService leaderElectionService = AtlasDbMetrics.instrument(LeaderElectionService.class, paxosLeaderElectionService);
PingableLeader pingableLeader = AtlasDbMetrics.instrument(PingableLeader.class, paxosLeaderElectionService);
return ImmutableLocalPaxosServices.builder().ourAcceptor(ourAcceptor).ourLearner(ourLearner).leaderElectionService(leaderElectionService).pingableLeader(pingableLeader).build();
}
Aggregations