Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKYAA-00028i-L1 for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jun 2017 22:50:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dKYA9-0002P8-Pq for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jun 2017 22:50:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dKY9S-000175-AD for pgsql-bugs@postgresql.org; Mon, 12 Jun 2017 22:49:38 +0000 Received: from mail-qt0-x230.google.com ([2607:f8b0:400d:c0d::230]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dKY9K-0002mD-Mp for pgsql-bugs@postgresql.org; Mon, 12 Jun 2017 22:49:37 +0000 Received: by mail-qt0-x230.google.com with SMTP id u12so146837079qth.0 for ; Mon, 12 Jun 2017 15:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=S8RGNJH30UEwcBJZEJmOs8oo1d+AijruEKerW1FVGqw=; b=jNfbkhflufiPey2vmj4g6uYWqrTvZIOJAnuGjdfczfIu395MmrVAPfr79Ntkc63VQA ph4NGRpfyyfKvLslwkkOrXAKTwoTkVPOJlxVMERIF4h+jZjh8KJWtyYbMWGdeltS80IK qCrEIJU2iXaTqn00gV4v4cwHkPff1AdazZL9G2OG4MD/Uz+060Bt8TIj2rrv197FN4Hy N9zHnnCGxADWMmOkOjIf9ehH19+2vFrbzRDxTZiqw52/zx9NP2MSPMCkg7qkpAb11HR+ Gi4WY32rvs1fwFWwxU8WBs4K9QuJ8E1yS5BQKecUZ2GzNfRNNAT4bLVe7cB37hv8nhQr 6Kgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=S8RGNJH30UEwcBJZEJmOs8oo1d+AijruEKerW1FVGqw=; b=m0/SM37TbeGoOJcZSBKHMpDJ2xwnmUonG123odWpl4sWmLjBVoyeqTbu8L76Uq2/Sw MaKlyMVU4ejIQ4qh5cI3SXKBtK7rhXf3G/133iPViOI4VwkLCq5kqRwpqP3WgjbyAmHE p4645RUFL7TaKf8gwCHN8wnb+YxaXCDzacKg4U3kmQN417o81uIAxJnsIk9OFCezwIgN Ce63jKfNsewStgge7W5T1UC89cFBz1VIvIhemtUC1AJcALqoAIDluQv4nda1DQgNZbCN 10DkLOUr1OKheuANmB9a21TUhpa6LDfmDHOI26Hd3odGnFRUdPc0VTi988lOTdSGBCR7 Gr0w== X-Gm-Message-State: AKS2vOwNgQZrrV6aeMb5fHPDhQsgZlWbBU5XqVAQBBxv2gZgxQ3vzy97 nGK1nGrZtU+qSqYD X-Received: by 10.200.57.228 with SMTP id v91mr17163121qte.116.1497307768270; Mon, 12 Jun 2017 15:49:28 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([179.57.115.10]) by smtp.gmail.com with ESMTPSA id l185sm7411970qke.36.2017.06.12.15.49.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:49:27 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 9A0E87A4; Mon, 12 Jun 2017 19:49:25 -0300 (-03) Date: Mon, 12 Jun 2017 18:49:25 -0400 From: Alvaro Herrera To: Michael Paquier Cc: wangchuanting , PostgreSQL mailing lists Subject: Re: Re: BUG #14680: startup process on standby encounter a deadlock of TwoPhaseStateLock when redo 2PC xlog Message-ID: <20170612224925.h3tiogbfj4cjeobu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier wrote: > On Sun, Jun 11, 2017 at 12:24 PM, Alvaro Herrera > wrote: > I have reworked the comment as follows: > /* > - * Don't need a lock in the recovery phase. > + * It is fine to access TwoPhaseState without a lock here: recovery is > + * finished (so if we were a standby, there's no master that can prepare > + * transactions anymore), and we haven't yet set WAL as open for writes, > + * so local existing backends, if any, cannot do so either. We could use a > + * coding pattern similar to restoreTwoPhaseData, i.e., run the whole loop > + * with the lock held; but this loop is far more complex, so instead only > + * grab the lock while calling the low-level functions working directly on > + * manipulating the two-phase state data. Functions working directly on > + * PGPROC entries linked with the two-phase transaction work with other > + * types of locks but we don't want to complicate that more than necessary. > */ Hmm. Honestly I don't like the final sentence you added. I find it more confusing than useful, because it doesn't explain what these "other types of locks" are, or why we care. However, I found out that this rationale is likely not true, because the checkpointer may be running concurrently with this code from startup process, and checkpointer does process 2PC data. Maybe there are other reasons why there's no live bug here, but it looks wrong (I didn't try to reproduce a problem). -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs