mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Fix possible recovery trouble if TRUNCATE overlaps a checkpoint.
If TRUNCATE causes some buffers to be invalidated and thus the checkpoint does not flush them, TRUNCATE must also ensure that the corresponding files are truncated on disk. Otherwise, a replay from the checkpoint might find that the buffers exist but have the wrong contents, which may cause replay to fail. Report by Teja Mupparti. Patch by Kyotaro Horiguchi, per a design suggestion from Heikki Linnakangas, with some changes to the comments by me. Review of this and a prior patch that approached the issue differently by Heikki Linnakangas, Andres Freund, Álvaro Herrera, Masahiko Sawada, and Tom Lane. Discussion: http://postgr.es/m/BYAPR06MB6373BF50B469CA393C614257ABF00@BYAPR06MB6373.namprd06.prod.outlook.com
This commit is contained in:
@ -6517,18 +6517,30 @@ CreateCheckPoint(int flags)
|
||||
* and we will correctly flush the update below. So we cannot miss any
|
||||
* xacts we need to wait for.
|
||||
*/
|
||||
vxids = GetVirtualXIDsDelayingChkpt(&nvxids);
|
||||
vxids = GetVirtualXIDsDelayingChkpt(&nvxids, DELAY_CHKPT_START);
|
||||
if (nvxids > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
pg_usleep(10000L); /* wait for 10 msec */
|
||||
} while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids));
|
||||
} while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids,
|
||||
DELAY_CHKPT_START));
|
||||
}
|
||||
pfree(vxids);
|
||||
|
||||
CheckPointGuts(checkPoint.redo, flags);
|
||||
|
||||
vxids = GetVirtualXIDsDelayingChkpt(&nvxids, DELAY_CHKPT_COMPLETE);
|
||||
if (nvxids > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
pg_usleep(10000L); /* wait for 10 msec */
|
||||
} while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids,
|
||||
DELAY_CHKPT_COMPLETE));
|
||||
}
|
||||
pfree(vxids);
|
||||
|
||||
/*
|
||||
* Take a snapshot of running transactions and write this to WAL. This
|
||||
* allows us to reconstruct the state of running transactions during
|
||||
|
Reference in New Issue
Block a user