Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rShKr-00FLda-KA for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 17:46:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rShKq-0072mr-QU for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 17:46:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rShKq-0072la-BY for pgsql-hackers@lists.postgresql.org; Wed, 24 Jan 2024 17:46:48 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rShKj-003ADl-9W for pgsql-hackers@lists.postgresql.org; Wed, 24 Jan 2024 17:46:47 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-557dcb0f870so7125217a12.2 for ; Wed, 24 Jan 2024 09:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1706118399; x=1706723199; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kCSFyWovTwGkhP6YDmSm/eATpeYzoRKCNkumQRX79q0=; b=bT3QD9ZGV4u0ySwS7KWQV5A/FfCeH6z3tSc+faYUSpVzNphYVRLWmPS2fAoZ+qfPDE WLVDvgVBuMgPyljtvfNslUISprtuBGfSuLpTXOFq4Ynik1cb6W9WnROMu/S9W85qteEt eDtwJda4J6YATFOquGUIneez/kpn/pmE4xFp2AoaIaUuYOjFfQpEKBoOczd0RWA/EGXw Y1xzv+Q5sQ7WSo3ER2UG7Wx9LvryBLgaV4XhfNe6RwKfSYmQYfXyWcaQQ1B7LHdhmqZ8 4usKwVxLJuDrkc2PJyQ+4z3QJwFUtoCv1K0KEeNebleTrdTbvOQ54B+InWOFwXwkuqR0 Wg/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118399; x=1706723199; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kCSFyWovTwGkhP6YDmSm/eATpeYzoRKCNkumQRX79q0=; b=U7gfk1JuPpGBmHyBfrnWPxP2c49IgQ/4Ijtz2wW/rEUwi9BO4licGKEki3E8W9nNUQ 6g0pQ9OxMs1XPL/nRiolWDV/YFWglNThOJ0Wzcz/LUFkg344EBrWzEhfgvtSxzkanmF9 gn2zdRzT79lYkB8RPfATPswsGWDCaHuiXwiW2GC3Sx2HqlOSxMgUNkDz7On01nFC9MTh gypuLH9cUkv3Clo7ChzuyYgbeDDNCsL4+FHIAPLN7rAbMdjq5MMLKO7W7XNRxZw/X23M x2r/oXWkdVfI8mSuNtZ3KOcmIGIjGloSCTVCrX/gqRHGQrYuunv9wiLdQnJup51Zgsi4 etpw== X-Gm-Message-State: AOJu0YzhRyFLG3Z2LAVosY3QOmTJHW1E5ca0hb/OAlkJl/5DasbUlEvo Bh055avUV0sHDcma3mFwZM4K1/Pq4/CDXC7vR2NDE9I/Rr9PoRIt4L1+7pe5Ag== X-Google-Smtp-Source: AGHT+IHfb11+mvePI9qM2CuSkSTXHwxNlPJqmD6PrwNk8h7CH8Nilu1NiQ0MDM9LDqNskdTEjVkPOA== X-Received: by 2002:a05:6402:1ca5:b0:55c:9051:61fa with SMTP id cz5-20020a0564021ca500b0055c905161famr1359501edb.65.1706118399639; Wed, 24 Jan 2024 09:46:39 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id o9-20020a056402444900b00559dd0a5146sm9197399edb.44.2024.01.24.09.46.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Jan 2024 09:46:39 -0800 (PST) Message-ID: <929a38f6-b9f9-4cc4-926a-ac972e769e17@enterprisedb.com> Date: Wed, 24 Jan 2024 18:46:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: logical decoding and replication of sequences, take 2 To: Robert Haas Cc: Amit Kapila , Ashutosh Bapat , Dilip Kumar , "Hayato Kuroda (Fujitsu)" , "Zhijie Hou (Fujitsu)" , PostgreSQL Hackers , Masahiko Sawada , Peter Eisentraut References: <577ec4fc-62c5-cb4a-de0f-66dee8232d00@enterprisedb.com> <09613730-5ee9-4cc3-82d8-f089be90aa64@enterprisedb.com> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/23/24 21:47, Robert Haas wrote: > On Thu, Jan 11, 2024 at 11:27 AM Tomas Vondra > wrote: >> 1) desirability: We want a built-in way to handle sequences in logical >> replication. I think everyone agrees this is not a way to do distributed >> sequences in an active-active setups, but that there are other use cases >> that need this feature - typically upgrades / logical failover. > > Yeah. I find it extremely hard to take seriously the idea that this > isn't a valuable feature. How else are you supposed to do a logical > failover without having your entire application break? > >> 2) performance: There was concern about the performance impact, and that >> it affects everyone, including those who don't replicate sequences (as >> the overhead is mostly incurred before calls to output plugin etc.). >> >> The agreement was that the best way is to have a CREATE SUBSCRIPTION >> option that would instruct the upstream to decode sequences. By default >> this option is 'off' (because that's the no-overhead case), but it can >> be enabled for each subscription. > > Seems reasonable, at least unless and until we come up with something better. > >> 3) correctness: The last point is about making "transactional" flag >> correct when the snapshot state changes mid-transaction, originally >> pointed out by Dilip [4]. Per [5] this however happens to work >> correctly, because while we identify the change as 'non-transactional' >> (which is incorrect), we immediately throw it again (so we don't try to >> apply it, which would error-out). > > I've said this before, but I still find this really scary. It's > unclear to me that we can simply classify updates as transactional or > non-transactional and expect things to work. If it's possible, I hope > we have a really good explanation somewhere of how and why it's > possible. If we do, can somebody point me to it so I can read it? > I did try to explain how this works (and why) in a couple places: 1) the commit message 2) reorderbuffer header comment 3) ReorderBufferSequenceIsTransactional comment (and nearby) It's possible this does not meet your expectations, ofc. Maybe there should be a separate README for this - I haven't found anything like that for logical decoding in general, which is why I did (1)-(3). > To be possibly slightly more clear about my concern, I think the scary > case is where we have transactional and non-transactional things > happening to the same sequence in close temporal proximity, either > within the same session or across two or more sessions. If a > non-transactional change can get reordered ahead of some transactional > change upon which it logically depends, or behind some transactional > change that logically depends on it, then we have trouble. I also > wonder if there are any cases where the same operation is partly > transactional and partly non-transactional. > I certainly understand this concern, and to some extent I even share it. Having to differentiate between transactional and non-transactional changes certainly confused me more than once. It's especially confusing, because the decoding implicitly changes the perceived ordering/atomicity of the events. That being said, I don't think it get reordered the way you're concerned about. The "transactionality" is determined by relfilenode change, so how could the reordering happen? We'd have to misidentify change in either direction - and for nontransactional->transactional change that's clearly not possible. There has to be a new relfilenode in that xact. In the other direction (transactional->nontransactional), it can happen if we fail to decode the relfilenode record. Which is what we discussed earlier, but came to the conclusion that it actually works OK. Of course, there might be bugs. I spent quite a bit of effort reviewing and testing this, but there still might be something wrong. But I think that applies to any feature. What would be worse is some sort of thinko in the approach in general. I don't have a good answer to that, unfortunately - I think it works, but how would I know for sure? We explored multiple alternative approaches and all of them crashed and burned ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company