1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

Use 64-bit integers for config options.

In particular, archive-queue-max requires a greater range than is provided by a 32-bit integer.
This commit is contained in:
David Steele
2018-02-09 13:54:33 -05:00
parent 305a3e1761
commit 7c58fe7451
10 changed files with 58 additions and 14 deletions

View File

@@ -1638,6 +1638,7 @@ my %hConfigDefine =
&CFGDEF_SECTION => CFGDEF_SECTION_GLOBAL,
&CFGDEF_TYPE => CFGDEF_TYPE_INTEGER,
&CFGDEF_REQUIRED => false,
&CFGDEF_ALLOW_RANGE => [0, 4 * 1024 * 1024 * 1024 * 1024 * 1024], # 0-4PiB
&CFGDEF_COMMAND =>
{
&CFGCMD_ARCHIVE_PUSH => {},

View File

@@ -316,7 +316,7 @@ cfgOptionDefault(ConfigOption optionId)
case cfgDefOptTypeInteger:
{
configOptionValue[optionId].defaultValue = varNewInt(varIntForce(defaultValue));
configOptionValue[optionId].defaultValue = varNewInt64(varInt64Force(defaultValue));
break;
}
@@ -494,10 +494,21 @@ cfgOptionInt(ConfigSource optionId)
{
cfgOptionCheck(optionId);
if (varType(configOptionValue[optionId].value) != varTypeInt)
THROW(AssertError, "option '%s' is not type 'int'", cfgOptionName(optionId));
if (varType(configOptionValue[optionId].value) != varTypeInt64)
THROW(AssertError, "option '%s' is not type 'int64'", cfgOptionName(optionId));
return varInt(configOptionValue[optionId].value);
return varIntForce(configOptionValue[optionId].value);
}
int64
cfgOptionInt64(ConfigSource optionId)
{
cfgOptionCheck(optionId);
if (varType(configOptionValue[optionId].value) != varTypeInt64)
THROW(AssertError, "option '%s' is not type 'int64'", cfgOptionName(optionId));
return varInt64(configOptionValue[optionId].value);
}
const KeyValue *
@@ -588,10 +599,10 @@ cfgOptionSet(ConfigOption optionId, ConfigSource source, const Variant *value)
case cfgDefOptTypeInteger:
{
if (varType(value) == varTypeInt)
if (varType(value) == varTypeInt64)
configOptionValue[optionId].value = varDup(value);
else
configOptionValue[optionId].value = varNewInt(varIntForce(value));
configOptionValue[optionId].value = varNewInt64(varInt64Force(value));
break;
}

View File

@@ -49,6 +49,7 @@ ConfigOption cfgOptionIdFromDefId(ConfigDefineOption optionDefId, int index);
int cfgOptionIndex(ConfigOption optionId);
int cfgOptionIndexTotal(ConfigOption optionDefId);
int cfgOptionInt(ConfigSource optionId);
int64 cfgOptionInt64(ConfigSource optionId);
const KeyValue *cfgOptionKv(ConfigSource optionId);
const VariantList *cfgOptionLst(ConfigSource optionId);
const char *cfgOptionName(ConfigOption optionId);

View File

@@ -370,6 +370,11 @@ static ConfigDefineOptionData configDefineOptionData[] = CFGDEFDATA_OPTION_LIST
(
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdArchivePush)
)
CFGDEFDATA_OPTION_OPTIONAL_LIST
(
CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(0, 4503599627370496)
)
)
// -----------------------------------------------------------------------------------------------------------------------------

View File

@@ -129,8 +129,11 @@ typedef enum
#define CFGDEFDATA_OPTION_OPTIONAL_ALLOW_RANGE(rangeMinParam, rangeMaxParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST( \
configDefDataTypeAllowRange, 2, 0, (const void *)(intptr_t)(int32)(rangeMinParam * 100), \
(const void *)(intptr_t)(int32)(rangeMaxParam * 100)),
configDefDataTypeAllowRange, 4, 0, \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMinParam * 100)) % 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMinParam * 100)) / 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMaxParam * 100)) % 1000000000L), \
(const void *)(intptr_t)(int32)(((int64)((double)rangeMaxParam * 100)) / 1000000000L)),
#define CFGDEFDATA_OPTION_OPTIONAL_PREFIX(prefixParam) \
CFGDATA_OPTION_OPTIONAL_PUSH_LIST(configDefDataTypePrefix, 1, 0, prefixParam),
@@ -362,7 +365,7 @@ cfgDefOptionAllowRangeMax(ConfigDefineCommand commandDefId, ConfigDefineOption o
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange);
return (double)(intptr_t)dataDefList[1] / 100;
return ((double)(((int64)(intptr_t)dataDefList[2]) + (((int64)(intptr_t)dataDefList[3]) * 1000000000L))) / 100;
}
double
@@ -372,7 +375,7 @@ cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption o
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange);
return (double)(intptr_t)dataDefList[0] / 100;
return ((double)(((int64)(intptr_t)dataDefList[0]) + (((int64)(intptr_t)dataDefList[1]) * 1000000000L))) / 100;
}
/***********************************************************************************************************************************

View File

@@ -618,7 +618,7 @@ configParse(int argListSize, const char *argList[])
TRY_BEGIN()
{
if (optionDefType == cfgDefOptTypeInteger)
valueDbl = varIntForce(varNewStr(value));
valueDbl = varInt64Force(varNewStr(value));
else
valueDbl = varDblForce(varNewStr(value));
}

View File

@@ -117,14 +117,18 @@ testRun()
TEST_RESULT_BOOL(cfgOptionBool(cfgOptOnline), true, "online is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptOnline), cfgSourceParam, "online source is set");
TEST_ERROR(cfgOptionDbl(cfgOptOnline), AssertError, "option 'online' is not type 'double'");
TEST_ERROR(cfgOptionInt64(cfgOptOnline), AssertError, "option 'online' is not type 'int64'");
TEST_RESULT_VOID(cfgOptionSet(cfgOptCompressLevel, cfgSourceParam, varNewInt(1)), "set compress-level");
TEST_RESULT_VOID(cfgOptionSet(cfgOptCompressLevel, cfgSourceParam, varNewInt64(1)), "set compress-level");
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 1, "compress-level is set");
TEST_RESULT_VOID(cfgOptionSet(cfgOptCompressLevel, cfgSourceDefault, varNewStrZ("3")), "set compress-level");
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, "compress-level is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceDefault, "compress source is set");
TEST_ERROR(cfgOptionBool(cfgOptCompressLevel), AssertError, "option 'compress-level' is not type 'bool'");
TEST_RESULT_VOID(cfgOptionSet(cfgOptArchiveQueueMax, cfgSourceParam, varNewInt64(999999999999)), "set archive-queue-max");
TEST_RESULT_INT(cfgOptionInt64(cfgOptArchiveQueueMax), 999999999999, "archive-queue-max is set");
TEST_RESULT_VOID(cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(1.1)), "set protocol-timeout");
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 1.1, "protocol-timeout is set");
TEST_RESULT_VOID(cfgOptionSet(cfgOptProtocolTimeout, cfgSourceConfig, varNewStrZ("3.3")), "set protocol-timeout");
@@ -156,7 +160,7 @@ testRun()
"option 'stanza' must be set with String variant");
TEST_RESULT_VOID(cfgOptionSet(cfgOptStanza, cfgSourceConfig, varNewStrZ("db")), "set stanza");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptStanza)), "db", "stanza is set");
TEST_ERROR(cfgOptionInt(cfgOptStanza), AssertError, "option 'stanza' is not type 'int'");
TEST_ERROR(cfgOptionInt(cfgOptStanza), AssertError, "option 'stanza' is not type 'int64'");
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_VOID(cfgInit(), "config init resets value");
@@ -172,7 +176,7 @@ testRun()
TEST_RESULT_STR(strPtr(varStr(cfgOptionDefault(cfgOptType))), "incr", "backup type default");
TEST_RESULT_BOOL(varBool(cfgOptionDefault(cfgOptCompress)), "true", "backup compress default");
TEST_RESULT_DOUBLE(varDbl(cfgOptionDefault(cfgOptProtocolTimeout)), 1830, "backup protocol-timeout default");
TEST_RESULT_INT(varInt(cfgOptionDefault(cfgOptCompressLevel)), 6, "backup compress-level default");
TEST_RESULT_INT(varIntForce(cfgOptionDefault(cfgOptCompressLevel)), 6, "backup compress-level default");
TEST_RESULT_PTR(cfgOptionDefault(cfgOptDbInclude), NULL, "backup db-include default is null");
TEST_RESULT_VOID(cfgOptionSet(cfgOptPgHost, cfgSourceParam, varNewStrZ("backup")), "backup host set");

View File

@@ -65,6 +65,9 @@ testRun()
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgDefCmdBackup, cfgDefOptDbTimeout), 0.1, "range min");
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMax(cfgDefCmdBackup, cfgDefOptCompressLevel), 9, "range max");
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgDefCmdArchivePush, cfgDefOptArchiveQueueMax), 0, "range min");
TEST_RESULT_DOUBLE(
cfgDefOptionAllowRangeMax(cfgDefCmdArchivePush, cfgDefOptArchiveQueueMax), 4503599627370496, "range max");
TEST_ERROR(cfgDefOptionDefault(-1, cfgDefOptCompressLevel), AssertError, commandIdInvalidLowError);
TEST_ERROR(cfgDefOptionDefault(cfgDefCmdBackup, cfgDefOptionTotal()), AssertError, optionIdInvalidHighError);

View File

@@ -421,6 +421,18 @@ testRun()
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, " compress-level is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, " compress-level is source config");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--archive-queue-max=4503599627370496"));
strLstAdd(argList, strNew("archive-push"));
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList)), "archive-push command");
TEST_RESULT_INT(cfgOptionInt64(cfgOptArchiveQueueMax), 4503599627370496, "archive-queue-max is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptArchiveQueueMax), cfgSourceParam, " archive-queue-max is source config");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE));

View File

@@ -52,6 +52,9 @@ testRun()
cfgOptionValidSet(cfgOptProtocolTimeout, true);
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(1.1));
cfgOptionValidSet(cfgOptArchiveQueueMax, true);
cfgOptionSet(cfgOptArchiveQueueMax, cfgSourceParam, varNewInt64(999999999999));
cfgOptionValidSet(cfgOptCompressLevel, true);
cfgOptionSet(cfgOptCompressLevel, cfgSourceConfig, varNewInt(3));
@@ -61,6 +64,7 @@ testRun()
TEST_RESULT_STR(
strPtr(strLstJoin(perlCommand(), "|")),
TEST_ENV_EXE "|" TEST_PERL_EXE "|" TEST_PERL_MAIN "','backup','{"
"\"archive-queue-max\":{\"source\":\"param\",\"value\":999999999999},"
"\"compress\":{\"source\":\"param\",\"value\":true},"
"\"compress-level\":{\"source\":\"config\",\"value\":3},"
"\"online\":{\"source\":\"param\",\"negate\":true},"