@Provides @Singleton Collection<ClusterInfo> provideCassandraClusterInfo(BlobStoreConfiguration configuration) { Map<String, ClusterInfo> clusterInfoMap = Maps.newLinkedHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { ClusterInfo clusterInfo = new ClusterInfo(config.getCluster(), config.getClusterMetric()); ClusterInfo old = clusterInfoMap.put(config.getCluster(), clusterInfo); checkState(old == null || old.getClusterMetric().equals(clusterInfo.getClusterMetric()), "Cluster %s is configured with multiple distinct names for the cluster metric.", config.getCluster()); } return ImmutableList.copyOf(clusterInfoMap.values()); }
private void createKeyspaces(CassandraConfiguration keyspaceConfig, Keyspaces keyspacesMetadata, String ddlResourcePath, EmoConfiguration conf, CuratorFramework curator, final MetricRegistry metricRegistry) { for (String keyspaceName : keyspaceConfig.getKeyspaces().keySet()) { createKeyspace(keyspaceName, keyspaceConfig, keyspacesMetadata, ddlResourcePath, conf, curator, metricRegistry); } }
private CassandraThriftFacade toCassandraClient(CassandraConfiguration cassandraConfiguration, CuratorFramework curator, MetricRegistry metricRegistry) { cassandraConfiguration.withZooKeeperHostDiscovery(curator); cassandraConfiguration.performHostDiscovery(metricRegistry); return CassandraThriftFacade.forSeedsAndPort(cassandraConfiguration.getSeeds(), cassandraConfiguration.getThriftPort()); }
private AstyanaxContext.Builder newAstyanaxBuilder(String name, ConnectionPoolConfiguration poolConfig, MetricRegistry metricRegistry) { performHostDiscovery(metricRegistry); .setSeeds(_seeds) .setPartitioner(_partitioner.newAstyanaxPartitioner()) .setInitConnsPerHost(poolConfig.getInitialConnectionsPerHost().or(getInitialConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_INIT_PER_PARTITION)) .setMaxConnsPerHost(poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_ACTIVE_PER_PARTITION)) .setPort(_thriftPort) .setSocketTimeout(poolConfig.getSocketTimeout().or(getSocketTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_SOCKET_TIMEOUT)) .setConnectTimeout(poolConfig.getConnectTimeout().or(getConnectTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECT_TIMEOUT)) .setMaxFailoverCount(poolConfig.getMaxFailoverCount().or(getMaxFailoverCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_FAILOVER_COUNT)) .setConnectionLimiterWindowSize(poolConfig.getConnectionLimiterWindowSize().or(getConnectionLimiterWindowSize()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_WINDOW_SIZE)) .setConnectionLimiterMaxPendingCount(poolConfig.getConnectionLimiterMaxPendingCount().or(getConnectionLimiterMaxPendingCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_MAX_PENDING_COUNT)) .setMaxPendingConnectionsPerHost(poolConfig.getMaxPendingConnectionsPerHost().or(getMaxPendingConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_PENDING_CONNECTIONS_PER_HOST)) .setMaxBlockedThreadsPerHost(poolConfig.getMaxBlockedThreadsPerHost().or(getMaxBlockedThreadsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_BLOCKED_THREADS_PER_HOST)) .setMaxTimeoutCount(poolConfig.getMaxTimeoutCount().or(getMaxTimeoutCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIMEOUT_COUNT)) .setTimeoutWindow(poolConfig.getTimeoutWindow().or(getTimeoutWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_TIMEOUT_WINDOW)) .setRetrySuspendWindow(poolConfig.getRetrySuspendWindow().or(getRetrySuspendWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_SUSPEND_WINDOW)) .setRetryDelaySlice(poolConfig.getRetryDelaySlice().or(getRetryDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_DELAY_SLICE)) .setRetryMaxDelaySlice(poolConfig.getRetryMaxDelaySlice().or(getRetryMaxDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_MAX_DELAY_SLICE)) .setMaxTimeoutWhenExhausted(poolConfig.getMaxTimeoutWhenExhausted().or(getMaxTimeoutWhenExhausted()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIME_WHEN_EXHAUSTED)) .setAuthenticationCredentials(_authenticationCredentials) .setLatencyScoreStrategy(latencyScoreStrategy);
configuration.withZooKeeperHostDiscovery(_curator); for (Map.Entry<String, KeyspaceConfiguration> entry : configuration.getKeyspaces().entrySet()) { String keyspaceName = entry.getKey(); KeyspaceConfiguration keyspaceConfig = entry.getValue(); keyspaceName, configuration.getCluster()); sharedAstyanaxCluster = configuration.astyanax().metricRegistry(_metricRegistry).cluster(); sharedCqlCluster = configuration.cql().metricRegistry(_metricRegistry).cluster(); _lifeCycle.manage(sharedAstyanaxCluster); _lifeCycle.manage(sharedCqlCluster); } else { _log.info("Connection to keyspace {} will be created using a private connection to cluster \"{}\"", keyspaceName, configuration.getCluster()); astyanaxCluster = configuration.astyanax() .keyspace(keyspaceName) .metricRegistry(_metricRegistry) .cluster(); cqlCluster = configuration.cql() .keyspace(keyspaceName) .metricRegistry(_metricRegistry) CassandraHealthCheckConfiguration healthCheckConfig = configuration.getHealthCheck(); CassandraKeyspace healthCheckKeyspace = keyspaceMap.values().iterator().next(); CassandraHealthCheck healthCheck = newHealthCheck(healthCheckKeyspace, healthCheckConfig.getHealthCheckCql());
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig, MetricRegistry metricRegistry) { performHostDiscovery(metricRegistry); if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) { poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get()); if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) { poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get()); if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) { socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get()); if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) { socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
@Provides @Singleton @CassandraClusters Collection<String> provideCassandraClusterNames(DataStoreConfiguration configuration) { Set<String> clusters = Sets.newLinkedHashSet(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { clusters.add(config.getCluster()); } return clusters; }
public HintsPollerCQLSession cqlSessionForHintsPoller(CassandraConfiguration configuration) { // Nodes can register themselves in ZooKeeper to help figure out which hosts are in this data center. configuration.withZooKeeperHostDiscovery(_curator); // Hints Poller only need 1 connection per host since all this is used for is single-threaded polling of the hints table. // We could also have a new property in the CassandraConfiguration yaml's just for the HintsPoller sake. CqlCluster cqlCluster = configuration.cql() .metricRegistry(_metricRegistry) .disableClusterMetrics() .maxConnectionsPerHost(1) .coreConnectionsPerHost(1) .loadBalancingPolicy(new SelectedHostLoadBalancingPolicy()) .retryPolicy(FallthroughRetryPolicy.INSTANCE) .cluster(); _lifeCycle.manage(cqlCluster); return new HintsPollerCQLSession(_lifeCycle, cqlCluster); }
private AstyanaxContext.Builder newAstyanaxBuilder(String name, ConnectionPoolConfiguration poolConfig, MetricRegistry metricRegistry) { performHostDiscovery(metricRegistry); .setSeeds(_seeds) .setPartitioner(_partitioner.newAstyanaxPartitioner()) .setInitConnsPerHost(poolConfig.getInitialConnectionsPerHost().or(getInitialConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_INIT_PER_PARTITION)) .setMaxConnsPerHost(poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_ACTIVE_PER_PARTITION)) .setPort(_thriftPort) .setSocketTimeout(poolConfig.getSocketTimeout().or(getSocketTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_SOCKET_TIMEOUT)) .setConnectTimeout(poolConfig.getConnectTimeout().or(getConnectTimeout()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECT_TIMEOUT)) .setMaxFailoverCount(poolConfig.getMaxFailoverCount().or(getMaxFailoverCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_FAILOVER_COUNT)) .setConnectionLimiterWindowSize(poolConfig.getConnectionLimiterWindowSize().or(getConnectionLimiterWindowSize()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_WINDOW_SIZE)) .setConnectionLimiterMaxPendingCount(poolConfig.getConnectionLimiterMaxPendingCount().or(getConnectionLimiterMaxPendingCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_CONNECTION_LIMITER_MAX_PENDING_COUNT)) .setMaxPendingConnectionsPerHost(poolConfig.getMaxPendingConnectionsPerHost().or(getMaxPendingConnectionsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_PENDING_CONNECTIONS_PER_HOST)) .setMaxBlockedThreadsPerHost(poolConfig.getMaxBlockedThreadsPerHost().or(getMaxBlockedThreadsPerHost()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_BLOCKED_THREADS_PER_HOST)) .setMaxTimeoutCount(poolConfig.getMaxTimeoutCount().or(getMaxTimeoutCount()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIMEOUT_COUNT)) .setTimeoutWindow(poolConfig.getTimeoutWindow().or(getTimeoutWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_TIMEOUT_WINDOW)) .setRetrySuspendWindow(poolConfig.getRetrySuspendWindow().or(getRetrySuspendWindow()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_SUSPEND_WINDOW)) .setRetryDelaySlice(poolConfig.getRetryDelaySlice().or(getRetryDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_DELAY_SLICE)) .setRetryMaxDelaySlice(poolConfig.getRetryMaxDelaySlice().or(getRetryMaxDelaySlice()).or(ConnectionPoolConfigurationImpl.DEFAULT_RETRY_MAX_DELAY_SLICE)) .setMaxTimeoutWhenExhausted(poolConfig.getMaxTimeoutWhenExhausted().or(getMaxTimeoutWhenExhausted()).or(ConnectionPoolConfigurationImpl.DEFAULT_MAX_TIME_WHEN_EXHAUSTED)) .setAuthenticationCredentials(_authenticationCredentials) .setLatencyScoreStrategy(latencyScoreStrategy);
configuration.withZooKeeperHostDiscovery(_curator); for (Map.Entry<String, KeyspaceConfiguration> entry : configuration.getKeyspaces().entrySet()) { String keyspaceName = entry.getKey(); KeyspaceConfiguration keyspaceConfig = entry.getValue(); keyspaceName, configuration.getCluster()); sharedAstyanaxCluster = configuration.astyanax().metricRegistry(_metricRegistry).cluster(); sharedCqlCluster = configuration.cql().metricRegistry(_metricRegistry).cluster(); _lifeCycle.manage(sharedAstyanaxCluster); _lifeCycle.manage(sharedCqlCluster); } else { _log.info("Connection to keyspace {} will be created using a private connection to cluster \"{}\"", keyspaceName, configuration.getCluster()); astyanaxCluster = configuration.astyanax() .keyspace(keyspaceName) .metricRegistry(_metricRegistry) .cluster(); cqlCluster = configuration.cql() .keyspace(keyspaceName) .metricRegistry(_metricRegistry) CassandraHealthCheckConfiguration healthCheckConfig = configuration.getHealthCheck(); CassandraKeyspace healthCheckKeyspace = keyspaceMap.values().iterator().next(); CassandraHealthCheck healthCheck = newHealthCheck(healthCheckKeyspace, healthCheckConfig.getHealthCheckCql());
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig, MetricRegistry metricRegistry) { performHostDiscovery(metricRegistry); if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) { poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get()); if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) { poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get()); if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) { socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get()); if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) { socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
@Provides @Singleton @CassandraClusters Collection<String> provideCassandraClusterNames(DataStoreConfiguration configuration) { Set<String> clusters = Sets.newLinkedHashSet(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { clusters.add(config.getCluster()); } return clusters; }
public HintsPollerCQLSession cqlSessionForHintsPoller(CassandraConfiguration configuration) { // Nodes can register themselves in ZooKeeper to help figure out which hosts are in this data center. configuration.withZooKeeperHostDiscovery(_curator); // Hints Poller only need 1 connection per host since all this is used for is single-threaded polling of the hints table. // We could also have a new property in the CassandraConfiguration yaml's just for the HintsPoller sake. CqlCluster cqlCluster = configuration.cql() .metricRegistry(_metricRegistry) .disableClusterMetrics() .maxConnectionsPerHost(1) .coreConnectionsPerHost(1) .loadBalancingPolicy(new SelectedHostLoadBalancingPolicy()) .retryPolicy(FallthroughRetryPolicy.INSTANCE) .cluster(); _lifeCycle.manage(cqlCluster); return new HintsPollerCQLSession(_lifeCycle, cqlCluster); }
private Collection<ClusterInfo> getClusterInfos(DataStoreConfiguration configuration) { Map<String, ClusterInfo> clusterInfoMap = Maps.newLinkedHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { ClusterInfo clusterInfo = new ClusterInfo(config.getCluster(), config.getClusterMetric()); ClusterInfo old = clusterInfoMap.put(config.getCluster(), clusterInfo); checkState(old == null || old.getClusterMetric().equals(clusterInfo.getClusterMetric()), "Cluster %s is configured with multiple distinct names for the cluster metric.", config.getCluster()); } return ImmutableList.copyOf(clusterInfoMap.values()); }
/** Required for HintsPollerManager **/ @Provides @Singleton @CassandraClusters Collection<String> provideCassandraClusterNames(BlobStoreConfiguration configuration) { Set<String> clusters = Sets.newLinkedHashSet(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { clusters.add(config.getCluster()); } return clusters; }
private void checkValidSystemTablePlacement() { String systemTablePlacement = _configuration.getSystemTablePlacement(); String systemKeyspace = systemTablePlacement.substring(0, systemTablePlacement.indexOf(':')); for (CassandraConfiguration cassandraConfig : _configuration.getDataStoreConfiguration().getCassandraClusters().values()) { if (cassandraConfig.getKeyspaces().containsKey(systemKeyspace)) { return; } } throw new ProvisionException("System Table Placement references a keyspace not defined in 'cassandraKeyspaces"); }
private Collection<ClusterInfo> getClusterInfos(DataStoreConfiguration configuration) { Map<String, ClusterInfo> clusterInfoMap = Maps.newLinkedHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { ClusterInfo clusterInfo = new ClusterInfo(config.getCluster(), config.getClusterMetric()); ClusterInfo old = clusterInfoMap.put(config.getCluster(), clusterInfo); checkState(old == null || old.getClusterMetric().equals(clusterInfo.getClusterMetric()), "Cluster %s is configured with multiple distinct names for the cluster metric.", config.getCluster()); } return ImmutableList.copyOf(clusterInfoMap.values()); }
@Provides @Singleton @CQLSessionForHintsPollerMap Map<String, HintsPollerCQLSession> provideCQLSessionsForHintsPoller(DataStoreConfiguration configuration, CassandraFactory factory) { Map<String, HintsPollerCQLSession> cqlSessionMap = Maps.newHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { String clusterName = config.getCluster(); if(!cqlSessionMap.containsKey(clusterName)) { cqlSessionMap.put(clusterName, factory.cqlSessionForHintsPoller(config)); } } return ImmutableMap.copyOf(cqlSessionMap); }
@Provides @Singleton @CQLSessionForHintsPollerMap Map<String, HintsPollerCQLSession> provideCQLSessionsForHintsPoller(BlobStoreConfiguration configuration, CassandraFactory factory) { Map<String, HintsPollerCQLSession> cqlSessionMap = Maps.newHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { String clusterName = config.getCluster(); if(!cqlSessionMap.containsKey(clusterName)) { cqlSessionMap.put(clusterName, factory.cqlSessionForHintsPoller(config)); } } return ImmutableMap.copyOf(cqlSessionMap); }
@Provides @Singleton @CQLSessionForHintsPollerMap Map<String, HintsPollerCQLSession> provideCQLSessionsForHintsPoller(DataStoreConfiguration configuration, CassandraFactory factory) { Map<String, HintsPollerCQLSession> cqlSessionMap = Maps.newHashMap(); for (CassandraConfiguration config : configuration.getCassandraClusters().values()) { String clusterName = config.getCluster(); if(!cqlSessionMap.containsKey(clusterName)) { cqlSessionMap.put(clusterName, factory.cqlSessionForHintsPoller(config)); } } return ImmutableMap.copyOf(cqlSessionMap); }