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 1vdHSA-00GCri-2V for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 00:31:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdHRA-00B5Go-28 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 00:30:09 +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 1vdHRA-00B5Gg-0h for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 00:30:09 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdHR9-004d3X-0B for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 00:30:07 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-595819064cdso598281e87.0 for ; Tue, 06 Jan 2026 16:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767745805; x=1768350605; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C3hZgcdCkHzu0/romfIabhAbwNW6OIBys238dT64mZE=; b=HnjK2/S0N3Qdjhv8hCktns12GDPs2BE6UoIe+k0MOjdfhLfJNc5/ctcx5+llmKPEYQ RUsmlzlnqH0oxxMxEZr6kPXH5jBQA3Wchtx+efpBlD9wRnL1YI5NinmSs1/66/zrDXz2 YZElYxOad7bO3mfti3ZQVNUfE4lXeFDN74Z7DqGz3wSttfTlPDOZbS6qem2aI9G5UOhx Rxk/u/kZF/o7Ti1JgXTxVoTOoWWZMVyHo/ONsdRqBVErGYfiU/ftfckkvxGM5lnMZSDY wYSnBQtQ3lp6yMTpRfCIuRWTzV44e0CqSC3gN1DKtAYsXTOH83wRQ2gyzu9ocgF15RJZ lkxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767745805; x=1768350605; h=content-transfer-encoding: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=C3hZgcdCkHzu0/romfIabhAbwNW6OIBys238dT64mZE=; b=pB5X/rzKY5jcQFS1063MXLqTTXEXdDWXfs1mO9tcKTcMeUPwqcTTg+mxoJrqZ/wITy a6uZNdlsaS4K0/0ALFpwHnU49vE6gpuIymhUOCfP1e0a6T9TtLgrv2V5GiOR062UKLRL e6qum434cMu25Jx5jvs74S/zXIDODKaRWVDeQVIZ666s0ycIItvUoaLzI8biZEOFgv01 swuCE2WiHyhkT4j6qHFOOEXn3xdj0utaE9aDFzGb+tmsfC2YC/ZlBJLn69ccWq7+kJtr aVh4niH2pAOiZ9Sm5n6j81cDYj0wNS+BOWRDC7wq96A3vKY+/KrPLlCOoTxPwWltW7gX EBwA== X-Forwarded-Encrypted: i=1; AJvYcCXLQmUKf60snaofP2zF4cCbHOi+NFVIUHMTpUQEd1IaBSg70aCFdCSdIIMGGo93cutokWX26R+wUXECNT4c@lists.postgresql.org X-Gm-Message-State: AOJu0Yx0UsOgGJovnzKy/gzFLfcogdv708aJxZRbwtOKa73g4F0eF7IU Q2IgN7gZCVFjVAmZ0RNFjZ/R0zr11lCfrjZrFlO8YKJhRyR5UVABszfp+8ogrcw6QFMf8I9fSOQ LfX1919c7ODtjWpzn8YtmeNpCYh5A1uk= X-Gm-Gg: AY/fxX48dZrBc1TaFGaC4Jt8gtTp1MAmEHGj24VaygRB/gzmjnY9/g23Fo/v2zyViNm D6cG1GrWr0JuGKmQ5x4zvjQihz4EEJHqUkcWE2glhjUGuLwMfd/DEGXOi69aooquQMjiScQ2JSj 5qAsLw8AW11KYxJxoVGdzGZBQ9WGgJSAjjcZpvEbGAp3vMes/UNKrjz9Kj2QxT89sD/VgJb59Ee s0WuTIo7vGi75vmaft17ysT0gF9xa+JmqGo+d+i8Ql1QdwlWHMsD5y85/5iVYBlVP4BIl6T X-Google-Smtp-Source: AGHT+IGpxbn6U57jZhmgaKvviaTU/p4Tv6aHFc89aO9ApBsnZgxZ4+WS0ZuNrQXy9gZSl/9ynRi09rPgCjIl5jT7fo4= X-Received: by 2002:a05:6512:31c7:b0:598:ea79:a5ca with SMTP id 2adb3069b0e04-59b6eb57781mr208901e87.15.1767745804759; Tue, 06 Jan 2026 16:30:04 -0800 (PST) MIME-Version: 1.0 References: <202512291435.5edkf3hnichv@alvherre.pgsql> In-Reply-To: From: Masahiko Sawada Date: Tue, 6 Jan 2026 16:29:28 -0800 X-Gm-Features: AQt7F2rYf32DZPgLHuMVKMJ_Apuq8bF7Pu_7B2amvh7FNAUPjBpCBo2t6MuxFkg Message-ID: Subject: Re: Refactor replication origin state reset helpers To: Chao Li Cc: Ashutosh Bapat , =?UTF-8?Q?=C3=81lvaro_Herrera?= , Postgres hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Dec 29, 2025 at 11:17=E2=80=AFPM Chao Li w= rote: > > On Tue, Dec 30, 2025 at 1:07=E2=80=AFPM Chao Li = wrote: >> >> >> On Tue, Dec 30, 2025 at 12:48=E2=80=AFPM Ashutosh Bapat wrote: >>> >>> On Mon, Dec 29, 2025 at 8:14=E2=80=AFPM =C3=81lvaro Herrera wrote: >>> > >>> > On 2025-Dec-24, Ashutosh Bapat wrote: >>> > >>> > > If we go this route, we at least need to declare the new functions = as >>> > > static inline and move them to a header file instead of .c file. >>> > >>> > Hmm, why would we make them static inline instead of standard (extern= ) >>> > functions? We use static inline functions when we want to avoid the >>> > overhead of a function call in a hot code path, but I doubt that's th= e >>> > case here. Am I mistaken on this? >>> > >>> >>> I wasn't aware that we are using static inline only in hot code paths. >>> Looking around I see most of the static inline functions are from >>> modules which are used in hot code paths. So, yeah that seems to be >>> the convention. I also see some exceptions like those in >>> basebackup_sink.h - I don't think all of those are used in hot code >>> paths. >>> >>> In this case, we are moving three assignments into their own >>> functions. CPU instructions to call extern functions will be >>> significant compared to CPU instructions for those assignments. static >>> inline functions, OTOH, would have similar performance as the existing >>> code while providing modularization. If you feel that's not a good >>> enough reason, I am ok keeping them extern. >>> >>> > > Further, does it make sense to put together all the state variables >>> > > into a single structure? >>> > >>> > Yeah -- keeping the threaded-backend project in mind, moving them to = a >>> > single struct seems to make sense. I think it's a separate patch tho= ugh >>> > because it'd be more invasive than Chao's initial patch, as those >>> > variables are used in many places. >>> > >> >> >> Attached v3 patch set. Comparing to v2, the changes are: >> >> 0001: >> * Combine the two cleanup functions into one and control them by a bool = flag. >> * Change the helper function to be extern. >> * Move out cleanup from reset function. >> >> 0002: Consolidate replication origin session globals into a single state= struct. > > > Fixed a bug in v4. > I've reviewed both patches. Here are some comments: 0001 patch: +/* + * Clear session replication origin state. + * + * If xact_only is true, only clear the per-transaction state. + */ +void +replorigin_session_clear_state(bool xact_only) +{ + replorigin_session_origin_lsn =3D InvalidXLogRecPtr; + replorigin_session_origin_timestamp =3D 0; + if (!xact_only) + replorigin_session_origin =3D InvalidRepOriginId; +} Given that we already have session_replication_state, I am concerned that the name replorigin_session_clear_state creates ambiguity. Could we rename it to something like replorigin_session_clear()? Additionally, I feel that the term "per-transaction state" in the comments does not accurately describe these two fields. How about renaming the xact_only parameter to clear_origin? This would make it explicit that setting the flag to true clears replorigin_session_origin as well. 0002 patch: +typedef struct RepOriginSessionState +{ + RepOriginId origin; + XLogRecPtr origin_lsn; + TimestampTz origin_timestamp; +} RepOriginSessionState; + +extern PGDLLIMPORT RepOriginSessionState replorigin_session_state; replorigin_session_state is quite confusable with the existing session_replication_state. Given that these values are used to add the additional information to the transaction, how about the name something like "replorigin_xact_state" or "replorigin_xact_origin"? -- +RepOriginSessionState replorigin_session_state =3D { + InvalidRepOriginId, InvalidXLogRecPtr, 0 +}; I think using designated initializers here would be better for readability and robustness against future struct changes. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com