Re: Race condition in SyncRepGetSyncStandbysPriority
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: tgl@sss.pgh.pa.us
Cc: masahiko.sawada@2ndquadrant.com, masao.fujii@oss.nttdata.com,
pgsql-hackers@lists.postgresql.org
Date: 2020-04-15T07:26:50Z
Lists: pgsql-hackers
Attachments
- syncrep-fixes-2.patch (text/x-patch) patch
At Wed, 15 Apr 2020 11:35:58 +0900 (JST), Kyotaro Horiguchi <horikyota.ntt@gmail.com> wrote in > I'm looking this more closer. It looks to be in the right direction to me. As mentioned in the previous mail, I removed is_sync_standby from SycnStandbyData. But just doing that breaks pg_stat_get_wal_senders. It is an exsting issue but the logic for sync_state (values[10]) looks odd. Fixed in the attached. SyncRepInitConfig uses mutex instead of SyncRepLock. Since anyway the integrity of sync_standby_priority is not guaranteed, it seems OK to me. It seems fine to remove the assertion and requirement about SyncRepLock from SyncRepGetSyncRecPtr for the same reason. (Actually the lock is held, though.) SyncRepGetSyncStandbysPriority doesn't seem worth existing as a function. Removed in the attached. + num_standbys = SyncRepGetSyncStandbys(&sync_standbys); The list is no longer consists only of synchronous standbys. I changed the function name, variable name and tried to adjust related comments. It's not what the patch did, but I don't understand why SyncRepGetNthLatestSyncRecPtr takes SyncRepConfig->num_sync but SyncRepGetOldest.. accesses it directly. Changed the function *Oldest* in the attached. I didn't do that but finally, the two functions can be consolidated, just by moving the selection logic currently in SyncRepGetSyncRecPtr into the new function. The resulting patch is attached. - removed is_sync_standby from SyncRepStandbyData - Fixed the logic for values[10] in pg_stat_get_wal_senders - Changed the signature of SyncRepGetOldestSyncRecPtr - Adjusted some comments to the behavioral change of SyncRepGet(Sync)Standbys. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
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