Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 89ac700

Browse files
committed
Move some code from RewindTest into PostgresNode
Some code in the RewindTest test suite is more generally useful than just for that suite, so put it where other test suites can reach it. Some postgresql.conf parameters change their default values when a cluster is initialized with 'allows_streaming' than the previous behavior; most notably, autovacuum is no longer turned off. (Also, we no longer call pg_ctl promote with -w, but that flag doesn't actually do anything in promote so there's no behavior change.) Author: Michael Paquier
1 parent 7bea19d commit 89ac700

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

src/bin/pg_rewind/RewindTest.pm

+2-17
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,9 @@ sub check_query
114114

115115
sub setup_cluster
116116
{
117-
118117
# Initialize master, data checksums are mandatory
119118
$node_master = get_new_node('master');
120-
$node_master->init;
121-
122-
# Custom parameters for master's postgresql.conf
123-
$node_master->append_conf(
124-
"postgresql.conf", qq(
125-
wal_level = hot_standby
126-
max_wal_senders = 2
127-
wal_keep_segments = 20
128-
max_wal_size = 200MB
129-
shared_buffers = 1MB
130-
wal_log_hints = on
131-
hot_standby = on
132-
autovacuum = off
133-
max_connections = 10
134-
));
119+
$node_master->init(allows_streaming => 1);
135120
}
136121

137122
sub start_master
@@ -177,7 +162,7 @@ sub promote_standby
177162
# Now promote slave and insert some new data on master, this will put
178163
# the master out-of-sync with the standby. Wait until the standby is
179164
# out of recovery mode, and is ready to accept read-write connections.
180-
system_or_bail('pg_ctl', '-w', '-D', $node_standby->data_dir, 'promote');
165+
$node_standby->promote;
181166
$node_standby->poll_query_until('postgres',
182167
"SELECT NOT pg_is_in_recovery()")
183168
or die "Timed out while waiting for promotion of standby";

src/test/perl/PostgresNode.pm

+63-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ allowing to start, stop, backup and initialize it with various options.
4747
The set of nodes managed by a given test is also managed by this module.
4848
4949
In addition to node management, PostgresNode instances have some wrappers
50-
around Test::More functions to run commands with an envronment set up to
50+
around Test::More functions to run commands with an environment set up to
5151
point to the instance.
5252
5353
The IPC::Run module is required.
@@ -66,7 +66,6 @@ use File::Basename;
6666
use File::Spec;
6767
use File::Temp ();
6868
use IPC::Run;
69-
use PostgresNode;
7069
use RecursiveCopy;
7170
use Test::More;
7271
use TestLib ();
@@ -347,6 +346,9 @@ On Windows, we use SSPI authentication to ensure the same (by pg_regress
347346
pg_hba.conf is configured to allow replication connections. Pass the keyword
348347
parameter hba_permit_replication => 0 to disable this.
349348
349+
postgresql.conf can be set up for replication by passing the keyword
350+
parameter allows_streaming => 1. This is disabled by default.
351+
350352
The new node is set up in a fast but unsafe configuration where fsync is
351353
disabled.
352354
@@ -360,7 +362,8 @@ sub init
360362
my $host = $self->host;
361363

362364
$params{hba_permit_replication} = 1
363-
if (!defined($params{hba_permit_replication}));
365+
unless defined $params{hba_permit_replication};
366+
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
364367

365368
mkdir $self->backup_dir;
366369
mkdir $self->archive_dir;
@@ -373,6 +376,19 @@ sub init
373376
print $conf "fsync = off\n";
374377
print $conf "log_statement = all\n";
375378
print $conf "port = $port\n";
379+
380+
if ($params{allows_streaming})
381+
{
382+
print $conf "wal_level = hot_standby\n";
383+
print $conf "max_wal_senders = 5\n";
384+
print $conf "wal_keep_segments = 20\n";
385+
print $conf "max_wal_size = 128MB\n";
386+
print $conf "shared_buffers = 1MB\n";
387+
print $conf "wal_log_hints = on\n";
388+
print $conf "hot_standby = on\n";
389+
print $conf "max_connections = 10\n";
390+
}
391+
376392
if ($TestLib::windows_os)
377393
{
378394
print $conf "listen_addresses = '$host'\n";
@@ -384,7 +400,7 @@ sub init
384400
}
385401
close $conf;
386402

387-
$self->set_replication_conf if ($params{hba_permit_replication});
403+
$self->set_replication_conf if $params{hba_permit_replication};
388404
}
389405

390406
=pod
@@ -446,19 +462,23 @@ Does not start the node after init.
446462
447463
A recovery.conf is not created.
448464
465+
Streaming replication can be enabled on this node by passing the keyword
466+
parameter has_streaming => 1. This is disabled by default.
467+
449468
The backup is copied, leaving the original unmodified. pg_hba.conf is
450469
unconditionally set to enable replication connections.
451470
452471
=cut
453472

454473
sub init_from_backup
455474
{
456-
my ($self, $root_node, $backup_name) = @_;
475+
my ($self, $root_node, $backup_name, %params) = @_;
457476
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
458477
my $port = $self->port;
459478
my $node_name = $self->name;
460479
my $root_name = $root_node->name;
461480

481+
$params{has_streaming} = 0 unless defined $params{has_streaming};
462482
print
463483
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
464484
die "Backup \"$backup_name\" does not exist at $backup_path"
@@ -479,6 +499,7 @@ sub init_from_backup
479499
port = $port
480500
));
481501
$self->set_replication_conf;
502+
$self->enable_streaming($root_node) if $params{has_streaming};
482503
}
483504

484505
=pod
@@ -525,7 +546,7 @@ sub stop
525546
my $port = $self->port;
526547
my $pgdata = $self->data_dir;
527548
my $name = $self->name;
528-
$mode = 'fast' if (!defined($mode));
549+
$mode = 'fast' unless defined $mode;
529550
print "### Stopping node \"$name\" using mode $mode\n";
530551
TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop');
531552
$self->{_pid} = undef;
@@ -536,7 +557,7 @@ sub stop
536557
537558
=item $node->restart()
538559
539-
wrapper for pg_ctl -w restart
560+
Wrapper for pg_ctl -w restart
540561
541562
=cut
542563

@@ -553,6 +574,39 @@ sub restart
553574
$self->_update_pid;
554575
}
555576

577+
=pod
578+
579+
=item $node->promote()
580+
581+
Wrapper for pg_ctl promote
582+
583+
=cut
584+
585+
sub promote
586+
{
587+
my ($self) = @_;
588+
my $port = $self->port;
589+
my $pgdata = $self->data_dir;
590+
my $logfile = $self->logfile;
591+
my $name = $self->name;
592+
print "### Promoting node \"$name\"\n";
593+
TestLib::system_log('pg_ctl', '-D', $pgdata, '-l', $logfile,
594+
'promote');
595+
}
596+
597+
# Internal routine to enable streaming replication on a standby node.
598+
sub enable_streaming
599+
{
600+
my ($self, $root_node) = @_;
601+
my $root_connstr = $root_node->connstr;
602+
my $name = $self->name;
603+
604+
print "### Enabling streaming replication for node \"$name\"\n";
605+
$self->append_conf('recovery.conf', qq(
606+
primary_conninfo='$root_connstr application_name=$name'
607+
standby_mode=on
608+
));
609+
}
556610

557611
# Internal method
558612
sub _update_pid
@@ -632,7 +686,7 @@ sub DESTROY
632686
{
633687
my $self = shift;
634688
my $name = $self->name;
635-
return if not defined $self->{_pid};
689+
return unless defined $self->{_pid};
636690
print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n";
637691
TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_pid});
638692
}
@@ -789,6 +843,7 @@ Run a command on the node, then verify that $expected_sql appears in the
789843
server log file.
790844
791845
Reads the whole log file so be careful when working with large log outputs.
846+
The log file is truncated prior to running the command, however.
792847
793848
=cut
794849

0 commit comments

Comments
 (0)