aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2019-12-14 17:38:09 +1300
committerThomas Munro <tmunro@postgresql.org>2019-12-14 18:35:58 +1300
commit7c85be08a2d404ec2a1a6a3b089e7f08d62e5db8 (patch)
treef9d94448f5422f923511b82ced949dfc03bde132 /src
parent7bb3102cea02101efcbb4c4fba3fdd452a52bdab (diff)
downloadpostgresql-7c85be08a2d404ec2a1a6a3b089e7f08d62e5db8.tar.gz
postgresql-7c85be08a2d404ec2a1a6a3b089e7f08d62e5db8.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/smgr/md.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index b110518a860..82442db046f 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -1280,19 +1280,16 @@ int
mdsyncfiletag(const FileTag *ftag, char *path)
{
SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId);
- int fd,
- result,
- save_errno;
+ File file;
bool need_to_close;
+ int result,
+ save_errno;
/* See if we already have the file open, or need to open it. */
if (ftag->segno < reln->md_num_open_segs[ftag->forknum])
{
- File file;
-
file = reln->md_seg_fds[ftag->forknum][ftag->segno].mdfd_vfd;
strlcpy(path, FilePathName(file), MAXPGPATH);
- fd = FileGetRawDesc(file);
need_to_close = false;
}
else
@@ -1303,24 +1300,20 @@ mdsyncfiletag(const FileTag *ftag, char *path)
strlcpy(path, p, MAXPGPATH);
pfree(p);
- fd = OpenTransientFile(path, O_RDWR);
- if (fd < 0)
+ file = PathNameOpenFile(path, O_RDWR | PG_BINARY);
+ if (file < 0)
return -1;
need_to_close = true;
}
/* Sync the file. */
- pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_SYNC);
- result = pg_fsync(fd);
+ result = FileSync(file, WAIT_EVENT_DATA_FILE_SYNC);
save_errno = errno;
- pgstat_report_wait_end();
- if (need_to_close && CloseTransientFile(fd) != 0)
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not close file \"%s\": %m", path)));
- errno = save_errno;
+ if (need_to_close)
+ FileClose(file);
+ errno = save_errno;
return result;
}