Re: Race condition in SyncRepGetSyncStandbysPriority
Fujii Masao <masao.fujii@oss.nttdata.com>
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Tom Lane <tgl@sss.pgh.pa.us>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: masahiko.sawada@2ndquadrant.com, pgsql-hackers@lists.postgresql.org
Date: 2020-04-16T17:20:04Z
Lists: pgsql-hackers
On 2020/04/14 22:52, Tom Lane wrote: > Kyotaro Horiguchi <horikyota.ntt@gmail.com> writes: >> SyncRepGetSyncStandbysPriority() is runing holding SyncRepLock so >> sync_standby_priority of any walsender can be changed while the >> function is scanning welsenders. The issue is we already have >> inconsistent walsender information before we enter the function. Thus >> how many times we scan on the array doesn't make any difference. > > *Yes it does*. The existing code can deliver entirely broken results > if some walsender exits between where we examine the priorities and > where we fetch the WAL pointers. So, in this case, the oldest lsn that SyncRepGetOldestSyncRecPtr() calculates may be based on also the lsn of already-exited walsender. This is what you say "broken results"? If yes, ISTM that this issue still remains even after applying your patch. No? The walsender marked as sync may still exit just before SyncRepGetOldestSyncRecPtr() calculates the oldest lsn. IMO that the broken results can be delivered when walsender marked as sync exits *and* new walsender comes at that moment. If this new walsender uses the WalSnd slot that the exited walsender used, SyncRepGetOldestSyncRecPtr() wronly calculates the oldest lsn based on this new walsender (i.e., different walsender from one marked as sync). If this is actually what you tried to say "broken results", your patch seems fine and fixes the issue. BTW, since the patch changes the API of SyncRepGetSyncStandbys(), it should not be back-patched to avoid ABI break. Right? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION
Commits
-
Fix race conditions in synchronous standby management.
- c65c1aa82105 9.6.18 landed
- f332241a60aa 13.0 landed
- b3fa6d016d82 11.8 landed
- 63ecdaf758c5 10.13 landed
- 00ef5d52c577 12.3 landed
-
When WalSndCaughtUp, sleep only in WalSndWaitForWal().
- 421685812290 13.0 cited