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 TimeConsistency class. This class requires the following information:

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

from nosqldb import Factory
from nosqldb import StoreConfig
from nosqldb import TimeConsistency

## Required for TimeConsistency
from nosqldb import ONDB_PERMISSIBLE_LAG
from nosqldb import ONDB_TIMEOUT

...

# locations where our store and proxy can be found
kvlite = 'localhost:5000'
proxy = 'localhost:7010'

...

# configure and open the store
def open_store():
    tc = TimeConsistency({ONDB_PERMISSIBLE_LAG : 2000,
                          ONDB_TIMEOUT : 4000})

    kvstoreconfig = StoreConfig('kvstore', [kvlite])
    kvstoreconfig.set_consistency(tc)

    return Factory.open(proxy, kvstoreconfig)

...