Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDfXR-003DxS-32 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 09:31:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDfXQ-009Ltj-2a for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 09:31:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDfXQ-009LtZ-1Y for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 09:31:00 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDfXO-00000001dKJ-0XFe for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 09:31:00 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-35fb7c1a455so207486a91.3 for ; Fri, 17 Apr 2026 02:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776418256; x=1777023056; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9hVaTRAypks8qC3WDbxaGr71EYAcs46miQkDiiVqXAg=; b=UBJPgtg8BPog2g1YFO61adLfllGq9EFhadpOtP0NdraNRv66y5h3kuFA9I/izhchYH f8M59GBqwum9A1B40s2t5u5b4owEsH7EMDu2VWFMB8vpH7noH0JP6Za/hxwa8W5s5SP9 tOi29OB+EdQNTJgNmJbq50tddiaWy+VWGzDVZQMTnDGj+PR6NiaFhn0Fk3Km9Q+7Gflr EU2GFEX9Ea5OeX+Y1qFJNC6GfJtX63t1+JteT/Ho5Fdth82wDI/jbyP3S9nZ2/YQQC1L ojhyHzMBzQuZQAy5BLUmpZULYgAU+/jKxSr1Wg+4LFXqeYtCyFAmzKwngIjA4wm+AVfJ K0Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776418256; x=1777023056; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9hVaTRAypks8qC3WDbxaGr71EYAcs46miQkDiiVqXAg=; b=B00nRmjmkLgrct6ALZjpLQx/2oYDBtb5GwbLN7MfvXgVBMrgEFOb3lBN0EBR2SSgPm MOE6yQTve6YdKb4KHQKPlHVQ+EOlDC0pZD4y/k9GkhxlVMI2HCBf4o9kWLvyNB/eyJTS 15OymzvHdvBTY9CFHMOrrGR4xsiA6UhaI829arQwsbGZnDT8IM/XyxP9bv5UVj6qFt4E KK+Bsi/HXK5DaPqAJ08VX3v2c3oRFGjz3uLrA2gV0lhE9RENzCTJZnoKB51uHViG2BGp x5lVmgpvxrVOkuIeYr0z8ZxOU/TIR/pTMT7gsaL3fkh9R8l3j3tCswgTnFssOnZgLVlv 9jvg== X-Gm-Message-State: AOJu0Yx+umjz1i0fR/1Xrni8jGHqJZ7IBG8RN5jo6FLHaDgnSz3pq1Fc ftSm/d5dZMY2DJxzN83AABEM93VlHATPrqFJu0oDXTv6pTk/9L0g465W X-Gm-Gg: AeBDievKIm/zu3mYhT6/tQNnoEa8SphGmgpTMkcHcIUuw7aDlAppyhqj1OGpZ0zp8QJ AzoR4y7Lh1BqiIyoUEQblmBn6FLnmk1HJsWhAo86VXfOyI/pi/Aur6RoaRSpjzbSjxTkwYtY4Ou 2dJMzPdA5OV6d1fAEJ38fdwf8ieRPI6JL5ly9pLlTTh3gixfDaXn0wupA1yKUof17l05kxYHQ0C ruzGdZJbmAeWTJaGAcK9SMtPGokJzufVzyDjkn7au449CPrxtftrqD9Q6dy/rT10Zb9Fxt+YoZq sxQZD4luTcy8NvwTvcceDeX7tCuDBVWajLDRWj667btGko4+CIyi8Dp9yjelwhEbYvIwu39oi6l o7tmXx9HrsdkYxDnObpoeJw0BcoA2gtIQk0RqmM8LD3jCpu85o3lSbbwYRgfLWPVAXZUhCtGjk9 WZd58Q7OHmsWZKmYMRPtzMaweHPkp6GotjBbgtm9MIbQ== X-Received: by 2002:a17:90b:2244:b0:35d:9c32:6219 with SMTP id 98e67ed59e1d1-3614040e440mr2262226a91.9.1776418255549; Fri, 17 Apr 2026 02:30:55 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-361410cc196sm1541270a91.17.2026.04.17.02.30.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Apr 2026 02:30:53 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Fix stats reporting delays in logical parallel apply worker From: Chao Li In-Reply-To: Date: Fri, 17 Apr 2026 17:30:14 +0800 Cc: PostgreSQL Hackers , Amit Kapila Content-Transfer-Encoding: quoted-printable Message-Id: <56F4B26D-F9B6-415D-B51A-AC96EA771006@gmail.com> References: <4F6FFB88-72EE-4685-BF58-5450FE3D5009@gmail.com> To: "Zhijie Hou (Fujitsu)" X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 17, 2026, at 17:20, Zhijie Hou (Fujitsu) = wrote: >=20 > On Friday, April 17, 2026 3:41 PM Chao Li = wrote: >>=20 >>> On Apr 17, 2026, at 11:35, Zhijie Hou (Fujitsu) = >> wrote: >>>=20 >>> On Friday, April 17, 2026 11:01 AM Zhijie Hou (Fujitsu) >> wrote: >>>> Hi, >>>>=20 >>>> When implementing another feature, I noticed that parallel apply = workers >>>> currently do not report statistics while idle in their main loop. = This can >> cause >>>> stats from the last processed transaction to be arbitrarily = delayed, >> especially >>>> when there are long gaps between streamed transactions. >>>>=20 >>>> The issue is demonstrated in 0002, where a TAP test fails when = attempting >> to >>>> collect stats from a parallel apply worker that has no subsequent >> transaction >>>> to >>>> trigger a stats report. >>>>=20 >>>> 0001 fixes this issue by forcing a stats report when the worker is = idle in the >>>> main loop, matching the behavior already present in >> LogicalRepApplyLoop() >>>> for >>>> regular logical apply workers. >>>=20 >>> Regarding 0002, I realized that the streaming option is now set to = 'parallel' >> by >>> default so can avoid adjusting the option again. The test needs to = be >> adjusted >>> to increase the worker limit so that a parallel worker can start. = Here are the >>> updated patches. >>>=20 >>> Best Regards, >>> Hou zj >>> = > 0002-Test-the-stats-report-in-parallel-apply-worker.patch> >>=20 >> I think WaitLatch will never return WL_LATCH_SET and WL_TIMEOUT >> together, so we can do =E2=80=9Celse if (rc & WL_TIMEOUT) >> && !IsTransactionState())=E2=80=9D, so that upon WL_LATCH_SET, it = skips the >> WL_TIMEOUT check, which could be slightly more efficient. >=20 > I'm not sure we should assume that WaitLatch will set only one flag at = a time. > even if that assumption holds for this specific case, handling bit = flags this way looks a bit odd. > AFAICS, we don't use this style elsewhere in the code. > Currently, users of WL_TIMEOUT (in basebackup_throttle.c, = walreceiver.c, worker.c) > all use if ... if logic. >=20 > Best Regards, > Hou zj WL_TIMEOUT is not a real event. If we look at the code of WaitLatch: ``` if (WaitEventSetWait(LatchWaitSet, (wakeEvents & WL_TIMEOUT) ? timeout : -1, &event, 1, wait_event_info) =3D=3D 0) return WL_TIMEOUT; else return event.events; ``` WL_TIMEOUT won=E2=80=99t be union with other events at all. Anyway, that=E2=80=99s not a big concern. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/