Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ff5Jf-00088U-EA for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jul 2018 15:21:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ff5Jd-00052b-8a for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jul 2018 15:21:33 +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.89) (envelope-from ) id 1ff5Jc-00052T-UE for pgsql-hackers@lists.postgresql.org; Mon, 16 Jul 2018 15:21:33 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ff5JY-0003Dx-Qm for pgsql-hackers@postgresql.org; Mon, 16 Jul 2018 15:21:32 +0000 Received: by mail-wm0-x243.google.com with SMTP id z13-v6so16305900wma.5 for ; Mon, 16 Jul 2018 08:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rDLdp6L+pkjHpARuLjoTGpSGSekumZ/7udEe4KRBPLk=; b=bDZn6vmTUvBHZYuMoOJc4QqO6PiQJeiD3SU1cDuedlgFKn7SNtw2/ZcwI0SqNTajik FOBk5fmlxWttI75zWdAQO4eMymU2WJvNd/38gyqsP6m7UwQUTfM0xXqM3C+5Ho3bUoir rW3ioOpTeYn+2aYHPmdqmPaJh3Cy99wTfU0hIl764mN4OG7hmBYrS1H0610noPtCMVax 6dMjzqb7i7rrk3wbJO9tapk8UoBw5qGgCBUpWMaQTqvocCdvPvpTiChqXOdP/b0TRJK6 4XmYo+K5MDguWHmZISOUZVgI520BEZmouoVwgcIHbeXFbRi2xPt5NDfW4LlNc/zynMZZ d0uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rDLdp6L+pkjHpARuLjoTGpSGSekumZ/7udEe4KRBPLk=; b=Ix63ZXNMuu9bhu1RGaA3xWKCtXWxifPgrOCs2Z05lo4rcn+TOFUMigV+o5mcFVgpEw A2rDYoDBDLX0M3VUYaq7pYM3oZXAUhpCox32c2lOo35Q7Ba51F7ntPmOK/fKndun5OYG hJkcsVDuV8d9DO9c4fSiyje6aFCL8Kvp8x76PjBn1SOwpmKLthRfueK79wFZc5wnz7W0 TOwU8ee0xlBBkKh6AfOrat4VMJ59tgkVIRsTmEaaTG8XJWO55xUTRDXJjB6nhfHN3GCL MW6G/BzwPmvBc1lo2PdH4YSW7nvoA9gPyD/oaa2ifHs6B9PrhTsgORbLmiTXo4BOo9lO Hr0Q== X-Gm-Message-State: AOUpUlEC+T8zWMdyBMCM2kJAGKhmzjTMNm8XEnFuc0sVg+PvqvSCgKVu GJg9oqFnOrfhTe2TIeQxmO5icA== X-Google-Smtp-Source: AAOMgpcwTArzQaUTCCMDKybz6/hBl/MTOhjteplE6DhDVQhpcaxqlgQqh+UQvTEyN4F/KSXdGM3/zg== X-Received: by 2002:a1c:6c03:: with SMTP id h3-v6mr9543984wmc.38.1531754487683; Mon, 16 Jul 2018 08:21:27 -0700 (PDT) Received: from [10.137.2.21] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id r125-v6sm19529282wmb.27.2018.07.16.08.21.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 08:21:27 -0700 (PDT) Subject: Re: [HACKERS] logical decoding of two-phase transactions To: Nikhil Sontakke , David Steele Cc: Andres Freund , Andrew Dunstan , Simon Riggs , Craig Ringer , Peter Eisentraut , Petr Jelinek , Sokolov Yura , Stas Kelvich , Dmitry Dolgov <9erthalion6@gmail.com>, Tom Lane , Masahiko Sawada , PostgreSQL Hackers , Robert Haas References: <782517ca-1e99-06fe-eba9-34f826118289@2ndquadrant.com> <9cac2837-7e58-1cad-3940-27ac0dd7c198@2ndquadrant.com> <20180406162023.wcic5kw73bgswgb6@alap3.anarazel.de> <9ea4c35b-f8ec-220b-2429-b860b49748f3@pgmasters.net> From: Tomas Vondra Message-ID: <0c7e9fb9-01f7-3284-da9e-22b6dde679d4@2ndquadrant.com> Date: Mon, 16 Jul 2018 17:21:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Nikhil, I've been looking at this patch series, and I do have a bunch of comments and questions, as usual ;-) Overall, I think it's clear the main risk associated with this patch is the decode group code - it touches PROC entries, so a bug may cause trouble pretty easily. So I've focused on this part, for now. 1) LogicalLockTransaction does roughly this ... if (MyProc->decodeGroupLeader == NULL) { leader = AssignDecodeGroupLeader(txn->xid); if (leader == NULL || !BecomeDecodeGroupMember((PGPROC *)leader, txn->xid)) goto lock_cleanup; } leader = BackendXidGetProc(txn->xid); if (!leader) goto lock_cleanup; leader_lwlock = LockHashPartitionLockByProc(leader); LWLockAcquire(leader_lwlock, LW_EXCLUSIVE); pgxact = &ProcGlobal->allPgXact[leader->pgprocno]; if(pgxact->xid != txn->xid) { LWLockRelease(leader_lwlock); goto lock_cleanup; } ... I wonder why we need the BackendXidGetProc call after the first if block. Can we simply grab MyProc->decodeGroupLeader at that point? 2) InitProcess now resets decodeAbortPending/decodeLocked flags, while checking decodeGroupLeader/decodeGroupMembers using asserts. Isn't that a bit strange? Shouldn't it do the same thing with both? 3) A comment in ProcKill says this: * Detach from any decode group of which we are a member. If the leader * exits before all other group members, its PGPROC will remain allocated * until the last group process exits; that process must return the * leader's PGPROC to the appropriate list. So I'm wondering what happens if the leader dies before other group members, but the PROC entry gets reused for a new connection. It clearly should not be a leader for that old decode group, but it may need to be a leader for another group. 4) strange hunk in ProcKill There seems to be some sort of merge/rebase issue, because this block of code (line ~880) related to lock groups /* Return PGPROC structure (and semaphore) to appropriate freelist */ proc->links.next = (SHM_QUEUE *) *procgloballist; *procgloballist = proc; got replaced by code relared to decode groups. That seems strange. 5) ReorderBufferCommitInternal I see the LogicalLockTransaction() calls in ReorderBufferCommitInternal have vastly variable comments. Some calls have no comment, some calls have "obvious" comment like "Lock transaction before catalog access" and one call has this very long comment /* * Output plugins can access catalog metadata and we * do not have any control over that. We could ask * them to call * LogicalLockTransaction/LogicalUnlockTransaction * APIs themselves, but that leads to unnecessary * complications and expectations from plugin * writers. We avoid this by calling these APIs * here, thereby ensuring that the in-progress * transaction will be around for the duration of * the apply_change call below */ I find that rather inconsistent, and I'd say those comments are useless. I suggest to remove all the per-call comments and instead add a comment about the locking into the initial file-level comment, which already explains handling of large transactions, etc. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services