1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-13 01:00:23 +02:00

Replace cfgOptionGroupIdxToKey() with cfgOptionGroupName().

Do the replacement anywhere cfgOptionGroupIdxToKey() is being used to construct a group name in a message. cfgOptionGroupName() is better for this case since it also includes the name of the group so that it does not need to be repeated in each message.
This commit is contained in:
David Steele
2022-01-10 09:10:06 -05:00
parent 9657f1b325
commit aced5d47ed
18 changed files with 99 additions and 70 deletions

View File

@ -45,6 +45,7 @@
<release-item> <release-item>
<commit subject="Fix inconsistent group display names in messages."/> <commit subject="Fix inconsistent group display names in messages."/>
<commit subject="Dynamically allocate index to key index map."/> <commit subject="Dynamically allocate index to key index map."/>
<commit subject="Replace cfgOptionGroupIdxToKey() with cfgOptionGroupName()."/>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-contributor id="david.steele"/> <release-item-contributor id="david.steele"/>

View File

@ -92,7 +92,7 @@ ArchiveGetFileResult archiveGetFile(
strLstAdd( strLstAdd(
result.warnList, result.warnList,
strNewFmt( strNewFmt(
"repo%u: %s [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, actual->repoIdx), strZ(actual->file), "%s: %s [%s] %s", cfgOptionGroupName(cfgOptGrpRepo, actual->repoIdx), strZ(actual->file),
errorTypeName(errorType()), errorMessage())); errorTypeName(errorType()), errorMessage()));
} }
MEM_CONTEXT_PRIOR_END(); MEM_CONTEXT_PRIOR_END();

View File

