Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.1
Community Wiki and Resources
Download Client Library
JavaDoc
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
Java Client Library
SDK Forum
Wiki: Java Client Library
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
6 Store Operations
Chapter Sections
Chapters

6.3. Store Operations with Durability Requirements

API Callclient.set(key, expiry, value, persistto)
Asynchronousyes
Description Store a value using the specified key and observe it being persisted on master and more node(s).
ReturnsOperationFuture<Boolean> ( Asynchronous request value, as Boolean )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Object value Value to be stored
enum persistto Specify the number of nodes on which the document must be persisted to before returning.
API Callclient.set(key, expiry, value, replicateto)
Asynchronousyes
Description Store a value using the specified key and observe it being replicated to one or more node(s).
ReturnsOperationFuture<Boolean> ( Asynchronous request value, as Boolean )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Object value Value to be stored
enum replicateto Specify the number of nodes on which the document must be replicated to before returning
API Callclient.set(key, expiry, value, persistto, replicateto)
Asynchronousyes
Description Store a value using the specified key and observe it being persisted on master and more node(s) and being replicated to one or more node(s).
ReturnsOperationFuture<Boolean> ( Asynchronous request value, as Boolean )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Object value Value to be stored
enum persistto Specify the number of nodes on which the document must be persisted to before returning.
enum replicateto Specify the number of nodes on which the document must be replicated to before returning

This method is identical to the set() method, but supports the ability to observe the persistence on the master and replicas and the propagation to the replicas. Using these methods above, it's possible to set the persistence requirements for the data on the nodes.

The persistence requirements can be specified in terms of how the data should be persisted on the master and the replicas using PeristTo and how the data should be propagated to the replicas using ReplicateTo respectively.

The client library will poll the server until the persistence requirements are met. The method will return FALSE if the requirments are impossible to meet based on the configuration (inadequate number of replicas) or even after a set amount of retries the persistence requirments could not be met.

The program snippet below illustrates how to specify a requirement that the data should be persisted on 4 nodes (master and three replicas).

// Perist to all four nodes including master
OperationFuture<Boolean> setOp =
   c.set("key", 0, "value", PersistTo.FOUR);
System.out.printf("Result was %b", setOp.get());

The peristence requirements can be specified for both the master and replicas. In the case above, it's required that the key and value is persisted on all the 4 nodes (including replicas).

In the following, the requirement is specified as requiring persistence to the master and propagation of the data to the three replicas. This requirment is weaker than requring the data to be persisted on all four nodes including the three replicas.

// Perist to master and propagate the data to three replicas
OperationFuture<Boolean> setOp =
   c.set("key", 0, "value", PersistTo.MASTER, ReplicateTo.THREE);
System.out.printf("Result was %b", setOp.get());

Similar requirements can used with the add() and replace() mutation operations.