Add PG_TEST_PG_COMBINEBACKUP_MODE
authorTomas Vondra <[email protected]>
Sun, 30 Jun 2024 17:26:12 +0000 (19:26 +0200)
committerTomas Vondra <[email protected]>
Sun, 30 Jun 2024 18:53:39 +0000 (20:53 +0200)
Introduces an environment variable PG_TEST_PG_COMBINEBACKUP_MODE, that
determines copy mode used by pg_combinebackup in TAP tests. Defaults to
"--copy" but may be set to "--clone" or "--copy-file-range" to use the
alternative stategies.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/48da4a1f-ccd9-4988-9622-24f37b1de2b4%40eisentraut.org

src/bin/pg_combinebackup/t/002_compare_backups.pl
src/bin/pg_combinebackup/t/003_timeline.pl
src/bin/pg_combinebackup/t/004_manifest.pl
src/bin/pg_combinebackup/t/005_integrity.pl
src/bin/pg_combinebackup/t/006_db_file_copy.pl
src/test/perl/PostgreSQL/Test/Cluster.pm

index f032959ef5c47c277beda1c54c8b15e0d4fe4fb8..63a0255de15224fb48827db3decbbfeea5458811 100644 (file)
@@ -9,6 +9,11 @@ use Test::More;
 
 my $tempdir = PostgreSQL::Test::Utils::tempdir_short();
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
+
+note "testing using mode $mode";
+
 # Set up a new database instance.
 my $primary = PostgreSQL::Test::Cluster->new('primary');
 $primary->init(has_archiving => 1, allows_streaming => 1);
@@ -134,7 +139,8 @@ $pitr2->init_from_backup(
    standby => 1,
    has_restoring => 1,
    combine_with_prior => ['backup1'],
-   tablespace_map => { $tsbackup2path => $tspitr2path });
+   tablespace_map => { $tsbackup2path => $tspitr2path },
+   combine_mode => $mode);
 $pitr2->append_conf(
    'postgresql.conf', qq{
 recovery_target_lsn = '$lsn'
index 52eb642a3922d473d6d38b42bbd05ec9d6dadc73..83ab674a2448f65ad54f375524cf0b8265cd672e 100644 (file)
@@ -10,6 +10,11 @@ use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
+
+note "testing using mode $mode";
+
 # Set up a new database instance.
 my $node1 = PostgreSQL::Test::Cluster->new('node1');
 $node1->init(has_archiving => 1, allows_streaming => 1);
@@ -68,7 +73,8 @@ $node2->command_ok(
 # Restore the incremental backup and use it to create a new node.
 my $node3 = PostgreSQL::Test::Cluster->new('node3');
 $node3->init_from_backup($node1, 'backup3',
-   combine_with_prior => [ 'backup1', 'backup2' ]);
+   combine_with_prior => [ 'backup1', 'backup2' ],
+   combine_mode => $mode);
 $node3->start();
 
 # Let's insert one more row.
index 0df9fed73a8ba846e5582cf29e46dacbce7e5248..6d475163ab9eaa887b09ba3295c95e7b4eabf8d1 100644 (file)
@@ -12,6 +12,11 @@ use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
+
+note "testing using mode $mode";
+
 # Set up a new database instance.
 my $node = PostgreSQL::Test::Cluster->new('node');
 $node->init(has_archiving => 1, allows_streaming => 1);
@@ -53,9 +58,9 @@ sub combine_and_test_one_backup
 combine_and_test_one_backup('nomanifest',
    qr/could not open file.*backup_manifest/,
    '--no-manifest');
-combine_and_test_one_backup('csum_none', undef, '--manifest-checksums=NONE');
+combine_and_test_one_backup('csum_none', undef, '--manifest-checksums=NONE', $mode);
 combine_and_test_one_backup('csum_sha224',
-   undef, '--manifest-checksums=SHA224');
+   undef, '--manifest-checksums=SHA224', $mode);
 
 # Verify that SHA224 is mentioned in the SHA224 manifest lots of times.
 my $sha224_manifest =
index 636c3cc1b14131e41e69186ee94f5262c349f865..3caed13f6edd578b4647a0d74b0175c44999d1fb 100644 (file)
@@ -13,6 +13,11 @@ use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
+
+note "testing using mode $mode";
+
 # Set up a new database instance.
 my $node1 = PostgreSQL::Test::Cluster->new('node1');
 $node1->init(has_archiving => 1, allows_streaming => 1);
@@ -79,13 +84,13 @@ my $resultpath = $node1->backup_dir . '/result';
 
 # Can't combine 2 full backups.
 $node1->command_fails_like(
-   [ 'pg_combinebackup', $backup1path, $backup1path, '-o', $resultpath ],
+   [ 'pg_combinebackup', $backup1path, $backup1path, '-o', $resultpath, $mode ],
    qr/is a full backup, but only the first backup should be a full backup/,
    "can't combine full backups");
 
 # Can't combine 2 incremental backups.
 $node1->command_fails_like(
-   [ 'pg_combinebackup', $backup2path, $backup2path, '-o', $resultpath ],
+   [ 'pg_combinebackup', $backup2path, $backup2path, '-o', $resultpath, $mode ],
    qr/is an incremental backup, but the first backup should be a full backup/,
    "can't combine full backups");
 
@@ -93,7 +98,7 @@ $node1->command_fails_like(
 $node1->command_fails_like(
    [
        'pg_combinebackup', $backup1path, $backupother2path, '-o',
-       $resultpath
+       $resultpath, $mode
    ],
    qr/expected system identifier.*but found/,
    "can't combine backups from different nodes");
@@ -106,7 +111,7 @@ copy("$backupother2path/backup_manifest", "$backup2path/backup_manifest")
 $node1->command_fails_like(
    [
        'pg_combinebackup', $backup1path, $backup2path, $backup3path,
-       '-o', $resultpath
+       '-o', $resultpath, $mode
    ],
    qr/ manifest system identifier is .*, but control file has /,
    "can't combine backups with different manifest system identifier ");
@@ -116,7 +121,7 @@ move("$backup2path/backup_manifest.orig", "$backup2path/backup_manifest")
 
 # Can't omit a required backup.
 $node1->command_fails_like(
-   [ 'pg_combinebackup', $backup1path, $backup3path, '-o', $resultpath ],
+   [ 'pg_combinebackup', $backup1path, $backup3path, '-o', $resultpath, $mode ],
    qr/starts at LSN.*but expected/,
    "can't omit a required backup");
 
@@ -124,7 +129,7 @@ $node1->command_fails_like(
 $node1->command_fails_like(
    [
        'pg_combinebackup', $backup1path, $backup3path, $backup2path,
-       '-o', $resultpath
+       '-o', $resultpath, $mode
    ],
    qr/starts at LSN.*but expected/,
    "can't combine backups in the wrong order");
@@ -133,7 +138,7 @@ $node1->command_fails_like(
 $node1->command_ok(
    [
        'pg_combinebackup', $backup1path, $backup2path, $backup3path,
-       '-o', $resultpath
+       '-o', $resultpath, $mode
    ],
    "can combine 3 matching backups");
 rmtree($resultpath);
@@ -143,19 +148,19 @@ my $synthetic12path = $node1->backup_dir . '/synthetic12';
 $node1->command_ok(
    [
        'pg_combinebackup', $backup1path, $backup2path, '-o',
-       $synthetic12path
+       $synthetic12path, $mode
    ],
    "can combine 2 matching backups");
 
 # Can combine result of previous step with second incremental.
 $node1->command_ok(
-   [ 'pg_combinebackup', $synthetic12path, $backup3path, '-o', $resultpath ],
+   [ 'pg_combinebackup', $synthetic12path, $backup3path, '-o', $resultpath, $mode ],
    "can combine synthetic backup with later incremental");
 rmtree($resultpath);
 
 # Can't combine result of 1+2 with 2.
 $node1->command_fails_like(
-   [ 'pg_combinebackup', $synthetic12path, $backup2path, '-o', $resultpath ],
+   [ 'pg_combinebackup', $synthetic12path, $backup2path, '-o', $resultpath, $mode ],
    qr/starts at LSN.*but expected/,
    "can't combine synthetic backup with included incremental");
 
index d57b550af2134d15ee91060fde934707b2b94049..f44788e82bfc5f375f57e5ff1f0bf681921065b3 100644 (file)
@@ -7,6 +7,11 @@ use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
+
+note "testing using mode $mode";
+
 # Set up a new database instance.
 my $primary = PostgreSQL::Test::Cluster->new('primary');
 $primary->init(has_archiving => 1, allows_streaming => 1);
@@ -45,7 +50,8 @@ $primary->command_ok(
 # Recover the incremental backup.
 my $restore = PostgreSQL::Test::Cluster->new('restore');
 $restore->init_from_backup($primary, 'backup2',
-   combine_with_prior => ['backup1']);
+   combine_with_prior => ['backup1'],
+   combine_mode => $mode);
 $restore->start();
 
 # Query the DB.
index 83f385a48700556c12abf3630e56c5c3415225ba..0135c5a795c072b8baa15b68729288c0b85937b5 100644 (file)
@@ -856,6 +856,11 @@ sub init_from_backup
                push @combineargs, "-T$olddir=$newdir";
            }
        }
+       # use the combine mode (clone/copy-file-range) if specified
+       if (defined $params{combine_mode})
+       {
+           push @combineargs, $params{combine_mode};
+       }
        push @combineargs, @prior_backup_path, $backup_path, '-o', $data_path;
        PostgreSQL::Test::Utils::system_or_bail(@combineargs);
    }