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 1pXAeK-0004gt-QT for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Mar 2023 00:48:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXAeJ-0008MT-Lp for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Mar 2023 00:48:51 +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 1pXAeJ-0008MK-7H for pgsql-hackers@lists.postgresql.org; Wed, 01 Mar 2023 00:48:51 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXAeG-0001sr-EB for pgsql-hackers@postgresql.org; Wed, 01 Mar 2023 00:48:50 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so11012711pjg.4 for ; Tue, 28 Feb 2023 16:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20210112.gappssmtp.com; s=20210112; t=1677631726; 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=D90qFJvoHHYdCIcuQUN1TRCvYA8t7ZhS7V8+eJYfZz8=; b=cm5cZwgZ3/bbwsND9d662TpSZkZoZRiQwg0LBAe2PqzYveQb3jyi4wQPzpcR0Oz9O7 xum0ZRuQiigakGWhkhE5W8JznOQB2R9ssU/+TlBV33ulfKSgeeiwqycQKJFYAUWGRTuv 8Lr3LG49/NzV4T6akudUGo4vOJP6LCJR73W2khIJt+Reax7CHnmkp4yNk73KThXfsELS +Sjf3xWQgb2HRpF9iPeJWTYaF6n/0eZn1OI+p1Xmaxk4Jt5XNFjDjZt5hE9XOcNn5FPr M/tw0qQLh+nkMQBP9Fqc5Uj6DwlaCJGzCO7+OVeY/vswwUOxzOEvQFaza6enUw+rsvSg WE5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677631726; 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=D90qFJvoHHYdCIcuQUN1TRCvYA8t7ZhS7V8+eJYfZz8=; b=IvE1JvWoAd4omaOSY1o2JpDXFs7u+b+xv9EXVM1Mx3GNzA1blRGQzBRLCQpREmOUck RLljHxSguW+PUuY4h+9leVqnu0B0VpBdVo1gn9p9ffrWXccEVu5SG10zWihFif0DgF7Z FFhHeZEM1sCB/BDGfFJH+pZXwQ32+4liyw1U4iQyaAdx7My1uq2Mx18oBTBeqwn1E/pn Eouac0kMh2E3diPiGm/f30YDGPvFsqggSzMUr946Ei7vX9h2pMFHRjwgRomYTc0wrtUL tNKovkpz74i+QIHirVEZNvxjOEaO7RvzjujJ/srMUHfHVifbXwRKcpDZsYYiROCubHxk 9B2w== X-Gm-Message-State: AO0yUKV7zlLSuvE7KVqGWJjjIn3ozN9Q1DTt2FoFvSVcNjsCveyK6JtA vImJuWMmOKEj/kH1NeayDX1+Fg== X-Google-Smtp-Source: AK7set9iKLVcp4dHWN5rBFm8nAk/e27QaCwhDIXk+ryGMoToRTPPy7pE+/OowvVAQHxf3s0Tfodatw== X-Received: by 2002:a17:90b:3147:b0:234:c030:7c7f with SMTP id ip7-20020a17090b314700b00234c0307c7fmr14709127pjb.18.1677631726179; Tue, 28 Feb 2023 16:48:46 -0800 (PST) Received: from [172.18.7.14] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id e9-20020a17090ac20900b00232cc61e16bsm8561841pjt.35.2023.02.28.16.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 16:48:45 -0800 (PST) Message-ID: <2d314c22b9e03415aa1c7d8fd1f698dae60effa7.camel@j-davis.com> 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: Tue, 28 Feb 2023 16:48:44 -0800 In-Reply-To: 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> 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 Mon, 2023-02-27 at 09:40 +0100, Drouvot, Bertrand wrote: > Please find attached V51 tiny rebase due to a6cd1fc692 (for 0001) and > 8a8661828a (for 0005). [ Jumping into this thread late, so I apologize if these comments have already been covered. ] Regarding v51-0004: * Why is the CV sleep not being canceled? * Comments on WalSndWaitForWal need to be updated to explain the difference between the flush (primary) and the replay (standby) cases. Overall, it seems like what you really want for the sleep/wakeup logic in WalSndWaitForLSN is something like this: condVar =3D RecoveryInProgress() ? replayCV : flushCV; waitEvent =3D RecoveryInProgress() ?=20 WAIT_EVENT_WAL_SENDER_WAIT_REPLAY : WAIT_EVENT_WAL_SENDER_WAIT_FLUSH; ConditionVariablePrepareToSleep(condVar); for(;;) { ... sleeptime =3D WalSndComputeSleepTime(GetCurrentTimestamp()); socketEvents =3D WL_SOCKET_READABLE; if (pq_is_send_pending()) socketEvents =3D WL_SOCKET_WRITABLE; ConditionVariableTimedSleepOrEvents( condVar, sleeptime, socketEvents, waitEvent); } ConditionVariableCancelSleep(); But the problem is that ConditionVariableTimedSleepOrEvents() doesn't exist, and I think that's what Andres was suggesting here[1]. WalSndWait() only waits for a timeout or a socket event, but not a CV; ConditionVariableTimedSleep() only waits for a timeout or a CV, but not a socket event. I'm also missing how WalSndWait() works currently. It calls ModifyWaitEvent() with NULL for the latch, so how does WalSndWakeup() wake it up? Assuming I'm wrong, and WalSndWait() does use the latch, then I guess it could be extended by having two different latches in the WalSnd structure, and waking them up separately and waiting on the right one. Not sure if that's a good idea though. [1] https://www.postgresql.org/message-id/20230106034036.2m4qnn7ep7b5ipet@awork= 3.anarazel.de --=20 Jeff Davis PostgreSQL Contributor Team - AWS