Search in sources :

Example 1 with PaxosProposer

use of com.palantir.paxos.PaxosProposer 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();
}
Also used : PaxosAcceptor(com.palantir.paxos.PaxosAcceptor) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) PaxosProposer(com.palantir.paxos.PaxosProposer) PaxosLearner(com.palantir.paxos.PaxosLearner) HostAndPort(com.google.common.net.HostAndPort) PingableLeader(com.palantir.leader.PingableLeader) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PaxosLeaderElectionService(com.palantir.leader.PaxosLeaderElectionService) PaxosLeaderElectionService(com.palantir.leader.PaxosLeaderElectionService) LeaderElectionService(com.palantir.leader.LeaderElectionService) PaxosLeadershipEventRecorder(com.palantir.leader.PaxosLeadershipEventRecorder) UUID(java.util.UUID) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) PaxosLeaderElectionServiceBuilder(com.palantir.leader.PaxosLeaderElectionServiceBuilder) LeaderRuntimeConfig(com.palantir.atlasdb.config.LeaderRuntimeConfig)

Example 2 with PaxosProposer

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

the class PaxosTimestampBoundStoreTest method retriesProposeUntilSuccessful.

@Test
public void retriesProposeUntilSuccessful() throws Exception {
    PaxosProposer wrapper = spy(new OnceFailingPaxosProposer(createPaxosProposer(0)));
    store = createPaxosTimestampBoundStore(0, wrapper);
    store.storeUpperLimit(TIMESTAMP_1);
    assertThat(store.getUpperLimit()).isGreaterThanOrEqualTo(TIMESTAMP_1);
    verify(wrapper, times(2)).propose(anyLong(), anyObject());
}
Also used : PaxosProposer(com.palantir.paxos.PaxosProposer) Test(org.junit.Test)

Example 3 with PaxosProposer

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

the class PaxosTimestampCreator method createTimestampService.

@Override
public Supplier<ManagedTimestampService> createTimestampService(String client, LeaderConfig unused) {
    ExecutorService executor = PTExecutors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("atlas-consensus-" + client + "-%d").setDaemon(true).build());
    Set<String> namespacedUris = PaxosTimeLockUriUtils.getClientPaxosUris(remoteServers, client);
    List<PaxosAcceptor> acceptors = Leaders.createProxyAndLocalList(paxosResource.getPaxosAcceptor(client), namespacedUris, optionalSecurity, PaxosAcceptor.class, "timestamp-bound-store." + client);
    PaxosLearner ourLearner = paxosResource.getPaxosLearner(client);
    List<PaxosLearner> learners = Leaders.createProxyAndLocalList(ourLearner, namespacedUris, optionalSecurity, PaxosLearner.class, "timestamp-bound-store." + client);
    PaxosProposer proposer = instrument(PaxosProposer.class, PaxosProposerImpl.newProposer(ourLearner, ImmutableList.copyOf(acceptors), ImmutableList.copyOf(learners), PaxosRemotingUtils.getQuorumSize(acceptors), UUID.randomUUID(), executor), client);
    PaxosSynchronizer.synchronizeLearner(ourLearner, learners);
    return () -> createManagedPaxosTimestampService(proposer, client, acceptors, learners);
}
Also used : PaxosAcceptor(com.palantir.paxos.PaxosAcceptor) PaxosProposer(com.palantir.paxos.PaxosProposer) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PaxosLearner(com.palantir.paxos.PaxosLearner)

Example 4 with PaxosProposer

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

the class PaxosTimestampBoundStoreTest method retriesForceAgreedStateUntilSuccessful.

@Test
public void retriesForceAgreedStateUntilSuccessful() throws Exception {
    PaxosProposer wrapper = spy(new OnceFailingPaxosProposer(createPaxosProposer(0)));
    store = createPaxosTimestampBoundStore(0, wrapper);
    store.forceAgreedState(1, TIMESTAMP_1);
    assertThat(store.getUpperLimit()).isGreaterThanOrEqualTo(TIMESTAMP_1);
    verify(wrapper, times(2)).propose(anyLong(), anyObject());
}
Also used : PaxosProposer(com.palantir.paxos.PaxosProposer) Test(org.junit.Test)

Aggregations

PaxosProposer (com.palantir.paxos.PaxosProposer)4 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 PaxosAcceptor (com.palantir.paxos.PaxosAcceptor)2 PaxosLearner (com.palantir.paxos.PaxosLearner)2 Test (org.junit.Test)2 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 HostAndPort (com.google.common.net.HostAndPort)1 LeaderRuntimeConfig (com.palantir.atlasdb.config.LeaderRuntimeConfig)1 LeaderElectionService (com.palantir.leader.LeaderElectionService)1 PaxosLeaderElectionService (com.palantir.leader.PaxosLeaderElectionService)1 PaxosLeaderElectionServiceBuilder (com.palantir.leader.PaxosLeaderElectionServiceBuilder)1 PaxosLeadershipEventRecorder (com.palantir.leader.PaxosLeadershipEventRecorder)1 PingableLeader (com.palantir.leader.PingableLeader)1 UUID (java.util.UUID)1 ExecutorService (java.util.concurrent.ExecutorService)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1