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 1vjAjh-009LKP-1i for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 06:33:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vjAjg-00GNPL-2F for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 06:33:37 +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 1vjAjg-00GNOk-17 for pgsql-hackers@lists.postgresql.org; Fri, 23 Jan 2026 06:33:36 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vjAje-000000003ha-12sz for pgsql-hackers@lists.postgresql.org; Fri, 23 Jan 2026 06:33:36 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-47d63594f7eso15266495e9.0 for ; Thu, 22 Jan 2026 22:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1769150013; x=1769754813; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/WlGecLPPuZPpqbAqy8bAvzA1nBF702lcwCzwi4sUC4=; b=VM+EAv2leF4XtwCamh/0i88GEGnxkucqkL9YfhP0aa0VD2Dq+u/vTyx3qikpeaXhkF 81DIpdKT6rJjZvkqStq+ofhPHCH5HNs3i/uOBEfEnnjdI6hl0CJk2plkdhVb/CHk1nzf IjuE/bI7YiTGmkTaY8R/TWr/ddwtAWvkjXA+GXzbb/rOhkPLTtfj3h/p2fH9NS5XwmKg Kph6pvfQwSycuIuyGyJXnCLpmRGTsYH1bEWRc6k0iL2lRgCrx8VVnKkkX7+ipeRfjWrM 7NzYlXmIb5eVeuh6fEu//tYygDKx1/Y8W1ylCjGgMjzUmL6rGRiepWG2avMQf8CwV51k qimA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769150013; x=1769754813; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/WlGecLPPuZPpqbAqy8bAvzA1nBF702lcwCzwi4sUC4=; b=TIoBulTfUT6dX495O1ZpjukKZBA8LTlZMHg7ZIXmZTHhgOHOPe+QXU4yJIP82GImuu 5zWRF46yyb9xfHbSb0ZIXuw2TvRPohnY1FeWCCwX+TAg+jUzme9kFRi31bTarzowmPwR LzAIBllj+pdd/8Vgai6B7AOlIntlTMB+2nl+SP3fjbf7XbV1iphKofbiSoG8YQT8KtRj DID1eEhiBO3C5xJniWOyqZd5xokX2RuDEUTLEMIblJlfzhy+Mdob/fPH3EeTbYv4jmgj T1Nuv3SPYBAEgi8grsrHk+glRI2GRhY7sm1X9gjpf9+0egJIrhMoZeMtJaHuG/FcinBO 1XIQ== X-Gm-Message-State: AOJu0YywWzD2phAs4KhPijsEfxyZC/wrz6BfP+r5ZJB6qHSTDYJuPfzd 0HRSUZOJp2ZoFxwsOLthBdZAdSujijjyf/832ygGfSCqF90nubbeksuFjFQGbB1Ub5MUN9BSnWa aoo4V X-Gm-Gg: AZuq6aLermQxuNk3bI6lMm4uyISrlKjCrdlRFZzhHHO28kfrrqZ2darIeobP5wNAOno vQNaZvTr1O1s8KsfhUbGStCmDsB6I/a8azPybZCjbY+VMg8pRxUoXb/sbXJq3cIgR6vaaf44hH3 PLB1NlfI0eFB56GCi///vzkR8+G0bc1isXNvOH/TXidXQlOgKT7tAHPD7+ITucQFctPU6vPQGnx wFqRh2xWxJC0i4KAhHrIItGzgnnkllBUoOriAOsXsAhiBRG+z7+xWu5VBufz6OXzmG6vXdWY2WE Z2oRHnpYdWVo3mZjUTFV6bO9bGsG58bj732JwU5HjFgnmI1jv7oyt93JbkHVvW5xswuiVUQG1x0 DKjsHTULqePA+U5XsOEmUnCMTe7TRwLCP5BbY3fMEbeufomoBkfEnKhl2RJA+mEIyUjMtH866dD GkUz5q/ANBILMrb1x+6+sJMvVPzApMZmgrn78= X-Received: by 2002:a05:600c:6089:b0:475:da1a:53f9 with SMTP id 5b1f17b1804b1-4804c954d5emr28423195e9.14.1769150013091; Thu, 22 Jan 2026 22:33:33 -0800 (PST) Received: from localhost (109-81-168-246.rct.o2.cz. [109.81.168.246]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4804d8a5b2dsm34361515e9.9.2026.01.22.22.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 22:33:32 -0800 (PST) From: Antonin Houska To: alvherre@kurilemu.de cc: pgsql-hackers@lists.postgresql.org Subject: Re: Race conditions in logical decoding In-reply-to: <202601221950.c5lwdnye3idv@alvherre.pgsql> References: <202601221950.c5lwdnye3idv@alvherre.pgsql> Comments: In-reply-to =?us-ascii?Q?=3D=3Futf-8=3FQ=3F=3DC3=3D81lvaro=3F=3D?= Herrera message dated "Thu, 22 Jan 2026 20:59:21 +0100." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 23 Jan 2026 07:33:32 +0100 Message-ID: <3805.1769150012@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =C3=81lvaro Herrera wrote: > I think this algorithm is strange -- if you do have to wait more than > once for one transaction, it would lead to doing the > TransactionIdDidCommit again times for _all_ transactions by starting > the inner loop from scratch, which sounds really wasteful. Why not nest > the for() loops the other way around? I'm quite sure I wanted to iterate through committed.xnt in the outer loop, but probably got distracted by something else and messed things up. > Something like this perhaps, >=20 > for (int i =3D 0; i < builder->committed.xcnt; i++) > { > for (;;) > { > if (TransactionIdDidCommit(builder->committed.xip[i])) > break; > else > { > (void) WaitLatch(MyLatch, > WL_LATCH_SET, WL_TIMEOUT, WL_EXIT_ON_PM_= DEATH, > 10L, > WAIT_EVENT_SNAPBUILD_CLOG); > ResetLatch(MyLatch); > } > CHECK_FOR_INTERRUPTS(); > } > } >=20 > This way you wait repeatedly for one transaction until it is marked > committed; and once it does, you don't test it again. Sure, that's much beter. Thanks. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com