2021-05-07 16:56:14 +02:00
|
|
|
|
|
|
|
# Copyright (c) 2021, PostgreSQL Global Development Group
|
|
|
|
|
2017-02-09 22:23:46 +01:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use TestLib;
|
2017-09-11 22:30:50 +02:00
|
|
|
use PostgresNode;
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
use Test::More tests => 27;
|
2017-02-09 22:23:46 +01:00
|
|
|
|
|
|
|
program_help_ok('pg_receivewal');
|
|
|
|
program_version_ok('pg_receivewal');
|
|
|
|
program_options_handling_ok('pg_receivewal');
|
2017-09-11 22:30:50 +02:00
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
# Set umask so test directories and files are created with default permissions
|
|
|
|
umask(0077);
|
|
|
|
|
2021-07-29 11:58:08 +02:00
|
|
|
my $primary = PostgresNode->new('primary');
|
2017-09-11 22:30:50 +02:00
|
|
|
$primary->init(allows_streaming => 1);
|
|
|
|
$primary->start;
|
|
|
|
|
|
|
|
my $stream_dir = $primary->basedir . '/archive_wal';
|
|
|
|
mkdir($stream_dir);
|
|
|
|
|
|
|
|
# Sanity checks for command line options.
|
|
|
|
$primary->command_fails(['pg_receivewal'],
|
|
|
|
'pg_receivewal needs target directory specified');
|
|
|
|
$primary->command_fails(
|
|
|
|
[ 'pg_receivewal', '-D', $stream_dir, '--create-slot', '--drop-slot' ],
|
|
|
|
'failure if both --create-slot and --drop-slot specified');
|
|
|
|
$primary->command_fails(
|
|
|
|
[ 'pg_receivewal', '-D', $stream_dir, '--create-slot' ],
|
|
|
|
'failure if --create-slot specified without --slot');
|
2017-10-29 08:16:55 +01:00
|
|
|
$primary->command_fails(
|
|
|
|
[ 'pg_receivewal', '-D', $stream_dir, '--synchronous', '--no-sync' ],
|
|
|
|
'failure if --synchronous specified with --no-sync');
|
2017-09-11 22:30:50 +02:00
|
|
|
|
|
|
|
# Slot creation and drop
|
|
|
|
my $slot_name = 'test';
|
|
|
|
$primary->command_ok(
|
|
|
|
[ 'pg_receivewal', '--slot', $slot_name, '--create-slot' ],
|
|
|
|
'creating a replication slot');
|
2017-09-26 22:41:20 +02:00
|
|
|
my $slot = $primary->slot($slot_name);
|
|
|
|
is($slot->{'slot_type'}, 'physical', 'physical replication slot was created');
|
|
|
|
is($slot->{'restart_lsn'}, '', 'restart LSN of new slot is null');
|
2017-09-11 22:30:50 +02:00
|
|
|
$primary->command_ok([ 'pg_receivewal', '--slot', $slot_name, '--drop-slot' ],
|
|
|
|
'dropping a replication slot');
|
2017-09-26 22:41:20 +02:00
|
|
|
is($primary->slot($slot_name)->{'slot_type'},
|
|
|
|
'', 'replication slot was removed');
|
2017-09-11 22:30:50 +02:00
|
|
|
|
|
|
|
# Generate some WAL. Use --synchronous at the same time to add more
|
|
|
|
# code coverage. Switch to the next segment first so that subsequent
|
|
|
|
# restarts of pg_receivewal will see this segment as full..
|
|
|
|
$primary->psql('postgres', 'CREATE TABLE test_table(x integer);');
|
|
|
|
$primary->psql('postgres', 'SELECT pg_switch_wal();');
|
|
|
|
my $nextlsn =
|
|
|
|
$primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();');
|
|
|
|
chomp($nextlsn);
|
|
|
|
$primary->psql('postgres',
|
|
|
|
'INSERT INTO test_table VALUES (generate_series(1,100));');
|
|
|
|
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
# Stream up to the given position. This is necessary to have a fixed
|
|
|
|
# started point for the next commands done in this test, with or without
|
|
|
|
# compression involved.
|
2017-09-11 22:30:50 +02:00
|
|
|
$primary->command_ok(
|
2018-05-09 16:14:46 +02:00
|
|
|
[
|
|
|
|
'pg_receivewal', '-D', $stream_dir, '--verbose',
|
|
|
|
'--endpos', $nextlsn, '--synchronous', '--no-loop'
|
|
|
|
],
|
2017-09-11 22:30:50 +02:00
|
|
|
'streaming some WAL with --synchronous');
|
2018-04-07 23:45:39 +02:00
|
|
|
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
# Verify that one partial file was generated and keep track of it
|
|
|
|
my @partial_wals = glob "$stream_dir/*\.partial";
|
|
|
|
is(scalar(@partial_wals), 1, "one partial WAL segment was created");
|
|
|
|
|
2021-07-31 03:13:15 +02:00
|
|
|
# Check ZLIB compression if available.
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
SKIP:
|
|
|
|
{
|
2021-07-31 03:13:15 +02:00
|
|
|
skip "postgres was not built with ZLIB support", 5
|
|
|
|
if (!check_pg_config("#define HAVE_LIBZ 1"));
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
|
|
|
|
# Generate more WAL worth one completed, compressed, segment.
|
|
|
|
$primary->psql('postgres', 'SELECT pg_switch_wal();');
|
|
|
|
$nextlsn =
|
|
|
|
$primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();');
|
|
|
|
chomp($nextlsn);
|
|
|
|
$primary->psql('postgres',
|
|
|
|
'INSERT INTO test_table VALUES (generate_series(100,200));');
|
|
|
|
|
2021-07-27 03:39:05 +02:00
|
|
|
# Note the trailing whitespace after the value of --compress, that is
|
|
|
|
# a valid value.
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
$primary->command_ok(
|
|
|
|
[
|
|
|
|
'pg_receivewal', '-D', $stream_dir, '--verbose',
|
2021-07-30 14:28:03 +02:00
|
|
|
'--endpos', $nextlsn, '--compress', '1 ',
|
|
|
|
'--no-loop'
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
],
|
|
|
|
"streaming some WAL using ZLIB compression");
|
|
|
|
|
|
|
|
# Verify that the stored files are generated with their expected
|
|
|
|
# names.
|
|
|
|
my @zlib_wals = glob "$stream_dir/*.gz";
|
|
|
|
is(scalar(@zlib_wals), 1,
|
|
|
|
"one WAL segment compressed with ZLIB was created");
|
|
|
|
my @zlib_partial_wals = glob "$stream_dir/*.gz.partial";
|
|
|
|
is(scalar(@zlib_partial_wals),
|
|
|
|
1, "one partial WAL segment compressed with ZLIB was created");
|
|
|
|
|
|
|
|
# Verify that the start streaming position is computed correctly by
|
|
|
|
# comparing it with the partial file generated previously. The name
|
|
|
|
# of the previous partial, now-completed WAL segment is updated, keeping
|
|
|
|
# its base number.
|
|
|
|
$partial_wals[0] =~ s/\.partial$/.gz/;
|
2021-07-27 03:58:21 +02:00
|
|
|
is($zlib_wals[0] eq $partial_wals[0],
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
1, "one partial WAL segment is now completed");
|
|
|
|
# Update the list of partial wals with the current one.
|
|
|
|
@partial_wals = @zlib_partial_wals;
|
|
|
|
|
2021-07-15 14:25:03 +02:00
|
|
|
# Check the integrity of the completed segment, if gzip is a command
|
|
|
|
# available.
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
my $gzip = $ENV{GZIP_PROGRAM};
|
|
|
|
skip "program gzip is not found in your system", 1
|
|
|
|
if ( !defined $gzip
|
|
|
|
|| $gzip eq ''
|
|
|
|
|| system_log($gzip, '--version') != 0);
|
|
|
|
|
|
|
|
my $gzip_is_valid = system_log($gzip, '--test', @zlib_wals);
|
|
|
|
is($gzip_is_valid, 0,
|
|
|
|
"gzip verified the integrity of compressed WAL segments");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that the start streaming position is computed and that the value is
|
|
|
|
# correct regardless of whether ZLIB is available.
|
|
|
|
$primary->psql('postgres', 'SELECT pg_switch_wal();');
|
|
|
|
$nextlsn =
|
|
|
|
$primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();');
|
|
|
|
chomp($nextlsn);
|
|
|
|
$primary->psql('postgres',
|
|
|
|
'INSERT INTO test_table VALUES (generate_series(200,300));');
|
|
|
|
$primary->command_ok(
|
2021-07-30 14:28:03 +02:00
|
|
|
[
|
|
|
|
'pg_receivewal', '-D', $stream_dir, '--verbose',
|
|
|
|
'--endpos', $nextlsn, '--no-loop'
|
|
|
|
],
|
Add TAP tests for ZLIB compression for pg_receivewal
There is a non-trivial amount of code that handles ZLIB compression in
pg_receivewal, from basics like the format name, the calculation of the
start streaming position and of course the compression itself, but there
was no automated coverage for it.
This commit introduces a set of conditional tests (if the build supports
ZLIB) to cover the creation of ZLIB-compressed WAL segments, the
handling of the partial, compressed, WAL segments and the compression
operation in itself. Note that there is an extra phase checking the
validity of the generated files by using directly a gzip command, passed
down by the Makefile of pg_receivewal. This part is skipped if the
command cannot be found, something likely going to happen on Windows
with MSVC except if one sets the variable GZIP_PROGRAM in the
environment of the test.
This set of tests will become handy for upcoming patches that add more
options for the compression methods used by pg_receivewal, like LZ4, to
make sure that no existing facilities are broken.
Author: Georgios Kokolatos
Reviewed-by: Gilles Darold, Michael Paquier
Discussion: https://postgr.es/m/07BK3Mk5aEOsTwGaY77qBVyf9GjoEzn8TMgHLyPGfEFPIpTEmoQuP2P4c7teesjSg-LPeUafsp1flnPeQYINMSMB_UpggJDoduB5EDYBqaQ=@protonmail.com
2021-07-15 08:53:20 +02:00
|
|
|
"streaming some WAL");
|
|
|
|
|
|
|
|
$partial_wals[0] =~ s/(\.gz)?.partial//;
|
|
|
|
ok(-e $partial_wals[0], "check that previously partial WAL is now complete");
|
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
# Permissions on WAL files should be default
|
|
|
|
SKIP:
|
|
|
|
{
|
|
|
|
skip "unix-style permissions not supported on Windows", 1
|
|
|
|
if ($windows_os);
|
|
|
|
|
|
|
|
ok(check_mode_recursive($stream_dir, 0700, 0600),
|
|
|
|
"check stream dir permissions");
|
|
|
|
}
|