From 1f2fa5df69ca921699711db2449b4131a30fbdbe Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 27 Sep 2021 11:09:40 +0200 Subject: [PATCH] sql: lock wcs_meta table during schema update (#57017) It's only done for do_formdef_table and migrate, for do_formdef_table a timeout is set to 10 seconds, for migrate the lock will wait indefinitely (or less if a timeout is set in postgresql configuration, but the default is 0, which means no timeout). --- wcs/sql.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wcs/sql.py b/wcs/sql.py index 684b17a1..2b1ad274 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -388,6 +388,14 @@ def get_connection(new=False, isolate=False): return get_publisher().pgconn +def lock_wcs_meta(timeout=0): + conn, cur = get_connection_and_cursor() + do_meta_table(conn, cur, insert_current_sql_level=False) + if timeout: + cur.execute('SET LOCAL lock_timeout = %s', [timeout]) + cur.execute('LOCK wcs_meta') + + def cleanup_connection(): if hasattr(get_publisher(), 'pgconn') and get_publisher().pgconn is not None: get_publisher().pgconn.close() @@ -512,6 +520,8 @@ def guard_postgres(func): @guard_postgres def do_formdef_tables(formdef, conn=None, cur=None, rebuild_views=False, rebuild_global_views=True): + lock_wcs_meta(timeout=10000) + if formdef.id is None: return [] @@ -3517,6 +3527,7 @@ def migrate_views(conn, cur): @guard_postgres def migrate(): + lock_wcs_meta() conn, cur = get_connection_and_cursor() sql_level = get_sql_level(conn, cur) if sql_level < 0: -- 2.33.0