Skip to content

Commit 33db8d7

Browse files
committed
Fall back to unix sockets in perl tests.
TCP required hold|release socket hack, which became worse with identity_func test: attempt to connect to such held socket hanged, so we had to resort on connection timeouts which are really elastic on buildfarm.
1 parent 6fd0c30 commit 33db8d7

File tree

5 files changed

+13
-104
lines changed

5 files changed

+13
-104
lines changed

Cluster.pm

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,11 @@ use Cwd;
1010
use IPC::Run;
1111
use Socket;
1212

13-
# 127.0.0.1 is not ok because we pick up random ephemeral port which might be
14-
# occupied by client connection while node is down -- and then it would refuse
15-
# to start later. At least on my linux the kernel binds clients to 127.0.0.1,
16-
# so this works. Alternatively we could
17-
# 1) bind to the socket manually immediately after shutdown and release before
18-
# the start, but this obviously only (greatly) reduces the danger;
19-
# 2) forget we are a distributed thing and use unix sockets like vanilla tests
20-
#
21-
# UPD: well, bf member msvs-6-3 decided to take 127.0.0.2 for local connections,
22-
# so 1) was also implemented for such cases.
23-
# I don't like falling back to 2) because a) it is slightly easier to connect to
24-
# ports b) Windows uses TCP anyway.
25-
our $mm_listen_address = '127.0.0.2';
26-
2713
sub new
2814
{
2915
my ($class, $n_nodes, $referee) = @_;
3016

31-
# ask PostgresNode to use tcp and listen on mm_listen_address
32-
$PostgresNode::use_tcp = 1;
33-
$PostgresNode::test_pghost = $mm_listen_address;
34-
3517
my @nodes = map { get_new_node("node$_") } (1..$n_nodes);
36-
$_->hold_port() foreach @nodes;
3718

3819
my $self = {
3920
nodes => \@nodes,
@@ -42,7 +23,6 @@ sub new
4223
if (defined $referee && $referee)
4324
{
4425
$self->{referee} = get_new_node("referee");
45-
$self->{referee}->hold_port();
4626
}
4727

4828
bless $self, $class;
@@ -63,8 +43,7 @@ sub init
6343
}
6444

6545
my $hba = qq{
66-
host all all ${mm_listen_address}/32 trust
67-
host replication all ${mm_listen_address}/32 trust
46+
local all all trust
6847
};
6948

7049
# binary protocol doesn't tolerate strict alignment currently, so use it
@@ -169,7 +148,7 @@ sub init
169148

170149
sub create_mm
171150
{
172-
my ($self, $dbname, $connect_timeout) = @_;
151+
my ($self, $dbname) = @_;
173152
my $nodes = $self->{nodes};
174153

175154
$self->await_nodes([0..$#{$self->{nodes}}], 0);
@@ -227,11 +206,8 @@ sub create_mm
227206
}
228207
}
229208

230-
# identity_func uses connect_timeout as it tries connecting to shutdown
231-
# node which hangs infinitely otherwise due to our hold_socket hack.
232209
(my $my_connstr, my @peers) = map {
233-
$_->connstr($_->{dbname}) . ((defined $connect_timeout) ?
234-
" connect_timeout=${connect_timeout}" : "");
210+
$_->connstr($_->{dbname});
235211
} @{$self->{nodes}};
236212

237213
my $node1 = $self->{nodes}->[0];
@@ -247,16 +223,17 @@ sub create_mm
247223
sub start
248224
{
249225
my ($self) = @_;
226+
my $hosts = join ', ', map { $_->{_host}} @{$self->{nodes}};
250227
my $ports = join ', ', map { $_->{_port}} @{$self->{nodes}};
251-
note( "starting cluster on ports: $ports");
228+
note( "starting cluster on hosts: $hosts, ports: $ports");
252229
$_->start() foreach @{$self->{nodes}};
253230
if (defined $self->{referee})
254231
{
232+
my $rhost = $self->{referee}->host;
255233
my $rport = $self->{referee}->port;
256-
note("starting referee on port $rport");
234+
note("starting referee on host $rhost port $rport");
257235
$self->{referee}->start();
258236
}
259-
260237
}
261238

262239
sub stop
@@ -292,7 +269,6 @@ sub add_node()
292269
my ($self) = @_;
293270

294271
my $new_node = get_new_node("node@{[$#{$self->{nodes}} + 2]}");
295-
$new_node->hold_port();
296272
push(@{$self->{nodes}}, $new_node);
297273

298274
return $#{$self->{nodes}};
@@ -316,12 +292,13 @@ sub backup_and_init()
316292
my $node = $self->{nodes}->[$from];
317293
my $backup_name = "backup_for_$to";
318294
my $backup_path = $node->backup_dir . '/' . $backup_name;
295+
my $host = $node->host;
319296
my $port = $node->port;
320297
my $name = $node->name;
321298

322299
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
323300
my $dumpres = command_output(['pg_basebackup', '-D', $backup_path, '-p', $port,
324-
'-h', $mm_listen_address, '--no-sync', '-v']);
301+
'-h', $host, '--no-sync', '-v']);
325302

326303
print "# Backup finished\n";
327304

@@ -462,65 +439,5 @@ sub is_ee
462439
return ($stdout =~ m/enterprise/);
463440
}
464441

465-
# Override PostgresNode::start|stop to reserve the port while node is down
466-
{
467-
# otherwise perl whines, thinking our override is redefine
468-
no warnings 'redefine';
469-
# that's how perl people call super from monkey-patch-overridden method
470-
# https://stackoverflow.com/a/575873/4014587
471-
my $postgres_node_start_super = \&PostgresNode::start;
472-
*PostgresNode::start = sub {
473-
my $self = shift;
474-
$self->release_port();
475-
$postgres_node_start_super->( $self, @_ );
476-
};
477-
478-
my $postgres_node_stop_super = \&PostgresNode::stop;
479-
*PostgresNode::stop = sub {
480-
my $self = shift;
481-
$postgres_node_stop_super->( $self, @_ );
482-
$self->hold_port();
483-
};
484-
}
485-
486-
# Bind to socket with our port so no one could use it while node is down.
487-
sub PostgresNode::hold_port {
488-
my $self = shift;
489-
490-
# do nothing if this is not mm node, it most probably uses unix socket
491-
return unless $self->host eq $mm_listen_address;
492-
493-
# stop() might be called several times without start(), don't bind if
494-
# already did so
495-
return if defined $self->{held_socket};
496-
497-
my $iaddr = inet_aton($self->host);
498-
my $paddr = sockaddr_in($self->port, $iaddr);
499-
my $proto = getprotobyname("tcp");
500-
501-
socket(my $sock, PF_INET, SOCK_STREAM, $proto)
502-
or die "socket failed: $!";
503-
504-
# As in postmaster, don't use SO_REUSEADDR on Windows
505-
setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))
506-
unless $TestLib::windows_os;
507-
bind($sock, $paddr) or die
508-
"socket bind failed: $!";
509-
listen($sock, SOMAXCONN)
510-
or die "socket listen failed: $!";
511-
512-
$self->{held_socket} = $sock;
513-
note("bind to port @{[$self->port]}");
514-
}
515-
516-
sub PostgresNode::release_port {
517-
my $self = shift;
518-
if (defined $self->{held_socket})
519-
{
520-
close($self->{held_socket});
521-
$self->{held_socket} = undef;
522-
}
523-
note("port released");
524-
}
525442

526443
1;

t/001_regress.pl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
$cluster->start();
4646
$cluster->create_mm('regression');
4747

48-
my $port = $cluster->{nodes}->[0]->port;
49-
5048
###############################################################################
5149
# postgres regression tests
5250
###############################################################################
@@ -101,7 +99,7 @@
10199
mkdir("${regress_outdir}/sql");
102100
mkdir("${regress_outdir}/expected");
103101
TestLib::system_log($ENV{'PG_REGRESS'},
104-
'--host=' . $Cluster::mm_listen_address, "--port=$port",
102+
'--host=' . $cluster->{nodes}->[0]->host, '--port=' . $cluster->{nodes}->[0]->port,
105103
'--use-existing', '--bindir=',
106104
'--schedule=parallel_schedule',
107105
"--dlpath=${regress_libdir}",

t/002_regressmm.pl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
$cluster->start();
1313
$cluster->create_mm('regression');
1414

15-
my $port = $cluster->{nodes}->[0]->port;
16-
1715
###############################################################################
1816
# multimaster regression tests
1917
###############################################################################
@@ -26,7 +24,7 @@
2624
}
2725

2826
my $ret = TestLib::system_log($ENV{'PG_REGRESS'},
29-
'--host=' . $Cluster::mm_listen_address, "--port=$port",
27+
'--host=' . $cluster->{nodes}->[0]->host, '--port=' . $cluster->{nodes}->[0]->port,
3028
'--use-existing', '--bindir=', @tests);
3129
if ($ret != 0)
3230
{

t/007_add_stop_node.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
$cluster->poll_query_until(0, "select exists(select * from pg_replication_slots where slot_name = 'mtm_filter_slot_${new_node_id}');")
108108
or croak "timed out waiting for slot creation";
109109
my $end_lsn = $cluster->backup_and_init(0, $new_node_off, $new_node_id);
110-
$cluster->{nodes}->[$new_node_off]->append_conf('postgresql.conf', q{unix_socket_directories = ''
111-
});
110+
112111
# Prevent recovery of new node further than the end point returned by
113112
# basebackup as streaming will be requested since it, so not doing this might
114113
# result in attempting to receive already existing data. This realistically

t/009_identity_func.pl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
my $cluster = new Cluster(3);
99
$cluster->init();
1010
$cluster->start();
11-
# connect_timeout prevents hanging while connecting to turned off node with
12-
# hold_socket done. Hopefully it is high enough to avoid slow bf machines random
13-
# failures
14-
$cluster->create_mm(undef, 3);
11+
$cluster->create_mm(undef);
1512

1613
my $dbname = $cluster->{nodes}->[0]->{dbname};
1714
my $nodes = $cluster->{nodes};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy