1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Increase max index allowed for pg/repo options to 256.

The prior limitations were based on using getopt_long() to parse command-line options, which required a static list of allowed options. Setting index max too high bloated the binary unacceptably. 45a4e80 replaced the functionality of getopt_long() but the static list remained.

Improve cfgParseOption() to use available option data and remove the need for a static list. This also allows the option deprecations to be represented more compactly.

Index max is still capped at 256 because a large enough index could cause parseOptionIdxValue() to run out of memory since it allocates a static list based on the highest index found. If that function were improved with a map of found index values then index max could be set to UINT64_MAX.

Note that deprecations no longer set an index max or define whether reset is valid. These were space-saving measures which are no longer required. This means that indexed deprecated options will also be valid up to 256 and always allow reset, but it doesn't seem worth additional code to limit this behavior.

cfgParseOptionId() is no longer needed because calling cfgParseOption() with .ignoreMissingIndex = true duplicates the functionality of cfgParseOptionId(). This leads to some simplification in the help code.
This commit is contained in:
David Steele
2021-08-31 12:09:50 -04:00
committed by GitHub
parent 8a4063c2b6
commit 02b06aa495
19 changed files with 1080 additions and 4840 deletions

View File

@ -33,43 +33,6 @@ use pgBackRestDoc::ProjectInfo;
####################################################################################################################################
use constant DOC_USER => getpwuid($UID) eq 'root' ? 'ubuntu' : getpwuid($UID) . '';
####################################################################################################################################
# Generate indexed defines
####################################################################################################################################
my $rhConfigDefineIndex = cfgDefine();
foreach my $strKey (sort(keys(%{$rhConfigDefineIndex})))
{
# Build options for all possible db configurations
if (defined($rhConfigDefineIndex->{$strKey}{&CFGDEF_PREFIX}) &&
$rhConfigDefineIndex->{$strKey}{&CFGDEF_PREFIX} eq CFGDEF_PREFIX_PG)
{
my $strPrefix = $rhConfigDefineIndex->{$strKey}{&CFGDEF_PREFIX};
for (my $iIndex = 1; $iIndex <= CFGDEF_INDEX_PG; $iIndex++)
{
my $strKeyNew = "${strPrefix}${iIndex}" . substr($strKey, length($strPrefix));
$rhConfigDefineIndex->{$strKeyNew} = dclone($rhConfigDefineIndex->{$strKey});
$rhConfigDefineIndex->{$strKeyNew}{&CFGDEF_INDEX_TOTAL} = CFGDEF_INDEX_PG;
$rhConfigDefineIndex->{$strKeyNew}{&CFGDEF_INDEX} = $iIndex - 1;
# Options indexed > 1 are never required
if ($iIndex != 1)
{
$rhConfigDefineIndex->{$strKeyNew}{&CFGDEF_REQUIRED} = false;
}
}
delete($rhConfigDefineIndex->{$strKey});
}
else
{
$rhConfigDefineIndex->{$strKey}{&CFGDEF_INDEX} = 0;
}
}
####################################################################################################################################
# CONSTRUCTOR
####################################################################################################################################
@ -563,17 +526,9 @@ sub backrestConfig
}
else
{
# Make sure the specified option exists
# ??? This is too simplistic to handle new indexed options. The check below works for now but it would be good
# ??? to bring back more sophisticated checking in the future.
# if (!defined($rhConfigDefineIndex->{$strKey}))
# {
# confess &log(ERROR, "option ${strKey} does not exist");
# }
# If this option is a hash and the value is already set then append to the array
if (defined($rhConfigDefineIndex->{$strKey}) &&
$rhConfigDefineIndex->{$strKey}{&CFGDEF_TYPE} eq CFGDEF_TYPE_HASH &&
if (defined(cfgDefine()->{$strKey}) &&
cfgDefine()->{$strKey}{&CFGDEF_TYPE} eq CFGDEF_TYPE_HASH &&
defined(${$self->{config}}{$strHostName}{$$hCacheKey{file}}{$strSection}{$strKey}))
{
my @oValue = ();