@ -31,7 +31,7 @@ Archive Get Command
Constants for log messages that are used multiple times to keep them consistent Constants for log messages that are used multiple times to keep them consistent
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#define FOUND_IN_ARCHIVE_MSG "found %s in the archive" #define FOUND_IN_ARCHIVE_MSG "found %s in the archive"
#define FOUND_IN_REPO_ARCHIVE_MSG "found %s in the repo%u: %s archive" #define FOUND_IN_REPO_ARCHIVE_MSG "found %s in the %s: %s archive"
#define UNABLE_TO_FIND_IN_ARCHIVE_MSG "unable to find %s in the archive" #define UNABLE_TO_FIND_IN_ARCHIVE_MSG "unable to find %s in the archive"
#define UNABLE_TO_FIND_VALID_REPO_MSG "unable to find a valid repository" #define UNABLE_TO_FIND_VALID_REPO_MSG "unable to find a valid repository"
#define REPO_INVALID_OR_ERR_MSG "some repositories were invalid or encountered errors" #define REPO_INVALID_OR_ERR_MSG "some repositories were invalid or encountered errors"
@ -61,8 +61,7 @@ typedef struct ArchiveGetCheckResult
static void static void
archiveGetErrorAdd(StringList *warnList, bool log, unsigned int repoIdx, const ErrorType *type, const String *message) archiveGetErrorAdd(StringList *warnList, bool log, unsigned int repoIdx, const ErrorType *type, const String *message)
{ {
const String *warn = strNewFmt( const String *warn = strNewFmt("%s: [%s] %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorTypeName(type), strZ(message));
"repo%u: [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), errorTypeName(type), strZ(message));
if (!strLstExists(warnList, warn)) if (!strLstExists(warnList, warn))
{ {
@ -814,7 +813,7 @@ cmdArchiveGet(void)
ASSERT(file != NULL); ASSERT(file != NULL);
LOG_INFO_FMT( LOG_INFO_FMT(
FOUND_IN_REPO_ARCHIVE_MSG, strZ(walSegment), cfgOptionGroupIdxToKey(cfgOptGrpRepo, file->repoIdx), FOUND_IN_REPO_ARCHIVE_MSG, strZ(walSegment), cfgOptionGroupName(cfgOptGrpRepo, file->repoIdx),
strZ(file->archiveId)); strZ(file->archiveId));
result = 0; result = 0;
@ -980,7 +979,7 @@ cmdArchiveGetAsync(void)
LOG_DETAIL_PID_FMT( LOG_DETAIL_PID_FMT(
processId, FOUND_IN_REPO_ARCHIVE_MSG, strZ(walSegment), processId, FOUND_IN_REPO_ARCHIVE_MSG, strZ(walSegment),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, file->repoIdx), strZ(file->archiveId)); cfgOptionGroupName(cfgOptGrpRepo, file->repoIdx), strZ(file->archiveId));
// Rename temp WAL segment to actual name. This is done after the ok file is written so the ok file // Rename temp WAL segment to actual name. This is done after the ok file is written so the ok file
// is guaranteed to exist before the foreground process finds the WAL segment. // is guaranteed to exist before the foreground process finds the WAL segment.

View File

@ -40,8 +40,7 @@ archivePushErrorAdd(StringList *errorList, unsigned int repoIdx)
strLstAdd( strLstAdd(
errorList, errorList,
strNewFmt( strNewFmt("%s: [%s] %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), errorMessage()));
"repo%u: [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), errorMessage()));
FUNCTION_TEST_RETURN_VOID(); FUNCTION_TEST_RETURN_VOID();
} }
@ -200,9 +199,9 @@ archivePushFile(
strLstAdd( strLstAdd(
result.warnList, result.warnList,
strNewFmt( strNewFmt(
"WAL file '%s' already exists in the repo%u archive with the same checksum" "WAL file '%s' already exists in the %s archive with the same checksum"
"\nHINT: this is valid in some recovery scenarios but may also indicate a problem.", "\nHINT: this is valid in some recovery scenarios but may also indicate a problem.",
strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoData->repoIdx))); strZ(archiveFile), cfgOptionGroupName(cfgOptGrpRepo, repoData->repoIdx)));
} }
MEM_CONTEXT_PRIOR_END(); MEM_CONTEXT_PRIOR_END();
@ -214,8 +213,8 @@ archivePushFile(
else else
{ {
THROW_FMT( THROW_FMT(
ArchiveDuplicateError, "WAL file '%s' already exists in the repo%u archive with a different checksum", ArchiveDuplicateError, "WAL file '%s' already exists in the %s archive with a different checksum",
strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoData->repoIdx)); strZ(archiveFile), cfgOptionGroupName(cfgOptGrpRepo, repoData->repoIdx));
} }
} }
// Else the repo needs a copy // Else the repo needs a copy

View File

@ -250,10 +250,10 @@ archivePushCheck(bool pgPathSet)
ArchiveMismatchError, ArchiveMismatchError,
"%s version %s, system-id %" PRIu64 " do not match %s stanza version %s, system-id %" PRIu64 "%s version %s, system-id %" PRIu64 " do not match %s stanza version %s, system-id %" PRIu64
"\nHINT: are you archiving to the correct stanza?", "\nHINT: are you archiving to the correct stanza?",
pgPathSet ? PG_NAME : strZ(strNewFmt("repo%u stanza", cfgOptionGroupIdxToKey(cfgOptGrpRepo, 0))), pgPathSet ? PG_NAME : strZ(strNewFmt("%s stanza", cfgOptionGroupName(cfgOptGrpRepo, 0))),
strZ(pgVersionToStr(result.pgVersion)), result.pgSystemId, strZ(pgVersionToStr(result.pgVersion)), result.pgSystemId,
strZ(strNewFmt("repo%u", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx))), cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(pgVersionToStr(archiveInfo.version)),
strZ(pgVersionToStr(archiveInfo.version)), archiveInfo.systemId); archiveInfo.systemId);
} }
} }
@ -279,8 +279,7 @@ archivePushCheck(bool pgPathSet)
strLstAdd( strLstAdd(
result.errorList, result.errorList,
strNewFmt( strNewFmt(
"repo%u: [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), "%s: [%s] %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), errorMessage()));
errorMessage()));
} }
TRY_END(); TRY_END();
} }

View File

@ -2062,8 +2062,8 @@ cmdBackup(void)
if (!cfgOptionTest(cfgOptRepo) && cfgOptionGroupIdxTotal(cfgOptGrpRepo) > 1) if (!cfgOptionTest(cfgOptRepo) && cfgOptionGroupIdxTotal(cfgOptGrpRepo) > 1)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo option not specified, defaulting to repo%u", "repo option not specified, defaulting to %s",
cfgOptionGroupIdxToKey(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo))); cfgOptionGroupName(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo)));
} }
// Load backup.info // Load backup.info

View File

@ -78,7 +78,7 @@ checkStandby(const DbGetResult dbGroup, unsigned int pgPathDefinedTotal)
// Check each repository configured // Check each repository configured
for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++) for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++)
{ {
LOG_INFO_FMT(CFGCMD_CHECK " repo%u (standby)", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); LOG_INFO_FMT(CFGCMD_CHECK " %s (standby)", cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
// Get the repo storage in case it is remote and encryption settings need to be pulled down (performed here for testing) // Get the repo storage in case it is remote and encryption settings need to be pulled down (performed here for testing)
const Storage *storageRepo = storageRepoIdx(repoIdx); const Storage *storageRepo = storageRepoIdx(repoIdx);
@ -121,7 +121,7 @@ checkPrimary(const DbGetResult dbGroup)
for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++) for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++)
{ {
LOG_INFO_FMT(CFGCMD_CHECK " repo%u configuration (primary)", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); LOG_INFO_FMT(CFGCMD_CHECK " %s configuration (primary)", cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
// Get the repo storage in case it is remote and encryption settings need to be pulled down (performed here for testing) // Get the repo storage in case it is remote and encryption settings need to be pulled down (performed here for testing)
const Storage *storageRepo = storageRepoIdx(repoIdx); const Storage *storageRepo = storageRepoIdx(repoIdx);
@ -145,16 +145,16 @@ checkPrimary(const DbGetResult dbGroup)
// Wait for the WAL to appear in each repo // Wait for the WAL to appear in each repo
for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++) for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++)
{ {
LOG_INFO_FMT(CFGCMD_CHECK " repo%u archive for WAL (primary)", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); LOG_INFO_FMT(CFGCMD_CHECK " %s archive for WAL (primary)", cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
const Storage *storageRepo = storageRepoIdx(repoIdx); const Storage *storageRepo = storageRepoIdx(repoIdx);
const String *walSegmentFile = walSegmentFind( const String *walSegmentFile = walSegmentFind(
storageRepo, repoArchiveId[repoIdx], walSegment, cfgOptionUInt64(cfgOptArchiveTimeout)); storageRepo, repoArchiveId[repoIdx], walSegment, cfgOptionUInt64(cfgOptArchiveTimeout));
LOG_INFO_FMT( LOG_INFO_FMT(
"WAL segment %s successfully archived to '%s' on repo%u", strZ(walSegment), "WAL segment %s successfully archived to '%s' on %s", strZ(walSegment),
strZ(storagePathP(storageRepo, strNewFmt(STORAGE_REPO_ARCHIVE "/%s/%s", strZ(repoArchiveId[repoIdx]), strZ(storagePathP(storageRepo, strNewFmt(STORAGE_REPO_ARCHIVE "/%s/%s", strZ(repoArchiveId[repoIdx]),
strZ(walSegmentFile)))), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); strZ(walSegmentFile)))), cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
} }
dbFree(dbGroup.primary); dbFree(dbGroup.primary);

View File

@ -143,9 +143,9 @@ expireAdhocBackup(InfoBackup *infoBackup, const String *backupLabel, unsigned in
// backups that can be recovered through PITR until the next full backup is created. Same problem for differential // backups that can be recovered through PITR until the next full backup is created. Same problem for differential
// backups with retention-diff. // backups with retention-diff.
LOG_WARN_FMT( LOG_WARN_FMT(
"repo%u: expiring latest backup %s - the ability to perform point-in-time-recovery (PITR) may be affected\n" "%s: expiring latest backup %s - the ability to perform point-in-time-recovery (PITR) may be affected\n"
"HINT: non-default settings for '%s'/'%s' (even in prior expires) can cause gaps in the WAL.", "HINT: non-default settings for '%s'/'%s' (even in prior expires) can cause gaps in the WAL.",
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), strZ(latestBackup), cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(latestBackup),
cfgOptionIdxName(cfgOptRepoRetentionArchive, repoIdx), cfgOptionIdxName(cfgOptRepoRetentionArchiveType, repoIdx)); cfgOptionIdxName(cfgOptRepoRetentionArchive, repoIdx), cfgOptionIdxName(cfgOptRepoRetentionArchiveType, repoIdx));
// Adhoc expire is never performed through backup command so only check to determine if dry-run has been set or not // Adhoc expire is never performed through backup command so only check to determine if dry-run has been set or not
@ -157,7 +157,7 @@ expireAdhocBackup(InfoBackup *infoBackup, const String *backupLabel, unsigned in
// Log the expired backup list (prepend "set:" if there were any dependents that were also expired) // Log the expired backup list (prepend "set:" if there were any dependents that were also expired)
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: expire adhoc backup %s%s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), (result > 1 ? "set " : ""), "%s: expire adhoc backup %s%s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), (result > 1 ? "set " : ""),
strZ(strLstJoin(backupExpired, ", "))); strZ(strLstJoin(backupExpired, ", ")));
} }
MEM_CONTEXT_TEMP_END(); MEM_CONTEXT_TEMP_END();
@ -209,7 +209,7 @@ expireDiffBackup(InfoBackup *infoBackup, unsigned int repoIdx)
// Log the expired backups. If there is more than one backup, then prepend "set:" // Log the expired backups. If there is more than one backup, then prepend "set:"
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: expire diff backup %s%s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: expire diff backup %s%s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
(strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", "))); (strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", ")));
} }
} }
@ -259,7 +259,7 @@ expireFullBackup(InfoBackup *infoBackup, unsigned int repoIdx)
// Log the expired backups. If there is more than one backup, then prepend "set:" // Log the expired backups. If there is more than one backup, then prepend "set:"
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: expire full backup %s%s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: expire full backup %s%s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
(strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", "))); (strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", ")));
} }
} }
@ -328,7 +328,7 @@ expireTimeBasedBackup(InfoBackup *infoBackup, const time_t minTimestamp, unsigne
// Log the expired backups. If there is more than one backup, then prepend "set:" // Log the expired backups. If there is more than one backup, then prepend "set:"
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: expire time-based backup %s%s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: expire time-based backup %s%s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
(strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", "))); (strLstSize(backupExpired) > 1 ? "set " : ""), strZ(strLstJoin(backupExpired, ", ")));
} }
@ -356,7 +356,7 @@ logExpire(ArchiveExpired *archiveExpire, String *archiveId, unsigned int repoIdx
{ {
// Force out any remaining message // Force out any remaining message
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: %s remove archive, start = %s, stop = %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), strZ(archiveId), "%s: %s remove archive, start = %s, stop = %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(archiveId),
strZ(archiveExpire->start), strZ(archiveExpire->stop)); strZ(archiveExpire->start), strZ(archiveExpire->stop));
archiveExpire->start = NULL; archiveExpire->start = NULL;
@ -396,8 +396,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
else else
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: time-based archive retention not met %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: time-based archive retention not met %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(msg));
strZ(msg));
} }
} }
else else
@ -527,8 +526,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
storageRepoIdx(repoIdx), strNewFmt(STORAGE_REPO_ARCHIVE "/%s", strZ(archiveId))); storageRepoIdx(repoIdx), strNewFmt(STORAGE_REPO_ARCHIVE "/%s", strZ(archiveId)));
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: remove archive path %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: remove archive path %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(fullPath));
strZ(fullPath));
// Execute the real expiration and deletion only if the dry-run option is disabled // Execute the real expiration and deletion only if the dry-run option is disabled
if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun)) if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun))
@ -620,9 +618,9 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
archiveExpireMax = strDup(archiveRange.start); archiveExpireMax = strDup(archiveRange.start);
LOG_DETAIL_FMT( LOG_DETAIL_FMT(
"repo%u: %s archive retention on backup %s, start = %s%s", "%s: %s archive retention on backup %s, start = %s%s",
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), strZ(archiveId), cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(archiveId), strZ(backupData->backupLabel),
strZ(backupData->backupLabel), strZ(archiveRange.start), strZ(archiveRange.start),
archiveRange.stop != NULL ? strZ(strNewFmt(", stop = %s", strZ(archiveRange.stop))) : ""); archiveRange.stop != NULL ? strZ(strNewFmt(", stop = %s", strZ(archiveRange.stop))) : "");
// Add the archive range to the list // Add the archive range to the list
@ -734,8 +732,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
if (archiveExpire.total == 0) if (archiveExpire.total == 0)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: %s no archive to remove", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: %s no archive to remove", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(archiveId));
strZ(archiveId));
} }
// Log if there is more to log // Log if there is more to log
else else
@ -768,7 +765,7 @@ removeExpiredArchive(InfoBackup *infoBackup, bool timeBasedFullRetention, unsign
} }
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: %s remove history file %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: %s remove history file %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
strZ(archiveId), strZ(historyFile)); strZ(archiveId), strZ(historyFile));
} }
} }
@ -847,8 +844,7 @@ removeExpiredBackup(InfoBackup *infoBackup, const String *adhocBackupLabel, unsi
if (!strLstExists(currentBackupList, strLstGet(backupList, backupIdx))) if (!strLstExists(currentBackupList, strLstGet(backupList, backupIdx)))
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: remove expired backup %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: remove expired backup %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(strLstGet(backupList, backupIdx)));
strZ(strLstGet(backupList, backupIdx)));
// Execute the real expiration and deletion only if the dry-run mode is disabled // Execute the real expiration and deletion only if the dry-run mode is disabled
if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun)) if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun))
@ -903,8 +899,7 @@ removeExpiredHistory(InfoBackup *infoBackup, unsigned int repoIdx)
if (strCmp(historyYear, strSubN(minBackupLabel, 0, 4)) < 0) if (strCmp(historyYear, strSubN(minBackupLabel, 0, 4)) < 0)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: remove expired backup history path %s", "%s: remove expired backup history path %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), strZ(historyYear));
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), strZ(historyYear));
// Execute the real expiration and deletion only if the dry-run mode is disabled // Execute the real expiration and deletion only if the dry-run mode is disabled
if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun)) if (!cfgOptionValid(cfgOptDryRun) || !cfgOptionBool(cfgOptDryRun))
@ -934,7 +929,7 @@ removeExpiredHistory(InfoBackup *infoBackup, unsigned int repoIdx)
if (!strLstExists(currentBackupList, historyBackupLabel) && strCmp(historyBackupLabel, minBackupLabel) < 0) if (!strLstExists(currentBackupList, historyBackupLabel) && strCmp(historyBackupLabel, minBackupLabel) < 0)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"repo%u: remove expired backup history manifest %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: remove expired backup history manifest %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
strZ(historyBackupFile)); strZ(historyBackupFile));
// Execute the real expiration and deletion only if the dry-run mode is disabled // Execute the real expiration and deletion only if the dry-run mode is disabled
@ -1069,8 +1064,7 @@ cmdExpire(void)
} }
CATCH_ANY() CATCH_ANY()
{ {
LOG_ERROR_FMT( LOG_ERROR_FMT(errorTypeCode(errorType()), "%s: %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorMessage());
errorTypeCode(errorType()), "repo%u: %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), errorMessage());
errorTotal++;; errorTotal++;;
} }
TRY_END(); TRY_END();

View File

@ -266,8 +266,7 @@ restoreBackupSet(void)
} }
CATCH_ANY() CATCH_ANY()
{ {
LOG_WARN_FMT( LOG_WARN_FMT("%s: [%s] %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), errorMessage());
"repo%u: [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), errorTypeName(errorType()), errorMessage());
} }
TRY_END(); TRY_END();
@ -278,7 +277,7 @@ restoreBackupSet(void)
if (infoBackupDataTotal(infoBackup) == 0) if (infoBackupDataTotal(infoBackup) == 0)
{ {
LOG_WARN_FMT( LOG_WARN_FMT(
"repo%u: [%s] no backup sets to restore", cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), "%s: [%s] no backup sets to restore", cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
errorTypeName(&BackupSetInvalidError)); errorTypeName(&BackupSetInvalidError));
continue; continue;
} }
@ -2254,7 +2253,7 @@ cmdRestore(void)
// Log the backup set to restore. If the backup was online then append the time recovery will start from. // Log the backup set to restore. If the backup was online then append the time recovery will start from.
String *const message = strCatFmt( String *const message = strCatFmt(
strNew(), "repo%u: restore backup set %s", cfgOptionGroupIdxToKey(cfgOptGrpRepo, backupData.repoIdx), strNew(), "%s: restore backup set %s", cfgOptionGroupName(cfgOptGrpRepo, backupData.repoIdx),
strZ(backupData.backupSet)); strZ(backupData.backupSet));
if (manifestData(jobData.manifest)->backupOptionOnline) if (manifestData(jobData.manifest)->backupOptionOnline)

View File

@ -44,8 +44,8 @@ cmdStanzaCreate(void)
for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++) for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
CFGCMD_STANZA_CREATE " for stanza '%s' on repo%u", strZ(cfgOptionDisplay(cfgOptStanza)), CFGCMD_STANZA_CREATE " for stanza '%s' on %s", strZ(cfgOptionDisplay(cfgOptStanza)),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
const Storage *storageRepoReadStanza = storageRepoIdx(repoIdx); const Storage *storageRepoReadStanza = storageRepoIdx(repoIdx);
const Storage *storageRepoWriteStanza = storageRepoIdxWrite(repoIdx); const Storage *storageRepoWriteStanza = storageRepoIdxWrite(repoIdx);
@ -133,8 +133,8 @@ cmdStanzaCreate(void)
if (sourceFile == NULL) if (sourceFile == NULL)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"stanza '%s' already exists on repo%u and is valid", strZ(cfgOptionDisplay(cfgOptStanza)), "stanza '%s' already exists on %s and is valid", strZ(cfgOptionDisplay(cfgOptStanza)),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
} }
} }
// Else if both .info and corresponding .copy file are missing for one but not the other, then error - the user will // Else if both .info and corresponding .copy file are missing for one but not the other, then error - the user will
@ -143,11 +143,11 @@ cmdStanzaCreate(void)
{ {
THROW_FMT( THROW_FMT(
FileMissingError, FileMissingError,
"%s on repo%u\n" "%s on %s\n"
"HINT: this may be a symptom of repository corruption!", "HINT: this may be a symptom of repository corruption!",
((archiveInfoFileExists || archiveInfoFileCopyExists) ? ((archiveInfoFileExists || archiveInfoFileCopyExists) ?
"archive.info exists but backup.info is missing" : "backup.info exists but archive.info is missing"), "archive.info exists but backup.info is missing" : "backup.info exists but archive.info is missing"),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
} }
} }
} }

