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

Commit36e4456

Browse files
committed
Fix race condition if a file is removed while pg_basebackup is running.
If a relation file was removed when the server-side counterpart ofpg_basebackup was just about to open it to send it to the client, you'dget a "could not open file" error. Fix that.Backpatch to 9.1, this goes back to when pg_basebackup was introduced.
1 parentd57a973 commit36e4456

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

‎src/backend/replication/basebackup.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ typedef struct
4444

4545

4646
staticint64sendDir(char*path,intbasepathlen,boolsizeonly);
47-
staticvoidsendFile(char*readfilename,char*tarfilename,
48-
structstat*statbuf);
47+
staticboolsendFile(char*readfilename,char*tarfilename,
48+
structstat*statbuf,boolmissing_ok);
4949
staticvoidsendFileWithContent(constchar*filename,constchar*content);
5050
staticvoid_tarWriteHeader(constchar*filename,constchar*linktarget,
5151
structstat*statbuf);
@@ -199,7 +199,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
199199
XLOG_CONTROL_FILE)));
200200
}
201201

202-
sendFile(XLOG_CONTROL_FILE,XLOG_CONTROL_FILE,&statbuf);
202+
sendFile(XLOG_CONTROL_FILE,XLOG_CONTROL_FILE,&statbuf, false);
203203
}
204204

205205
/*
@@ -712,11 +712,18 @@ sendDir(char *path, int basepathlen, bool sizeonly)
712712
}
713713
elseif (S_ISREG(statbuf.st_mode))
714714
{
715-
/* Add size, rounded up to 512byte block */
716-
size+= ((statbuf.st_size+511)& ~511);
715+
boolsent= false;
716+
717717
if (!sizeonly)
718-
sendFile(pathbuf,pathbuf+basepathlen+1,&statbuf);
719-
size+=512;/* Size of the header of the file */
718+
sent=sendFile(pathbuf,pathbuf+basepathlen+1,&statbuf,
719+
true);
720+
721+
if (sent||sizeonly)
722+
{
723+
/* Add size, rounded up to 512byte block */
724+
size+= ((statbuf.st_size+511)& ~511);
725+
size+=512;/* Size of the header of the file */
726+
}
720727
}
721728
else
722729
ereport(WARNING,
@@ -776,9 +783,17 @@ _tarChecksum(char *header)
776783
returnsum;
777784
}
778785

779-
/* Given the member, write the TAR header & send the file */
780-
staticvoid
781-
sendFile(char*readfilename,char*tarfilename,structstat*statbuf)
786+
/*
787+
* Given the member, write the TAR header & send the file.
788+
*
789+
* If 'missing_ok' is true, will not throw an error if the file is not found.
790+
*
791+
* Returns true if the file was successfully sent, false if 'missing_ok',
792+
* and the file did not exist.
793+
*/
794+
staticbool
795+
sendFile(char*readfilename,char*tarfilename,structstat*statbuf,
796+
boolmissing_ok)
782797
{
783798
FILE*fp;
784799
charbuf[TAR_SEND_SIZE];
@@ -788,9 +803,13 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
788803

789804
fp=AllocateFile(readfilename,"rb");
790805
if (fp==NULL)
806+
{
807+
if (errno==ENOENT&&missing_ok)
808+
return false;
791809
ereport(ERROR,
792810
(errcode_for_file_access(),
793811
errmsg("could not open file \"%s\": %m",readfilename)));
812+
}
794813

795814
/*
796815
* Some compilers will throw a warning knowing this test can never be true
@@ -844,6 +863,8 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
844863
}
845864

846865
FreeFile(fp);
866+
867+
return true;
847868
}
848869

849870

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp