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 1rDhu8-002suf-FD for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Dec 2023 09:21:16 +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 1rDhu6-0063Iw-PM for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Dec 2023 09:21:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rDhu6-0063Ih-FV for pgsql-hackers@lists.postgresql.org; Thu, 14 Dec 2023 09:21:14 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rDhtz-00Bw7O-Vw for pgsql-hackers@lists.postgresql.org; Thu, 14 Dec 2023 09:21:13 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-1f055438492so5988021fac.3 for ; Thu, 14 Dec 2023 01:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702545666; x=1703150466; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vWVQMKVLxsUC781YfUUDQd2GYhPbsIfwFBs9lj6yFNg=; b=BQTHjvhayXovdJrx3h3nnqJPinBIB9enCVi3qHaNk+qpNvHC7exqv8gQpjl/zrTY6v akwmKDtYNQwrjQR6cwObbqo7RrmrADYj+LxnIVr0lB5vtEfqULlrYmOFq0eJdxu6cihA cCLFNnxa2XhDuGbZ/+Lwr271c/giYhf5/dFwZXk1jjPlt9IsysM8oFlC9sLHkV5Uk95i BPr+otX1zMMhRYYp4eRj6YLvmA+DVdm4jiitLiJiHJGc7q5zEewTS6PYux8j6aJN1ebU 9GBS8XWCGZuA7k6SsPnEb1g/Q0Vr3BPFq8O+CcqELrtA2QoVyGAxRuNUbrt2Wf2tBeDF H1aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702545666; x=1703150466; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vWVQMKVLxsUC781YfUUDQd2GYhPbsIfwFBs9lj6yFNg=; b=iDEHAWqEYhLM077zCsSOQjVtVN0mLgl/2QUkXwzxsZasbZyM4BP0qlVFgXtciWA6SD EpcF2iE3/+MWbkenUvPDAxopCrIWYeOVb1i3jn8qabnr9S/aHh3+jsX8M3BnEx6druhV JiR3Y+gfcjcKkROTiH5A3/AsJTTKg4IHWeTKOLvrzqfn8uz7WKN7nbXb0zjTI/Vr2L/q YP2SsW38DPtyQKOk/W426mj8NIeHDxLOPj/QZ8V3QF2AEETG1a293AGOL/CVktG2EmlZ bsXw38H22x1ppUCcheMUcOUE2PjblZKemYCzFP75ViTqfeuehQGI6QChSfLaTQcpgO0R DWLw== X-Gm-Message-State: AOJu0Yyi/p4mQXpjm1R+e0w5WqCZ9FDkoeDhUH2sQ0f33NyPTtbqffpd V+BSyw+U4PxLSs5ZSxO7Ed1YCFG3uwtGg9x847s= X-Google-Smtp-Source: AGHT+IH1+QDiAL6s+GV98fQBl3ny2aJV76le3c0rke486v5Zb4q/rZA/Y8VwYL2dSxn7uypgK3j1FMD4/mjDN8hs1IQ= X-Received: by 2002:a05:6871:809:b0:1fa:f404:b94b with SMTP id q9-20020a056871080900b001faf404b94bmr11119604oap.58.1702545665939; Thu, 14 Dec 2023 01:21:05 -0800 (PST) MIME-Version: 1.0 References: <36f3a200-f185-887c-da08-fdc866436e6c@enterprisedb.com> <195be236-7580-72c6-97c7-59f06c4e093c@enterprisedb.com> <4954a4f8-ba9d-d352-571b-7b94372ea5ae@enterprisedb.com> <418ff5ac-1664-9038-8ac6-0dd308b5df07@enterprisedb.com> <8a2f25d8-23d4-4ab8-2a23-7c8d2d976209@enterprisedb.com> In-Reply-To: From: Amit Kapila Date: Thu, 14 Dec 2023 14:50:54 +0530 Message-ID: Subject: Re: logical decoding and replication of sequences, take 2 To: Ashutosh Bapat Cc: Dilip Kumar , Tomas Vondra , "Hayato Kuroda (Fujitsu)" , "Zhijie Hou (Fujitsu)" , PostgreSQL Hackers , Masahiko Sawada , Peter Eisentraut Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 14, 2023 at 2:45=E2=80=AFPM Ashutosh Bapat wrote: > > On Thu, Dec 14, 2023 at 12:37=E2=80=AFPM Dilip Kumar wrote: > > > > I think you forgot to attach the patch. > > Sorry. Here it is. > > On Thu, Dec 14, 2023 at 2:36=E2=80=AFPM Amit Kapila wrote: > > > > > > > It looks like the solution works. But this is the only place where we > > process a change before SNAPSHOT reaches FULL. But this is also the > > only record which affects a decision to queue/not a following change. > > So it should be ok. The sequence_hash'es as separate for each > > transaction and they are cleaned when processing COMMIT record. > > > > > > > But it is possible that even commit or abort also happens before the > > snapshot reaches full state in which case the hash table will have > > stale or invalid (for aborts) entries. That will probably be cleaned > > at a later point by running_xact records. > > Why would cleaning wait till running_xact records? Won't txn entry > itself be removed when processing commit/abort record? At the same the > sequence hash will be cleaned as well. > > > Now, I think in theory, it > > is possible that the same RelFileLocator can again be allocated before > > we clean up the existing entry which can probably confuse the system. > > How? The transaction allocating the first time would be cleaned before > it happens the second time. So shouldn't matter. > It can only be cleaned if we process it but xact_decode won't allow us to process it and I don't think it would be a good idea to add another hack for sequences here. See below code: xact_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf) { SnapBuild *builder =3D ctx->snapshot_builder; ReorderBuffer *reorder =3D ctx->reorder; XLogReaderState *r =3D buf->record; uint8 info =3D XLogRecGetInfo(r) & XLOG_XACT_OPMASK; /* * If the snapshot isn't yet fully built, we cannot decode anything, so * bail out. */ if (SnapBuildCurrentState(builder) < SNAPBUILD_FULL_SNAPSHOT) return; --=20 With Regards, Amit Kapila.