diff --git a/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql b/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql index 4d5dbe038..dc09bd0d0 100644 --- a/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql +++ b/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql @@ -46,39 +46,7 @@ RETURNS int4[] AS $$ RETURN mRemoteBlockingPids; END; $$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION pg_catalog.citus_isolation_test_session_is_blocked(pBlockedPid integer, pInterestingPids integer[]) -RETURNS boolean AS $$ - DECLARE - mBlockedTransactionNum int8; - workerProcessId integer := current_setting('citus.isolation_test_session_remote_process_id'); - coordinatorProcessId integer := current_setting('citus.isolation_test_session_process_id'); - BEGIN - IF pg_catalog.old_pg_isolation_test_session_is_blocked(pBlockedPid, pInterestingPids) THEN - RETURN true; - END IF; - -- pg says we're not blocked locally; check whether we're blocked globally. - -- Note that worker process may be blocked or waiting for a lock. So we need to - -- get transaction number for both of them. Following IF provides the transaction - -- number when the worker process waiting for other session. - IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() - WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN - SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() - WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; - ELSE - -- Check whether transactions initiated from the coordinator get locked - SELECT transaction_number INTO mBlockedTransactionNum - FROM get_all_active_transactions() WHERE process_id = pBlockedPid; - END IF; - - RETURN EXISTS ( - SELECT 1 FROM dump_global_wait_edges() - WHERE waiting_transaction_num = mBlockedTransactionNum - ); - - END; - -$$ LANGUAGE plpgsql; +#include "udfs/citus_isolation_test_session_is_blocked/8.0-6.sql" RESET search_path; diff --git a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql new file mode 100644 index 000000000..9cdf21e7c --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql @@ -0,0 +1,32 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_isolation_test_session_is_blocked(pBlockedPid integer, pInterestingPids integer[]) +RETURNS boolean AS $$ + DECLARE + mBlockedTransactionNum int8; + workerProcessId integer := current_setting('citus.isolation_test_session_remote_process_id'); + coordinatorProcessId integer := current_setting('citus.isolation_test_session_process_id'); + BEGIN + IF pg_catalog.old_pg_isolation_test_session_is_blocked(pBlockedPid, pInterestingPids) THEN + RETURN true; + END IF; + + -- pg says we're not blocked locally; check whether we're blocked globally. + -- Note that worker process may be blocked or waiting for a lock. So we need to + -- get transaction number for both of them. Following IF provides the transaction + -- number when the worker process waiting for other session. + IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() + WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN + SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() + WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; + ELSE + -- Check whether transactions initiated from the coordinator get locked + SELECT transaction_number INTO mBlockedTransactionNum + FROM get_all_active_transactions() WHERE process_id = pBlockedPid; + END IF; + + RETURN EXISTS ( + SELECT 1 FROM dump_global_wait_edges() + WHERE waiting_transaction_num = mBlockedTransactionNum + ); + + END; +$$ LANGUAGE plpgsql; diff --git a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql new file mode 100644 index 000000000..9cdf21e7c --- /dev/null +++ b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql @@ -0,0 +1,32 @@ +CREATE OR REPLACE FUNCTION pg_catalog.citus_isolation_test_session_is_blocked(pBlockedPid integer, pInterestingPids integer[]) +RETURNS boolean AS $$ + DECLARE + mBlockedTransactionNum int8; + workerProcessId integer := current_setting('citus.isolation_test_session_remote_process_id'); + coordinatorProcessId integer := current_setting('citus.isolation_test_session_process_id'); + BEGIN + IF pg_catalog.old_pg_isolation_test_session_is_blocked(pBlockedPid, pInterestingPids) THEN + RETURN true; + END IF; + + -- pg says we're not blocked locally; check whether we're blocked globally. + -- Note that worker process may be blocked or waiting for a lock. So we need to + -- get transaction number for both of them. Following IF provides the transaction + -- number when the worker process waiting for other session. + IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() + WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN + SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() + WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; + ELSE + -- Check whether transactions initiated from the coordinator get locked + SELECT transaction_number INTO mBlockedTransactionNum + FROM get_all_active_transactions() WHERE process_id = pBlockedPid; + END IF; + + RETURN EXISTS ( + SELECT 1 FROM dump_global_wait_edges() + WHERE waiting_transaction_num = mBlockedTransactionNum + ); + + END; +$$ LANGUAGE plpgsql;