]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Teach mdnblocks() not to create zero-length files.
authorRobert Haas <rhaas@postgresql.org>
Tue, 15 Dec 2015 18:57:45 +0000 (13:57 -0500)
committerRobert Haas <rhaas@postgresql.org>
Tue, 15 Dec 2015 18:57:45 +0000 (13:57 -0500)
commit049469e7e7cfe0c69d30385952e2576b63230283
tree65c6220cd5989a90a3f4cdfec2359e6c52686d03
parent6150a1b08a9fe7ead2b25240be46dddeae9d98e1
Teach mdnblocks() not to create zero-length files.

It's entirely surprising that mdnblocks() has the side effect of
creating new files on disk, so let's make it not do that.  One
consequence of the old behavior is that, if running on a damaged
cluster that is missing a file, mdnblocks() can recreate the file
and allow a subsequent _mdfd_getseg() for a higher segment to succeed.
This happens because, while mdnblocks() stops when it finds a segment
that is shorter than 1GB, _mdfd_getseg() has no such check, and thus
the empty file created by mdnblocks() can allow it to continue its
traversal and find higher-numbered segments which remain.

It might be a good idea for _mdfd_getseg() to actually verify that
each segment it finds is exactly 1GB before proceeding to the next
one, but that would involve some additional system calls, so for
now I'm just doing this much.

Patch by me, per off-list analysis by Kevin Grittner and Rahila Syed.
Review by Andres Freund.
src/backend/storage/smgr/md.c