Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5f30c2

Browse files
committed
Allow parallel workers to cope with a newly-created session user ID.
Parallel workers failed after a sequence likeBEGIN;CREATE USER foo;SET SESSION AUTHORIZATION foo;because check_session_authorization could not see the uncommittedpg_authid row for "foo". This is because we ran RestoreGUCState()in a separate transaction using an ordinary just-created snapshot.The same disease afflicts any other GUC that requires catalog lookupsand isn't forgiving about the lookups failing.To fix, postpone RestoreGUCState() into the worker's main transactionafter we've set up a snapshot duplicating the leader's. This affectscheck_transaction_isolation and check_transaction_deferrable, whichthink they should only run during transaction start. Make themact like check_transaction_read_only, which already knows it shouldsilently accept the value when InitializingParallelWorker.Per bug #18545 from Andrey Rachitskiy. Back-patch to allsupported branches, because this has been wrong for awhile.Discussion:https://postgr.es/m/18545-feba138862f19aaa@postgresql.org
1 parentbd15b7d commitf5f30c2

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

‎src/backend/access/transam/parallel.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,10 +1410,6 @@ ParallelWorkerMain(Datum main_arg)
14101410
libraryspace=shm_toc_lookup(toc,PARALLEL_KEY_LIBRARY, false);
14111411
StartTransactionCommand();
14121412
RestoreLibraryState(libraryspace);
1413-
1414-
/* Restore GUC values from launching backend. */
1415-
gucspace=shm_toc_lookup(toc,PARALLEL_KEY_GUC, false);
1416-
RestoreGUCState(gucspace);
14171413
CommitTransactionCommand();
14181414

14191415
/* Crank up a transaction state appropriate to a parallel worker. */
@@ -1455,6 +1451,14 @@ ParallelWorkerMain(Datum main_arg)
14551451
*/
14561452
InvalidateSystemCaches();
14571453

1454+
/*
1455+
* Restore GUC values from launching backend. We can't do this earlier,
1456+
* because GUC check hooks that do catalog lookups need to see the same
1457+
* database state as the leader.
1458+
*/
1459+
gucspace=shm_toc_lookup(toc,PARALLEL_KEY_GUC, false);
1460+
RestoreGUCState(gucspace);
1461+
14581462
/*
14591463
* Restore current role id. Skip verifying whether session user is
14601464
* allowed to become this role and blindly restore the leader's state for

‎src/backend/commands/variable.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,16 @@ check_transaction_read_only(bool *newval, void **extra, GucSource source)
577577
* We allow idempotent changes at any time, but otherwise this can only be
578578
* changed in a toplevel transaction that has not yet taken a snapshot.
579579
*
580-
* As in check_transaction_read_only, allow it if not inside a transaction.
580+
* As in check_transaction_read_only, allow it if not inside a transaction,
581+
* or if restoring state in a parallel worker.
581582
*/
582583
bool
583584
check_transaction_isolation(int*newval,void**extra,GucSourcesource)
584585
{
585586
intnewXactIsoLevel=*newval;
586587

587-
if (newXactIsoLevel!=XactIsoLevel&&IsTransactionState())
588+
if (newXactIsoLevel!=XactIsoLevel&&
589+
IsTransactionState()&& !InitializingParallelWorker)
588590
{
589591
if (FirstSnapshotSet)
590592
{
@@ -619,6 +621,10 @@ check_transaction_isolation(int *newval, void **extra, GucSource source)
619621
bool
620622
check_transaction_deferrable(bool*newval,void**extra,GucSourcesource)
621623
{
624+
/* Just accept the value when restoring state in a parallel worker */
625+
if (InitializingParallelWorker)
626+
return true;
627+
622628
if (IsSubTransaction())
623629
{
624630
GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);

‎src/test/regress/expected/select_parallel.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,21 @@ SELECT 1 FROM tenk1_vw_sec
13291329
(9 rows)
13301330

13311331
rollback;
1332+
-- test that a newly-created session role propagates to workers.
1333+
begin;
1334+
create role regress_parallel_worker;
1335+
set session authorization regress_parallel_worker;
1336+
select current_setting('session_authorization');
1337+
current_setting
1338+
-------------------------
1339+
regress_parallel_worker
1340+
(1 row)
1341+
1342+
set debug_parallel_query = 1;
1343+
select current_setting('session_authorization');
1344+
current_setting
1345+
-------------------------
1346+
regress_parallel_worker
1347+
(1 row)
1348+
1349+
rollback;

‎src/test/regress/sql/select_parallel.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,12 @@ SELECT 1 FROM tenk1_vw_sec
511511
WHERE (SELECTsum(f1)FROM int4_tblWHERE f1< unique1)<100;
512512

513513
rollback;
514+
515+
-- test that a newly-created session role propagates to workers.
516+
begin;
517+
create role regress_parallel_worker;
518+
set session authorization regress_parallel_worker;
519+
select current_setting('session_authorization');
520+
set debug_parallel_query=1;
521+
select current_setting('session_authorization');
522+
rollback;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp