move fetchmot before waiting wal sync, or else backup will failed occasionally when waiting wal sync for more than wal_timeout.

This commit is contained in:
wuyuechuan
2020-11-27 17:27:03 +08:00
parent 467acdb8ea
commit 2a746791fa
2 changed files with 63 additions and 65 deletions

View File

@ -1349,6 +1349,32 @@ static void BaseBackup(void)
disconnect_and_exit(1);
}
/*
* End of copy data. Final result is already checked inside the loop.
*/
PQclear(res);
res = PQgetResult(conn);
if (res != NULL) {
/*
* We expect the result to be NULL, otherwise we received some unexpected result.
* We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE,
* otherwise we have problem! Report error and disconnect.
*/
fprintf(stderr,
_("%s: unexpected result received after final result, status: %u\n"),
progname,
PQresultStatus(res));
free(sysidentifier);
disconnect_and_exit(1);
}
if (verbose) {
fprintf(stderr, "%s: fetching MOT checkpoint\n", progname);
}
FetchMotCheckpoint(basedir, conn, progname, (bool)verbose, format, compresslevel);
if (bgchild > 0) {
#ifndef WIN32
int status;
@ -1428,32 +1454,6 @@ static void BaseBackup(void)
#endif
}
/*
* End of copy data. Final result is already checked inside the loop.
*/
PQclear(res);
res = PQgetResult(conn);
if (res != NULL) {
/*
* We expect the result to be NULL, otherwise we received some unexpected result.
* We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE,
* otherwise we have problem! Report error and disconnect.
*/
fprintf(stderr,
_("%s: unexpected result received after final result, status: %u\n"),
progname,
PQresultStatus(res));
free(sysidentifier);
disconnect_and_exit(1);
}
if (verbose) {
fprintf(stderr, "%s: fetching MOT checkpoint\n", progname);
}
FetchMotCheckpoint(basedir, conn, progname, (bool)verbose, format, compresslevel);
PQfinish(conn);
conn = NULL;

View File

@ -1316,6 +1316,43 @@ static void BaseBackup(const char* dirname, uint32 term)
disconnect_and_exit(1);
}
/*
* End of copy data. Final result is already checked inside the loop.
*/
PQclear(res);
res = PQgetResult(streamConn);
if (res != NULL) {
/*
* We expect the result to be NULL, otherwise we received some unexpected result.
* We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE,
* otherwise we have problem! Report error and disconnect.
*/
pg_log(PG_WARNING, _("unexpected result received after final result, status: %u\n"), PQresultStatus(res));
disconnect_and_exit(1);
}
show_full_build_process("fetching MOT checkpoint");
/* see if we have an mot conf file configured */
nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "postgresql.conf");
securec_check_ss_c(nRet, "\0", "\0");
motConfPath = GetOptionValueFromFile(confPath, "mot_config_file");
if (motConfPath != NULL) {
motChkptDir = GetOptionValueFromFile(motConfPath, "checkpoint_dir");
} else {
nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "mot.conf");
securec_check_ss_c(nRet, "\0", "\0");
motChkptDir = GetOptionValueFromFile(confPath, "checkpoint_dir");
}
FetchMotCheckpoint(motChkptDir ? (const char*)motChkptDir : dirname, streamConn, progname, (bool)verbose);
if (motChkptDir) {
free(motChkptDir);
}
if (motConfPath) {
free(motConfPath);
}
if (bgchild > 0) {
#ifndef WIN32
int status;
@ -1389,45 +1426,6 @@ static void BaseBackup(const char* dirname, uint32 term)
TABLESPACE_LIST_RELEASE();
/*
* End of copy data. Final result is already checked inside the loop.
*/
PQclear(res);
res = PQgetResult(streamConn);
if (res != NULL) {
/*
* We expect the result to be NULL, otherwise we received some unexpected result.
* We just expect a 'Z' message and PQgetResult should set conn->asyncStatus to PGASYNC_IDLE,
* otherwise we have problem! Report error and disconnect.
*/
pg_log(PG_WARNING, _("unexpected result received after final result, status: %u\n"), PQresultStatus(res));
disconnect_and_exit(1);
}
show_full_build_process("fetching MOT checkpoint");
/* see if we have an mot conf file configured */
nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "postgresql.conf");
securec_check_ss_c(nRet, "\0", "\0");
motConfPath = GetOptionValueFromFile(confPath, "mot_config_file");
if (motConfPath != NULL) {
motChkptDir = GetOptionValueFromFile(motConfPath, "checkpoint_dir");
} else {
nRet = sprintf_s(confPath, sizeof(confPath), "%s/%s", dirname, "mot.conf");
securec_check_ss_c(nRet, "\0", "\0");
motChkptDir = GetOptionValueFromFile(confPath, "checkpoint_dir");
}
FetchMotCheckpoint(motChkptDir ? (const char*)motChkptDir : dirname, streamConn, progname, (bool)verbose);
if (motChkptDir) {
free(motChkptDir);
}
if (motConfPath) {
free(motConfPath);
}
PQfinish(streamConn);
streamConn = NULL;