Move initialization of global_config to Patroni class (#3309)

we rely on it's value when creating instance of Postgresql class
This commit is contained in:
Alexander Kukushkin
2025-03-14 10:35:36 +01:00
committed by GitHub
parent 7543e64000
commit 9977850b56
3 changed files with 6 additions and 5 deletions
+4 -1
View File
@@ -12,7 +12,7 @@ import time
from argparse import Namespace from argparse import Namespace
from typing import Any, Dict, List, Optional, TYPE_CHECKING from typing import Any, Dict, List, Optional, TYPE_CHECKING
from patroni import MIN_PSYCOPG2, MIN_PSYCOPG3, parse_version from patroni import global_config, MIN_PSYCOPG2, MIN_PSYCOPG3, parse_version
from patroni.daemon import abstract_main, AbstractPatroniDaemon, get_base_arg_parser from patroni.daemon import abstract_main, AbstractPatroniDaemon, get_base_arg_parser
from patroni.tags import Tags from patroni.tags import Tags
@@ -70,6 +70,9 @@ class Patroni(AbstractPatroniDaemon, Tags):
self.watchdog = Watchdog(self.config) self.watchdog = Watchdog(self.config)
self.apply_dynamic_configuration(cluster) self.apply_dynamic_configuration(cluster)
# Initialize global config
global_config.update(None, self.config.dynamic_configuration)
self.postgresql = Postgresql(self.config['postgresql'], self.dcs.mpp) self.postgresql = Postgresql(self.config['postgresql'], self.dcs.mpp)
self.api = RestApiServer(self, self.config['restapi']) self.api = RestApiServer(self, self.config['restapi'])
self.ha = Ha(self) self.ha = Ha(self)
-3
View File
@@ -263,9 +263,6 @@ class Ha(object):
# used only in backoff after failing a pre_promote script # used only in backoff after failing a pre_promote script
self._released_leader_key_timestamp = 0 self._released_leader_key_timestamp = 0
# Initialize global config
global_config.update(None, self.patroni.config.dynamic_configuration)
def primary_stop_timeout(self) -> Union[int, None]: def primary_stop_timeout(self) -> Union[int, None]:
""":returns: "primary_stop_timeout" from the global configuration or `None` when not in synchronous mode.""" """:returns: "primary_stop_timeout" from the global configuration or `None` when not in synchronous mode."""
ret = global_config.primary_stop_timeout ret = global_config.primary_stop_timeout
+2 -1
View File
@@ -94,6 +94,8 @@ class Postgresql(object):
self._connection = self.connection_pool.get('heartbeat') self._connection = self.connection_pool.get('heartbeat')
self.mpp_handler = mpp.get_handler_impl(self) self.mpp_handler = mpp.get_handler_impl(self)
self._bin_dir = config.get('bin_dir') or '' self._bin_dir = config.get('bin_dir') or ''
self._role_lock = Lock()
self.set_role('uninitialized')
self.config = ConfigHandler(self, config) self.config = ConfigHandler(self, config)
self.config.check_directories() self.config.check_directories()
@@ -118,7 +120,6 @@ class Postgresql(object):
self._is_leader_retry = Retry(max_tries=1, deadline=config['retry_timeout'] / 2.0, max_delay=1, self._is_leader_retry = Retry(max_tries=1, deadline=config['retry_timeout'] / 2.0, max_delay=1,
retry_exceptions=PostgresConnectionException) retry_exceptions=PostgresConnectionException)
self._role_lock = Lock()
self.set_role(self.get_postgres_role_from_data_directory()) self.set_role(self.get_postgres_role_from_data_directory())
self._state_entry_timestamp = 0 self._state_entry_timestamp = 0