mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
pgindent run for 8.3.
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* pg_standby.c
|
||||
*
|
||||
*
|
||||
* Production-ready example of how to create a Warm Standby
|
||||
* database server using continuous archiving as a
|
||||
* database server using continuous archiving as a
|
||||
* replication mechanism
|
||||
*
|
||||
* We separate the parameters for archive and nextWALfile
|
||||
* so that we can check the archive exists, even if the
|
||||
* so that we can check the archive exists, even if the
|
||||
* WAL file doesn't (yet).
|
||||
*
|
||||
* This program will be executed once in full for each file
|
||||
@ -14,9 +14,9 @@
|
||||
*
|
||||
* It is designed to cater to a variety of needs, as well
|
||||
* providing a customizable section.
|
||||
*
|
||||
* Original author: Simon Riggs simon@2ndquadrant.com
|
||||
* Current maintainer: Simon Riggs
|
||||
*
|
||||
* Original author: Simon Riggs simon@2ndquadrant.com
|
||||
* Current maintainer: Simon Riggs
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef WIN32
|
||||
int getopt(int argc, char * const argv[], const char *optstring);
|
||||
int getopt(int argc, char *const argv[], const char *optstring);
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
@ -34,42 +34,44 @@ int getopt(int argc, char * const argv[], const char *optstring);
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#endif /* ! WIN32 */
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
/* Options and defaults */
|
||||
int sleeptime = 5; /* amount of time to sleep between file checks */
|
||||
int waittime = -1; /* how long we have been waiting, -1 no wait yet */
|
||||
int maxwaittime = 0; /* how long are we prepared to wait for? */
|
||||
int keepfiles = 0; /* number of WAL files to keep, 0 keep all */
|
||||
int maxretries = 3; /* number of retries on restore command */
|
||||
bool debug = false; /* are we debugging? */
|
||||
bool triggered = false; /* have we been triggered? */
|
||||
bool need_cleanup = false; /* do we need to remove files from archive? */
|
||||
int sleeptime = 5; /* amount of time to sleep between file checks */
|
||||
int waittime = -1; /* how long we have been waiting, -1 no wait
|
||||
* yet */
|
||||
int maxwaittime = 0; /* how long are we prepared to wait for? */
|
||||
int keepfiles = 0; /* number of WAL files to keep, 0 keep all */
|
||||
int maxretries = 3; /* number of retries on restore command */
|
||||
bool debug = false; /* are we debugging? */
|
||||
bool triggered = false; /* have we been triggered? */
|
||||
bool need_cleanup = false; /* do we need to remove files from
|
||||
* archive? */
|
||||
|
||||
static volatile sig_atomic_t signaled = false;
|
||||
|
||||
char *archiveLocation; /* where to find the archive? */
|
||||
char *triggerPath; /* where to find the trigger file? */
|
||||
char *xlogFilePath; /* where we are going to restore to */
|
||||
char *nextWALFileName; /* the file we need to get from archive */
|
||||
char *restartWALFileName; /* the file from which we can restart restore */
|
||||
char *priorWALFileName; /* the file we need to get from archive */
|
||||
char WALFilePath[MAXPGPATH];/* the file path including archive */
|
||||
char restoreCommand[MAXPGPATH]; /* run this to restore */
|
||||
char exclusiveCleanupFileName[MAXPGPATH]; /* the file we need to get from archive */
|
||||
char *archiveLocation; /* where to find the archive? */
|
||||
char *triggerPath; /* where to find the trigger file? */
|
||||
char *xlogFilePath; /* where we are going to restore to */
|
||||
char *nextWALFileName; /* the file we need to get from archive */
|
||||
char *restartWALFileName; /* the file from which we can restart restore */
|
||||
char *priorWALFileName; /* the file we need to get from archive */
|
||||
char WALFilePath[MAXPGPATH]; /* the file path including archive */
|
||||
char restoreCommand[MAXPGPATH]; /* run this to restore */
|
||||
char exclusiveCleanupFileName[MAXPGPATH]; /* the file we need to
|
||||
* get from archive */
|
||||
|
||||
#define RESTORE_COMMAND_COPY 0
|
||||
#define RESTORE_COMMAND_LINK 1
|
||||
int restoreCommandType;
|
||||
int restoreCommandType;
|
||||
|
||||
#define XLOG_DATA 0
|
||||
#define XLOG_HISTORY 1
|
||||
#define XLOG_BACKUP_LABEL 2
|
||||
int nextWALFileType;
|
||||
int nextWALFileType;
|
||||
|
||||
#define SET_RESTORE_COMMAND(cmd, arg1, arg2) \
|
||||
snprintf(restoreCommand, MAXPGPATH, cmd " \"%s\" \"%s\"", arg1, arg2)
|
||||
@ -86,21 +88,21 @@ struct stat stat_buf;
|
||||
* accessible directory. If you want to make other assumptions,
|
||||
* such as using a vendor-specific archive and access API, these
|
||||
* routines are the ones you'll need to change. You're
|
||||
* enouraged to submit any changes to pgsql-patches@postgresql.org
|
||||
* or personally to the current maintainer. Those changes may be
|
||||
* enouraged to submit any changes to pgsql-patches@postgresql.org
|
||||
* or personally to the current maintainer. Those changes may be
|
||||
* folded in to later versions of this program.
|
||||
*/
|
||||
|
||||
#define XLOG_DATA_FNAME_LEN 24
|
||||
#define XLOG_DATA_FNAME_LEN 24
|
||||
/* Reworked from access/xlog_internal.h */
|
||||
#define XLogFileName(fname, tli, log, seg) \
|
||||
snprintf(fname, XLOG_DATA_FNAME_LEN + 1, "%08X%08X%08X", tli, log, seg)
|
||||
|
||||
/*
|
||||
* Initialize allows customized commands into the warm standby program.
|
||||
* Initialize allows customized commands into the warm standby program.
|
||||
*
|
||||
* As an example, and probably the common case, we use either
|
||||
* cp/ln commands on *nix, or copy/move command on Windows.
|
||||
* As an example, and probably the common case, we use either
|
||||
* cp/ln commands on *nix, or copy/move command on Windows.
|
||||
*
|
||||
*/
|
||||
static void
|
||||
@ -111,79 +113,79 @@ CustomizableInitialize(void)
|
||||
switch (restoreCommandType)
|
||||
{
|
||||
case RESTORE_COMMAND_LINK:
|
||||
SET_RESTORE_COMMAND("mklink",WALFilePath, xlogFilePath);
|
||||
SET_RESTORE_COMMAND("mklink", WALFilePath, xlogFilePath);
|
||||
case RESTORE_COMMAND_COPY:
|
||||
default:
|
||||
SET_RESTORE_COMMAND("copy",WALFilePath, xlogFilePath);
|
||||
SET_RESTORE_COMMAND("copy", WALFilePath, xlogFilePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
snprintf(WALFilePath, MAXPGPATH, "%s/%s", archiveLocation, nextWALFileName);
|
||||
switch (restoreCommandType)
|
||||
{
|
||||
case RESTORE_COMMAND_LINK:
|
||||
#if HAVE_WORKING_LINK
|
||||
SET_RESTORE_COMMAND("ln -s -f",WALFilePath, xlogFilePath);
|
||||
SET_RESTORE_COMMAND("ln -s -f", WALFilePath, xlogFilePath);
|
||||
break;
|
||||
#endif
|
||||
case RESTORE_COMMAND_COPY:
|
||||
default:
|
||||
SET_RESTORE_COMMAND("cp",WALFilePath, xlogFilePath);
|
||||
SET_RESTORE_COMMAND("cp", WALFilePath, xlogFilePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This code assumes that archiveLocation is a directory
|
||||
* You may wish to add code to check for tape libraries, etc..
|
||||
* So, since it is a directory, we use stat to test if its accessible
|
||||
* This code assumes that archiveLocation is a directory You may wish to
|
||||
* add code to check for tape libraries, etc.. So, since it is a
|
||||
* directory, we use stat to test if its accessible
|
||||
*/
|
||||
if (stat(archiveLocation, &stat_buf) != 0)
|
||||
{
|
||||
fprintf(stderr, "pg_standby: archiveLocation \"%s\" does not exist\n", archiveLocation);
|
||||
fprintf(stderr, "pg_standby: archiveLocation \"%s\" does not exist\n", archiveLocation);
|
||||
fflush(stderr);
|
||||
exit(2);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* CustomizableNextWALFileReady()
|
||||
*
|
||||
*
|
||||
* Is the requested file ready yet?
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
CustomizableNextWALFileReady()
|
||||
{
|
||||
if (stat(WALFilePath, &stat_buf) == 0)
|
||||
{
|
||||
/*
|
||||
* If its a backup file, return immediately
|
||||
* If its a regular file return only if its the right size already
|
||||
* If its a backup file, return immediately If its a regular file
|
||||
* return only if its the right size already
|
||||
*/
|
||||
if (strlen(nextWALFileName) > 24 &&
|
||||
strspn(nextWALFileName, "0123456789ABCDEF") == 24 &&
|
||||
strcmp(nextWALFileName + strlen(nextWALFileName) - strlen(".backup"),
|
||||
".backup") == 0)
|
||||
strcmp(nextWALFileName + strlen(nextWALFileName) - strlen(".backup"),
|
||||
".backup") == 0)
|
||||
{
|
||||
nextWALFileType = XLOG_BACKUP_LABEL;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (stat_buf.st_size == XLOG_SEG_SIZE)
|
||||
{
|
||||
else if (stat_buf.st_size == XLOG_SEG_SIZE)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* Windows reports that the file has the right number of bytes
|
||||
* even though the file is still being copied and cannot be
|
||||
* opened by pg_standby yet. So we wait for sleeptime secs
|
||||
* before attempting to restore. If that is not enough, we
|
||||
* will rely on the retry/holdoff mechanism.
|
||||
*/
|
||||
pg_usleep(sleeptime * 1000000L);
|
||||
|
||||
/*
|
||||
* Windows reports that the file has the right number of bytes
|
||||
* even though the file is still being copied and cannot be opened
|
||||
* by pg_standby yet. So we wait for sleeptime secs before
|
||||
* attempting to restore. If that is not enough, we will rely on
|
||||
* the retry/holdoff mechanism.
|
||||
*/
|
||||
pg_usleep(sleeptime * 1000000L);
|
||||
#endif
|
||||
nextWALFileType = XLOG_DATA;
|
||||
return true;
|
||||
}
|
||||
nextWALFileType = XLOG_DATA;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* If still too small, wait until it is the correct size
|
||||
@ -192,10 +194,10 @@ CustomizableNextWALFileReady()
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
fprintf(stderr, "file size greater than expected\n");
|
||||
fprintf(stderr, "file size greater than expected\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
exit(3);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,35 +214,36 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
*/
|
||||
if (nextWALFileType == XLOG_DATA)
|
||||
{
|
||||
int rc;
|
||||
DIR *xldir;
|
||||
struct dirent *xlde;
|
||||
int rc;
|
||||
DIR *xldir;
|
||||
struct dirent *xlde;
|
||||
|
||||
/*
|
||||
* Assume its OK to keep failing. The failure situation may change over
|
||||
* time, so we'd rather keep going on the main processing than fail
|
||||
* because we couldnt clean up yet.
|
||||
* Assume its OK to keep failing. The failure situation may change
|
||||
* over time, so we'd rather keep going on the main processing than
|
||||
* fail because we couldnt clean up yet.
|
||||
*/
|
||||
if ((xldir = opendir(archiveLocation)) != NULL)
|
||||
{
|
||||
while ((xlde = readdir(xldir)) != NULL)
|
||||
{
|
||||
/*
|
||||
* We ignore the timeline part of the XLOG segment identifiers in
|
||||
* deciding whether a segment is still needed. This ensures that we
|
||||
* won't prematurely remove a segment from a parent timeline. We could
|
||||
* probably be a little more proactive about removing segments of
|
||||
* non-parent timelines, but that would be a whole lot more
|
||||
* complicated.
|
||||
* We ignore the timeline part of the XLOG segment identifiers
|
||||
* in deciding whether a segment is still needed. This
|
||||
* ensures that we won't prematurely remove a segment from a
|
||||
* parent timeline. We could probably be a little more
|
||||
* proactive about removing segments of non-parent timelines,
|
||||
* but that would be a whole lot more complicated.
|
||||
*
|
||||
* We use the alphanumeric sorting property of the filenames to decide
|
||||
* which ones are earlier than the exclusiveCleanupFileName file.
|
||||
* Note that this means files are not removed in the order they were
|
||||
* originally written, in case this worries you.
|
||||
* We use the alphanumeric sorting property of the filenames
|
||||
* to decide which ones are earlier than the
|
||||
* exclusiveCleanupFileName file. Note that this means files
|
||||
* are not removed in the order they were originally written,
|
||||
* in case this worries you.
|
||||
*/
|
||||
if (strlen(xlde->d_name) == XLOG_DATA_FNAME_LEN &&
|
||||
strspn(xlde->d_name, "0123456789ABCDEF") == XLOG_DATA_FNAME_LEN &&
|
||||
strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0)
|
||||
strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0)
|
||||
{
|
||||
#ifdef WIN32
|
||||
snprintf(WALFilePath, MAXPGPATH, "%s\\%s", archiveLocation, xlde->d_name);
|
||||
@ -249,7 +252,7 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
#endif
|
||||
|
||||
if (debug)
|
||||
fprintf(stderr, "\nremoving \"%s\"", WALFilePath);
|
||||
fprintf(stderr, "\nremoving \"%s\"", WALFilePath);
|
||||
|
||||
rc = unlink(WALFilePath);
|
||||
if (rc != 0)
|
||||
@ -264,7 +267,7 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "pg_standby: archiveLocation \"%s\" open error\n", archiveLocation);
|
||||
fprintf(stderr, "pg_standby: archiveLocation \"%s\" open error\n", archiveLocation);
|
||||
|
||||
closedir(xldir);
|
||||
fflush(stderr);
|
||||
@ -278,19 +281,19 @@ CustomizableCleanupPriorWALFiles(void)
|
||||
|
||||
/*
|
||||
* SetWALFileNameForCleanup()
|
||||
*
|
||||
*
|
||||
* Set the earliest WAL filename that we want to keep on the archive
|
||||
* and decide whether we need_cleanup
|
||||
* and decide whether we need_cleanup
|
||||
*/
|
||||
static bool
|
||||
SetWALFileNameForCleanup(void)
|
||||
{
|
||||
uint32 tli = 1,
|
||||
log = 0,
|
||||
seg = 0;
|
||||
uint32 log_diff = 0,
|
||||
seg_diff = 0;
|
||||
bool cleanup = false;
|
||||
uint32 tli = 1,
|
||||
log = 0,
|
||||
seg = 0;
|
||||
uint32 log_diff = 0,
|
||||
seg_diff = 0;
|
||||
bool cleanup = false;
|
||||
|
||||
if (restartWALFileName)
|
||||
{
|
||||
@ -305,7 +308,7 @@ SetWALFileNameForCleanup(void)
|
||||
{
|
||||
log_diff = keepfiles / MaxSegmentsPerLogFile;
|
||||
seg_diff = keepfiles % MaxSegmentsPerLogFile;
|
||||
if (seg_diff > seg)
|
||||
if (seg_diff > seg)
|
||||
{
|
||||
log_diff++;
|
||||
seg = MaxSegmentsPerLogFile - seg_diff;
|
||||
@ -333,31 +336,30 @@ SetWALFileNameForCleanup(void)
|
||||
|
||||
/*
|
||||
* CheckForExternalTrigger()
|
||||
*
|
||||
*
|
||||
* Is there a trigger file?
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
CheckForExternalTrigger(void)
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* Look for a trigger file, if that option has been selected
|
||||
* Look for a trigger file, if that option has been selected
|
||||
*
|
||||
* We use stat() here because triggerPath is always a file
|
||||
* rather than potentially being in an archive
|
||||
* We use stat() here because triggerPath is always a file rather than
|
||||
* potentially being in an archive
|
||||
*/
|
||||
if (triggerPath && stat(triggerPath, &stat_buf) == 0)
|
||||
{
|
||||
fprintf(stderr, "trigger file found\n");
|
||||
fprintf(stderr, "trigger file found\n");
|
||||
fflush(stderr);
|
||||
|
||||
/*
|
||||
* If trigger file found, we *must* delete it. Here's why:
|
||||
* When recovery completes, we will be asked again
|
||||
* for the same file from the archive using pg_standby
|
||||
* so must remove trigger file so we can reload file again
|
||||
* and come up correctly.
|
||||
* If trigger file found, we *must* delete it. Here's why: When
|
||||
* recovery completes, we will be asked again for the same file from
|
||||
* the archive using pg_standby so must remove trigger file so we can
|
||||
* reload file again and come up correctly.
|
||||
*/
|
||||
rc = unlink(triggerPath);
|
||||
if (rc != 0)
|
||||
@ -374,14 +376,14 @@ CheckForExternalTrigger(void)
|
||||
|
||||
/*
|
||||
* RestoreWALFileForRecovery()
|
||||
*
|
||||
*
|
||||
* Perform the action required to restore the file from archive
|
||||
*/
|
||||
static bool
|
||||
RestoreWALFileForRecovery(void)
|
||||
{
|
||||
int rc = 0;
|
||||
int numretries = 0;
|
||||
int rc = 0;
|
||||
int numretries = 0;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -401,7 +403,7 @@ RestoreWALFileForRecovery(void)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
pg_usleep(numretries++ * sleeptime * 1000000L);
|
||||
pg_usleep(numretries++ * sleeptime * 1000000L);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -441,13 +443,13 @@ sighandler(int sig)
|
||||
}
|
||||
|
||||
/*------------ MAIN ----------------------------------------*/
|
||||
int
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
|
||||
(void) signal(SIGINT, sighandler);
|
||||
(void) signal(SIGQUIT, sighandler);
|
||||
(void) signal(SIGINT, sighandler);
|
||||
(void) signal(SIGQUIT, sighandler);
|
||||
|
||||
while ((c = getopt(argc, argv, "cdk:lr:s:t:w:")) != -1)
|
||||
{
|
||||
@ -492,8 +494,8 @@ main(int argc, char **argv)
|
||||
case 't': /* Trigger file */
|
||||
triggerPath = optarg;
|
||||
if (CheckForExternalTrigger())
|
||||
exit(1); /* Normal exit, with non-zero */
|
||||
break;
|
||||
exit(1); /* Normal exit, with non-zero */
|
||||
break;
|
||||
case 'w': /* Max wait time */
|
||||
maxwaittime = atoi(optarg);
|
||||
if (maxwaittime < 0)
|
||||
@ -510,7 +512,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Parameter checking - after checking to see if trigger file present
|
||||
*/
|
||||
if (argc == 1)
|
||||
@ -521,8 +523,8 @@ main(int argc, char **argv)
|
||||
|
||||
/*
|
||||
* We will go to the archiveLocation to get nextWALFileName.
|
||||
* nextWALFileName may not exist yet, which would not be an error,
|
||||
* so we separate the archiveLocation and nextWALFileName so we can check
|
||||
* nextWALFileName may not exist yet, which would not be an error, so we
|
||||
* separate the archiveLocation and nextWALFileName so we can check
|
||||
* separately whether archiveLocation exists, if not that is an error
|
||||
*/
|
||||
if (optind < argc)
|
||||
@ -532,7 +534,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "pg_standby: must specify archiveLocation\n");
|
||||
fprintf(stderr, "pg_standby: must specify archiveLocation\n");
|
||||
usage();
|
||||
exit(2);
|
||||
}
|
||||
@ -544,7 +546,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "pg_standby: use %%f to specify nextWALFileName\n");
|
||||
fprintf(stderr, "pg_standby: use %%f to specify nextWALFileName\n");
|
||||
usage();
|
||||
exit(2);
|
||||
}
|
||||
@ -556,7 +558,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "pg_standby: use %%p to specify xlogFilePath\n");
|
||||
fprintf(stderr, "pg_standby: use %%p to specify xlogFilePath\n");
|
||||
usage();
|
||||
exit(2);
|
||||
}
|
||||
@ -573,14 +575,14 @@ main(int argc, char **argv)
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fprintf(stderr, "\nTrigger file : %s", triggerPath ? triggerPath : "<not set>");
|
||||
fprintf(stderr, "\nWaiting for WAL file : %s", nextWALFileName);
|
||||
fprintf(stderr, "\nWAL file path : %s", WALFilePath);
|
||||
fprintf(stderr, "\nRestoring to... : %s", xlogFilePath);
|
||||
fprintf(stderr, "\nSleep interval : %d second%s",
|
||||
sleeptime, (sleeptime > 1 ? "s" : " "));
|
||||
fprintf(stderr, "\nMax wait interval : %d %s",
|
||||
maxwaittime, (maxwaittime > 0 ? "seconds" : "forever"));
|
||||
fprintf(stderr, "\nTrigger file : %s", triggerPath ? triggerPath : "<not set>");
|
||||
fprintf(stderr, "\nWaiting for WAL file : %s", nextWALFileName);
|
||||
fprintf(stderr, "\nWAL file path : %s", WALFilePath);
|
||||
fprintf(stderr, "\nRestoring to... : %s", xlogFilePath);
|
||||
fprintf(stderr, "\nSleep interval : %d second%s",
|
||||
sleeptime, (sleeptime > 1 ? "s" : " "));
|
||||
fprintf(stderr, "\nMax wait interval : %d %s",
|
||||
maxwaittime, (maxwaittime > 0 ? "seconds" : "forever"));
|
||||
fprintf(stderr, "\nCommand for restore : %s", restoreCommand);
|
||||
fprintf(stderr, "\nKeep archive history : %s and later", exclusiveCleanupFileName);
|
||||
fflush(stderr);
|
||||
@ -609,20 +611,20 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Main wait loop
|
||||
*/
|
||||
while (!CustomizableNextWALFileReady() && !triggered)
|
||||
{
|
||||
if (sleeptime <= 60)
|
||||
pg_usleep(sleeptime * 1000000L);
|
||||
pg_usleep(sleeptime * 1000000L);
|
||||
|
||||
if (signaled)
|
||||
{
|
||||
triggered = true;
|
||||
if (debug)
|
||||
{
|
||||
fprintf(stderr, "\nsignaled to exit\n");
|
||||
fprintf(stderr, "\nsignaled to exit\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
@ -631,36 +633,34 @@ main(int argc, char **argv)
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fprintf(stderr, "\nWAL file not present yet.");
|
||||
fprintf(stderr, "\nWAL file not present yet.");
|
||||
if (triggerPath)
|
||||
fprintf(stderr, " Checking for trigger file...");
|
||||
fprintf(stderr, " Checking for trigger file...");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
waittime += sleeptime;
|
||||
|
||||
|
||||
if (!triggered && (CheckForExternalTrigger() || (waittime >= maxwaittime && maxwaittime > 0)))
|
||||
{
|
||||
triggered = true;
|
||||
if (debug && waittime >= maxwaittime && maxwaittime > 0)
|
||||
fprintf(stderr, "\nTimed out after %d seconds\n",waittime);
|
||||
fprintf(stderr, "\nTimed out after %d seconds\n", waittime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Action on exit
|
||||
/*
|
||||
* Action on exit
|
||||
*/
|
||||
if (triggered)
|
||||
exit(1); /* Normal exit, with non-zero */
|
||||
exit(1); /* Normal exit, with non-zero */
|
||||
|
||||
/*
|
||||
* Once we have restored this file successfully we
|
||||
* can remove some prior WAL files.
|
||||
* If this restore fails we musn't remove any
|
||||
* file because some of them will be requested again
|
||||
* immediately after the failed restore, or when
|
||||
* we restart recovery.
|
||||
/*
|
||||
* Once we have restored this file successfully we can remove some prior
|
||||
* WAL files. If this restore fails we musn't remove any file because some
|
||||
* of them will be requested again immediately after the failed restore,
|
||||
* or when we restart recovery.
|
||||
*/
|
||||
if (RestoreWALFileForRecovery() && need_cleanup)
|
||||
CustomizableCleanupPriorWALFiles();
|
||||
|
Reference in New Issue
Block a user