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 1wPg05-000waM-1s for pgpool-hackers@arkaria.postgresql.org; Wed, 20 May 2026 12:26:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wPg03-007bl2-1W for pgpool-hackers@arkaria.postgresql.org; Wed, 20 May 2026 12:26:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wPg02-007bks-2F for pgpool-hackers@lists.postgresql.org; Wed, 20 May 2026 12:26:12 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wPfzz-00000000UE1-0GgP for pgpool-hackers@lists.postgresql.org; Wed, 20 May 2026 12:26:10 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-65dead17c24so4475171d50.2 for ; Wed, 20 May 2026 05:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779279967; cv=none; d=google.com; s=arc-20240605; b=YNMfdYamZ+T7Cr3PvHS7uWbuBo46Rz3O4ZOab4paW/0yPXZQuXkDcLXHm5DzYfX+qx EEDG1lKvJUlzU4Okgw4wU7t0jceTKbgpgf1944O/o6FecNJsVi/fm5Olb2ZMbeSUGLQC uJMwVTnG3PgYtMC/LDVDikdhtUbjUGHgVh/hNMGIDOLQdPA9cBlIpOP2EYAY5Msvx2KE vxFnlNfAdwwemK2p3uMf3DtxhhTmVcfSdAqJboFnJdq14lGN0oPXVeGm/qhNL4ZJfAIX f0goxbhDPuDM3xjGVpqa7zvS3XnAFEgFgFAgo3HW++t6XT3zTa39mxcA+glyNxsaKIoc vrQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=n5arOnVH+RwGo7T9dsNaY4I6K3lHzLrB8cUmmb/xtx8=; fh=m3oiE62fRN5J1XaE+5vpHZRIgCyFefxVI0mFw3d8yxA=; b=fGIjtUlTc/TZAnAMK+6Qs99Xy66m4kJ+xEKTly+y/m/QtapNjMvy76cKytFWHm5RNo j7E7MDbXcJIgQBy07D2M9yRDHt7XhCG/+IIgam34S4Eu9LY4KmRNL506wjM36GdGhhef 15xRfQtY8JMKUFqDhG8qqqB+AWo/fQk3NuECGlLAwpDjZhGh4dVPJk7kM1vN/Gg+QCKk AoNSyvJTFRhwiyVi25Kl1CJWIkOdMC2iYaJGvfGyJWnJ/KxkZfZ1CVrYE0v9UdjD8bsp C+g/zx64jnk3cNO6J1vOzWWx7uwvVD1WmCrzfZq0pnTfvwKSEX+obxxslowjpVH17kny joBA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tailorbrands.com; s=google; t=1779279967; x=1779884767; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=n5arOnVH+RwGo7T9dsNaY4I6K3lHzLrB8cUmmb/xtx8=; b=h35MZ2YSdEUdts8FY4HNlcdyKJM2ufh486EAXbaMFlIu7+qIEQD8vnjJOKYkCVAQLK 7sh/2RGkMe5WBnobLmGy73KXMLav+capWdx8Si7/Kq5qrpJ86GZ2DethqiRREPP8q9m6 da9Q2JGzEZedGY7EdQ7MDpt952sPcSijao/A3jNk+EOAHYLxbvwDPNu7QMjAONHqpW1j v5ouL13OnbSvJzv2XGiBg5YvOTUri7J15wZJU7IpAh+vXEH2SOIr7N5Hv71w4jJNDHmd LDLocvhwyjvpAJX9K7B4t9r2mfIr9oYbPWqPeAeuo5wpA/1yJnQD7+EQ03dPb8wmSWGJ sIVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779279967; x=1779884767; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=n5arOnVH+RwGo7T9dsNaY4I6K3lHzLrB8cUmmb/xtx8=; b=MBcOV0aHgt3sWtL+hmZeavzN39PxiSgMD40K6AvBD9ZvM4mhyY/5F/dxqgpqZdhOJg 6r5zsHkITqmYGqDj2woe47Pj16jSv3wlwR6Im9197zqRGoupUMMZVLkJrDP8ScddK5oi GysypFFH2Ch9CXGRCWRdqeR5PZCaDTW8wo1SmjLMy4nt++FwkVWWfPxRpfSKtVytSZsD IIpA9PBjefspyzeLl0C4MIbERqUeVOd6S8sO3K8qSHhYDAfGumjT93gUCVF8PH81BpFz RaxFShFs5BuUZ5ZFC4PPw4sU+M3bc5tx8HVvwKmR4sZ38fUXG5bTtTba8ZWKkT4ffz6P Fe9A== X-Gm-Message-State: AOJu0YxNi+WrSYH2Wtr6mRW63D9u4Si1Wk2ifubr4WmJWJjrsyyuhugY p+m4G5vBZaaxKj9zct9mQCji06L2+zDvDHn7A8fvllS9SakG6MxNaALqLIBzJmoble091IyVpi7 cEtXhZ/q0pO0kVxrsgF8ZzBB7++SWYV4osYc5Vt2BQ6NQVDJcU9TytIztr4kE X-Gm-Gg: Acq92OH80N5jDZukJxSrJs4jvhm7qr7VEB9yo1XfucTRKoCdLYCGqd6rFEHfmUWAh5N mDyi/0kIcL24WSwGHMvurYpQcq7qBO21Z/3C7mNOHzfUn+CkdSS545y+keYN6zVjb1jt5/Nmjjb 58nq94+QjH6oFb8LcwKW9GqDQJlU16fKaA7e8Bz29R/EVtOKfH9JzfWuqbCLGgowZRzgchSUkVT e/APgLda7TO4967cg84ZGK+YZHQNGoeBRdtULNIVHSld50EppdbBLIXW9SXBcJfT492dV3XXups eC/ynDuaqsj3sGJ/qPBVNthnpr0TwI+ezD96cihNiKhPq3L8LtP4MNHOq1xSq1ThLnnIXp+rwjk 7f2p6PVy0woLpraSqwTHhiyT+JH7+SEetvFNh X-Received: by 2002:a53:d058:0:10b0:658:7513:5ee8 with SMTP id 956f58d0204a3-65e226b1b0fmr18945187d50.21.1779279966428; Wed, 20 May 2026 05:26:06 -0700 (PDT) MIME-Version: 1.0 References: <20260518.191105.282754674107940178.ishii@postgresql.org> <20260520.132810.1024114140609315185.ishii@postgresql.org> In-Reply-To: <20260520.132810.1024114140609315185.ishii@postgresql.org> From: Nadav Shatz Date: Wed, 20 May 2026 15:25:54 +0300 X-Gm-Features: AVHnY4LPQ20pc0rxsE7dIh9tk011hz0G7fj0jA4CbfxyvWTuN2aOKS4LN4ulC0M Message-ID: Subject: Re: Proposal: Recent mutated table tracking in memory To: Tatsuo Ishii Cc: pgpool-hackers@lists.postgresql.org Content-Type: multipart/mixed; boundary="0000000000005b422006523ee630" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005b422006523ee630 Content-Type: multipart/alternative; boundary="0000000000005b421f06523ee62e" --0000000000005b421f06523ee62e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Tatsuo, Thanks for checking the V3, sorry for missing the test issue. I reproduced the timeout locally. Found and fixed the root cause. Root cause ---------- In CommandComplete.c, the autocommit write-tracking code was gated only on session_context->is_in_transaction, not on the cluster mode. In native replication and snapshot isolation modes, dml_adaptive() is never called (it lives inside where_to_send_main_replica), so is_in_transaction is never set to true even inside an explicit BEGIN/COMMIT block. That meant every DML in those modes was treated as autocommit by the write-tracking code, triggering pool_track_table_mutation_get_database_oid() =E2=80=94 which does a relcache do_query =E2=80=94 while a transaction was actually in flight on the backend connection. The do_query conflicts with the in-flight transaction and hangs the session. Subsequent shutdown then hangs in terminate_all_childrens / waitpid. Fix --- Gate the autocommit write-tracking in CommandComplete.c on MAIN_REPLICA in addition to the existing checks. dml_adaptive_global is only meaningful in streaming replication mode anyway (the matching routing logic in where_to_send_main_replica is already SR-only), so this just makes the autocommit path consistent. Also broadened the query cache bypass to all dml_adaptive* modes. The new helper pool_has_dml_adaptive_write_in_transaction() checks the existing memqcache DML oid buffer (oidbufp via the new pool_has_dml_table_oids()), which is populated for any DML in any cluster mode and reset on transaction boundary. This fixes the original "SELECT returns stale 1 instead of 2 after UPDATE" regression in streaming replication and avoids the same class of bug in plain dml_adaptive too. Verified -------- - 006.memqcache with disable_load_balance_on_write =3D 'dml_adaptive_global' appended in all three modes: PASS - 043.track_table_mutation: PASS Attached: v4-0001-Feature-load-balancing-control-by-table-tracking.patch Thanks! On Wed, May 20, 2026 at 7:28=E2=80=AFAM Tatsuo Ishii = wrote: > > Hi Nadav, > > > > Sorry, I missed your last email. > > Will check & test tomorrow. > > I finally got a chance to test your v3 patch. > Unfortunately the test failed with timeout again. > > testing 006.memqcache...timeout. > out of 1 ok:0 failed:0 timeout:1 > > From src/test/regression/log/006.memqcache: > > 2026-05-20 13:08:33.798: main pid 3562591: LOG: stop request sent to > pgpool (pid: 3561918). waiting for termination... > .....2026-05-20 13:08:38.799: main pid 3562591: LOG: stop request sent t= o > pgpool (pid: 3561918). waiting for termination... > .....2026-05-20 13:08:43.801: main pid 3562591: LOG: stop request sent t= o > pgpool (pid: 3561918). waiting for termination... > > It seems pgpool main process won't stop. > > Regards, > -- > Tatsuo Ishii > SRA OSS K.K. > English: http://www.sraoss.co.jp/index_en/ > Japanese:http://www.sraoss.co.jp > --=20 Nadav Shatz Tailor Brands | CTO --0000000000005b421f06523ee62e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tatsuo,

