Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit049469e

Browse files
committed
Teach mdnblocks() not to create zero-length files.
It's entirely surprising that mdnblocks() has the side effect ofcreating new files on disk, so let's make it not do that. Oneconsequence of the old behavior is that, if running on a damagedcluster that is missing a file, mdnblocks() can recreate the fileand allow a subsequent _mdfd_getseg() for a higher segment to succeed.This happens because, while mdnblocks() stops when it finds a segmentthat is shorter than 1GB, _mdfd_getseg() has no such check, and thusthe empty file created by mdnblocks() can allow it to continue itstraversal and find higher-numbered segments which remain.It might be a good idea for _mdfd_getseg() to actually verify thateach segment it finds is exactly 1GB before proceeding to the nextone, but that would involve some additional system calls, so fornow I'm just doing this much.Patch by me, per off-list analysis by Kevin Grittner and Rahila Syed.Review by Andres Freund.
1 parent6150a1b commit049469e

File tree

1 file changed

+7
-9
lines changed
  • src/backend/storage/smgr

1 file changed

+7
-9
lines changed

‎src/backend/storage/smgr/md.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,17 +848,15 @@ mdnblocks(SMgrRelation reln, ForkNumber forknum)
848848
if (v->mdfd_chain==NULL)
849849
{
850850
/*
851-
* Because we pass O_CREAT, we will create the next segment (with
852-
* zero length) immediately, if the last segment is of length
853-
* RELSEG_SIZE. While perhaps not strictly necessary, this keeps
854-
* the logic simple.
851+
* We used to pass O_CREAT here, but that's has the disadvantage
852+
* that it might create a segment which has vanished through some
853+
* operating system misadventure. In such a case, creating the
854+
* segment here undermine _mdfd_getseg's attempts to notice and
855+
* report an error upon access to a missing segment.
855856
*/
856-
v->mdfd_chain=_mdfd_openseg(reln,forknum,segno,O_CREAT);
857+
v->mdfd_chain=_mdfd_openseg(reln,forknum,segno,0);
857858
if (v->mdfd_chain==NULL)
858-
ereport(ERROR,
859-
(errcode_for_file_access(),
860-
errmsg("could not open file \"%s\": %m",
861-
_mdfd_segpath(reln,forknum,segno))));
859+
returnsegno* ((BlockNumber)RELSEG_SIZE);
862860
}
863861

864862
v=v->mdfd_chain;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp