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....@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