com.datastax.driver.core.policies.RetryPolicy Java Examples

The following examples show how to use com.datastax.driver.core.policies.RetryPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatastaxMetricModule.java    From heroic with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public DatastaxMetricModule(
    @JsonProperty("id") Optional<String> id,
    @JsonProperty("groups") Optional<Groups> groups,
    @JsonProperty("seeds") Optional<Set<String>> seeds,
    @JsonProperty("schema") Optional<SchemaModule> schema,
    @JsonProperty("configure") Optional<Boolean> configure,
    @JsonProperty("fetchSize") Optional<Integer> fetchSize,
    @JsonProperty("readTimeout") Optional<Duration> readTimeout,
    @JsonProperty("consistencyLevel") Optional<ConsistencyLevel> consistencyLevel,
    @JsonProperty("retryPolicy") Optional<RetryPolicy> retryPolicy,
    @JsonProperty("authentication") Optional<DatastaxAuthentication> authentication,
    @JsonProperty("poolingOptions") Optional<DatastaxPoolingOptions> poolingOptions
) {
    this.id = id;
    this.groups = groups.orElseGet(Groups::empty).or("heroic");
    this.seeds = convert(seeds.orElse(DEFAULT_SEEDS));
    this.schema = schema.orElseGet(NextGenSchemaModule.builder()::build);
    this.configure = configure.orElse(DEFAULT_CONFIGURE);
    this.fetchSize = fetchSize.orElse(DEFAULT_FETCH_SIZE);
    this.readTimeout = readTimeout.orElse(DEFAULT_READ_TIMEOUT);
    this.consistencyLevel = consistencyLevel.orElse(ConsistencyLevel.ONE);
    this.retryPolicy = retryPolicy.orElse(DefaultRetryPolicy.INSTANCE);
    this.authentication = authentication.orElseGet(DatastaxAuthentication.None::new);
    this.poolingOptions = poolingOptions.orElseGet(DatastaxPoolingOptions::new);
}
 
Example #2
Source File: ManagedSetupConnection.java    From heroic with Apache License 2.0 6 votes vote down vote up
@java.beans.ConstructorProperties({ "async", "seeds", "schema", "configure", "fetchSize",
                                    "readTimeout", "consistencyLevel", "retryPolicy",
                                    "authentication", "poolingOptions" })
public ManagedSetupConnection(final AsyncFramework async,
                              final Collection<InetSocketAddress> seeds,
                              final Schema schema,
                              final boolean configure,
                              final int fetchSize,
                              final Duration readTimeout,
                              final ConsistencyLevel consistencyLevel,
                              final RetryPolicy retryPolicy,
                              final DatastaxAuthentication authentication,
                              final DatastaxPoolingOptions poolingOptions) {
    this.async = async;
    this.seeds = seeds;
    this.schema = schema;
    this.configure = configure;
    this.fetchSize = fetchSize;
    this.readTimeout = readTimeout;
    this.consistencyLevel = consistencyLevel;
    this.retryPolicy = retryPolicy;
    this.authentication = authentication;
    this.poolingOptions = poolingOptions;
}
 
Example #3
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void firstTimeRetryOnUnavailable_shouldRetry() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );
    RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 0);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.ONE);
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #4
Source File: CqlSession.java    From ob1k with Apache License 2.0 5 votes vote down vote up
public CqlSession(final String nodes, final int port, final String keyspace, final SocketOptions socketOptions,
                  final RetryPolicy retryPolicy, final QueryOptions queryOptions,
                  final LoadBalancingPolicy loadBalancingPolicy, final int maxConnectionsPerHost,
                  final MetricFactory metricFactory) {

  // this is temp. to reuse current hosts properties:
  final Iterable<String> nodesIter = Splitter.on(",").split(nodes);
  final String[] nodesArr = Iterables.toArray(
    StreamSupport.stream(nodesIter.spliterator(), false).map(input -> {
    if (input == null) return null;

    final int idx = input.lastIndexOf(":");
    return input.substring(0, idx);
  }).collect(Collectors.toList()), String.class);


  /*PoolingOptions poolingOptions = new PoolingOptions();
  poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionsPerHost);
  poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionsPerHost);*/


  final Cluster cluster = Cluster.builder().
          withPort(port).
          withSocketOptions(socketOptions).
          withQueryOptions(queryOptions).
          withLoadBalancingPolicy(loadBalancingPolicy).
          //  withPoolingOptions(poolingOptions).
                  addContactPoints(nodesArr).build();
  //cluster.init();
  this.session = cluster.connect(keyspace);
  this.retryPolicy = Preconditions.checkNotNull(retryPolicy);
  this.metricFactory = Preconditions.checkNotNull(metricFactory);
}
 
Example #5
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void firstTimeRetryOnReadTimeout_shouldRetry() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );
    RetryPolicy.RetryDecision retryResult = retryPolicy.onReadTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, false, 0);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE);
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #6
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void maxTimeRetryOnReadTimeout_shouldRethrow() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );

    RetryPolicy.RetryDecision retryResult = retryPolicy.onReadTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, false, 3);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow();
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #7
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );
    RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE);
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #8
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void maxTimeRetryOnWriteTimeout_shouldRethrow() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );

    RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 3);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow();
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #9
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void maxTimeRetryOnUnavailable_shouldRethrow() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );

    RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 3);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow();
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #10
Source File: CassandraProfile.java    From heroic with Apache License 2.0 5 votes vote down vote up
private RetryPolicy convertRetryPolicy(final String policyName, final ExtraParameters params) {
    if ("aggressive".equals(policyName)) {
        final int numRetries = params.getInteger("numRetries").orElse(DEFAULT_NUM_RETRIES);
        final int rotateHost = params.getInteger("rotateHost").orElse(DEFAULT_ROTATE_HOST);
        return new AggressiveRetryPolicy(numRetries, rotateHost);
    }

    throw new IllegalArgumentException("Not a valid retry policy: " + policyName);
}
 
