pgsql: postgres_fdw: Fix handling of pending asynchronous requests. - Mailing list pgsql-committers

From Etsuro Fujita
Subject pgsql: postgres_fdw: Fix handling of pending asynchronous requests.
Date
Msg-id E1m9NYt-0005Z5-Od@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Amit Kapila
Date:
Subject: pgsql: Remove unused argument in apply_handle_commit_internal().
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Update obsolete comment that still referred to CheckpointLock