Skip to content

Commit fa53942

Browse files
committed
Merge branch 'master' of github.com:postgrespro/postgres_cluster
2 parents 5efab16 + 76d7f27 commit fa53942

File tree

3 files changed

+133
-3
lines changed

3 files changed

+133
-3
lines changed

contrib/mmts/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ OBJS = multimaster.o raftable.o arbiter.o bytebuf.o bgwpool.o pglogical_output.o
33

44
override CPPFLAGS += -I../raftable
55

6+
SCRIPTS_built = tests/dtmbench
67
EXTRA_INSTALL = contrib/raftable contrib/mmts
78

89
EXTENSION = multimaster
910
DATA = multimaster--1.0.sql
1011

1112
.PHONY: all
1213

13-
all: multimaster.so
14+
all: multimaster.so tests/dtmbench
15+
16+
tests/dtmbench:
17+
make -C tests
1418

1519
PG_CPPFLAGS = -I$(libpq_srcdir) -DUSE_PGLOGICAL_OUTPUT
1620
SHLIB_LINK = $(libpq)

contrib/mmts/t/001_basic_recovery.pl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ sub PostgresNode::inet_connstr {
9494
# Work after node stop
9595
###############################################################################
9696

97+
diag("stopping node 2");
9798
$nodes[2]->teardown_node;
9899

99-
diag("sleeping");
100+
diag("sleeping 15");
100101
sleep(15);
101102

102103
diag("inserting 2");
@@ -110,8 +111,10 @@ sub PostgresNode::inet_connstr {
110111
# Work after node start
111112
###############################################################################
112113

114+
diag("starting node 2");
113115
$nodes[2]->start;
114-
sleep(15); # XXX: here we can poll
116+
diag("sleeping 30");
117+
sleep(30); # XXX: here we can poll
115118
diag("inserting 3");
116119
$nodes[0]->psql('postgres', "insert into t values(3, 30);");
117120
diag("selecting");

contrib/mmts/t/002_dtmbench.pl

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 1;
7+
8+
my %allocated_ports = ();
9+
sub allocate_ports
10+
{
11+
my @allocated_now = ();
12+
my ($host, $ports_to_alloc) = @_;
13+
14+
while ($ports_to_alloc > 0)
15+
{
16+
my $port = int(rand() * 16384) + 49152;
17+
next if $allocated_ports{$port};
18+
diag("checking for port $port\n");
19+
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
20+
{
21+
$allocated_ports{$port} = 1;
22+
push(@allocated_now, $port);
23+
$ports_to_alloc--;
24+
}
25+
}
26+
27+
return @allocated_now;
28+
}
29+
30+
my $nnodes = 2;
31+
my @nodes = ();
32+
33+
diag("creating nodes");
34+
foreach my $i (1..$nnodes)
35+
{
36+
my $host = "127.0.0.1";
37+
my ($pgport, $raftport) = allocate_ports($host, 2);
38+
my $node = new PostgresNode("node$i", $host, $pgport);
39+
$node->{id} = $i;
40+
$node->{raftport} = $raftport;
41+
push(@nodes, $node);
42+
}
43+
44+
my $mm_connstr = join(',', map { "${ \$_->connstr('postgres') }" } @nodes);
45+
my $raft_peers = join(',', map { join(':', $_->{id}, $_->host, $_->{raftport}) } @nodes);
46+
47+
diag("mm_connstr = $mm_connstr\n");
48+
diag("raft_peers = $raft_peers\n");
49+
50+
diag("initting and configuring nodes");
51+
foreach my $node (@nodes)
52+
{
53+
my $id = $node->{id};
54+
my $host = $node->host;
55+
my $pgport = $node->port;
56+
my $raftport = $node->{raftport};
57+
58+
$node->init(hba_permit_replication => 0);
59+
$node->append_conf("postgresql.conf", qq(
60+
listen_addresses = '$host'
61+
unix_socket_directories = ''
62+
port = $pgport
63+
max_prepared_transactions = 10
64+
max_worker_processes = 10
65+
wal_level = logical
66+
fsync = off
67+
max_wal_senders = 10
68+
wal_sender_timeout = 0
69+
max_replication_slots = 10
70+
shared_preload_libraries = 'raftable,multimaster'
71+
multimaster.workers = 4
72+
multimaster.queue_size = 10485760 # 10mb
73+
multimaster.node_id = $id
74+
multimaster.conn_strings = '$mm_connstr'
75+
multimaster.use_raftable = true
76+
raftable.id = $id
77+
raftable.peers = '$raft_peers'
78+
));
79+
80+
$node->append_conf("pg_hba.conf", qq(
81+
local replication all trust
82+
host replication all 127.0.0.1/32 trust
83+
host replication all ::1/128 trust
84+
));
85+
}
86+
87+
diag("starting nodes");
88+
foreach my $node (@nodes)
89+
{
90+
$node->start();
91+
}
92+
93+
my ($rc, $out, $err);
94+
95+
diag("sleeping");
96+
sleep(10);
97+
98+
my @argv = ('dtmbench');
99+
foreach my $node (@nodes)
100+
{
101+
push(@argv, '-c', $node->connstr('postgres'));
102+
}
103+
push(@argv, '-n', 10, '-a', 1000, '-w', 10, '-r', 1);
104+
105+
diag("running dtmbench -i");
106+
if (TestLib::run_log([@argv, '-i']))
107+
{
108+
BAIL_OUT("dtmbench -i failed");
109+
}
110+
111+
diag("running dtmbench");
112+
if (TestLib::run_log(\@argv, '>', \$out))
113+
{
114+
fail("dtmbench failed");
115+
}
116+
elsif ($out =~ /Wrong sum/)
117+
{
118+
fail("inconsistency detected");
119+
}
120+
else
121+
{
122+
pass("all consistent during dtmbench");
123+
}

0 commit comments

Comments
 (0)