Re: Problem with synchronous replication

Kyotaro Horiguchi <horikyota.ntt@gmail.com>

From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: masao.fujii@gmail.com
Cc: lingce.ldm@alibaba-inc.com, pgsql-hackers@postgresql.org
Date: 2019-10-30T08:43:04Z
Lists: pgsql-hackers
Hello.

At Wed, 30 Oct 2019 17:21:17 +0900, Fujii Masao <masao.fujii@gmail.com> wrote in 
> This change causes every ending backends to always take the exclusive lock
> even when it's not in SyncRep queue. This may be problematic, for example,
> when terminating multiple backends at the same time? If yes,
> it might be better to check SHMQueueIsDetached() again after taking the lock.
> That is,

I'm not sure how much that harms but double-checked locking
(releasing) is simple enough for reducing possible congestion here, I
think. In short, + 1 for that.

> if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
> {
>     LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
>     if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
>         SHMQueueDelete(&(MyProc->syncRepLinks));
>     LWLockRelease(SyncRepLock);
> }

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



Commits

  1. Add some assertions in syncrep.c

  2. Fix race condition at backend exit when deleting element in syncrep queue

  3. Fix typo in comment of syncrep.c