aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2024-01-15 13:02:03 +0100
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2024-01-15 13:02:03 +0100
commitaa817c7496575b37fde6ea5e0cd65b26f29ea532 (patch)
treeaf1b36f38520ce57a312d89aceb48ef62f34f525
parent31acee4b66f9f88ad5c19c1276252688bdaa95c9 (diff)
downloadpostgresql-aa817c7496575b37fde6ea5e0cd65b26f29ea532.tar.gz
postgresql-aa817c7496575b37fde6ea5e0cd65b26f29ea532.zip
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
-rw-r--r--src/backend/replication/logical/origin.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 21ed07e3aa3..4ef3385c952 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -172,9 +172,10 @@ static ReplicationState *replication_states;
static ReplicationStateCtl *replication_states_ctl;
/*
- * Backend-local, cached element from ReplicationState for use in a backend
- * replaying remote commits, so we don't have to search ReplicationState for
- * the backends current RepOriginId.
+ * We keep a pointer to this backend's ReplicationState to avoid having to
+ * search the replication_states array in replorigin_session_advance for each
+ * remote commit. (Ownership of a backend's own entry can only be changed by
+ * that backend.)
*/
static ReplicationState *session_replication_state = NULL;
@@ -1056,10 +1057,12 @@ ReplicationOriginExitCleanup(int code, Datum arg)
{
ConditionVariable *cv = NULL;
+ if (session_replication_state == NULL)
+ return;
+
LWLockAcquire(ReplicationOriginLock, LW_EXCLUSIVE);
- if (session_replication_state != NULL &&
- session_replication_state->acquired_by == MyProcPid)
+ if (session_replication_state->acquired_by == MyProcPid)
{
cv = &session_replication_state->origin_cv;