public class Policy extends Object
Modifier and Type | Field and Description |
---|---|
ConsistencyLevel |
consistencyLevel
How replicas should be consulted in a read operation to provide the desired
consistency guarantee.
|
int |
maxRetries
Maximum number of retries before aborting the current transaction.
|
Priority |
priority
Transaction policy attributes used in all database commands.
|
Replica |
replica
Replica algorithm used to determine the target node for a single record command.
|
boolean |
sendKey
Send user defined key in addition to hash digest on both reads and writes.
|
int |
sleepBetweenRetries
Milliseconds to sleep between retries.
|
int |
socketTimeout
Socket timeout for each transaction attempt in milliseconds.
|
int |
timeoutDelay
Delay milliseconds after transaction timeout before closing socket in async mode only.
|
int |
totalTimeout
Total transaction timeout in milliseconds.
|
Constructor and Description |
---|
Policy()
Default constructor.
|
Policy(Policy other)
Copy policy from another policy.
|
Modifier and Type | Method and Description |
---|---|
void |
setTimeout(int timeout)
Create a single timeout by setting socketTimeout and totalTimeout
to the same value.
|
void |
setTimeouts(int socketTimeout,
int totalTimeout)
Set socketTimeout and totalTimeout.
|
public Priority priority
public ConsistencyLevel consistencyLevel
Default: ConsistencyLevel.CONSISTENCY_ONE
public Replica replica
Default: Replica.SEQUENCE
public int socketTimeout
If socketTimeout is not zero and timeout is reached before an attempt completes, the totalTimeout is checked. If totalTimeout is not exceeded, the transaction is retried.
If both socketTimeout and totalTimeout are non-zero and socketTimeout > totalTimeout, then socketTimeout will be set to totalTimeout.
If socketTimeout is zero, there will be no time limit per attempt. If the transaction fails on a network error, totalTimeout still applies.
For synchronous methods, socketTimeout is the socket timeout. For asynchronous methods, the socketTimeout is implemented using a HashedWheelTimer.
Default: 0 (no time limit for each attempt).
public int totalTimeout
If totalTimeout is not zero and totalTimeout is reached before the transaction
completes, the transaction will abort with
AerospikeException.Timeout
.
If totalTimeout is zero, there will be no time limit and the transaction will retry
on network errors until maxRetries is exceeded. If maxRetries is exceeded, the
transaction also aborts with AerospikeException.Timeout
.
Default: 0 (no time limit and use maxRetries).
public int timeoutDelay
This field delays the closing of the socket to give the transaction more time to complete in the hope that the socket can be reused. This is helpful when timeouts are aggressive and a certain percentage of timeouts is expected.
The user is still notified of the timeout in async mode at the original timeout value. The transaction's async timer is then reset to this delay and the transaction is allowed to continue. If the transactions succeeds within the delay, then the socket is placed back on the pool and the transaction response is discarded. Otherwise, the socket must be closed.
This field is ignored in sync mode because control must be returned back to user on timeout and there is no currently available thread pool to process the delay.
Default: 0 (no delay, connection closed on timeout)
public int maxRetries
If totalTimeout is zero and maxRetries is exceeded, the abort will
occur with a AerospikeException.Timeout
.
if totalTimeout is not zero, maxRetries is ignored.
WARNING: Database writes that are not idempotent (such as add()) should not be retried because the write operation may be performed multiple times if the client timed out previous transaction attempts. It's important to use a distinct WritePolicy for non-idempotent writes which sets maxRetries = 0;
Default: 2 (initial attempt + 2 retries = 3 attempts)
public int sleepBetweenRetries
The sleep only occurs on connection errors and server timeouts which suggest a node is down and the cluster is reforming. The sleep does not occur when the client's socketTimeout expires.
This field is ignored in async mode.
Reads do not have to sleep when a node goes down because the cluster does not shut out reads during cluster reformation. The default for reads is zero.
Writes need to wait for the cluster to reform when a node goes down.
Immediate write retries on node failure have been shown to consistently
result in errors. The default for writes is 500ms. This default is
implemented in ClientPolicy.ClientPolicy()
)
public boolean sendKey
Default: false (do not send the user defined key)
public Policy(Policy other)
public Policy()
public void setTimeout(int timeout)
public void setTimeouts(int socketTimeout, int totalTimeout)
Copyright © 2012–2017 Aerospike, Inc. All rights reserved.