Lockless exit path for ReplicationOriginExitCleanup

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Lockless exit path for ReplicationOriginExitCleanup
Date: 2023-11-22 08:42:06
Message-ID: CALj2ACX+YaeRU5xJqR4C7kLsTO_F7DBRNF8WgeHvJZcKtNuK_A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While looking at the use of session_replication_state, I noticed that
ReplicationOriginLock is acquired in ReplicationOriginExitCleanup()
even if session_replication_state is reset to NULL by
replorigin_session_reset(). Why can't there be a lockless exit path
something like [1] similar to
replorigin_session_reset() which checks session_replication_state ==
NULL without a lock?

[1]
diff --git a/src/backend/replication/logical/origin.c
b/src/backend/replication/logical/origin.c
index 460e3dcc38..99bbe90f6c 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -1056,6 +1056,9 @@ ReplicationOriginExitCleanup(int code, Datum arg)
{
ConditionVariable *cv = NULL;

+ if (session_replication_state == NULL)
+ return;
+
LWLockAcquire(ReplicationOriginLock, LW_EXCLUSIVE);

if (session_replication_state != NULL &&

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2023-11-22 08:46:31 Re: pipe_read_line for reading arbitrary strings
Previous Message Amit Langote 2023-11-22 08:37:28 Re: remaining sql/json patches