From 56774063ef78aa564fc278e288520c8200592ef1 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Tue, 7 Jan 2025 15:03:08 -0500 Subject: [PATCH] CRF: drop update SQL and always re-insert all static cfg --- edb/server/pgcon/__init__.py | 2 ++ edb/server/pgcon/connect.py | 6 ++++++ edb/server/tenant.py | 37 ++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/edb/server/pgcon/__init__.py b/edb/server/pgcon/__init__.py index 2edf5755519..8babc785151 100644 --- a/edb/server/pgcon/__init__.py +++ b/edb/server/pgcon/__init__.py @@ -33,6 +33,7 @@ pg_connect, SETUP_TEMP_TABLE_SCRIPT, SETUP_CONFIG_CACHE_SCRIPT, + RESET_STATIC_CFG_SCRIPT, ) __all__ = ( @@ -44,4 +45,5 @@ 'BackendCatalogNameError', 'SETUP_TEMP_TABLE_SCRIPT', 'SETUP_CONFIG_CACHE_SCRIPT', + 'RESET_STATIC_CFG_SCRIPT' ) diff --git a/edb/server/pgcon/connect.py b/edb/server/pgcon/connect.py index 899318b5459..aafe1532f3f 100644 --- a/edb/server/pgcon/connect.py +++ b/edb/server/pgcon/connect.py @@ -61,6 +61,12 @@ value edgedb._sys_config_val_t NOT NULL ); '''.strip() +RESET_STATIC_CFG_SCRIPT: bytes = b''' + WITH x1 AS ( + DELETE FROM _config_cache + ) + DELETE FROM _edgecon_state WHERE type = 'A' OR type = 'E' OR type = 'F'; +''' def _build_init_con_script(*, check_pg_is_in_recovery: bool) -> bytes: diff --git a/edb/server/tenant.py b/edb/server/tenant.py index f296511919b..4f938c14e10 100644 --- a/edb/server/tenant.py +++ b/edb/server/tenant.py @@ -121,7 +121,6 @@ class Tenant(ha_base.ClusterProtocol): _pg_unavailable_msg: str | None _init_con_data: list[config.ConState] _init_con_sql: bytes | None - _update_init_con_sql: bytes | None _ha_master_serial: int _backend_adaptive_ha: adaptive_ha.AdaptiveHASupport | None @@ -208,7 +207,7 @@ def __init__( self._block_new_connections = set() self._report_config_data = {} self._init_con_data = [] - self._init_con_sql = self._update_init_con_sql = None + self._init_con_sql = None # DB state will be initialized in init(). self._dbindex = None @@ -731,7 +730,6 @@ def terminate_sys_pgcon(self) -> None: def set_init_con_data(self, data: list[config.ConState]) -> None: self._init_con_data = data self._init_con_sql = None - self._update_init_con_sql = None if data: self._init_con_sql = self._make_init_con_sql(data) @@ -1028,20 +1026,18 @@ async def acquire_pgcon(self, dbname: str) -> pgcon.PGConnection: if not conn.is_healthy(): logger.warning("acquired an unhealthy pgcon; discard now") elif conn.last_init_con_data is not self._init_con_data: - if self._update_init_con_sql: - try: - await conn.sql_execute(self._update_init_con_sql) - except Exception as e: - logger.warning( - "failed to update pgcon; discard now: %s", e - ) - else: - conn.last_init_con_data = self._init_con_data - return conn - else: + try: + await conn.sql_execute( + pgcon.RESET_STATIC_CFG_SCRIPT + + (self._init_con_sql or b'') + ) + except Exception as e: logger.warning( - "don't know how to update pgcon; discard now" + "failed to update pgcon; discard now: %s", e ) + else: + conn.last_init_con_data = self._init_con_data + return conn else: return conn self._pg_pool.release(dbname, conn, discard=True) @@ -1701,20 +1697,19 @@ async def load_config_file(self, compiler): ] + config_file_data ) - return config_file_data async def _reload_config_file(self): # Load TOML config file compiler = self._server.get_compiler_pool() - config_file_data = await self.load_config_file(compiler) - self._update_init_con_sql = b""" - DELETE FROM _edgecon_state WHERE "type" = 'F'; - """.strip() + self._make_init_con_sql(config_file_data) + await self.load_config_file(compiler) # Update sys pgcon and reload system config async with self.use_sys_pgcon() as syscon: if syscon.last_init_con_data is not self._init_con_data: - await syscon.sql_execute(self._update_init_con_sql) + await syscon.sql_execute( + pgcon.RESET_STATIC_CFG_SCRIPT + (self._init_con_sql or b'') + ) + syscon.last_init_con_data = self._init_con_data sys_config = await self._load_sys_config(syscon=syscon) # GOTCHA: don't notify the change of sysconfig because it's local self._dbindex.update_sys_config(sys_config)