From: Etsuro Fujita <efujita@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: Fix handling of pending asynchronous requests.
Date: Fri, 30 Jul 2021 08:08:07 +0000
Message-ID: <E1m9NYt-0005Z5-Od@gemulon.postgresql.org> (raw)
postgres_fdw: Fix handling of pending asynchronous requests.
A pending asynchronous request is handled by process_pending_request(),
which previously not only processed an in-progress remote query but
performed ExecForeignScan() to produce a tuple to return to the local
server asynchronously from the result of the remote query. But that led
to a server crash when executing a query or led to an "InstrStartNode
called twice in a row" or "InstrEndLoop called on running node" failure
when doing EXPLAIN ANALYZE of it, in cases where the plan tree for it
contained multiple async-capable nodes accessing the same
initplan/subplan that contained multiple async-capable nodes scanning
the same foreign tables as for the parent async-capable nodes, as
reported by Andrey Lepikhov. The reason is that the second step in
process_pending_request() invoked when executing the initplan/subplan
for one of the parent async-capable nodes caused recursive execution of
the initplan/subplan for another of the parent async-capable nodes.
To fix, split process_pending_request() into the two steps and postpone
the second step until ForeignAsyncConfigureWait() is called for each of
the pending asynchronous requests. Also, in ExecAppendAsyncEventWait()
we assumed that FDWs would register at least one wait event in a
WaitEventSet created there when they were called from
ForeignAsyncConfigureWait() in that function, but allow FDWs to register
zero wait events in the WaitEventSet; modify ExecAppendAsyncEventWait()
to just return in that case.
Oversight in commit 27e1f1456. Back-patch to v14 where that commit went
in.
Andrey Lepikhov and Etsuro Fujita
Discussion: https://postgr.es/m/fe5eaa19-1704-e4a4-76ee-3b9d37ade399@postgrespro.ru
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/1cf7fb376acd48710c1c2c5cd97d11cd82e71ae4
Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 55 +++++++++++++++++++++-
contrib/postgres_fdw/postgres_fdw.c | 65 ++++++++++++++++++++------
contrib/postgres_fdw/sql/postgres_fdw.sql | 13 ++++--
src/backend/executor/nodeAppend.c | 11 +++++
4 files changed, 126 insertions(+), 18 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: efujita@postgresql.org
Subject: Re: pgsql: postgres_fdw: Fix handling of pending asynchronous requests.
In-Reply-To: <E1m9NYt-0005Z5-Od@gemulon.postgresql.org>
References: <E1m9NYt-0005Z5-Od@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox