Hi, Bumping this, and attaching v2.
While re-testing on the current master I found that v1 only fixes half
the problem. Here's the full picture.
If a relation's main fork file goes missing while it still has dirty
buffers, and the relation has no other forks (e.g. a small table with
no FSM yet), DROP TABLE skips the buffers. Since bea449c635c (v14) we
only fall back to the full buffer scan when some fork exists but its
size isn't cached; a missing main fork with no other forks looks like
"nothing to drop". After that every checkpoint fails:
and a clean shutdown fails too. Only an immediate shutdown plus crash
recovery gets you out.
To reproduce:
CREATE TABLE t (a int);
INSERT INTO t SELECT generate_series(1, 10);
SELECT pg_relation_filepath('t');
-- remove that file, no checkpoint in between
DROP TABLE t;
CHECKPOINT;
0001 fixes the buffers: if the main fork is missing, fall back to the
full scan. That's the same as v1, with a shorter comment.
With only 0001, though, the next checkpoint PANICs instead:
PANIC: could not fsync file "base/5/16413": No such file or directory
For the main fork, mdunlinkfork() leaves a tombstone rather than
sending a forget request, so the fsync request queued when the file
was extended never gets cancelled. You hit the same PANIC on master
with a bigger table (one that has an FSM), where the buffers do get
dropped.
0002 fixes that: if truncating the main fork fails with ENOENT, forget
its pending sync requests, since there's nothing left to sync.
With both patches, both cases checkpoint cleanly, and the full test
suite passes.
A missing data file already means something went wrong, I know. But
DROP is the natural way to clean up, and right now it leaves the
server unable to checkpoint. I'd suggest backpatching 0001 to 14, and
0002 to all supported branches.
CC'ing Amit and Horiguchi-san (bea449c635c), and Thomas for the smgr size cache.
CommitFest entry: https://commitfest.postgresql.org/patch/7687/
--
Adam
v2-0002-Forget-pending-fsyncs-when-dropping-a-main-fork-t.patch
Description: Binary data
v2-0001-Avoid-orphaning-buffers-when-a-relation-s-main-fo.patch
Description: Binary data
