2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# HostDbTest.pm - Database host
|
|
|
|
####################################################################################################################################
|
2017-05-12 22:43:04 +02:00
|
|
|
package pgBackRestTest::Env::Host::HostDbCommonTest;
|
|
|
|
use parent 'pgBackRestTest::Env::Host::HostBackupTest';
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
2017-04-10 19:24:45 +02:00
|
|
|
use File::Basename qw(dirname);
|
2016-12-10 16:11:12 +02:00
|
|
|
use Storable qw(dclone);
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
2016-08-12 04:35:24 +02:00
|
|
|
use pgBackRest::DbVersion;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRest::Manifest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRest::Version;
|
|
|
|
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostBaseTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::HostGroupTest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2018-10-27 21:00:00 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Test WAL size
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant PG_WAL_SIZE_TEST => 16777216;
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2016-12-23 15:22:59 +02:00
|
|
|
# Host defaults
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2016-06-24 16:54:31 +02:00
|
|
|
use constant HOST_PATH_SPOOL => 'spool';
|
2016-06-24 14:12:58 +02:00
|
|
|
use constant HOST_PATH_DB => 'db';
|
2016-06-24 16:54:31 +02:00
|
|
|
use constant HOST_PATH_DB_BASE => 'base';
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# new
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oParam,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->new', \@_,
|
|
|
|
{name => 'oParam', required => false, trace => true},
|
|
|
|
);
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Get host group
|
|
|
|
my $oHostGroup = hostGroupGet();
|
|
|
|
|
|
|
|
# Is standby?
|
|
|
|
my $bStandby = defined($$oParam{bStandby}) && $$oParam{bStandby} ? true : false;
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
my $self = $class->SUPER::new(
|
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
strName => $bStandby ? HOST_DB_STANDBY : HOST_DB_MASTER,
|
2016-06-24 14:12:58 +02:00
|
|
|
strImage => $$oParam{strImage},
|
2016-08-24 18:39:27 +02:00
|
|
|
strBackupDestination => $$oParam{strBackupDestination},
|
2016-06-24 14:12:58 +02:00
|
|
|
oLogTest => $$oParam{oLogTest},
|
|
|
|
bSynthetic => $$oParam{bSynthetic},
|
2017-06-12 16:52:32 +02:00
|
|
|
bRepoLocal => $oParam->{bRepoLocal},
|
2017-11-06 19:51:12 +02:00
|
|
|
bRepoEncrypt => $oParam->{bRepoEncrypt},
|
2016-06-24 14:12:58 +02:00
|
|
|
});
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Set parameters
|
2016-08-24 18:39:27 +02:00
|
|
|
$self->{bStandby} = $bStandby;
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
$self->{strDbPath} = $self->testPath() . '/' . HOST_PATH_DB;
|
|
|
|
$self->{strDbBasePath} = $self->dbPath() . '/' . HOST_PATH_DB_BASE;
|
|
|
|
$self->{strTablespacePath} = $self->dbPath() . '/tablespace';
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($self->dbBasePath(), {strMode => '0700', bCreateParent => true});
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$self->{strSpoolPath} = $self->testPath() . '/' . HOST_PATH_SPOOL;
|
|
|
|
storageTest()->pathCreate($self->spoolPath());
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Initialize linkRemap Hashes
|
|
|
|
$self->{hLinkRemap} = {};
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# archivePush
|
|
|
|
####################################################################################################################################
|
|
|
|
sub archivePush
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2017-09-01 18:29:34 +02:00
|
|
|
$strWalPath,
|
2016-06-24 14:12:58 +02:00
|
|
|
$strArchiveTestFile,
|
|
|
|
$iArchiveNo,
|
|
|
|
$iExpectedError,
|
2016-11-17 16:39:21 +02:00
|
|
|
$bAsync,
|
2018-10-27 17:57:57 +02:00
|
|
|
$strOptionalParam,
|
2016-06-24 14:12:58 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->archivePush', \@_,
|
2017-09-01 18:29:34 +02:00
|
|
|
{name => 'strWalPath'},
|
2016-11-17 16:39:21 +02:00
|
|
|
{name => 'strArchiveTestFile', required => false},
|
|
|
|
{name => 'iArchiveNo', required => false},
|
2016-06-24 14:12:58 +02:00
|
|
|
{name => 'iExpectedError', required => false},
|
2016-11-17 16:39:21 +02:00
|
|
|
{name => 'bAsync', default => true},
|
2018-10-27 17:57:57 +02:00
|
|
|
{name => 'strOptionalParam', required => false},
|
2016-06-24 14:12:58 +02:00
|
|
|
);
|
|
|
|
|
2016-11-17 16:39:21 +02:00
|
|
|
my $strSourceFile;
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2016-11-17 16:39:21 +02:00
|
|
|
if (defined($strArchiveTestFile))
|
|
|
|
{
|
2017-09-01 18:29:34 +02:00
|
|
|
$strSourceFile = "${strWalPath}/" . uc(sprintf('0000000100000001%08x', $iArchiveNo));
|
2016-11-17 16:39:21 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->copy($strArchiveTestFile, storageTest()->openWrite($strSourceFile, {bPathCreate => true}));
|
2017-01-27 18:02:27 +02:00
|
|
|
|
2017-09-01 18:29:34 +02:00
|
|
|
storageTest()->pathCreate("${strWalPath}/archive_status/", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
storageTest()->put("${strWalPath}/archive_status/" . uc(sprintf('0000000100000001%08x', $iArchiveNo)) . '.ready');
|
2016-11-17 16:39:21 +02:00
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
$self->executeSimple(
|
|
|
|
$self->backrestExe() .
|
|
|
|
' --config=' . $self->backrestConfig() .
|
2018-10-27 21:00:00 +02:00
|
|
|
' --log-level-console=warn --archive-push-queue-max=' . int(2 * PG_WAL_SIZE_TEST) .
|
2017-01-27 18:02:27 +02:00
|
|
|
' --stanza=' . $self->stanza() .
|
2019-03-29 15:26:33 +02:00
|
|
|
(defined($iExpectedError) && $iExpectedError == ERROR_UNKNOWN ? ' --repo1-host=bogus' : '') .
|
2016-11-17 16:39:21 +02:00
|
|
|
($bAsync ? '' : ' --no-archive-async') .
|
2018-10-27 17:57:57 +02:00
|
|
|
" archive-push" . (defined($strSourceFile) ? " ${strSourceFile}" : '') .
|
|
|
|
(defined($strOptionalParam) ? " ${strOptionalParam}" : ''),
|
2016-08-24 18:39:27 +02:00
|
|
|
{iExpectedExitStatus => $iExpectedError, oLogTest => $self->{oLogTest}, bLogOutput => $self->synthetic()});
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# linkRemap
|
|
|
|
####################################################################################################################################
|
|
|
|
sub linkRemap
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strTarget,
|
|
|
|
$strDestination
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->linkRemap', \@_,
|
|
|
|
{name => 'strTarget'},
|
|
|
|
{name => 'strDestination'},
|
|
|
|
);
|
|
|
|
|
|
|
|
${$self->{hLinkRemap}}{$strTarget} = $strDestination;
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Getters
|
|
|
|
####################################################################################################################################
|
2016-12-23 15:22:59 +02:00
|
|
|
sub dbPath {return shift->{strDbPath};}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
sub dbBasePath
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $iIndex = shift;
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
return $self->{strDbBasePath} . (defined($iIndex) ? "-${iIndex}" : '');
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
sub spoolPath {return shift->{strSpoolPath}}
|
2016-08-24 18:39:27 +02:00
|
|
|
sub standby {return shift->{bStandby}}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
sub tablespacePath
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $iTablespace = shift;
|
|
|
|
my $iIndex = shift;
|
|
|
|
|
|
|
|
return
|
2016-12-23 15:22:59 +02:00
|
|
|
$self->{strTablespacePath} .
|
2016-06-24 14:12:58 +02:00
|
|
|
(defined($iTablespace) ? "/ts${iTablespace}" .
|
|
|
|
(defined($iIndex) ? "-${iIndex}" : '') : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|