Using Time-Based Consistency

A time-based consistency policy describes the amount of time that a replica node is allowed to lag behind the master node. These type of consistency policies matter only for read operations, because replica nodes can only service read operations.

When servicing a read operation, if the replica's data is more than the specified amount of time out-of-date relative to the master, then a ConsistencyException is thrown. In that event, you can either abandon the operation, retry it immediately, or pause and then retry it.

In order for this type of a consistency policy to be effective, the clocks on all the nodes in the store must be synchronized using a protocol such as NTP.

In order to specify a time-based consistency policy, you use the Consistency.Time class. The constructor for this class requires the following information:

The following sets a default time-based consistency policy of 2 seconds. The timeout is 4 seconds.

package kvstore.basicExample;

import oracle.kv.Consistency;
import oracle.kv.KVStore;
import oracle.kv.KVStoreConfig;
import oracle.kv.KVStoreFactory;

import java.util.concurrent.TimeUnit;

...

KVStoreConfig kconfig = new KVStoreConfig("exampleStore", 
    "node1.example.org:5088, node2.example.org:4129");

Consistency.Time cpolicy =  
        new Consistency.Time(2, TimeUnit.SECONDS,
                             4, TimeUnit.SECONDS);
kconfig.setConsistency(cpolicy);

KVStore kvstore = KVStoreFactory.getStore(kconfig);