From aeb3bd2444ccc6c996557dc0b0753238a6b9287a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 29 Jun 2017 10:17:17 -0400 Subject: [PATCH] Add a stateless configmanager mode Certain embodiments of confluent may not want to persist configuration. Enable an opt-in full-volatile config mode. --- .../confluent/config/configmanager.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index c4a14c39..74a9f949 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -90,6 +90,8 @@ _masterintegritykey = None _dirtylock = threading.RLock() _config_areas = ('nodegroups', 'nodes', 'usergroups', 'users') tracelog = None +statelessmode = False +_cfgstore = None def _mkpath(pathname): try: @@ -495,6 +497,8 @@ class ConfigManager(object): def __init__(self, tenant, decrypt=False, username=None): global _cfgstore + if _cfgstore is None: + init() self.decrypt = decrypt self.current_user = username if tenant is None: @@ -1408,6 +1412,8 @@ class ConfigManager(object): @classmethod def _bg_sync_to_file(cls): + if statelessmode: + return with cls._syncstate: if cls._syncrunning: cls._writepending = True @@ -1421,6 +1427,8 @@ class ConfigManager(object): @classmethod def _sync_to_file(cls): + if statelessmode: + return if 'dirtyglobals' in _cfgstore: with _dirtylock: dirtyglobals = copy.deepcopy(_cfgstore['dirtyglobals']) @@ -1566,11 +1574,15 @@ def dump_db_to_directory(location, password, redact=None): except OSError: pass - -try: - ConfigManager._read_from_path() -except IOError: - _cfgstore = {} +def init(stateless=False): + global _cfgstore + if stateless: + _cfgstore = {} + return + try: + ConfigManager._read_from_path() + except IOError: + _cfgstore = {} # some unit tests worth implementing: