1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Add infrastructure for multiple compression type support.

Add compress-type option and deprecate compress option. Since the compress option is boolean it won't work with multiple compression types. Add logic to cfgLoadUpdateOption() to update compress-type if it is not set directly. The compress option should no longer be referenced outside the cfgLoadUpdateOption() function.

Add common/compress/helper module to contain interface functions that work with multiple compression types. Code outside this module should no longer call specific compression drivers, though it may be OK to reference a specific compression type using the new interface (e.g., saving backup history files in gz format).

Unit tests only test compression using the gz format because other formats may not be available in all builds. It is the job of integration tests to exercise all compression types.

Additional compression types will be added in future commits.
This commit is contained in:
David Steele
2020-03-06 14:41:03 -05:00
parent 02aa03d1a2
commit 438b957f9c
70 changed files with 1237 additions and 490 deletions

View File

@ -62,14 +62,14 @@ sub run
foreach my $rhRun
(
{vm => VM1, remote => false, s3 => true, encrypt => false, delta => true},
{vm => VM1, remote => true, s3 => false, encrypt => true, delta => false},
{vm => VM2, remote => false, s3 => false, encrypt => true, delta => true},
{vm => VM2, remote => true, s3 => true, encrypt => false, delta => false},
{vm => VM3, remote => false, s3 => false, encrypt => false, delta => true},
{vm => VM3, remote => true, s3 => true, encrypt => true, delta => false},
{vm => VM4, remote => false, s3 => false, encrypt => false, delta => false},
{vm => VM4, remote => true, s3 => true, encrypt => true, delta => true},
{vm => VM1, remote => false, s3 => true, encrypt => false, delta => true, compress => GZ},
{vm => VM1, remote => true, s3 => false, encrypt => true, delta => false, compress => GZ},
{vm => VM2, remote => false, s3 => false, encrypt => true, delta => true, compress => GZ},
{vm => VM2, remote => true, s3 => true, encrypt => false, delta => false, compress => GZ},
{vm => VM3, remote => false, s3 => false, encrypt => false, delta => true, compress => GZ},
{vm => VM3, remote => true, s3 => true, encrypt => true, delta => false, compress => GZ},
{vm => VM4, remote => false, s3 => false, encrypt => false, delta => false, compress => GZ},
{vm => VM4, remote => true, s3 => true, encrypt => true, delta => true, compress => GZ},
)
{
# Only run tests for this vm
@ -80,13 +80,14 @@ sub run
my $bS3 = $rhRun->{s3};
my $bEncrypt = $rhRun->{encrypt};
my $bDeltaBackup = $rhRun->{delta};
my $strCompressType = $rhRun->{compress};
# Increment the run, log, and decide whether this unit test should be run
if (!$self->begin("rmt ${bRemote}, s3 ${bS3}, enc ${bEncrypt}, delta ${bDeltaBackup}")) {next}
# Create hosts, file object, and config
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
true, $self->expect(), {bHostBackup => $bRemote, bCompress => false, bS3 => $bS3, bRepoEncrypt => $bEncrypt});
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bEncrypt, strCompressType => NONE});
# If S3 set process max to 2. This seems like the best place for parallel testing since it will help speed S3 processing
# without slowing down the other tests too much.
@ -114,6 +115,7 @@ sub run
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_BUFFER_SIZE} = 16384;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_CHECKSUM_PAGE} = JSON::PP::true;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS} = JSON::PP::false;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS_TYPE} = CFGOPTVAL_COMPRESS_TYPE_NONE;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS_LEVEL} = 3;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS_LEVEL_NETWORK} = $bRemote ? 1 : 3;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_HARDLINK} = JSON::PP::false;
@ -809,8 +811,15 @@ sub run
$strType = CFGOPTVAL_BACKUP_TYPE_DIFF;
# Enable compression to ensure a warning is raised
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_COMPRESS) => 'y'}});
# Enable compression to ensure a warning is raised (reset when gz to avoid log churn since it is the default)
if ($strCompressType eq GZ)
{
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_COMPRESS_TYPE) => undef}});
}
else
{
$oHostBackup->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_COMPRESS_TYPE) => $strCompressType}});
}
# Enable hardlinks (except for s3) to ensure a warning is raised
if (!$bS3)
@ -841,6 +850,7 @@ sub run
# Now the compression and hardlink changes will take effect
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS} = JSON::PP::true;
$oManifest{&MANIFEST_SECTION_BACKUP_OPTION}{&MANIFEST_KEY_COMPRESS_TYPE} = $strCompressType;
if (!$bS3)
{

View File

@ -44,14 +44,14 @@ sub run
foreach my $rhRun
(
{vm => VM1, remote => false, s3 => false, encrypt => false, compress => true, error => 0},
{vm => VM1, remote => true, s3 => true, encrypt => true, compress => false, error => 1},
{vm => VM2, remote => false, s3 => true, encrypt => false, compress => false, error => 0},
{vm => VM2, remote => true, s3 => false, encrypt => true, compress => true, error => 0},
{vm => VM3, remote => false, s3 => false, encrypt => true, compress => false, error => 0},
{vm => VM3, remote => true, s3 => true, encrypt => false, compress => true, error => 1},
{vm => VM4, remote => false, s3 => true, encrypt => true, compress => true, error => 0},
{vm => VM4, remote => true, s3 => false, encrypt => false, compress => false, error => 0},
{vm => VM1, remote => false, s3 => false, encrypt => false, compress => GZ, error => 0},
{vm => VM1, remote => true, s3 => true, encrypt => true, compress => GZ, error => 1},
{vm => VM2, remote => false, s3 => true, encrypt => false, compress => NONE, error => 0},
{vm => VM2, remote => true, s3 => false, encrypt => true, compress => GZ, error => 0},
{vm => VM3, remote => false, s3 => false, encrypt => true, compress => NONE, error => 0},
{vm => VM3, remote => true, s3 => true, encrypt => false, compress => GZ, error => 1},
{vm => VM4, remote => false, s3 => true, encrypt => true, compress => GZ, error => 0},
{vm => VM4, remote => true, s3 => false, encrypt => false, compress => NONE, error => 0},
)
{
# Only run tests for this vm
@ -61,20 +61,21 @@ sub run
my $bRemote = $rhRun->{remote};
my $bS3 = $rhRun->{s3};
my $bEncrypt = $rhRun->{encrypt};
my $bCompress = $rhRun->{compress};
my $strCompressType = $rhRun->{compress};
my $iError = $rhRun->{error};
# Increment the run, log, and decide whether this unit test should be run
if (!$self->begin("rmt ${bRemote}, cmp ${bCompress}, error " . ($iError ? 'connect' : 'version') . ", s3 ${bS3}, " .
"enc ${bEncrypt}")) {next}
if (!$self->begin(
"rmt ${bRemote}, cmp ${strCompressType}, error " . ($iError ? 'connect' : 'version') .
", s3 ${bS3}, enc ${bEncrypt}")) {next}
# Create hosts, file object, and config
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
true, $self->expect(), {bHostBackup => $bRemote, bCompress => $bCompress, bArchiveAsync => true, bS3 => $bS3,
bRepoEncrypt => $bEncrypt});
true, $self->expect(), {bHostBackup => $bRemote, strCompressType => $strCompressType, bArchiveAsync => true,
bS3 => $bS3, bRepoEncrypt => $bEncrypt});
# Create compression extension
my $strCompressExt = $bCompress ? qw{.} . COMPRESS_EXT : '';
my $strCompressExt = $strCompressType ne NONE ? ".${strCompressType}" : '';
# Create the wal path
my $strWalPath = $oHostDbMaster->dbBasePath() . '/pg_xlog';

View File

@ -40,15 +40,15 @@ sub archiveCheck
my $self = shift;
my $strArchiveFile = shift;
my $strArchiveChecksum = shift;
my $bCompress = shift;
my $strCompressType = shift;
my $strSpoolPath = shift;
# Build the archive name to check for at the destination
my $strArchiveCheck = PG_VERSION_94 . "-1/${strArchiveFile}-${strArchiveChecksum}";
if ($bCompress)
if (defined($strCompressType))
{
$strArchiveCheck .= '.gz';
$strArchiveCheck .= ".${strCompressType}";
}
my $oWait = waitInit(5);
@ -82,14 +82,14 @@ sub run
foreach my $rhRun
(
{vm => VM1, remote => false, s3 => false, encrypt => false},
{vm => VM1, remote => true, s3 => true, encrypt => true},
{vm => VM2, remote => false, s3 => true, encrypt => false},
{vm => VM2, remote => true, s3 => false, encrypt => true},
{vm => VM3, remote => false, s3 => false, encrypt => true},
{vm => VM3, remote => true, s3 => true, encrypt => false},
{vm => VM4, remote => false, s3 => true, encrypt => true},
{vm => VM4, remote => true, s3 => false, encrypt => false},
{vm => VM1, remote => false, s3 => false, encrypt => false, compress => GZ},
{vm => VM1, remote => true, s3 => true, encrypt => true, compress => GZ},
{vm => VM2, remote => false, s3 => true, encrypt => false, compress => GZ},
{vm => VM2, remote => true, s3 => false, encrypt => true, compress => GZ},
{vm => VM3, remote => false, s3 => false, encrypt => true, compress => GZ},
{vm => VM3, remote => true, s3 => true, encrypt => false, compress => GZ},
{vm => VM4, remote => false, s3 => true, encrypt => true, compress => GZ},
{vm => VM4, remote => true, s3 => false, encrypt => false, compress => GZ},
)
{
# Only run tests for this vm
@ -99,12 +99,13 @@ sub run
my $bRemote = $rhRun->{remote};
my $bS3 = $rhRun->{s3};
my $bEncrypt = $rhRun->{encrypt};
my $strCompressType = $rhRun->{compress};
if (!$self->begin("rmt ${bRemote}, s3 ${bS3}, enc ${bEncrypt}")) {next}
if (!$self->begin("rmt ${bRemote}, s3 ${bS3}, enc ${bEncrypt}, cmp ${strCompressType}")) {next}
# Create hosts, file object, and config
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup) = $self->setup(
true, $self->expect(), {bHostBackup => $bRemote, bCompress => false, bS3 => $bS3, bRepoEncrypt => $bEncrypt});
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bEncrypt, strCompressType => NONE});
# Reduce console logging to detail
$oHostDbMaster->configUpdate({&CFGDEF_SECTION_GLOBAL => {cfgOptionName(CFGOPT_LOG_LEVEL_CONSOLE) => lc(DETAIL)}});
@ -153,12 +154,13 @@ sub run
my $strArchiveFile = $self->walGenerate($strWalPath, PG_VERSION_94, 2, $strSourceFile);
$oHostDbMaster->executeSimple(
$strCommandPush . ($bRemote ? ' --cmd-ssh=/usr/bin/ssh' : '') . " --compress ${strWalPath}/${strSourceFile}",
$strCommandPush . ($bRemote ? ' --cmd-ssh=/usr/bin/ssh' : '') .
" --compress-type=${strCompressType} ${strWalPath}/${strSourceFile}",
{oLogTest => $self->expect()});
push(@stryExpectedWAL, "${strSourceFile}-${strArchiveChecksum}.gz");
push(@stryExpectedWAL, "${strSourceFile}-${strArchiveChecksum}.${strCompressType}");
# Test that the WAL was pushed
$self->archiveCheck($strSourceFile, $strArchiveChecksum, true);
$self->archiveCheck($strSourceFile, $strArchiveChecksum, $strCompressType);
# Remove from archive_status
storageTest()->remove("${strWalPath}/archive_status/${strSourceFile}.ready");
@ -211,7 +213,7 @@ sub run
$strArchiveTmp =
$oHostBackup->repoPath() . '/archive/' . $self->stanza() . '/' . PG_VERSION_94 . '-1/' .
substr($strSourceFile, 0, 16) . "/${strSourceFile}-${strArchiveChecksum}." . COMPRESS_EXT . qw{.} .
substr($strSourceFile, 0, 16) . "/${strSourceFile}-${strArchiveChecksum}.${strCompressType}" . qw{.} .
STORAGE_TEMP_EXT;
storageTest()->put($strArchiveTmp, 'JUNK');
@ -219,9 +221,10 @@ sub run
# Push the WAL
$oHostDbMaster->executeSimple(
"${strCommandPush} --compress --archive-async --process-max=2 ${strWalPath}/${strSourceFile}",
"${strCommandPush} --compress-type=${strCompressType} --archive-async --process-max=2" .
" ${strWalPath}/${strSourceFile}",
{oLogTest => $self->expect()});
push(@stryExpectedWAL, "${strSourceFile}-${strArchiveChecksum}." . COMPRESS_EXT);
push(@stryExpectedWAL, "${strSourceFile}-${strArchiveChecksum}.${strCompressType}");
# Make sure the temp file no longer exists if it was created
if (defined($strArchiveTmp))
@ -242,7 +245,7 @@ sub run
}
# Test that the WAL was pushed
$self->archiveCheck($strSourceFile, $strArchiveChecksum, true, $oHostDbMaster->spoolPath());
$self->archiveCheck($strSourceFile, $strArchiveChecksum, $strCompressType, $oHostDbMaster->spoolPath());
# Remove from archive_status
storageTest()->remove("${strWalPath}/archive_status/${strSourceFile}.ready");
@ -381,7 +384,7 @@ sub run
$oHostDbMaster->executeSimple(
$strCommandPush . " ${strWalPath}/${strSourceFile}.partial",
{oLogTest => $self->expect()});
$self->archiveCheck("${strSourceFile}.partial", $strArchiveChecksum, false);
$self->archiveCheck("${strSourceFile}.partial", $strArchiveChecksum);
push(@stryExpectedWAL, "${strSourceFile}.partial-${strArchiveChecksum}");
@ -390,8 +393,7 @@ sub run
$oHostDbMaster->executeSimple(
$strCommandPush . " ${strWalPath}/${strSourceFile}.partial", {oLogTest => $self->expect()});
$self->archiveCheck(
"${strSourceFile}.partial", $strArchiveChecksum, false);
$self->archiveCheck("${strSourceFile}.partial", $strArchiveChecksum);
#---------------------------------------------------------------------------------------------------------------------------
&log(INFO, ' .partial WAL with different checksum');

View File

@ -53,14 +53,14 @@ sub run
foreach my $rhRun
(
{vm => VM1, remote => false, s3 => false, encrypt => true},
{vm => VM1, remote => true, s3 => true, encrypt => false},
{vm => VM2, remote => false, s3 => true, encrypt => true},
{vm => VM2, remote => true, s3 => false, encrypt => false},
{vm => VM3, remote => false, s3 => false, encrypt => false},
{vm => VM3, remote => true, s3 => true, encrypt => true},
{vm => VM4, remote => false, s3 => true, encrypt => false},
{vm => VM4, remote => true, s3 => false, encrypt => true},
{vm => VM1, remote => false, s3 => false, encrypt => true, compress => GZ},
{vm => VM1, remote => true, s3 => true, encrypt => false, compress => GZ},
{vm => VM2, remote => false, s3 => true, encrypt => true, compress => GZ},
{vm => VM2, remote => true, s3 => false, encrypt => false, compress => GZ},
{vm => VM3, remote => false, s3 => false, encrypt => false, compress => GZ},
{vm => VM3, remote => true, s3 => true, encrypt => true, compress => GZ},
{vm => VM4, remote => false, s3 => true, encrypt => false, compress => GZ},
{vm => VM4, remote => true, s3 => false, encrypt => true, compress => GZ},
)
{
# Only run tests for this vm
@ -70,13 +70,15 @@ sub run
my $bRemote = $rhRun->{remote};
my $bS3 = $rhRun->{s3};
my $bEncrypt = $rhRun->{encrypt};
my $strCompressType = $rhRun->{compress};
# Increment the run, log, and decide whether this unit test should be run
if (!$self->begin("remote ${bRemote}, s3 ${bS3}, enc ${bEncrypt}")) {next}
if (!$self->begin("remote ${bRemote}, s3 ${bS3}, enc ${bEncrypt}, cmp ${strCompressType}")) {next}
# Create hosts, file object, and config
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oHostS3) = $self->setup(
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bEncrypt});
true, $self->expect(), {bHostBackup => $bRemote, bS3 => $bS3, bRepoEncrypt => $bEncrypt,
strCompressType => $strCompressType});
# Create the stanza
$oHostBackup->stanzaCreate('fail on missing control file', {iExpectedExitStatus => ERROR_FILE_MISSING,
@ -192,7 +194,7 @@ sub run
$oHostDbMaster->archivePush($strWalPath, $strArchiveTestFile, 1);
$self->testResult(
sub {storageRepo()->list(STORAGE_REPO_ARCHIVE . qw{/} . PG_VERSION_94 . '-2/0000000100000001')},
'000000010000000100000001-' . $self->walGenerateContentChecksum(PG_VERSION_94) . '.' . COMPRESS_EXT,
'000000010000000100000001-' . $self->walGenerateContentChecksum(PG_VERSION_94) . ".${strCompressType}",
'check that WAL is in the archive at -2');
# Create the tablespace directory and perform a backup