patroni.git / summary / log / commit / refs

commit    bbddca6a76bac41ccd5fe142bc198fa7d42fa1ed
Author:   Alexander Kukushkin <cyberdemn@gmail.com>
Commit:   GitHub <noreply@github.com>
Date:     Wed Dec 06 14:55:51 2023 +0000

    Use consistent read when fetching just updated sync key (#2974)
    
    Consul doesn't provide any interface to immediately get `ModifyIndex` for the key that we just updated, therefore we have to perform an explicit read operation. By default stale reads are allowed and sometimes we may read stale data. As a result write_sync_state() call was considered as failed. To mitigate the problem we switch to `consistent` reads when that executed after update of the `/sync` key.
    
    Close #2972


patroni/dcs/consul.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patroni/dcs/consul.py b/patroni/dcs/consul.py index 27cab778..fe66c6d8 100644 --- a/patroni/dcs/consul.py +++ b/patroni/dcs/consul.py @@ -666,7 +666,7 @@ class Consul(AbstractDCS): if ret: # We have no other choise, only read after write :( if not retry.ensure_deadline(0.5): return False - _, ret = self.retry(self._client.kv.get, self.sync_path) + _, ret = self.retry(self._client.kv.get, self.sync_path, consistency='consistent') if ret and (ret.get('Value') or b'').decode('utf-8') == value: return ret['ModifyIndex'] return False [parent: a4e0a2220dd8]