2018-04-30 17:27:39 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Archive Get Command
|
|
|
|
***********************************************************************************************************************************/
|
2020-03-06 14:41:03 -05:00
|
|
|
#include "common/compress/helper.h"
|
2018-05-06 08:56:42 -04:00
|
|
|
#include "common/harnessConfig.h"
|
|
|
|
#include "common/harnessFork.h"
|
2019-02-27 23:03:02 +02:00
|
|
|
#include "common/io/bufferRead.h"
|
|
|
|
#include "common/io/bufferWrite.h"
|
2019-04-23 14:02:30 -04:00
|
|
|
#include "postgres/interface.h"
|
|
|
|
#include "postgres/version.h"
|
2019-05-03 15:46:15 -04:00
|
|
|
#include "storage/posix/storage.h"
|
2018-09-11 15:42:31 -04:00
|
|
|
|
2019-04-23 14:02:30 -04:00
|
|
|
#include "common/harnessInfo.h"
|
2021-01-08 16:48:32 -05:00
|
|
|
#include "common/harnessStorage.h"
|
2019-04-23 14:02:30 -04:00
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
void
|
2018-08-03 19:19:14 -04:00
|
|
|
testRun(void)
|
2018-04-30 17:27:39 -04:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
2020-04-30 11:01:38 -04:00
|
|
|
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2018-09-11 15:42:31 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("archiveGetCheck()"))
|
|
|
|
{
|
|
|
|
// Load Parameters
|
|
|
|
StringList *argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--stanza=test1");
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
2021-01-08 16:48:32 -05:00
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
2018-09-11 15:42:31 -04:00
|
|
|
|
|
|
|
// Create pg_control file
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
2021-01-08 16:48:32 -05:00
|
|
|
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
|
2018-09-25 10:24:42 +01:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
|
2018-09-11 15:42:31 -04:00
|
|
|
|
|
|
|
// Control and archive info mismatch
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test1/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-16 15:27:38 +04:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n"));
|
2018-09-11 15:42:31 -04:00
|
|
|
|
|
|
|
TEST_ERROR(
|
2018-11-28 14:56:26 -05:00
|
|
|
archiveGetCheck(strNew("876543218765432187654321"), cipherTypeNone, NULL), ArchiveMismatchError,
|
2018-09-11 15:42:31 -04:00
|
|
|
"unable to retrieve the archive id for database version '10' and system-id '18072658121562454734'");
|
|
|
|
|
|
|
|
// Nothing to find in empty archive dir
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test1/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-16 15:27:38 +04:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=3\n"
|
|
|
|
"\n"
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n"
|
|
|
|
"2={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n"
|
|
|
|
"3={\"db-id\":18072658121562454734,\"db-version\":\"9.6\"}\n"
|
|
|
|
"4={\"db-id\":18072658121562454734,\"db-version\":\"10\"}"));
|
2018-09-11 15:42:31 -04:00
|
|
|
|
2020-06-17 09:46:09 -04:00
|
|
|
TEST_RESULT_STR(
|
2018-11-28 14:56:26 -05:00
|
|
|
archiveGetCheck(strNew("876543218765432187654321"), cipherTypeNone, NULL).archiveFileActual, NULL, "no segment found");
|
2018-09-11 15:42:31 -04:00
|
|
|
|
|
|
|
// Write segment into an older archive path
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(
|
2018-09-11 15:42:31 -04:00
|
|
|
storageTest,
|
|
|
|
strNew(
|
|
|
|
"repo/archive/test1/10-2/8765432187654321/876543218765432187654321-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")),
|
|
|
|
NULL);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
archiveGetCheck(strNew("876543218765432187654321"), cipherTypeNone, NULL).archiveFileActual,
|
2018-09-11 15:42:31 -04:00
|
|
|
"10-2/8765432187654321/876543218765432187654321-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "segment found");
|
|
|
|
|
|
|
|
// Write segment into an newer archive path
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(
|
2018-09-11 15:42:31 -04:00
|
|
|
storageTest,
|
|
|
|
strNew(
|
|
|
|
"repo/archive/test1/10-4/8765432187654321/876543218765432187654321-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")),
|
|
|
|
NULL);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
archiveGetCheck(strNew("876543218765432187654321"), cipherTypeNone, NULL).archiveFileActual,
|
2018-09-11 15:42:31 -04:00
|
|
|
"10-4/8765432187654321/876543218765432187654321-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "newer segment found");
|
|
|
|
|
|
|
|
// Get history file
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-06-17 09:46:09 -04:00
|
|
|
TEST_RESULT_STR(
|
2018-11-28 14:56:26 -05:00
|
|
|
archiveGetCheck(strNew("00000009.history"), cipherTypeNone, NULL).archiveFileActual, NULL, "history file not found");
|
2018-09-11 15:42:31 -04:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storageTest, strNew("repo/archive/test1/10-4/00000009.history")), NULL);
|
2018-09-11 15:42:31 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
archiveGetCheck(strNew("00000009.history"), cipherTypeNone, NULL).archiveFileActual, "10-4/00000009.history",
|
|
|
|
"history file found");
|
2018-09-11 15:42:31 -04:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("queueNeed()"))
|
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
2018-09-16 14:12:53 -04:00
|
|
|
strLstAddZ(argList, "--stanza=test1");
|
2018-04-30 17:27:39 -04:00
|
|
|
strLstAddZ(argList, "--archive-async");
|
2020-10-19 14:03:48 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, "/unused");
|
2018-04-30 17:27:39 -04:00
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s/spool", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2018-09-25 10:24:42 +01:00
|
|
|
size_t queueSize = 16 * 1024 * 1024;
|
|
|
|
size_t walSegmentSize = 16 * 1024 * 1024;
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
TEST_ERROR_FMT(
|
|
|
|
queueNeed(strNew("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_92),
|
2020-04-06 16:09:18 -04:00
|
|
|
PathMissingError, "unable to list file info for missing path '%s/spool/archive/test1/in'", testPath());
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
|
|
|
queueNeed(STRDEF("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_92),
|
|
|
|
"000000010000000100000001\n000000010000000100000002\n", "queue size smaller than min");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-09-25 10:24:42 +01:00
|
|
|
queueSize = (16 * 1024 * 1024) * 3;
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
|
|
|
queueNeed(strNew("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_92),
|
|
|
|
"000000010000000100000001\n000000010000000100000002\n000000010000000100000003\n", "empty queue");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-05-18 11:57:32 -04:00
|
|
|
Buffer *walSegmentBuffer = bufNew(walSegmentSize);
|
|
|
|
memset(bufPtr(walSegmentBuffer), 0, walSegmentSize);
|
|
|
|
|
2021-01-08 16:14:26 -05:00
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FE", walSegmentBuffer);
|
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FF", walSegmentBuffer);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
|
|
|
queueNeed(strNew("0000000100000001000000FE"), false, queueSize, walSegmentSize, PG_VERSION_92),
|
|
|
|
"000000010000000200000000\n000000010000000200000001\n", "queue has wal < 9.3");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
|
|
|
storageListP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN)), "0000000100000001000000FE\n", "check queue");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
walSegmentSize = 1024 * 1024;
|
|
|
|
queueSize = walSegmentSize * 5;
|
|
|
|
|
2021-01-08 16:14:26 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/junk", "JUNK");
|
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFE", walSegmentBuffer);
|
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFF", walSegmentBuffer);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
|
|
|
queueNeed(strNew("000000010000000A00000FFD"), true, queueSize, walSegmentSize, PG_VERSION_11),
|
|
|
|
"000000010000000B00000000\n000000010000000B00000001\n000000010000000B00000002\n", "queue has wal >= 9.3");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:14:26 -05:00
|
|
|
TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000A00000FFE\n000000010000000A00000FFF\n");
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("cmdArchiveGetAsync()"))
|
|
|
|
{
|
|
|
|
harnessLogLevelSet(logLevelDetail);
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// Arguments that must be included
|
|
|
|
StringList *argBaseList = strLstNew();
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH_PG);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH_REPO);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptSpoolPath, TEST_PATH_SPOOL);
|
|
|
|
hrnCfgArgRawBool(argBaseList, cfgOptArchiveAsync, true);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptStanza, "test2");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("command must be run on the pg host");
|
|
|
|
|
|
|
|
StringList *argList = strLstDup(argBaseList);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgHost, BOGUS_STR);
|
|
|
|
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleAsync, argList);
|
|
|
|
|
|
|
|
TEST_ERROR(cmdArchiveGetAsync(), HostInvalidError, "archive-get command must be run on the PostgreSQL host");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-08 16:29:56 -05:00
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "global.error\n", .remove = true);
|
|
|
|
|
2020-02-12 17:18:48 -07:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_TITLE("error on no segments");
|
2020-02-12 17:18:48 -07:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2020-02-12 17:18:48 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleAsync, argList);
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_ERROR(cmdArchiveGetAsync(), ParamInvalidError, "at least one wal segment is required");
|
2020-02-12 17:18:48 -07:00
|
|
|
|
2021-01-08 16:29:56 -05:00
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "global.error\n", .remove = true);
|
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_TITLE("no segments to find");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
|
2019-02-27 23:03:02 +02:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleAsync, argList);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "get async");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
harnessLogResult(
|
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
|
|
|
"P01 DETAIL: unable to find 000000010000000100000001 in the archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.ok\n", .remove = true);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("error on invalid compressed segment");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "get async");
|
|
|
|
|
|
|
|
harnessLogResult(
|
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-01-13 10:24:47 -05:00
|
|
|
"P01 WARN: could not get 000000010000000100000001 from the repo1 archive (will be retried):"
|
2021-01-08 16:48:32 -05:00
|
|
|
" [29] raised from local-1 protocol: unexpected eof in compressed data");
|
|
|
|
|
|
|
|
TEST_STORAGE_LIST(
|
|
|
|
storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.error\n000000010000000100000001.pgbackrest.tmp\n");
|
|
|
|
TEST_STORAGE_REMOVE(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.error");
|
|
|
|
|
|
|
|
TEST_STORAGE_REMOVE(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("single segment");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");
|
|
|
|
|
|
|
|
// There should be a temp file left over. Make sure it still exists to test that temp files are removed on retry.
|
|
|
|
TEST_STORAGE_EXISTS(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.pgbackrest.tmp");
|
2020-07-14 15:05:31 -04:00
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
harnessLogResult(
|
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-01-13 10:24:47 -05:00
|
|
|
"P01 DETAIL: found 000000010000000100000001 in the repo1 archive");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001\n", .remove = true);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_TITLE("multiple segments where some are missing or errored");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "0000000100000001000000FE");
|
|
|
|
strLstAddZ(argList, "0000000100000001000000FF");
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleAsync, argList);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/0000000100000001000000FE-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// Create segment duplicates
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
2021-01-12 18:20:28 -05:00
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
2021-01-12 18:20:28 -05:00
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
harnessLogResult(
|
2021-01-12 18:20:28 -05:00
|
|
|
"P00 INFO: get 3 WAL file(s) from archive: 0000000100000001000000FE...000000010000000200000000\n"
|
2021-01-13 10:24:47 -05:00
|
|
|
"P01 DETAIL: found 0000000100000001000000FE in the repo1 archive\n"
|
2021-01-12 18:20:28 -05:00
|
|
|
"P01 DETAIL: unable to find 0000000100000001000000FF in the archive\n"
|
2021-01-13 10:24:47 -05:00
|
|
|
"P01 WARN: could not get 000000010000000200000000 from the repo1 archive (will be retried): "
|
2021-01-12 18:20:28 -05:00
|
|
|
"[45] raised from local-1 protocol: duplicates found in archive for WAL segment 000000010000000200000000: "
|
|
|
|
"000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, "
|
|
|
|
"000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2019-02-27 23:03:02 +02:00
|
|
|
" HINT: are multiple primaries archiving to this stanza?");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_LIST(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN,
|
2021-01-12 18:20:28 -05:00
|
|
|
"0000000100000001000000FE\n0000000100000001000000FF.ok\n000000010000000200000000.error\n",
|
2021-01-08 16:48:32 -05:00
|
|
|
.remove = true);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_TITLE("global error on invalid executable");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "pgbackrest-bogus");
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH_REPO);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH_SPOOL);
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test2");
|
2020-01-15 12:24:58 -07:00
|
|
|
strLstAddZ(argList, CFGCMD_ARCHIVE_GET ":" CONFIG_COMMAND_ROLE_ASYNC);
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "0000000100000001000000FE");
|
|
|
|
strLstAddZ(argList, "0000000100000001000000FF");
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGetAsync(), ExecuteError,
|
|
|
|
"local-1 process terminated unexpectedly [102]: unable to execute 'pgbackrest-bogus': [2] No such file or directory");
|
|
|
|
|
|
|
|
harnessLogResult(
|
2021-01-12 18:20:28 -05:00
|
|
|
"P00 INFO: get 3 WAL file(s) from archive: 0000000100000001000000FE...000000010000000200000000");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strNewBuf(storageGetP(storageNewReadP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_IN "/global.error")))),
|
2019-02-27 23:03:02 +02:00
|
|
|
"102\nlocal-1 process terminated unexpectedly [102]: unable to execute 'pgbackrest-bogus': "
|
|
|
|
"[2] No such file or directory",
|
2019-03-25 08:12:38 +04:00
|
|
|
"check global error");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "global.error\n", .remove = true);
|
2019-02-27 23:03:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("cmdArchiveGet()"))
|
|
|
|
{
|
2021-01-08 16:48:32 -05:00
|
|
|
harnessLogLevelSet(logLevelDetail);
|
|
|
|
|
|
|
|
// Arguments that must be included. Use raw config here because we need to keep the
|
|
|
|
StringList *argBaseList = strLstNew();
|
|
|
|
strLstAddZ(argBaseList, "pgbackrest-bogus");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH_PG);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH_REPO);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptStanza, "test1");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptArchiveTimeout, "1");
|
|
|
|
strLstAddZ(argBaseList, CFGCMD_ARCHIVE_GET);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-02-12 17:18:48 -07:00
|
|
|
TEST_TITLE("command must be run on the pg host");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
StringList *argList = strLstDup(argBaseList);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgHost, BOGUS_STR);
|
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2020-02-12 17:18:48 -07:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchiveGet(), HostInvalidError, "archive-get command must be run on the PostgreSQL host");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_ERROR(cmdArchiveGet(), ParamRequiredError, "WAL segment to get required");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_ERROR(cmdArchiveGet(), ParamRequiredError, "path to copy WAL segment required");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
|
2018-09-25 10:24:42 +01:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
storagePathCreateP(storageTest, strNewFmt("%s/pg/pg_wal", testPath()));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYXLOG");
|
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_ERROR_FMT(
|
|
|
|
cmdArchiveGet(), FileMissingError,
|
|
|
|
"unable to load info file '%s/archive/test1/archive.info' or '%s/archive/test1/archive.info.copy':\n"
|
|
|
|
"FileMissingError: " STORAGE_ERROR_READ_MISSING "\n"
|
|
|
|
"FileMissingError: " STORAGE_ERROR_READ_MISSING "\n"
|
|
|
|
"HINT: archive.info cannot be opened but is required to push/get WAL segments.\n"
|
|
|
|
"HINT: is archive_command configured correctly in postgresql.conf?\n"
|
|
|
|
"HINT: has a stanza-create been performed?\n"
|
|
|
|
"HINT: use --no-archive-check to disable archive checks during backup if you have an alternate archiving"
|
|
|
|
" scheme.",
|
|
|
|
strZ(cfgOptionStr(cfgOptRepoPath)), strZ(cfgOptionStr(cfgOptRepoPath)),
|
|
|
|
strZ(strNewFmt("%s/archive/test1/archive.info", strZ(cfgOptionStr(cfgOptRepoPath)))),
|
|
|
|
strZ(strNewFmt("%s/archive/test1/archive.info.copy", strZ(cfgOptionStr(cfgOptRepoPath)))));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
// !!! IS THIS TEST NEEDED
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "00000001.history");
|
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYHISTORY");
|
|
|
|
strLstAddZ(argList, "--archive-async");
|
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_ERROR_FMT(
|
|
|
|
cmdArchiveGet(), FileMissingError,
|
|
|
|
"unable to load info file '%s/archive/test1/archive.info' or '%s/archive/test1/archive.info.copy':\n"
|
|
|
|
"FileMissingError: " STORAGE_ERROR_READ_MISSING "\n"
|
|
|
|
"FileMissingError: " STORAGE_ERROR_READ_MISSING "\n"
|
|
|
|
"HINT: archive.info cannot be opened but is required to push/get WAL segments.\n"
|
|
|
|
"HINT: is archive_command configured correctly in postgresql.conf?\n"
|
|
|
|
"HINT: has a stanza-create been performed?\n"
|
|
|
|
"HINT: use --no-archive-check to disable archive checks during backup if you have an alternate archiving"
|
|
|
|
" scheme.",
|
|
|
|
strZ(cfgOptionStr(cfgOptRepoPath)), strZ(cfgOptionStr(cfgOptRepoPath)),
|
|
|
|
strZ(strNewFmt("%s/archive/test1/archive.info", strZ(cfgOptionStr(cfgOptRepoPath)))),
|
|
|
|
strZ(strNewFmt("%s/archive/test1/archive.info.copy", strZ(cfgOptionStr(cfgOptRepoPath)))));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// Make sure the process times out when there is nothing to get
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH_SPOOL);
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
2018-04-30 17:27:39 -04:00
|
|
|
strLstAddZ(argList, "pg_wal/RECOVERYXLOG");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2020-07-30 07:49:06 -04:00
|
|
|
THROW_ON_SYS_ERROR(chdir(strZ(cfgOptionStr(cfgOptPgPath))) != 0, PathMissingError, "unable to chdir()");
|
2019-12-11 14:36:39 -05:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "timeout getting WAL segment");
|
2018-10-02 17:54:43 +01:00
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: unable to find 000000010000000100000001 in the archive asynchronously");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// Check for missing WAL
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "successful get of missing WAL");
|
2018-10-02 17:54:43 +01:00
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: unable to find 000000010000000100000001 in the archive asynchronously");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
2021-01-08 16:48:32 -05:00
|
|
|
storageExistsP(storageSpool(), STRDEF(STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok")), false,
|
2018-04-30 17:27:39 -04:00
|
|
|
"check OK file was removed");
|
|
|
|
|
|
|
|
// Write out a WAL segment for success
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", "SHOULD-BE-A-REAL-WAL-FILE");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "successful get");
|
2018-10-02 17:54:43 +01:00
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
TEST_RESULT_VOID(
|
|
|
|
harnessLogResult("P00 INFO: found 000000010000000100000001 in the archive asynchronously"), "check log");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// Write more WAL segments (in this case queue should be full)
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
strLstAddZ(argList, "--archive-get-queue-max=48");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", "SHOULD-BE-A-REAL-WAL-FILE");
|
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000002", "SHOULD-BE-A-REAL-WAL-FILE");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "successful get");
|
2018-10-02 17:54:43 +01:00
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
TEST_RESULT_VOID(harnessLogResult("P00 INFO: found 000000010000000100000001 in the archive asynchronously"), "check log");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// Make sure the process times out when it can't get a lock
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_VOID(
|
2020-11-23 12:41:54 -05:00
|
|
|
lockAcquire(
|
|
|
|
cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), STRDEF("999-dededede"), cfgLockType(), 30000, true),
|
|
|
|
"acquire lock");
|
2018-04-30 17:27:39 -04:00
|
|
|
TEST_RESULT_VOID(lockClear(true), "clear lock");
|
|
|
|
|
2021-01-06 11:36:42 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "timeout waiting for lock");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: unable to find 000000010000000100000001 in the archive asynchronously");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
strLstAddZ(argList, BOGUS_STR);
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2018-05-18 11:57:32 -04:00
|
|
|
TEST_ERROR(cmdArchiveGet(), ParamInvalidError, "extra parameters found");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-01-12 18:20:28 -05:00
|
|
|
TEST_TITLE("pg version does not match archive.info");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
|
2021-01-12 18:20:28 -05:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}");
|
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
argBaseList = strLstNew();
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH_PG);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH_REPO);
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptStanza, "test1");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
2021-01-08 16:48:32 -05:00
|
|
|
strLstAddZ(argList, "01ABCDEF01ABCDEF01ABCDEF");
|
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYXLOG");
|
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveMismatchError,
|
|
|
|
"unable to retrieve the archive id for database version '11' and system-id '18072658121562454734'");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("pg version does not match archive.info");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
|
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0x8888888888888888}));
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveMismatchError,
|
|
|
|
"unable to retrieve the archive id for database version '10' and system-id '9838263505978427528'");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("file is missing");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
|
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "get");
|
|
|
|
|
|
|
|
harnessLogResult("P00 INFO: unable to find 01ABCDEF01ABCDEF01ABCDEF in the archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageTest, TEST_PATH_PG "/pg_wal");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get WAL segment");
|
|
|
|
|
|
|
|
Buffer *buffer = bufNew(16 * 1024 * 1024);
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1 archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
TEST_RESULT_UINT(
|
|
|
|
storageInfoP(storageTest, STRDEF(TEST_PATH_PG "/pg_wal/RECOVERYXLOG")).size, 16 * 1024 * 1024, "check size");
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n", .remove = true);
|
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get from prior db-id");
|
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n"
|
|
|
|
"2={\"db-id\":10000000000000000000,\"db-version\":\"11\"}\n"
|
|
|
|
"3={\"db-id\":18072658121562454734,\"db-version\":\"10\"}");
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_REMOVE(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get partial");
|
|
|
|
|
|
|
|
buffer = bufNew(16 * 1024 * 1024);
|
|
|
|
memset(bufPtr(buffer), 0xFF, bufSize(buffer));
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storageRepoWrite(),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-3/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
buffer);
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001.partial");
|
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYXLOG");
|
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: found 000000010000000100000001.partial in the repo1 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n", .remove = true);
|
|
|
|
TEST_STORAGE_REMOVE(
|
|
|
|
storageRepoWrite(),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-3/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get missing history");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "00000001.history");
|
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYHISTORY");
|
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "get");
|
|
|
|
|
|
|
|
harnessLogResult("P00 INFO: unable to find 00000001.history in the archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", NULL);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get history");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/00000001.history", BUFSTRDEF("HISTORY"));
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: found 00000001.history in the repo1 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_UINT(storageInfoP(storageTest, STRDEF(TEST_PATH_PG "/pg_wal/RECOVERYHISTORY")).size, 7, "check size");
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYHISTORY\n", .remove = true);
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get compressed and encrypted WAL segment");
|
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[cipher]\n"
|
|
|
|
"cipher-pass=\"" TEST_CIPHER_PASS_ARCHIVE "\"\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}",
|
|
|
|
.cipherType = cipherTypeAes256Cbc);
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
buffer, .compressType = compressTypeGz, .cipherType = cipherTypeAes256Cbc, .cipherPass = TEST_CIPHER_PASS_ARCHIVE);
|
|
|
|
|
|
|
|
// Add encryption options
|
2021-01-12 18:20:28 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepoCipherType, CIPHER_TYPE_AES_256_CBC);
|
|
|
|
hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "01ABCDEF01ABCDEF01ABCDEF");
|
|
|
|
strLstAddZ(argList, TEST_PATH_PG "/pg_wal/RECOVERYXLOG");
|
2021-01-08 16:48:32 -05:00
|
|
|
harnessCfgLoad(cfgCmdArchiveGet, argList);
|
|
|
|
hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-01-13 10:24:47 -05:00
|
|
|
harnessLogResult("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1 archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_LIST(storageTest, TEST_PATH_PG "/pg_wal", "RECOVERYXLOG\n");
|
|
|
|
TEST_RESULT_UINT(
|
|
|
|
storageInfoP(storageTest, STRDEF(TEST_PATH_PG "/pg_wal/RECOVERYXLOG")).size, 16 * 1024 * 1024, "check size");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("call protocol function directly");
|
|
|
|
|
|
|
|
// Start a protocol server
|
|
|
|
Buffer *serverWrite = bufNew(8192);
|
|
|
|
IoWrite *serverWriteIo = ioBufferWriteNew(serverWrite);
|
|
|
|
ioWriteOpen(serverWriteIo);
|
|
|
|
|
|
|
|
ProtocolServer *server = protocolServerNew(
|
|
|
|
strNew("test"), strNew("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
|
|
|
|
|
|
|
bufUsedSet(serverWrite, 0);
|
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
// Add archive-async and spool path
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH_SPOOL);
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
hrnCfgEnvRawZ(cfgOptRepoCipherPass, TEST_CIPHER_PASS);
|
|
|
|
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleLocal, argList);
|
|
|
|
hrnCfgEnvRemoveRaw(cfgOptRepoCipherPass);
|
|
|
|
|
|
|
|
// Setup protocol command
|
|
|
|
VariantList *paramList = varLstNew();
|
|
|
|
varLstAdd(paramList, varNewStrZ("01ABCDEF01ABCDEF01ABCDEF"));
|
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
archiveGetProtocol(PROTOCOL_COMMAND_ARCHIVE_GET_STR, paramList, server), true, "protocol archive get");
|
|
|
|
|
|
|
|
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":0}\n", "check result");
|
|
|
|
TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000002\n01ABCDEF01ABCDEF01ABCDEF\n");
|
|
|
|
|
|
|
|
bufUsedSet(serverWrite, 0);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("invalid protocol command");
|
|
|
|
|
|
|
|
TEST_RESULT_BOOL(archiveGetProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|