Prevent splitbrain from duplicate names in configuration (#2724)

When starting check if node with the same is registered in DCS and try to query it's REST API.
If REST API is accessible exit with the error.

Close #1804
This commit is contained in:
Mark Pekala
2023-07-11 07:43:57 +02:00
committed by GitHub
parent 4725f12f9a
commit 412c51ddf1
5 changed files with 91 additions and 4 deletions
+9 -3
View File
@@ -52,10 +52,9 @@ class AbstractController(abc.ABC):
self._log = open(os.path.join(self._output_dir, self._name + '.log'), 'a')
self._handle = self._start()
assert self._has_started(), "Process {0} is not running after being started".format(self._name)
max_wait_limit *= self._context.timeout_multiplier
for _ in range(max_wait_limit):
assert self._has_started(), "Process {0} is not running after being started".format(self._name)
if self._is_accessible():
break
time.sleep(1)
@@ -344,6 +343,13 @@ class PatroniController(AbstractController):
'--datadir=' + os.path.join(self._work_directory, dest),
'--dbname=' + self.backup_source])
def read_patroni_log(self, level):
try:
with open(str(os.path.join(self._output_dir or '', self._name + ".log"))) as f:
return [line for line in f.readlines() if line[24:24 + len(level)] == level]
except IOError:
return []
class ProcessHang(object):
@@ -827,7 +833,7 @@ class PatroniPoolController(object):
def __getattr__(self, func):
if func not in ['stop', 'query', 'write_label', 'read_label', 'check_role_has_changed_to',
'add_tag_to_config', 'get_watchdog', 'patroni_hang', 'backup']:
'add_tag_to_config', 'get_watchdog', 'patroni_hang', 'backup', 'read_patroni_log']:
raise AttributeError("PatroniPoolController instance has no attribute '{0}'".format(func))
def wrapper(name, *args, **kwargs):