2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-01-05 01:31:16 +02:00
|
|
|
# ArchiveStopTest.pm - Tests for archive-push command to make sure aync queue limits are implemented correctly
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-05-12 22:43:04 +02:00
|
|
|
package pgBackRestTest::Module::Archive::ArchiveStopTest;
|
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
|
2017-06-21 14:02:21 +02:00
|
|
|
use pgBackRest::Archive::Info;
|
2017-05-15 22:01:00 +02:00
|
|
|
use pgBackRest::Backup::Info;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRest::DbVersion;
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::Manifest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
use pgBackRest::Storage::Helper;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate test WAL file
|
|
|
|
my $strWalTestFile = $self->testPath() . '/test-wal-' . PG_VERSION_94;
|
|
|
|
my $strWalHash = $self->walGenerateContentChecksum(PG_VERSION_94);
|
|
|
|
storageTest()->put($strWalTestFile, $self->walGenerateContent(PG_VERSION_94));
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bS3 (false, true)
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bRemote ($bS3 ? (true) : (false, true))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-06-12 16:52:32 +02:00
|
|
|
foreach my $bCompress ($bS3 ? (false) : (false, true))
|
|
|
|
{
|
|
|
|
foreach my $iError ($bS3 ? (1) : ($bRemote ? (0, 1) : (0)))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-11-06 19:51:12 +02:00
|
|
|
my $bRepoEncrypt = ($bCompress && !$bS3) ? true : false;
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2017-11-06 19:51:12 +02:00
|
|
|
if (!$self->begin("rmt ${bRemote}, cmp ${bCompress}, error " . ($iError ? 'connect' : 'version') . ", s3 ${bS3}, " .
|
|
|
|
"enc ${bRepoEncrypt}")) {next}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create hosts, file object, and config
|
2017-06-12 16:52:32 +02:00
|
|
|
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
|
2017-11-06 19:51:12 +02:00
|
|
|
true, $self->expect(), {bHostBackup => $bRemote, bCompress => $bCompress, bArchiveAsync => true, bS3 => $bS3,
|
|
|
|
bRepoEncrypt => $bRepoEncrypt});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
my $oStorage = storageRepo();
|
|
|
|
|
2017-03-02 18:47:23 +02:00
|
|
|
# Create compression extension
|
2017-06-09 23:51:41 +02:00
|
|
|
my $strCompressExt = $bCompress ? qw{.} . COMPRESS_EXT : '';
|
2017-03-02 18:47:23 +02:00
|
|
|
|
2017-09-01 18:29:34 +02:00
|
|
|
# Create the wal path
|
|
|
|
my $strWalPath = $oHostDbMaster->dbBasePath() . '/pg_xlog';
|
|
|
|
$oStorage->pathCreate($strWalPath, {bCreateParent => true});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Create the test path for pg_control and generate pg_control for stanza-create
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($oHostDbMaster->dbBasePath() . '/' . DB_PATH_GLOBAL, {bCreateParent => true});
|
2017-11-19 03:02:54 +02:00
|
|
|
$self->controlGenerate($oHostDbMaster->dbBasePath(), PG_VERSION_94);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Create the archive info file
|
2017-08-25 22:47:47 +02:00
|
|
|
$oHostBackup->stanzaCreate('create required data for stanza', {strOptionalParam => '--no-' . cfgOptionName(CFGOPT_ONLINE)});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Push a WAL segment
|
2017-11-19 03:02:54 +02:00
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strWalTestFile, 1);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Break the database version of the archive info file
|
|
|
|
if ($iError == 0)
|
|
|
|
{
|
|
|
|
$oHostBackup->infoMunge(
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorage->pathGet(STORAGE_REPO_ARCHIVE . qw{/} . ARCHIVE_INFO_FILE),
|
2016-12-23 15:22:59 +02:00
|
|
|
{&INFO_ARCHIVE_SECTION_DB => {&INFO_ARCHIVE_KEY_DB_VERSION => '8.0'}});
|
|
|
|
}
|
|
|
|
|
2017-11-28 03:43:44 +02:00
|
|
|
# Push two more segments with errors to exceed archive-queue-max
|
2016-12-23 15:22:59 +02:00
|
|
|
$oHostDbMaster->archivePush(
|
2017-11-19 03:02:54 +02:00
|
|
|
$strWalPath, $strWalTestFile, 2, $iError ? ERROR_FILE_READ : ERROR_ARCHIVE_MISMATCH);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
$oHostDbMaster->archivePush(
|
2017-11-19 03:02:54 +02:00
|
|
|
$strWalPath, $strWalTestFile, 3, $iError ? ERROR_FILE_READ : ERROR_ARCHIVE_MISMATCH);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Now this segment will get dropped
|
2017-11-19 03:02:54 +02:00
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strWalTestFile, 4);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
# Fix the database version
|
|
|
|
if ($iError == 0)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
$oHostBackup->infoRestore($oStorage->pathGet(STORAGE_REPO_ARCHIVE . qw{/} . ARCHIVE_INFO_FILE));
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
2017-03-02 18:47:23 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$self->testResult(
|
2017-06-09 23:51:41 +02:00
|
|
|
sub {$oStorage->list(
|
|
|
|
STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_94 . '-1/0000000100000001',
|
|
|
|
{strExpression => '^(?!000000010000000100000002).+'})},
|
2017-11-19 03:02:54 +02:00
|
|
|
"000000010000000100000001-${strWalHash}${strCompressExt}",
|
2017-04-05 16:50:32 +02:00
|
|
|
'segment 2-4 not pushed (2 is pushed sometimes when remote but ignore)', {iWaitSeconds => 5});
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-03-02 18:47:23 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-11-19 03:02:54 +02:00
|
|
|
$oHostDbMaster->archivePush($strWalPath, $strWalTestFile, 5);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-03-02 18:47:23 +02:00
|
|
|
$self->testResult(
|
2017-06-09 23:51:41 +02:00
|
|
|
sub {$oStorage->list(
|
|
|
|
STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_94 . '-1/0000000100000001',
|
|
|
|
{strExpression => '^(?!000000010000000100000002).+'})},
|
2017-11-19 03:02:54 +02:00
|
|
|
"(000000010000000100000001-${strWalHash}${strCompressExt}, " .
|
|
|
|
"000000010000000100000005-${strWalHash}${strCompressExt})",
|
2017-04-05 16:50:32 +02:00
|
|
|
'segment 5 is pushed', {iWaitSeconds => 5});
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|