public void prepare() { LOG.info("Preparing state for {}", options.toString()); Preconditions.checkNotNull(options.getMapper, "CassandraBackingMap.Options should have getMapper"); Preconditions.checkNotNull(options.putMapper, "CassandraBackingMap.Options should have putMapper"); client = options.clientProvider.getClient(conf); session = client.connect(); if (options.maxParallelism == null || options.maxParallelism <= 0) { PoolingOptions po = session.getCluster().getConfiguration().getPoolingOptions(); Integer maxRequestsPerHost = Math.min( po.getMaxConnectionsPerHost(HostDistance.LOCAL) * po.getMaxRequestsPerConnection(HostDistance.LOCAL), po.getMaxConnectionsPerHost(HostDistance.REMOTE) * po.getMaxRequestsPerConnection(HostDistance.REMOTE) ); options.maxParallelism = maxRequestsPerHost / 2; LOG.info("Parallelism default set to {}", options.maxParallelism); } throttle = new Semaphore(options.maxParallelism, false); this.getResultMapper = new TridentAyncCQLResultSetValuesMapper(options.stateMapper.getStateFields(), throttle); this.putResultMapper = new TridentAyncCQLResultSetValuesMapper(null, throttle); }
@Inject public DataStaxClusterImpl(final CassandraConfig cassandraFig ) throws Exception { this.cassandraConfig = cassandraFig; this.cluster = getCluster(); logger.info("Initialized datastax cluster client. Hosts={}, Idle Timeout={}s, Pool Timeout={}s", getCluster().getMetadata().getAllHosts().toString(), getCluster().getConfiguration().getPoolingOptions().getIdleTimeoutSeconds(), getCluster().getConfiguration().getPoolingOptions().getPoolTimeoutMillis() / 1000); // always initialize the keyspaces this.createApplicationKeyspace(false); this.createApplicationLocalKeyspace(false); }
MAX_CONNECTIONS_PROPERTY); if (maxConnections != null) { cluster.getConfiguration().getPoolingOptions() .setMaxConnectionsPerHost(HostDistance.LOCAL, Integer.valueOf(maxConnections)); CORE_CONNECTIONS_PROPERTY); if (coreConnections != null) { cluster.getConfiguration().getPoolingOptions() .setCoreConnectionsPerHost(HostDistance.LOCAL, Integer.valueOf(coreConnections));
private PoolingOptions options() { return manager.configuration().getPoolingOptions(); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (isInitialized && !isClosed() && evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == READER_IDLE) { logger.debug( "{} was inactive for {} seconds, sending heartbeat", Connection.this, factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds()); write(HEARTBEAT_CALLBACK); } }
public void changeTheHost(Host theNewHost) { this.theHost = theNewHost; cluster.getConfiguration().getPoolingOptions().refreshConnectedHosts(); }
public static int numberOfLocalCoreConnections(Cluster cluster) { Configuration configuration = cluster.getConfiguration(); return configuration.getPoolingOptions().getCoreConnectionsPerHost(HostDistance.LOCAL); }
private void updateChosenHosts() { if (chosenHosts.size() > maxHosts - threshold || liveHosts.size() == 0) return; // We lock to prevent two events from triggering this simultaneously. updateLock.lock(); try { int missing = maxHosts - chosenHosts.size(); if (missing < threshold || liveHosts.size() == 0) return; Set<Host> newlyChosen = new HashSet<Host>(); for (Host host : liveHosts) { // Note that this picks hosts whatever their distance is. // We can't reliably call childPolicy.distance() here, because the childPolicy // might require hosts to be already added to compute their distance properly // (this is the case for DCAware policy). newlyChosen.add(host); missing -= 1; if (missing == 0) break; } chosenHosts.addAll(newlyChosen); liveHosts.removeAll(newlyChosen); for (Host host : newlyChosen) { delegate.onAdd(host); // delegate should have updated the distance, inform the driver so that it can // recreate the pool. cluster.getConfiguration().getPoolingOptions().refreshConnectedHost(host); } } finally { updateLock.unlock(); } }
scheduleExecution(speculativeExecutionPlan.nextExecution(host)); PoolingOptions poolingOptions = manager.configuration().getPoolingOptions(); ListenableFuture<Connection> connectionFuture = pool.borrowConnection(
factory.manager.configuration.getPoolingOptions().getInitializationExecutor());
Assert.assertEquals(configuration.getSocketOptions().getTcpNoDelay().booleanValue(), true); Assert.assertEquals(configuration.getPoolingOptions().getCoreConnectionsPerHost(distance), 5); Assert.assertEquals(configuration.getPoolingOptions().getMaxConnectionsPerHost(distance), 12); Assert.assertEquals(configuration.getPoolingOptions() .getMaxRequestsPerConnection(distance), 128); Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(), TAP);
Assert.assertEquals(configuration.getSocketOptions().getTcpNoDelay().booleanValue(), true); Assert.assertEquals(configuration.getPoolingOptions().getCoreConnectionsPerHost(distance), 5); Assert.assertEquals(configuration.getPoolingOptions().getMaxConnectionsPerHost(distance), 12); Assert.assertEquals(configuration.getPoolingOptions() .getMaxRequestsPerConnection(distance), 128); Assert.assertEquals(configuration.getPolicies().getLoadBalancingPolicy().getClass().getName(),
Assert.assertEquals(configuration.getSocketOptions().getTcpNoDelay().booleanValue(), true); Assert.assertEquals(configuration.getPoolingOptions().getCoreConnectionsPerHost(distance), 5); Assert.assertEquals(configuration.getPoolingOptions().getMaxConnectionsPerHost(distance), 12); Assert.assertEquals(configuration.getPoolingOptions() .getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getSocketOptions().getTcpNoDelay().booleanValue(), true); Assert.assertEquals(configuration.getPoolingOptions().getCoreConnectionsPerHost(distance), 5); Assert.assertEquals(configuration.getPoolingOptions().getMaxConnectionsPerHost(distance), 12); Assert.assertEquals(configuration.getPoolingOptions() .getMaxRequestsPerConnection(distance), 128);
Assert.assertEquals(configuration.getSocketOptions().getTcpNoDelay().booleanValue(), true); Assert.assertEquals(configuration.getPoolingOptions().getCoreConnectionsPerHost(distance), 5); Assert.assertEquals(configuration.getPoolingOptions().getMaxConnectionsPerHost(distance), 12); Assert.assertEquals(configuration.getPoolingOptions() .getMaxRequestsPerConnection(distance), 128);
/** * Copy constructor. * * @param toCopy the object to copy from. */ protected Configuration(Configuration toCopy) { this( toCopy.getPolicies(), toCopy.getProtocolOptions(), toCopy.getPoolingOptions(), toCopy.getSocketOptions(), toCopy.getMetricsOptions(), toCopy.getQueryOptions(), toCopy.getThreadingOptions(), toCopy.getNettyOptions(), toCopy.getCodecRegistry()); }
cluster() .getConfiguration() .getPoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequests);
private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) { cluster .getConfiguration() .getPoolingOptions() .setNewConnectionThreshold(HostDistance.LOCAL, 100) .setMaxRequestsPerConnection(HostDistance.LOCAL, 128) .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); Session session = cluster.connect(); Host host = TestUtils.findHost(cluster, 1); // Replace the existing pool with a spy pool and return it. SessionManager sm = ((SessionManager) session); return sm.pools.get(host); }
.getPoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, 100); int maxQueueSize = 256;
.build(); cluster.getConfiguration().getPoolingOptions().setPoolTimeoutMillis(500); try { Session session = cluster.connect();