Skip to content

Commit

Permalink
CRF: drop update SQL and always re-insert all static cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Jan 7, 2025
1 parent 4018ee8 commit 5677406
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions edb/server/pgcon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
pg_connect,
SETUP_TEMP_TABLE_SCRIPT,
SETUP_CONFIG_CACHE_SCRIPT,
RESET_STATIC_CFG_SCRIPT,
)

__all__ = (
Expand All @@ -44,4 +45,5 @@
'BackendCatalogNameError',
'SETUP_TEMP_TABLE_SCRIPT',
'SETUP_CONFIG_CACHE_SCRIPT',
'RESET_STATIC_CFG_SCRIPT'
)
6 changes: 6 additions & 0 deletions edb/server/pgcon/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 16 additions & 21 deletions edb/server/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5677406

Please sign in to comment.