pgbackrest.git / summary / log / commit / refs

commit    538e2c7474394f1f24bb0899bc7d85bf7c68bd5a
Author:   David Steele <david@pgmasters.net>
Date:     Mon Mar 25 05:45:36 2019 +0000

    Add storagePg()/storagePgWrite() to storage helper.
    
    Add read/write storage helper functions for the PostgreSQL data directory.


doc/xml/release.xml | 2 +- src/storage/helper.c | 50 +++++++++++++++++++++++++++++++++++++ src/storage/helper.h | 2 ++ test/src/module/storage/posixTest.c | 18 +++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 934e82370..d2b3b87a0 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -46,7 +46,7 @@ </release-item> <release-item> - <p>Add <id>storageRepoWrite()</id> to storage helper.</p> + <p>Add <code>storageRepoWrite()</code> and <code>storagePg()</code>/<code>storagePgWrite()</code> to storage helper.</p> </release-item> <release-item> diff --git a/src/storage/helper.c b/src/storage/helper.c index 05500bf4b..c6a5f80f4 100644 --- a/src/storage/helper.c +++ b/src/storage/helper.c @@ -32,6 +32,8 @@ static struct Storage *storageLocal; // Local read-only storage Storage *storageLocalWrite; // Local write storage + Storage *storagePg; // PostgreSQL read-only storage + Storage *storagePgWrite; // PostgreSQL write storage Storage *storageRepo; // Repository read-only storage Storage *storageRepoWrite; // Repository write storage Storage *storageSpool; // Spool read-only storage @@ -137,6 +139,54 @@ storageLocalWrite(void) FUNCTION_TEST_RETURN(storageHelper.storageLocalWrite); } +/*********************************************************************************************************************************** +Get ready-only PostgreSQL storage +***********************************************************************************************************************************/ +const Storage * +storagePg(void) +{ + FUNCTION_TEST_VOID(); + + if (storageHelper.storagePg == NULL) + { + storageHelperInit(); + + MEM_CONTEXT_BEGIN(storageHelper.memContext) + { + storageHelper.storagePg = storageDriverPosixInterface( + storageDriverPosixNew( + cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, false, NULL)); + } + MEM_CONTEXT_END(); + } + + FUNCTION_TEST_RETURN(storageHelper.storagePg); +} + +/*********************************************************************************************************************************** +Get write PostgreSQL storage +***********************************************************************************************************************************/ +const Storage * +storagePgWrite(void) +{ + FUNCTION_TEST_VOID(); + + if (storageHelper.storagePgWrite == NULL) + { + storageHelperInit(); + + MEM_CONTEXT_BEGIN(storageHelper.memContext) + { + storageHelper.storagePgWrite = storageDriverPosixInterface( + storageDriverPosixNew( + cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL)); + } + MEM_CONTEXT_END(); + } + + FUNCTION_TEST_RETURN(storageHelper.storagePgWrite); +} + /*********************************************************************************************************************************** Create the WAL regular expression ***********************************************************************************************************************************/ diff --git a/src/storage/helper.h b/src/storage/helper.h index 0b0cce661..870b20df2 100644 --- a/src/storage/helper.h +++ b/src/storage/helper.h @@ -34,6 +34,8 @@ Functions ***********************************************************************************************************************************/ const Storage *storageLocal(void); const Storage *storageLocalWrite(void); +const Storage *storagePg(void); +const Storage *storagePgWrite(void); const Storage *storageRepo(void); const Storage *storageRepoWrite(void); const Storage *storageSpool(void); diff --git a/test/src/module/storage/posixTest.c b/test/src/module/storage/posixTest.c index 5b4fc971b..e7667b5ec 100644 --- a/test/src/module/storage/posixTest.c +++ b/test/src/module/storage/posixTest.c @@ -1032,6 +1032,7 @@ testRun(void) strLstAddZ(argList, "--stanza=db"); strLstAddZ(argList, "--archive-async"); strLstAdd(argList, strNewFmt("--spool-path=%s", testPath())); + strLstAdd(argList, strNewFmt("--pg1-path=%s/db", testPath())); strLstAddZ(argList, "archive-get"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); @@ -1068,6 +1069,23 @@ testRun(void) TEST_RESULT_VOID(storageNewWriteNP(storage, writeFile), "writes are allowed"); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_RESULT_PTR(storageHelper.storagePg, NULL, "pg storage not cached"); + TEST_ASSIGN(storage, storagePg(), "new pg storage"); + TEST_RESULT_PTR(storageHelper.storagePg, storage, "pg storage cached"); + TEST_RESULT_PTR(storagePg(), storage, "get cached pg storage"); + + TEST_RESULT_STR(strPtr(storage->path), strPtr(strNewFmt("%s/db", testPath())), "check pg storage path"); + TEST_RESULT_BOOL(storage->write, false, "check pg storage write"); + + TEST_RESULT_PTR(storageHelper.storagePgWrite, NULL, "pg write storage not cached"); + TEST_ASSIGN(storage, storagePgWrite(), "new pg write storage"); + TEST_RESULT_PTR(storageHelper.storagePgWrite, storage, "pg write storage cached"); + TEST_RESULT_PTR(storagePgWrite(), storage, "get cached pg write storage"); + + TEST_RESULT_STR(strPtr(storage->path), strPtr(strNewFmt("%s/db", testPath())), "check pg write storage path"); + TEST_RESULT_BOOL(storage->write, true, "check pg write storage write"); + // Change the stanza to NULL, stanzaInit flag to false and make sure helper fails because stanza is required // ------------------------------------------------------------------------------------------------------------------------- storageHelper.storageSpool = NULL; [parent: 444b4f864030]