Skip to content

Commit 2c902bb

Browse files
committed
Remove durable_rename_excl()
ccfbd92 has replaced all existing in-core callers of this function in favor of durable_rename(). durable_rename_excl() is by nature unsafe on crashes happening at the wrong time, so just remove it. Author: Nathan Bossart Reviewed-by: Robert Haas, Kyotaro Horiguchi, Michael Paquier Discussion: https://postgr.es/m/20220407182954.GA1231544@nathanxps13
1 parent ccfbd92 commit 2c902bb

File tree

3 files changed

+0
-71
lines changed

3 files changed

+0
-71
lines changed

src/backend/storage/file/fd.c

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -807,69 +807,6 @@ durable_unlink(const char *fname, int elevel)
807807
return 0;
808808
}
809809

810-
/*
811-
* durable_rename_excl -- rename a file in a durable manner.
812-
*
813-
* Similar to durable_rename(), except that this routine tries (but does not
814-
* guarantee) not to overwrite the target file.
815-
*
816-
* Note that a crash in an unfortunate moment can leave you with two links to
817-
* the target file.
818-
*
819-
* Log errors with the caller specified severity.
820-
*
821-
* On Windows, using a hard link followed by unlink() causes concurrency
822-
* issues, while a simple rename() does not cause that, so be careful when
823-
* changing the logic of this routine.
824-
*
825-
* Returns 0 if the operation succeeded, -1 otherwise. Note that errno is not
826-
* valid upon return.
827-
*/
828-
int
829-
durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
830-
{
831-
/*
832-
* Ensure that, if we crash directly after the rename/link, a file with
833-
* valid contents is moved into place.
834-
*/
835-
if (fsync_fname_ext(oldfile, false, false, elevel) != 0)
836-
return -1;
837-
838-
#ifdef HAVE_WORKING_LINK
839-
if (link(oldfile, newfile) < 0)
840-
{
841-
ereport(elevel,
842-
(errcode_for_file_access(),
843-
errmsg("could not link file \"%s\" to \"%s\": %m",
844-
oldfile, newfile)));
845-
return -1;
846-
}
847-
unlink(oldfile);
848-
#else
849-
if (rename(oldfile, newfile) < 0)
850-
{
851-
ereport(elevel,
852-
(errcode_for_file_access(),
853-
errmsg("could not rename file \"%s\" to \"%s\": %m",
854-
oldfile, newfile)));
855-
return -1;
856-
}
857-
#endif
858-
859-
/*
860-
* Make change persistent in case of an OS crash, both the new entry and
861-
* its parent directory need to be flushed.
862-
*/
863-
if (fsync_fname_ext(newfile, false, false, elevel) != 0)
864-
return -1;
865-
866-
/* Same for parent directory */
867-
if (fsync_parent_path(newfile, elevel) != 0)
868-
return -1;
869-
870-
return 0;
871-
}
872-
873810
/*
874811
* InitFileAccess --- initialize this module during backend startup
875812
*

src/include/pg_config_manual.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,6 @@
163163
#define USE_BARRIER_SMGRRELEASE
164164
#endif
165165

166-
/*
167-
* Define this if your operating system supports link()
168-
*/
169-
#if !defined(WIN32) && !defined(__CYGWIN__)
170-
#define HAVE_WORKING_LINK 1
171-
#endif
172-
173166
/*
174167
* USE_POSIX_FADVISE controls whether Postgres will attempt to use the
175168
* posix_fadvise() kernel call. Usually the automatic configure tests are

src/include/storage/fd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ extern void fsync_fname(const char *fname, bool isdir);
187187
extern int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel);
188188
extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
189189
extern int durable_unlink(const char *fname, int loglevel);
190-
extern int durable_rename_excl(const char *oldfile, const char *newfile, int loglevel);
191190
extern void SyncDataDirectory(void);
192191
extern int data_sync_elevel(int elevel);
193192

0 commit comments

Comments
 (0)