mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-05 21:09:22 +02:00
Make XLogFileCopy() look the same as in 9.4.
XLogFileCopy() was changed heavily in commitde76884
. However it was partially reverted in commit7abc685
and most of those changes to XLogFileCopy() were no longer needed. Then commit7cbee7c
removed those unnecessary code, but XLogFileCopy() looked different in master and 9.4 though the contents are almost the same. This patch makes XLogFileCopy() look the same in master and back-branches, which makes back-patching easier, per discussion on pgsql-hackers. Back-patch to 9.5. Discussion: 55760844.7090703@iki.fi Michael Paquier
This commit is contained in:
parent
31380b900e
commit
6cfb6d9874
@ -808,7 +808,7 @@ static bool XLogCheckpointNeeded(XLogSegNo new_segno);
|
|||||||
static void XLogWrite(XLogwrtRqst WriteRqst, bool flexible);
|
static void XLogWrite(XLogwrtRqst WriteRqst, bool flexible);
|
||||||
static bool InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
static bool InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
||||||
bool find_free, XLogSegNo max_segno,
|
bool find_free, XLogSegNo max_segno,
|
||||||
bool use_lock, int elevel);
|
bool use_lock);
|
||||||
static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
|
static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
|
||||||
int source, bool notexistOk);
|
int source, bool notexistOk);
|
||||||
static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source);
|
static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source);
|
||||||
@ -3013,7 +3013,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
|
|||||||
max_segno = logsegno + CheckPointSegments;
|
max_segno = logsegno + CheckPointSegments;
|
||||||
if (!InstallXLogFileSegment(&installed_segno, tmppath,
|
if (!InstallXLogFileSegment(&installed_segno, tmppath,
|
||||||
*use_existent, max_segno,
|
*use_existent, max_segno,
|
||||||
use_lock, LOG))
|
use_lock))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* No need for any more future segments, or InstallXLogFileSegment()
|
* No need for any more future segments, or InstallXLogFileSegment()
|
||||||
@ -3040,20 +3040,25 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy a WAL segment file in pg_xlog directory.
|
* Create a new XLOG file segment by copying a pre-existing one.
|
||||||
*
|
*
|
||||||
* srcfname source filename
|
* destsegno: identify segment to be created.
|
||||||
* upto how much of the source file to copy? (the rest is filled with
|
|
||||||
* zeros)
|
|
||||||
* segno identify segment to install.
|
|
||||||
*
|
*
|
||||||
* The file is first copied with a temporary filename, and then installed as
|
* srcTLI, srclog, srcseg: identify segment to be copied (could be from
|
||||||
* a newly-created segment.
|
* a different timeline)
|
||||||
|
*
|
||||||
|
* upto: how much of the source file to copy (the rest is filled with
|
||||||
|
* zeros)
|
||||||
|
*
|
||||||
|
* Currently this is only used during recovery, and so there are no locking
|
||||||
|
* considerations. But we should be just as tense as XLogFileInit to avoid
|
||||||
|
* emplacing a bogus file.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
|
||||||
|
int upto)
|
||||||
{
|
{
|
||||||
char srcpath[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
char tmppath[MAXPGPATH];
|
char tmppath[MAXPGPATH];
|
||||||
char buffer[XLOG_BLCKSZ];
|
char buffer[XLOG_BLCKSZ];
|
||||||
int srcfd;
|
int srcfd;
|
||||||
@ -3063,12 +3068,12 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
|||||||
/*
|
/*
|
||||||
* Open the source file
|
* Open the source file
|
||||||
*/
|
*/
|
||||||
snprintf(srcpath, MAXPGPATH, XLOGDIR "/%s", srcfname);
|
XLogFilePath(path, srcTLI, srcsegno);
|
||||||
srcfd = OpenTransientFile(srcpath, O_RDONLY | PG_BINARY, 0);
|
srcfd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
|
||||||
if (srcfd < 0)
|
if (srcfd < 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not open file \"%s\": %m", srcpath)));
|
errmsg("could not open file \"%s\": %m", path)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy into a temp file name.
|
* Copy into a temp file name.
|
||||||
@ -3112,11 +3117,11 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read file \"%s\": %m",
|
errmsg("could not read file \"%s\": %m",
|
||||||
srcpath)));
|
path)));
|
||||||
else
|
else
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errmsg("not enough data in file \"%s\"",
|
(errmsg("not enough data in file \"%s\"",
|
||||||
srcpath)));
|
path)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -3149,9 +3154,11 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
|||||||
|
|
||||||
CloseTransientFile(srcfd);
|
CloseTransientFile(srcfd);
|
||||||
|
|
||||||
/* install the new file */
|
/*
|
||||||
(void) InstallXLogFileSegment(&segno, tmppath, false,
|
* Now move the segment into place with its final name.
|
||||||
0, false, ERROR);
|
*/
|
||||||
|
if (!InstallXLogFileSegment(&destsegno, tmppath, false, 0, false))
|
||||||
|
elog(ERROR, "InstallXLogFileSegment should not have failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3178,8 +3185,6 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
|||||||
* place. This should be TRUE except during bootstrap log creation. The
|
* place. This should be TRUE except during bootstrap log creation. The
|
||||||
* caller must *not* hold the lock at call.
|
* caller must *not* hold the lock at call.
|
||||||
*
|
*
|
||||||
* elevel: log level used by this routine.
|
|
||||||
*
|
|
||||||
* Returns TRUE if the file was installed successfully. FALSE indicates that
|
* Returns TRUE if the file was installed successfully. FALSE indicates that
|
||||||
* max_segno limit was exceeded, or an error occurred while renaming the
|
* max_segno limit was exceeded, or an error occurred while renaming the
|
||||||
* file into place.
|
* file into place.
|
||||||
@ -3187,7 +3192,7 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
|
|||||||
static bool
|
static bool
|
||||||
InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
||||||
bool find_free, XLogSegNo max_segno,
|
bool find_free, XLogSegNo max_segno,
|
||||||
bool use_lock, int elevel)
|
bool use_lock)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
@ -3232,7 +3237,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
|||||||
{
|
{
|
||||||
if (use_lock)
|
if (use_lock)
|
||||||
LWLockRelease(ControlFileLock);
|
LWLockRelease(ControlFileLock);
|
||||||
ereport(elevel,
|
ereport(LOG,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not link file \"%s\" to \"%s\" (initialization of log file): %m",
|
errmsg("could not link file \"%s\" to \"%s\" (initialization of log file): %m",
|
||||||
tmppath, path)));
|
tmppath, path)));
|
||||||
@ -3244,7 +3249,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
|
|||||||
{
|
{
|
||||||
if (use_lock)
|
if (use_lock)
|
||||||
LWLockRelease(ControlFileLock);
|
LWLockRelease(ControlFileLock);
|
||||||
ereport(elevel,
|
ereport(LOG,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not rename file \"%s\" to \"%s\" (initialization of log file): %m",
|
errmsg("could not rename file \"%s\" to \"%s\" (initialization of log file): %m",
|
||||||
tmppath, path)));
|
tmppath, path)));
|
||||||
@ -3733,7 +3738,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
|
|||||||
if (endlogSegNo <= recycleSegNo &&
|
if (endlogSegNo <= recycleSegNo &&
|
||||||
lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) &&
|
lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) &&
|
||||||
InstallXLogFileSegment(&endlogSegNo, path,
|
InstallXLogFileSegment(&endlogSegNo, path,
|
||||||
true, recycleSegNo, true, LOG))
|
true, recycleSegNo, true))
|
||||||
{
|
{
|
||||||
ereport(DEBUG2,
|
ereport(DEBUG2,
|
||||||
(errmsg("recycled transaction log file \"%s\"",
|
(errmsg("recycled transaction log file \"%s\"",
|
||||||
@ -5212,8 +5217,6 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
|
|||||||
*/
|
*/
|
||||||
if (endLogSegNo == startLogSegNo)
|
if (endLogSegNo == startLogSegNo)
|
||||||
{
|
{
|
||||||
XLogFileName(xlogfname, endTLI, endLogSegNo);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make a copy of the file on the new timeline.
|
* Make a copy of the file on the new timeline.
|
||||||
*
|
*
|
||||||
@ -5221,7 +5224,8 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
|
|||||||
* considerations. But we should be just as tense as XLogFileInit to
|
* considerations. But we should be just as tense as XLogFileInit to
|
||||||
* avoid emplacing a bogus file.
|
* avoid emplacing a bogus file.
|
||||||
*/
|
*/
|
||||||
XLogFileCopy(xlogfname, endOfLog % XLOG_SEG_SIZE, endLogSegNo);
|
XLogFileCopy(endLogSegNo, endTLI, endLogSegNo,
|
||||||
|
endOfLog % XLOG_SEG_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user