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

Commit93ac14e

Browse files
committed
Sync 9.5 version of access/transam/parallel.c with HEAD.
This back-patches commita5fe473 (notably, marking ParallelMessagePendingas volatile, which is not particularly optional). I also back-patched someprevious cosmetic changes to remove unnecessary diffs between the twobranches. I'm unsure how much of this code is actually reachable in 9.5,but to the extent that it is reachable, it needs to be maintained, andminimizing cross-branch diffs will make that easier.
1 parent89c30d1 commit93ac14e

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include"postgres.h"
1616

17+
#include"access/parallel.h"
1718
#include"access/xact.h"
1819
#include"access/xlog.h"
19-
#include"access/parallel.h"
2020
#include"commands/async.h"
2121
#include"libpq/libpq.h"
2222
#include"libpq/pqformat.h"
@@ -33,6 +33,7 @@
3333
#include"utils/resowner.h"
3434
#include"utils/snapmgr.h"
3535

36+
3637
/*
3738
* We don't want to waste a lot of memory on an error queue which, most of
3839
* the time, will process only a handful of small messages. However, it is
@@ -90,7 +91,7 @@ typedef struct FixedParallelState
9091
intParallelWorkerNumber=-1;
9192

9293
/* Is there a parallel message pending which we need to receive? */
93-
boolParallelMessagePending= false;
94+
volatileboolParallelMessagePending= false;
9495

9596
/* Are we initializing a parallel worker? */
9697
boolInitializingParallelWorker= false;
@@ -102,11 +103,12 @@ static FixedParallelState *MyFixedParallelState;
102103
staticdlist_headpcxt_list=DLIST_STATIC_INIT(pcxt_list);
103104

104105
/* Private functions. */
105-
staticvoidHandleParallelMessage(ParallelContext*,int,StringInfomsg);
106+
staticvoidHandleParallelMessage(ParallelContext*pcxt,inti,StringInfomsg);
106107
staticvoidParallelErrorContext(void*arg);
107108
staticvoidParallelExtensionTrampoline(dsm_segment*seg,shm_toc*toc);
108109
staticvoidParallelWorkerMain(Datummain_arg);
109110

111+
110112
/*
111113
* Establish a new parallel context. This should be done after entering
112114
* parallel mode, and (unless there is an error) the context should be
@@ -178,8 +180,8 @@ CreateParallelContextForExternalFunction(char *library_name,
178180

179181
/*
180182
* Establish the dynamic shared memory segment for a parallel context and
181-
*copied state and other bookkeeping information that willneed by parallel
182-
* workers into it.
183+
*copy state and other bookkeeping information that willbe needed by
184+
*parallelworkers into it.
183185
*/
184186
void
185187
InitializeParallelDSM(ParallelContext*pcxt)
@@ -231,7 +233,8 @@ InitializeParallelDSM(ParallelContext *pcxt)
231233
PARALLEL_ERROR_QUEUE_SIZE,
232234
"parallel error queue size not buffer-aligned");
233235
shm_toc_estimate_chunk(&pcxt->estimator,
234-
PARALLEL_ERROR_QUEUE_SIZE*pcxt->nworkers);
236+
mul_size(PARALLEL_ERROR_QUEUE_SIZE,
237+
pcxt->nworkers));
235238
shm_toc_estimate_keys(&pcxt->estimator,1);
236239

