pgbackrest.git / summary / log / commit / refs
commit cec486b6dd02b6a755142ad4bee322fb02ff0d23
Author: David Steele <david@pgmasters.net>
Date: Tue Jun 18 03:42:59 2024 +0000
Refactor backup to use flag for backup standby state rather than option.
Using the option adds a bit of complexity -- it is simpler just to use the state of the standby object to determine if backup from standby is enabled.
src/command/backup/backup.c | 24 ++++++++++++------------
test/src/module/command/backupTest.c | 4 +---
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c
index 97573f3f2..d0eb46785 100644
--- a/src/command/backup/backup.c
+++ b/src/command/backup/backup.c
@@ -185,13 +185,14 @@ backupInit(const InfoBackup *const infoBackup)
*result = (BackupData){0};
// Don't allow backup from standby when offline
+ bool backupStandby = cfgOptionBool(cfgOptBackupStandby);
const InfoPgData infoPg = infoPgDataCurrent(infoBackupPg(infoBackup));
- if (!cfgOptionBool(cfgOptOnline) && cfgOptionBool(cfgOptBackupStandby))
+ if (!cfgOptionBool(cfgOptOnline) && backupStandby)
{
LOG_WARN(
"option " CFGOPT_BACKUP_STANDBY " is enabled but backup is offline - backups will be performed from the primary");
- cfgOptionSet(cfgOptBackupStandby, cfgSourceParam, BOOL_FALSE_VAR);
+ backupStandby = false;
}
// Get database info when online
@@ -199,13 +200,12 @@ backupInit(const InfoBackup *const infoBackup)
if (cfgOptionBool(cfgOptOnline))
{
- const bool backupStandby = cfgOptionBool(cfgOptBackupStandby);
const DbGetResult dbInfo = dbGet(!backupStandby, true, backupStandby);
result->pgIdxPrimary = dbInfo.primaryIdx;
result->dbPrimary = dbInfo.primary;
- if (backupStandby)
+ if (dbInfo.standby != NULL)
{
ASSERT(dbInfo.standby != NULL);
@@ -1114,7 +1114,7 @@ backupStart(const BackupData *const backupData)
LOG_INFO_FMT("backup start archive = %s, lsn = %s", strZ(result.walSegmentName), strZ(result.lsn));
// Wait for replay on the standby to catch up
- if (cfgOptionBool(cfgOptBackupStandby))
+ if (backupData->dbStandby != NULL)
{
LOG_INFO_FMT("wait for replay on the standby to reach %s", strZ(result.lsn));
dbReplayWait(backupData->dbStandby, result.lsn, backupData->timeline, cfgOptionUInt64(cfgOptArchiveTimeout));
@@ -1677,7 +1677,7 @@ backupDbPing(const BackupData *const backupData, const bool force)
{
dbPing(backupData->dbPrimary, force);
- if (cfgOptionBool(cfgOptBackupStandby))
+ if (backupData->dbStandby != NULL)
dbPing(backupData->dbStandby, force);
}
@@ -2109,13 +2109,13 @@ backupProcess(const BackupData *const backupData, Manifest *const manifest, cons
const String *const backupLabel = manifestData(manifest)->backupLabel;
const String *const backupPathExp = strNewFmt(STORAGE_REPO_BACKUP "/%s", strZ(backupLabel));
const bool hardLink = cfgOptionBool(cfgOptRepoHardlink) && storageFeature(storageRepoWrite(), storageFeatureHardLink);
- const bool backupStandby = cfgOptionBool(cfgOptBackupStandby);
+ const bool backupStandby = backupData->dbStandby != NULL;
BackupJobData jobData =
{
.manifest = manifest,
.backupLabel = backupLabel,
- .backupStandby = backupStandby,
+ .backupStandby = backupData->dbStandby != NULL,
.compressType = compressTypeEnum(cfgOptionStrId(cfgOptCompressType)),
.compressLevel = cfgOptionInt(cfgOptCompressLevel),
.cipherType = cfgOptionStrId(cfgOptRepoCipherType),
@@ -2197,8 +2197,8 @@ backupProcess(const BackupData *const backupData, Manifest *const manifest, cons
// Create the rest of the clients on the primary or standby depending on the value of backup-standby. Note that standby
// backups don't count the primary client in process-max.
- const unsigned int processMax = cfgOptionUInt(cfgOptProcessMax) + (backupStandby ? 1 : 0);
- const unsigned int pgIdx = backupStandby ? backupData->pgIdxStandby : backupData->pgIdxPrimary;
+ const unsigned int processMax = cfgOptionUInt(cfgOptProcessMax) + (jobData.backupStandby ? 1 : 0);
+ const unsigned int pgIdx = jobData.backupStandby ? backupData->pgIdxStandby : backupData->pgIdxPrimary;
for (unsigned int processIdx = 2; processIdx <= processMax; processIdx++)
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypePg, pgIdx, processIdx));
@@ -2615,7 +2615,7 @@ cmdBackup(void)
backupDbPing(backupData, true);
// The standby db object and protocol won't be used anymore so free them
- if (cfgOptionBool(cfgOptBackupStandby))
+ if (backupData->dbStandby != NULL)
{
dbFree(backupData->dbStandby);
protocolRemoteFree(backupData->pgIdxStandby);
@@ -2630,7 +2630,7 @@ cmdBackup(void)
backupStopResult.walSegmentName, infoPg.id, infoPg.systemId, backupStartResult.dbList,
cfgOptionBool(cfgOptArchiveCheck), cfgOptionBool(cfgOptArchiveCopy), cfgOptionUInt(cfgOptBufferSize),
cfgOptionUInt(cfgOptCompressLevel), cfgOptionUInt(cfgOptCompressLevelNetwork), cfgOptionBool(cfgOptRepoHardlink),
- cfgOptionUInt(cfgOptProcessMax), cfgOptionBool(cfgOptBackupStandby),
+ cfgOptionUInt(cfgOptProcessMax), backupData->dbStandby != NULL,
cfgOptionTest(cfgOptAnnotation) ? cfgOptionKv(cfgOptAnnotation) : NULL);
// The primary db object won't be used anymore so free it
diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c
index 28f7e9cce..4ed96a52a 100644
--- a/test/src/module/command/backupTest.c
+++ b/test/src/module/command/backupTest.c
@@ -1494,9 +1494,7 @@ testRun(void)
HRN_CFG_LOAD(cfgCmdBackup, argList);
TEST_RESULT_VOID(
- backupInit(infoBackupNew(PG_VERSION_96, HRN_PG_SYSTEMID_96, hrnPgCatalogVersion(PG_VERSION_96), NULL)),
- "backup init");
- TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, "check backup-standby");
+ backupInit(infoBackupNew(PG_VERSION_96, HRN_PG_SYSTEMID_96, hrnPgCatalogVersion(PG_VERSION_96), NULL)), "backup init");
TEST_RESULT_LOG(
"P00 WARN: option backup-standby is enabled but backup is offline - backups will be performed from the primary");
[parent: 270dce41b6ff]