postgresql/src/backend/access
Peter Geoghegan 0a7d771f0f Make nbtree split REDO locking match original execution.
Make the nbtree page split REDO routine consistent with original
execution in its approach to acquiring and releasing buffer locks (at
least for pages on the tree level of the page being split).  This brings
btree_xlog_split() in line with btree_xlog_unlink_page(), which was
taught to couple buffer locks by commit 9a9db08a.

Note that the precise order in which we both acquire and release sibling
buffer locks in btree_xlog_split() now matches original execution
exactly (the precise order in which the locks are released probably
doesn't matter much, but we might as well be consistent about it).

The rule for nbtree REDO routines from here on is that same-level locks
should be acquired in an order that's consistent with original
execution.  It's not practical to have a similar rule for cross-level
page locks, since for the most part original execution holds those locks
for a period that spans multiple atomic actions/WAL records.  It's also
not necessary, because clearly the cross-level lock coupling is only
truly needed during original execution because of the presence of
concurrent inserters.

This is not a bug fix (unlike the similar aforementioned commit, commit
9a9db08a).  The immediate reason to tighten things up in this area is to
enable an upcoming enhancement to contrib/amcheck that allows it to
verify that sibling links are in agreement with only an AccessShareLock
(this check produced false positives when run on a replica server on
account of the inconsistency fixed by this commit).  But that's not the
only reason to be stricter here.

It is generally useful to make locking on replicas be as close to what
happens during original execution as practically possible.  It makes it
less likely that hard to catch bugs will slip in in the future.  The
previous state of affairs seems to be a holdover from before the
introduction of Hot Standby, when buffer lock acquisitions during
recovery were totally unnecessary.  See also: commit 3bbf668d, which
tightened things up in this area a few years after the introduction of
Hot Standby.

Discussion: https://postgr.es/m/CAH2-Wz=465cJj11YXD9RKH8z=nhQa2dofOZ_23h67EXUGOJ00Q@mail.gmail.com
2020-08-07 15:27:56 -07:00
..
brin Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
common Move syncscan.c to src/backend/access/common. 2020-07-29 16:59:33 +12:00
gin Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
gist Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
hash Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
heap Cache smgrnblocks() results in recovery. 2020-07-31 14:29:52 +12:00
index Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
nbtree Make nbtree split REDO locking match original execution. 2020-08-07 15:27:56 -07:00
rmgrdesc WAL Log invalidations at command end with wal_level=logical. 2020-07-23 08:34:48 +05:30
spgist Invent "amadjustmembers" AM method for validating opclass members. 2020-08-01 17:12:47 -04:00
table Move syncscan.c to src/backend/access/common. 2020-07-29 16:59:33 +12:00
tablesample Move src/backend/utils/hash/hashfn.c to src/common 2020-02-27 09:25:41 +05:30
transam Change XID and mxact limits to warn at 40M and stop at 3M. 2020-08-01 15:31:01 -07:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00