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 1nQQ2I-0002ix-0n for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Mar 2022 08:45:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nQQ2G-0007A6-Np for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Mar 2022 08:45:08 +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 1nQQ2G-00079x-57 for pgsql-hackers@lists.postgresql.org; Sat, 05 Mar 2022 08:45:08 +0000 Received: from mail-vk1-xa31.google.com ([2607:f8b0:4864:20::a31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nQQ2D-0006zH-Ru for pgsql-hackers@lists.postgresql.org; Sat, 05 Mar 2022 08:45:07 +0000 Received: by mail-vk1-xa31.google.com with SMTP id t69so3117800vkc.5 for ; Sat, 05 Mar 2022 00:45:05 -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; bh=7+jnRfHbUFXjbvd6nXMX2JznJQaSIJThNGHfLXc4LOA=; b=BA6MOeU1WNd3bvLXZldjZBpXjWRHQBqeAw54+s+Xs9WSuRE67dp2fEmhqNBXhf2BSb xRU24nHkDcxSZ5ELyuZsk3UcAqe1yHPGC+bLMQUq4+HmoZ0UpNUD9MMPqyARPQzHDHFM eb/yPZ+mQhLhZI62KBoulVYFof/9L63VdBwLudOJLAtsjvu4KFqaM2jKUKNMVtZgju+M 7CQnKPY8aRu+ht3SpAG4rJtYQvA1IpBzKVtPmhEe78+Abzf+bQK02U/mwqYBQcCFozPf fEO0QCrGVc0UFfnamxAcUID28ujTu2oJJFYpeC+Wy+2lQ9BrHvu0/Yd4/wS6jaXF9b24 n0Ug== 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; bh=7+jnRfHbUFXjbvd6nXMX2JznJQaSIJThNGHfLXc4LOA=; b=e33ZBE3PfTJOJ4uBDmsbkzyo82X0DqMTBflw4UQI3RBpayp74j07piCohl1rfgwbJk 9008zeeRQzA8lKvRfwIFrDXd78SC0h7+eslve0bvZydi7bPOcAUCjDxIevWv0w5jj+zx Huv+9payWfcTbANvOPGXyC8VxLJQJAeaAmNDZUrRAErxVqtHrGG/9wQZ9iIomAR7+Iu/ iaUQCeky5kvZS1peHYYt/4qsyRqAV9f0pvbiSUp2o7ZwMg/25Cs+UeNM4l16+0oePA4I O2CwQ50RcbO63hXZPuBeo4/NoR/qgbK8aEeSEgxXPKqoc2qHBfnNJa9Uxq72cEDirZ93 1rqQ== X-Gm-Message-State: AOAM533i70GYe6wX62Jih+BN+swBOmp2mUZqm2Xl2KzSvhN3WpDytuVY c7r7jQ7Ug/HRRj9BmM4iCMXZVDO9r2Q9DWSbuWY2ZhU4rQM= X-Google-Smtp-Source: ABdhPJwGBjYGY25JKwNK3vP3/VAjihV105RicMa3yPIrpu3EGWIBbDlgFlVp9gi+suBDve0q08Omw+j6XAVeLew4t6o= X-Received: by 2002:a05:6122:d93:b0:331:4fb0:7162 with SMTP id bc19-20020a0561220d9300b003314fb07162mr978290vkb.4.1646469904650; Sat, 05 Mar 2022 00:45:04 -0800 (PST) MIME-Version: 1.0 References: <20220228185732.GB944837@nathanxps13> <20220301060528.GA1026683@nathanxps13> <20220301.163431.1826638724406024793.horikyota.ntt@gmail.com> <20220301170537.GA1031413@nathanxps13> <20220301212700.GB1033258@nathanxps13> <20220304195602.GA1184024@nathanxps13> In-Reply-To: <20220304195602.GA1184024@nathanxps13> From: Bharath Rupireddy Date: Sat, 5 Mar 2022 14:14:54 +0530 Message-ID: Subject: Re: Allow async standbys wait for sync replication To: Nathan Bossart Cc: Kyotaro Horiguchi , SATYANARAYANA NARLAPURAM , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Mar 5, 2022 at 1:26 AM Nathan Bossart wrote: > > 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(). I understand. Even if we use the SyncRepWaitForLSN approach, the async walsenders will have to do nothing in WalSndLoop() until the sync walsender wakes them up via SyncRepWakeQueue. For sure, the SyncRepWaitForLSN approach avoids extra looping and makes the code look better. One concern is that increased burden on SyncRepLock the SyncRepWaitForLSN approach will need to take (LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);), now that the async walsenders will get added to the list of backends that contened for SyncRepLock. Whereas the other approach that I earlier proposed would require SyncRepLock shared mode as it just needs to read the flushLSN. I'm not sure if it's a bigger problem. Having said above, I agree that the SyncRepWaitForLSN approach makes things probably easy and avoids the new wait loops. Let me think more and work on this approach. Regards, Bharath Rupireddy.