From 7fa431dbc9d7c44d79fcd1fd5e9513313219ad7c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 11 May 2018 11:53:45 -0400 Subject: [PATCH] Persist the transactioncount Needed for eventually ascertaining the viability in selecting leader. --- confluent_server/confluent/config/configmanager.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index 7d5fea93..4b34151d 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -446,7 +446,7 @@ def add_collective_member(name, address, fingerprint): ConfigManager._bg_sync_to_file() def list_collective(): - return iter(_cfgstore['collective']) + return iter(_cfgstore.get('collective', ())) def get_collective_member(name): return _cfgstore['collective'][name] @@ -1651,8 +1651,14 @@ class ConfigManager(object): @classmethod def _read_from_path(cls): global _cfgstore + global _txcount _cfgstore = {} rootpath = cls._cfgdir + try: + with open(os.path.join(rootpath, 'transactioncount', 'r')) as f: + _txcount = struct.unpack('!Q', f.read())[0] + except IOError: + pass _load_dict_from_dbm(['collective'], os.path.join(rootpath, "collective")) _load_dict_from_dbm(['globals'], os.path.join(rootpath, "globals")) @@ -1697,6 +1703,8 @@ class ConfigManager(object): def _sync_to_file(cls): if statelessmode: return + with open(os.path.join(cls._cfgdir, 'transactioncount'), 'w') as f: + f.write(struct.pack('!Q', _txcount)) if 'dirtyglobals' in _cfgstore: with _dirtylock: dirtyglobals = copy.deepcopy(_cfgstore['dirtyglobals'])