Re: Problem while setting the fpw with SIGHUP
Amit Kapila <amit.kapila16@gmail.com>
From: Amit Kapila <amit.kapila16@gmail.com>
To: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: Michael Paquier <michael@paquier.xyz>,
Robert Haas <robertmhaas@gmail.com>, hlinnaka <hlinnaka@iki.fi>, Dilip Kumar <dilipbalaut@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2018-07-28T13:35:22Z
Lists: pgsql-hackers
Attachments
- Correctly-attach-FPI-to-the-first-record.2.patch (application/octet-stream) patch
On Fri, Apr 20, 2018 at 6:06 PM, Amit Kapila <amit.kapila16@gmail.com> wrote: > On Fri, Apr 20, 2018 at 11:40 AM, Kyotaro HORIGUCHI > <horiguchi.kyotaro@lab.ntt.co.jp> wrote: >> By the way, I think I found a bug of FPW. >> >> The following steps yields INSERT record that doesn't have a FPI >> after a checkpoint. >> >> (Start server with full_page_writes = off) >> CREATE TABLE t (a int); >> CHECKPOINT; >> INSERT INTO t VALUES (1); >> ALTER SYSTEM SET full_page_writes TO on; >> SELECT pg_reload_conf(); >> CHECKPOINT; >> INSERT INTO t VALUES (1); >> >> The last insert is expected to write a record with FPI but it >> doesn't actually. No FPI will be written for the page after that. >> >> It seems that the reason is that XLogInsertRecord is forgetting >> to check doPageWrites' update. >> >> In the failure case, fpw_lsn has been set by XLogRecordAssemble >> but doPageWrite is false at the time and it considers that no FPI >> is required then it sets fpw_lsn to InvalidXLogRecPtr. >> >> After that, XLogInsertRecord receives the record but it thinks >> that doPageWrites is true since it looks the shared value. >> >>> if (fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr && doPageWrites) >> >> So this line thinks that "no FPI is omitted in this record" but >> actually the record is just forgotten to attach them. >> >> The attached patch lets XLogInsertRecord check if doPageWrites >> has been turned on after the last call and cause recomputation in >> the case. >> > > I think you have correctly spotted the problem and your fix looks good > to me. As this is a separate problem and fix is different from what > we are discussing here, I think this can be committed it separately. > AFAICS, this problem has been introduced by commit 2c03216d831160bedd72d45f712601b6f7d03f1c, so we should backpatch till 9.5. Please find attached the slightly modified patch for this bug. I have modified one of the comments in the patch and the proposed commit message. Can you please once cross-verify if the problem exits till 9.5 and that this patch fixes it? Also, I don't see an easy way to write a test for it, do you have anything in mind? -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com
Commits
-
Fix assertion failure when updating full_page_writes for checkpointer.
- 85cc9c4e2da8 9.5.15 landed
- e315bd7db96a 9.6.11 landed
- 8256d7ae9ee3 10.6 landed
- 6c8671bc395c 11.0 landed
- a86bf6057edf 12.0 landed
-
Attach FPI to the first record after full_page_writes is turned on.
- 47a589c1fe35 9.5.15 landed
- fd4f2af774db 9.6.11 landed
- ede7d8192ca3 10.6 landed
- ff4220ead2c8 11.0 landed
- bc153c941d2e 12.0 landed
-
Revamp the WAL record format.
- 2c03216d8311 9.5.0 cited
-
Move the backup-block logic from XLogInsert to a new file, xloginsert.c.
- 2076db2aea76 9.5.0 cited