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:
ONDB_PERMISSIBLE_LAG
The number of milliseconds the replica is allowed to lag behind the master.
ONDB_TIMEOUT
The number of milliseconds
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.
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) ...