You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-03 00:26:59 +02:00
Add protocolStorageType*() to manage protocol storage types.
Abstract the string representation of storage types that are passed over the protocol layer.
This commit is contained in:
@ -588,7 +588,7 @@ storage/posix/write.o: storage/posix/write.c build.auto.h common/assert.h common
|
||||
storage/read.o: storage/read.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/read.intern.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/variant.h common/type/variantList.h storage/read.h storage/read.intern.h
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c storage/read.c -o storage/read.o
|
||||
|
||||
storage/remote/protocol.o: storage/remote/protocol.c build.auto.h command/backup/pageChecksum.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/crypto/hash.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/filter/sink.h common/io/filter/size.h common/io/io.h common/io/read.h common/io/read.intern.h common/io/write.h common/io/write.intern.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h protocol/server.h storage/helper.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h
|
||||
storage/remote/protocol.o: storage/remote/protocol.c build.auto.h command/backup/pageChecksum.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/crypto/hash.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/filter/sink.h common/io/filter/size.h common/io/io.h common/io/read.h common/io/read.intern.h common/io/write.h common/io/write.intern.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/regExp.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h protocol/client.h protocol/command.h protocol/helper.h protocol/server.h storage/helper.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c storage/remote/protocol.c -o storage/remote/protocol.o
|
||||
|
||||
storage/remote/read.o: storage/remote/read.c build.auto.h common/assert.h common/compress/gzip/compress.h common/compress/gzip/decompress.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/read.intern.h common/io/write.h common/io/write.intern.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/list.h common/type/param.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h protocol/client.h protocol/command.h protocol/server.h storage/info.h storage/read.h storage/read.intern.h storage/remote/protocol.h storage/remote/read.h storage/remote/storage.h storage/remote/storage.intern.h storage/storage.h storage/storage.intern.h storage/write.h storage/write.intern.h version.h
|
||||
|
@ -20,6 +20,9 @@ Constants
|
||||
STRING_EXTERN(PROTOCOL_SERVICE_LOCAL_STR, PROTOCOL_SERVICE_LOCAL);
|
||||
STRING_EXTERN(PROTOCOL_SERVICE_REMOTE_STR, PROTOCOL_SERVICE_REMOTE);
|
||||
|
||||
STRING_STATIC(PROTOCOL_STORAGE_TYPE_PG_STR, "db");
|
||||
STRING_STATIC(PROTOCOL_STORAGE_TYPE_REPO_STR, "backup");
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Local variables
|
||||
***********************************************************************************************************************************/
|
||||
@ -122,8 +125,8 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int protoco
|
||||
// Add the host id -- for now this is hard-coded to 1
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_HOST_ID_STR), VARINT(1));
|
||||
|
||||
// Add the type
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), VARSTRDEF("backup"));
|
||||
// Add the storage type
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), VARSTR(protocolStorageTypeStr(protocolStorageType)));
|
||||
|
||||
// Only enable file logging on the local when requested
|
||||
kvPut(
|
||||
@ -298,7 +301,7 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_STDERR_STR), VARSTRDEF("error"));
|
||||
|
||||
// Add the type
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), isRepo ? VARSTRDEF("backup") : VARSTRDEF("db"));
|
||||
kvPut(optionReplace, VARSTR(CFGOPT_TYPE_STR), VARSTR(protocolStorageTypeStr(protocolStorageType)));
|
||||
|
||||
StringList *commandExec = cfgExecParam(cfgCmdRemote, optionReplace, false);
|
||||
strLstInsert(commandExec, 0, cfgOptionStr(isRepo ? cfgOptRepoHostCmd : cfgOptPgHostCmd + hostIdx));
|
||||
@ -419,6 +422,45 @@ protocolKeepAlive(void)
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters
|
||||
***********************************************************************************************************************************/
|
||||
ProtocolStorageType
|
||||
protocolStorageTypeEnum(const String *type)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STRING, type);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(type != NULL);
|
||||
|
||||
if (strEq(type, PROTOCOL_STORAGE_TYPE_PG_STR))
|
||||
FUNCTION_TEST_RETURN(protocolStorageTypePg);
|
||||
else if (strEq(type, PROTOCOL_STORAGE_TYPE_REPO_STR))
|
||||
FUNCTION_TEST_RETURN(protocolStorageTypeRepo);
|
||||
|
||||
THROW_FMT(AssertError, "invalid protocol storage type '%s'", strPtr(type));
|
||||
}
|
||||
|
||||
const String *
|
||||
protocolStorageTypeStr(ProtocolStorageType type)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(ENUM, type);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case protocolStorageTypePg:
|
||||
FUNCTION_TEST_RETURN(PROTOCOL_STORAGE_TYPE_PG_STR);
|
||||
|
||||
case protocolStorageTypeRepo:
|
||||
FUNCTION_TEST_RETURN(PROTOCOL_STORAGE_TYPE_REPO_STR);
|
||||
}
|
||||
|
||||
THROW_FMT(AssertError, "invalid protocol storage type %u", type);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Free the protocol objects and shutdown processes
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -37,6 +37,10 @@ bool pgIsLocal(unsigned int hostId);
|
||||
bool repoIsLocal(void);
|
||||
void repoIsLocalVerify(void);
|
||||
|
||||
// Get enum/string for protocol storage type
|
||||
ProtocolStorageType protocolStorageTypeEnum(const String *type);
|
||||
const String *protocolStorageTypeStr(ProtocolStorageType type);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -17,6 +17,7 @@ Remote Storage Protocol Handler
|
||||
#include "common/regExp.h"
|
||||
#include "common/type/json.h"
|
||||
#include "config/config.h"
|
||||
#include "protocol/helper.h"
|
||||
#include "storage/remote/protocol.h"
|
||||
#include "storage/helper.h"
|
||||
#include "storage/storage.intern.h"
|
||||
@ -191,7 +192,8 @@ storageRemoteProtocol(const String *command, const VariantList *paramList, Proto
|
||||
ASSERT(command != NULL);
|
||||
|
||||
// Determine which storage should be used
|
||||
const Storage *storage = strEqZ(cfgOptionStr(cfgOptType), "backup") ? storageRepo() : storagePg();
|
||||
const Storage *storage = protocolStorageTypeEnum(
|
||||
cfgOptionStr(cfgOptType)) == protocolStorageTypeRepo ? storageRepo() : storagePg();
|
||||
StorageInterface interface = storageInterface(storage);
|
||||
void *driver = storageDriver(storage);
|
||||
|
||||
|
@ -507,7 +507,7 @@ unit:
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: protocol
|
||||
total: 8
|
||||
total: 9
|
||||
containerReq: true
|
||||
perlReq: true
|
||||
|
||||
|
@ -100,6 +100,18 @@ testRun(void)
|
||||
Storage *storageTest = storagePosixNew(
|
||||
strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("protocolStorageTypeEnum() and protocolStorageTypeEnum()"))
|
||||
{
|
||||
TEST_RESULT_UINT(protocolStorageTypeEnum(PROTOCOL_STORAGE_TYPE_PG_STR), protocolStorageTypePg, "pg enum");
|
||||
TEST_RESULT_UINT(protocolStorageTypeEnum(PROTOCOL_STORAGE_TYPE_REPO_STR), protocolStorageTypeRepo, "repo enum");
|
||||
TEST_ERROR(protocolStorageTypeEnum(STRDEF(BOGUS_STR)), AssertError, "invalid protocol storage type 'BOGUS'");
|
||||
|
||||
TEST_RESULT_STR_STR(protocolStorageTypeStr(protocolStorageTypePg), PROTOCOL_STORAGE_TYPE_PG_STR, "pg str");
|
||||
TEST_RESULT_STR_STR(protocolStorageTypeStr(protocolStorageTypeRepo), PROTOCOL_STORAGE_TYPE_REPO_STR, "repo str");
|
||||
TEST_ERROR(protocolStorageTypeStr((ProtocolStorageType)999), AssertError, "invalid protocol storage type 999");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("repoIsLocal() and pgIsLocal()"))
|
||||
{
|
||||
|
Reference in New Issue
Block a user