pgsql: Fix relation leak for subscribers firing triggers in logical rep

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix relation leak for subscribers firing triggers in logical rep
Date: 2021-04-22 03:50:23
Message-ID: E1lZQMB-0007qK-0J@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix relation leak for subscribers firing triggers in logical replication

Creating a trigger on a relation to which an apply operation is
triggered would cause a relation leak once the change gets committed,
as the executor would miss that the relation needs to be closed
beforehand. This issue got introduced with the refactoring done in
1375422c, where it becomes necessary to track relations within
es_opened_result_relations to make sure that they are closed.

We have discussed using ExecInitResultRelation() coupled with
ExecCloseResultRelations() for the relations in need of tracking by the
apply operations in the subscribers, which would simplify greatly the
opening and closing of indexes, but this requires a larger rework and
reorganization of the worker code, particularly for the tuple routing
part. And that's not really welcome post feature freeze. So, for now,
settle down to the same solution as TRUNCATE which is to fill in
es_opened_result_relations with the relation opened, to make sure that
ExecGetTriggerResultRel() finds them and that they get closed.

The code is lightly refactored so as a relation is not registered three
times for each DML code path, making the whole a bit easier to follow.

Reported-by: Tang Haiying, Shi Yu, Hou Zhijie
Author: Amit Langote, Masahiko Sawada, Hou Zhijie
Reviewed-by: Amit Kapila, Michael Paquier
Discussion: https://postgr.es/m/OS0PR01MB611383FA0FE92EB9DE21946AFB769@OS0PR01MB6113.jpnprd01.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f3b141c482552a57866c72919007d6481cd59ee3

Modified Files
--------------
src/backend/replication/logical/worker.c | 73 ++++++++++++++++++++------------
1 file changed, 47 insertions(+), 26 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2021-04-22 15:12:01 pgsql: Make PostgresNode version aware
Previous Message Michael Paquier 2021-04-22 00:55:29 pgsql: doc: Move parallel_leader_participation to its correct category