View File

@ -54,9 +54,9 @@ stanzaDelete(const Storage *storageRepoWriteStanza, const StringList *archiveLis
{ {
THROW_FMT( THROW_FMT(
PgRunningError, PG_FILE_POSTMTRPID " exists - looks like " PG_NAME " is running. " PgRunningError, PG_FILE_POSTMTRPID " exists - looks like " PG_NAME " is running. "
"To delete stanza '%s' on repo%u, shut down " PG_NAME " for stanza '%s' and try again, or use --force.", "To delete stanza '%s' on %s, shut down " PG_NAME " for stanza '%s' and try again, or use --force.",
strZ(cfgOptionDisplay(cfgOptStanza)), strZ(cfgOptionDisplay(cfgOptStanza)),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo)), cfgOptionGroupName(cfgOptGrpRepo, cfgOptionGroupIdxDefault(cfgOptGrpRepo)),
strZ(cfgOptionDisplay(cfgOptStanza))); strZ(cfgOptionDisplay(cfgOptStanza)));
} }

View File

@ -41,8 +41,8 @@ cmdStanzaUpgrade(void)
for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++) for (unsigned int repoIdx = 0; repoIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); repoIdx++)
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
CFGCMD_STANZA_UPGRADE " for stanza '%s' on repo%u", strZ(cfgOptionDisplay(cfgOptStanza)), CFGCMD_STANZA_UPGRADE " for stanza '%s' on %s", strZ(cfgOptionDisplay(cfgOptStanza)),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
const Storage *storageRepoReadStanza = storageRepoIdx(repoIdx); const Storage *storageRepoReadStanza = storageRepoIdx(repoIdx);
const Storage *storageRepoWriteStanza = storageRepoIdxWrite(repoIdx); const Storage *storageRepoWriteStanza = storageRepoIdxWrite(repoIdx);
@ -100,8 +100,8 @@ cmdStanzaUpgrade(void)
if (!(infoArchiveUpgrade || infoBackupUpgrade)) if (!(infoArchiveUpgrade || infoBackupUpgrade))
{ {
LOG_INFO_FMT( LOG_INFO_FMT(
"stanza '%s' on repo%u is already up to date", strZ(cfgOptionDisplay(cfgOptStanza)), "stanza '%s' on %s is already up to date", strZ(cfgOptionDisplay(cfgOptStanza)),
cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
} }
} }
} }

View File

@ -237,6 +237,39 @@ cfgOptionGroup(ConfigOption optionId)
FUNCTION_TEST_RETURN(configLocal->option[optionId].group); FUNCTION_TEST_RETURN(configLocal->option[optionId].group);
} }
/**********************************************************************************************************************************/
const char *
cfgOptionGroupName(const ConfigOptionGroup groupId, const unsigned int groupIdx)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, groupId);
FUNCTION_TEST_PARAM(UINT, groupIdx);
FUNCTION_TEST_END();
ASSERT(configLocal != NULL);
ASSERT(groupId < CFG_OPTION_GROUP_TOTAL);
ASSERT(groupIdx < configLocal->optionGroup[groupId].indexTotal);
// Generate display names for the group the first time one is requested
if (configLocal->optionGroup[groupId].indexDisplay == NULL)
{
MEM_CONTEXT_BEGIN(configLocal->memContext)
{
configLocal->optionGroup[groupId].indexDisplay = memNew(
sizeof(String *) * configLocal->optionGroup[groupId].indexTotal);
for (unsigned int groupIdx = 0; groupIdx < configLocal->optionGroup[groupId].indexTotal; groupIdx++)
{
configLocal->optionGroup[groupId].indexDisplay[groupIdx] = strNewFmt(
"%s%u", configLocal->optionGroup[groupId].name, configLocal->optionGroup[groupId].indexMap[groupIdx] + 1);
}
}
MEM_CONTEXT_END();
}
FUNCTION_TEST_RETURN(strZ(configLocal->optionGroup[groupId].indexDisplay[groupIdx]));
}
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
unsigned int unsigned int
cfgOptionGroupId(ConfigOption optionId) cfgOptionGroupId(ConfigOption optionId)

View File

@ -80,12 +80,14 @@ const StringList *cfgCommandParam(void);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Option Group Functions Option Group Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
// Format group name for display to the user. Useful for messages that do not show an option name but must use an group name that
// the user will recognize.
const char *cfgOptionGroupName(ConfigOptionGroup groupId, unsigned int groupIdx);
// Get the default index for this group, i.e. the index that will be used if a non-indexed function like cfgOptionTest() is called. // Get the default index for this group, i.e. the index that will be used if a non-indexed function like cfgOptionTest() is called.
unsigned int cfgOptionGroupIdxDefault(ConfigOptionGroup groupId); unsigned int cfgOptionGroupIdxDefault(ConfigOptionGroup groupId);
// Convert the group index to a key, i.e. the key that was used in the original configuration file, command-line, etc. Useful for // Convert the group index to a key, i.e. the key that was used in the original configuration file, command-line, etc.
// messages that do not show an option name but must use an index that the user will recognize. It is preferrable to generate an
// option name with cfgOptionIdxName() when possible.
unsigned int cfgOptionGroupIdxToKey(ConfigOptionGroup groupId, unsigned int groupIdx); unsigned int cfgOptionGroupIdxToKey(ConfigOptionGroup groupId, unsigned int groupIdx);
// Total indexes, 0 if the group is not valid. Will be the total configured indexes, no matter which raw indexes were used during // Total indexes, 0 if the group is not valid. Will be the total configured indexes, no matter which raw indexes were used during

View File

@ -62,6 +62,7 @@ typedef struct Config
bool indexDefaultExists; // Is there a default index for non-indexed functions? bool indexDefaultExists; // Is there a default index for non-indexed functions?
unsigned int indexDefault; // Default index (usually 0) unsigned int indexDefault; // Default index (usually 0)
unsigned int *indexMap; // List of index to key index mappings unsigned int *indexMap; // List of index to key index mappings
const String **indexDisplay; // List of index display names
} optionGroup[CFG_OPTION_GROUP_TOTAL]; } optionGroup[CFG_OPTION_GROUP_TOTAL];
// Option data // Option data

View File

@ -98,8 +98,8 @@ cfgLoadUpdateOption(void)
{ {
THROW_FMT( THROW_FMT(
OptionInvalidValueError, OptionInvalidValueError,
"local repo%u and repo%u paths are both '%s' but must be different", "local %s and %s paths are both '%s' but must be different",
cfgOptionGroupIdxToKey(cfgOptGrpRepo, optionIdx), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx), cfgOptionGroupName(cfgOptGrpRepo, optionIdx), cfgOptionGroupName(cfgOptGrpRepo, repoIdx),
strZ(cfgOptionIdxDisplay(cfgOptRepoPath, repoIdx))); strZ(cfgOptionIdxDisplay(cfgOptRepoPath, repoIdx)));
} }
} }

View File

@ -89,7 +89,7 @@ dbGet(bool primaryOnly, bool primaryRequired, bool standbyRequired)
CATCH_ANY() CATCH_ANY()
{ {
LOG_WARN_FMT( LOG_WARN_FMT(
"unable to check pg%u: [%s] %s", cfgOptionGroupIdxToKey(cfgOptGrpPg, pgIdx), errorTypeName(errorType()), "unable to check %s: [%s] %s", cfgOptionGroupName(cfgOptGrpPg, pgIdx), errorTypeName(errorType()),
errorMessage()); errorMessage());
db = NULL; db = NULL;
} }

View File

@ -1687,6 +1687,8 @@ testRun(void)
TEST_RESULT_BOOL(cfgOptionIdxReset(cfgOptPgHost, 0), true, "pg1-host was reset"); TEST_RESULT_BOOL(cfgOptionIdxReset(cfgOptPgHost, 0), true, "pg1-host was reset");
TEST_RESULT_UINT(cfgOptionGroupIdxDefault(cfgOptGrpPg), 0, "pg1 is default"); TEST_RESULT_UINT(cfgOptionGroupIdxDefault(cfgOptGrpPg), 0, "pg1 is default");
TEST_RESULT_UINT(cfgOptionGroupIdxToKey(cfgOptGrpPg, 1), 2, "pg2 is index 2"); TEST_RESULT_UINT(cfgOptionGroupIdxToKey(cfgOptGrpPg, 1), 2, "pg2 is index 2");
TEST_RESULT_Z(cfgOptionGroupName(cfgOptGrpPg, 1), "pg2", "pg2 group display");
TEST_RESULT_Z(cfgOptionGroupName(cfgOptGrpPg, 0), "pg1", "pg1 group display (cached)");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/db", "default pg-path"); TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/db", "default pg-path");
TEST_RESULT_STR_Z(varStr(cfgOptionVar(cfgOptPgPath)), "/path/to/db", "default pg-path as variant"); TEST_RESULT_STR_Z(varStr(cfgOptionVar(cfgOptPgPath)), "/path/to/db", "default pg-path as variant");
TEST_RESULT_BOOL(cfgOptionGroupValid(cfgOptGrpPg), true, "pg group is valid"); TEST_RESULT_BOOL(cfgOptionGroupValid(cfgOptGrpPg), true, "pg group is valid");