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 1pXWzX-0005pu-GI for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 00:40:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXWzV-0002c3-Bh for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 00:40:13 +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 1pXWzU-0002bu-Th for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 00:40:13 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXWzS-0007mh-2e for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 00:40:11 +0000 Received: by mail-pf1-x42e.google.com with SMTP id n5so9090975pfv.11 for ; Wed, 01 Mar 2023 16:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20210112.gappssmtp.com; s=20210112; t=1677717608; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=K1b94fNXIU95BdTZigorpoaPAcB0MpV+Yca9TaM8ahM=; b=HDlQ7sgnTymENj0dlqW7JA3T14+HEa8i0R2rVaVIAZOBboYr4YmdLv2TKa8/i5vkJN 1wrS4AYej3ffYPvgKBtDC7+giHoMUAvtjLqqjCZg5SCHNLLcrWVuEzH1p2hdOmSZppRG 3fibIKs//msQp4d+1dw/b8WsGOOjP5F6UFsXfV58TzFxx/QOmjaqukrFHBZC/xCBDhS3 GZpUqGAsFXgObnXraW3LkqNED39jd0WhRZjDH+kZ+pB7WeeQlU+RaFz+7Qh+v9M13Y0O X8szRL15SBj+oQuMy4FNn+jDYo5TenmH2HmU8mh7pTyOyN0ZUcXjoVKjXiQfm8uFrDJ/ N3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677717608; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=K1b94fNXIU95BdTZigorpoaPAcB0MpV+Yca9TaM8ahM=; b=CKf91nh4O2121Mq9zknlL58P+H/jpS7FlOddQyTP6yAVScvCmkDTR31Vj1wybB6kLb +QUnZAdFZbEHpWMlndtE3HI1C+nt3IqRNHFmGd17zquzrWqigGxzhOpjzN13L7Xvfyoa TX1dQKgVOuea0bPX7Ml9i414oaQwwYWnw9uP5xKfy6MecC3ZG9yQIMlTez7453i7gu56 VpuaGW5cr6FbVZ0cDA08bFr8S3nKYXQDAtJFCfgXrJDflgnmgCFdYIKnaeWZ8zAIAQoI Yf/1dXY7jsqF1KkDFTrQj5Xak8V40tH9WUBCK0EfVVmU9w25WEtq8FWF8Mj/pkIdsmPE fdSg== X-Gm-Message-State: AO0yUKV63u/CPqQ342hAMF8Vt73L0OclozqaxjIrAneWZ33nQC+E0NHs GIctG1bmhpNHxDHAXK+pVlOd8w== X-Google-Smtp-Source: AK7set9o9RjbVtw705FeQEEaz+BX8EyxmyQOjEdZz6mnJxH84lSBZTc9DXSW70N3H64rwAnXZPV9YQ== X-Received: by 2002:a62:4ed0:0:b0:594:26a7:cbd2 with SMTP id c199-20020a624ed0000000b0059426a7cbd2mr432443pfb.8.1677717607974; Wed, 01 Mar 2023 16:40:07 -0800 (PST) Received: from jeff-laptop.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id u24-20020a62ed18000000b005a8bc11d259sm8744063pfh.141.2023.03.01.16.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 16:40:07 -0800 (PST) Message-ID: Subject: Re: Minimal logical decoding on standbys From: Jeff Davis To: "Drouvot, Bertrand" , Andres Freund Cc: Robert Haas , Thomas Munro , Alvaro Herrera , Ibrar Ahmed , Amit Khandekar , fabriziomello@gmail.com, tushar , Rahila Syed , pgsql-hackers Date: Wed, 01 Mar 2023 16:40:05 -0800 In-Reply-To: <061eeb26-156e-6011-02b6-b4b1422e2aa6@gmail.com> References: <1f2ad9fd-53ff-74cc-a602-72d45423bcab@gmail.com> <05c0c4f3-82eb-bc6d-c876-5a265c05927b@gmail.com> <20230106034036.2m4qnn7ep7b5ipet@awork3.anarazel.de> <490206c5-bcde-e558-628a-dc67dae4d439@gmail.com> <20230119024617.jzsgpcrgjdc6ysge@awork3.anarazel.de> <94d9d47e-72f4-393a-246e-e3fe8db7b741@gmail.com> <2d314c22b9e03415aa1c7d8fd1f698dae60effa7.camel@j-davis.com> <061eeb26-156e-6011-02b6-b4b1422e2aa6@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-03-01 at 11:51 +0100, Drouvot, Bertrand wrote: >=20 > Why not "simply" call ConditionVariablePrepareToSleep() without any > call to ConditionVariableTimedSleep() later? ConditionVariableSleep() re-inserts itself into the queue if it was previously removed. Without that, a single wakeup could remove it from the wait queue, and the effects of ConditionVariablePrepareToSleep() would be lost. > In that case the walsender will be put in the wait queue (thanks to > ConditionVariablePrepareToSleep()) > and will be waked up by the event on the socket, the timeout or the > CV broadcast I believe it will only be awakened once, and if it enters WalSndWait() again, future ConditionVariableBroadcast/Signal() calls won't wake it up any more. > (since IIUC they all rely on the same latch). Relying on that fact seems like too much action-at-a-distance to me. If we change the implementation of condition variables, then it would stop working. Also, since they are using the same latch, that means we are still waking up too frequently, right? We haven't really solved the problem. > That looks weird to use ConditionVariablePrepareToSleep() without > actually using ConditionVariableTimedSleep() > but it looks to me that it would achieve the same goal: having the > walsender being waked up > by the event on the socket, the timeout or the CV broadcast. I don't think it actually works, because something needs to keep re- inserting it into the queue after it gets removed. You could maybe hack it to put ConditionVariablePrepareToSleep() *in* the loop, and never sleep. But that just seems like too much of a hack, and I didn't really look at the details to see if that would actually work. To use condition variables properly, I think we'd need an API like ConditionVariableEventsSleep(), which takes a WaitEventSet and a timeout. I think this is what Andres was suggesting and seems like a good idea. I looked into it and I don't think it's too hard to implement -- we just need to WaitEventSetWait instead of WaitLatch. There are a few details to sort out, like how to enable callers to easily create the right WaitEventSet (it obviously needs to include MyLatch, for instance) and update it with the right socket events. --=20 Jeff Davis PostgreSQL Contributor Team - AWS