Subject: Index corruption: two more checkpoint races

Hi,

Two more races like [1] and [2]. A checkpoint can start between a WAL
record and the file change.

1. vac_truncate_clog() truncates CLOG before it advances oldestXid.
After a crash, pg_xact_status() on a removed XID fails with "could not
open file pg_xact/0000" instead of returning NULL. A client that
checks an old transaction after a reconnect gets an error.

The next vacuum does not fix it. It stays until another CLOG segment
is removed.

0001 swaps the two steps, like commit_ts. 0002 is the repro.

2. _hash_alloc_buckets() WAL-logs the new splitpoint before it extends
the file. If a base backup starts in between, the hash index on the new
standby or restored server is broken. It looks fine at first. Once the
index needs an overflow page, inserts fail with "access to noncontiguous
page" until a REINDEX.

A power loss at the same moment can do the same on the primary.

0003 sets DELAY_CHKPT_START around the two steps,
like bulk_write.c. 0004 is the repro.

The fixes apply to 14 and up. 14 needs the old delayChkpt flag. The
tests need 18 and up.

[1]
https://www.postgresql.org/message-id/CAGRkXqRhpq=fd8qf_-ki1ow7b1il+o3yuhihqhlw5rujy2j...@mail.gmail.com
[2]
https://www.postgresql.org/message-id/cagrkxqsuij_x4+z6rsd42pcuacnd9phoq-os+mujnmjarbw...@mail.gmail.com

Thanks,
Shihao

Attachment: v1-0002-Add-test-for-a-checkpoint-that-starts-during-CLOG.patch
Description: Binary data

Attachment: v1-0003-Delay-checkpoint-start-while-allocating-hash-inde.patch
Description: Binary data

Attachment: v1-0001-Advance-oldestXid-before-truncating-CLOG.patch
Description: Binary data

Attachment: v1-0004-Add-test-for-a-checkpoint-that-starts-during-hash.patch
Description: Binary data

Reply via email to