mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Revert recent changes with durable_rename_excl()
This reverts commits2c902bb
andccfbd92
. Per buildfarm members kestrel, rorqual and calliphoridae, the assertions checking that a TLI history file should not exist when created by a WAL receiver have been failing, and switching to durable_rename() over durable_rename_excl() would cause the newest TLI history file to overwrite the existing one. We need to think harder about such cases, so revert the new logic for now. Note that all the failures have been reported in the test 025_stuck_on_old_timeline. Discussion: https://postgr.es/m/511362.1651116498@sss.pgh.pa.us
This commit is contained in:
@@ -807,6 +807,69 @@ durable_unlink(const char *fname, int elevel)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* durable_rename_excl -- rename a file in a durable manner.
|
||||
*
|
||||
* Similar to durable_rename(), except that this routine tries (but does not
|
||||
* guarantee) not to overwrite the target file.
|
||||
*
|
||||
* Note that a crash in an unfortunate moment can leave you with two links to
|
||||
* the target file.
|
||||
*
|
||||
* Log errors with the caller specified severity.
|
||||
*
|
||||
* On Windows, using a hard link followed by unlink() causes concurrency
|
||||
* issues, while a simple rename() does not cause that, so be careful when
|
||||
* changing the logic of this routine.
|
||||
*
|
||||
* Returns 0 if the operation succeeded, -1 otherwise. Note that errno is not
|
||||
* valid upon return.
|
||||
*/
|
||||
int
|
||||
durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
|
||||
{
|
||||
/*
|
||||
* Ensure that, if we crash directly after the rename/link, a file with
|
||||
* valid contents is moved into place.
|
||||
*/
|
||||
if (fsync_fname_ext(oldfile, false, false, elevel) != 0)
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_WORKING_LINK
|
||||
if (link(oldfile, newfile) < 0)
|
||||
{
|
||||
ereport(elevel,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not link file \"%s\" to \"%s\": %m",
|
||||
oldfile, newfile)));
|
||||
return -1;
|
||||
}
|
||||
unlink(oldfile);
|
||||
#else
|
||||
if (rename(oldfile, newfile) < 0)
|
||||
{
|
||||
ereport(elevel,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not rename file \"%s\" to \"%s\": %m",
|
||||
oldfile, newfile)));
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Make change persistent in case of an OS crash, both the new entry and
|
||||
* its parent directory need to be flushed.
|
||||
*/
|
||||
if (fsync_fname_ext(newfile, false, false, elevel) != 0)
|
||||
return -1;
|
||||
|
||||
/* Same for parent directory */
|
||||
if (fsync_parent_path(newfile, elevel) != 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* InitFileAccess --- initialize this module during backend startup
|
||||
*
|
||||
|
Reference in New Issue
Block a user