2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-01-05 01:31:16 +02:00
|
|
|
# FullCommonTest.pm - Common code for backup tests
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-05-12 22:43:04 +02:00
|
|
|
package pgBackRestTest::Env::HostEnvTest;
|
|
|
|
use parent 'pgBackRestTest::Env::ConfigEnvTest';
|
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-06-09 23:51:41 +02:00
|
|
|
use Storable qw(dclone);
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
use pgBackRest::Archive::Common;
|
2016-08-24 18:39:27 +02:00
|
|
|
use pgBackRest::Common::Log;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRest::Config::Config;
|
2017-11-19 03:02:54 +02:00
|
|
|
use pgBackRest::DbVersion;
|
2018-06-11 20:52:26 +02:00
|
|
|
use pgBackRest::LibC qw(:crypto);
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostBaseTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostDbCommonTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostDbTest;
|
|
|
|
use pgBackRestTest::Env::Host::HostDbSyntheticTest;
|
2017-06-12 16:52:32 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostS3Test;
|
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::HostGroupTest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-12-23 15:22:59 +02:00
|
|
|
# Constants
|
|
|
|
####################################################################################################################################
|
2017-11-06 19:51:12 +02:00
|
|
|
use constant ENCRYPTION_KEY_ARCHIVE => 'archive';
|
|
|
|
push @EXPORT, qw(ENCRYPTION_KEY_ARCHIVE);
|
|
|
|
use constant ENCRYPTION_KEY_MANIFEST => 'manifest';
|
|
|
|
push @EXPORT, qw(ENCRYPTION_KEY_MANIFEST);
|
|
|
|
use constant ENCRYPTION_KEY_BACKUPSET => 'backupset';
|
|
|
|
push @EXPORT, qw(ENCRYPTION_KEY_BACKUPSET);
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# setup
|
|
|
|
####################################################################################################################################
|
|
|
|
sub setup
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-06-24 14:12:58 +02:00
|
|
|
my $bSynthetic = shift;
|
|
|
|
my $oLogTest = shift;
|
|
|
|
my $oConfigParam = shift;
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
# Start S3 server first since it takes the longest
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $oHostS3;
|
|
|
|
|
|
|
|
if ($oConfigParam->{bS3})
|
|
|
|
{
|
|
|
|
$oHostS3 = new pgBackRestTest::Env::Host::HostS3Test();
|
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
# Get host group
|
|
|
|
my $oHostGroup = hostGroupGet();
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Create the backup host
|
|
|
|
my $strBackupDestination;
|
|
|
|
my $bHostBackup = defined($$oConfigParam{bHostBackup}) ? $$oConfigParam{bHostBackup} : false;
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oHostBackup = undef;
|
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
my $bRepoEncrypt = defined($$oConfigParam{bRepoEncrypt}) ? $$oConfigParam{bRepoEncrypt} : false;
|
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
if ($bHostBackup)
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
$strBackupDestination = defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_BACKUP;
|
|
|
|
|
2017-05-12 22:43:04 +02:00
|
|
|
$oHostBackup = new pgBackRestTest::Env::Host::HostBackupTest(
|
2017-06-12 16:52:32 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, bSynthetic => $bSynthetic, oLogTest => $oLogTest,
|
2017-11-06 19:51:12 +02:00
|
|
|
bRepoLocal => !$oConfigParam->{bS3}, bRepoEncrypt => $bRepoEncrypt});
|
2016-06-24 14:12:58 +02:00
|
|
|
$oHostGroup->hostAdd($oHostBackup);
|
|
|
|
}
|
2016-08-24 18:39:27 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$strBackupDestination =
|
|
|
|
defined($$oConfigParam{strBackupDestination}) ? $$oConfigParam{strBackupDestination} : HOST_DB_MASTER;
|
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2016-08-24 18:39:27 +02:00
|
|
|
# Create the db-master host
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oHostDbMaster = undef;
|
|
|
|
|
|
|
|
if ($bSynthetic)
|
|
|
|
{
|
2017-05-12 22:43:04 +02:00
|
|
|
$oHostDbMaster = new pgBackRestTest::Env::Host::HostDbSyntheticTest(
|
2017-11-06 19:51:12 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest, bRepoLocal => !$oConfigParam->{bS3},
|
|
|
|
bRepoEncrypt => $bRepoEncrypt});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-12 22:43:04 +02:00
|
|
|
$oHostDbMaster = new pgBackRestTest::Env::Host::HostDbTest(
|
2017-11-06 19:51:12 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, oLogTest => $oLogTest, bRepoLocal => !$oConfigParam->{bS3},
|
|
|
|
bRepoEncrypt => $bRepoEncrypt});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$oHostGroup->hostAdd($oHostDbMaster);
|
2016-08-24 18:39:27 +02:00
|
|
|
|
|
|
|
# Create the db-standby host
|
|
|
|
my $oHostDbStandby = undef;
|
|
|
|
|
|
|
|
if (defined($$oConfigParam{bStandby}) && $$oConfigParam{bStandby})
|
|
|
|
{
|
2017-05-12 22:43:04 +02:00
|
|
|
$oHostDbStandby = new pgBackRestTest::Env::Host::HostDbTest(
|
2017-06-12 16:52:32 +02:00
|
|
|
{strBackupDestination => $strBackupDestination, bStandby => true, oLogTest => $oLogTest,
|
|
|
|
bRepoLocal => !$oConfigParam->{bS3}});
|
2016-08-24 18:39:27 +02:00
|
|
|
|
|
|
|
$oHostGroup->hostAdd($oHostDbStandby);
|
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
# Finalize S3 server
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (defined($oHostS3))
|
|
|
|
{
|
|
|
|
$oHostGroup->hostAdd($oHostS3, {rstryHostName => ['pgbackrest-dev.s3.amazonaws.com', 's3.amazonaws.com']});
|
|
|
|
}
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
# Create db master config
|
2016-08-24 18:39:27 +02:00
|
|
|
$oHostDbMaster->configCreate({
|
|
|
|
strBackupSource => $$oConfigParam{strBackupSource},
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
|
|
|
bHardlink => $bHostBackup ? undef : $$oConfigParam{bHardLink},
|
2017-06-12 16:52:32 +02:00
|
|
|
bArchiveAsync => $$oConfigParam{bArchiveAsync},
|
|
|
|
bS3 => $$oConfigParam{bS3}});
|
2016-08-24 18:39:27 +02:00
|
|
|
|
|
|
|
# Create backup config if backup host exists
|
|
|
|
if (defined($oHostBackup))
|
|
|
|
{
|
|
|
|
$oHostBackup->configCreate({
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
2017-06-12 16:52:32 +02:00
|
|
|
bHardlink => $$oConfigParam{bHardLink},
|
|
|
|
bS3 => $$oConfigParam{bS3}});
|
2016-08-24 18:39:27 +02:00
|
|
|
}
|
|
|
|
# If backup host is not defined set it to db-master
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oHostBackup = $strBackupDestination eq HOST_DB_MASTER ? $oHostDbMaster : $oHostDbStandby;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create db-standby config
|
|
|
|
if (defined($oHostDbStandby))
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2016-08-24 18:39:27 +02:00
|
|
|
$oHostDbStandby->configCreate({
|
|
|
|
strBackupSource => $$oConfigParam{strBackupSource},
|
|
|
|
bCompress => $$oConfigParam{bCompress},
|
|
|
|
bHardlink => $bHostBackup ? undef : $$oConfigParam{bHardLink},
|
|
|
|
bArchiveAsync => $$oConfigParam{bArchiveAsync}});
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Set options needed for storage helper
|
2018-02-04 01:27:38 +02:00
|
|
|
$self->optionTestSet(CFGOPT_PG_PATH, $oHostDbMaster->dbBasePath());
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_PATH, $oHostBackup->repoPath());
|
|
|
|
$self->optionTestSet(CFGOPT_STANZA, $self->stanza());
|
2017-06-12 16:52:32 +02:00
|
|
|
|
2017-11-06 19:51:12 +02:00
|
|
|
# Configure the repo to be encrypted if required
|
|
|
|
if ($bRepoEncrypt)
|
|
|
|
{
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_CIPHER_TYPE, CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_CIPHER_PASS, 'x');
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
# Set S3 options
|
|
|
|
if (defined($oHostS3))
|
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_TYPE, CFGOPTVAL_REPO_TYPE_S3);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_KEY, HOST_S3_ACCESS_KEY);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_KEY_SECRET, HOST_S3_ACCESS_SECRET_KEY);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_BUCKET, HOST_S3_BUCKET);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_ENDPOINT, HOST_S3_ENDPOINT);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_REGION, HOST_S3_REGION);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_HOST, $oHostS3->ipGet());
|
2019-05-21 16:14:41 +02:00
|
|
|
$self->optionTestSetBool(CFGOPT_REPO_S3_VERIFY_TLS, false);
|
2017-06-12 16:52:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2019-06-26 21:02:30 +02:00
|
|
|
# Create S3 bucket
|
|
|
|
if (defined($oHostS3))
|
|
|
|
{
|
|
|
|
storageRepo()->{oStorageC}->bucketCreate();
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
return $oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3;
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-11-19 03:02:54 +02:00
|
|
|
# Generate database system id for the db version
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-11-19 03:02:54 +02:00
|
|
|
sub dbSysId
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->dbSysId', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
return (1000000000000000000 + ($strPgVersion * 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Get database catalog version for the db version
|
|
|
|
####################################################################################################################################
|
|
|
|
sub dbCatalogVersion
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->sysId', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
my $hCatalogVersion =
|
|
|
|
{
|
|
|
|
&PG_VERSION_83 => 200711281,
|
|
|
|
&PG_VERSION_84 => 200904091,
|
|
|
|
&PG_VERSION_90 => 201008051,
|
|
|
|
&PG_VERSION_91 => 201105231,
|
|
|
|
&PG_VERSION_92 => 201204301,
|
|
|
|
&PG_VERSION_93 => 201306121,
|
|
|
|
&PG_VERSION_94 => 201409291,
|
|
|
|
&PG_VERSION_95 => 201510051,
|
|
|
|
&PG_VERSION_96 => 201608131,
|
|
|
|
&PG_VERSION_10 => 201707211,
|
2018-07-16 23:25:15 +02:00
|
|
|
&PG_VERSION_11 => 201806231,
|
2019-10-01 19:20:43 +02:00
|
|
|
&PG_VERSION_12 => 201909212,
|
2017-11-19 03:02:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!defined($hCatalogVersion->{$strPgVersion}))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "no catalog version defined for pg version ${strPgVersion}");
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
return $hCatalogVersion->{$strPgVersion};
|
|
|
|
}
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Get database control version for the db version
|
|
|
|
####################################################################################################################################
|
|
|
|
sub dbControlVersion
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->dbControlVersion', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
my $hControlVersion =
|
|
|
|
{
|
|
|
|
&PG_VERSION_83 => 833,
|
|
|
|
&PG_VERSION_84 => 843,
|
|
|
|
&PG_VERSION_90 => 903,
|
|
|
|
&PG_VERSION_91 => 903,
|
|
|
|
&PG_VERSION_92 => 922,
|
|
|
|
&PG_VERSION_93 => 937,
|
|
|
|
&PG_VERSION_94 => 942,
|
|
|
|
&PG_VERSION_95 => 942,
|
|
|
|
&PG_VERSION_96 => 960,
|
|
|
|
&PG_VERSION_10 => 1002,
|
2019-09-27 15:45:11 +02:00
|
|
|
&PG_VERSION_11 => 1100,
|
2019-10-01 19:20:43 +02:00
|
|
|
&PG_VERSION_12 => 1201,
|
2017-11-19 03:02:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!defined($hControlVersion->{$strPgVersion}))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "no control version defined for pg version ${strPgVersion}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hControlVersion->{$strPgVersion};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Generate control file content
|
|
|
|
####################################################################################################################################
|
|
|
|
sub controlGenerateContent
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->controlGenerateContent', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
my $tControlContent = pack('Q', $self->dbSysId($strPgVersion));
|
|
|
|
$tControlContent .= pack('L', $self->dbControlVersion($strPgVersion));
|
|
|
|
$tControlContent .= pack('L', $self->dbCatalogVersion($strPgVersion));
|
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Offset to page size by architecture bits and version
|
2018-09-25 11:24:42 +02:00
|
|
|
my $rhOffsetToPageSize =
|
|
|
|
{
|
|
|
|
32 =>
|
|
|
|
{
|
|
|
|
'8.3' => 96 - length($tControlContent),
|
|
|
|
'8.4' => 104 - length($tControlContent),
|
|
|
|
'9.0' => 140 - length($tControlContent),
|
|
|
|
'9.1' => 140 - length($tControlContent),
|
|
|
|
'9.2' => 156 - length($tControlContent),
|
|
|
|
'9.3' => 180 - length($tControlContent),
|
|
|
|
'9.4' => 188 - length($tControlContent),
|
|
|
|
'9.5' => 200 - length($tControlContent),
|
|
|
|
'9.6' => 200 - length($tControlContent),
|
|
|
|
'10' => 200 - length($tControlContent),
|
|
|
|
'11' => 192 - length($tControlContent),
|
2019-10-01 19:20:43 +02:00
|
|
|
'12' => 196 - length($tControlContent),
|
2018-09-25 11:24:42 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
64 =>
|
|
|
|
{
|
|
|
|
'8.3' => 112 - length($tControlContent),
|
|
|
|
'8.4' => 112 - length($tControlContent),
|
|
|
|
'9.0' => 152 - length($tControlContent),
|
|
|
|
'9.1' => 152 - length($tControlContent),
|
|
|
|
'9.2' => 168 - length($tControlContent),
|
|
|
|
'9.3' => 192 - length($tControlContent),
|
|
|
|
'9.4' => 200 - length($tControlContent),
|
|
|
|
'9.5' => 216 - length($tControlContent),
|
|
|
|
'9.6' => 216 - length($tControlContent),
|
|
|
|
'10' => 216 - length($tControlContent),
|
|
|
|
'11' => 208 - length($tControlContent),
|
2019-10-01 19:20:43 +02:00
|
|
|
'12' => 212 - length($tControlContent),
|
2018-09-25 11:24:42 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
# Fill up to page size and set page size
|
|
|
|
$tControlContent .= ('C' x $rhOffsetToPageSize->{$self->archBits()}{$strPgVersion});
|
|
|
|
$tControlContent .= pack('L', 8192);
|
|
|
|
|
|
|
|
# Fill up to wal segment size and set wal segment size
|
|
|
|
$tControlContent .= ('C' x 8);
|
|
|
|
$tControlContent .= pack('L', 16 * 1024 * 1024);
|
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Pad bytes
|
|
|
|
$tControlContent .= ('C' x (8192 - length($tControlContent)));
|
|
|
|
|
|
|
|
return \$tControlContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Generate control file and write to disk
|
|
|
|
####################################################################################################################################
|
|
|
|
sub controlGenerate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strDbPath,
|
|
|
|
$strPgVersion,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->controlGenerate', \@_,
|
|
|
|
{name => 'strDbPath', trace => true},
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
storageTest()->put("${strDbPath}/global/pg_control", $self->controlGenerateContent($strPgVersion));
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-01-27 18:02:27 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# walSegment
|
|
|
|
#
|
|
|
|
# Generate name of WAL segment from component parts.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walSegment
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $iTimeline = shift;
|
|
|
|
my $iMajor = shift;
|
|
|
|
my $iMinor = shift;
|
|
|
|
|
|
|
|
return uc(sprintf('%08x%08x%08x', $iTimeline, $iMajor, $iMinor));
|
|
|
|
}
|
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Generate WAL file content
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walGenerateContent
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
$iSourceNo,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->walGenerateContent', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
{name => 'iSourceNo', optional => true, default => 1, trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Get WAL magic for the PG version
|
|
|
|
my $hWalMagic =
|
|
|
|
{
|
|
|
|
&PG_VERSION_83 => hex('0xD062'),
|
|
|
|
&PG_VERSION_84 => hex('0xD063'),
|
|
|
|
&PG_VERSION_90 => hex('0xD064'),
|
|
|
|
&PG_VERSION_91 => hex('0xD066'),
|
|
|
|
&PG_VERSION_92 => hex('0xD071'),
|
|
|
|
&PG_VERSION_93 => hex('0xD075'),
|
|
|
|
&PG_VERSION_94 => hex('0xD07E'),
|
|
|
|
&PG_VERSION_95 => hex('0xD087'),
|
|
|
|
&PG_VERSION_96 => hex('0xD093'),
|
|
|
|
&PG_VERSION_10 => hex('0xD097'),
|
2019-09-27 15:45:11 +02:00
|
|
|
&PG_VERSION_11 => hex('0xD098'),
|
2019-10-01 19:20:43 +02:00
|
|
|
&PG_VERSION_12 => hex('0xD101'),
|
2017-11-19 03:02:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
my $tWalContent = pack('S', $hWalMagic->{$strPgVersion});
|
|
|
|
|
|
|
|
# Indicate that the long header is present
|
|
|
|
$tWalContent .= pack('S', 2);
|
|
|
|
|
|
|
|
# Add junk (H for header) for the bytes that won't be read by the tests
|
2017-11-19 03:14:14 +02:00
|
|
|
my $iOffset = 12 + ($strPgVersion >= PG_VERSION_93 ? testRunGet()->archBits() / 8 : 0);
|
2017-11-19 03:02:54 +02:00
|
|
|
$tWalContent .= ('H' x $iOffset);
|
|
|
|
|
|
|
|
# Add the system identifier
|
|
|
|
$tWalContent .= pack('Q', $self->dbSysId($strPgVersion));
|
|
|
|
|
|
|
|
# Add the source number to produce WAL segments with different checksums
|
|
|
|
$tWalContent .= pack('S', $iSourceNo);
|
|
|
|
|
|
|
|
# Pad out to the required size (B for body)
|
|
|
|
$tWalContent .= ('B' x (PG_WAL_SEGMENT_SIZE - length($tWalContent)));
|
|
|
|
|
|
|
|
return \$tWalContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Generate WAL file content checksum
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walGenerateContentChecksum
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strPgVersion,
|
|
|
|
$hParam,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->walGenerateContent', \@_,
|
|
|
|
{name => 'strPgVersion', trace => true},
|
|
|
|
{name => 'hParam', required => false, trace => true},
|
|
|
|
);
|
|
|
|
|
2018-06-11 20:52:26 +02:00
|
|
|
return cryptoHashOne('sha1', ${$self->walGenerateContent($strPgVersion, $hParam)});
|
2017-11-19 03:02:54 +02:00
|
|
|
}
|
|
|
|
|
2017-01-27 18:02:27 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# walGenerate
|
|
|
|
#
|
|
|
|
# Generate a WAL segment and ready file for testing.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walGenerate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strWalPath = shift;
|
|
|
|
my $strPgVersion = shift;
|
|
|
|
my $iSourceNo = shift;
|
|
|
|
my $strWalSegment = shift;
|
|
|
|
my $bPartial = shift;
|
2018-04-30 23:27:39 +02:00
|
|
|
my $bChecksum = shift;
|
|
|
|
my $bReady = shift;
|
2017-01-27 18:02:27 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
my $rtWalContent = $self->walGenerateContent($strPgVersion, {iSourceNo => $iSourceNo});
|
2018-04-30 23:27:39 +02:00
|
|
|
my $strWalFile =
|
2018-06-11 20:52:26 +02:00
|
|
|
"${strWalPath}/${strWalSegment}" . ($bChecksum ? '-' . cryptoHashOne('sha1', $rtWalContent) : '') .
|
2018-04-30 23:27:39 +02:00
|
|
|
(defined($bPartial) && $bPartial ? '.partial' : '');
|
2017-01-27 18:02:27 +02:00
|
|
|
|
2017-11-19 03:02:54 +02:00
|
|
|
# Put the WAL segment and the ready file
|
|
|
|
storageTest()->put($strWalFile, $rtWalContent);
|
2018-04-30 23:27:39 +02:00
|
|
|
|
|
|
|
if (!defined($bReady) || $bReady)
|
|
|
|
{
|
|
|
|
storageTest()->put("${strWalPath}/archive_status/${strWalSegment}.ready");
|
|
|
|
}
|
2017-01-27 18:02:27 +02:00
|
|
|
|
|
|
|
return $strWalFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# walRemove
|
|
|
|
#
|
|
|
|
# Remove WAL file and ready file.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub walRemove
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strWalPath = shift;
|
|
|
|
my $strWalFile = shift;
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->remove("$self->{strWalPath}/${strWalFile}");
|
|
|
|
storageTest()->remove("$self->{strWalPath}/archive_status/${strWalFile}.ready");
|
2017-01-27 18:02:27 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
1;
|