new ConnectionPoolConfigurationImpl(usedFor + "TitanConnectionPool") .setPort(port) .setMaxOperationsPerConnection(maxOperationsPerConnection) .setMaxConnsPerHost(maxConnsPerHost) .setRetryDelaySlice(retryDelaySlice) .setRetryMaxDelaySlice(retryMaxDelaySlice) .setRetrySuspendWindow(retrySuspendWindow) .setSocketTimeout(connectionTimeout) .setConnectTimeout(connectionTimeout) .setSeeds(StringUtils.join(hostnames, ",")); cpool.setRetryBackoffStrategy(retryBackoffStrategy); log.debug("Custom RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy()); } else { log.debug("Default RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy()); cpool.setLocalDatacenter(localDatacenter); log.debug("Set local datacenter: {}", cpool.getLocalDatacenter()); cpool.setMaxConns(maxConnections); cpool.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password)); cpool.setSSLConnectionContext(new SSLConnectionContext(config.get(SSL_TRUSTSTORE_LOCATION), config.get(SSL_TRUSTSTORE_PASSWORD)));
private ConnectionPoolConfiguration getConnectionPoolConfig ( final String poolName, final int poolSize ){ ConnectionPoolConfiguration config; final String username = cassandraFig.getUsername(); final String password = cassandraFig.getPassword(); if ( username != null && !username.isEmpty() && password != null && !password.isEmpty() ){ config = new ConnectionPoolConfigurationImpl( poolName ) .setPort( cassandraFig.getThriftPort() ) .setLocalDatacenter( cassandraFig.getLocalDataCenter() ) .setMaxConnsPerHost( poolSize ) .setSeeds( cassandraFig.getHosts() ) .setConnectTimeout( cassandraFig.getTimeout() ) .setSocketTimeout( cassandraFig.getTimeout() ) .setAuthenticationCredentials(new SimpleAuthenticationCredentials( username, password)); } else { // create instance of the connection pool without credential if they are not set config = new ConnectionPoolConfigurationImpl( poolName ) .setPort( cassandraFig.getThriftPort() ) .setLocalDatacenter( cassandraFig.getLocalDataCenter() ) .setMaxConnsPerHost( poolSize ) .setSeeds( cassandraFig.getHosts() ) .setSocketTimeout( cassandraFig.getTimeout() ) .setConnectTimeout( cassandraFig.getTimeout() ); } return config; }
public CassandraStorage(CassandraDataSegmentConfig config) { this.astyanaxContext = new AstyanaxContext.Builder() .forCluster(CLUSTER_NAME) .forKeyspace(config.getKeyspace()) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("MyConnectionPool").setMaxConnsPerHost(10) .setSeeds(config.getHost())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); this.astyanaxContext.start(); this.keyspace = this.astyanaxContext.getEntity(); this.config = config; indexStorage = new CassandraChunkedStorageProvider(keyspace, INDEX_TABLE_NAME); descriptorStorage = new ColumnFamily<String, String>(DESCRIPTOR_TABLE_NAME, StringSerializer.get(), StringSerializer.get()); } }
public synchronized Cluster registerCluster(String clusterName, String contactPoint, int port) { logger.info("Connected Cassandra Cluster: " + clusterName); if(clusterContext == null) { clusterContext = new AstyanaxContext.Builder().forCluster(clusterName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildCluster(ThriftFamilyFactory.getInstance()); clusterContext.start(); } logger.warn("Cluster already registered"); return clusterContext.getClient(); }
new EmptyLatencyScoreStrategyImpl(); ConnectionPoolConfigurationImpl poolConfiguration = new ConnectionPoolConfigurationImpl(name) .setLocalDatacenter(_dataCenter) .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);
.setDiscoveryDelayInSeconds(60000)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(TEST_CLUSTER_NAME + "_" + TEST_KEYSPACE_NAME) .setSocketTimeout(30000) .setMaxTimeoutWhenExhausted(2000) .setMaxConnsPerHost(20) .setInitConnsPerHost(10) .setSeeds(SEEDS) .setPort(9042)
ConnectionPoolConfigurationImpl poolConfig = new ConnectionPoolConfigurationImpl(getClusterName()).setPort(port); poolConfig.setMaxConnsPerHost(Integer.parseInt(maxConnection)); poolConfig.setSeeds(StringUtils.join(endpoints, ":" + port + ",")); poolConfig.setLatencyScoreStrategy(latencyScoreStrategy); logger.info("ConnectionPoolConfiguration: " + poolConfig.toString());
private AstyanaxContext<Keyspace> getKeyspaceContext(final String ks, final String seedHost) { AstyanaxContext<Keyspace> ctx = new AstyanaxContext.Builder() .forKeyspace(ks) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("myCPConfig-" + ks) .setSeeds(seedHost) .setPort(7102)) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl() .setDefaultReadConsistencyLevel(ConsistencyLevel.CL_LOCAL_QUORUM) .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE) .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)) .buildKeyspace(ThriftFamilyFactory.getInstance()); return ctx; }
private AstyanaxContext<Keyspace> initWithThriftDriverWithEurekaHostsSupplier() { logger.info("BOOT_CLUSTER = {}, KS_NAME = {}", BOOT_CLUSTER, KS_NAME); return new AstyanaxContext.Builder().forCluster(BOOT_CLUSTER).forKeyspace(KS_NAME) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.DISCOVERY_SERVICE)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setMaxConnsPerHost(3).setPort(thriftPortForAstyanax)) .withHostSupplier(hostSupplier.getSupplier(BOOT_CLUSTER)) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); }
ConnectionPoolConfigurationImpl cpConfig = (ConnectionPoolConfigurationImpl) settings .get(ASTYANAX_CONNECTION_POOL_CONFIGURATION); cpConfig.setSeeds((String) config.get(StormCassandraConstants.CASSANDRA_HOST)); Long port = (Long)config.get(StormCassandraConstants.CASSANDRA_PORT); if(port != null){ cpConfig.setPort(port.intValue()); (String) config.get(StormCassandraConstants.CASSANDRA_PASSWORD) : "password"; cpConfig.setAuthenticationCredentials( new SimpleAuthenticationCredentials(new String(user), new String(password)));
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(9160) .setMaxConnsPerHost(40) .setLocalDatacenter("phx") .setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160") )
protected AstyanaxContext<Keyspace> createContext(Map<String, Object> config) { Map<String, Object> settings = Maps.newHashMap(); for (Map.Entry<String, Object> defaultEntry : DEFAULTS.entrySet()) { if (config.containsKey(defaultEntry.getKey())) { settings.put(defaultEntry.getKey(), config.get(defaultEntry.getKey())); } else { settings.put(defaultEntry.getKey(), defaultEntry.getValue()); } } // in the defaults case, we don't know the seed hosts until context // creation time if (settings.get(ASTYANAX_CONNECTION_POOL_CONFIGURATION) instanceof ConnectionPoolConfigurationImpl) { ConnectionPoolConfigurationImpl cpConfig = (ConnectionPoolConfigurationImpl) settings .get(ASTYANAX_CONNECTION_POOL_CONFIGURATION); cpConfig.setSeeds((String) config.get(StormCassandraConstants.CASSANDRA_HOST)); } return new AstyanaxContext.Builder() .forCluster((String) settings.get(CASSANDRA_CLUSTER_NAME)) .forKeyspace((String) config.get(StormCassandraConstants.CASSANDRA_STATE_KEYSPACE)) .withAstyanaxConfiguration((AstyanaxConfiguration) settings.get(ASTYANAX_CONFIGURATION)) .withConnectionPoolConfiguration( (ConnectionPoolConfiguration) settings.get(ASTYANAX_CONNECTION_POOL_CONFIGURATION)) .withConnectionPoolMonitor((ConnectionPoolMonitor) settings.get(ASTYANAX_CONNECTION_POOL_MONITOR)) .buildKeyspace(ThriftFamilyFactory.getInstance()); }
public synchronized Cluster registerCluster(String clusterName, String contactPoint, int port) { logger.info("Connected Cassandra Cluster: " + clusterName); if(clusterContext == null) { clusterContext = new AstyanaxContext.Builder().forCluster(clusterName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(port) .setMaxConnsPerHost(1) .setSeeds(contactPoint) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildCluster(ThriftFamilyFactory.getInstance()); clusterContext.start(); } logger.warn("Cluster already registered"); return clusterContext.getClient(); }
new EmptyLatencyScoreStrategyImpl(); ConnectionPoolConfigurationImpl poolConfiguration = new ConnectionPoolConfigurationImpl(name) .setLocalDatacenter(_dataCenter) .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);
.setDiscoveryDelayInSeconds(60000)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl(TEST_CLUSTER_NAME + "_" + TEST_KEYSPACE_NAME) .setSocketTimeout(30000) .setMaxTimeoutWhenExhausted(2000) .setMaxConnsPerHost(20) .setInitConnsPerHost(10) .setSeeds(SEEDS) .setPort(9160)
ConnectionPoolConfigurationImpl connectionPoolConfiguration = new ConnectionPoolConfigurationImpl("CMBAstyananxConnectionPool") .setMaxConnsPerHost(CMBProperties.getInstance().getAstyanaxMaxConnectionsPerNode()) .setSocketTimeout(CMBProperties.getInstance().getCassandraThriftSocketTimeOutMS()) .setConnectTimeout(CMBProperties.getInstance().getAstyanaxConnectionWaitTimeOutMS()) .setSeeds(AbstractDurablePersistence.CLUSTER_URL); connectionPoolConfiguration.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password)); connectionPoolConfiguration.setLocalDatacenter(dataCenter);
public CassandraStorage(CassandraDataSegmentConfig config) { this.astyanaxContext = new AstyanaxContext.Builder() .forCluster(CLUSTER_NAME) .forKeyspace(config.getKeyspace()) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.NONE)) .withConnectionPoolConfiguration( new ConnectionPoolConfigurationImpl("MyConnectionPool").setMaxConnsPerHost(10) .setSeeds(config.getHost())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); this.astyanaxContext.start(); this.keyspace = this.astyanaxContext.getEntity(); this.config = config; indexStorage = new CassandraChunkedStorageProvider(keyspace, INDEX_TABLE_NAME); descriptorStorage = new ColumnFamily<String, String>(DESCRIPTOR_TABLE_NAME, StringSerializer.get(), StringSerializer.get()); } }
/** * Builds a {@link Keyspace} from current configuration. */ public Keyspace build() { final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder() .forCluster(clusterName) .forKeyspace(keyspaceName) .withAstyanaxConfiguration(new AstyanaxConfigurationImpl() .setDiscoveryType(RING_DESCRIBE) ) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("ConnectionPool") .setPort(thriftPort) .setSeeds(hosts) ) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); context.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public synchronized void run() { context.shutdown(); } }); return context.getClient(); } }
private AstyanaxContext<Keyspace> initWithThriftDriverWithExternalHostsSupplier() { logger.info("BOOT_CLUSTER = {}, KS_NAME = {}", BOOT_CLUSTER, KS_NAME); return new AstyanaxContext.Builder().forCluster(BOOT_CLUSTER).forKeyspace(KS_NAME) .withAstyanaxConfiguration( new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.DISCOVERY_SERVICE) .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setMaxConnsPerHost(3).setPort(thriftPortForAstyanax)) .withHostSupplier(getSupplier()).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); }
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool") .setPort(9160) .setMaxConnsPerHost(40) .setLocalDatacenter("DC1") .setSeeds("127.0.0.1:9160") )