Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb64cea

Browse files
committed
Remove durable_rename_excl()
A previous commit replaced all the calls to this function with durable_rename() as of dac1ff3, making it used nowhere in the tree. Using it in extension code is also risky based on the issues described in this previous commit, so let's remove it. This makes possible the removal of HAVE_WORKING_LINK. Author: Nathan Bossart Reviewed-by: Robert Haas, Kyotaro Horiguchi, Michael Paquier Discussion: https://postgr.es/m/20220407182954.GA1231544@nathanxps13
1 parent dac1ff3 commit eb64cea

File tree

3 files changed

+0
-71
lines changed

3 files changed

+0
-71
lines changed

src/backend/storage/file/fd.c

-63
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

-7
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@
152152
#define EXEC_BACKEND
153153
#endif
154154

155-
/*
156-
* Define this if your operating system supports link()
157-
*/
158-
#if !defined(WIN32) && !defined(__CYGWIN__)
159-
#define HAVE_WORKING_LINK 1
160-
#endif
161-
162155
/*
163156
* USE_POSIX_FADVISE controls whether Postgres will attempt to use the
164157
* posix_fadvise() kernel call. Usually the automatic configure tests are

src/include/storage/fd.h

-1
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)