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 1rNsgW-00GeF1-EU for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jan 2024 10:53:17 +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 1rNsgT-00Awvi-En for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jan 2024 10:53:13 +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 1rNsgT-00AwvY-56 for pgsql-hackers@lists.postgresql.org; Thu, 11 Jan 2024 10:53:13 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rNsgQ-000zVh-Kk for pgsql-hackers@postgresql.org; Thu, 11 Jan 2024 10:53:12 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-595b3644acbso2614743eaf.1 for ; Thu, 11 Jan 2024 02:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704970388; x=1705575188; darn=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=JbuOF4XE5nk95ED2MXh1cdwpgUnTjhR5tAJ0DmhnXsM=; b=Z/jHqt1UzXdoVM7TBo2P42uhwkD3M9K7VuLC0aJO/8g2ak7Mnt3BrFZvqRbEfM+B4f IufMAY259XdYy4nG84hNRpMwEt0DHLCa2e3Tki1kEAwEnp1HH+Om/AW9Z1h8gUAEKOPd 5pz9B0QyA0m9vxEKvU4VpMbv/hONwYPODFJklex5Ng8/L/YXgLnKfAKTiY3p2EdNrztR 03v6WKT+TTomYWNfkCcGltirXLHpS6RtJlK6EU/jUEb6jzvIGEuSqLOYIn7GMbdOMXk/ vbWuW0qXgPojdhu4Mn38ZAuMSD4nrJQyg9iqEBlyv7v2BaxeEgyPNqFtdWnqsMdaG6vL 81Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704970388; x=1705575188; 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=JbuOF4XE5nk95ED2MXh1cdwpgUnTjhR5tAJ0DmhnXsM=; b=VrJKK59TfwvtTFSglBqm1JPjIUC8bFfN5dlIXqXF/9/1Ri0usBI9aH+U7OUZc7olB4 kYBtemvHy/gdx5+OavyQE6faQn6pQdaf58al34KwaC3hZ+DrvK9Lag/wS/WZBLb8mSRL zW42qouTJGTz2ZPaNnxGZTDnpZ1IFnnmWTQ4/FUbeTDn8oTqxT0jmRsyVih4FdyQCYcP 5YVvZwZGr1Z6VYesfep/ZQNDmWtEdp3XJvyEM2XWUhHEVMr80ykUuh6+BQvljjbalq2B Is20UXBtd1TPFL8NXjSgcF0eD2GH3TwO8TCXPQIKrFIJQyInXj0OOHQcO4THt4TjbL+y l1CA== X-Gm-Message-State: AOJu0YxpjsUpqVMnnWv/L8VYahmEf8ae9M4ojfEaa1cTTOGYJC3wdm9F +qOEcoqH40NMNUxRQ9C7nAkMSKkNMEn0jl/b+dM= X-Google-Smtp-Source: AGHT+IGsltu76Kt5LT1DD6K/2mEsMs3wGpqUiN80GwuItDY+JXtT0vd1b4+c2zd9kR2Cni3PMxCwuawStwP1vxxQ6Ew= X-Received: by 2002:a05:6870:b4a5:b0:203:a770:6b33 with SMTP id y37-20020a056870b4a500b00203a7706b33mr258461oap.12.1704970388368; Thu, 11 Jan 2024 02:53:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Thu, 11 Jan 2024 16:22:56 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: "Zhijie Hou (Fujitsu)" , Masahiko Sawada , Dilip Kumar , Bertrand Drouvot Cc: shveta malik , Peter Smith , Nisha Moond , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera 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 Tue, Jan 9, 2024 at 6:39=E2=80=AFPM Amit Kapila wrote: > > +static bool > +synchronize_one_slot(WalReceiverConn *wrconn, RemoteSlot *remote_slot) > { > ... > + /* Slot ready for sync, so sync it. */ > + else > + { > + /* > + * Sanity check: With hot_standby_feedback enabled and > + * invalidations handled appropriately as above, this should never > + * happen. > + */ > + if (remote_slot->restart_lsn < slot->data.restart_lsn) > + elog(ERROR, > + "cannot synchronize local slot \"%s\" LSN(%X/%X)" > + " to remote slot's LSN(%X/%X) as synchronization" > + " would move it backwards", remote_slot->name, > + LSN_FORMAT_ARGS(slot->data.restart_lsn), > + LSN_FORMAT_ARGS(remote_slot->restart_lsn)); > ... > } > > I was thinking about the above code in the patch and as far as I can > think this can only occur if the same name slot is re-created with > prior restart_lsn after the existing slot is dropped. Normally, the > newly created slot (with the same name) will have higher restart_lsn > but one can mimic it by copying some older slot by using > pg_copy_logical_replication_slot(). > > I don't think as mentioned in comments even if hot_standby_feedback is > temporarily set to off, the above shouldn't happen. It can only lead > to invalidated slots on standby. > > To close the above race, I could think of the following ways: > 1. Drop and re-create the slot. > 2. Emit LOG/WARNING in this case and once remote_slot's LSN moves > ahead of local_slot's LSN then we can update it; but as mentioned in > your previous comment, we need to update all other fields as well. If > we follow this then we probably need to have a check for catalog_xmin > as well. > The second point as mentioned is slightly misleading, so let me try to rephrase it once again: Emit LOG/WARNING in this case and once remote_slot's LSN moves ahead of local_slot's LSN then we can update it; additionally, we need to update all other fields like two_phase as well. If we follow this then we probably need to have a check for catalog_xmin as well along remote_slot's restart_lsn. > Now, related to this the other case which needs some handling is what > if the remote_slot's restart_lsn is greater than local_slot's > restart_lsn but it is a re-created slot with the same name. In that > case, I think the other properties like 'two_phase', 'plugin' could be > different. So, is simply copying those sufficient or do we need to do > something else as well? > Bertrand, Dilip, Sawada-San, and others, please share your opinion on this problem as I think it is important to handle this race condition. --=20 With Regards, Amit Kapila.