Thanks for checking the V3, sorry for mi= ssing the test issue.

I reproduced the timeout locally. Found and f= ixed the root cause.

Root cause
----------

In CommandCompl= ete.c, the autocommit write-tracking code was
gated only on session_cont= ext->is_in_transaction, not on the
cluster mode.

In native rep= lication and snapshot isolation modes,
dml_adaptive() is never called (i= t lives inside
where_to_send_main_replica), so is_in_transaction is neve= r set
to true even inside an explicit BEGIN/COMMIT block.=C2=A0 That mea= nt
every DML in those modes was treated as autocommit by the
write-tr= acking code, triggering
pool_track_table_mutation_get_database_oid() =E2= =80=94 which does a
relcache do_query =E2=80=94 while a transaction was = actually in flight
on the backend connection.=C2=A0 The do_query conflic= ts with the
in-flight transaction and hangs the session.=C2=A0 Subsequen= t
shutdown then hangs in terminate_all_childrens / waitpid.

Fix---

Gate the autocommit write-tracking in CommandComplete.c on
= MAIN_REPLICA in addition to the existing checks.
dml_adaptive_global is = only meaningful in streaming replication
mode anyway (the matching routi= ng logic in
where_to_send_main_replica is already SR-only), so this just=
makes the autocommit path consistent.

Also broadened the query c= ache bypass to all dml_adaptive*
modes.=C2=A0 The new helper pool_has_dm= l_adaptive_write_in_transaction()
checks the existing memqcache DML oid = buffer (oidbufp via the
new pool_has_dml_table_oids()), which is populat= ed for any DML
in any cluster mode and reset on transaction boundary.=C2= =A0 This
fixes the original "SELECT returns stale 1 instead of 2 af= ter
UPDATE" regression in streaming replication and avoids the same=
class of bug in plain dml_adaptive too.

Verified
--------
=
- 006.memqcache with disable_load_balance_on_write =3D
=C2=A0 'd= ml_adaptive_global' appended in all three modes: PASS
- 043.track_ta= ble_mutation: PASS

Attached: v4-0001-Feature-load-balancing-control-= by-table-tracking.patch

Thanks!

On Wed, May 20, 2026 at 7:28=E2=80=AFAM Tatsuo Ishii <ishii@postgresql.org> wrote:
> Hi Nadav,
>
> Sorry, I missed your last email.
> Will check & test tomorrow.

I finally got a chance to test your v3 patch.
Unfortunately the test failed with timeout again.

testing 006.memqcache...timeout.
out of 1 ok:0 failed:0 timeout:1