pgbackrest.git / summary / log / commit / refs

commit    a42629f87ab70ffaee8d1241eb50c5ea7154a87d
Author:   David Steele <david@pgmasters.net>
Commit:   GitHub <noreply@github.com>
Date:     Mon Sep 09 09:56:52 2024 +0000

    Allow requested standby backup to proceed with no standby.
    
    Add a "prefer" value to the backup-standby option to allow the backup to proceed when no standby is found. Note that this will not help if the standby is responding but fails to sync with the primary after the backup has started.
    
    Introduce a new option modifier, bool-like, that allows a boolean option to be converted to a string or string-id option while still allowing the option to act like a boolean on the command-line, e.g. --no-backup-standby.


doc/xml/release/2024/2.54.xml | 11 ++++++ src/build/config/config.yaml | 13 ++++++- src/build/config/parse.c | 9 ++++- src/build/config/parse.h | 1 + src/build/config/render.c | 3 ++ src/build/help/help.xml | 8 ++++ src/command/backup/backup.c | 12 ++++-- src/command/check/check.c | 4 +- src/command/stanza/common.c | 2 +- src/config/config.auto.h | 7 ++++ src/config/parse.auto.c.inc | 27 ++++++++++++- src/config/parse.c | 33 +++++++++++++--- src/db/helper.c | 8 ++-- src/db/helper.h | 2 +- test/src/common/harnessBackup.c | 17 +++++++- test/src/common/harnessBackup.h | 1 + test/src/module/build/configTest.c | 75 +++++++++++++++++++++++++++++++++++- test/src/module/command/backupTest.c | 63 +++++++++++++++++++++++++++++- test/src/module/command/checkTest.c | 4 +- test/src/module/config/parseTest.c | 31 ++++++++++++++- test/src/module/db/dbTest.c | 67 ++++++++++++++++++++++++-------- 21 files changed, 352 insertions(+), 46 deletions(-) diff --git a/doc/xml/release/2024/2.54.xml b/doc/xml/release/2024/2.54.xml index c7f845a1f..cadb572ad 100644 --- a/doc/xml/release/2024/2.54.xml +++ b/doc/xml/release/2024/2.54.xml @@ -1,6 +1,17 @@ <release date="XXXX-XX-XX" version="2.54dev" title="UNDER DEVELOPMENT"> <release-core-list> <release-improvement-list> + <release-item> + <github-pull-request id="2378"/> + + <release-item-contributor-list> + <release-item-contributor id="david.steele"/> + <release-item-reviewer id="stefan.fercot"/> + </release-item-contributor-list> + + <p>Allow requested standby backup to proceed with no standby.</p> + </release-item> + <release-item> <github-pull-request id="2399"/> diff --git a/src/build/config/config.yaml b/src/build/config/config.yaml index 72c65bc44..b892cbfb2 100644 --- a/src/build/config/config.yaml +++ b/src/build/config/config.yaml @@ -212,6 +212,10 @@ optionGroup: # defined for the option command override, then they override command roles defined for the option (rule 2) above) # and all roles defined for the command (rule 1) above). # +# bool-like: +# Used to convert a boolean to a string or string-id type. It can be used as a boolean (e.g. --option or option=y) and the +# boolean values will be mapped to y/n. Otherwise it is used just as a string or string-id type. +# # required: # In global section: # true - if the option does not have a default, then setting required in the global section means all commands listed in @@ -1226,8 +1230,13 @@ option: backup-standby: section: global - type: boolean - default: false + type: string-id + bool-like: true + default: n + allow-list: + - n + - prefer + - y command: backup: {} check: {} diff --git a/src/build/config/parse.c b/src/build/config/parse.c index e34920d97..fd6fd8012 100644 --- a/src/build/config/parse.c +++ b/src/build/config/parse.c @@ -297,6 +297,7 @@ typedef struct BldCfgOptionRaw const String *name; // See BldCfgOption for comments const String *type; const String *section; + bool boolLike; bool internal; bool beta; const Variant *required; @@ -858,6 +859,10 @@ bldCfgParseOptionList(Yaml *const yaml, const List *const cmdList, const List *c { optRaw.internal = yamlBoolParse(optDefVal); } + else if (strEqZ(optDef.value, "bool-like")) + { + optRaw.boolLike = yamlBoolParse(optDefVal); + } else if (strEqZ(optDef.value, "beta")) { optRaw.beta = yamlBoolParse(optDefVal); @@ -905,7 +910,8 @@ bldCfgParseOptionList(Yaml *const yaml, const List *const cmdList, const List *c if (optRaw.negate == NULL) { optRaw.negate = varNewBool( - strEq(optRaw.type, OPT_TYPE_BOOLEAN_STR) && !strEq(optRaw.section, SECTION_COMMAND_LINE_STR)); + (strEq(optRaw.type, OPT_TYPE_BOOLEAN_STR) || optRaw.boolLike) && + !strEq(optRaw.section, SECTION_COMMAND_LINE_STR)); } // Build default command list if not defined @@ -950,6 +956,7 @@ bldCfgParseOptionList(Yaml *const yaml, const List *const cmdList, const List *c .name = strDup(optRaw->name), .type = strDup(optRaw->type), .section = strDup(optRaw->section), + .boolLike = optRaw->boolLike, .internal = optRaw->internal, .beta = optRaw->beta, .required = varBool(optRaw->required), diff --git a/src/build/config/parse.h b/src/build/config/parse.h index 0b8f6be39..6e4af8e64 100644 --- a/src/build/config/parse.h +++ b/src/build/config/parse.h @@ -125,6 +125,7 @@ struct BldCfgOption const String *name; // Name const String *type; // Option type, e.g. integer const String *section; // Option section, i.e. stanza or global + bool boolLike; // Option accepts y/n and can be treated as bool? bool internal; // Is the option internal? bool beta; // Is the option beta? bool required; // Is the option required? diff --git a/src/build/config/render.c b/src/build/config/render.c index 39443753e..abfd2afed 100644 --- a/src/build/config/render.c +++ b/src/build/config/render.c @@ -863,6 +863,9 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg, co " PARSE_RULE_OPTION_TYPE(%s),\n", strZ(opt->name), strZ(bldEnum("", opt->type))); + if (opt->boolLike) + strCatZ(configOpt, " PARSE_RULE_OPTION_BOOL_LIKE(true),\n"); + if (opt->beta) strCatZ(configOpt, " PARSE_RULE_OPTION_BETA(true),\n"); diff --git a/src/build/help/help.xml b/src/build/help/help.xml index df7dab9b2..b2bbedad4 100644 --- a/src/build/help/help.xml +++ b/src/build/help/help.xml @@ -1376,6 +1376,14 @@ <text> <p>Enable backup from standby to reduce load on the primary cluster. This option requires that both the <host>primary</host> and <host>standby</host> hosts be configured.</p> + + <p>The following modes are supported:</p> + + <list> + <list-item><id>y</id> - Standby is required for backup.</list-item> + <list-item><id>prefer</id> - Backup from standby if available otherwise backup from primary.</list-item> + <list-item><id>n</id> - Backup from primary only.</list-item> + </list> </text> <example>y</example> diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c index 9fbd30c9b..3a9abf697 100644 --- a/src/command/backup/backup.c +++ b/src/command/backup/backup.c @@ -185,14 +185,14 @@ backupInit(const InfoBackup *const infoBackup) *result = (BackupData){0}; // Don't allow backup from standby when offline - bool backupStandby = cfgOptionBool(cfgOptBackupStandby); + StringId backupStandby = cfgOptionStrId(cfgOptBackupStandby); const InfoPgData infoPg = infoPgDataCurrent(infoBackupPg(infoBackup)); - if (!cfgOptionBool(cfgOptOnline) && backupStandby) + if (!cfgOptionBool(cfgOptOnline) && backupStandby != CFGOPTVAL_BACKUP_STANDBY_N) { LOG_WARN( "option " CFGOPT_BACKUP_STANDBY " is enabled but backup is offline - backups will be performed from the primary"); - backupStandby = false; + backupStandby = CFGOPTVAL_BACKUP_STANDBY_N; } // Get database info when online @@ -200,7 +200,11 @@ backupInit(const InfoBackup *const infoBackup) if (cfgOptionBool(cfgOptOnline)) { - const DbGetResult dbInfo = dbGet(!backupStandby, true, backupStandby); + const DbGetResult dbInfo = dbGet(backupStandby == CFGOPTVAL_BACKUP_STANDBY_N, true, backupStandby); + + // If no standby was found but using the primary is allowed then warn and proceed + if (backupStandby == CFGOPTVAL_BACKUP_STANDBY_PREFER && dbInfo.standby == NULL) + LOG_WARN("unable to find a standby to perform the backup, using primary instead"); result->pgIdxPrimary = dbInfo.primaryIdx; result->dbPrimary = dbInfo.primary; diff --git a/src/command/check/check.c b/src/command/check/check.c index 0ed606fff..909933f92 100644 --- a/src/command/check/check.c +++ b/src/command/check/check.c @@ -101,7 +101,7 @@ checkStandby(const DbGetResult dbGroup, const unsigned int pgPathDefinedTotal) dbFree(dbGroup.standby); } // If backup from standby is true then warn when a standby not found - else if (cfgOptionBool(cfgOptBackupStandby)) + else if (cfgOptionStrId(cfgOptBackupStandby) != CFGOPTVAL_BACKUP_STANDBY_N) { LOG_WARN("option '" CFGOPT_BACKUP_STANDBY "' is enabled but standby is not properly configured"); } @@ -225,7 +225,7 @@ cmdCheck(void) } // Get the primary/standby connections (standby is only required if backup from standby is enabled) - DbGetResult dbGroup = dbGet(false, false, false); + DbGetResult dbGroup = dbGet(false, false, CFGOPTVAL_BACKUP_STANDBY_N); if (dbGroup.standby == NULL && dbGroup.primary == NULL) THROW(ConfigError, "no database found\nHINT: check indexed pg-path/pg-host configurations"); diff --git a/src/command/stanza/common.c b/src/command/stanza/common.c index f5f7c5221..40d42983e 100644 --- a/src/command/stanza/common.c +++ b/src/command/stanza/common.c @@ -47,7 +47,7 @@ pgValidate(void) if (cfgOptionBool(cfgOptOnline)) { // Check the primary connections (and standby, if any) and return the primary database object. - const DbGetResult dbObject = dbGet(false, true, false); + const DbGetResult dbObject = dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_N); // Get the pgControl information from the pg*-path deemed to be the primary result = dbPgControl(dbObject.primary); diff --git a/src/config/config.auto.h b/src/config/config.auto.h index d1a4d85a8..f7716cdd8 100644 --- a/src/config/config.auto.h +++ b/src/config/config.auto.h @@ -148,6 +148,13 @@ Option value constants #define CFGOPTVAL_ARCHIVE_MODE_PRESERVE STRID5("preserve", 0x2da45996500) #define CFGOPTVAL_ARCHIVE_MODE_PRESERVE_Z "preserve" +#define CFGOPTVAL_BACKUP_STANDBY_N STRID5("n", 0xe0) +#define CFGOPTVAL_BACKUP_STANDBY_N_Z "n" +#define CFGOPTVAL_BACKUP_STANDBY_PREFER STRID5("prefer", 0x245316500) +#define CFGOPTVAL_BACKUP_STANDBY_PREFER_Z "prefer" +#define CFGOPTVAL_BACKUP_STANDBY_Y STRID5("y", 0x190) +#define CFGOPTVAL_BACKUP_STANDBY_Y_Z "y" + #define CFGOPTVAL_COMPRESS_TYPE_BZ2 STRID5("bz2", 0x73420) #define CFGOPTVAL_COMPRESS_TYPE_BZ2_Z "bz2" #define CFGOPTVAL_COMPRESS_TYPE_GZ STRID5("gz", 0x3470) diff --git a/src/config/parse.auto.c.inc b/src/config/parse.auto.c.inc index dab87559c..6cd506683 100644 --- a/src/config/parse.auto.c.inc +++ b/src/config/parse.auto.c.inc @@ -92,6 +92,7 @@ static const StringPub parseRuleValueStr[] = PARSE_RULE_STRPUB("lsn"), // val/str PARSE_RULE_STRPUB("lz4"), // val/str PARSE_RULE_STRPUB("md5"), // val/str + PARSE_RULE_STRPUB("n"), // val/str PARSE_RULE_STRPUB("name"), // val/str PARSE_RULE_STRPUB("none"), // val/str PARSE_RULE_STRPUB("off"), // val/str @@ -101,6 +102,7 @@ static const StringPub parseRuleValueStr[] = PARSE_RULE_STRPUB("pgbackrest"), // val/str PARSE_RULE_STRPUB("posix"), // val/str PARSE_RULE_STRPUB("postgres"), // val/str + PARSE_RULE_STRPUB("prefer"), // val/str PARSE_RULE_STRPUB("preserve"), // val/str PARSE_RULE_STRPUB("promote"), // val/str PARSE_RULE_STRPUB("repo"), // val/str @@ -124,6 +126,7 @@ static const StringPub parseRuleValueStr[] = PARSE_RULE_STRPUB("warn"), // val/str PARSE_RULE_STRPUB("web-id"), // val/str PARSE_RULE_STRPUB("xid"), // val/str + PARSE_RULE_STRPUB("y"), // val/str PARSE_RULE_STRPUB("zst"), // val/str PARSE_RULE_STRPUB(CFGOPTDEF_CONFIG_PATH), // val/str PARSE_RULE_STRPUB(CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE), // val/str @@ -213,6 +216,7 @@ typedef enum parseRuleValStrQT_lsn_QT, // val/str/enum parseRuleValStrQT_lz4_QT, // val/str/enum parseRuleValStrQT_md5_QT, // val/str/enum + parseRuleValStrQT_n_QT, // val/str/enum parseRuleValStrQT_name_QT, // val/str/enum parseRuleValStrQT_none_QT, // val/str/enum parseRuleValStrQT_off_QT, // val/str/enum @@ -222,6 +226,7 @@ typedef enum parseRuleValStrQT_pgbackrest_QT, // val/str/enum parseRuleValStrQT_posix_QT, // val/str/enum parseRuleValStrQT_postgres_QT, // val/str/enum + parseRuleValStrQT_prefer_QT, // val/str/enum parseRuleValStrQT_preserve_QT, // val/str/enum parseRuleValStrQT_promote_QT, // val/str/enum parseRuleValStrQT_repo_QT, // val/str/enum @@ -245,6 +250,7 @@ typedef enum parseRuleValStrQT_warn_QT, // val/str/enum parseRuleValStrQT_web_DS_id_QT, // val/str/enum parseRuleValStrQT_xid_QT, // val/str/enum + parseRuleValStrQT_y_QT, // val/str/enum parseRuleValStrQT_zst_QT, // val/str/enum parseRuleValStrCFGOPTDEF_CONFIG_PATH, // val/str/enum parseRuleValStrCFGOPTDEF_CONFIG_PATH_SP_QT_FS_QT_SP_PROJECT_CONFIG_FILE, // val/str/enum @@ -284,6 +290,7 @@ static const StringId parseRuleValueStrId[] = STRID5("lsn", 0x3a6c0), // val/strid STRID6("lz4", 0x2068c1), // val/strid STRID5("md5", 0x748d0), // val/strid + STRID5("n", 0xe0), // val/strid STRID5("name", 0x2b42e0), // val/strid STRID5("none", 0x2b9ee0), // val/strid STRID5("off", 0x18cf0), // val/strid @@ -291,6 +298,7 @@ static const StringId parseRuleValueStrId[] = STRID5("pause", 0x59d4300), // val/strid STRID5("pg", 0xf00), // val/strid STRID5("posix", 0x184cdf00), // val/strid + STRID5("prefer", 0x245316500), // val/strid STRID5("preserve", 0x2da45996500), // val/strid STRID5("promote", 0x168f6be500), // val/strid STRID5("repo", 0x7c0b20), // val/strid @@ -313,6 +321,7 @@ static const StringId parseRuleValueStrId[] = STRID5("warn", 0x748370), // val/strid STRID5("web-id", 0x89d88b70), // val/strid STRID5("xid", 0x11380), // val/strid + STRID5("y", 0x190), // val/strid STRID5("zst", 0x527a0), // val/strid }; @@ -344,6 +353,7 @@ static const uint8_t parseRuleValueStrIdStrMap[] = parseRuleValStrQT_lsn_QT, // val/strid/strmap parseRuleValStrQT_lz4_QT, // val/strid/strmap parseRuleValStrQT_md5_QT, // val/strid/strmap + parseRuleValStrQT_n_QT, // val/strid/strmap parseRuleValStrQT_name_QT, // val/strid/strmap parseRuleValStrQT_none_QT, // val/strid/strmap parseRuleValStrQT_off_QT, // val/strid/strmap @@ -351,6 +361,7 @@ static const uint8_t parseRuleValueStrIdStrMap[] = parseRuleValStrQT_pause_QT, // val/strid/strmap parseRuleValStrQT_pg_QT, // val/strid/strmap parseRuleValStrQT_posix_QT, // val/strid/strmap + parseRuleValStrQT_prefer_QT, // val/strid/strmap parseRuleValStrQT_preserve_QT, // val/strid/strmap parseRuleValStrQT_promote_QT, // val/strid/strmap parseRuleValStrQT_repo_QT, // val/strid/strmap @@ -373,6 +384,7 @@ static const uint8_t parseRuleValueStrIdStrMap[] = parseRuleValStrQT_warn_QT, // val/strid/strmap parseRuleValStrQT_web_DS_id_QT, // val/strid/strmap parseRuleValStrQT_xid_QT, // val/strid/strmap + parseRuleValStrQT_y_QT, // val/strid/strmap parseRuleValStrQT_zst_QT, // val/strid/strmap }; @@ -404,6 +416,7 @@ typedef enum parseRuleValStrIdLsn, // val/strid/enum parseRuleValStrIdLz4, // val/strid/enum parseRuleValStrIdMd5, // val/strid/enum + parseRuleValStrIdN, // val/strid/enum parseRuleValStrIdName, // val/strid/enum parseRuleValStrIdNone, // val/strid/enum parseRuleValStrIdOff, // val/strid/enum @@ -411,6 +424,7 @@ typedef enum parseRuleValStrIdPause, // val/strid/enum parseRuleValStrIdPg, // val/strid/enum parseRuleValStrIdPosix, // val/strid/enum + parseRuleValStrIdPrefer, // val/strid/enum parseRuleValStrIdPreserve, // val/strid/enum parseRuleValStrIdPromote, // val/strid/enum parseRuleValStrIdRepo, // val/strid/enum @@ -433,6 +447,7 @@ typedef enum parseRuleValStrIdWarn, // val/strid/enum parseRuleValStrIdWebId, // val/strid/enum parseRuleValStrIdXid, // val/strid/enum + parseRuleValStrIdY, // val/strid/enum parseRuleValStrIdZst, // val/strid/enum } ParseRuleValueStrId; @@ -1396,7 +1411,8 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] = PARSE_RULE_OPTION // opt/backup-standby ( // opt/backup-standby PARSE_RULE_OPTION_NAME("backup-standby"), // opt/backup-standby - PARSE_RULE_OPTION_TYPE(Boolean), // opt/backup-standby + PARSE_RULE_OPTION_TYPE(StringId), // opt/backup-standby + PARSE_RULE_OPTION_BOOL_LIKE(true), // opt/backup-standby PARSE_RULE_OPTION_NEGATE(true), // opt/backup-standby PARSE_RULE_OPTION_RESET(true), // opt/backup-standby PARSE_RULE_OPTION_REQUIRED(true), // opt/backup-standby @@ -1412,9 +1428,16 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] = ( // opt/backup-standby PARSE_RULE_OPTIONAL_GROUP // opt/backup-standby ( // opt/backup-standby + PARSE_RULE_OPTIONAL_ALLOW_LIST // opt/backup-standby + ( // opt/backup-standby + PARSE_RULE_VAL_STRID(N), // opt/backup-standby + PARSE_RULE_VAL_STRID(Prefer), // opt/backup-standby + PARSE_RULE_VAL_STRID(Y), // opt/backup-standby + ), // opt/backup-standby + // opt/backup-standby PARSE_RULE_OPTIONAL_DEFAULT // opt/backup-standby ( // opt/backup-standby - PARSE_RULE_VAL_BOOL_FALSE, // opt/backup-standby + PARSE_RULE_VAL_STRID(N), // opt/backup-standby ), // opt/backup-standby ), // opt/backup-standby ), // opt/backup-standby diff --git a/src/config/parse.c b/src/config/parse.c index e88be2f67..3c5805e13 100644 --- a/src/config/parse.c +++ b/src/config/parse.c @@ -123,6 +123,7 @@ typedef struct ParseRuleOption { const char *name; // Name unsigned int type : 4; // e.g. string, int, boolean + bool boolLike : 1; // Option accepts y/n and can be treated as bool? bool beta : 1; // Is the option a beta feature? bool negate : 1; // Can the option be negated on the command line? bool reset : 1; // Can the option be reset on the command line? @@ -167,6 +168,9 @@ typedef enum #define PARSE_RULE_OPTION_TYPE(typeParam) \ .type = cfgOptType##typeParam +#define PARSE_RULE_OPTION_BOOL_LIKE(boolLikeParam) \ + .boolLike = boolLikeParam + #define PARSE_RULE_OPTION_BETA(betaParam) \ .beta = betaParam @@ -1671,10 +1675,12 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha THROW_FMT(OptionInvalidError, "invalid option '--%s'", arg); // If the option may have an argument (arguments are optional for boolean options) + const ParseRuleOption *const ruleOption = &parseRuleOption[option.id]; + if (!option.negate && !option.reset) { // Handle boolean (only y/n allowed as argument) - if (parseRuleOption[option.id].type == cfgOptTypeBoolean) + if (ruleOption->type == cfgOptTypeBoolean) { // Validate argument/set negate when argument present if (optionArg != NULL) @@ -1688,20 +1694,35 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha } } } - // If no argument was found with the option then try the next argument + // If no argument was found with the option then try the next argument (unless bool-like) else if (optionArg == NULL) { - // Error if there are no more arguments in the list - if (argListIdx == argListSize - 1) + // If bool-like then set arg to y + if (ruleOption->boolLike) + { + optionArg = Y_STR; + } + // Else if there are no more arguments in the list + else if (argListIdx == argListSize - 1) + { THROW_FMT(OptionInvalidError, "option '--%s' requires an argument", strZ(optionName)); - - optionArg = strNewZ(argList[++argListIdx]); + } + // Else get arg + else + optionArg = strNewZ(argList[++argListIdx]); } } // Else error if an argument was found with the option else if (optionArg != NULL) THROW_FMT(OptionInvalidError, "option '%s' does not allow an argument", strZ(optionName)); + // if negated and bool-like then set to n + if (option.negate && ruleOption->boolLike) + { + option.negate = false; + optionArg = N_STR; + } + // Error if this option is secure and cannot be passed on the command line if (cfgParseOptionSecure(option.id)) { diff --git a/src/db/helper.c b/src/db/helper.c index 0b677cc31..64db23151 100644 --- a/src/db/helper.c +++ b/src/db/helper.c @@ -48,17 +48,17 @@ dbGetIdx(const unsigned int pgIdx) } FN_EXTERN DbGetResult -dbGet(const bool primaryOnly, const bool primaryRequired, const bool standbyRequired) +dbGet(const bool primaryOnly, const bool primaryRequired, const StringId standbyRequired) { FUNCTION_LOG_BEGIN(logLevelDebug); FUNCTION_LOG_PARAM(BOOL, primaryOnly); FUNCTION_LOG_PARAM(BOOL, primaryRequired); - FUNCTION_LOG_PARAM(BOOL, standbyRequired); + FUNCTION_LOG_PARAM(STRING_ID, standbyRequired); FUNCTION_LOG_END(); FUNCTION_AUDIT_STRUCT(); - ASSERT(!(primaryOnly && standbyRequired)); + ASSERT(!(primaryOnly && standbyRequired == CFGOPTVAL_BACKUP_STANDBY_Y)); DbGetResult result = {0}; @@ -136,7 +136,7 @@ dbGet(const bool primaryOnly, const bool primaryRequired, const bool standbyRequ } // Error if no standby was found - if (result.standby == NULL && standbyRequired) + if (result.standby == NULL && standbyRequired == CFGOPTVAL_BACKUP_STANDBY_Y) THROW(DbConnectError, "unable to find standby cluster - cannot proceed"); dbMove(result.primary, memContextPrior()); diff --git a/src/db/helper.h b/src/db/helper.h index 1c9f4a482..f17a4bd83 100644 --- a/src/db/helper.h +++ b/src/db/helper.h @@ -22,7 +22,7 @@ typedef struct DbGetResult Db *standby; // Standby db object (NULL if none requested) } DbGetResult; -FN_EXTERN DbGetResult dbGet(bool primaryOnly, bool primaryRequired, bool standbyRequired); +FN_EXTERN DbGetResult dbGet(bool primaryOnly, bool primaryRequired, StringId standbyRequired); /*********************************************************************************************************************************** Macros for function logging diff --git a/test/src/common/harnessBackup.c b/test/src/common/harnessBackup.c index 53bdf9ccf..82d82c1d3 100644 --- a/test/src/common/harnessBackup.c +++ b/test/src/common/harnessBackup.c @@ -264,7 +264,22 @@ hrnBackupPqScript(const unsigned int pgVersion, const time_t backupTimeStart, Hr if (pgVersion <= PG_VERSION_95) HRN_PQ_SCRIPT_ADD(HRN_PQ_SCRIPT_OPEN_GE_93(2, "dbname='postgres' port=5433", pgVersion, pg2Path, true, NULL, NULL)); else - HRN_PQ_SCRIPT_ADD(HRN_PQ_SCRIPT_OPEN_GE_96(2, "dbname='postgres' port=5433", pgVersion, pg2Path, true, NULL, NULL)); + { + if (param.backupStandbyError) + { + HRN_PQ_SCRIPT_ADD( + {.session = 2, .function = HRN_PQ_CONNECTDB, .param = "[\"dbname='postgres' port=5433\"]"}, + {.session = 2, .function = HRN_PQ_STATUS, .resultInt = CONNECTION_BAD}, + {.session = 2, .function = HRN_PQ_ERRORMESSAGE, .resultZ = "error"}); + + param.backupStandby = false; + } + else + { + HRN_PQ_SCRIPT_ADD( + HRN_PQ_SCRIPT_OPEN_GE_96(2, "dbname='postgres' port=5433", pgVersion, pg2Path, true, NULL, NULL)); + } + } } // Get start time diff --git a/test/src/common/harnessBackup.h b/test/src/common/harnessBackup.h index a76dbb8b5..f8ace1102 100644 --- a/test/src/common/harnessBackup.h +++ b/test/src/common/harnessBackup.h @@ -39,6 +39,7 @@ typedef struct HrnBackupPqScriptParam VAR_PARAM_HEADER; bool startFast; // Start backup fast bool backupStandby; // Backup from standby + bool backupStandbyError; // Standby errors on backup from standby bool errorAfterStart; // Error after backup start bool errorAfterCopyStart; // Error after backup copy start bool noWal; // Don't write test WAL segments diff --git a/test/src/module/build/configTest.c b/test/src/module/build/configTest.c index fa5fb2ee4..8009600ff 100644 --- a/test/src/module/build/configTest.c +++ b/test/src/module/build/configTest.c @@ -398,6 +398,20 @@ testRun(void) " deprecate:\n" " online-old: {}\n" "\n" + " bool-like:\n" + " section: global\n" + " type: string-id\n" + " bool-like: true\n" + " default: n\n" + " allow-list:\n" + " - n\n" + " - check\n" + " - y\n" + " command:\n" + " backup: {}\n" + " command-role:\n" + " main: {}\n" + "\n" " backup-standby:\n" " section: global\n" " type: boolean\n" @@ -477,6 +491,7 @@ testRun(void) "Option constants\n" COMMENT_BLOCK_END "\n" "#define CFGOPT_BACKUP_STANDBY \"backup-standby\"\n" + "#define CFGOPT_BOOL_LIKE \"bool-like\"\n" "#define CFGOPT_BUFFER_SIZE \"buffer-size\"\n" "#define CFGOPT_COMPRESS_LEVEL \"compress-level\"\n" "#define CFGOPT_COMPRESS_LEVEL_NETWORK \"compress-level-network\"\n" @@ -490,11 +505,18 @@ testRun(void) "#define CFGOPT_STANZA \"stanza\"\n" "#define CFGOPT_TIMEOUT \"timeout\"\n" "\n" - "#define CFG_OPTION_TOTAL 15\n" + "#define CFG_OPTION_TOTAL 16\n" "\n" COMMENT_BLOCK_BEGIN "\n" "Option value constants\n" COMMENT_BLOCK_END "\n" + "#define CFGOPTVAL_BOOL_LIKE_CHECK STRID5(\"check\", 0xb195030)\n" + "#define CFGOPTVAL_BOOL_LIKE_CHECK_Z \"check\"\n" + "#define CFGOPTVAL_BOOL_LIKE_N STRID5(\"n\", 0xe0)\n" + "#define CFGOPTVAL_BOOL_LIKE_N_Z \"n\"\n" + "#define CFGOPTVAL_BOOL_LIKE_Y STRID5(\"y\", 0x190)\n" + "#define CFGOPTVAL_BOOL_LIKE_Y_Z \"y\"\n" + "\n" "#define CFGOPTVAL_COMPRESS_NETWORK_GZ STRID5(\"gz\", 0x3470)\n" "#define CFGOPTVAL_COMPRESS_NETWORK_GZ_Z \"gz\"\n" "\n" @@ -542,6 +564,7 @@ testRun(void) "typedef enum\n" "{\n" " cfgOptBackupStandby,\n" + " cfgOptBoolLike,\n" " cfgOptBufferSize,\n" " cfgOptCompressLevel,\n" " cfgOptCompressLevelNetwork,\n" @@ -589,13 +612,16 @@ testRun(void) " PARSE_RULE_STRPUB(\"7w\"),\n" " PARSE_RULE_STRPUB(\"8KiB\"),\n" " PARSE_RULE_STRPUB(\"9\"),\n" + " PARSE_RULE_STRPUB(\"check\"),\n" " PARSE_RULE_STRPUB(\"debug1\"),\n" " PARSE_RULE_STRPUB(\"error\"),\n" " PARSE_RULE_STRPUB(\"gz\"),\n" " PARSE_RULE_STRPUB(\"host1\"),\n" " PARSE_RULE_STRPUB(\"info\"),\n" + " PARSE_RULE_STRPUB(\"n\"),\n" " PARSE_RULE_STRPUB(\"off\"),\n" " PARSE_RULE_STRPUB(\"warn\"),\n" + " PARSE_RULE_STRPUB(\"y\"),\n" " PARSE_RULE_STRPUB(CFGOPTDEF_CONFIG_PATH \"/\" PROJECT_CONFIG_FILE),\n" " PARSE_RULE_STRPUB(CFGOPTDEF_CONFIG_PATH \"/.-\" PROJECT_CONFIG_FILE),\n" "};\n" @@ -612,13 +638,16 @@ testRun(void) " parseRuleValStrQT_7w_QT,\n" " parseRuleValStrQT_8KiB_QT,\n" " parseRuleValStrQT_9_QT,\n" + " parseRuleValStrQT_check_QT,\n" " parseRuleValStrQT_debug1_QT,\n" " parseRuleValStrQT_error_QT,\n" " parseRuleValStrQT_gz_QT,\n" " parseRuleValStrQT_host1_QT,\n" " parseRuleValStrQT_info_QT,\n" + " parseRuleValStrQT_n_QT,\n" " parseRuleValStrQT_off_QT,\n" " parseRuleValStrQT_warn_QT,\n" + " parseRuleValStrQT_y_QT,\n" " parseRuleValStrCFGOPTDEF_CONFIG_PATH_SP_QT_FS_QT_SP_PROJECT_CONFIG_FILE,\n" " parseRuleValStrCFGOPTDEF_CONFIG_PATH_SP_QT_FS_DT_DS_QT_SP_PROJECT_CONFIG_FILE,\n" "} ParseRuleValueStr;\n" @@ -630,32 +659,41 @@ testRun(void) "\n" "static const StringId parseRuleValueStrId[] =\n" "{\n" + " STRID5(\"check\", 0xb195030),\n" " STRID6(\"debug1\", 0x7475421441),\n" " STRID5(\"error\", 0x127ca450),\n" " STRID5(\"gz\", 0x3470),\n" " STRID5(\"info\", 0x799c90),\n" + " STRID5(\"n\", 0xe0),\n" " STRID5(\"off\", 0x18cf0),\n" " STRID5(\"warn\", 0x748370),\n" + " STRID5(\"y\", 0x190),\n" "};\n" "\n" "static const uint8_t parseRuleValueStrIdStrMap[] =\n" "{\n" + " parseRuleValStrQT_check_QT,\n" " parseRuleValStrQT_debug1_QT,\n" " parseRuleValStrQT_error_QT,\n" " parseRuleValStrQT_gz_QT,\n" " parseRuleValStrQT_info_QT,\n" + " parseRuleValStrQT_n_QT,\n" " parseRuleValStrQT_off_QT,\n" " parseRuleValStrQT_warn_QT,\n" + " parseRuleValStrQT_y_QT,\n" "};\n" "\n" "typedef enum\n" "{\n" + " parseRuleValStrIdCheck,\n" " parseRuleValStrIdDebug1,\n" " parseRuleValStrIdError,\n" " parseRuleValStrIdGz,\n" " parseRuleValStrIdInfo,\n" + " parseRuleValStrIdN,\n" " parseRuleValStrIdOff,\n" " parseRuleValStrIdWarn,\n" + " parseRuleValStrIdY,\n" "} ParseRuleValueStrId;\n" "\n" COMMENT_BLOCK_BEGIN "\n" @@ -862,6 +900,40 @@ testRun(void) COMMENT_SEPARATOR "\n" " PARSE_RULE_OPTION\n" " (\n" + " PARSE_RULE_OPTION_NAME(\"bool-like\"),\n" + " PARSE_RULE_OPTION_TYPE(StringId),\n" + " PARSE_RULE_OPTION_BOOL_LIKE(true),\n" + " PARSE_RULE_OPTION_NEGATE(true),\n" + " PARSE_RULE_OPTION_RESET(true),\n" + " PARSE_RULE_OPTION_REQUIRED(true),\n" + " PARSE_RULE_OPTION_SECTION(Global),\n" + "\n" + " PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST\n" + " (\n" + " PARSE_RULE_OPTION_COMMAND(Backup)\n" + " ),\n" + "\n" + " PARSE_RULE_OPTIONAL\n" + " (\n" + " PARSE_RULE_OPTIONAL_GROUP\n" + " (\n" + " PARSE_RULE_OPTIONAL_ALLOW_LIST\n" + " (\n" + " PARSE_RULE_VAL_STRID(N),\n" + " PARSE_RULE_VAL_STRID(Check),\n" + " PARSE_RULE_VAL_STRID(Y),\n" + " ),\n" + "\n" + " PARSE_RULE_OPTIONAL_DEFAULT\n" + " (\n" + " PARSE_RULE_VAL_STRID(N),\n" + " ),\n" + " ),\n" + " ),\n" + " ),\n" + COMMENT_SEPARATOR "\n" + " PARSE_RULE_OPTION\n" + " (\n" " PARSE_RULE_OPTION_NAME(\"buffer-size\"),\n" " PARSE_RULE_OPTION_TYPE(Size),\n" " PARSE_RULE_OPTION_RESET(true),\n" @@ -1617,6 +1689,7 @@ testRun(void) "static const uint8_t optionResolveOrder[] =\n" "{\n" " cfgOptStanza,\n" + " cfgOptBoolLike,\n" " cfgOptBufferSize,\n" " cfgOptCompressNetwork,\n" " cfgOptConfig,\n" diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index 8e4d80fdf..356780981 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -2784,7 +2784,7 @@ testRun(void) hrnCfgArgRawBool(argList, cfgOptRepoBundle, true); hrnCfgArgRawBool(argList, cfgOptRepoBlock, true); hrnCfgArgRawBool(argList, cfgOptCompress, false); - hrnCfgArgRawBool(argList, cfgOptBackupStandby, true); + hrnCfgArgRawZ(argList, cfgOptBackupStandby, "prefer"); hrnCfgArgRawBool(argList, cfgOptStartFast, true); HRN_CFG_LOAD(cfgCmdBackup, argList); @@ -2821,6 +2821,67 @@ testRun(void) "compare file list"); } + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("online 9.6 backup-standby (prefer) incr backup with block incremental"); + + backupTimeStart = BACKUP_EPOCH + 1800000; + + { + // Load options + StringList *argList = strLstNew(); + hrnCfgArgRawZ(argList, cfgOptStanza, "test1"); + hrnCfgArgRaw(argList, cfgOptRepoPath, repoPath); + hrnCfgArgKeyRaw(argList, cfgOptPgPath, 1, pg1Path); + hrnCfgArgKeyRaw(argList, cfgOptPgPath, 2, pg2Path); + hrnCfgArgKeyRawZ(argList, cfgOptPgPort, 2, "5433"); + hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1"); + hrnCfgArgRawStrId(argList, cfgOptType, backupTypeIncr); + hrnCfgArgRawBool(argList, cfgOptRepoBundle, true); + hrnCfgArgRawBool(argList, cfgOptRepoBlock, true); + hrnCfgArgRawBool(argList, cfgOptCompress, false); + hrnCfgArgRawZ(argList, cfgOptBackupStandby, "prefer"); + hrnCfgArgRawBool(argList, cfgOptStartFast, true); + HRN_CFG_LOAD(cfgCmdBackup, argList); + + // Run backup + hrnBackupPqScriptP( + PG_VERSION_96, backupTimeStart, .backupStandby = true, .backupStandbyError = true, .startFast = true); + TEST_RESULT_VOID(hrnCmdBackup(), "backup"); + + TEST_RESULT_LOG( + "P00 WARN: unable to check pg2: [DbConnectError] unable to connect to 'dbname='postgres' port=5433': error\n" + "P00 WARN: unable to find a standby to perform the backup, using primary instead\n" + "P00 INFO: last backup label = 20191020-193320F_20191021-232000I, version = " PROJECT_VERSION "\n" + "P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes\n" + "P00 INFO: backup start archive = 0000000105DAFC3000000000, lsn = 5dafc30/0\n" + "P00 INFO: check archive for prior segment 0000000105DAFC2F000000FF\n" + "P01 DETAIL: backup file " TEST_PATH "/pg1/base/1/4 (bundle 1/0, 40KB, [PCT]) checksum [SHA1]\n" + "P01 DETAIL: backup file " TEST_PATH "/pg1/base/1/3 (bundle 1/8234, 40KB, [PCT]) checksum [SHA1]\n" + "P01 DETAIL: backup file " TEST_PATH "/pg1/global/pg_control (bundle 1/16476, 8KB, [PCT]) checksum [SHA1]\n" + "P00 DETAIL: reference pg_data/PG_VERSION to 20191020-193320F\n" + "P00 DETAIL: reference pg_data/postgresql.conf to 20191020-193320F\n" + "P00 INFO: execute non-exclusive backup stop and wait for all WAL segments to archive\n" + "P00 INFO: backup stop archive = 0000000105DAFC3000000000, lsn = 5dafc30/800000\n" + "P00 DETAIL: wrote 'backup_label' file returned from backup stop function\n" + "P00 INFO: check archive for segment(s) 0000000105DAFC3000000000:0000000105DAFC3000000000\n" + "P00 INFO: new backup label = 20191020-193320F_20191023-030640I\n" + "P00 INFO: incr backup size = [SIZE], file total = 6"); + + TEST_RESULT_STR_Z( + testBackupValidateP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/latest")), + ".> {d=20191020-193320F_20191023-030640I}\n" + "bundle/1/pg_data/base/1/3 {s=40960, m=0:{0,1,2},1:{0},2:{0}, ts=-200000}\n" + "bundle/1/pg_data/base/1/4 {s=40960, m=0:{0,1,2,3},2:{0}, ts=-200000}\n" + "bundle/1/pg_data/global/pg_control {s=8192}\n" + "pg_data/backup_label {s=17, ts=+2}\n" + "20191020-193320F/bundle/1/pg_data/PG_VERSION {s=3, ts=-600000}\n" + "20191020-193320F/bundle/1/pg_data/postgresql.conf {s=11, ts=-1800000}\n" + "--------\n" + "[backup:target]\n" + "pg_data={\"path\":\"" TEST_PATH "/pg1\",\"type\":\"path\"}\n", + "compare file list"); + } + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("online 11 full backup with tablespaces and page checksums"); diff --git a/test/src/module/command/checkTest.c b/test/src/module/command/checkTest.c index fbf996a6d..46a1f0ed6 100644 --- a/test/src/module/command/checkTest.c +++ b/test/src/module/command/checkTest.c @@ -590,7 +590,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(1), HRN_PQ_SCRIPT_CLOSE(8)); - TEST_ASSIGN(db, dbGet(false, false, false), "get primary and standby"); + TEST_ASSIGN(db, dbGet(false, false, CFGOPTVAL_BACKUP_STANDBY_N), "get primary and standby"); TEST_RESULT_VOID(checkDbConfig(PG_VERSION_11, db.primaryIdx, db.primary, false), "valid db config"); @@ -651,7 +651,7 @@ testRun(void) HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_11, TEST_PATH "/pg", false, "always", NULL), HRN_PQ_SCRIPT_CLOSE(1)); - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); TEST_ERROR( checkDbConfig(PG_VERSION_11, db.primaryIdx, db.primary, false), FeatureNotSupportedError, "archive_mode=always not supported"); diff --git a/test/src/module/config/parseTest.c b/test/src/module/config/parseTest.c index 3d9fa0ae3..5c4c80438 100644 --- a/test/src/module/config/parseTest.c +++ b/test/src/module/config/parseTest.c @@ -182,7 +182,7 @@ testRun(void) TEST_RESULT_INT(cfgOptionSource(cfgOptRepoHardlink), cfgSourceConfig, "repo-hardlink is source config"); TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, "compress-level is set"); TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, "compress-level is source config"); - TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, "backup-standby not is set"); + TEST_RESULT_UINT(cfgOptionStrId(cfgOptBackupStandby), CFGOPTVAL_BACKUP_STANDBY_N, "backup-standby not is set"); TEST_RESULT_INT(cfgOptionSource(cfgOptBackupStandby), cfgSourceDefault, "backup-standby is source default"); TEST_RESULT_INT(cfgOptionInt64(cfgOptBufferSize), 65536, "buffer-size is set"); TEST_RESULT_INT(cfgOptionSource(cfgOptBufferSize), cfgSourceConfig, "backup-standby is source config"); @@ -1677,6 +1677,33 @@ testRun(void) TEST_RESULT_STRLST_Z( cfgCommandParam(), "000000010000000200000003\n/path/to/wal/RECOVERYWAL\n", "check command arguments"); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("bool-like"); + + StringList *argListBase = strLstNew(); + strLstAddZ(argListBase, TEST_BACKREST_EXE); + strLstAddZ(argListBase, "backup"); + strLstAddZ(argListBase, "--stanza=test"); + strLstAddZ(argListBase, "--pg1-path=/"); + + argList = strLstDup(argListBase); + strLstAddZ(argList, "--no-backup-standby"); + + TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "negate"); + TEST_RESULT_UINT(cfgOptionStrId(cfgOptBackupStandby), CFGOPTVAL_BACKUP_STANDBY_N, "backup-standby is n"); + + argList = strLstDup(argListBase); + strLstAddZ(argList, "--backup-standby"); + + TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "no arg"); + TEST_RESULT_UINT(cfgOptionStrId(cfgOptBackupStandby), CFGOPTVAL_BACKUP_STANDBY_Y, "backup-standby is y"); + + argList = strLstDup(argListBase); + strLstAddZ(argList, "--backup-standby=prefer"); + + TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "prefer arg"); + TEST_RESULT_UINT(cfgOptionStrId(cfgOptBackupStandby), CFGOPTVAL_BACKUP_STANDBY_PREFER, "backup-standby is prefer"); + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("various configuration settings"); @@ -1880,7 +1907,7 @@ testRun(void) TEST_RESULT_INT(varInt64(cfgOptionVar(cfgOptRepoRetentionFull)), 55, "repo-retention-full as variant"); TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, "compress-level is set"); TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, "compress-level is source config"); - TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, "backup-standby not is set"); + TEST_RESULT_UINT(cfgOptionStrId(cfgOptBackupStandby), CFGOPTVAL_BACKUP_STANDBY_N, "backup-standby not is set"); TEST_RESULT_INT(cfgOptionSource(cfgOptBackupStandby), cfgSourceDefault, "backup-standby is source default"); TEST_RESULT_BOOL(cfgOptionIdxReset(cfgOptBackupStandby, 0), true, "backup-standby was reset"); TEST_RESULT_BOOL(cfgOptionBool(cfgOptDelta), true, "delta is set"); diff --git a/test/src/module/db/dbTest.c b/test/src/module/db/dbTest.c index 4f559db5e..a055f1f2c 100644 --- a/test/src/module/db/dbTest.c +++ b/test/src/module/db/dbTest.c @@ -248,7 +248,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(1)); TEST_ERROR( - dbGet(true, true, false), DbConnectError, + dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), DbConnectError, "unable to find primary cluster - cannot proceed\n" "HINT: are all available clusters in recovery?"); @@ -267,7 +267,7 @@ testRun(void) HRN_PQ_SCRIPT_OPEN_GE_93(1, "dbname='backupdb' port=5432", PG_VERSION_95, TEST_PATH "/pg1", false, NULL, NULL)); DbGetResult db = {0}; - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); // Get start time HRN_PQ_SCRIPT_SET(HRN_PQ_SCRIPT_TIME_QUERY(1, 1000)); @@ -323,7 +323,7 @@ testRun(void) HRN_PQ_SCRIPT_SET( HRN_PQ_SCRIPT_OPEN_GE_93(1, "dbname='backupdb' port=5432", PG_VERSION_95, TEST_PATH "/pg1", false, NULL, NULL)); - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); // Start backup when backup is in progress HRN_PQ_SCRIPT_SET( @@ -359,7 +359,7 @@ testRun(void) HRN_PQ_SCRIPT_SET( HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='backupdb' port=5432", PG_VERSION_96, TEST_PATH "/pg1", false, NULL, NULL)); - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); // Start backup with timeline error HRN_PQ_SCRIPT_SET( @@ -421,7 +421,7 @@ testRun(void) HRN_PQ_SCRIPT_OPEN_GE_93(1, "dbname='postgres' port=5432", PG_VERSION_95, TEST_PATH "/pg1", false, NULL, NULL), HRN_PQ_SCRIPT_OPEN_GE_93(2, "dbname='postgres' port=5433", PG_VERSION_95, TEST_PATH "/pg2", true, NULL, NULL)); - TEST_ASSIGN(db, dbGet(false, true, true), "get primary and standby"); + TEST_ASSIGN(db, dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_Y), "get primary and standby"); // Start backup HRN_PQ_SCRIPT_SET( @@ -482,7 +482,7 @@ testRun(void) HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_10, TEST_PATH "/pg1", false, NULL, NULL), HRN_PQ_SCRIPT_OPEN_GE_96(2, "dbname='postgres' port=5433", PG_VERSION_10, TEST_PATH "/pg2", true, NULL, NULL)); - TEST_ASSIGN(db, dbGet(false, true, true), "get primary and standby"); + TEST_ASSIGN(db, dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_Y), "get primary and standby"); TEST_RESULT_UINT(dbPgControl(db.primary).timeline, 5, "check primary timeline"); TEST_RESULT_UINT(dbPgControl(db.standby).timeline, 5, "check standby timeline"); @@ -608,7 +608,7 @@ testRun(void) HRN_PQ_SCRIPT_SET( HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_14, TEST_PATH "/pg1", false, NULL, NULL)); - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); // Start backup HRN_PQ_SCRIPT_SET( @@ -640,7 +640,7 @@ testRun(void) HRN_PQ_SCRIPT_SET( HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_15, TEST_PATH "/pg1", false, NULL, NULL)); - TEST_ASSIGN(db, dbGet(true, true, false), "get primary"); + TEST_ASSIGN(db, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary"); // Start backup HRN_PQ_SCRIPT_SET( @@ -692,7 +692,7 @@ testRun(void) {.function = HRN_PQ_FINISH}); TEST_ERROR( - dbGet(true, true, false), DbConnectError, + dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), DbConnectError, "unable to find primary cluster - cannot proceed\n" "HINT: are all available clusters in recovery?"); TEST_RESULT_LOG( @@ -712,7 +712,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(1)); TEST_ERROR( - dbGet(true, true, false), DbConnectError, + dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), DbConnectError, "unable to find primary cluster - cannot proceed\n" "HINT: are all available clusters in recovery?"); @@ -728,7 +728,8 @@ testRun(void) HRN_PQ_SCRIPT_IS_STANDBY_QUERY(1, false), HRN_PQ_SCRIPT_CLOSE(1)); - TEST_ERROR(dbGet(false, false, true), DbConnectError, "unable to find standby cluster - cannot proceed"); + TEST_ERROR( + dbGet(false, false, CFGOPTVAL_BACKUP_STANDBY_Y), DbConnectError, "unable to find standby cluster - cannot proceed"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("primary cluster found"); @@ -738,7 +739,7 @@ testRun(void) 1, "dbname='postgres' port=5432 user='bob'", PG_VERSION_94, TEST_PATH "/pg1", false, NULL, NULL), HRN_PQ_SCRIPT_CLOSE(1)); - TEST_ASSIGN(result, dbGet(true, true, false), "get primary only"); + TEST_ASSIGN(result, dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary only"); TEST_RESULT_INT(result.primaryIdx, 0, "check primary id"); TEST_RESULT_BOOL(result.primary != NULL, true, "check primary"); @@ -770,7 +771,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(1), HRN_PQ_SCRIPT_CLOSE(8)); - TEST_ERROR(dbGet(true, true, false), DbConnectError, "more than one primary cluster found"); + TEST_ERROR(dbGet(true, true, CFGOPTVAL_BACKUP_STANDBY_N), DbConnectError, "more than one primary cluster found"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("two standbys found but no primary"); @@ -783,7 +784,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(1)); TEST_ERROR( - dbGet(false, true, false), DbConnectError, + dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_N), DbConnectError, "unable to find primary cluster - cannot proceed\n" "HINT: are all available clusters in recovery?"); @@ -797,7 +798,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(8), HRN_PQ_SCRIPT_CLOSE(1)); - TEST_ASSIGN(result, dbGet(false, false, false), "get standbys"); + TEST_ASSIGN(result, dbGet(false, false, CFGOPTVAL_BACKUP_STANDBY_N), "get standbys"); TEST_RESULT_INT(result.primaryIdx, 0, "check primary id"); TEST_RESULT_BOOL(result.primary == NULL, true, "check primary"); @@ -839,7 +840,7 @@ testRun(void) HRN_PQ_SCRIPT_CLOSE(8), HRN_PQ_SCRIPT_CLOSE(1)); - TEST_ASSIGN(result, dbGet(false, true, false), "get primary and standy"); + TEST_ASSIGN(result, dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_N), "get primary and standy"); hrnLogReplaceAdd("(could not connect to server|connection to server on socket).*$", NULL, "PG ERROR", false); TEST_RESULT_LOG( @@ -857,6 +858,40 @@ testRun(void) TEST_RESULT_VOID(dbFree(result.primary), "free primary"); TEST_RESULT_VOID(dbFree(result.standby), "free standby"); + + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("primary found and standby skipped"); + + argList = strLstNew(); + hrnCfgArgRawZ(argList, cfgOptStanza, "test1"); + hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionFull, 1, "1"); + hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, TEST_PATH "/pg1"); + hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 4, TEST_PATH "/pg4"); + hrnCfgArgKeyRawZ(argList, cfgOptPgPort, 4, "5433"); + HRN_CFG_LOAD(cfgCmdBackup, argList); + + HRN_PQ_SCRIPT_SET( + HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_12, TEST_PATH "/pg1", false, NULL, NULL), + + // pg4 error + {.session = 4, .function = HRN_PQ_CONNECTDB, .param = "[\"dbname='postgres' port=5433\"]"}, + {.session = 4, .function = HRN_PQ_STATUS, .resultInt = CONNECTION_BAD}, + {.session = 4, .function = HRN_PQ_ERRORMESSAGE, .resultZ = "error"}, + {.session = 4, .function = HRN_PQ_FINISH}, + + HRN_PQ_SCRIPT_CLOSE(1)); + + TEST_ASSIGN(result, dbGet(false, true, CFGOPTVAL_BACKUP_STANDBY_PREFER), "get primary and try standby"); + + TEST_RESULT_LOG( + "P00 WARN: unable to check pg4: [DbConnectError] unable to connect to 'dbname='postgres' port=5433': error"); + + TEST_RESULT_INT(result.primaryIdx, 0, "check primary idx"); + TEST_RESULT_BOOL(result.primary != NULL, true, "check primary"); + TEST_RESULT_BOOL(result.standby == NULL, true, "check standby was not found"); + + TEST_RESULT_VOID(dbFree(result.primary), "free primary"); + TEST_RESULT_VOID(dbFree(result.standby), "free standby"); } protocolFree(); [parent: b454b9e40352]