Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94b4f7e

Browse files
committed
Tighten up application of parallel mode checks.
Commit 924bcf4 failed to enforce parallel mode checks during the commit of a parallel worker, because we exited parallel mode prior to ending the transaction so that we could pop the active snapshot. Re-establish parallel mode during parallel worker commit. Without this, it's far too easy for unsafe actions during the pre-commit sequence to crash the server instead of hitting the error checks as intended. Just to be extra paranoid, adjust a couple of the sanity checks in xact.c to check not only IsInParallelMode() but also IsParallelWorker().
1 parent 423ec08 commit 94b4f7e

File tree

1 file changed

+7
-5
lines changed
  • src/backend/access/transam

1 file changed

+7
-5
lines changed

src/backend/access/transam/xact.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ AssignTransactionId(TransactionState s)
497497
* Workers synchronize transaction state at the beginning of each parallel
498498
* operation, so we can't account for new XIDs at this point.
499499
*/
500-
if (IsInParallelMode())
500+
if (IsInParallelMode() || IsParallelWorker())
501501
elog(ERROR, "cannot assign XIDs during a parallel operation");
502502

503503
/*
@@ -931,7 +931,7 @@ CommandCounterIncrement(void)
931931
* parallel operation, so we can't account for new commands after that
932932
* point.
933933
*/
934-
if (IsInParallelMode())
934+
if (IsInParallelMode() || IsParallelWorker())
935935
elog(ERROR, "cannot start commands during a parallel operation");
936936

937937
currentCommandId += 1;
@@ -1927,6 +1927,10 @@ CommitTransaction(void)
19271927

19281928
is_parallel_worker = (s->blockState == TBLOCK_PARALLEL_INPROGRESS);
19291929

1930+
/* Enforce parallel mode restrictions during parallel worker commit. */
1931+
if (is_parallel_worker)
1932+
EnterParallelMode();
1933+
19301934
ShowTransactionState("CommitTransaction");
19311935

19321936
/*
@@ -1971,10 +1975,7 @@ CommitTransaction(void)
19711975

19721976
/* If we might have parallel workers, clean them up now. */
19731977
if (IsInParallelMode())
1974-
{
19751978
AtEOXact_Parallel(true);
1976-
s->parallelModeLevel = 0;
1977-
}
19781979

19791980
/* Shut down the deferred-trigger manager */
19801981
AfterTriggerEndXact(true);
@@ -2013,6 +2014,7 @@ CommitTransaction(void)
20132014
* commit processing
20142015
*/
20152016
s->state = TRANS_COMMIT;
2017+
s->parallelModeLevel = 0;
20162018

20172019
if (!is_parallel_worker)
20182020
{

0 commit comments

Comments
 (0)