pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arseny Sher <a.sher@postgrespro.ru>
To: pgsql-hackers@postgresql.org
Subject: Re: DROP SUBSCRIPTION hangs if sub is disabled in the same transaction
Date: Mon, 04 Sep 2017 17:43:09 +0300
Message-ID: <87ingyv81u.fsf@ars-thinkpad> (raw)
In-Reply-To: <87mv6av84w.fsf@ars-thinkpad>
References: <87mv6av84w.fsf@ars-thinkpad>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Arseny Sher <a.sher@postgrespro.ru> writes:

> Attached patch fixes this by stopping workers before RO drop, as
> already done in case when we drop replication slot.

Sorry, here is the patch.


--
Arseny Sher
Postgres Professional: https://postgrespro.ru
The Russian Postgres Company

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

0001-Stop-LR-workers-before-dropping-replication-origin.patch (text/x-diff, 2.6K) download From 008d54dfe2e8ba610bb7c897cfbb4ee7a700aa2e Mon Sep 17 00:00:00 2001 From: Arseny Sher <sher-ars@yandex.ru> Date: Mon, 4 Sep 2017 16:55:08 +0300 Subject: [PATCH] Stop LR workers before dropping replication origin. Previously, executing ALTER SUBSCRIPTION DISABLE and DROP SUBSCRIPTION in one transaction would hang forever, because worker didn't stop until transaction is commited, and transaction couldn't commit before worker exit since the latter occupies ReplicationState. --- src/backend/commands/subscriptioncmds.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 77620dfd42..5d608855a1 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -886,6 +886,10 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) else slotname = NULL; + /* Get originid */ + snprintf(originname, sizeof(originname), "pg_%u", subid); + originid = replorigin_by_name(originname, true); + /* * Since dropping a replication slot is not transactional, the replication * slot stays dropped even if the transaction rolls back. So we cannot @@ -909,9 +913,10 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) ReleaseSysCache(tup); /* - * If we are dropping the replication slot, stop all the subscription - * workers immediately, so that the slot becomes accessible. Otherwise - * just schedule the stopping for the end of the transaction. + * We stop all subscription workers immediately in two cases: + * - We are dropping the replication slot, to make the slot accessible; + * - We are dropping repl origin tracking, to release ReplicationState; + * Otherwise just schedule the stopping for the end of the transaction. * * New workers won't be started because we hold an exclusive lock on the * subscription till the end of the transaction. @@ -923,7 +928,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) { LogicalRepWorker *w = (LogicalRepWorker *) lfirst(lc); - if (slotname) + if (slotname || originid != InvalidRepOriginId) logicalrep_worker_stop(w->subid, w->relid); else logicalrep_worker_stop_at_commit(w->subid, w->relid); @@ -937,8 +942,6 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) RemoveSubscriptionRel(subid, InvalidOid); /* Remove the origin tracking if exists. */ - snprintf(originname, sizeof(originname), "pg_%u", subid); - originid = replorigin_by_name(originname, true); if (originid != InvalidRepOriginId) replorigin_drop(originid, false); -- 2.11.0

view thread (32+ messages)  latest in thread

Message-ID: <87ingyv81u.fsf@ars-thinkpad>
Permalink:  ../87ingyv81u.fsf@ars-thinkpad/
Also on:    postgresql.org/message-id/87ingyv81u.fsf@ars-thinkpad

 ·  · 

reply

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-hackers@postgresql.org
  Cc: a.sher@postgrespro.ru
  Subject: Re: DROP SUBSCRIPTION hangs if sub is disabled in the same transaction
  In-Reply-To: <87ingyv81u.fsf@ars-thinkpad>
  References: <87mv6av84w.fsf@ars-thinkpad> <87ingyv81u.fsf@ars-thinkpad>

* 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