mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
Fix mdsyncfiletag(), take II.
The previous commit failed to consider that FileGetRawDesc() might not return a valid fd, as discovered on the build farm. Switch to using the File interface only. Back-patch to 12, like the previous commit.
This commit is contained in:
parent
7bb3102cea
commit
7c85be08a2
@ -1280,19 +1280,16 @@ int
|
|||||||
mdsyncfiletag(const FileTag *ftag, char *path)
|
mdsyncfiletag(const FileTag *ftag, char *path)
|
||||||
{
|
{
|
||||||
SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId);
|
SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId);
|
||||||
int fd,
|
File file;
|
||||||
result,
|
|
||||||
save_errno;
|
|
||||||
bool need_to_close;
|
bool need_to_close;
|
||||||
|
int result,
|
||||||
|
save_errno;
|
||||||
|
|
||||||
/* See if we already have the file open, or need to open it. */
|
/* See if we already have the file open, or need to open it. */
|
||||||
if (ftag->segno < reln->md_num_open_segs[ftag->forknum])
|
if (ftag->segno < reln->md_num_open_segs[ftag->forknum])
|
||||||
{
|
{
|
||||||
File file;
|
|
||||||
|
|
||||||
file = reln->md_seg_fds[ftag->forknum][ftag->segno].mdfd_vfd;
|
file = reln->md_seg_fds[ftag->forknum][ftag->segno].mdfd_vfd;
|
||||||
strlcpy(path, FilePathName(file), MAXPGPATH);
|
strlcpy(path, FilePathName(file), MAXPGPATH);
|
||||||
fd = FileGetRawDesc(file);
|
|
||||||
need_to_close = false;
|
need_to_close = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1303,24 +1300,20 @@ mdsyncfiletag(const FileTag *ftag, char *path)
|
|||||||
strlcpy(path, p, MAXPGPATH);
|
strlcpy(path, p, MAXPGPATH);
|
||||||
pfree(p);
|
pfree(p);
|
||||||
|
|
||||||
fd = OpenTransientFile(path, O_RDWR);
|
file = PathNameOpenFile(path, O_RDWR | PG_BINARY);
|
||||||
if (fd < 0)
|
if (file < 0)
|
||||||
return -1;
|
return -1;
|
||||||
need_to_close = true;
|
need_to_close = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sync the file. */
|
/* Sync the file. */
|
||||||
pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_SYNC);
|
result = FileSync(file, WAIT_EVENT_DATA_FILE_SYNC);
|
||||||
result = pg_fsync(fd);
|
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
pgstat_report_wait_end();
|
|
||||||
|
|
||||||
if (need_to_close && CloseTransientFile(fd) != 0)
|
if (need_to_close)
|
||||||
ereport(WARNING,
|
FileClose(file);
|
||||||
(errcode_for_file_access(),
|
|
||||||
errmsg("could not close file \"%s\": %m", path)));
|
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user