Example #11
Source File: CassandraPreparedBuilder.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public PreparedStatement prepare(Session session, String query, ConsistencyLevel consistency, RetryPolicy retryPolicy) {
   PreparedStatement result = cache.get(query);
   if (result != null && result.getConsistencyLevel() == consistency) {
      return result;
   }

   PreparedStatement newPrepared = StandardPreparedStatementFactory.INSTANCE.prepare(session,query,consistency, retryPolicy);
   PreparedStatement existingPrepared = cache.putIfAbsent(query,newPrepared);
   return (existingPrepared != null) ? existingPrepared : newPrepared;
}
 
Example #12
Source File: CassandraPreparedBuilder.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public PreparedStatement prepare(Session session, String query, ConsistencyLevel consistency, RetryPolicy retryPolicy) {
   PreparedStatement ps = session.prepare(query);
   ps.setConsistencyLevel(consistency);
   if(retryPolicy != null) {
      ps.setRetryPolicy(retryPolicy);
   }
   return ps;
}
 
Example #13
Source File: CassandraStorage.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
private void prepare(String cql, RetryPolicy petryPolicy) {
    logger.info("Preparing cql stmt {}", cql);
    PreparedStatement pstmt = session.prepare(cql);
    pstmt.setConsistencyLevel(consistencyLevel);
    pstmt.setRetryPolicy(petryPolicy);
    pstmt.setIdempotent(true);
    preparedStatements.put(cql, pstmt);
}
 
Example #14
Source File: LoggingRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return new LoggingRetryPolicy(subPolicy.build());
}
 
Example #15
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 4 votes vote down vote up
private void assertRetryDecisionEquals(RetryPolicy.RetryDecision expected, RetryPolicy.RetryDecision result) {
    assertEquals("first time retry type", expected.getType(), result.getType());
    assertEquals("first time retry consistency level", expected.getRetryConsistencyLevel(), result.getRetryConsistencyLevel());
    assertEquals("first time retry current", expected.isRetryCurrent(), result.isRetryCurrent());
}
 
Example #16
Source File: CassandraClusterConfig.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public void setRetryPolicy(RetryPolicy retryPolicy) {
	this.retryPolicy = retryPolicy;
}
 
Example #17
Source File: CassandraClusterConfig.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public RetryPolicy getRetryPolicy() {
	return retryPolicy;
}
 
Example #18
Source File: RetryPolicyWithMetrics.java    From ob1k with Apache License 2.0 4 votes vote down vote up
RetryPolicyWithMetrics(final RetryPolicy delegate, final List<TagMetrics> tagMetrics) {
  this.delegate = Preconditions.checkNotNull(delegate);
  this.tagMetrics = Preconditions.checkNotNull(tagMetrics);
}
 
Example #19
Source File: DefaultRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return DefaultRetryPolicy.INSTANCE;
}
 
Example #20
Source File: FallthroughRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return FallthroughRetryPolicy.INSTANCE;
}
 
Example #21
Source File: CassandraQueryBuilder.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public B withRetryPolicy(RetryPolicy retryPolicy) {
   this.retryPolicy = retryPolicy;
   return ths();
}
 
Example #22
Source File: DowngradingConsistencyRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return DowngradingConsistencyRetryPolicy.INSTANCE;
}
 
Example #23
Source File: CassandraConfig.java    From realtime-analytics with GNU General Public License v2.0 4 votes vote down vote up
public void setRetryPolicy(RetryPolicy retryPolicy) {
    this.retryPolicy = retryPolicy;
}
 
Example #24
Source File: CassandraConfig.java    From realtime-analytics with GNU General Public License v2.0 4 votes vote down vote up
public RetryPolicy getRetryPolicy() {
    return retryPolicy;
}
 
Example #25
Source File: WrappedPreparedStatement.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public RetryPolicy getRetryPolicy() {
    return st.getRetryPolicy();
}
 
Example #26
Source File: WrappedPreparedStatement.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public PreparedStatement setRetryPolicy(RetryPolicy policy) {
    return st.setRetryPolicy(policy);
}
 
Example #27
Source File: DataSource.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Sets retry policy.
 *
 * @param plc Retry policy.
 */
public void setRetryPolicy(RetryPolicy plc) {
    retryPlc = plc;

    invalidate();
}
 
Example #28
Source File: ConnectionStateManager.java    From attic-apex-malhar with Apache License 2.0 2 votes vote down vote up
/**
 * Used to specify how queries will need to be retried in case the current in progress one fails.
 * The default is to use a DowngradingConsistency Policy i.e. first LOCAL_QUORUM is attempted and if
 * there is a failure because less than RF/2-1 nodes are alive, it automatically switches to the Consistency Level
 * of LOCAL_ONE and so on. ( and hope that hint windows take care of the rest when the nodes come back up )
 * @param retryPolicy
 * @return The builder instance as initially created updated with this value
   */
public ConnectionBuilder withRetryPolicy(RetryPolicy retryPolicy)
{
  this.retryPolicy = retryPolicy;
  return this;
}
 
Example #29
Source File: RetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 votes vote down vote up
RetryPolicy build(); 
Example #30
Source File: CassandraPreparedBuilder.java    From arcusplatform with Apache License 2.0 votes vote down vote up
PreparedStatement prepare(Session session, String query, ConsistencyLevel consistency, RetryPolicy retryPolicy);