Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csRKo-0006H1-Dc for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Mar 2017 09:53:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1csRKn-0000TJ-PR for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Mar 2017 09:53:09 +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 1csRKm-0000T9-DU for pgsql-hackers@postgresql.org; Mon, 27 Mar 2017 09:53:08 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csRKi-00006y-AQ for pgsql-hackers@postgresql.org; Mon, 27 Mar 2017 09:53:07 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 9626921C2522; Mon, 27 Mar 2017 12:53:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1490608381; bh=cwoO+Z/yewiOv15t1ll0jqY6fBZ9FgsvJs8Rq7V7QdU=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=pJqxLfw4uz28G2vEOMSDtFdVN3P34Zm01ANE3QEC9VSlram1s0nZMI0C7myLlzcQD pGFnCli/AtqZ7DKH976dh3AEZGLb7IstTkqZQRSq3+W/W5RxqKCRdoWDIj6Raks0Uo KTTV6zLrTKdFp8Antck0Qp/O72V6xdheFTx/HLMo= Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: logical decoding of two-phase transactions From: Stas Kelvich In-Reply-To: Date: Mon, 27 Mar 2017 12:53:01 +0300 Cc: Petr Jelinek , PostgreSQL Hackers , Robert Haas Content-Transfer-Encoding: quoted-printable Message-Id: References: <02DA5F5E-CECE-4D9C-8B4B-418077E2C010@postgrespro.ru> <89073436-925E-4299-A9AF-88D04E55C231@postgrespro.ru> <3477E635-F590-4432-BD20-C59142B65CD3@postgrespro.ru> <1FE466EA-7058-484D-B0DB-42CD81FA59F0@postgrespro.ru> <46ebc39d-82a0-e59f-2552-2ea8911a64e7@2ndquadrant.com> <25A09FA8-5B0E-447D-97FB-F37F3B0E34E9@postgrespro.ru> <8217d096-3641-8022-09e4-4e625633b278@2ndquadrant.com> To: Craig Ringer X-Mailer: Apple Mail (2.3259) X-Pg-Spam-Score: -2.0 (--) 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 27 Mar 2017, at 12:26, Craig Ringer wrote: >=20 > On 27 March 2017 at 09:31, Craig Ringer wrote: >=20 >> We're in the last week of the CF. If you have a patch that's nearly >> ready or getting there, now would be a good time to post it for help >> and input from others. >>=20 >> I would really like to get this in, but we're running out of time. >>=20 >> Even if you just post your snapshot management work, with the cosmetic >> changes discussed above, that would be a valuable start. >=20 > I'm going to pick up the last patch and: I=E2=80=99m heavily underestimated amount of changes there, but almost fini= shed and will send updated patch in several hours. > * Ensure we only add the GID to xact records for 2pc commits and aborts And only during wal_level >=3D logical. Done. Also patch adds origin info to prepares and aborts. > * Add separate callbacks for prepare, abort prepared, and commit > prepared (of xacts already processed during prepare), so we aren't > overloading the "commit" callback and don't have to create fake empty > transactions to pass to the commit callback; Done. > * Add another callback to determine whether an xact should be > processed at PREPARE TRANSACTION or COMMIT PREPARED time. Also done. > * Rename the snapshot builder faux-commit stuff in the current patch > so it's clearer what's going on. Hm. Okay, i=E2=80=99ll leave that part to you. > * Write tests covering DDL, abort-during-decode, etc I=E2=80=99ve extended test, but it is good to have some more. > Some special care is needed for the callback that decides whether to > process a given xact as 2PC or not. It's called before PREPARE > TRANSACTION to decide whether to decode any given xact at prepare time > or wait until it commits. It's called again at COMMIT PREPARED time if > we crashed after we processed PREPARE TRANSACTION and advanced our > confirmed_flush_lsn such that we won't re-process the PREPARE > TRANSACTION again. Our restart_lsn might've advanced past it so we > never even decode it, so we can't rely on seeing it at all. It has > access to the xid, gid and invalidations, all of which we have at both > prepare and commit time, to make its decision from. It must have the > same result at prepare and commit time for any given xact. We can > probably use a cache in the reorder buffer to avoid the 2nd call on > commit prepared if we haven't crashed/reconnected between the two. Good point. Didn=E2=80=99t think about restart_lsn in case when we are skip= ping this particular prepare (filter_prepared() -> true, in my terms). I think that s= hould work properly as it use the same code path as it was before, but I=E2=80=99= ll look at it. > This proposal does not provide a way to safely decode a 2pc xact that > made catalog changes which may be aborted while being decoded. The > plugin must lock such an xact so that it can't be aborted while being > processed, or defer decoding until commit prepared. It can use the > invalidations for the commit to decide. I had played with that two-pass catalog scan and it seems to be working but after some time I realised that it is not useful for the main case when commit/abort is generated after receiver side will answer to prepares. Also that two-pass scan is a massive change in relcache.c and genam.c (FWIW there were no problems with cache, but some problems with index scan and handling one-to-many queries to catalog, e.g. table with it fields) Finally i decided to throw it and switched to filter_prepare callback and passed there txn structure to allow access to has_catalog_changes field. Stas Kelvich Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers