56 for (tli = begin; tli < end; tli++)
85 bool fromArchive =
false;
91 entry->
tli = targetTLI;
111 errmsg(
"could not open file \"%s\": %m", path)));
114 entry->
tli = targetTLI;
136 res = fgets(fline,
sizeof(fline),
fd);
143 errmsg(
"could not read file \"%s\": %m", path)));
149 for (ptr = fline; *ptr; ptr++)
151 if (!isspace((
unsigned char) *ptr))
154 if (*ptr ==
'\0' || *ptr ==
'#')
157 nfields = sscanf(fline,
"%u\t%X/%X", &tli, &switchpoint_hi, &switchpoint_lo);
163 (
errmsg(
"syntax error in history file: %s", fline),
164 errhint(
"Expected a numeric timeline ID.")));
168 (
errmsg(
"syntax error in history file: %s", fline),
169 errhint(
"Expected a write-ahead log switchpoint location.")));
171 if (result && tli <= lasttli)
173 (
errmsg(
"invalid data in history file: %s", fline),
174 errhint(
"Timeline IDs must be in increasing sequence.")));
180 entry->
begin = prevend;
181 entry->
end = ((
uint64) (switchpoint_hi)) << 32 | (
uint64) switchpoint_lo;
182 prevend = entry->
end;
185 result =
lcons(entry, result);
192 if (result && targetTLI <= lasttli)
194 (
errmsg(
"invalid data in history file \"%s\"", path),
195 errhint(
"Timeline IDs must be less than child timeline's ID.")));
202 entry->
tli = targetTLI;
203 entry->
begin = prevend;
206 result =
lcons(entry, result);
251 errmsg(
"could not open file \"%s\": %m", path)));
273 newestTLI = startTLI;
275 for (probeTLI = startTLI + 1;; probeTLI++)
279 newestTLI = probeTLI;
315 Assert(newTLI > parentTLI);
329 errmsg(
"could not create file \"%s\": %m", tmppath)));
348 errmsg(
"could not open file \"%s\": %m", path)));
357 nbytes = (int)
read(srcfd, buffer,
sizeof(buffer));
359 if (nbytes < 0 || errno != 0)
362 errmsg(
"could not read file \"%s\": %m", path)));
367 if ((
int)
write(
fd, buffer, nbytes) != nbytes)
369 int save_errno = errno;
380 errno = save_errno ? save_errno : ENOSPC;
384 errmsg(
"could not write to file \"%s\": %m", tmppath)));
392 errmsg(
"could not close file \"%s\": %m", path)));
403 (srcfd < 0) ?
"" :
"\n",
408 nbytes = strlen(buffer);
411 if ((
int)
write(
fd, buffer, nbytes) != nbytes)
413 int save_errno = errno;
420 errno = save_errno ? save_errno : ENOSPC;
424 errmsg(
"could not write to file \"%s\": %m", tmppath)));
432 errmsg(
"could not fsync file \"%s\": %m", tmppath)));
438 errmsg(
"could not close file \"%s\": %m", tmppath)));
481 errmsg(
"could not create file \"%s\": %m", tmppath)));
487 int save_errno = errno;
494 errno = save_errno ? save_errno : ENOSPC;
498 errmsg(
"could not write to file \"%s\": %m", tmppath)));
506 errmsg(
"could not fsync file \"%s\": %m", tmppath)));
512 errmsg(
"could not close file \"%s\": %m", tmppath)));
548 foreach(cell, history)
561 elog(
ERROR,
"timeline history was not contiguous");
578 foreach(cell, history)
589 (
errmsg(
"requested timeline %u is not in this server's history",
List * readTimeLineHistory(TimeLineID targetTLI)
TimeLineID findNewestTimeLine(TimeLineID startTLI)
void writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history)
XLogRecPtr tliSwitchPoint(TimeLineID tli, List *history, TimeLineID *nextTLI)
bool existsTimeLineHistory(TimeLineID probeTLI)
void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end)
void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, XLogRecPtr switchpoint, char *reason)
bool tliInHistory(TimeLineID tli, List *expectedTLEs)
#define Assert(condition)
static void PGresult * res
int errcode_for_file_access(void)
int errhint(const char *fmt,...)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
int CloseTransientFile(int fd)
int data_sync_elevel(int elevel)
FILE * AllocateFile(const char *name, const char *mode)
int OpenTransientFile(const char *fileName, int fileFlags)
List * lcons(void *datum, List *list)
static int fd(const char *x, int i)
static pg_noinline void Size size
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
#define XLogArchivingActive()
static void TLHistoryFilePath(char *path, TimeLineID tli)
static void TLHistoryFileName(char *fname, TimeLineID tli)
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
void XLogArchiveNotify(const char *xlog)
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
#define LSN_FORMAT_ARGS(lsn)
#define XLogRecPtrIsInvalid(r)
#define InvalidXLogRecPtr
bool ArchiveRecoveryRequested
static List * expectedTLEs