Skip to content

Commit

Permalink
Add Config.auto_rebuild_query_cache (#6924)
Browse files Browse the repository at this point in the history
It's turned off by default in ClusterTestCases
  • Loading branch information
fantix authored Feb 27, 2024
1 parent 6164002 commit 9d40457
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion edb/buildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


# Increment this whenever the database layout or stdlib changes.
EDGEDB_CATALOG_VERSION = 2024_02_23_00_00
EDGEDB_CATALOG_VERSION = 2024_02_26_00_00
EDGEDB_MAJOR_VERSION = 5


Expand Down
6 changes: 6 additions & 0 deletions edb/lib/cfg.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ ALTER TYPE cfg::AbstractConfig {
Access-Control-Allow-Origin HTTP header';
};

CREATE PROPERTY auto_rebuild_query_cache -> std::bool {
SET default := true;
CREATE ANNOTATION std::description :=
'Recompile all cached queries on DDL if enabled.';
};

# Exposed backend settings follow.
# When exposing a new setting, remember to modify
# the _read_sys_config function to select the value
Expand Down
38 changes: 26 additions & 12 deletions edb/server/protocol/execute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ async def execute(
not dbv.in_tx()
and not query_unit.tx_rollback
and query_unit.user_schema
and server.config_lookup(
"auto_rebuild_query_cache",
dbv.get_session_config(),
dbv.get_database_config(),
dbv.get_system_config(),
)
):
# TODO(fantix): recompile first and update cache in tx
if debug.flags.func_cache:
Expand Down Expand Up @@ -515,19 +521,27 @@ async def execute_script(
conn.last_state = state
if unit_group.state_serializer is not None:
dbv.set_state_serializer(unit_group.state_serializer)
if not in_tx:
if any(query_unit.user_schema for query_unit in unit_group):
# TODO(fantix): recompile first and update cache in tx
if debug.flags.func_cache:
recompile_requests = await dbv.clear_cache_keys(conn)
else:
recompile_requests = [
req
for req, (grp, _) in dbv._db._eql_to_compiled.items()
if len(grp) == 1
]
if (
not in_tx
and any(query_unit.user_schema for query_unit in unit_group)
and dbv.server.config_lookup(
"auto_rebuild_query_cache",
dbv.get_session_config(),
dbv.get_database_config(),
dbv.get_system_config(),
)
):
# TODO(fantix): recompile first and update cache in tx
if debug.flags.func_cache:
recompile_requests = await dbv.clear_cache_keys(conn)
else:
recompile_requests = [
req
for req, (grp, _) in dbv._db._eql_to_compiled.items()
if len(grp) == 1
]

await dbv.recompile_all(conn, recompile_requests)
await dbv.recompile_all(conn, recompile_requests)

finally:
if sent and not sync:
Expand Down
18 changes: 17 additions & 1 deletion edb/testbase/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ class ClusterTestCase(BaseHTTPTestCase):
# library (e.g. declaring casts).
INTERNAL_TESTMODE = True

# Turns off query cache recompilation on DDL
ENABLE_RECOMPILATION = False

# Setup and teardown commands that run per test
PER_TEST_SETUP: Sequence[str] = ()
PER_TEST_TEARDOWN: Sequence[str] = ()
Expand Down Expand Up @@ -851,6 +854,13 @@ def setUp(self):
self.con.execute(
'CONFIGURE SESSION SET __internal_testmode := true;'))

if not self.ENABLE_RECOMPILATION:
self.loop.run_until_complete(
self.con.execute(
'CONFIGURE SESSION SET auto_rebuild_query_cache := false;'
)
)

if self.TRANSACTION_ISOLATION:
self.xact = self.con.transaction()
self.loop.run_until_complete(self.xact.start())
Expand Down Expand Up @@ -1167,9 +1177,13 @@ def get_api_prefix(cls):
def get_setup_script(cls):
script = ''

# allow the setup script to also run in test mode
# allow the setup script to also run in test mode and no recompilation
if cls.INTERNAL_TESTMODE:
script += '\nCONFIGURE SESSION SET __internal_testmode := true;'
if not cls.ENABLE_RECOMPILATION:
script += (
'\nCONFIGURE SESSION SET auto_rebuild_query_cache := false;'
)

if getattr(cls, 'BACKEND_SUPERUSER', False):
is_superuser = getattr(cls, 'is_superuser', True)
Expand Down Expand Up @@ -1228,6 +1242,8 @@ def get_setup_script(cls):
# allow the setup script to also run in test mode
if cls.INTERNAL_TESTMODE:
script += '\nCONFIGURE SESSION SET __internal_testmode := false;'
if not cls.ENABLE_RECOMPILATION:
script += '\nCONFIGURE SESSION RESET auto_rebuild_query_cache;'

return script.strip(' \n')

Expand Down

0 comments on commit 9d40457

Please sign in to comment.