private LeaderConfig getLeaderConfig() { // TODO (jkong): Live Reload Paxos Ping Rates PaxosRuntimeConfiguration paxosRuntimeConfiguration = runtime.get(); return ImmutableLeaderConfig.builder() .sslConfiguration(PaxosRemotingUtils.getSslConfigurationOptional(install)) .leaders(PaxosRemotingUtils.addProtocols(install, PaxosRemotingUtils.getClusterAddresses(install))) .localServer(PaxosRemotingUtils.addProtocol(install, PaxosRemotingUtils.getClusterConfiguration(install).localServer())) .acceptorLogDir(Paths.get(install.paxos().dataDirectory().toString(), PaxosTimeLockConstants.LEADER_PAXOS_NAMESPACE, PaxosTimeLockConstants.ACCEPTOR_SUBDIRECTORY_PATH).toFile()) .learnerLogDir(Paths.get(install.paxos().dataDirectory().toString(), PaxosTimeLockConstants.LEADER_PAXOS_NAMESPACE, PaxosTimeLockConstants.LEARNER_SUBDIRECTORY_PATH).toFile()) .pingRateMs(paxosRuntimeConfiguration.pingRateMs()) .quorumSize(PaxosRemotingUtils.getQuorumSize(PaxosRemotingUtils.getClusterAddresses(install))) .leaderPingResponseWaitMs(paxosRuntimeConfiguration.pingRateMs()) .randomWaitBeforeProposingLeadershipMs(paxosRuntimeConfiguration.pingRateMs()) .build(); }
private void setUpLeaderBlockInConfig() throws IOException { when(config.leader()).thenReturn(Optional.of(ImmutableLeaderConfig.builder() .localServer(getUriForPort(availablePort)) .addLeaders(getUriForPort(availablePort)) .acceptorLogDir(temporaryFolder.newFolder()) .learnerLogDir(temporaryFolder.newFolder()) .quorumSize(1) .build())); }
private static Optional<LeaderConfig> addFallbackSslConfigurationToLeader( Optional<LeaderConfig> config, Optional<SslConfiguration> sslConfiguration) { return config.map(leader -> ImmutableLeaderConfig.builder() .from(leader) .sslConfiguration(getFirstPresentOptional(leader.sslConfiguration(), sslConfiguration)) .build()); }
private static Optional<LeaderConfig> addFallbackSslConfigurationToLeader( Optional<LeaderConfig> config, Optional<SslConfiguration> sslConfiguration) { return config.map(leader -> ImmutableLeaderConfig.builder() .from(leader) .sslConfiguration(getFirstPresentOptional(leader.sslConfiguration(), sslConfiguration)) .build()); }
/** * Creates timestamp and lock services for the given client. It is expected that for each client there should * only be (up to) one active timestamp service, and one active lock service at any time. * @param client Client namespace to create the services for * @return Invalidating timestamp and lock services */ private TimeLockServices createInvalidatingTimeLockServices(String client) { List<String> uris = install.cluster().clusterMembers(); ImmutableLeaderConfig leaderConfig = ImmutableLeaderConfig.builder() .addLeaders(uris.toArray(new String[uris.size()])) .localServer(install.cluster().localServer()) .sslConfiguration(PaxosRemotingUtils.getSslConfigurationOptional(install)) .quorumSize(PaxosRemotingUtils.getQuorumSize(uris)) .build(); Supplier<ManagedTimestampService> rawTimestampServiceSupplier = timestampCreator .createTimestampService(client, leaderConfig); Supplier<LockService> rawLockServiceSupplier = lockCreator::createThreadPoolingLockService; return timelockCreator.createTimeLockServices(client, rawTimestampServiceSupplier, rawLockServiceSupplier); } }
@Test public void addingFallbackSslWhenItExistsDoesntOverride() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(ImmutableLeaderConfig.builder() .from(LEADER_CONFIG) .sslConfiguration(SSL_CONFIG) .build()) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, OTHER_SSL_CONFIG); assertThat(withSsl.leader().get().sslConfiguration(), is(SSL_CONFIG)); }
@Test(expected = IllegalStateException.class) public void cannotCreateALeaderConfigWithQuorumSizeLargerThanTheAmountOfLeaders() { ImmutableLeaderConfig.builder() .localServer("me") .addLeaders("not me", "me") .quorumSize(3) .build(); } }
@Override public boolean canConnect(InetSocketAddress addr) { return CassandraKeyValueServiceImpl.createForTesting( (CassandraKeyValueServiceConfig) getKeyValueServiceConfig(addr), Optional.of(ImmutableLeaderConfig.builder() .quorumSize(1) .localServer(addr.getHostString()) .leaders(ImmutableSet.of(addr.getHostString())) .build())) .isInitialized(); }
@Test(expected = IllegalStateException.class) public void cannotCreateALeaderConfigWithQuorumSizeNotBeingAMajorityOfTheLeaders() { ImmutableLeaderConfig.builder() .localServer("me") .addLeaders("not me", "me") .quorumSize(1) .build(); }
@Test(expected = IllegalStateException.class) public void cannotCreateALeaderConfigWithNoLeaders() { ImmutableLeaderConfig.builder() .localServer("me") .leaders(Collections.emptySet()) .quorumSize(0) .build(); }