diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-03-28 12:43:10 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-03-28 12:43:10 -0400 |
commit | 0075d78947e3800c5a807f48fd901f16db91101b (patch) | |
tree | 1bad670dde55f7388573d9933623772f69cb602a /src/backend/access/transam/parallel.c | |
parent | e2395cdbe83adc50ac03dd17474ee88c5a97359a (diff) |
Allow "internal" subtransactions in parallel mode.
Allow use of BeginInternalSubTransaction() in parallel mode, so long
as the subtransaction doesn't attempt to acquire an XID or increment
the command counter. Given those restrictions, the other parallel
processes don't need to know about the subtransaction at all, so
this should be safe. The benefit is that it allows subtransactions
intended for error recovery, such as pl/pgsql exception blocks,
to be used in PARALLEL SAFE functions.
Another reason for doing this is that the API of
BeginInternalSubTransaction() doesn't allow reporting failure.
pl/python for one, and perhaps other PLs, copes very poorly with an
error longjmp out of BeginInternalSubTransaction(). The headline
feature of this patch removes the only easily-triggerable failure
case within that function. There remain some resource-exhaustion
and similar cases, which we now deal with by promoting them to FATAL
errors, so that callers need not try to clean up. (It is likely
that such errors would leave us with corrupted transaction state
inside xact.c, making recovery difficult if not impossible anyway.)
Although this work started because of a report of a pl/python crash,
we're not going to do anything about that in the back branches.
Back-patching this particular fix is obviously not very wise.
While we could contemplate some narrower band-aid, pl/python is
already an untrusted language, so it seems okay to classify this
as a "so don't do that" case.
Patch by me, per report from Hao Zhang. Thanks to Robert Haas for
review.
Discussion: https://postgr.es/m/CALY6Dr-2yLVeVPhNMhuBnRgOZo1UjoTETgtKBx1B2gUi8yy+3g@mail.gmail.com
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r-- | src/backend/access/transam/parallel.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 751c251cf52..8613fc6fb54 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -1226,10 +1226,8 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg) /* * End-of-subtransaction cleanup for parallel contexts. * - * Currently, it's forbidden to enter or leave a subtransaction while - * parallel mode is in effect, so we could just blow away everything. But - * we may want to relax that restriction in the future, so this code - * contemplates that there may be multiple subtransaction IDs in pcxt_list. + * Here we remove only parallel contexts initiated within the current + * subtransaction. */ void AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId) @@ -1249,6 +1247,8 @@ AtEOSubXact_Parallel(bool isCommit, SubTransactionId mySubId) /* * End-of-transaction cleanup for parallel contexts. + * + * We nuke all remaining parallel contexts. */ void AtEOXact_Parallel(bool isCommit) |