You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by dj...@apache.org on 2026/10/11 01:41:54 UTC
(cloudberry) 07/07: Wait for temporary table cleanup before dropping the resgroup test role
This is an automated email from the ASF dual-hosted git repository.
tuhaihe pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 7b6e95a08a32c1b89a8e318c067455a4de8263dd
Author: Alena Rybakina <al...@gmail.com>
AuthorDate: Thu Oct 8 21:04:59 2026 +0300
Wait for temporary table cleanup before dropping the resgroup test role
The final termination scenario can receive a disconnect before backend
exit has removed its temporary table. Keep pg_terminate_backend()
asynchronous and use wait_for_temp_table_cleanup() to poll pg_class
until no temporary relations belong to the test role, before DROP ROLE.
This prevents a leftover role and resource group from affecting later
tests. Bound the retries and report an error if cleanup never completes.
---
.../resgroup/resgroup_cancel_terminate_concurrency.out | 11 +++++++++++
.../resgroup/resgroup_cancel_terminate_concurrency.sql | 18 ++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/test/isolation2/expected/resgroup/resgroup_cancel_terminate_concurrency.out b/src/test/isolation2/expected/resgroup/resgroup_cancel_terminate_concurrency.out
index e1c3c77403c..8c7dd672d13 100644
--- a/src/test/isolation2/expected/resgroup/resgroup_cancel_terminate_concurrency.out
+++ b/src/test/isolation2/expected/resgroup/resgroup_cancel_terminate_concurrency.out
@@ -244,6 +244,9 @@ DROP RESOURCE GROUP rg_concurrency_test;
DROP
-- test5: terminate a query waiting for a slot, that opens a transaction on exit callback
+CREATE FUNCTION wait_for_temp_table_cleanup(owner_role regrole) RETURNS bool AS $$ DECLARE retries int; /* in func */ BEGIN FOR retries IN 1..600 LOOP IF NOT EXISTS (SELECT 1 FROM pg_class WHERE relowner = owner_role AND relpersistence = 't') THEN RETURN true; /* in func */ END IF; /* in func */ PERFORM pg_sleep(0.1); /* in func */ END LOOP; /* in func */ RAISE EXCEPTION 'timed out waiting for temporary table cleanup for %', owner_role; /* in func */ END; /* in func */ $$ LANGUAGE plpgsql;
+CREATE
+
DROP ROLE IF EXISTS role_concurrency_test;
DROP
-- start_ignore
@@ -291,6 +294,12 @@ SELECT * FROM rg_concurrency_view;
(0 rows)
1q: ... <quitting>
2q: ... <quitting>
+-- Wait until backend cleanup has removed the role's temporary tables.
+SELECT wait_for_temp_table_cleanup('role_concurrency_test');
+ wait_for_temp_table_cleanup
+-----------------------------
+ t
+(1 row)
DROP ROLE role_concurrency_test;
DROP
DROP RESOURCE GROUP rg_concurrency_test;
@@ -298,3 +307,5 @@ DROP
DROP VIEW rg_concurrency_view;
DROP
+DROP FUNCTION wait_for_temp_table_cleanup(regrole);
+DROP
diff --git a/src/test/isolation2/sql/resgroup/resgroup_cancel_terminate_concurrency.sql b/src/test/isolation2/sql/resgroup/resgroup_cancel_terminate_concurrency.sql
index b978f6bbcc6..efcf8e7b323 100644
--- a/src/test/isolation2/sql/resgroup/resgroup_cancel_terminate_concurrency.sql
+++ b/src/test/isolation2/sql/resgroup/resgroup_cancel_terminate_concurrency.sql
@@ -116,6 +116,21 @@ DROP ROLE role_concurrency_test;
DROP RESOURCE GROUP rg_concurrency_test;
-- test5: terminate a query waiting for a slot, that opens a transaction on exit callback
+CREATE FUNCTION wait_for_temp_table_cleanup(owner_role regrole) RETURNS bool AS $$
+DECLARE
+ retries int; /* in func */
+BEGIN
+ FOR retries IN 1..600 LOOP
+ IF NOT EXISTS (SELECT 1 FROM pg_class
+ WHERE relowner = owner_role AND relpersistence = 't') THEN
+ RETURN true; /* in func */
+ END IF; /* in func */
+ PERFORM pg_sleep(0.1); /* in func */
+ END LOOP; /* in func */
+ RAISE EXCEPTION 'timed out waiting for temporary table cleanup for %', owner_role; /* in func */
+END; /* in func */
+$$ LANGUAGE plpgsql;
+
DROP ROLE IF EXISTS role_concurrency_test;
-- start_ignore
DROP RESOURCE GROUP rg_concurrency_test;
@@ -138,7 +153,10 @@ SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE wait_event_type='Re
SELECT * FROM rg_concurrency_view;
1q:
2q:
+-- Wait until backend cleanup has removed the role's temporary tables.
+SELECT wait_for_temp_table_cleanup('role_concurrency_test');
DROP ROLE role_concurrency_test;
DROP RESOURCE GROUP rg_concurrency_test;
DROP VIEW rg_concurrency_view;
+DROP FUNCTION wait_for_temp_table_cleanup(regrole);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org