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 1vq7Ba-004s1C-2g for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 10:11:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vq7BZ-003EGQ-2m for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 10:11:06 +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 1vq7BZ-003EGI-1i for pgsql-hackers@lists.postgresql.org; Wed, 11 Feb 2026 10:11:06 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vq7BY-0000000086Z-0wzS for pgsql-hackers@lists.postgresql.org; Wed, 11 Feb 2026 10:11:05 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-383153e06d6so15218331fa.0 for ; Wed, 11 Feb 2026 02:11:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770804663; cv=none; d=google.com; s=arc-20240605; b=SFPxGnjaPhwItFCX1ZiZWs4KvOTgbnBaFVI0WnEMSesDI4Q98Op5ALreEolyancvSh krmmoIzkKIUr+CLdBcMTa51bRdOsRHw+d9gXlcgqtpl3N8RHx4sIjwYJdSdFc6hWQJe3 IDiZIUEGHe4O7tuBjLmNXoKkNDZ+jo/EIvQ2xPi/3Yx1BkobnfxbG6smtHMvStE1vKOo I+mmLkH5pndpEBtkDm5OklgcdhAAmTQX7V2rWhNmmlvnw3XvgKhVZfaMVItg+qyUFyiN WwZGCnSl4mD8o1b9gxtEQ1a39MB2PkZvmngF+syLAPv/3Oo6dfHILnEVPat2Vlpp8m/S PLmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=f6nAarx7RZTsucVolRt/tDbv5BJOofS8mUVbTGGBfuQ=; fh=Y4kP1uMin0CszzQi/AiqpVMdyYokeS849Y9ZmiWqx2E=; b=jlzu94IHcKY55Zj4b24jmzGgwuLbV2fnDlfJLT38CFqPKRwx8xjC9zKnQpDtmj8xJd 0xsqzYIZo7ckQJVj1g5o5IxMnJUu4Pd3rezAgE3TNMTxupipYkAeXT01yorWbg1RRJ5b j1AvHWk9nKZZ8Flp3UtWdqplaOPceB3cHD5+H4xBdYa/GA6SWm/3VJf1OgERRUaU/nsi iQ0qHXN4AyiYr1tXFgE1g3LOYBda+B7SKQvH7GA+oRP3/SNgPB7hkxxQQuuI8U6/Txjw N+JEZZxINEkjj/Ae+HrDjdNfgQOxj0QUHC3g3gDm6Cd6pkwIFNs/ODxfMb4yuNnOhgKV MaOQ==; 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=gmail.com; s=20230601; t=1770804663; x=1771409463; 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=f6nAarx7RZTsucVolRt/tDbv5BJOofS8mUVbTGGBfuQ=; b=LEuLvFUhI3Q8qDAuTb3kaSE50GanuieEsLhDKyrKR7RLPsqk0GGqEP9BqSkzys9v/f NuIE0e0GrnozIYGqqdBhNV0UH1jZ+UDt6wstRP8CKtTsaW4PV+Vz4XwNdm2q6XOXxHuX PKJQuy7D7aSVMh2FvhvtCY95KrVm7GpY9NuVvPztajYb+ELSAV34viyP8XhqTHvOv5ci cCWSVHZeLaoL2IM5A+uPxGJLVgBG8RshMYbD183NZzfhx1vmZ+YS7LbaNaIty/c+nlzW 8Oc7jXAXsKwvM1oQVQRbn2LtXVkPr+Qk1nm+WHqxHPL9yp5Vrz5/evZqIHy/GDLKPhu+ ZAVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770804663; x=1771409463; 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=f6nAarx7RZTsucVolRt/tDbv5BJOofS8mUVbTGGBfuQ=; b=pbSyxJs1QaUu/ukXli7F8opBSFGMgKSwjheipkngoOwB0Ehqji5mdPZpVQ8H9E5pM7 rPrauUFiS1bmAyi7NE5cj7pAEftfZk9rBtC3eJ+rqybR5TuEGBR1hwvjD8ZltoAEfIZY bsoHQGofMOBGuvDZyDNs/WvEUP2/O2fO7xb++NdZ5iZSI/mID9QnAN4Fq/Y13VdgrXpx RvspUZ9sYrFm5kXYDoU4J1qr5PB3KqXquhBMprW0P8gjbuaDVFpxFY2VMNJoxB2oI20S 2ESmlD3WPC2hebkZwlDWvaq0PS5DKFoF6zA8zvR5VYfkRDP8+Rg07IfWVOEMkE3lXHb7 v/dw== X-Forwarded-Encrypted: i=1; AJvYcCXVtmk7dqRQHxlEO1aSDwEfL1g6ilMatWCDJxFtzQVWUB/h+N6CTpN3XTHXTWrIV3joYKo3BX48ZZkz37Ur@lists.postgresql.org X-Gm-Message-State: AOJu0YxSHdg4DumGwi2xFVPca1m105HLsAw2u890+WezBOUbxAqRyumo ZtXELRB5sdNuiB2y8qYDn9jPJoR22fso3HHDfR1Rt4ML7XKD0P97h2XzjVMKw2ksSViqUTpFm1q oXjT7DzgNX3hw9nJjPFLUu0LBgk/MHmw= X-Gm-Gg: AZuq6aJOjBPapyNOnDKTXW7eNgeH6X4+wjFb1narztvGSrNS0DwVpa91dST2AHjUdln BBMcscXaTbsLU4W8/Q4aYHcfHfY6p60anf5HUGdIqApG/75HWC5Pg7KnDYOZ2MZEioTXYNSnzJW bjfG9iVglaZMfzDEY+BH9ori3R44PwNVoKKgkrDsl/YUirWNkgU/pH+8fBm8cTraLTpxxoNuG4M QsExpIEu4rrgmYE9PDunCIqHhbRxGn8/gsIOFtXvXQL00vN9O+ryvr2onyqAj/Zhr+vAgEfKzpw nBrD8fhwkCwhJ0T6atobu4dINBvQnc3cOaVBiPfth98A5GXIlA== X-Received: by 2002:a2e:a58e:0:b0:37c:c856:60eb with SMTP id 38308e7fff4ca-386b4bbca97mr57246841fa.0.1770804662396; Wed, 11 Feb 2026 02:11:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Wed, 11 Feb 2026 15:40:50 +0530 X-Gm-Features: AZwV_QiGfR1EK6c_7n5k4wSujx3ytYtIIfqfYbjZzKYRWq0VQU8Q7YhBwv8h2ak Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: shveta malik Cc: Heikki Linnakangas , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@lists.postgresql.org" , "Zhijie Hou (Fujitsu)" , Doruk Yilmaz 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 Wed, Feb 4, 2026 at 11:32=E2=80=AFAM shveta malik wrote: > > On Wed, Feb 4, 2026 at 12:38=E2=80=AFAM Heikki Linnakangas wrote: > > > > > > > The second patch rearranges the if-else statements to check those > > conditions. I found the current logic hard to follow, this makes them > > feel more natural, in my opinion at least. > > I=E2=80=99m not fully convinced that it makes the code clearer or better = to > understand. For example, consider the following error case: > > else if (curstate->acquired_by =3D=3D 0 && curstate->refcount > 0) > ereport(ERROR, > (errcode(ERRCODE_OBJECT_IN_USE), > errmsg("replication origin with ID %d is already active > in another process", > curstate->roident))); > > > The condition was self explanatory earlier. The condition has now been > rewritten (or reduced) to: > if (acquired_by =3D=3D 0 && curstate->refcount > 0) > > However, this is not exactly the same as the earlier logic. On closer > inspection, the condition 'curstate->acquired_by =3D=3D 0', while no > longer stated explicitly, was implicitly guaranteed by the preceding > error block: > > if (curstate->acquired_by !=3D 0) > ERROR; > > One way to make this clearer would be to structure the logic as: > > if (curstate->acquired_by !=3D 0) > ERROR; > else if (curstate->refcount > 0) > ERROR; > > Even then, it is still not clear why this error (the case where > curstate->refcount > 0 and curstate->acquired_by =3D=3D 0) is raised only > when acquired_by =3D=3D 0, or how the same situation is expected to be > handled when acquired_by !=3D 0. The earlier code was clearer in this > regard (at least to me), as it first handled the > 'curstate->acquired_by !=3D acquired_by' case, making the overall logic > somehow easier to understand. Perhaps we can try by adding a comment > or restructure in some other way if possible and needed? > I see your point but one advantage with the proposed code change is that it started to appear that we can extend this part of code easily in the future as it separates most of the handling related to when a user has given acquired_by parameter's value as zero and non-zero. > > It has one user-visible > > effect: If you call the function with acquired_pid !=3D 0 and the origi= n > > has no state slot, *and* there are no free slots, you previously got > > this error: > > > > postgres=3D# select pg_replication_origin_session_setup('other', 123); > > ERROR: could not find free replication state slot for replication > > origin with ID 2 > > HINT: Increase "max_active_replication_origins" and try again. > > > > Now you get this: > > > > postgres=3D# select pg_replication_origin_session_setup('other', 123); > > ERROR: cannot use PID 123 for inactive replication origin with ID 2 > > > > Both error messages are more or less appropriate in that situation, but > > I think the new behavior is slightly better. The fact that the origin i= s > > inactive feels like the bigger problem here. > > I am okay with this change though. Let's see what others have to say. > Either message is fine with me in this situation. --=20 With Regards, Amit Kapila.