2018-04-30 17:27:39 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Archive Get Command
|
|
|
|
***********************************************************************************************************************************/
|
2021-04-14 15:41:55 -04:00
|
|
|
#include "common/io/fdRead.h"
|
|
|
|
#include "common/io/fdWrite.h"
|
2018-09-11 15:42:31 -04:00
|
|
|
|
2021-05-24 12:40:27 -04:00
|
|
|
#include "common/harnessConfig.h"
|
|
|
|
#include "common/harnessFork.h"
|
2019-04-23 14:02:30 -04:00
|
|
|
#include "common/harnessInfo.h"
|
2021-05-17 07:20:28 -04:00
|
|
|
#include "common/harnessPostgres.h"
|
2021-05-25 11:06:05 -04:00
|
|
|
#include "common/harnessProtocol.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
|
|
|
|
***********************************************************************************************************************************/
|
2021-10-18 12:22:48 -04:00
|
|
|
static 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();
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("queueNeed()"))
|
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
2021-07-02 12:22:11 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
2020-10-19 14:03:48 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, "/unused");
|
2021-07-02 12:22:11 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH "/spool");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(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
|
|
|
|
2021-07-02 12:22:11 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("path missing");
|
|
|
|
|
2021-05-22 09:30:54 -04:00
|
|
|
TEST_ERROR(
|
2022-12-20 12:20:47 +07:00
|
|
|
queueNeed(STRDEF("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_95),
|
2021-05-22 09:30:54 -04:00
|
|
|
PathMissingError, "unable to list file info for missing path '" TEST_PATH "/spool/archive/test1/in'");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("queue size too small");
|
|
|
|
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
2022-12-20 12:20:47 +07:00
|
|
|
queueNeed(STRDEF("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_95),
|
2021-01-08 12:49:33 -05:00
|
|
|
"000000010000000100000001\n000000010000000100000002\n", "queue size smaller than min");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("queue empty");
|
|
|
|
|
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(
|
2022-12-20 12:20:47 +07:00
|
|
|
queueNeed(STRDEF("000000010000000100000001"), false, queueSize, walSegmentSize, PG_VERSION_95),
|
2021-01-08 12:49:33 -05:00
|
|
|
"000000010000000100000001\n000000010000000100000002\n000000010000000100000003\n", "empty queue");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2022-12-20 12:20:47 +07:00
|
|
|
TEST_TITLE("ok/junk status files");
|
2021-07-02 12:22:11 -04:00
|
|
|
|
2018-05-18 11:57:32 -04:00
|
|
|
Buffer *walSegmentBuffer = bufNew(walSegmentSize);
|
|
|
|
memset(bufPtr(walSegmentBuffer), 0, walSegmentSize);
|
|
|
|
|
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");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// Bad OK file with wrong length (just to make sure this does not cause strSubN() issues)
|
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/AAA.ok", "0\nWARNING");
|
|
|
|
|
|
|
|
// OK file with warnings somehow left over from a prior run
|
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFD.ok", "0\nWARNING");
|
|
|
|
|
|
|
|
// Valid queued WAL segments (one with an OK file containing warnings)
|
2021-01-08 16:14:26 -05:00
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFE", walSegmentBuffer);
|
|
|
|
HRN_STORAGE_PUT(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFF", walSegmentBuffer);
|
2021-02-23 15:34:28 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFF.ok", "0\nWARNING2");
|
|
|
|
|
|
|
|
// Empty OK file indicating a WAL segment not found at the end of the queue
|
|
|
|
HRN_STORAGE_PUT_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000B00000000.ok");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-01-08 12:49:33 -05:00
|
|
|
TEST_RESULT_STRLST_Z(
|
2021-05-21 17:36:43 -04:00
|
|
|
queueNeed(STRDEF("000000010000000A00000FFD"), true, queueSize, walSegmentSize, PG_VERSION_11),
|
2023-11-09 12:59:12 -03:00
|
|
|
"000000010000000B00000000\n000000010000000B00000001\n000000010000000B00000002\n", "queue has wal");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_LIST(
|
|
|
|
storageSpool(), STORAGE_SPOOL_ARCHIVE_IN,
|
|
|
|
"000000010000000A00000FFE\n000000010000000A00000FFF\n000000010000000A00000FFF.ok\n");
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("cmdArchiveGetAsync()"))
|
|
|
|
{
|
|
|
|
harnessLogLevelSet(logLevelDetail);
|
|
|
|
|
2021-05-25 11:06:05 -04:00
|
|
|
// Install local command handler shim
|
|
|
|
static const ProtocolServerHandler testLocalHandlerList[] = {PROTOCOL_SERVER_HANDLER_ARCHIVE_GET_LIST};
|
2022-04-07 19:00:15 -04:00
|
|
|
hrnProtocolLocalShimInstall(testLocalHandlerList, LENGTH_OF(testLocalHandlerList));
|
2021-05-25 11:06:05 -04:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// Arguments that must be included
|
|
|
|
StringList *argBaseList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH "/repo");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptSpoolPath, TEST_PATH "/spool");
|
2021-01-08 16:48:32 -05:00
|
|
|
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);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchiveGetAsync(), HostInvalidError, "archive-get command must be run on the PostgreSQL host");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/global.error",
|
|
|
|
"72\narchive-get command must be run on the PostgreSQL host", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
2021-01-08 16:29:56 -05:00
|
|
|
|
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);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
2020-02-12 17:18:48 -07:00
|
|
|
|
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-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/global.error", "96\nat least one wal segment is required",
|
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
2021-01-08 16:29:56 -05:00
|
|
|
|
2024-03-10 17:08:42 +13:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("pg_control from backup is not valid without backup_label");
|
|
|
|
|
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_10, .checkpoint = PG_CONTROL_CHECKPOINT_INVALID);
|
|
|
|
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGetAsync(), FormatError,
|
|
|
|
"pg_control from backup is not valid without backup_label\n"
|
|
|
|
"HINT: was the backup_label file removed?");
|
|
|
|
|
|
|
|
TEST_RESULT_LOG(
|
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001");
|
|
|
|
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");
|
|
|
|
|
2024-03-10 17:08:42 +13:00
|
|
|
// Success not that backup_label exists
|
|
|
|
HRN_STORAGE_PUT_EMPTY(storagePgWrite(), PG_FILE_BACKUPLABEL);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
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"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n");
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
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-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-01-08 16:48:32 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-01-15 10:15:52 -05:00
|
|
|
"P00 DETAIL: unable to find 000000010000000100000001 in the archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("error on path permission");
|
|
|
|
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storageRepoIdxWrite(0), STORAGE_REPO_ARCHIVE "/10-1", .mode = 0400);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "get async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
"P00 WARN: repo1: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo/archive/test2/10-1"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/0000000100000001': [13] Permission denied\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 WARN: [RepoInvalidError] unable to find a valid repository");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.error",
|
|
|
|
"103\n"
|
|
|
|
"unable to find a valid repository\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
"repo1: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo/archive/test2/10-1/0000000100000001':"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [13] Permission denied",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
|
|
|
HRN_STORAGE_MODE(storageRepoIdxWrite(0), STORAGE_REPO_ARCHIVE "/10-1");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-01-08 16:48:32 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-05-25 11:06:05 -04:00
|
|
|
"P01 WARN: [FileReadError] raised from local-1 shim protocol: unable to get 000000010000000100000001:\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
" repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.error",
|
|
|
|
"42\n"
|
2021-05-25 11:06:05 -04:00
|
|
|
"raised from local-1 shim protocol: unable to get 000000010000000100000001:\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz [FormatError]"
|
2023-01-30 11:55:54 +07:00
|
|
|
" unexpected eof in compressed data",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.pgbackrest.tmp\n");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
|
|
|
.remove = true);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2019-02-27 23:03:02 +02:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 000000010000000100000001 in the repo1: 10-1 archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("single segment with one invalid file");
|
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n"
|
|
|
|
"2={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
|
|
|
"P01 WARN: repo1: 10-2/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 000000010000000100000001 in the repo1: 10-1 archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo1: 10-2/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz [FormatError]"
|
2023-01-30 11:55:54 +07:00
|
|
|
" unexpected eof in compressed data",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("single segment with one invalid file");
|
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n"
|
|
|
|
"2={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
|
|
|
"P01 WARN: repo1: 10-2/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 000000010000000100000001 in the repo1: 10-1 archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo1: 10-2/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz [FormatError]"
|
2023-01-30 11:55:54 +07:00
|
|
|
" unexpected eof in compressed data",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
|
|
|
.remove = true);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_TITLE("multiple segments where some are missing or errored and mismatched repo");
|
|
|
|
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgKeyRawZ(argBaseList, cfgOptRepoPath, 2, TEST_PATH "/repo2");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "0000000100000001000000FE");
|
|
|
|
strLstAddZ(argList, "0000000100000001000000FF");
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
2019-02-27 23:03:02 +02:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoIdxWrite(1), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_11_Z ",\"db-version\":\"11\"}\n");
|
2021-02-23 15:34:28 -05: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
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-01-12 18:20:28 -05:00
|
|
|
"P00 INFO: get 3 WAL file(s) from archive: 0000000100000001000000FE...000000010000000200000000\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P00 WARN: repo2: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 0000000100000001000000FE in the repo1: 10-1 archive\n"
|
2021-01-15 10:15:52 -05:00
|
|
|
"P00 DETAIL: unable to find 0000000100000001000000FF in the archive");
|
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET(
|
2021-07-02 12:22:11 -04:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FE.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo2: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2021-11-30 08:28:36 -05:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'",
|
2021-07-02 12:22:11 -04:00
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET(
|
2021-07-02 12:22:11 -04:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FF.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo2: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2021-11-30 08:28:36 -05:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'",
|
2021-07-02 12:22:11 -04:00
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FE", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
2021-01-15 10:15:52 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_TITLE("error on duplicates now that no segments are missing, repo with bad perms");
|
|
|
|
|
|
|
|
// Fix repo 2 archive info but break archive path
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoIdxWrite(1), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1", .mode = 0400);
|
2021-01-15 10:15:52 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/0000000100000001000000FF-efefefefefefefefefefefefefefefefefefefef");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-01-15 10:15:52 -05:00
|
|
|
"P00 INFO: get 3 WAL file(s) from archive: 0000000100000001000000FE...000000010000000200000000\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P00 WARN: repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo2/archive/test2/10-1"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/0000000100000001': [13] Permission denied\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P00 WARN: repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo2/archive/test2/10-1"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/0000000100000002': [13] Permission denied\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 0000000100000001000000FE in the repo1: 10-1 archive\n"
|
|
|
|
"P01 DETAIL: found 0000000100000001000000FF in the repo1: 10-1 archive\n"
|
|
|
|
"P00 WARN: [ArchiveDuplicateError] duplicates found for WAL segment 000000010000000200000000:\n"
|
2021-10-02 16:29:31 -04:00
|
|
|
" repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
2023-01-30 11:55:54 +07:00
|
|
|
", 10-1/0000000100000002/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2019-02-27 23:03:02 +02:00
|
|
|
" HINT: are multiple primaries archiving to this stanza?");
|
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FE", .remove = true);
|
|
|
|
TEST_STORAGE_GET(
|
2021-07-02 12:22:11 -04:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FE.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo2/archive/test2/10-1/0000000100000001':"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [13] Permission denied",
|
2021-07-02 12:22:11 -04:00
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FF", .remove = true);
|
|
|
|
TEST_STORAGE_GET(
|
2021-07-02 12:22:11 -04:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/0000000100000001000000FF.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo2/archive/test2/10-1/0000000100000001':"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [13] Permission denied",
|
2021-07-02 12:22:11 -04:00
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.error",
|
|
|
|
"45\n"
|
|
|
|
"duplicates found for WAL segment 000000010000000200000000:\n"
|
2021-10-02 16:29:31 -04:00
|
|
|
"repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 10-1/0000000100000002"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"HINT: are multiple primaries archiving to this stanza?\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo2/archive/test2/10-1" \
|
2023-01-30 11:55:54 +07:00
|
|
|
"/0000000100000002': [13] Permission denied",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
|
|
|
HRN_STORAGE_MODE(storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("error on duplicates");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000200000000\n"
|
|
|
|
"P00 WARN: [ArchiveDuplicateError] duplicates found for WAL segment 000000010000000200000000:\n"
|
2021-10-02 16:29:31 -04:00
|
|
|
" repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
2023-01-30 11:55:54 +07:00
|
|
|
", 10-1/0000000100000002/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
" HINT: are multiple primaries archiving to this stanza?");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.error",
|
|
|
|
"45\n"
|
|
|
|
"duplicates found for WAL segment 000000010000000200000000:\n"
|
2021-10-02 16:29:31 -04:00
|
|
|
"repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 10-1/0000000100000002"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"HINT: are multiple primaries archiving to this stanza?",
|
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("warn on invalid file");
|
|
|
|
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgKeyRawZ(argBaseList, cfgOptRepoPath, 3, TEST_PATH "/repo3");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoIdxWrite(2), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"11\"}\n");
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storageRepoIdxWrite(2), "10-1", .mode = 0400);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoIdxWrite(0),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz");
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoIdxWrite(1),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000200000000\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P00 WARN: repo3: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P01 WARN: repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P01 DETAIL: found 000000010000000200000000 in the repo2: 10-1 archive");
|
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
2021-07-02 12:22:11 -04:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.ok",
|
|
|
|
"0\n"
|
|
|
|
"repo3: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000", .remove = true);
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
|
|
|
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
.remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("error with warnings");
|
|
|
|
|
2021-10-01 17:15:36 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync, .jobRetry = 1);
|
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoIdxWrite(1),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGetAsync(), "archive async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000200000000\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"P00 WARN: repo3: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'\n"
|
2021-05-25 11:06:05 -04:00
|
|
|
"P01 WARN: [FileReadError] raised from local-1 shim protocol: unable to get 000000010000000200000000:\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
" repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
" repo2: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2023-04-06 11:03:46 +04:00
|
|
|
" [RETRY DETAIL OMITTED]");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_STORAGE_GET(
|
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.error",
|
|
|
|
"42\n"
|
2021-05-25 11:06:05 -04:00
|
|
|
"raised from local-1 shim protocol: unable to get 000000010000000200000000:\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"repo1: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"repo2: 10-1/0000000100000002/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2023-04-06 11:03:46 +04:00
|
|
|
"[RETRY DETAIL OMITTED]\n"
|
2021-07-02 12:22:11 -04:00
|
|
|
"repo3: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_Z "'",
|
2021-02-23 15:34:28 -05:00
|
|
|
.remove = true);
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_STORAGE_LIST(
|
2021-02-23 15:34:28 -05:00
|
|
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000200000000.pgbackrest.tmp\n", .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
|
|
|
|
2021-05-25 11:06:05 -04:00
|
|
|
// Uninstall local command handler shim
|
|
|
|
hrnProtocolLocalShimUninstall();
|
|
|
|
|
2019-02-27 23:03:02 +02:00
|
|
|
argList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH "/spool");
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test2");
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "0000000100000001000000FE");
|
|
|
|
strLstAddZ(argList, "0000000100000001000000FF");
|
|
|
|
strLstAddZ(argList, "000000010000000200000000");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .role = cfgCmdRoleAsync, .exeBogus = true);
|
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");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
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(
|
2021-05-21 17:36:43 -04:00
|
|
|
strNewBuf(storageGetP(storageNewReadP(storageSpool(), STRDEF(STORAGE_SPOOL_ARCHIVE_IN "/global.error")))),
|
2023-01-30 11:55:54 +07: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);
|
|
|
|
|
|
|
|
StringList *argBaseList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH "/repo");
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptStanza, "test1");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptArchiveTimeout, "1");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
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);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
2020-02-12 17:18:48 -07:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchiveGet(), HostInvalidError, "archive-get command must be run on the PostgreSQL host");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("segment parameter not specified");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
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-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("path parameter not specified");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
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-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("no valid repo");
|
|
|
|
|
2021-11-30 13:23:11 -05:00
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_10);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-05-22 11:59:43 -04:00
|
|
|
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2023-01-30 11:55:54 +07:00
|
|
|
"P00 WARN: repo1: [FileMissingError] unable to load info file '" TEST_PATH "/repo/archive/test1/archive.info' or"
|
|
|
|
" '" TEST_PATH "/repo/archive/test1/archive.info.copy':\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo/archive/test1/archive.info' for read\n"
|
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo/archive/test1/archive.info.copy' for"
|
2023-01-30 11:55:54 +07:00
|
|
|
" read\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
" 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"
|
2023-01-30 11:55:54 +07:00
|
|
|
" scheme.");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("no valid repo - async");
|
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2021-07-02 12:22:11 -04:00
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
2021-01-08 16:48:32 -05:00
|
|
|
strLstAddZ(argList, "00000001.history");
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYHISTORY");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-05-22 11:59:43 -04:00
|
|
|
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2023-01-30 11:55:54 +07:00
|
|
|
"P00 WARN: repo1: [FileMissingError] unable to load info file '" TEST_PATH "/repo/archive/test1/archive.info' or"
|
|
|
|
" '" TEST_PATH "/repo/archive/test1/archive.info.copy':\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo/archive/test1/archive.info' for read\n"
|
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo/archive/test1/archive.info.copy' for"
|
2023-01-30 11:55:54 +07:00
|
|
|
" read\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
" 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"
|
2023-01-30 11:55:54 +07:00
|
|
|
" scheme.");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("WAL not found - timeout");
|
|
|
|
|
|
|
|
// Make sure the process times out when there is nothing to get
|
2021-01-08 16:48:32 -05:00
|
|
|
argList = strLstDup(argBaseList);
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH "/spool");
|
2021-01-08 16:48:32 -05:00
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
2018-04-30 17:27:39 -04:00
|
|
|
strLstAddZ(argList, "pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
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-05-13 17:51:39 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveTimeoutError,
|
2022-05-02 08:49:13 -04:00
|
|
|
"unable to get WAL file '000000010000000100000001' from the archive asynchronously after 1 second(s)\n"
|
|
|
|
"HINT: check '" HRN_PATH "/test1-archive-get-async.log' for errors.");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("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-05-13 17:51:39 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveTimeoutError,
|
2022-05-02 08:49:13 -04:00
|
|
|
"unable to get WAL file '000000010000000100000001' from the archive asynchronously after 1 second(s)\n"
|
|
|
|
"HINT: check '" HRN_PATH "/test1-archive-get-async.log' for errors.");
|
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");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("write WAL segment for success");
|
|
|
|
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storagePgWrite(), "pg_wal");
|
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-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001 in the archive asynchronously");
|
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);
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("write WAL segments for success - queue full");
|
|
|
|
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptArchiveGetQueueMax, "48");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-07-02 12:22:11 -04:00
|
|
|
// Write more WAL segments (in this case queue should be full)
|
2021-01-08 16:48:32 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", "SHOULD-BE-A-REAL-WAL-FILE");
|
2021-02-23 15:34:28 -05:00
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok", "0\nwarning about x");
|
2021-01-08 16:48:32 -05:00
|
|
|
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-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
|
|
|
"P00 WARN: warning about x\n"
|
|
|
|
"P00 INFO: found 000000010000000100000001 in the archive asynchronously");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-05-24 12:40:27 -04:00
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000002\n", .remove = true);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("unable to get lock");
|
|
|
|
|
|
|
|
// Make sure the process times out when it can't get a lock
|
2021-07-13 11:58:23 -04:00
|
|
|
HRN_FORK_BEGIN()
|
2021-04-14 15:41:55 -04:00
|
|
|
{
|
2021-07-13 14:22:53 -04:00
|
|
|
HRN_FORK_CHILD_BEGIN()
|
2021-04-14 15:41:55 -04:00
|
|
|
{
|
2023-03-25 14:07:31 +07:00
|
|
|
lockInit(cfgOptionStr(cfgOptLockPath), STRDEF("999-dededede"), cfgOptionStr(cfgOptStanza), cfgLockType());
|
|
|
|
TEST_RESULT_VOID(lockAcquireP(.timeout = 30000, .returnOnNoLock = true), "acquire lock");
|
2021-04-14 15:41:55 -04:00
|
|
|
|
2021-07-14 14:31:57 -04:00
|
|
|
// Notify parent that lock has been acquired
|
|
|
|
HRN_FORK_CHILD_NOTIFY_PUT();
|
|
|
|
|
|
|
|
// Wait for parent to allow release lock
|
|
|
|
HRN_FORK_CHILD_NOTIFY_GET();
|
2021-04-14 15:41:55 -04:00
|
|
|
|
|
|
|
lockRelease(true);
|
|
|
|
}
|
2021-07-13 11:58:23 -04:00
|
|
|
HRN_FORK_CHILD_END();
|
2021-04-14 15:41:55 -04:00
|
|
|
|
2021-07-13 11:58:23 -04:00
|
|
|
HRN_FORK_PARENT_BEGIN()
|
2021-04-14 15:41:55 -04:00
|
|
|
{
|
2021-07-14 14:31:57 -04:00
|
|
|
// Wait for child to acquire lock
|
|
|
|
HRN_FORK_PARENT_NOTIFY_GET(0);
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-05-13 17:51:39 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveTimeoutError,
|
2022-05-02 08:49:13 -04:00
|
|
|
"unable to get WAL file '000000010000000100000001' from the archive asynchronously after 1 second(s)\n"
|
|
|
|
"HINT: check '" HRN_PATH "/test1-archive-get-async.log' for errors.");
|
2018-04-30 17:27:39 -04:00
|
|
|
|
2021-07-14 14:31:57 -04:00
|
|
|
// Notify child to release lock
|
|
|
|
HRN_FORK_PARENT_NOTIFY_PUT(0);
|
2021-04-14 15:41:55 -04:00
|
|
|
}
|
2021-07-13 11:58:23 -04:00
|
|
|
HRN_FORK_PARENT_END();
|
2021-04-14 15:41:55 -04:00
|
|
|
}
|
2021-07-13 11:58:23 -04:00
|
|
|
HRN_FORK_END();
|
2021-04-14 15:41:55 -04:00
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_TITLE("too many parameters specified");
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
strLstAddZ(argList, BOGUS_STR);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList, .exeBogus = true);
|
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
|
|
|
|
2021-11-30 13:23:11 -05:00
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_11);
|
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"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-01-12 18:20:28 -05:00
|
|
|
argBaseList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptRepoPath, TEST_PATH "/repo");
|
2021-01-12 18:20:28 -05:00
|
|
|
hrnCfgArgRawZ(argBaseList, cfgOptStanza, "test1");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
2021-01-08 16:48:32 -05:00
|
|
|
strLstAddZ(argList, "01ABCDEF01ABCDEF01ABCDEF");
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 WARN: repo1: [ArchiveMismatchError] unable to retrieve the archive id for database version '11' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_11_Z "'");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-04-21 18:27:18 -04:00
|
|
|
TEST_TITLE("pg system id does not match archive.info");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-11-30 13:23:11 -05:00
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_10, .systemId = 1);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 WARN: repo1: [ArchiveMismatchError] unable to retrieve the archive id for database version '10' and system-id"
|
2023-01-30 11:55:54 +07:00
|
|
|
" '" HRN_PG_SYSTEMID_10_1_Z "'");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("file is missing");
|
|
|
|
|
2021-11-30 13:23:11 -05:00
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_10);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: unable to find 01ABCDEF01ABCDEF01ABCDEF in the archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST_EMPTY(storagePg(), "pg_wal");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
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-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-1 archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2023-03-09 02:23:15 +01:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get WAL segment with a modified control/catalog version");
|
|
|
|
|
|
|
|
// Modify control/catalog version and use the --pg-version option
|
2023-07-26 10:45:12 +02:00
|
|
|
HRN_PG_CONTROL_OVERRIDE_VERSION_PUT(storagePgWrite(), PG_VERSION_10, 1501, .catalogVersion = 202211111);
|
2023-03-09 02:23:15 +01:00
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), VersionNotSupportedError,
|
|
|
|
"unexpected control version = 1501 and catalog version = 202211111\n"
|
|
|
|
"HINT: is this version of PostgreSQL supported?");
|
|
|
|
|
|
|
|
StringList *argListTemp = strLstDup(argList);
|
|
|
|
hrnCfgArgRawZ(argListTemp, cfgOptPgVersionForce, "10");
|
|
|
|
HRN_CFG_LOAD(cfgCmdArchivePush, argListTemp);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
|
|
|
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-1 archive");
|
|
|
|
|
|
|
|
// Reset control file and command options
|
|
|
|
HRN_PG_CONTROL_PUT(storagePgWrite(), PG_VERSION_10);
|
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
|
|
|
|
|
|
|
// Clean-up pg_wal directory
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_RESULT_UINT(storageInfoP(storagePg(), STRDEF("pg_wal/RECOVERYXLOG")).size, 16 * 1024 * 1024, "check size");
|
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-01-13 13:01:40 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("error on duplicate WAL segment");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), ArchiveDuplicateError,
|
2021-02-23 15:34:28 -05:00
|
|
|
"duplicates found for WAL segment 01ABCDEF01ABCDEF01ABCDEF:\n"
|
2021-10-02 16:29:31 -04:00
|
|
|
"repo1: 10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
2023-01-30 11:55:54 +07:00
|
|
|
", 10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
|
2021-01-13 13:01:40 -05:00
|
|
|
"HINT: are multiple primaries archiving to this stanza?");
|
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL);
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
|
|
.remove = true);
|
2021-01-13 13:01:40 -05:00
|
|
|
|
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"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n"
|
|
|
|
"2={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}\n"
|
|
|
|
"3={\"db-id\":" HRN_PG_SYSTEMID_11_Z ",\"db-version\":\"11\"}\n"
|
|
|
|
"4={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-1 archive");
|
2021-01-15 10:15:52 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-01-15 10:15:52 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get from current db-id");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
2021-02-23 15:34:28 -05:00
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
2021-01-15 10:15:52 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-4 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
.remove = true);
|
|
|
|
TEST_STORAGE_EXISTS(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
.remove = true);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
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(),
|
2021-02-23 15:34:28 -05:00
|
|
|
STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
2021-01-12 18:20:28 -05:00
|
|
|
buffer);
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001.partial");
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001.partial in the repo1: 10-4 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-06-08 14:51:23 -04:00
|
|
|
TEST_STORAGE_EXISTS(
|
2021-01-12 18:20:28 -05:00
|
|
|
storageRepoWrite(),
|
2021-06-08 14:51:23 -04:00
|
|
|
STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", .remove = true);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get missing history");
|
|
|
|
|
|
|
|
argList = strLstDup(argBaseList);
|
|
|
|
strLstAddZ(argList, "00000001.history");
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYHISTORY");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 1, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: unable to find 00000001.history in the archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("get history");
|
|
|
|
|
|
|
|
HRN_STORAGE_PUT(storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/00000001.history", BUFSTRDEF("HISTORY"));
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 00000001.history in the repo1: 10-1 archive");
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_RESULT_UINT(storageInfoP(storagePg(), STRDEF("pg_wal/RECOVERYHISTORY")).size, 7, "check size");
|
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYHISTORY\n", .remove = true);
|
2021-01-12 18:20:28 -05:00
|
|
|
|
2021-01-08 16:48:32 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-02-23 15:34:28 -05:00
|
|
|
TEST_TITLE("get compressed and encrypted WAL segment with invalid repo");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
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"
|
2021-11-30 08:28:36 -05:00
|
|
|
"1={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}",
|
2021-01-08 16:48:32 -05:00
|
|
|
.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-21 15:21:50 -05:00
|
|
|
argList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 1, TEST_PATH "/repo-bogus");
|
|
|
|
hrnCfgArgKeyRawFmt(argList, cfgOptRepoPath, 2, TEST_PATH "/repo");
|
2021-04-28 11:36:20 -04:00
|
|
|
hrnCfgArgKeyRawStrId(argList, cfgOptRepoCipherType, 2, cipherTypeAes256Cbc);
|
2021-01-21 15:21:50 -05:00
|
|
|
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
|
2021-01-12 18:20:28 -05:00
|
|
|
strLstAddZ(argList, "01ABCDEF01ABCDEF01ABCDEF");
|
2021-06-28 13:28:28 -04:00
|
|
|
strLstAddZ(argList, TEST_PATH "/pg/pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-01-21 15:21:50 -05:00
|
|
|
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 2);
|
2021-01-08 16:48:32 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-06-28 13:28:28 -04:00
|
|
|
"P00 WARN: repo1: [FileMissingError] unable to load info file '" TEST_PATH "/repo-bogus/archive/test1/archive.info'"
|
2023-01-30 11:55:54 +07:00
|
|
|
" or '" TEST_PATH "/repo-bogus/archive/test1/archive.info.copy':\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo-bogus/archive/test1/archive.info'"
|
2023-01-30 11:55:54 +07:00
|
|
|
" for read\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
" FileMissingError: unable to open missing file '" TEST_PATH "/repo-bogus/archive/test1/archive.info.copy'"
|
2023-01-30 11:55:54 +07:00
|
|
|
" for read\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
" 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"
|
2023-01-30 11:55:54 +07:00
|
|
|
" archiving scheme.\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_RESULT_UINT(storageInfoP(storagePg(), STRDEF("pg_wal/RECOVERYXLOG")).size, 16 * 1024 * 1024, "check size");
|
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("repo1 has info but bad permissions");
|
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=2\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"2={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
2021-05-28 15:23:18 -04:00
|
|
|
HRN_STORAGE_PATH_CREATE(storageRepoIdxWrite(0), STORAGE_REPO_ARCHIVE "/10-2", .mode = 0400);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-06-28 13:28:28 -04:00
|
|
|
"P00 WARN: repo1: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo-bogus/archive/test1/10-2"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/01ABCDEF01ABCDEF': [13] Permission denied\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
|
|
|
|
2021-05-27 16:50:18 -04:00
|
|
|
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("all repos have info but bad permissions");
|
|
|
|
|
|
|
|
HRN_STORAGE_MODE(storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1", .mode = 0400);
|
|
|
|
|
|
|
|
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-06-28 13:28:28 -04:00
|
|
|
"P00 WARN: repo1: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo-bogus/archive/test1/10-2"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/01ABCDEF01ABCDEF': [13] Permission denied\n"
|
2021-06-28 13:28:28 -04:00
|
|
|
"P00 WARN: repo2: [PathOpenError] unable to list file info for path '" TEST_PATH "/repo/archive/test1/10-1"
|
2023-01-30 11:55:54 +07:00
|
|
|
"/01ABCDEF01ABCDEF': [13] Permission denied");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_MODE(storageRepoIdxWrite(0), STORAGE_REPO_ARCHIVE "/10-2");
|
|
|
|
HRN_STORAGE_MODE(storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("unable to get from one repo");
|
|
|
|
|
2021-07-02 12:22:11 -04:00
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
2021-02-23 15:34:28 -05:00
|
|
|
storageRepoIdxWrite(0),
|
2021-07-02 12:22:11 -04:00
|
|
|
STORAGE_REPO_ARCHIVE "/10-2/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG(
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 WARN: repo1: 10-2/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"
|
2023-01-30 11:55:54 +07:00
|
|
|
" [FormatError] unexpected eof in compressed data\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("unable to get from all repos");
|
|
|
|
|
|
|
|
HRN_STORAGE_MODE(
|
|
|
|
storageRepoIdxWrite(1),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz", .mode = 0200);
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchiveGet(), FileReadError,
|
|
|
|
"unable to get 01ABCDEF01ABCDEF01ABCDEF:\n"
|
|
|
|
"repo1: 10-2/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz [FormatError]"
|
2023-01-30 11:55:54 +07:00
|
|
|
" unexpected eof in compressed data\n"
|
2021-02-23 15:34:28 -05:00
|
|
|
"repo2: 10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz [FileOpenError]"
|
2023-01-30 11:55:54 +07:00
|
|
|
" unable to open file '" TEST_PATH "/repo/archive/test1/10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF"
|
|
|
|
"-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz' for read: [13] Permission denied");
|
2021-02-23 15:34:28 -05:00
|
|
|
|
|
|
|
HRN_STORAGE_MODE(
|
|
|
|
storageRepoIdxWrite(1),
|
|
|
|
STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("repo is specified so invalid repo is skipped");
|
|
|
|
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepo, "2");
|
|
|
|
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-02-23 15:34:28 -05:00
|
|
|
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 2);
|
|
|
|
|
|
|
|
TEST_RESULT_INT(cmdArchiveGet(), 0, "get");
|
|
|
|
|
2021-07-02 12:22:11 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
2021-01-08 16:48:32 -05:00
|
|
|
|
2021-05-13 17:51:39 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("no segments to find with existing ok file");
|
|
|
|
|
|
|
|
argList = strLstNew();
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
|
2021-05-13 17:51:39 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptArchiveTimeout, "10");
|
2021-06-28 13:28:28 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH "/spool");
|
2021-05-13 17:51:39 -04:00
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
|
|
|
strLstAddZ(argList, "pg_wal/RECOVERYXLOG");
|
2021-06-01 09:03:44 -04:00
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
2021-05-13 17:51:39 -04:00
|
|
|
|
|
|
|
HRN_INFO_PUT(
|
|
|
|
storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE,
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=2\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
2021-11-30 08:28:36 -05:00
|
|
|
"2={\"db-id\":" HRN_PG_SYSTEMID_10_Z ",\"db-version\":\"10\"}");
|
2021-05-13 17:51:39 -04:00
|
|
|
|
|
|
|
// Put a warning in the file to show that it was read and later overwritten
|
|
|
|
HRN_STORAGE_PUT_Z(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok", "0\nshould not be output");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGet(), "get async");
|
|
|
|
|
2021-05-22 14:09:45 -04:00
|
|
|
TEST_RESULT_LOG("P00 INFO: unable to find 000000010000000100000001 in the archive asynchronously");
|
2021-05-13 17:51:39 -04:00
|
|
|
|
|
|
|
// Check that the ok file is missing since it should have been removed on the first loop and removed again on a subsequent
|
|
|
|
// loop once the async process discovered that the file was missing and wrote the ok file again.
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
2022-02-23 09:14:27 -06:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("do not retry missing segment");
|
|
|
|
|
|
|
|
argList = strLstNew();
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH "/pg");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH "/repo");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test1");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptArchiveTimeout, "10");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH "/spool");
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
|
|
hrnCfgArgRawBool(argList, cfgOptArchiveMissingRetry, false);
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
|
|
|
strLstAddZ(argList, "pg_wal/RECOVERYXLOG");
|
|
|
|
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
|
|
|
|
|
|
|
// Make sure that a WAL segment is found when the ok file is missing
|
|
|
|
HRN_STORAGE_PUT_EMPTY(
|
|
|
|
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGet(), "get async");
|
|
|
|
TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001 in the archive asynchronously");
|
|
|
|
|
|
|
|
// Remove the ok file created by the async process
|
|
|
|
TEST_STORAGE_LIST(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000002.ok\n", .remove = true);
|
|
|
|
|
|
|
|
// Write an ok file
|
|
|
|
HRN_STORAGE_PUT_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.ok");
|
|
|
|
|
|
|
|
// Missing should be returned since archive-missing-retry=n
|
|
|
|
TEST_RESULT_VOID(cmdArchiveGet(), "get async");
|
|
|
|
TEST_RESULT_LOG("P00 INFO: unable to find 000000010000000100000001 in the archive asynchronously");
|
|
|
|
|
|
|
|
// Check that the ok file was removed
|
|
|
|
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
2021-03-10 18:42:22 -05:00
|
|
|
FUNCTION_HARNESS_RETURN_VOID();
|
2018-04-30 17:27:39 -04:00
|
|
|
}
|