Skip to content

Commit 7c85be0

Browse files
committed
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.
1 parent 7bb3102 commit 7c85be0

File tree

1 file changed

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

1 file changed

+9
-16
lines changed

src/backend/storage/smgr/md.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,19 +1280,16 @@ int
12801280
mdsyncfiletag(const FileTag *ftag, char *path)
12811281
{
12821282
SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId);
1283-
int fd,
1284-
result,
1285-
save_errno;
1283+
File file;
12861284
bool need_to_close;
1285+
int result,
1286+
save_errno;
12871287

12881288
/* See if we already have the file open, or need to open it. */
12891289
if (ftag->segno < reln->md_num_open_segs[ftag->forknum])
12901290
{
1291-
File file;
1292-
12931291
file = reln->md_seg_fds[ftag->forknum][ftag->segno].mdfd_vfd;
12941292
strlcpy(path, FilePathName(file), MAXPGPATH);
1295-
fd = FileGetRawDesc(file);
12961293
need_to_close = false;
12971294
}
12981295
else
@@ -1303,24 +1300,20 @@ mdsyncfiletag(const FileTag *ftag, char *path)
13031300
strlcpy(path, p, MAXPGPATH);
13041301
pfree(p);
13051302

1306-
fd = OpenTransientFile(path, O_RDWR);
1307-
if (fd < 0)
1303+
file = PathNameOpenFile(path, O_RDWR | PG_BINARY);
1304+
if (file < 0)
13081305
return -1;
13091306
need_to_close = true;
13101307
}
13111308

13121309
/* Sync the file. */
1313-
pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_SYNC);
1314-
result = pg_fsync(fd);
1310+
result = FileSync(file, WAIT_EVENT_DATA_FILE_SYNC);
13151311
save_errno = errno;
1316-
pgstat_report_wait_end();
13171312

1318-
if (need_to_close && CloseTransientFile(fd) != 0)
1319-
ereport(WARNING,
1320-
(errcode_for_file_access(),
1321-
errmsg("could not close file \"%s\": %m", path)));
1322-
errno = save_errno;
1313+
if (need_to_close)
1314+
FileClose(file);
13231315

1316+
errno = save_errno;
13241317
return result;
13251318
}
13261319

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy