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 1nQE29-0006Eu-Gb for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Mar 2022 19:56:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nQE27-0006G0-3g for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Mar 2022 19:56:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nQE26-0006B5-Nb for pgsql-hackers@lists.postgresql.org; Fri, 04 Mar 2022 19:56:10 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nQE22-00017c-P1 for pgsql-hackers@lists.postgresql.org; Fri, 04 Mar 2022 19:56:09 +0000 Received: by mail-pj1-x1030.google.com with SMTP id ev16-20020a17090aead000b001bc3835fea8so8936115pjb.0 for ; Fri, 04 Mar 2022 11:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DFPTkmjNUedNLVRWTFlrssPnzlfwEwm3t3ghJodDdLY=; b=Yeo1dqs40zfUUKuepngO9iK242uoXwSlFwgSFI6uCTMK1rjUutWVm5fBsmsf4L/5oI S9LNkc/NxDI4MEi/uX4K3jq3YJ93z/BcMnqVgRIGDxSKoKuh8PhYDXL63Fs5WvqdGY/G Ab2bdg68371FMEOB/SKEPQKulfNR0tjHgsvVBc6jOc8w0LXSU6JooJNkwmFtlTvgtChn yMmdrvWiJ2dW0XBVHF55+GrCwW7uRwVPr8wY6/F6+gF3wcNE9lGbDSXpcXv0MOGDqnyw H+ep9y0V3UiyjdH3WiWfGrc+VEJN1bT6g4uTgDeue1dUTMAyD+O0A3bvukhHJN6IIZ2Z 46FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DFPTkmjNUedNLVRWTFlrssPnzlfwEwm3t3ghJodDdLY=; b=To/b1egqNNgBQoDJ06dE12CeLwhTgnD/n3hlIaJP59VjQNabjfQsBdh+Ld7dLuPF7+ WIPcV9/as90Qx2rESsLZSxr+/iZO1+dYUtriYrIAaidPF1Oa91SqiejgCAIWNlI+NLw3 f0AkkMV2l9JRg3Ylq7oCjOKdX4mLMYuTp2EfI9warByJWdAPVg4u7TSfWwoEHdGz8kPp +e3h+SzmPuX0BM3fd23GUSMEGohxVx4BuoAErzTyH0SAUrf28bNR5kHfXIa6WtC7pfJE cSPVDfOlM1tgxTlU/bQAPZNCpmNfjAS7RXWVQrB4Q+6EuXOUTDStcY6f1IN/qPqlDp4r PEBg== X-Gm-Message-State: AOAM530cHnRCxv2O3DQzCOLf2W51Cq3UTJ8MUIFonn8EF+wsGkTVU3M6 N44aY9bYouxoTsqnZIxSyQg= X-Google-Smtp-Source: ABdhPJzocfbrrVbhvoa7IDd7mswFyPrPLad4uufPCIYM4ggQnWrh4SdCA0ZVMxD4H7NIigarIRID1A== X-Received: by 2002:a17:902:ecc1:b0:151:9614:59f5 with SMTP id a1-20020a170902ecc100b00151961459f5mr7392plh.132.1646423765581; Fri, 04 Mar 2022 11:56:05 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id n42-20020a056a000d6a00b004d221c3e021sm6630541pfv.55.2022.03.04.11.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 11:56:05 -0800 (PST) Date: Fri, 4 Mar 2022 11:56:02 -0800 From: Nathan Bossart To: Bharath Rupireddy Cc: Kyotaro Horiguchi , SATYANARAYANA NARLAPURAM , PostgreSQL Hackers Subject: Re: Allow async standbys wait for sync replication Message-ID: <20220304195602.GA1184024@nathanxps13> References: <20220228185732.GB944837@nathanxps13> <20220301060528.GA1026683@nathanxps13> <20220301.163431.1826638724406024793.horikyota.ntt@gmail.com> <20220301170537.GA1031413@nathanxps13> <20220301212700.GB1033258@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Mar 02, 2022 at 09:47:09AM +0530, Bharath Rupireddy wrote: > On Wed, Mar 2, 2022 at 2:57 AM Nathan Bossart wrote: >> I think there are a couple of advantages. For one, spinning is probably >> not the best from a resource perspective. > > Just to be on the same page - by spinning do you mean - the async > walsender waiting for the sync flushLSN in a for-loop with > WaitLatch()? Yes. >> Also, this approach might fit in better >> with the existing synchronous replication framework. When a WAL sender >> realizes that it can't send up to the current "flush" LSN because it's not >> synchronously replicated, it will request to be alerted when it is. > > I think you are referring to the way a backend calls SyncRepWaitForLSN > and waits until any one of the walsender sets syncRepState to > SYNC_REP_WAIT_COMPLETE in SyncRepWakeQueue. Firstly, SyncRepWaitForLSN > blocking i.e. the backend spins/waits in for (;;) loop until its > syncRepState becomes SYNC_REP_WAIT_COMPLETE. The backend doesn't do > any other work but waits. So, spinning isn't avoided completely. > > Unless, I'm missing something, the existing syc repl queue > (SyncRepQueue) mechanism doesn't avoid spinning in the requestors > (backends) SyncRepWaitForLSN or in the walsenders SyncRepWakeQueue. My point is that there are existing tools for alerting processes when an LSN is synchronously replicated and for waking up WAL senders. What I am proposing wouldn't involve spinning in XLogSendPhysical() waiting for synchronous replication. Like SyncRepWaitForLSN(), we'd register our LSN in the queue (SyncRepQueueInsert()), but we wouldn't sit in a separate loop waiting to be woken. Instead, SyncRepWakeQueue() would eventually wake up the WAL sender and trigger another iteration of WalSndLoop(). -- Nathan Bossart Amazon Web Services: https://aws.amazon.com