Search in sources :

Example 1 with LeaderElectionServiceBuilder

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);
}
Also used : SimulatingFailingServerProxy(com.palantir.leader.proxy.SimulatingFailingServerProxy) LeaderElectionService(com.palantir.leader.LeaderElectionService) LeaderElectionServiceBuilder(com.palantir.leader.LeaderElectionServiceBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) ToggleableExceptionProxy(com.palantir.leader.proxy.ToggleableExceptionProxy) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileUtils(org.apache.commons.io.FileUtils) UUID(java.util.UUID) PaxosKnowledgeEventRecorder(com.palantir.leader.PaxosKnowledgeEventRecorder) Maps(com.google.common.collect.Maps) File(java.io.File) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PTExecutors(com.palantir.common.concurrent.PTExecutors) Paths(java.nio.file.Paths) Duration(java.time.Duration) DataSource(javax.sql.DataSource) Optional(java.util.Optional) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) DataSource(javax.sql.DataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) LeaderElectionServiceBuilder(com.palantir.leader.LeaderElectionServiceBuilder) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) ExecutorService(java.util.concurrent.ExecutorService) LeaderElectionService(com.palantir.leader.LeaderElectionService) UUID(java.util.UUID)

Example 2 with LeaderElectionServiceBuilder

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

ImmutableList (com.google.common.collect.ImmutableList)2 PTExecutors (com.palantir.common.concurrent.PTExecutors)2 LeaderElectionService (com.palantir.leader.LeaderElectionService)2 LeaderElectionServiceBuilder (com.palantir.leader.LeaderElectionServiceBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 HostAndPort (com.google.common.net.HostAndPort)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 NotCurrentLeaderExceptionMapper (com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper)1 AtlasDbMetrics (com.palantir.atlasdb.util.AtlasDbMetrics)1 MetricsManager (com.palantir.atlasdb.util.MetricsManager)1 KeyedStream (com.palantir.common.streams.KeyedStream)1 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)1