WritePolicy Class

Container object for policy attributes used in write operations. This object is passed into methods where database writes can occur.
Inheritance Hierarchy


Namespace:  Aerospike.Client
Assembly:  AerospikeClient (in AerospikeClient.dll) Version: (5.1.1)

public sealed class WritePolicy : Policy

The WritePolicy type exposes the following members.


Public methodWritePolicy
Default constructor.
Public methodWritePolicy(Policy)
Copy write policy from another policy.
Public methodWritePolicy(WritePolicy)
Copy write policy from another write policy.

Public methodSetTimeout
Create a single timeout by setting socketTimeout and totalTimeout to the same value.
(Inherited from Policy.)
Public methodSetTimeouts
Set socketTimeout and totalTimeout. If totalTimeout defined and socketTimeout greater than totalTimeout, set socketTimeout to totalTimeout.
(Inherited from Policy.)

Public fieldcommitLevel
Desired consistency guarantee when committing a transaction on the server. The default (COMMIT_ALL) indicates that the server should wait for master and all replica commits to be successful before returning success to the client.

Default: CommitLevel.COMMIT_ALL

Public fieldcompress
Use zlib compression on command buffers sent to the server and responses received from the server when the buffer size is greater than 128 bytes.

This option will increase cpu and memory usage (for extra compressed buffers), but decrease the size of data sent over the network.

Default: false

(Inherited from Policy.)
Public fielddurableDelete
If the transaction results in a record deletion, leave a tombstone for the record. This prevents deleted records from reappearing after node failures. Valid for Aerospike Server Enterprise Edition 3.10+ only.

Default: false (do not tombstone deleted records).

Public fieldexpiration
Record expiration. Also known as ttl (time to live). Seconds record will live before being removed by the server.

Expiration values:

  • -2: Do not change ttl when record is updated. Supported by Aerospike server versions >= 3.10.1.
  • -1: Never expire. Supported by Aerospike server versions >= 3.1.4.
  • 0: Default to namespace's "default-ttl" on the server.
  • > 0: Actual ttl in seconds.

Default: 0

Public fieldfailOnFilteredOut
Throw exception if filterExp is defined and that filter evaluates to false (transaction ignored). The AerospikeException will contain result code .

This field is not applicable to batch, scan or query commands.

Default: false

(Inherited from Policy.)
Public fieldCode examplefilterExp
Optional expression filter. If filterExp exists and evaluates to false, the transaction is ignored.

Default: null

(Inherited from Policy.)
Public fieldgeneration
Expected generation. Generation is the number of times a record has been modified (including creation) on the server. If a write operation is creating a record, the expected generation would be 0. This field is only relevant when generationPolicy is not NONE.

The server does not support this field for UDF Execute() calls. The read-modify-write usage model can still be enforced inside the UDF code itself.

Default: 0

Public fieldgenerationPolicy
Qualify how to handle record writes based on record generation. The default (NONE) indicates that the generation is not used to restrict writes.

The server does not support this field for UDF Execute() calls. The read-modify-write usage model can still be enforced inside the UDF code itself.

Default: GenerationPolicy.NONE

Public fieldmaxRetries
Maximum number of retries before aborting the current transaction. The initial attempt is not counted as a retry.

If maxRetries is exceeded, the transaction will abort with AerospikeExceptionTimeout.

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 for read: 2 (initial attempt + 2 retries = 3 attempts)

Default for write: 0 (no retries)

Default for partition scan or query with null filter: 5 (6 attempts. See ScanPolicy comments.)

No default for legacy scan/query. No retries are allowed for these commands.

(Inherited from Policy.)
Public fieldreadModeAP
Read policy for AP (availability) namespaces.

Default: ONE

(Inherited from Policy.)
Public fieldreadModeSC
Read policy for SC (strong consistency) namespaces.

Default: SESSION

(Inherited from Policy.)
Public fieldrecordExistsAction
Qualify how to handle writes where the record already exists.

Default: RecordExistsAction.UPDATE

Public fieldrecordParser
Alternate record parser.

Default: Use standard record parser.

(Inherited from Policy.)
Public fieldreplica
Replica algorithm used to determine the target node for a single record command. Scan and query are not affected by replica algorithms.


(Inherited from Policy.)
Public fieldrespondAllOps
For client operate(), return a result for every operation.

Some operations do not return results by default (ListOperation.clear() for example). This can make it difficult to determine the desired result offset in the returned bin's result list.

Setting respondAllOps to true makes it easier to identify the desired result offset (result offset equals bin's operate sequence). If there is a map operation in operate(), respondAllOps will be forced to true for that operate() call.

Default: false

Public fieldsendKey
Send user defined key in addition to hash digest on both reads and writes. If the key is sent on a write, the key will be stored with the record on the server.

Default: false (do not send the user defined key)

(Inherited from Policy.)
Public fieldsleepBetweenRetries
Milliseconds to sleep between retries. Enter zero to skip sleep. This field is ignored when maxRetries is zero. This field is also ignored in async mode.

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.

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.

The default for writes is also zero because writes are not retried by default. 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. If maxRetries is greater than zero on a write, then sleepBetweenRetries should be set high enough to allow the cluster to reform (>= 3000ms).

Default: 0 (do not sleep between retries)

(Inherited from Policy.)
Public fieldsocketTimeout
Socket idle timeout in milliseconds when processing a database command.

If socketTimeout is zero and totalTimeout is non-zero, then socketTimeout will be set to totalTimeout. If both socketTimeout and totalTimeout are non-zero and socketTimeout > totalTimeout, then socketTimeout will be set to totalTimeout. If both socketTimeout and totalTimeout are zero, then there will be no socket idle limit.

If socketTimeout is not zero and the socket has been idle for at least socketTimeout, both maxRetries and totalTimeout are checked. If maxRetries and totalTimeout are not exceeded, the transaction is retried.

For synchronous methods, socketTimeout is the socket SendTimeout and ReceiveTimeout. For asynchronous methods, the socketTimeout is implemented using the AsyncTimeoutQueue and socketTimeout is only used if totalTimeout is not defined.

Default: 30000ms

(Inherited from Policy.)
Public fieldtotalTimeout
Total transaction timeout in milliseconds.

The totalTimeout is tracked on the client and sent to the server along with the transaction in the wire protocol. The client will most likely timeout first, but the server also has the capability to timeout the transaction.

If totalTimeout is not zero and totalTimeout is reached before the transaction completes, the transaction will abort with AerospikeExceptionTimeout.

If totalTimeout is zero, there will be no total time limit.

Default: 0 (no time limit)

(Inherited from Policy.)
See Also