Customizing calls

elandau edited this page Nov 29, 2012 · 3 revisions
Clone this wiki locally


Settings a different consistency level for each call

OperationResult<Void> result =
  .getKey("Key1").copyTo(CF_STANDARD2, "Key2")

Retry policy

Astyanax distinguishes between failover and retry.  Failover is invoked within the context of selecting a connection from the connection pool or failing over if the connection is terminated or times out.  Retry operates on top of the connection pool failover and retries the entire operation with a new failover context.  Retry is useful when you want to retry after all lower level connection pool failovers have been exhausted.  Retry implements backoff whereas failover in the connection pool waits for connections to be available.  Use a retry policy when you want your app to be more resilient when there are lots of timeouts from cassandra, the connection pool is overwhelmed with requests of if there is a temporary cassandra outage. A retry policy may be added to a query or a mutation immediately after preparing the query or mutation object by calling withRetryPolicy. Astyanax provides the following retry policies: RunOnce (this is the default), RetryNTimes (no backoff), ConstantBackoff, ExponentialBackoff, BoundedExponentialBackoff.

ColumnList<String> result = keyspace.prepareQuery(CF_STANDARD1)
    .withRetryPolicy(new ExponentialBackoff(250, 5))
if (!result.isEmpty()) {