2018-01-17 15:52:00 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Archive Push Command
|
|
|
|
***********************************************************************************************************************************/
|
2019-03-29 13:26:33 +00:00
|
|
|
#include "common/io/bufferRead.h"
|
|
|
|
#include "common/io/bufferWrite.h"
|
2020-08-05 18:25:07 -04:00
|
|
|
#include "common/io/fdRead.h"
|
|
|
|
#include "common/io/fdWrite.h"
|
2019-03-29 13:26:33 +00:00
|
|
|
#include "common/time.h"
|
|
|
|
#include "postgres/version.h"
|
2019-05-03 15:46:15 -04:00
|
|
|
#include "storage/posix/storage.h"
|
2018-09-14 16:08:33 -04:00
|
|
|
|
2018-04-13 16:05:52 -04:00
|
|
|
#include "common/harnessConfig.h"
|
2019-03-29 13:26:33 +00:00
|
|
|
#include "common/harnessFork.h"
|
2019-04-23 14:02:30 -04:00
|
|
|
#include "common/harnessInfo.h"
|
2018-04-13 16:05:52 -04:00
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
2018-01-31 18:22:25 -05:00
|
|
|
void
|
2018-08-03 19:19:14 -04:00
|
|
|
testRun(void)
|
2018-01-17 15:52:00 -05:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
// Create default storage object for testing
|
2020-04-30 11:01:38 -04:00
|
|
|
Storage *storageTest = storagePosixNewP(strNew(testPath()), .write = true);
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Start a protocol server to test the protocol directly
|
|
|
|
Buffer *serverWrite = bufNew(8192);
|
2019-05-02 17:52:24 -04:00
|
|
|
IoWrite *serverWriteIo = ioBufferWriteNew(serverWrite);
|
2019-03-29 13:26:33 +00:00
|
|
|
ioWriteOpen(serverWriteIo);
|
|
|
|
|
|
|
|
ProtocolServer *server = protocolServerNew(
|
2019-05-02 17:52:24 -04:00
|
|
|
strNew("test"), strNew("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
bufUsedSet(serverWrite, 0);
|
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
// *****************************************************************************************************************************
|
2019-03-29 13:26:33 +00:00
|
|
|
if (testBegin("archivePushReadyList(), archivePushProcessList(), and archivePushDrop()"))
|
2018-01-17 15:52:00 -05:00
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--stanza=db");
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/db", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s/spool", testPath()));
|
2020-01-15 12:24:58 -07:00
|
|
|
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_ASYNC);
|
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argList);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storagePgWrite(), strNew("pg_wal/archive_status"));
|
|
|
|
storagePathCreateP(storageTest, strNew("spool/archive/db/out"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Create ok files to indicate WAL that has already been archived
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")), NULL);
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000003.ok")), NULL);
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000004.ok")), NULL);
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000005.error")), NULL);
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000006.error")), NULL);
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/global.error")), NULL);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Create ready files for wal that still needs to be archived
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000002.ready")), NULL);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000003.ready")), NULL);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000005.ready")), NULL);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000006.ready")), NULL);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(archivePushProcessList(strNewFmt("%s/db/pg_wal", testPath())), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"000000010000000100000002|000000010000000100000005|000000010000000100000006", "ready list");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(strLstSort(storageListP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"000000010000000100000003.ok", "remaining status list");
|
|
|
|
|
|
|
|
// Test drop
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
StringList *argListDrop = strLstDup(argList);
|
|
|
|
strLstAdd(argListDrop, strNewFmt("--archive-push-queue-max=%zu", (size_t)1024 * 1024 * 1024));
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argListDrop);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Write the files that we claim are in pg_wal
|
|
|
|
Buffer *walBuffer = bufNew((size_t)16 * 1024 * 1024);
|
|
|
|
bufUsedSet(walBuffer, bufSize(walBuffer));
|
|
|
|
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer);
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000002")), walBuffer);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000003")), walBuffer);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000005")), walBuffer);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000006")), walBuffer);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Queue max is high enough that no WAL will be dropped
|
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
archivePushDrop(strNew("pg_wal"), archivePushProcessList(strNewFmt("%s/db/pg_wal", testPath()))), false,
|
|
|
|
"wal is not dropped");
|
|
|
|
|
|
|
|
// Now set queue max low enough that WAL will be dropped
|
|
|
|
argListDrop = strLstDup(argList);
|
|
|
|
strLstAdd(argListDrop, strNewFmt("--archive-push-queue-max=%zu", (size_t)16 * 1024 * 1024 * 2));
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argListDrop);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
archivePushDrop(strNew("pg_wal"), archivePushProcessList(strNewFmt("%s/db/pg_wal", testPath()))), true,
|
|
|
|
"wal is dropped");
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("archivePushCheck()"))
|
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--stanza=test");
|
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argList);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Check mismatched pg_control and archive.info
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
|
2019-03-29 13:26:33 +00:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 0xFACEFACEFACEFACE}));
|
|
|
|
|
|
|
|
// Create incorrect archive info
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n"));
|
|
|
|
|
|
|
|
TEST_ERROR(
|
2020-05-01 10:30:35 -04:00
|
|
|
archivePushCheck(true, cipherTypeNone, NULL), ArchiveMismatchError,
|
2019-03-29 13:26:33 +00:00
|
|
|
"PostgreSQL version 9.6, system-id 18072658121562454734 do not match stanza version 9.4, system-id 5555555555555555555"
|
|
|
|
"\nHINT: are you archiving to the correct stanza?");
|
|
|
|
|
|
|
|
// Fix the version
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":5555555555555555555,\"db-version\":\"9.6\"}\n"));
|
|
|
|
|
|
|
|
TEST_ERROR(
|
2020-05-01 10:30:35 -04:00
|
|
|
archivePushCheck(true, cipherTypeNone, NULL), ArchiveMismatchError,
|
2019-03-29 13:26:33 +00:00
|
|
|
"PostgreSQL version 9.6, system-id 18072658121562454734 do not match stanza version 9.6, system-id 5555555555555555555"
|
|
|
|
"\nHINT: are you archiving to the correct stanza?");
|
|
|
|
|
|
|
|
// Fix archive info
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"9.6\"}\n"));
|
|
|
|
|
|
|
|
ArchivePushCheckResult result = {0};
|
2020-05-01 10:30:35 -04:00
|
|
|
TEST_ASSIGN(result, archivePushCheck(true, cipherTypeNone, NULL), "get archive check result");
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_UINT(result.pgVersion, PG_VERSION_96, "check pg version");
|
|
|
|
TEST_RESULT_UINT(result.pgSystemId, 0xFACEFACEFACEFACE, "check pg system id");
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(result.archiveId, "9.6-1", "check archive id");
|
|
|
|
TEST_RESULT_STR_Z(result.archiveCipherPass, NULL, "check archive cipher pass (not set in this test)");
|
2019-03-29 13:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("Synchronous cmdArchivePush(), archivePushFile() and archivePushProtocol()"))
|
|
|
|
{
|
2020-02-12 17:18:48 -07:00
|
|
|
TEST_TITLE("command must be run on the pg host");
|
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
StringList *argList = strLstNew();
|
2020-10-19 14:03:48 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgHost, "host");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg");
|
2020-02-12 17:18:48 -07:00
|
|
|
strLstAddZ(argList, "--" CFGOPT_STANZA "=test2");
|
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleDefault, argList);
|
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), HostInvalidError, "archive-push command must be run on the PostgreSQL host");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAddZ(argList, "--stanza=test");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argList);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), ParamRequiredError, "WAL segment to push required");
|
|
|
|
|
2019-12-11 14:36:39 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
StringList *argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "pg_wal/000000010000000100000001");
|
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), OptionRequiredError,
|
|
|
|
"option 'pg1-path' must be specified when relative wal paths are used"
|
|
|
|
"\nHINT: is %f passed to archive-push instead of %p?"
|
|
|
|
"\nHINT: PostgreSQL may pass relative paths even with %p depending on the environment.");
|
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Create pg_control and archive.info
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-12-11 14:36:39 -05:00
|
|
|
argListTemp = strLstDup(argList);
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAddZ(argListTemp, "pg_wal/000000010000000100000001");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
|
2019-03-29 13:26:33 +00:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"11\"}\n"));
|
|
|
|
|
|
|
|
// Generate WAL with incorrect headers and try to push them
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-03-29 13:26:33 +00:00
|
|
|
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
|
|
|
|
bufUsedSet(walBuffer1, bufSize(walBuffer1));
|
|
|
|
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer1);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2020-07-30 07:49:06 -04:00
|
|
|
THROW_ON_SYS_ERROR(chdir(strZ(cfgOptionStr(cfgOptPgPath))) != 0, PathMissingError, "unable to chdir()");
|
2019-10-30 14:55:25 +01:00
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
TEST_ERROR(
|
2019-03-29 13:26:33 +00:00
|
|
|
cmdArchivePush(), ArchiveMismatchError,
|
2020-07-30 07:49:06 -04:00
|
|
|
strZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
strNewFmt(
|
|
|
|
"WAL file '%s/pg/pg_wal/000000010000000100000001' version 10, system-id 18072658121562454734 do not match"
|
|
|
|
" stanza version 11, system-id 18072658121562454734",
|
|
|
|
testPath())));
|
|
|
|
|
|
|
|
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAFECAFECAF}, walBuffer1);
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer1);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), ArchiveMismatchError,
|
2020-07-30 07:49:06 -04:00
|
|
|
strZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
strNewFmt(
|
|
|
|
"WAL file '%s/pg/pg_wal/000000010000000100000001' version 11, system-id 17055110554209741999 do not match"
|
|
|
|
" stanza version 11, system-id 18072658121562454734",
|
|
|
|
testPath())));
|
|
|
|
|
|
|
|
// Generate valid WAL and push them
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
|
|
|
|
|
2020-07-20 09:47:43 -04:00
|
|
|
// Check sha1 checksum against fixed values once to make sure they are not getting munged. After this we'll calculate them
|
|
|
|
// directly from the buffers to reduce the cost of maintaining checksums.
|
|
|
|
const char *walBuffer1Sha1 = TEST_64BIT() ?
|
2020-07-20 09:59:16 -04:00
|
|
|
(TEST_BIG_ENDIAN() ? "1c5f963d720bb199d7935dbd315447ea2ec3feb2" : "aae7591a1dbc58f21d0d004886075094f622e6dd") :
|
|
|
|
"28a13fd8cf6fcd9f9a8108aed4c8bcc58040863a";
|
2020-07-20 09:47:43 -04:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer1);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push the WAL segment");
|
|
|
|
harnessLogResult("P00 INFO: pushed WAL file '000000010000000100000001' to the archive");
|
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageTest, strNewFmt("repo/archive/test/11-1/0000000100000001/000000010000000100000001-%s.gz", walBuffer1Sha1)),
|
2019-03-29 13:26:33 +00:00
|
|
|
true, "check repo for WAL file");
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push the WAL segment again");
|
|
|
|
harnessLogResult(
|
|
|
|
"P00 WARN: WAL file '000000010000000100000001' already exists in the archive with the same checksum\n"
|
|
|
|
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
|
|
|
"P00 INFO: pushed WAL file '000000010000000100000001' to the archive");
|
|
|
|
|
|
|
|
// Now create a new WAL buffer with a different checksum to test checksum errors
|
|
|
|
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
|
|
|
|
bufUsedSet(walBuffer2, bufSize(walBuffer2));
|
|
|
|
memset(bufPtr(walBuffer2), 0xFF, bufSize(walBuffer2));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer2);
|
2020-07-30 07:49:06 -04:00
|
|
|
const char *walBuffer2Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer2)));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer2);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), ArchiveDuplicateError, "WAL file '000000010000000100000001' already exists in the archive");
|
|
|
|
|
2020-05-01 10:30:35 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("WAL with absolute path and no pg1-path");
|
|
|
|
|
|
|
|
argListTemp = strLstNew();
|
|
|
|
strLstAddZ(argListTemp, "--" CFGOPT_STANZA "=test");
|
2020-10-19 14:03:48 -04:00
|
|
|
hrnCfgArgRawFmt(argListTemp, cfgOptRepoPath, "%s/repo", testPath());
|
2020-05-01 10:30:35 -04:00
|
|
|
strLstAdd(argListTemp, strNewFmt("%s/pg/pg_wal/000000010000000100000002", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2020-07-14 15:05:31 -04:00
|
|
|
TEST_RESULT_VOID(
|
|
|
|
storagePutP(storageNewWriteP(storageTest, strNew("pg/pg_wal/000000010000000100000002")), walBuffer2), "write WAL");
|
|
|
|
|
|
|
|
// Create tmp file to make it look like a prior push failed partway through to ensure that retries work
|
|
|
|
TEST_RESULT_VOID(
|
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(
|
|
|
|
storageTest,
|
2020-07-20 09:47:43 -04:00
|
|
|
strNewFmt("repo/archive/test/11-1/0000000100000001/000000010000000100000002-%s.gz.pgbackrest.tmp",
|
|
|
|
walBuffer2Sha1)),
|
2020-07-14 15:05:31 -04:00
|
|
|
BUFSTRDEF("PARTIAL")),
|
|
|
|
"write WAL tmp file");
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push the WAL segment");
|
|
|
|
harnessLogResult("P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
|
|
|
|
|
2020-07-14 15:05:31 -04:00
|
|
|
TEST_RESULT_BOOL(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageExistsP(
|
|
|
|
storageTest, strNewFmt("repo/archive/test/11-1/0000000100000001/000000010000000100000002-%s.gz", walBuffer2Sha1)),
|
2020-07-14 15:05:31 -04:00
|
|
|
true, "check repo for WAL file");
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2019-03-29 13:26:33 +00:00
|
|
|
storageTest,
|
2020-07-20 09:47:43 -04:00
|
|
|
strNewFmt("repo/archive/test/11-1/0000000100000001/000000010000000100000002-%s.gz.pgbackrest.tmp", walBuffer2Sha1)),
|
2020-07-14 15:05:31 -04:00
|
|
|
false, "check WAL tmp file is gone");
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Push a history file
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "pg_wal/00000001.history");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/00000001.history")), BUFSTRDEF("FAKEHISTORY"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push a history file");
|
|
|
|
harnessLogResult("P00 INFO: pushed WAL file '00000001.history' to the archive");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(storageTest, strNew("repo/archive/test/11-1/00000001.history")), true, "check repo for history file");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Check drop functionality
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000001.ready")), NULL);
|
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/archive_status/000000010000000100000002.ready")), NULL);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "--archive-push-queue-max=16m");
|
|
|
|
strLstAddZ(argListTemp, "pg_wal/000000010000000100000002");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "drop WAL file");
|
|
|
|
harnessLogResult("P00 WARN: dropped WAL file '000000010000000100000002' because archive queue exceeded 16MB");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "--archive-push-queue-max=1GB");
|
|
|
|
strLstAddZ(argListTemp, "pg_wal/000000010000000100000002");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push WAL file again");
|
|
|
|
harnessLogResult(
|
|
|
|
"P00 WARN: WAL file '000000010000000100000002' already exists in the archive with the same checksum\n"
|
|
|
|
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
|
|
|
"P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
|
|
|
|
|
|
|
|
// Check protocol function directly
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
VariantList *paramList = varLstNew();
|
|
|
|
varLstAdd(paramList, varNewStr(strNewFmt("%s/pg/pg_wal/000000010000000100000002", testPath())));
|
|
|
|
varLstAdd(paramList, varNewStrZ("11-1"));
|
|
|
|
varLstAdd(paramList, varNewUInt64(PG_VERSION_11));
|
|
|
|
varLstAdd(paramList, varNewUInt64(0xFACEFACEFACEFACE));
|
|
|
|
varLstAdd(paramList, varNewStrZ("000000010000000100000002"));
|
|
|
|
varLstAdd(paramList, varNewUInt64(cipherTypeNone));
|
|
|
|
varLstAdd(paramList, NULL);
|
|
|
|
varLstAdd(paramList, varNewBool(false));
|
|
|
|
varLstAdd(paramList, varNewInt(6));
|
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
archivePushProtocol(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, paramList, server), true, "protocol archive put");
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strNewBuf(serverWrite),
|
2019-03-29 13:26:33 +00:00
|
|
|
"{\"out\":\"WAL file '000000010000000100000002' already exists in the archive with the same checksum"
|
|
|
|
"\\nHINT: this is valid in some recovery scenarios but may also indicate a problem.\"}\n",
|
|
|
|
"check result");
|
|
|
|
|
|
|
|
bufUsedSet(serverWrite, 0);
|
|
|
|
|
|
|
|
// Check invalid protocol function
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_BOOL(archivePushProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
|
|
|
|
|
|
|
|
// Create a new encrypted repo to test encryption
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
storagePathRemoveP(storageTest, strNew("repo"), .errorOnMissing = true, .recurse = true);
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
StorageWrite *infoWrite = storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
ioFilterGroupAdd(
|
|
|
|
ioWriteFilterGroup(storageWriteIo(infoWrite)), cipherBlockNew(cipherModeEncrypt, cipherTypeAes256Cbc,
|
|
|
|
BUFSTRDEF("badpassphrase"), NULL));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
2019-03-29 13:26:33 +00:00
|
|
|
infoWrite,
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[cipher]\n"
|
|
|
|
"cipher-pass=\"badsubpassphrase\"\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":18072658121562454734,\"db-version\":\"11\"}"));
|
|
|
|
|
|
|
|
// Push encrypted WAL segment
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "pg_wal/000000010000000100000002");
|
|
|
|
strLstAddZ(argListTemp, "--repo1-cipher-type=aes-256-cbc");
|
|
|
|
strLstAddZ(argListTemp, "--no-compress");
|
|
|
|
setenv("PGBACKREST_REPO1_CIPHER_PASS", "badpassphrase", true);
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
unsetenv("PGBACKREST_REPO1_CIPHER_PASS");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push the WAL segment");
|
|
|
|
harnessLogResult("P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageTest, strNewFmt("repo/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
2019-03-29 13:26:33 +00:00
|
|
|
true, "check repo for WAL file");
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("Asynchronous cmdArchivePush() and cmdArchivePushAsync()"))
|
|
|
|
{
|
|
|
|
harnessLogLevelSet(logLevelDetail);
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2020-02-12 17:18:48 -07:00
|
|
|
TEST_TITLE("command must be run on the pg host");
|
|
|
|
|
|
|
|
StringList *argList = strLstNew();
|
2020-10-19 14:03:48 -04:00
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgHost, "host");
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg");
|
2020-02-12 17:18:48 -07:00
|
|
|
strLstAddZ(argList, "--" CFGOPT_SPOOL_PATH "=/spool");
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_STANZA "=test2");
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_ASYNC);
|
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argList);
|
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), HostInvalidError, "archive-push command must be run on the PostgreSQL host");
|
|
|
|
|
2020-05-01 10:30:35 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("pg1-path must be set when async");
|
|
|
|
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_SPOOL_PATH "=/spool");
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_STANZA "=test2");
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_ASYNC);
|
|
|
|
strLstAddZ(argList, "/000000010000000100000001");
|
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argList);
|
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), OptionRequiredError, "'archive-push' command in async mode requires option 'pg1-path'");
|
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Call with a bogus exe name so the async process will error out and we can make sure timeouts work
|
2018-05-05 09:38:09 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-02-12 17:18:48 -07:00
|
|
|
argList = strLstNew();
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAddZ(argList, "pgbackrest-bogus");
|
|
|
|
strLstAddZ(argList, "--stanza=test");
|
|
|
|
strLstAddZ(argList, "--archive-async");
|
|
|
|
strLstAddZ(argList, "--archive-timeout=1");
|
2019-10-08 12:06:30 -04:00
|
|
|
strLstAdd(argList, strNewFmt("--lock-path=%s/lock", testPath()));
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s/spool", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
|
|
|
strLstAddZ(argList, "archive-push");
|
|
|
|
strLstAddZ(argList, "pg_wal/bogus");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2019-12-11 14:36:39 -05:00
|
|
|
storagePathCreateP(storageTest, cfgOptionStr(cfgOptPgPath));
|
2020-07-30 07:49:06 -04:00
|
|
|
THROW_ON_SYS_ERROR(chdir(strZ(cfgOptionStr(cfgOptPgPath))) != 0, PathMissingError, "unable to chdir()");
|
2019-10-30 14:55:25 +01:00
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), ArchiveTimeoutError,
|
2019-03-29 13:26:33 +00:00
|
|
|
"unable to push WAL file 'bogus' to the archive asynchronously after 1 second(s)");
|
|
|
|
|
|
|
|
// Create pg_control and archive.info
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--stanza=test");
|
|
|
|
strLstAddZ(argList, "--archive-async");
|
|
|
|
strLstAddZ(argList, "--no-compress");
|
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s/spool", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
|
|
|
strLstAddZ(argList, "--log-subprocess");
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
|
2019-03-29 13:26:33 +00:00
|
|
|
pgControlTestToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}));
|
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
|
2019-04-23 14:02:30 -04:00
|
|
|
harnessInfoChecksumZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
"[db]\n"
|
|
|
|
"db-id=1\n"
|
|
|
|
"\n"
|
|
|
|
"[db:history]\n"
|
|
|
|
"1={\"db-id\":12297848147757817309,\"db-version\":\"9.4\"}\n"));
|
|
|
|
|
|
|
|
// Write out an error file that will be ignored on the first pass, then the async process will write a new one
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
StringList *argListTemp = strLstDup(argList);
|
|
|
|
strLstAdd(argListTemp, strNewFmt("%s/pg/pg_xlog/000000010000000100000001", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storagePgWrite(), strNew("pg_xlog/archive_status"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(
|
|
|
|
storageNewWriteP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.error")),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF("25\nbogus error"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), AssertError, "no WAL files to process");
|
|
|
|
|
|
|
|
storageRemoveP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/global.error"), .errorOnMissing = true);
|
|
|
|
|
|
|
|
// Acquire a lock so the async process will not be able to run -- this will result in a timeout
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAdd(argListTemp, strNewFmt("%s/pg/pg_xlog/000000010000000100000001", testPath()));
|
|
|
|
strLstAddZ(argListTemp, "--archive-timeout=1");
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2020-07-30 07:49:06 -04:00
|
|
|
THROW_ON_SYS_ERROR(chdir(strZ(cfgOptionStr(cfgOptPgPath))) != 0, PathMissingError, "unable to chdir()");
|
2019-10-30 14:55:25 +01:00
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
HARNESS_FORK_BEGIN()
|
|
|
|
{
|
|
|
|
HARNESS_FORK_CHILD_BEGIN(0, true)
|
|
|
|
{
|
2020-08-05 18:25:07 -04:00
|
|
|
IoRead *read = ioFdReadNew(strNew("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
2019-03-29 13:26:33 +00:00
|
|
|
ioReadOpen(read);
|
2020-08-08 11:23:37 -04:00
|
|
|
IoWrite *write = ioFdWriteNew(strNew("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
2019-03-29 13:26:33 +00:00
|
|
|
ioWriteOpen(write);
|
|
|
|
|
2020-11-23 12:41:54 -05:00
|
|
|
lockAcquire(
|
|
|
|
cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), STRDEF("555-fefefefe"), cfgLockType(), 30000, true);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Let the parent know the lock has been acquired and wait for the parent to allow lock release
|
2019-04-22 18:46:29 -04:00
|
|
|
ioWriteStrLine(write, strNew(""));
|
2019-03-29 13:26:33 +00:00
|
|
|
ioWriteFlush(write);
|
|
|
|
ioReadLine(read);
|
|
|
|
|
|
|
|
lockRelease(true);
|
|
|
|
}
|
|
|
|
HARNESS_FORK_CHILD_END();
|
|
|
|
|
|
|
|
HARNESS_FORK_PARENT_BEGIN()
|
|
|
|
{
|
2020-08-05 18:25:07 -04:00
|
|
|
IoRead *read = ioFdReadNew(strNew("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
2019-03-29 13:26:33 +00:00
|
|
|
ioReadOpen(read);
|
2020-08-08 11:23:37 -04:00
|
|
|
IoWrite *write = ioFdWriteNew(strNew("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
2019-03-29 13:26:33 +00:00
|
|
|
ioWriteOpen(write);
|
|
|
|
|
|
|
|
// Wait for the child to acquire the lock
|
|
|
|
ioReadLine(read);
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), ArchiveTimeoutError,
|
|
|
|
"unable to push WAL file '000000010000000100000001' to the archive asynchronously after 1 second(s)");
|
|
|
|
|
|
|
|
// Notify the child to release the lock
|
2019-04-22 18:46:29 -04:00
|
|
|
ioWriteLine(write, bufNew(0));
|
2019-03-29 13:26:33 +00:00
|
|
|
ioWriteFlush(write);
|
|
|
|
}
|
|
|
|
HARNESS_FORK_PARENT_END();
|
|
|
|
}
|
|
|
|
HARNESS_FORK_END();
|
|
|
|
|
|
|
|
// Actually push a WAL file
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAdd(argListTemp, strNewFmt("%s/pg/pg_xlog/000000010000000100000001", testPath()));
|
2019-10-08 12:06:30 -04:00
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/archive_status/000000010000000100000001.ready")), NULL);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
|
|
|
|
bufUsedSet(walBuffer1, bufSize(walBuffer1));
|
|
|
|
memset(bufPtr(walBuffer1), 0xFF, bufSize(walBuffer1));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer1);
|
2020-07-30 07:49:06 -04:00
|
|
|
const char *walBuffer1Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer1)));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/000000010000000100000001")), walBuffer1);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "push the WAL segment");
|
|
|
|
harnessLogResult("P00 INFO: pushed WAL file '000000010000000100000001' to the archive asynchronously");
|
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageTest, strNewFmt("repo/archive/test/9.4-1/0000000100000001/000000010000000100000001-%s", walBuffer1Sha1)),
|
2019-03-29 13:26:33 +00:00
|
|
|
true, "check repo for WAL file");
|
|
|
|
|
|
|
|
// Direct tests of the async function
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "--stanza=test");
|
|
|
|
strLstAddZ(argList, "--no-compress");
|
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s/spool", testPath()));
|
2020-01-15 12:24:58 -07:00
|
|
|
strLstAddZ(argList, "--" CFGOPT_ARCHIVE_ASYNC);
|
2019-03-29 13:26:33 +00:00
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
|
|
|
|
strLstAddZ(argList, "--log-subprocess");
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argList);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePushAsync(), ParamRequiredError, "WAL path to push required");
|
|
|
|
|
|
|
|
// Check that global.error is created
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
// Remove data from prior tests
|
|
|
|
storagePathRemoveP(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_OUT_STR, .recurse = true);
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_OUT_STR);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
storagePathRemoveP(storagePgWrite(), strNew("pg_xlog/archive_status"), .recurse = true);
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storagePgWrite(), strNew("pg_xlog/archive_status"));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
strLstAdd(argList, strNewFmt("%s/pg/pg_xlog", testPath()));
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argList);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePushAsync(), AssertError, "no WAL files to process");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strNewBuf(storageGetP(storageNewReadP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/global.error")))),
|
2019-03-29 13:26:33 +00:00
|
|
|
"25\nno WAL files to process", "check global.error");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(strLstSort(storageListP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"global.error", "check status files");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-11-09 16:10:59 -05:00
|
|
|
TEST_TITLE("push already pushed WAL and error on missing WAL");
|
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Recreate ready file for WAL 1
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/archive_status/000000010000000100000001.ready")), NULL);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
// Create a ready file for WAL 2 but don't create the segment yet -- this will test the file error
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/archive_status/000000010000000100000002.ready")), NULL);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePushAsync(), "push WAL segments");
|
|
|
|
harnessLogResult(
|
2020-07-30 07:49:06 -04:00
|
|
|
strZ(
|
2019-03-29 13:26:33 +00:00
|
|
|
strNewFmt(
|
|
|
|
"P00 INFO: push 2 WAL file(s) to archive: 000000010000000100000001...000000010000000100000002\n"
|
2020-11-09 16:10:59 -05:00
|
|
|
"P01 WARN: WAL file '000000010000000100000001' already exists in the archive with the same checksum\n"
|
|
|
|
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
2019-04-09 11:08:27 -04:00
|
|
|
"P01 DETAIL: pushed WAL file '000000010000000100000001' to the archive\n"
|
|
|
|
"P01 WARN: could not push WAL file '000000010000000100000002' to the archive (will be retried): "
|
2019-05-26 12:41:15 -04:00
|
|
|
"[55] raised from local-1 protocol: " STORAGE_ERROR_READ_MISSING,
|
2020-07-30 07:49:06 -04:00
|
|
|
strZ(strNewFmt("%s/pg/pg_xlog/000000010000000100000002", testPath())))));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageTest, strNewFmt("repo/archive/test/9.4-1/0000000100000001/000000010000000100000001-%s", walBuffer1Sha1)),
|
2019-03-29 13:26:33 +00:00
|
|
|
true, "check repo for WAL 1 file");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(strLstSort(storageListP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"000000010000000100000001.ok|000000010000000100000002.error", "check status files");
|
|
|
|
|
2020-11-09 16:10:59 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("create and push previously missing WAL");
|
|
|
|
|
2019-03-29 13:26:33 +00:00
|
|
|
// Create WAL 2 segment
|
|
|
|
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
|
|
|
|
bufUsedSet(walBuffer2, bufSize(walBuffer2));
|
|
|
|
memset(bufPtr(walBuffer2), 0x0C, bufSize(walBuffer2));
|
|
|
|
pgWalTestToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer2);
|
2020-07-30 07:49:06 -04:00
|
|
|
const char *walBuffer2Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer2)));
|
2019-03-29 13:26:33 +00:00
|
|
|
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/000000010000000100000002")), walBuffer2);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "--archive-push-queue-max=1gb");
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePushAsync(), "push WAL segments");
|
|
|
|
harnessLogResult(
|
|
|
|
"P00 INFO: push 1 WAL file(s) to archive: 000000010000000100000002\n"
|
2019-04-09 11:08:27 -04:00
|
|
|
"P01 DETAIL: pushed WAL file '000000010000000100000002' to the archive");
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_BOOL(
|
2019-11-17 15:10:40 -05:00
|
|
|
storageExistsP(
|
2020-07-20 09:47:43 -04:00
|
|
|
storageTest, strNewFmt("repo/archive/test/9.4-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
2019-03-29 13:26:33 +00:00
|
|
|
true, "check repo for WAL 2 file");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(strLstSort(storageListP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"000000010000000100000001.ok|000000010000000100000002.ok", "check status files");
|
|
|
|
|
|
|
|
// Check that drop functionality works
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
// Remove status files
|
|
|
|
storagePathRemoveP(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_OUT_STR, .recurse = true);
|
2019-11-17 15:10:40 -05:00
|
|
|
storagePathCreateP(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_OUT_STR);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
argListTemp = strLstDup(argList);
|
|
|
|
strLstAddZ(argListTemp, "--archive-push-queue-max=16m");
|
2020-01-15 12:24:58 -07:00
|
|
|
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleAsync, argListTemp);
|
2019-03-29 13:26:33 +00:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePushAsync(), "push WAL segments");
|
|
|
|
harnessLogResult(
|
|
|
|
"P00 INFO: push 2 WAL file(s) to archive: 000000010000000100000001...000000010000000100000002\n"
|
|
|
|
"P00 WARN: dropped WAL file '000000010000000100000001' because archive queue exceeded 16MB\n"
|
|
|
|
"P00 WARN: dropped WAL file '000000010000000100000002' because archive queue exceeded 16MB");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strNewBuf(
|
|
|
|
storageGetP(storageNewReadP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")))),
|
2019-03-29 13:26:33 +00:00
|
|
|
"0\ndropped WAL file '000000010000000100000001' because archive queue exceeded 16MB", "check WAL 1 warning");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strNewBuf(
|
|
|
|
storageGetP(storageNewReadP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000002.ok")))),
|
2019-03-29 13:26:33 +00:00
|
|
|
"0\ndropped WAL file '000000010000000100000002' because archive queue exceeded 16MB", "check WAL 2 warning");
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
strLstJoin(strLstSort(storageListP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc), "|"),
|
2019-03-29 13:26:33 +00:00
|
|
|
"000000010000000100000001.ok|000000010000000100000002.ok", "check status files");
|
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
2018-01-17 15:52:00 -05:00
|
|
|
}
|