pgsql: Teach mdnblocks() not to create zero-length files. - Mailing list pgsql-committers

From Robert Haas
Subject pgsql: Teach mdnblocks() not to create zero-length files.
Date
Msg-id E1a8wuS-0007kY-ND@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/049469e7e7cfe0c69d30385952e2576b63230283

Modified Files
--------------
src/backend/storage/smgr/md.c |   16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Move buffer I/O and content LWLocks out of the main tranche.
Next
From: Tom Lane
Date:
Subject: pgsql: Update 9.5 release notes through today.