Skip to content

Commit 5677406

Browse files
committed
CRF: drop update SQL and always re-insert all static cfg
1 parent 4018ee8 commit 5677406

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

edb/server/pgcon/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
pg_connect,
3434
SETUP_TEMP_TABLE_SCRIPT,
3535
SETUP_CONFIG_CACHE_SCRIPT,
36+
RESET_STATIC_CFG_SCRIPT,
3637
)
3738

3839
__all__ = (
@@ -44,4 +45,5 @@
4445
'BackendCatalogNameError',
4546
'SETUP_TEMP_TABLE_SCRIPT',
4647
'SETUP_CONFIG_CACHE_SCRIPT',
48+
'RESET_STATIC_CFG_SCRIPT'
4749
)

edb/server/pgcon/connect.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
value edgedb._sys_config_val_t NOT NULL
6262
);
6363
'''.strip()
64+
RESET_STATIC_CFG_SCRIPT: bytes = b'''
65+
WITH x1 AS (
66+
DELETE FROM _config_cache
67+
)
68+
DELETE FROM _edgecon_state WHERE type = 'A' OR type = 'E' OR type = 'F';
69+
'''
6470

6571

6672
def _build_init_con_script(*, check_pg_is_in_recovery: bool) -> bytes:

edb/server/tenant.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class Tenant(ha_base.ClusterProtocol):
121121
_pg_unavailable_msg: str | None
122122
_init_con_data: list[config.ConState]
123123
_init_con_sql: bytes | None
124-
_update_init_con_sql: bytes | None
125124

126125
_ha_master_serial: int
127126
_backend_adaptive_ha: adaptive_ha.AdaptiveHASupport | None
@@ -208,7 +207,7 @@ def __init__(
208207
self._block_new_connections = set()
209208
self._report_config_data = {}
210209
self._init_con_data = []
211-
self._init_con_sql = self._update_init_con_sql = None
210+
self._init_con_sql = None
212211

213212
# DB state will be initialized in init().
214213
self._dbindex = None
@@ -731,7 +730,6 @@ def terminate_sys_pgcon(self) -> None:
731730
def set_init_con_data(self, data: list[config.ConState]) -> None:
732731
self._init_con_data = data
733732
self._init_con_sql = None
734-
self._update_init_con_sql = None
735733
if data:
736734
self._init_con_sql = self._make_init_con_sql(data)
737735

@@ -1028,20 +1026,18 @@ async def acquire_pgcon(self, dbname: str) -> pgcon.PGConnection:
10281026
if not conn.is_healthy():
10291027
logger.warning("acquired an unhealthy pgcon; discard now")
10301028
elif conn.last_init_con_data is not self._init_con_data:
1031-
if self._update_init_con_sql:
1032-
try:
1033-
await conn.sql_execute(self._update_init_con_sql)
1034-
except Exception as e:
1035-
logger.warning(
1036-
"failed to update pgcon; discard now: %s", e
1037-
)
1038-
else:
1039-
conn.last_init_con_data = self._init_con_data
1040-
return conn
1041-
else:
1029+
try:
1030+
await conn.sql_execute(
1031+
pgcon.RESET_STATIC_CFG_SCRIPT +
1032+
(self._init_con_sql or b'')
1033+
)
1034+
except Exception as e:
10421035
logger.warning(
1043-
"don't know how to update pgcon; discard now"
1036+
"failed to update pgcon; discard now: %s", e
10441037
)
1038+
else:
1039+
conn.last_init_con_data = self._init_con_data
1040+
return conn
10451041
else:
10461042
return conn
10471043
self._pg_pool.release(dbname, conn, discard=True)
@@ -1701,20 +1697,19 @@ async def load_config_file(self, compiler):
17011697
]
17021698
+ config_file_data
17031699
)
1704-
return config_file_data
17051700

17061701
async def _reload_config_file(self):
17071702
# Load TOML config file
17081703
compiler = self._server.get_compiler_pool()
1709-
config_file_data = await self.load_config_file(compiler)
1710-
self._update_init_con_sql = b"""
1711-
DELETE FROM _edgecon_state WHERE "type" = 'F';
1712-
""".strip() + self._make_init_con_sql(config_file_data)
1704+
await self.load_config_file(compiler)
17131705

17141706
# Update sys pgcon and reload system config
17151707
async with self.use_sys_pgcon() as syscon:
17161708
if syscon.last_init_con_data is not self._init_con_data:
1717-
await syscon.sql_execute(self._update_init_con_sql)
1709+
await syscon.sql_execute(
1710+
pgcon.RESET_STATIC_CFG_SCRIPT + (self._init_con_sql or b'')
1711+
)
1712+
syscon.last_init_con_data = self._init_con_data
17181713
sys_config = await self._load_sys_config(syscon=syscon)
17191714
# GOTCHA: don't notify the change of sysconfig because it's local
17201715
self._dbindex.update_sys_config(sys_config)

0 commit comments

Comments
 (0)