Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nNskK-0000ez-DW for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Feb 2022 08:48:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nNskI-00023v-DJ for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Feb 2022 08:48:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nNskI-00023l-2S for pgsql-hackers@lists.postgresql.org; Sat, 26 Feb 2022 08:48:06 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nNskF-0005Ud-Gq for pgsql-hackers@lists.postgresql.org; Sat, 26 Feb 2022 08:48:05 +0000 Received: by mail-pj1-x102e.google.com with SMTP id g7-20020a17090a708700b001bb78857ccdso10464356pjk.1 for ; Sat, 26 Feb 2022 00:48:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=auCIS7qVhYVJXMWrXXZnH2+avAWT5j2qNaZSCDy6UpI=; b=Gcr8U7VL6GJMJz0t5P1dpokLWZHwJ5ds7YJlKGKeNq0ttGJgF8aV6SpXpM/W84smPS zFEAujVJN4OyrSAZLfDhZtQjZq+H1fyHvHDiFt8Es2cbOX9B3p9PKKw/Fi2zidfsXIOU +n7Zlj335i3JDXviPAw4lk9IEdZbmXJ1k/601T+vgm/JfgdyPKRsDD3pFIYYUtm7hV5t qeXgHO6ADXM8xQWRZ2UINYQyGJ3HvVI76pDufxPTNXIVZwSlJ1kkNyg47PzCOgQJKmz3 g2ckvqh1QZHlUrmmi0EUyvxyumk+CB9imBILgyLs+2wUL+kQhREzFS4P2mwRbypzMKGK yjdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=auCIS7qVhYVJXMWrXXZnH2+avAWT5j2qNaZSCDy6UpI=; b=VzOhelSUtFhlLrnnXnUPBjBdUY+wcRlapv7J4OzGpMObK+YbEzJIhDh7E/ZEcBX9uW q2lvgUU/4P7cigTp/IpcGXFZwYCjISDZ8vlCLGMGYHuGmX6Dkb1WTXRq28Vc/E+OcOUM 8Hmfysq7Y+uI+0hux9Atm29S4u3Sf3slPJWLW6enmbZcqx4y+ZOZB7vIz/ma5JIBHiEw C3iNPM7ulCu9l0etajm7ejsRteOy6lyBDkB8eUs6d3jduOZzP2ZDF5HUdu6GKREOmlHy 44aonggntfQ4vPtfUR9cfuwlOFuP3ED2z86tmlnsaOL4WJkwvvqorpqcPZY+G/RvS6ga nVug== X-Gm-Message-State: AOAM532TFI6oVRDsh8GqdSk/M9nqX5pL1tSVjDgXKcDzIxvSBlcMwYh4 XoRjVIpGqqXov4Nr3bFJjKOCemzFuXZmpMFVOmc= X-Google-Smtp-Source: ABdhPJzKKo9yFawslkAJVeB240UKRB3TgIvqK4HmTyglC9vZSyu7SjHiIhmccy1EP/fIxPe2P2HsqRpeb3pgGtcWhr4= X-Received: by 2002:a17:902:eecb:b0:14f:dfe5:d7a4 with SMTP id h11-20020a170902eecb00b0014fdfe5d7a4mr11094770plb.131.1645865281397; Sat, 26 Feb 2022 00:48:01 -0800 (PST) MIME-Version: 1.0 References: <20220225193819.GB662561@nathanxps13> In-Reply-To: <20220225193819.GB662561@nathanxps13> From: Bharath Rupireddy Date: Sat, 26 Feb 2022 14:17:50 +0530 Message-ID: Subject: Re: Allow async standbys wait for sync replication (was: Disallow quorum uncommitted (with synchronous standbys) txns in logical replication subscribers) To: Nathan Bossart Cc: SATYANARAYANA NARLAPURAM , PostgreSQL Hackers 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 Sat, Feb 26, 2022 at 1:08 AM Nathan Bossart w= rote: > > On Fri, Feb 25, 2022 at 08:31:37PM +0530, Bharath Rupireddy wrote: > > Thanks Satya and others for the inputs. Here's the v1 patch that > > basically allows async wal senders to wait until the sync standbys > > report their flush lsn back to the primary. Please let me know your > > thoughts. > > I haven't had a chance to look too closely yet, but IIUC this adds a new > function that waits for synchronous replication. This new function > essentially spins until the synchronous LSN has advanced. > > I don't think it's a good idea to block sending any WAL like this. AFAIC= T > it is possible that there will be a lot of synchronously replicated WAL > that we can send, and it might just be the last several bytes that cannot > yet be replicated to the asynchronous standbys. =D0=86 believe this patc= h will > cause the server to avoid sending _any_ WAL until the synchronous LSN > advances. > > Perhaps we should instead just choose the SendRqstPtr based on the curren= t > synchronous LSN. Presumably there are other things we'd need to consider= , > but in general, I think we ought to send as much WAL as possible for a > given call to XLogSendPhysical(). A global min LSN of SendRqstPtr of all the sync standbys can be calculated and the async standbys can send WAL up to global min LSN. This is unlike what the v1 patch does i.e. async standbys will wait until the sync standbys report flush LSN back to the primary. Problem with the global min LSN approach is that there can still be a small window where async standbys can get ahead of sync standbys. Imagine async standbys being closer to the primary than sync standbys and if the failover has to happen while the WAL at SendRqstPtr isn't received by the sync standbys, but the async standbys can receive them as they are closer. We hit the same problem that we are trying to solve with this patch. This is the reason, we are waiting till the sync flush LSN as it guarantees more transactional protection. Do you think allowing async standbys optionally wait for either remote write or flush or apply or global min LSN of SendRqstPtr so that users can choose what they want? > > I've done pgbench testing to see if the patch causes any problems. I > > ran tests two times, there isn't much difference in the txns per > > seconds (tps), although there's a delay in the async standby receiving > > the WAL, after all, that's the feature we are pursuing. > > I'm curious what a longer pgbench run looks like when the synchronous > replicas are in the same region. That is probably a more realistic > use-case. We are performing more tests, I will share the results once done. Regards, Bharath Rupireddy.