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

Commitb8df690

Browse files
committed
Improve fix for not entering parallel mode when holding interrupts.
Commitac04aa8 put the shutoff for this into the planner, which isnot ideal because it doesn't prevent us from re-using a previouslymade parallel plan. Revert the planner change and instead put theshutoff into InitializeParallelDSM, modeling it on the existing codethere for recovering from failure to allocate a DSM segment.However, that code path is mostly untested, and testing a bit hardershowed there's at least one bug: ExecHashJoinReInitializeDSM is notprepared for us to have skipped doing parallel DSM setup. I alsothought the Assert in ReinitializeParallelWorkers is prettyill-advised, and replaced it with a silent Min() operation.The existing test case added byac04aa8 serves fine to test thisversion of the fix, so no change needed there.Patch by me, but thanks to Noah Misch for the core idea that wecould shut off worker creation when !INTERRUPTS_CAN_BE_PROCESSED.Back-patch to v12, asac04aa8 was.Discussion:https://postgr.es/m/CAC-SaSzHUKT=vZJ8MPxYdC_URPfax+yoA1hKTcF4ROz_Q6z0_Q@mail.gmail.com
1 parentb5ee4e5 commitb8df690

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ InitializeParallelDSM(ParallelContext *pcxt)
230230
shm_toc_estimate_chunk(&pcxt->estimator,sizeof(FixedParallelState));
231231
shm_toc_estimate_keys(&pcxt->estimator,1);
232232

233+
/*
234+
* If we manage to reach here while non-interruptible, it's unsafe to
235+
* launch any workers: we would fail to process interrupts sent by them.
236+
* We can deal with that edge case by pretending no workers were
237+
* requested.
238+
*/
239+
if (!INTERRUPTS_CAN_BE_PROCESSED())
240+
pcxt->nworkers=0;
241+
233242
/*
234243
* Normally, the user will have requested at least one worker process, but
235244
* if by chance they have not, we can skip a bunch of things here.
@@ -476,6 +485,9 @@ InitializeParallelDSM(ParallelContext *pcxt)
476485
shm_toc_insert(pcxt->toc,PARALLEL_KEY_ENTRYPOINT,entrypointstate);
477486
}
478487

488+
/* Update nworkers_to_launch, in case we changed nworkers above. */
489+
pcxt->nworkers_to_launch=pcxt->nworkers;
490+
479491
/* Restore previous memory context. */
480492
MemoryContextSwitchTo(oldcontext);
481493
}
@@ -539,10 +551,11 @@ ReinitializeParallelWorkers(ParallelContext *pcxt, int nworkers_to_launch)
539551
{
540552
/*
541553
* The number of workers that need to be launched must be less than the
542-
* number of workers with which the parallel context is initialized.
554+
* number of workers with which the parallel context is initialized. But
555+
* the caller might not know that InitializeParallelDSM reduced nworkers,
556+
* so just silently trim the request.
543557
*/
544-
Assert(pcxt->nworkers >=nworkers_to_launch);
545-
pcxt->nworkers_to_launch=nworkers_to_launch;
558+
pcxt->nworkers_to_launch=Min(pcxt->nworkers,nworkers_to_launch);
546559
}
547560

548561
/*

‎src/backend/executor/nodeHashjoin.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,13 @@ void
17131713
ExecHashJoinReInitializeDSM(HashJoinState*state,ParallelContext*pcxt)
17141714
{
17151715
intplan_node_id=state->js.ps.plan->plan_node_id;
1716-
ParallelHashJoinState*pstate=
1717-
shm_toc_lookup(pcxt->toc,plan_node_id, false);
1716+
ParallelHashJoinState*pstate;
1717+
1718+
/* Nothing to do if we failed to create a DSM segment. */
1719+
if (pcxt->seg==NULL)
1720+
return;
1721+
1722+
pstate=shm_toc_lookup(pcxt->toc,plan_node_id, false);
17181723

17191724
/*
17201725
* It would be possible to reuse the shared hash table in single-batch

‎src/backend/optimizer/plan/planner.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,6 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
342342
* we want to allow parallel inserts in general; updates and deletes have
343343
* additional problems especially around combo CIDs.)
344344
*
345-
* We don't try to use parallel mode unless interruptible. The leader
346-
* expects ProcessInterrupts() calls to reach HandleParallelMessages().
347-
* Even if we called HandleParallelMessages() another way, starting a
348-
* parallel worker is too delay-prone to be prudent when uncancellable.
349-
*
350345
* For now, we don't try to use parallel mode if we're running inside a
351346
* parallel worker. We might eventually be able to relax this
352347
* restriction, but for now it seems best not to have parallel workers
@@ -357,7 +352,6 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
357352
parse->commandType==CMD_SELECT&&
358353
!parse->hasModifyingCTE&&
359354
max_parallel_workers_per_gather>0&&
360-
INTERRUPTS_CAN_BE_PROCESSED()&&
361355
!IsParallelWorker())
362356
{
363357
/* all the cheap tests pass, so scan the query tree */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp