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. 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:

  • permissibleLag

    A long that describes the number of TimeUnits the replica is allowed to lag behind the master.

  • permissibleLagUnits

    A TimeUnit that identifies the units used by permissibleLag. For example: TimeUnit.MILLISECONDS.

  • timeout

    A long that describes how long the replica is permitted to wait in an attempt to meet the permissible lag limit. That is, if the replica cannot immediately meet the permissible lag requirement, then it will wait this amount of time to see if it is updated with the required data from the master. If the replica cannot meet the permissible lag requirement within the timeout period, a ConsistencyException is thrown.

  • timeoutUnit

    A TimeUnit that identifies the units used by timeout. For example: TimeUnit.SECONDS.

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);