Search in sources :

Example 1 with PingableLeader

use of com.palantir.leader.PingableLeader 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 PingableLeader

use of com.palantir.leader.PingableLeader in project atlasdb by palantir.

the class LeaderPingHealthCheckTest method shouldBeUnhealthyIfQuorumNodesAreUpAndNoNodePingedSuccessfully.

@Test
public void shouldBeUnhealthyIfQuorumNodesAreUpAndNoNodePingedSuccessfully() throws Exception {
    PingableLeader leader1 = getMockOfPingableLeaderWherePingReturns(false);
    PingableLeader leader2 = getMockOfPingableLeaderWherePingReturns(false);
    PingableLeader leader3 = getMockOfPingableLeaderWherePingThrows();
    ImmutableSet<PingableLeader> leaders = ImmutableSet.of(leader1, leader2, leader3);
    assertEquals(TimeLockStatus.NO_LEADER, new LeaderPingHealthCheck(leaders).getStatus());
}
Also used : PingableLeader(com.palantir.leader.PingableLeader) Test(org.junit.Test)

Example 3 with PingableLeader

use of com.palantir.leader.PingableLeader in project atlasdb by palantir.

the class LeaderPingHealthCheckTest method shouldBeUnhealthyIfQuorumNodesAreNotUpAndNoNodePingedSuccessfully.

@Test
public void shouldBeUnhealthyIfQuorumNodesAreNotUpAndNoNodePingedSuccessfully() throws Exception {
    PingableLeader leader1 = getMockOfPingableLeaderWherePingReturns(false);
    PingableLeader leader2 = getMockOfPingableLeaderWherePingThrows();
    PingableLeader leader3 = getMockOfPingableLeaderWherePingThrows();
    ImmutableSet<PingableLeader> leaders = ImmutableSet.of(leader1, leader2, leader3);
    assertEquals(TimeLockStatus.NO_QUORUM, new LeaderPingHealthCheck(leaders).getStatus());
}
Also used : PingableLeader(com.palantir.leader.PingableLeader) Test(org.junit.Test)

Example 4 with PingableLeader

use of com.palantir.leader.PingableLeader in project atlasdb by palantir.

the class LeaderPingHealthCheckTest method shouldBeHealthyIfQuorumNodesUpAndOnePingedSuccessfully.

@Test
public void shouldBeHealthyIfQuorumNodesUpAndOnePingedSuccessfully() throws Exception {
    PingableLeader leader1 = getMockOfPingableLeaderWherePingReturns(true);
    PingableLeader leader2 = getMockOfPingableLeaderWherePingReturns(false);
    PingableLeader leader3 = getMockOfPingableLeaderWherePingThrows();
    ImmutableSet<PingableLeader> leaders = ImmutableSet.of(leader1, leader2, leader3);
    assertEquals(TimeLockStatus.ONE_LEADER, new LeaderPingHealthCheck(leaders).getStatus());
}
Also used : PingableLeader(com.palantir.leader.PingableLeader) Test(org.junit.Test)

Example 5 with PingableLeader

use of com.palantir.leader.PingableLeader in project atlasdb by palantir.

the class LeaderPingHealthCheckTest method getPingableLeaders.

private ImmutableSet<PingableLeader> getPingableLeaders(boolean pingResultForLeader1, boolean pingResultForLeader2, boolean pingResultForLeader3) {
    PingableLeader leader1 = getMockOfPingableLeaderWherePingReturns(pingResultForLeader1);
    PingableLeader leader2 = getMockOfPingableLeaderWherePingReturns(pingResultForLeader2);
    PingableLeader leader3 = getMockOfPingableLeaderWherePingReturns(pingResultForLeader3);
    return ImmutableSet.of(leader1, leader2, leader3);
}
Also used : PingableLeader(com.palantir.leader.PingableLeader)

Aggregations

PingableLeader (com.palantir.leader.PingableLeader)13 Test (org.junit.Test)5 HostAndPort (com.google.common.net.HostAndPort)2 LeaderRuntimeConfig (com.palantir.atlasdb.config.LeaderRuntimeConfig)2 LeaderElectionService (com.palantir.leader.LeaderElectionService)2 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ImmutableLeaderRuntimeConfig (com.palantir.atlasdb.config.ImmutableLeaderRuntimeConfig)1 ImmutableServerListConfig (com.palantir.atlasdb.config.ImmutableServerListConfig)1 LocalPaxosServices (com.palantir.atlasdb.factory.Leaders.LocalPaxosServices)1 AtlasDbRemoteException (com.palantir.atlasdb.http.errors.AtlasDbRemoteException)1 KvsBackedPersistentLockService (com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService)1 NoOpPersistentLockService (com.palantir.atlasdb.persistentlock.NoOpPersistentLockService)1 PersistentLockService (com.palantir.atlasdb.persistentlock.PersistentLockService)1 PaxosLeaderElectionService (com.palantir.leader.PaxosLeaderElectionService)1 PaxosLeaderElectionServiceBuilder (com.palantir.leader.PaxosLeaderElectionServiceBuilder)1 PaxosLeadershipEventRecorder (com.palantir.leader.PaxosLeadershipEventRecorder)1 LockService (com.palantir.lock.LockService)1 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)1 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)1