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

Commita5fe473

Browse files
committed
Minor cleanup for access/transam/parallel.c.
ParallelMessagePending *must* be marked volatile, because it's setby a signal handler. On the other hand, it's pointless forHandleParallelMessageInterrupt to save/restore errno; that must be,and is, done at the outer level of the SIGUSR1 signal handler.Calling CHECK_FOR_INTERRUPTS() inside HandleParallelMessages, which itselfis called from CHECK_FOR_INTERRUPTS(), seems both useless and hazardous.The comment claiming that this is needed to handle the error queue goingaway is certainly misguided, in any case.Improve a couple of error message texts, and useERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE to report loss of parallel workerconnection, since that's what's used in e.g. tqueue.c. (Maybe it would beworth inventing a dedicated ERRCODE for this type of failure? But I do notthink ERRCODE_INTERNAL_ERROR is appropriate.)Minor stylistic cleanups.
1 parent887feef commita5fe473

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

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

Lines changed: 12 additions & 13 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"catalog/namespace.h"
2121
#include"commands/async.h"
2222
#include"libpq/libpq.h"
@@ -35,6 +35,7 @@
3535
#include"utils/resowner.h"
3636
#include"utils/snapmgr.h"
3737

38+
3839
/*
3940
* We don't want to waste a lot of memory on an error queue which, most of
4041
* the time, will process only a handful of small messages. However, it is
@@ -94,7 +95,7 @@ typedef struct FixedParallelState
9495
intParallelWorkerNumber=-1;
9596

9697
/* Is there a parallel message pending which we need to receive? */
97-
boolParallelMessagePending= false;
98+
volatileboolParallelMessagePending= false;
9899

99100
/* Are we initializing a parallel worker? */
100101
boolInitializingParallelWorker= false;
@@ -106,12 +107,13 @@ static FixedParallelState *MyFixedParallelState;
106107
staticdlist_headpcxt_list=DLIST_STATIC_INIT(pcxt_list);
107108

108109
/* Private functions. */
109-
staticvoidHandleParallelMessage(ParallelContext*,int,StringInfomsg);
110+
staticvoidHandleParallelMessage(ParallelContext*pcxt,inti,StringInfomsg);
110111
staticvoidParallelErrorContext(void*arg);
111112
staticvoidParallelExtensionTrampoline(dsm_segment*seg,shm_toc*toc);
112113
staticvoidParallelWorkerMain(Datummain_arg);
113114
staticvoidWaitForParallelWorkersToExit(ParallelContext*pcxt);
114115

116+
115117
/*
116118
* Establish a new parallel context. This should be done after entering
117119
* parallel mode, and (unless there is an error) the context should be
@@ -681,17 +683,17 @@ ParallelContextActive(void)
681683

682684
/*
683685
* Handle receipt of an interrupt indicating a parallel worker message.
686+
*
687+
* Note: this is called within a signal handler! All we can do is set
688+
* a flag that will cause the next CHECK_FOR_INTERRUPTS() to invoke
689+
* HandleParallelMessages().
684690
*/
685691
void
686692
HandleParallelMessageInterrupt(void)
687693
{
688-
intsave_errno=errno;
689-
690694
InterruptPending= true;
691695
ParallelMessagePending= true;
692696
SetLatch(MyLatch);
693-
694-
errno=save_errno;
695697
}
696698

697699
/*
@@ -742,11 +744,8 @@ HandleParallelMessages(void)
742744
}
743745
else
744746
ereport(ERROR,
745-
(errcode(ERRCODE_INTERNAL_ERROR),/* XXX: wrong errcode? */
746-
errmsg("lost connection to parallel worker")));
747-
748-
/* This might make the error queue go away. */
749-
CHECK_FOR_INTERRUPTS();
747+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
748+
errmsg("lost connection to parallel worker")));
750749
}
751750
}
752751
}
@@ -833,7 +832,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
833832

834833
default:
835834
{
836-
elog(ERROR,"unknown message type: %c (%d bytes)",
835+
elog(ERROR,"unrecognized message type received from parallel worker: %c (message length%d bytes)",
837836
msgtype,msg->len);
838837
}
839838
}

‎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

@@ -47,25 +46,25 @@ typedef struct ParallelContext
4746
ParallelWorkerInfo*worker;
4847
}ParallelContext;
4948

50-
externboolParallelMessagePending;
49+
externvolatileboolParallelMessagePending;
5150
externintParallelWorkerNumber;
5251
externboolInitializingParallelWorker;
5352

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

5655
externParallelContext*CreateParallelContext(parallel_worker_main_typeentrypoint,intnworkers);
5756
externParallelContext*CreateParallelContextForExternalFunction(char*library_name,char*function_name,intnworkers);
58-
externvoidInitializeParallelDSM(ParallelContext*);
57+
externvoidInitializeParallelDSM(ParallelContext*pcxt);
5958
externvoidReinitializeParallelDSM(ParallelContext*pcxt);
60-
externvoidLaunchParallelWorkers(ParallelContext*);
61-
externvoidWaitForParallelWorkersToFinish(ParallelContext*);
62-
externvoidDestroyParallelContext(ParallelContext*);
59+
externvoidLaunchParallelWorkers(ParallelContext*pcxt);
60+
externvoidWaitForParallelWorkersToFinish(ParallelContext*pcxt);
61+
externvoidDestroyParallelContext(ParallelContext*pcxt);
6362
externboolParallelContextActive(void);
6463

6564
externvoidHandleParallelMessageInterrupt(void);
6665
externvoidHandleParallelMessages(void);
6766
externvoidAtEOXact_Parallel(boolisCommit);
6867
externvoidAtEOSubXact_Parallel(boolisCommit,SubTransactionIdmySubId);
69-
externvoidParallelWorkerReportLastRecEnd(XLogRecPtr);
68+
externvoidParallelWorkerReportLastRecEnd(XLogRecPtrlast_xlog_end);
7069

7170
#endif/* PARALLEL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp