You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-13 01:00:23 +02:00
Move WAL path prefix logic into walPath().
This logic is used by both archive-push and archive-get.
This commit is contained in:
@ -45,6 +45,10 @@
|
|||||||
<p>Add <id>storageRepoWrite()</id> to storage helper.</p>
|
<p>Add <id>storageRepoWrite()</id> to storage helper.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Move WAL path prefix logic into <code>walPath()</code>.</p>
|
||||||
|
</release-item>
|
||||||
|
|
||||||
<release-item>
|
<release-item>
|
||||||
<p>Make notion of current <postgres/> info ID in C align with Perl.</p>
|
<p>Make notion of current <postgres/> info ID in C align with Perl.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
@ -199,7 +199,7 @@ clean:
|
|||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# Compile rules
|
# Compile rules
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
command/archive/common.o: command/archive/common.c command/archive/common.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/write.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/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h postgres/version.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
command/archive/common.o: command/archive/common.c command/archive/common.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/write.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/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h common/wait.h config/config.auto.h config/config.h config/define.auto.h config/define.h postgres/version.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
||||||
$(CC) $(CFLAGS) -c command/archive/common.c -o command/archive/common.o
|
$(CC) $(CFLAGS) -c command/archive/common.c -o command/archive/common.o
|
||||||
|
|
||||||
command/archive/get/file.o: command/archive/get/file.c command/archive/common.h command/archive/get/file.h command/control/control.h common/assert.h common/compress/gzip/common.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.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 info/infoArchive.h info/infoPg.h postgres/interface.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
command/archive/get/file.o: command/archive/get/file.c command/archive/common.h command/archive/get/file.h command/control/control.h common/assert.h common/compress/gzip/common.h common/compress/gzip/decompress.h common/crypto/cipherBlock.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.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 info/infoArchive.h info/infoPg.h postgres/interface.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h
|
||||||
|
@ -11,6 +11,7 @@ Archive Common
|
|||||||
#include "common/memContext.h"
|
#include "common/memContext.h"
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
|
#include "config/config.h"
|
||||||
#include "postgres/version.h"
|
#include "postgres/version.h"
|
||||||
#include "storage/helper.h"
|
#include "storage/helper.h"
|
||||||
#include "storage/helper.h"
|
#include "storage/helper.h"
|
||||||
@ -221,6 +222,43 @@ walIsPartial(const String *walSegment)
|
|||||||
FUNCTION_LOG_RETURN(BOOL, strEndsWithZ(walSegment, WAL_SEGMENT_PARTIAL_EXT));
|
FUNCTION_LOG_RETURN(BOOL, strEndsWithZ(walSegment, WAL_SEGMENT_PARTIAL_EXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Generates the location of the wal directory using a relative wal path and the supplied pg path
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
String *
|
||||||
|
walPath(const String *walFile, const String *pgPath, const String *command)
|
||||||
|
{
|
||||||
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||||
|
FUNCTION_LOG_PARAM(STRING, walFile);
|
||||||
|
FUNCTION_LOG_PARAM(STRING, pgPath);
|
||||||
|
FUNCTION_LOG_PARAM(STRING, command);
|
||||||
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
|
ASSERT(walFile != NULL);
|
||||||
|
ASSERT(command != NULL);
|
||||||
|
|
||||||
|
String *result = NULL;
|
||||||
|
|
||||||
|
if (!strBeginsWithZ(walFile, "/"))
|
||||||
|
{
|
||||||
|
if (pgPath == NULL)
|
||||||
|
{
|
||||||
|
THROW_FMT(
|
||||||
|
OptionRequiredError,
|
||||||
|
"option '%s' must be specified when relative wal paths are used\n"
|
||||||
|
"HINT: Is %%f passed to %s instead of %%p?\n"
|
||||||
|
"HINT: PostgreSQL may pass relative paths even with %%p depending on the environment.",
|
||||||
|
cfgOptionName(cfgOptPgPath), strPtr(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
result = strNewFmt("%s/%s", strPtr(pgPath), strPtr(walFile));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result = strDup(walFile);
|
||||||
|
|
||||||
|
FUNCTION_LOG_RETURN(STRING, result);
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Is the file a segment or some other file (e.g. .history, .backup, etc)
|
Is the file a segment or some other file (e.g. .history, .backup, etc)
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
@ -56,6 +56,7 @@ void archiveAsyncStatusErrorWrite(
|
|||||||
|
|
||||||
bool walIsPartial(const String *walSegment);
|
bool walIsPartial(const String *walSegment);
|
||||||
bool walIsSegment(const String *walSegment);
|
bool walIsSegment(const String *walSegment);
|
||||||
|
String *walPath(const String *walFile, const String *pgPath, const String *command);
|
||||||
String *walSegmentFind(const Storage *storage, const String *archiveId, const String *walSegment);
|
String *walSegmentFind(const Storage *storage, const String *archiveId, const String *walSegment);
|
||||||
String *walSegmentNext(const String *walSegment, size_t walSegmentSize, unsigned int pgVersion);
|
String *walSegmentNext(const String *walSegment, size_t walSegmentSize, unsigned int pgVersion);
|
||||||
StringList *walSegmentRange(const String *walSegmentBegin, size_t walSegmentSize, unsigned int pgVersion, unsigned int range);
|
StringList *walSegmentRange(const String *walSegmentBegin, size_t walSegmentSize, unsigned int pgVersion, unsigned int range);
|
||||||
|
@ -127,12 +127,9 @@ cmdArchiveGet(void)
|
|||||||
// Get the segment name
|
// Get the segment name
|
||||||
String *walSegment = strBase(strLstGet(commandParam, 0));
|
String *walSegment = strBase(strLstGet(commandParam, 0));
|
||||||
|
|
||||||
// Destination is wherever we were told to move the WAL segment. In some cases the path that PostgreSQL passes will not be
|
// Destination is wherever we were told to move the WAL segment
|
||||||
// absolute so prefix pg-path.
|
const String *walDestination =
|
||||||
const String *walDestination = strLstGet(commandParam, 1);
|
walPath(strLstGet(commandParam, 1), cfgOptionStr(cfgOptPgPath), strNew(cfgCommandName(cfgCommand())));
|
||||||
|
|
||||||
if (!strBeginsWithZ(walDestination, "/"))
|
|
||||||
walDestination = strNewFmt("%s/%s", strPtr(cfgOptionStr(cfgOptPgPath)), strPtr(walDestination));
|
|
||||||
|
|
||||||
// Async get can only be performed on WAL segments, history or other files must use synchronous mode
|
// Async get can only be performed on WAL segments, history or other files must use synchronous mode
|
||||||
if (cfgOptionBool(cfgOptArchiveAsync) && walIsSegment(walSegment))
|
if (cfgOptionBool(cfgOptArchiveAsync) && walIsSegment(walSegment))
|
||||||
|
@ -620,7 +620,7 @@ unit:
|
|||||||
test:
|
test:
|
||||||
# ----------------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------------
|
||||||
- name: archive-common
|
- name: archive-common
|
||||||
total: 7
|
total: 8
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
command/archive/common: full
|
command/archive/common: full
|
||||||
|
@ -168,6 +168,20 @@ testRun(void)
|
|||||||
TEST_RESULT_BOOL(walIsSegment(strNew("0000001A.history")), false, "history file");
|
TEST_RESULT_BOOL(walIsSegment(strNew("0000001A.history")), false, "history file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *****************************************************************************************************************************
|
||||||
|
if (testBegin("walPath()"))
|
||||||
|
{
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(walPath(strNew("/absolute/path"), strNew("/pg"), strNew("test"))), "/absolute/path", "absolute path");
|
||||||
|
TEST_RESULT_STR(
|
||||||
|
strPtr(walPath(strNew("relative/path"), strNew("/pg"), strNew("test"))), "/pg/relative/path", "relative path");
|
||||||
|
TEST_ERROR(
|
||||||
|
walPath(strNew("relative/path"), NULL, strNew("test")), OptionRequiredError,
|
||||||
|
"option 'pg1-path' must be specified when relative wal paths are used\n"
|
||||||
|
"HINT: Is %f passed to test instead of %p?\n"
|
||||||
|
"HINT: PostgreSQL may pass relative paths even with %p depending on the environment.");
|
||||||
|
}
|
||||||
|
|
||||||
// *****************************************************************************************************************************
|
// *****************************************************************************************************************************
|
||||||
if (testBegin("walSegmentFind()"))
|
if (testBegin("walSegmentFind()"))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user