# How to set read.consistency\_level in python aerospike client?

**URL:** <https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762>\
**Category:** Python Client\
**Created:** [December 16, 2014, 12:51pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762 "2014-12-16T12:51:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tombo](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tombo](https://discuss.aerospike.com/u/tombo)\
**Post date:** [December 16, 2014, 12:51pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/1 "2014-12-16T12:51:23Z")

</div>

Hi Is there a way to set “read.consistency\_level=all” in python client in connection or in transaction ?

Is there anothers setting to force “read.consistency\_level=all” only if cluster is replicating/synchronizing partition ?

– Kind Regards Marek Grzybowski

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [December 17, 2014, 7:56pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/2 "2014-12-17T19:56:48Z")

</div>

We are working on exposing those policies for the underlying C-client in one of the next releases (depending on which branches get into master first). It’s close.

Ronen

---

<div class="post-metadata">

**Author:** ![tombo](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tombo](https://discuss.aerospike.com/u/tombo)\
**Post date:** [December 18, 2014, 4:37pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/3 "2014-12-18T16:37:27Z")

</div>

Excellent, this feature seems to be very important. Current default aerospike settings (write.commit\_level=all, read.consistency\_level=one) means that if some ssd storage node is back from downtime, it will return old values from ssd for all master records belonging to node. If You have counters on aerospike, and You increment them frequently, every aeorospike node restart means data loss. AFIK only way to awoid this beahevior is to setup global read.consistency\_level=all, or every time node is down wipe ssd disks. Or maybe there is another way ?

PS: We wrote some nagios plugins, to test our aerospike cluster: [GitHub - RTBHOUSE/check\_aerospike\_put\_get: Nagios plugin that gets and put data to aerospike to assess potential data loss after node failures.](https://github.com/RTBHOUSE/check_aerospike_put_get)[GitHub - RTBHOUSE/check\_naglio\_aerospike: Nagios plugins that parse output from aerospike tools.](https://github.com/RTBHOUSE/check_naglio_aerospike)

---

<div class="post-metadata">

**Author:** ![Mnemaudsyne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/mnemaudsyne/32/200_2.png) [@Mnemaudsyne](https://discuss.aerospike.com/u/Mnemaudsyne)\
**Post date:** [December 23, 2014, 9:56pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/4 "2014-12-23T21:56:56Z")

</div>

Hi Marek,

Thank you for your follow-up post. We are looking into your issue and will get back to you soon. Thank you for your patience.

Regards,

Maud

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [December 27, 2014, 12:26am UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/5 "2014-12-27T00:26:46Z")

</div>

Hi Marek,

If a node is recovering from being partitioned an automatic process will resolve write duplicates by assuming the copy with the most recent timestamp is the canonical one - unless you overwrote the config parameter _write-duplicate-resolution-disable_ to _true_. If the client sends a write to the wrong node during cluster reconfiguration because its not yet in sync about the new owner of the record the cluster will proxy the write to the correct node.

Both situations are rare and handled by the cluster.

See more here: [http://www.aerospike.com/docs/architecture/data-distribution.html](http://www.aerospike.com/docs/architecture/data-distribution.html) and [http://www.aerospike.com/docs/reference/configuration/#write-duplicate-resolution-disable](http://www.aerospike.com/docs/reference/configuration/#write-duplicate-resolution-disable)

---

<div class="post-metadata">

**Author:** ![tombo](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tombo](https://discuss.aerospike.com/u/tombo)\
**Post date:** [December 27, 2014, 3:32pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/6 "2014-12-27T15:32:22Z")

</div>

Hi Ronen Steps to reproduce my tests on clear three node cluster ( i currently do not have spare ssd servers, so i used containers and file backstore instead, result is the same ) :

```
ii aerospike-server-community 3.4.0-1 The Aerospike distributed datastore allows fully scalable and reliable data storage with elastic server properties.
ii aerospike-tools 3.4.0 Aerospike server tools.

```

aerospike.conf:

```
namespace test {
        replication-factor 2
        memory-size 2G
        default-ttl 30d # 30 days, use 0 to never expire/evict.

        storage-engine memory

        storage-engine device {
                file /opt/aerospike/data/test.dat
                filesize 16G
                data-in-memory true # Store data in memory in addition to file.
        }
}

```

- start clear cluster with namespace “test” that have persistant storage ( file or SSD )

- check config ( to make sure “write-duplicate-resolution-disable” is not enabled ):

- put some several key-values to the cluster:

- increment values ( get , increment, put )

- down single cluster node ( you can wait since cluster finish migrate all partition, but it does not mather )

- increment values in loop

- start node that were down in time when You icrement values

In my test two values are different than others.

There is time window when python client reads old values from node that is getting up. The more data in partitions, the longer time window when client reads old records. Writes/puts are always go in the right place, rekord generation is the same for all values.

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [December 29, 2014, 9:58pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/7 "2014-12-29T21:58:39Z")

</div>

I’ll look to recreate the problem using your code. Thanks.

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [January 13, 2015, 9:47pm UTC](https://discuss.aerospike.com/t/how-to-set-read-consistency-level-in-python-aerospike-client/762/8 "2015-01-13T21:47:46Z")

</div>

I will get back to reproducing your problem. Sorry about the delay.

First, though, I wanted to point out that the read consistency level and read replica policies can be controlled by passing a policy with the get() method, as seen in [test/test\_get.py](https://github.com/citrusleaf/aerospike-client-python/blob/master/test/test_get.py).

- The policy field ‘consistency’ can take on the values aerospike.POLICY\_CONSISTENCY\_ONE (default) or aerospike.POLICY\_CONSISTENCY\_ALL.
- The ‘replica’ field can take on the values aerospike.POLICY\_REPLICA\_MASTER (default) or aerospike.POLICY\_REPLICA\_ANY.

The write commit level policy can be controlled by passing a policy containing it to the put() method, as seen in [test/test\_put.py](https://github.com/citrusleaf/aerospike-client-python/blob/master/test/test_put.py#L554).

- The policy field ‘commit\_level’ can take on the values aerospike.POLICY\_COMMIT\_LEVEL\_ALL (default) or aerospike.POLICY\_COMMIT\_LEVEL\_MASTER.
