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

Commit f188972

Browse files
Add new parallel message type to progress reporting.
This commit adds a new type of parallel message 'P' to allow a parallel worker to poke at a leader to update the progress. Currently it supports only incremental progress reporting but it's possible to allow for supporting of other backend progress APIs in the future. There are no users of this new message type as of this commit. That will follow in future commits. Idea from Andres Freund. Author: Sami Imseih Reviewed by: Michael Paquier, Masahiko Sawada Discussion: https://www.postgresql.org/message-id/flat/5478DFCD-2333-401A-B2F0-0D186AB09228@amazon.com
1 parent 26dd028 commit f188972

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/backend/access/transam/parallel.c

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "catalog/pg_enum.h"
2525
#include "catalog/storage.h"
2626
#include "commands/async.h"
27+
#include "commands/progress.h"
2728
#include "commands/vacuum.h"
2829
#include "executor/execParallel.h"
2930
#include "libpq/libpq.h"
@@ -1199,6 +1200,23 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
11991200
break;
12001201
}
12011202

1203+
case 'P': /* Parallel progress reporting */
1204+
{
1205+
/*
1206+
* Only incremental progress reporting is currently supported.
1207+
* However, it's possible to add more fields to the message to
1208+
* allow for handling of other backend progress APIs.
1209+
*/
1210+
int index = pq_getmsgint(msg, 4);
1211+
int64 incr = pq_getmsgint64(msg);
1212+
1213+
pq_getmsgend(msg);
1214+
1215+
pgstat_progress_incr_param(index, incr);
1216+
1217+
break;
1218+
}
1219+
12021220
case 'X': /* Terminate, indicating clean exit */
12031221
{
12041222
shm_mq_detach(pcxt->worker[i].error_mqh);

src/backend/utils/activity/backend_progress.c

+32
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
#include "postgres.h"
1212

13+
#include "access/parallel.h"
14+
#include "libpq/pqformat.h"
1315
#include "port/atomics.h" /* for memory barriers */
1416
#include "utils/backend_progress.h"
1517
#include "utils/backend_status.h"
@@ -79,6 +81,36 @@ pgstat_progress_incr_param(int index, int64 incr)
7981
PGSTAT_END_WRITE_ACTIVITY(beentry);
8082
}
8183

84+
/*-----------
85+
* pgstat_progress_parallel_incr_param() -
86+
*
87+
* A variant of pgstat_progress_incr_param to allow a worker to poke at
88+
* a leader to do an incremental progress update.
89+
*-----------
90+
*/
91+
void
92+
pgstat_progress_parallel_incr_param(int index, int64 incr)
93+
{
94+
/*
95+
* Parallel workers notify a leader through a 'P' protocol message to
96+
* update progress, passing the progress index and incremented value.
97+
* Leaders can just call pgstat_progress_incr_param directly.
98+
*/
99+
if (IsParallelWorker())
100+
{
101+
static StringInfoData progress_message;
102+
103+
initStringInfo(&progress_message);
104+
105+
pq_beginmessage(&progress_message, 'P');
106+
pq_sendint32(&progress_message, index);
107+
pq_sendint64(&progress_message, incr);
108+
pq_endmessage(&progress_message);
109+
}
110+
else
111+
pgstat_progress_incr_param(index, incr);
112+
}
113+
82114
/*-----------
83115
* pgstat_progress_update_multi_param() -
84116
*

src/include/utils/backend_progress.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern void pgstat_progress_start_command(ProgressCommandType cmdtype,
3737
Oid relid);
3838
extern void pgstat_progress_update_param(int index, int64 val);
3939
extern void pgstat_progress_incr_param(int index, int64 incr);
40+
extern void pgstat_progress_parallel_incr_param(int index, int64 incr);
4041
extern void pgstat_progress_update_multi_param(int nparam, const int *index,
4142
const int64 *val);
4243
extern void pgstat_progress_end_command(void);

0 commit comments

Comments
 (0)