diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-06-30 18:35:32 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-06-30 18:35:32 -0400 |
commit | 10c0558ffefcd12bf1d3dc35587eba41d1ce4571 (patch) | |
tree | 5b6344c420e2822f7c66f626294218adbd54343f /src/backend/access/transam/parallel.c | |
parent | f8c58554db48fe004938a8a34a42afb78157b66c (diff) | |
download | postgresql-10c0558ffefcd12bf1d3dc35587eba41d1ce4571.tar.gz postgresql-10c0558ffefcd12bf1d3dc35587eba41d1ce4571.zip |
Fix several mistakes around parallel workers and client_encoding.
Previously, workers sent data to the leader using the client encoding.
That mostly worked, but the leader the converted the data back to the
server encoding. Since not all encoding conversions are reversible,
that could provoke failures. Fix by using the database encoding for
all communication between worker and leader.
Also, while temporary changes to GUC settings, as from the SET clause
of a function, are in general OK for parallel query, changing
client_encoding this way inside of a parallel worker is not OK.
Previously, that would have confused the leader; with these changes,
it would not confuse the leader, but it wouldn't do anything either.
So refuse such changes in parallel workers.
Also, the previous code naively assumed that when it received a
NotifyResonse from the worker, it could pass that directly back to the
user. But now that worker-to-leader communication always uses the
database encoding, that's clearly no longer correct - though,
actually, the old way was always broken for V2 clients. So
disassemble and reconstitute the message instead.
Issues reported by Peter Eisentraut. Patch by me, reviewed by
Peter Eisentraut.
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r-- | src/backend/access/transam/parallel.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 088700e17cb..eef1dc2b184 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -810,7 +810,17 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg) case 'A': /* NotifyResponse */ { /* Propagate NotifyResponse. */ - pq_putmessage(msg->data[0], &msg->data[1], msg->len - 1); + int32 pid; + const char *channel; + const char *payload; + + pid = pq_getmsgint(msg, 4); + channel = pq_getmsgrawstring(msg); + payload = pq_getmsgrawstring(msg); + pq_endmessage(msg); + + NotifyMyFrontEnd(channel, payload, pid); + break; } @@ -988,6 +998,12 @@ ParallelWorkerMain(Datum main_arg) BackgroundWorkerInitializeConnectionByOid(fps->database_id, fps->authenticated_user_id); + /* + * Set the client encoding to the database encoding, since that is what + * the leader will expect. + */ + SetClientEncoding(GetDatabaseEncoding()); + /* Restore GUC values from launching backend. */ gucspace = shm_toc_lookup(toc, PARALLEL_KEY_GUC); Assert(gucspace != NULL); |