diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index e2b77d3885..7b8b79bdd9 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -264,6 +264,21 @@ pa_can_start(TransactionId xid) { Assert(TransactionIdIsValid(xid)); + /* Only leader apply workers can start parallel apply workers. */ + if (!am_leader_apply_worker()) + return false; + + /* + * It is good to check for any change in the subscription parameter to + * avoid the case where for a very long time the change doesn't get + * reflected. This can happen when there is a constant flow of streaming + * transactions that are handled by parallel apply workers. + * + * It is better to do it before the below checks so that the latest values + * of subscription can be used for the checks. + */ + maybe_reread_subscription(); + /* * Don't start a new parallel apply worker if the subscription is not * using parallel streaming mode, or if the publisher does not support @@ -272,10 +287,6 @@ pa_can_start(TransactionId xid) if (!MyLogicalRepWorker->parallel_apply) return false; - /* Only leader apply workers can start parallel apply workers. */ - if (!am_leader_apply_worker()) - return false; - /* * Don't start a new parallel worker if user has set skiplsn as it's * possible that they want to skip the streaming transaction. For @@ -485,14 +496,6 @@ pa_allocate_worker(TransactionId xid) HASH_ELEM | HASH_BLOBS | HASH_CONTEXT); } - /* - * It is good to check for any change in the subscription parameter to - * avoid the case where for a very long time the change doesn't get - * reflected. This can happen when there is a constant flow of streaming - * transactions that are handled by parallel apply workers. - */ - maybe_reread_subscription(); - winfo = pa_launch_parallel_worker(); if (!winfo) return; diff --git a/src/test/subscription/t/017_stream_ddl.pl b/src/test/subscription/t/017_stream_ddl.pl index b4101e979d..fb03b708b4 100644 --- a/src/test/subscription/t/017_stream_ddl.pl +++ b/src/test/subscription/t/017_stream_ddl.pl @@ -3,9 +3,8 @@ # Test streaming of large transaction with DDL and subtransactions # -# This file is mainly to test the DDL/DML interaction of publisher side and -# doesn't cover some extra code, so we don't add a parallel version for this -# file. +# This file is mainly to test the DDL/DML interaction of the publisher side, +# so we didn't add a parallel apply version for the tests in this file. use strict; use warnings; use PostgreSQL::Test::Cluster; diff --git a/src/test/subscription/t/019_stream_subxact_ddl_abort.pl b/src/test/subscription/t/019_stream_subxact_ddl_abort.pl index 905d2516ba..353e826a93 100644 --- a/src/test/subscription/t/019_stream_subxact_ddl_abort.pl +++ b/src/test/subscription/t/019_stream_subxact_ddl_abort.pl @@ -4,9 +4,8 @@ # Test streaming of transaction with subtransactions, DDLs, DMLs, and # rollbacks # -# This file is mainly to test the DDL/DML interaction of publisher side and -# doesn't cover some extra code, so we don't add a parallel version for this -# file. +# This file is mainly to test the DDL/DML interaction of the publisher side, +# so we didn't add a parallel apply version for the tests in this file. use strict; use warnings; use PostgreSQL::Test::Cluster;