55 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;
125 while (fgets(fline,
sizeof(fline), fd) != NULL)
134 for (ptr = fline; *ptr; ptr++)
136 if (!isspace((
unsigned char) *ptr))
139 if (*ptr ==
'\0' || *ptr ==
'#')
142 nfields = sscanf(fline,
"%u\t%X/%X", &tli, &switchpoint_hi, &switchpoint_lo);
148 (
errmsg(
"syntax error in history file: %s", fline),
149 errhint(
"Expected a numeric timeline ID.")));
153 (
errmsg(
"syntax error in history file: %s", fline),
154 errhint(
"Expected a write-ahead log switchpoint location.")));
156 if (result && tli <= lasttli)
158 (
errmsg(
"invalid data in history file: %s", fline),
159 errhint(
"Timeline IDs must be in increasing sequence.")));
165 entry->
begin = prevend;
166 entry->
end = ((uint64) (switchpoint_hi)) << 32 | (uint64) switchpoint_lo;
167 prevend = entry->
end;
170 result =
lcons(entry, result);
177 if (result && targetTLI <= lasttli)
179 (
errmsg(
"invalid data in history file \"%s\"", path),
180 errhint(
"Timeline IDs must be less than child timeline's ID.")));
187 entry->
tli = targetTLI;
188 entry->
begin = prevend;
191 result =
lcons(entry, result);
236 errmsg(
"could not open file \"%s\": %m", path)));
258 newestTLI = startTLI;
260 for (probeTLI = startTLI + 1;; probeTLI++)
264 newestTLI = probeTLI;
300 Assert(newTLI > parentTLI);
314 errmsg(
"could not create file \"%s\": %m", tmppath)));
333 errmsg(
"could not open file \"%s\": %m", path)));
342 nbytes = (int)
read(srcfd, buffer,
sizeof(buffer));
344 if (nbytes < 0 || errno != 0)
347 errmsg(
"could not read file \"%s\": %m", path)));
352 if ((
int)
write(fd, buffer, nbytes) != nbytes)
354 int save_errno = errno;
365 errno = save_errno ? save_errno : ENOSPC;
369 errmsg(
"could not write to file \"%s\": %m", tmppath)));
377 errmsg(
"could not close file \"%s\": %m", path)));
388 (srcfd < 0) ?
"" :
"\n",
393 nbytes = strlen(buffer);
395 if ((
int)
write(fd, buffer, nbytes) != nbytes)
397 int save_errno = errno;
404 errno = save_errno ? save_errno : ENOSPC;
408 errmsg(
"could not write to file \"%s\": %m", tmppath)));
415 errmsg(
"could not fsync file \"%s\": %m", tmppath)));
421 errmsg(
"could not close file \"%s\": %m", tmppath)));
468 errmsg(
"could not create file \"%s\": %m", tmppath)));
472 if ((
int)
write(fd, content, size) != size)
474 int save_errno = errno;
481 errno = save_errno ? save_errno : ENOSPC;
485 errmsg(
"could not write to file \"%s\": %m", tmppath)));
493 errmsg(
"could not fsync file \"%s\": %m", tmppath)));
499 errmsg(
"could not close file \"%s\": %m", tmppath)));
521 foreach(cell, expectedTLEs)
539 foreach(cell, history)
552 elog(
ERROR,
"timeline history was not contiguous");
569 foreach(cell, history)
580 (
errmsg(
"requested timeline %u is not in this server's history",
bool ArchiveRecoveryRequested
#define InvalidXLogRecPtr
TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history)
int errhint(const char *fmt,...)
void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end)
List * readTimeLineHistory(TimeLineID targetTLI)
static List * expectedTLEs
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
static int fd(const char *x, int i)
void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, XLogRecPtr switchpoint, char *reason)
void XLogArchiveNotify(const char *xlog)
TimeLineID findNewestTimeLine(TimeLineID startTLI)
int OpenTransientFile(const char *fileName, int fileFlags)
#define TLHistoryFileName(fname, tli)
void writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
int errcode_for_file_access(void)
FILE * AllocateFile(const char *name, const char *mode)
static void pgstat_report_wait_end(void)
bool existsTimeLineHistory(TimeLineID probeTLI)
#define ereport(elevel, rest)
int CloseTransientFile(int fd)
#define XLogRecPtrIsInvalid(r)
int data_sync_elevel(int elevel)
XLogRecPtr tliSwitchPoint(TimeLineID tli, List *history, TimeLineID *nextTLI)
List * lcons(void *datum, List *list)
#define Assert(condition)
#define XLogArchivingActive()
int durable_link_or_rename(const char *oldfile, const char *newfile, int elevel)
static void pgstat_report_wait_start(uint32 wait_event_info)
int errmsg(const char *fmt,...)
bool tliInHistory(TimeLineID tli, List *expectedTLEs)
#define TLHistoryFilePath(path, tli)