@Override public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry) { return DefaultRetryPolicy.INSTANCE.onWriteTimeout(statement, cl, writeType, requiredAcks, receivedAcks, nbRetry); }
@Override public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) { return DefaultRetryPolicy.INSTANCE.onReadTimeout(statement, cl, requiredResponses, receivedResponses, dataRetrieved, nbRetry); }
@Override public RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry) { return RetryDecision.tryNextHost(cl); }
checkArgument(!contactPoints.isEmpty(), "empty contactPoints"); clusterBuilder.withPort(config.getNativeProtocolPort()); clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000)); clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy()); LoadBalancingPolicy loadPolicy = new RoundRobinPolicy(); DCAwareRoundRobinPolicy.Builder builder = DCAwareRoundRobinPolicy.builder() .withLocalDc(config.getDcAwareLocalDC()); if (config.getDcAwareUsedHostsPerRemoteDc() > 0) { builder.withUsedHostsPerRemoteDc(config.getDcAwareUsedHostsPerRemoteDc()); if (config.isDcAwareAllowRemoteDCsForLocal()) { builder.allowRemoteDCsForLocalConsistencyLevel(); loadPolicy = builder.build(); loadPolicy = new TokenAwarePolicy(loadPolicy, config.isTokenAwareShuffleReplicas()); whiteList.add(new InetSocketAddress(point, config.getNativeProtocolPort())); loadPolicy = new WhiteListPolicy(loadPolicy, whiteList); clusterBuilder.withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(
public LoadBalancingPolicy getLoadBalancingPolicy() { if (this.loadBalancingPolicyName.equals(TokenAwarePolicy.class.getSimpleName())) { return new TokenAwarePolicy(new RoundRobinPolicy()); } if (this.loadBalancingPolicyName.equals(DCAwareRoundRobinPolicy.class.getSimpleName())) { Builder builder = DCAwareRoundRobinPolicy.builder(); if (StringUtils.isNotBlank(datacenterName)) { builder = builder.withLocalDc(this.datacenterName); } return new TokenAwarePolicy(builder.build()); } throw new IllegalArgumentException("Unknown cassandra load balancing policy " + this.loadBalancingPolicyName); }
@Override public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry) { if (nbRetry == m_retryCount) return RetryDecision.rethrow(); else { m_unavailableRetries.incrementAndGet(); return RetryDecision.tryNextHost(cl); } }
private <T> T executeWithSession(SessionCallable<T> sessionCallable) { ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy(); ReconnectionSchedule schedule = reconnectionPolicy.newSchedule(); long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis(); while (true) { try { return sessionCallable.executeWithSession(session.get()); } catch (NoHostAvailableException e) { long timeLeft = deadline - System.currentTimeMillis(); if (timeLeft <= 0) { throw e; } else { long delay = Math.min(schedule.nextDelayMs(), timeLeft); log.warn(e.getCustomMessage(10, true, true)); log.warn("Reconnecting in %dms", delay); try { Thread.sleep(delay); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted", interrupted); } } } } }
@Override public RetryDecision onUnavailable(Statement statement, ConsistencyLevel consistencyLevel, int requiredReplica, int aliveReplica, int retries) { if (retries >= 10) { return RetryDecision.rethrow(); } try { int jitter = ThreadLocalRandom.current().nextInt(100); int delay = (100 * (retries + 1)) + jitter; Thread.sleep(delay); return RetryDecision.retry(consistencyLevel); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return RetryDecision.rethrow(); } }
@Override public HostDistance distance(Host host) { return m_writePolicy.distance(host); }
@Override public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { if (statement instanceof BatchStatement) { return m_writePolicy.newQueryPlan(loggedKeyspace, statement); } else { return m_queryPolicy.newQueryPlan(loggedKeyspace, statement); } }
public RetryPolicy getRetryPolicy() { if (this.retryPolicyName.equals(DowngradingConsistencyRetryPolicy.class.getSimpleName())) { return new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); } if (this.retryPolicyName.equals(FallthroughRetryPolicy.class.getSimpleName())) { return FallthroughRetryPolicy.INSTANCE; } if (this.retryPolicyName.equals(DefaultRetryPolicy.class.getSimpleName())) { return DefaultRetryPolicy.INSTANCE; } throw new IllegalArgumentException("Unknown cassandra retry policy " + this.retryPolicyName); }
@Override public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) { if (nbRetry == m_retryCount) return RetryDecision.rethrow(); else { int count = m_readRetries.incrementAndGet(); return RetryDecision.tryNextHost(cl); } }
@Override public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry) { if (nbRetry == m_retryCount) return RetryDecision.rethrow(); else { m_writeRetries.incrementAndGet(); return RetryDecision.tryNextHost(cl); } }
@Override public RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry) { if (nbRetry == m_retryCount) return RetryDecision.rethrow(); else { m_errorRetries.incrementAndGet(); return RetryDecision.tryNextHost(cl); } }