1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Add hostId to protocolLocalGet().

Previously this function was only creating locals that talked to the repository.  Backup will need to be able to talk to multiple PostgreSQL hosts.
This commit is contained in:
David Steele 2019-11-23 10:32:57 -05:00
parent ab65ffdfac
commit cace54151f
6 changed files with 23 additions and 19 deletions

View File

@ -347,7 +347,7 @@ cmdArchiveGetAsync(void)
(TimeMSec)(cfgOptionDbl(cfgOptProtocolTimeout) * MSEC_PER_SEC) / 2, archiveGetAsyncCallback, &jobData);
for (unsigned int processIdx = 1; processIdx <= cfgOptionUInt(cfgOptProcessMax); processIdx++)
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, processIdx));
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, 1, processIdx));
// Process jobs
do

View File

@ -498,7 +498,7 @@ cmdArchivePushAsync(void)
(TimeMSec)(cfgOptionDbl(cfgOptProtocolTimeout) * MSEC_PER_SEC) / 2, archivePushAsyncCallback, &jobData);
for (unsigned int processIdx = 1; processIdx <= cfgOptionUInt(cfgOptProcessMax); processIdx++)
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, processIdx));
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, 1, processIdx));
// Process jobs
do

View File

@ -1929,7 +1929,7 @@ cmdRestore(void)
(TimeMSec)(cfgOptionDbl(cfgOptProtocolTimeout) * MSEC_PER_SEC) / 2, restoreJobCallback, &jobData);
for (unsigned int processIdx = 1; processIdx <= cfgOptionUInt(cfgOptProcessMax); processIdx++)
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, processIdx));
protocolParallelClientAdd(parallelExec, protocolLocalGet(protocolStorageTypeRepo, 1, processIdx));
// Process jobs
uint64_t sizeRestored = 0;

View File

@ -102,10 +102,11 @@ pgIsLocal(unsigned int hostId)
Get the command line required for local protocol execution
***********************************************************************************************************************************/
static StringList *
protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protocolId)
protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int hostId, unsigned int protocolId)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(ENUM, protocolStorageType);
FUNCTION_LOG_PARAM(UINT, hostId);
FUNCTION_LOG_PARAM(UINT, protocolId);
FUNCTION_LOG_END();
@ -120,10 +121,10 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco
kvPut(optionReplace, VARSTR(CFGOPT_COMMAND_STR), VARSTRZ(cfgCommandName(cfgCommand())));
// Add the process id -- used when more than one process will be called
kvPut(optionReplace, VARSTR(CFGOPT_PROCESS_STR), VARINT((int)protocolId));
kvPut(optionReplace, VARSTR(CFGOPT_PROCESS_STR), VARUINT(protocolId));
// Add the host id -- for now this is hard-coded to 1
kvPut(optionReplace, VARSTR(CFGOPT_HOST_ID_STR), VARINT(1));
// Add the host id
kvPut(optionReplace, VARSTR(CFGOPT_HOST_ID_STR), VARUINT(hostId));
// Add the storage type
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), VARSTR(protocolStorageTypeStr(protocolStorageType)));
@ -147,10 +148,11 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco
Get the local protocol client
***********************************************************************************************************************************/
ProtocolClient *
protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int protocolId)
protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int hostId, unsigned int protocolId)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(ENUM, protocolStorageType);
FUNCTION_LOG_PARAM(UINT, hostId);
FUNCTION_LOG_PARAM(UINT, protocolId);
FUNCTION_LOG_END();
@ -179,7 +181,7 @@ protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int protocolI
{
// Execute the protocol command
protocolHelperClient->exec = execNew(
cfgExe(), protocolLocalParam(protocolStorageType, protocolId),
cfgExe(), protocolLocalParam(protocolStorageType, hostId, protocolId),
strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u process", protocolId),
(TimeMSec)(cfgOptionDbl(cfgOptProtocolTimeout) * 1000));
execOpen(protocolHelperClient->exec);

View File

@ -27,7 +27,7 @@ Constants
Functions
***********************************************************************************************************************************/
void protocolKeepAlive(void);
ProtocolClient *protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int protocolId);
ProtocolClient *protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int hostId, unsigned int protocolId);
ProtocolClient *protocolRemoteGet(ProtocolStorageType protocolStorageType, unsigned int hostId);
/***********************************************************************************************************************************

View File

@ -172,28 +172,30 @@ testRun(void)
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_STR(
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypeRepo, 0), "|")),
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypeRepo, 1, 0), "|")),
strPtr(
strNew(
"--command=archive-get|--host-id=1|--log-level-file=off|--log-level-stderr=error|--process=0|--stanza=test1"
"|--type=backup|local")),
"local protocol params");
"local repo protocol params");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "--pg1-path=/pg");
strLstAddZ(argList, "--repo1-retention-full=1");
strLstAddZ(argList, "--log-subprocess");
strLstAddZ(argList, "archive-get");
strLstAddZ(argList, "backup");
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_STR(
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypeRepo, 1), "|")),
strPtr(strLstJoin(protocolLocalParam(protocolStorageTypePg, 2, 1), "|")),
strPtr(
strNew(
"--command=archive-get|--host-id=1|--log-level-file=info|--log-level-stderr=error|--log-subprocess|--process=1"
"|--stanza=test1|--type=backup|local")),
"local protocol params with replacements");
"--command=backup|--host-id=2|--log-level-file=info|--log-level-stderr=error|--log-subprocess|--pg1-path=/pg"
"|--process=1|--stanza=test1|--type=db|local")),
"local pg protocol params");
}
// *****************************************************************************************************************************
@ -942,8 +944,8 @@ testRun(void)
strLstAddZ(argList, "--process-max=2");
harnessCfgLoad(cfgCmdArchiveGetAsync, argList);
TEST_ASSIGN(client, protocolLocalGet(protocolStorageTypeRepo, 1), "get local protocol");
TEST_RESULT_PTR(protocolLocalGet(protocolStorageTypeRepo, 1), client, "get local cached protocol");
TEST_ASSIGN(client, protocolLocalGet(protocolStorageTypeRepo, 1, 1), "get local protocol");
TEST_RESULT_PTR(protocolLocalGet(protocolStorageTypeRepo, 1, 1), client, "get local cached protocol");
TEST_RESULT_PTR(protocolHelper.clientLocal[0].client, client, "check location in cache");
TEST_RESULT_VOID(protocolFree(), "free local and remote protocol objects");