From bbddca6a76bac41ccd5fe142bc198fa7d42fa1ed Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Wed, 6 Dec 2023 15:55:51 +0100 Subject: [PATCH] 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