• Robert Haas's avatar
    Teach mdnblocks() not to create zero-length files. · 049469e7
    Robert Haas authored
    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.
    049469e7
md.c 55.2 KB