237240
/* Estimate how much we'll need for extension entrypoint info. */
@@ -257,7 +260,7 @@ InitializeParallelDSM(ParallelContext *pcxt)
257260
* parallelism than to fail outright.
258261
*/
259262
segsize=shm_toc_estimate(&pcxt->estimator);
260-
if (pcxt->nworkers!=0)
263+
if (pcxt->nworkers>0)
261264
pcxt->seg=dsm_create(segsize,DSM_CREATE_NULL_IF_MAXSEGMENTS);
262265
if (pcxt->seg!=NULL)
263266
pcxt->toc=shm_toc_create(PARALLEL_MAGIC,
@@ -337,7 +340,8 @@ InitializeParallelDSM(ParallelContext *pcxt)
337340
*/
338341
error_queue_space=
339342
shm_toc_allocate(pcxt->toc,
340-
PARALLEL_ERROR_QUEUE_SIZE*pcxt->nworkers);
343+
mul_size(PARALLEL_ERROR_QUEUE_SIZE,
344+
pcxt->nworkers));
341345
for (i=0;i<pcxt->nworkers;++i)
342346
{
343347
char*start;
@@ -603,17 +607,17 @@ ParallelContextActive(void)
603607

604608
/*
605609
* Handle receipt of an interrupt indicating a parallel worker message.
610+
*
611+
* Note: this is called within a signal handler! All we can do is set
612+
* a flag that will cause the next CHECK_FOR_INTERRUPTS() to invoke
613+
* HandleParallelMessages().
606614
*/
607615
void
608616
HandleParallelMessageInterrupt(void)
609617
{
610-
intsave_errno=errno;
611-
612618
InterruptPending= true;
613619
ParallelMessagePending= true;
614620
SetLatch(MyLatch);
615-
616-
errno=save_errno;
617621
}
618622

619623
/*
@@ -664,11 +668,8 @@ HandleParallelMessages(void)
664668
}
665669
else
666670
ereport(ERROR,
667-
(errcode(ERRCODE_INTERNAL_ERROR),/* XXX: wrong errcode? */
668-
errmsg("lost connection to parallel worker")));
669-
670-
/* This might make the error queue go away. */
671-
CHECK_FOR_INTERRUPTS();
671+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
672+
errmsg("lost connection to parallel worker")));
672673
}
673674
}
674675
}
@@ -714,7 +715,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
714715
errctx.previous=pcxt->error_context_stack;
715716
error_context_stack=&errctx;
716717

717-
/* ParseErrorReponse or NoticeResponse. */
718+
/* ParseErrorResponse or NoticeResponse. */
718719
pq_parse_errornotice(msg,&edata);
719720

720721
/* Death of a worker isn't enough justification for suicide. */
@@ -747,7 +748,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
747748

748749
default:
749750
{
750-
elog(ERROR,"unknown message type: %c (%d bytes)",
751+
elog(ERROR,"unrecognized message type received from parallel worker: %c (message length%d bytes)",
751752
msgtype,msg->len);
752753
}
753754
}
@@ -847,7 +848,7 @@ ParallelWorkerMain(Datum main_arg)
847848
if (toc==NULL)
848849
ereport(ERROR,
849850
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
850-
errmsg("invalid magic number in dynamic shared memory segment")));
851+
errmsg("invalid magic number in dynamic shared memory segment")));
851852

852853
/* Look up fixed parallel state. */
853854
fps=shm_toc_lookup(toc,PARALLEL_KEY_FIXED);

‎src/include/access/parallel.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include"postmaster/bgworker.h"
2020
#include"storage/shm_mq.h"
2121
#include"storage/shm_toc.h"
22-
#include"utils/elog.h"
2322

2423
typedefvoid (*parallel_worker_main_type) (dsm_segment*seg,shm_toc*toc);
2524

@@ -46,24 +45,24 @@ typedef struct ParallelContext
4645
ParallelWorkerInfo*worker;
4746
}ParallelContext;
4847

49-
externboolParallelMessagePending;
48+
externvolatileboolParallelMessagePending;
5049
externintParallelWorkerNumber;
5150
externboolInitializingParallelWorker;
5251

5352
#defineIsParallelWorker()(ParallelWorkerNumber >= 0)
5453

5554
externParallelContext*CreateParallelContext(parallel_worker_main_typeentrypoint,intnworkers);
5655
externParallelContext*CreateParallelContextForExternalFunction(char*library_name,char*function_name,intnworkers);
57-
externvoidInitializeParallelDSM(ParallelContext*);
58-
externvoidLaunchParallelWorkers(ParallelContext*);
59-
externvoidWaitForParallelWorkersToFinish(ParallelContext*);
60-
externvoidDestroyParallelContext(ParallelContext*);
56+
externvoidInitializeParallelDSM(ParallelContext*pcxt);
57+
externvoidLaunchParallelWorkers(ParallelContext*pcxt);
58+
externvoidWaitForParallelWorkersToFinish(ParallelContext*pcxt);
59+
externvoidDestroyParallelContext(ParallelContext*pcxt);
6160
externboolParallelContextActive(void);
6261

6362
externvoidHandleParallelMessageInterrupt(void);
6463
externvoidHandleParallelMessages(void);
6564
externvoidAtEOXact_Parallel(boolisCommit);
6665
externvoidAtEOSubXact_Parallel(boolisCommit,SubTransactionIdmySubId);
67-
externvoidParallelWorkerReportLastRecEnd(XLogRecPtr);
66+
externvoidParallelWorkerReportLastRecEnd(XLogRecPtrlast_xlog_end);
6867

6968
#endif/* PARALLEL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp