Skip to content

Commit aa817c7

Browse files
committed
Avoid useless ReplicationOriginExitCleanup locking
When session_replication_state is NULL, we can know there's nothing to do with no lock acquisition. Do that. Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Discussion: https://postgr.es/m/CALj2ACX+YaeRU5xJqR4C7kLsTO_F7DBRNF8WgeHvJZcKtNuK_A@mail.gmail.com
1 parent 31acee4 commit aa817c7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/replication/logical/origin.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ static ReplicationState *replication_states;
172172
static ReplicationStateCtl *replication_states_ctl;
173173

174174
/*
175-
* Backend-local, cached element from ReplicationState for use in a backend
176-
* replaying remote commits, so we don't have to search ReplicationState for
177-
* the backends current RepOriginId.
175+
* We keep a pointer to this backend's ReplicationState to avoid having to
176+
* search the replication_states array in replorigin_session_advance for each
177+
* remote commit. (Ownership of a backend's own entry can only be changed by
178+
* that backend.)
178179
*/
179180
static ReplicationState *session_replication_state = NULL;
180181

@@ -1056,10 +1057,12 @@ ReplicationOriginExitCleanup(int code, Datum arg)
10561057
{
10571058
ConditionVariable *cv = NULL;
10581059

1060+
if (session_replication_state == NULL)
1061+
return;
1062+
10591063
LWLockAcquire(ReplicationOriginLock, LW_EXCLUSIVE);
10601064

1061-
if (session_replication_state != NULL &&
1062-
session_replication_state->acquired_by == MyProcPid)
1065+
if (session_replication_state->acquired_by == MyProcPid)
10631066
{
10641067
cv = &session_replication_state->origin_cv;
10651068

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy