1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-07 00:35:37 +02:00

Prepare configuration module for multi-repository support.

Refactor the code to allow a dynamic number of indexes for indexed options, e.g. pg-path. Our reliance on getopt_long() still limits the number of indexes we can have per group, but once this limitation is removed the rest of the code should be happy with dynamic numbers of indexes (with a reasonable maximum).

Add an option to set a default in each group. This was previously handled by the host-id option but now there is a specific option for each group, pg and repo. These remain internal until they can be fully tested with multi-repo support. They are fully tested for internal usage.

Remove the ConfigDefineOption enum and use the ConfigOption enum instead. They are now equal since the indexed options (e.g. cfgOptRepoHost2) have been removed from ConfigOption.

Remove the config/config test module and add required tests to the config/parse test module. Parsing is now the only way to load a config so this removes some redundancy.

Split new internal config structures and functions into a new header file, config.intern.h. More functions will need to be moved over from config.h but that will need to be done in a future commit to reduce churn.

Add repoIdx to repoIsLocal() and storageRepo*(). Multi-repository support requires that repo locality and storage be accessible by index. This allows, for example, multiple repos to be iterated in a loop. This could be done in a separate commit but doesn't seem worth it since the code is related.

Remove the type parameter from storageRepoGet(). This parameter existed solely to provide coverage for the case where the storage type was invalid. A better pattern is to check that the type is S3 once all other types have been ruled out.
This commit is contained in:
David Steele
2020-11-23 15:55:46 -05:00
parent 7fda83b31e
commit 117f03eba1
47 changed files with 2784 additions and 3546 deletions

View File

@ -12,7 +12,7 @@ Common Command Routines
#include "common/stat.h"
#include "common/time.h"
#include "common/type/json.h"
#include "config/config.h"
#include "config/config.intern.h"
#include "config/define.h"
#include "version.h"
@ -76,71 +76,75 @@ cmdOption(void)
// Skip the option if not valid for this command. Generally only one command runs at a time, but sometimes
// commands are chained together (e.g. backup and expire) and the second command may not use all the options of
// the first command. Displaying them is harmless but might cause confusion.
if (!cfgDefOptionValid(cfgCommand(), cfgOptionDefIdFromId(optionId)))
if (!cfgOptionValid(optionId) || !cfgDefOptionValid(cfgCommand(), optionId))
continue;
// If option was negated
if (cfgOptionNegate(optionId))
strCatFmt(cmdOptionStr, " --no-%s", cfgOptionName(optionId));
// If option was reset
else if (cfgOptionReset(optionId))
strCatFmt(cmdOptionStr, " --reset-%s", cfgOptionName(optionId));
// Else not default
else if (cfgOptionSource(optionId) != cfgSourceDefault)
// Loop through option indexes
unsigned int optionIdxTotal = cfgOptionGroup(optionId) ? cfgOptionGroupIdxTotal(cfgOptionGroupId(optionId)) : 1;
for (unsigned int optionIdx = 0; optionIdx < optionIdxTotal; optionIdx++)
{
ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId);
// Don't show redacted options
if (cfgDefOptionSecure(optionDefId))
strCatFmt(cmdOptionStr, " --%s=<redacted>", cfgOptionName(optionId));
// Output boolean option
else if (cfgDefOptionType(optionDefId) == cfgDefOptTypeBoolean)
strCatFmt(cmdOptionStr, " --%s", cfgOptionName(optionId));
// Output other options
else
// If option was negated
if (cfgOptionIdxNegate(optionId, optionIdx))
strCatFmt(cmdOptionStr, " --no-%s", cfgOptionIdxName(optionId, optionIdx));
// If option was reset
else if (cfgOptionIdxReset(optionId, optionIdx))
strCatFmt(cmdOptionStr, " --reset-%s", cfgOptionIdxName(optionId, optionIdx));
// Else not default
else if (cfgOptionIdxSource(optionId, optionIdx) != cfgSourceDefault)
{
StringList *valueList = NULL;
// Generate the values of hash options
if (cfgDefOptionType(optionDefId) == cfgDefOptTypeHash)
{
valueList = strLstNew();
const KeyValue *optionKv = cfgOptionKv(optionId);
const VariantList *keyList = kvKeyList(optionKv);
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
{
strLstAdd(
valueList,
strNewFmt(
"%s=%s", strZ(varStr(varLstGet(keyList, keyIdx))),
strZ(varStrForce(kvGet(optionKv, varLstGet(keyList, keyIdx))))));
}
}
// Generate values for list options
else if (cfgDefOptionType(optionDefId) == cfgDefOptTypeList)
{
valueList = strLstNewVarLst(cfgOptionLst(optionId));
}
// Else only one value
// Don't show redacted options
if (cfgDefOptionSecure(optionId))
strCatFmt(cmdOptionStr, " --%s=<redacted>", cfgOptionIdxName(optionId, optionIdx));
// Output boolean option
else if (cfgDefOptionType(optionId) == cfgDefOptTypeBoolean)
strCatFmt(cmdOptionStr, " --%s", cfgOptionIdxName(optionId, optionIdx));
// Output other options
else
{
valueList = strLstNew();
strLstAdd(valueList, varStrForce(cfgOption(optionId)));
}
StringList *valueList = NULL;
// Output options and values
for (unsigned int valueListIdx = 0; valueListIdx < strLstSize(valueList); valueListIdx++)
{
const String *value = strLstGet(valueList, valueListIdx);
// Generate the values of hash options
if (cfgDefOptionType(optionId) == cfgDefOptTypeHash)
{
valueList = strLstNew();
strCatFmt(cmdOptionStr, " --%s", cfgOptionName(optionId));
const KeyValue *optionKv = cfgOptionIdxKv(optionId, optionIdx);
const VariantList *keyList = kvKeyList(optionKv);
if (strchr(strZ(value), ' ') != NULL)
value = strNewFmt("\"%s\"", strZ(value));
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
{
strLstAdd(
valueList,
strNewFmt(
"%s=%s", strZ(varStr(varLstGet(keyList, keyIdx))),
strZ(varStrForce(kvGet(optionKv, varLstGet(keyList, keyIdx))))));
}
}
// Generate values for list options
else if (cfgDefOptionType(optionId) == cfgDefOptTypeList)
{
valueList = strLstNewVarLst(cfgOptionIdxLst(optionId, optionIdx));
}
// Else only one value
else
{
valueList = strLstNew();
strLstAdd(valueList, varStrForce(cfgOptionIdx(optionId, optionIdx)));
}
strCatFmt(cmdOptionStr, "=%s", strZ(value));
// Output options and values
for (unsigned int valueListIdx = 0; valueListIdx < strLstSize(valueList); valueListIdx++)
{
const String *value = strLstGet(valueList, valueListIdx);
strCatFmt(cmdOptionStr, " --%s", cfgOptionIdxName(optionId, optionIdx));
if (strchr(strZ(value), ' ') != NULL)
value = strNewFmt("\"%s\"", strZ(value));
strCatFmt(cmdOptionStr, "=%s", strZ(value));
}
}
}
}