elog(DEBUG2 in SpinLocked section. - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject elog(DEBUG2 in SpinLocked section.
Date
Msg-id 20200602.161518.1399689010416646074.horikyota.ntt@gmail.com
Whole thread Raw
Responses Re: elog(DEBUG2 in SpinLocked section.
List pgsql-hackers
Hello.

I noticed that UpdateSpillStats calls "elog(DEBUG2" within
SpinLockAcquire section on MyWalSnd.  The lock doesn't protect rb and
in the first place the rb cannot be modified during the function is
running.

It should be out of the lock section.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
From 8098f066e5884128df04ecb94bcbf960d55b0c93 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyoga.ntt@gmail.com>
Date: Tue, 2 Jun 2020 16:10:14 +0900
Subject: [PATCH] Move an elog out of spin-lock section

The variable to be shown by the elog is not protected by the spin lock
and the elog call unnecessarily prolongs the lock section. Move it out
of the lock section.
---
 src/backend/replication/walsender.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 86847cbb54..2364cbfc61 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -3685,17 +3685,15 @@ UpdateSpillStats(LogicalDecodingContext *ctx)
 {
     ReorderBuffer *rb = ctx->reorder;
 
-    SpinLockAcquire(&MyWalSnd->mutex);
-
-    MyWalSnd->spillTxns = rb->spillTxns;
-    MyWalSnd->spillCount = rb->spillCount;
-    MyWalSnd->spillBytes = rb->spillBytes;
-
     elog(DEBUG2, "UpdateSpillStats: updating stats %p %lld %lld %lld",
          rb,
          (long long) rb->spillTxns,
          (long long) rb->spillCount,
          (long long) rb->spillBytes);
 
+    SpinLockAcquire(&MyWalSnd->mutex);
+    MyWalSnd->spillTxns = rb->spillTxns;
+    MyWalSnd->spillCount = rb->spillCount;
+    MyWalSnd->spillBytes = rb->spillBytes;
     SpinLockRelease(&MyWalSnd->mutex);
 }
-- 
2.18.2


pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: Resetting spilled txn statistics in pg_stat_replication
Next
From: Masahiko Sawada
Date:
Subject: Re: More tests with USING INDEX replident and dropped indexes