Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ca6hc-0006E4-3u for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Feb 2017 20:12:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ca6hb-00045n-E4 for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Feb 2017 20:12:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ca6gB-0001aM-6k for pgsql-hackers@postgresql.org; Sat, 04 Feb 2017 20:11:27 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ca6g8-0003Ml-Bd for pgsql-hackers@postgresql.org; Sat, 04 Feb 2017 20:11:25 +0000 Received: by mail-wm0-x22a.google.com with SMTP id b65so78425867wmf.0 for ; Sat, 04 Feb 2017 12:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=Nubf/wP+d4PwYyHNCUo/a2+q5Jfm1fI3LzF5JL8d6j8=; b=qM0pMyHssp6oExKrGx0fRupxFmD5andI0vr5J9XUqkQ+soHt5DXP5IVWfhPUlayJPn CiGPH/8YUODbKtGriqLH7H1Ld/RRr8j0/+FfXdjZEh3AH00GuBo1fvHaNIm6ELAgOm5/ RIlNzIyzzMrPCwb74sQfs2L6cfhRcX7Xc2piusEQknmPVRwpEV+gSw+eTdBLIef1l7xj 7iL21HqD8Tm1WSPiGR1ZKKM+evMEqFZkVppEn1AszwLnxeBTU3YANMpB9VUohLrzdeFK noDOI2pRygE02Vp9pb5+tEW7IkD3beUOuP+gu/SlXyILUNRVrS126BAgj8NhRh2rTb84 HuZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Nubf/wP+d4PwYyHNCUo/a2+q5Jfm1fI3LzF5JL8d6j8=; b=iOBgHsEw4lUhWf5qF2eswmJurXtDj2BqdExHtbsNMJ7MH5zm91SMtvO3pCblfxTL3u I168fhl527br9jUqWDBUqLG7WOL+5nkjoXo7jaIyXujbfXqv5SgvU+g6hlrPzrastv6I ii4DZ5v/jbxJBSW5W5QTsFDdA+4T8m2XD25WnczQAoORWIYCJ4Q3x5RLvaUMPsW5GgBk dYaGFev2hHwWc/9ZXYU3SSk8UYm/yxdBYLYbfBu8r7ql+LBZ9bA4rKRb7B1APYqahKIt 9tSad/rGiYLWMvR4QHC+E2ylGQF+A6mD4TIUkNPpOZQMy2zze/gDAun0nFPtjWcX4FGP asYA== X-Gm-Message-State: AMke39m3FOq8ZTDN+BkvNQ/3Toe/WJVES+qPeUQ30wa5sAjPoMKzxCz5g7Vly7QgVLQ1SwdZv3JeGSNuc2343r3eYiUg9RtT+u7AhOZWSFHAliolHLSYu82hrIa6sz7XUtahjq0oCmOuEcoOjzG6NRtyjY80/gyXrH5XkUDMOhp4NMb2lzR9wgaueo1zGQLj1UFpnAC1uPn6 X-Received: by 10.28.88.6 with SMTP id m6mr2754410wmb.4.1486239082197; Sat, 04 Feb 2017 12:11:22 -0800 (PST) Received: from [192.168.83.175] ([212.76.254.194]) by smtp.gmail.com with ESMTPSA id 18sm51588093wrb.14.2017.02.04.12.11.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 12:11:21 -0800 (PST) Subject: Re: Cannot shutdown subscriber after DROP SUBSCRIPTION To: Fujii Masao , Kyotaro HORIGUCHI References: <1289.1486012392@sss.pgh.pa.us> <20170203.105635.240968059.horiguchi.kyotaro@lab.ntt.co.jp> Cc: Michael Paquier , Tom Lane , PostgreSQL-development From: Petr Jelinek Message-ID: Date: Sat, 4 Feb 2017 21:11:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 03/02/17 19:38, Fujii Masao wrote: > On Sat, Feb 4, 2017 at 12:49 AM, Fujii Masao wrote: >> On Fri, Feb 3, 2017 at 10:56 AM, Kyotaro HORIGUCHI >> wrote: >>> At Fri, 3 Feb 2017 01:02:47 +0900, Fujii Masao wrote in >>>> On Thu, Feb 2, 2017 at 2:36 PM, Michael Paquier >>>> wrote: >>>>> On Thu, Feb 2, 2017 at 2:13 PM, Tom Lane wrote: >>>>>> Kyotaro HORIGUCHI writes: >>>>>>> Then, the reason for the TRY-CATCH cluase is that I found that >>>>>>> some functions called from there can throw exceptions. >>>>>> >>>>>> Yes, but all LWLocks should be released by normal error recovery. >>>>>> It should not be necessary for this code to clean that up by hand. >>>>>> If it were necessary, there would be TRY-CATCH around every single >>>>>> LWLockAcquire in the backend, and we'd have an unreadable and >>>>>> unmaintainable system. Please don't add a TRY-CATCH unless it's >>>>>> *necessary* -- and you haven't explained why this one is. >>>> >>>> Yes. >>> >>> Thank you for the suggestion. I minunderstood that. >>> >>>>> Putting hands into the code and at the problem, I can see that >>>>> dropping a subscription on a node makes it unresponsive in case of a >>>>> stop. And that's just because calls to LWLockRelease are missing as in >>>>> the patch attached. A try/catch problem should not be necessary. >>>> >>>> Thanks for the patch! >>>> >>>> With the patch, LogicalRepLauncherLock is released at the end of >>>> DropSubscription(). But ISTM that the lock should be released just after >>>> logicalrep_worker_stop() and there is no need to protect the removal of >>>> replication slot with the lock. >>> >>> That's true. logicalrep_worker_stop returns after confirmig that >>> worker->proc is cleard, so no false relaunch cannot be caused. >>> After all, logicalrep_worker_stop is surrounded by >>> LWLockAcquire/Relase pair. So it can be moved into the funciton >>> and make the lock secrion to be more narrower. > > If we do this, Assert(LWLockHeldByMe(LogicalRepLauncherLock)) should be > removed and the comment for logicalrep_worker_stop() should be updated. > > Your approach may cause the deadlock. The launcher takes LogicalRepWorkerLock > while holding LogicalRepLauncherLock. OTOH, with your approach, > logicalrep_worker_stop() takes LogicalRepLauncherLock while holding > LogicalRepWorkerLock. > > Therefore I pushed the simple patch which adds LWLockRelease() just after > logicalrep_worker_stop(). > > Another problem that I found while reading the code is that the launcher can > start up the worker with the subscription that DROP SUBSCRIPTION just removed. > That is, DROP SUBSCRIPTION removes the target entry from pg_subscription, > but the launcher can see it and start new worker until the transaction for > DROP has been committed. > That was the reason why DropSubscription didn't release the lock in the first place. It was supposed to be released at the end of the transaction though. > To fix this issue, I think that DROP SUBSCRIPTION should take > AccessExclusiveLock on pg_subscription, instead of RowExclusiveLock, > so that the launcher cannot see the entry to be being removed. > The whole point of having LogicalRepLauncherLock is to avoid having to do this, so if we do this we could probably get rid of it. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers