diff options
author | Thomas Munro <tmunro@postgresql.org> | 2019-04-05 16:39:47 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2019-04-05 17:41:58 +1300 |
commit | 794c543b1736f71ff5bc5231eee41cdf460ad8ce (patch) | |
tree | 0fc903d9dda6ec119314db5619fc41da0e62e1f9 | |
parent | c46c85d4594d52fb34d36d4761bb9cfc5626f20b (diff) | |
download | postgresql-794c543b1736f71ff5bc5231eee41cdf460ad8ce.tar.gz postgresql-794c543b1736f71ff5bc5231eee41cdf460ad8ce.zip |
Fix bugs in mdsyncfiletag().
Commit 3eb77eba moved a _mdfd_getseg() call from mdsync() into a new
callback function mdsyncfiletag(), but didn't get the arguments quite
right. Without the EXTENSION_DONT_CHECK_SIZE flag we fail to open a
segment if lower-numbered segments have been truncated, and it wants
a block number rather than a segment number.
While comparing with the older coding, also remove an unnecessary
clobbering of errno, and adjust the code in mdunlinkfiletag() to
ressemble the original code from mdpostckpt() more closely instead
of using an unnecessary call to smgropen().
Author: Thomas Munro
Discussion: https://postgr.es/m/CA%2BhUKGL%2BYLUOA0eYiBXBfwW%2BbH5kFgh94%3DgQH0jHEJ-t5Y91wQ%40mail.gmail.com
-rw-r--r-- | src/backend/storage/smgr/md.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index ffb3569698f..61a8f11469b 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -1266,14 +1266,14 @@ mdsyncfiletag(const FileTag *ftag, char *path) strlcpy(path, p, MAXPGPATH); pfree(p); - /* Try to find open the requested segment. */ - v = _mdfd_getseg(reln, ftag->forknum, ftag->segno, false, - EXTENSION_RETURN_NULL); + /* Try to open the requested segment. */ + v = _mdfd_getseg(reln, + ftag->forknum, + ftag->segno * (BlockNumber) RELSEG_SIZE, + false, + EXTENSION_RETURN_NULL | EXTENSION_DONT_CHECK_SIZE); if (v == NULL) - { - errno = ENOENT; return -1; - } /* Try to fsync the file. */ return FileSync(v->mdfd_vfd, WAIT_EVENT_DATA_FILE_SYNC); @@ -1288,11 +1288,10 @@ mdsyncfiletag(const FileTag *ftag, char *path) int mdunlinkfiletag(const FileTag *ftag, char *path) { - SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId); char *p; /* Compute the path. */ - p = _mdfd_segpath(reln, ftag->forknum, ftag->segno); + p = relpathperm(ftag->rnode, MAIN_FORKNUM); strlcpy(path, p, MAXPGPATH); pfree(p); |