Skip to content

Commit c9e0dd8

Browse files
committed
Add status change time
2 parents 4760ea1 + 55b2178 commit c9e0dd8

File tree

7 files changed

+189
-379
lines changed

7 files changed

+189
-379
lines changed

contrib/mmts/Cluster.pm

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package Cluster;
2+
3+
use strict;
4+
use warnings;
5+
6+
use PostgresNode;
7+
use TestLib;
8+
use Test::More;
9+
use Cwd;
10+
11+
my %allocated_ports = ();
12+
sub allocate_ports
13+
{
14+
my @allocated_now = ();
15+
my ($host, $ports_to_alloc) = @_;
16+
17+
while ($ports_to_alloc > 0)
18+
{
19+
my $port = int(rand() * 16384) + 49152;
20+
next if $allocated_ports{$port};
21+
diag("checking for port $port\n");
22+
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
23+
{
24+
$allocated_ports{$port} = 1;
25+
push(@allocated_now, $port);
26+
$ports_to_alloc--;
27+
}
28+
}
29+
30+
return @allocated_now;
31+
}
32+
33+
sub new
34+
{
35+
my ($class, $nodenum) = @_;
36+
37+
my $nodes = [];
38+
39+
foreach my $i (1..$nodenum)
40+
{
41+
my $host = "127.0.0.1";
42+
my ($pgport, $raftport) = allocate_ports($host, 2);
43+
my $node = new PostgresNode("node$i", $host, $pgport);
44+
$node->{id} = $i;
45+
$node->{raftport} = $raftport;
46+
push(@$nodes, $node);
47+
}
48+
49+
my $self = {
50+
nodenum => $nodenum,
51+
nodes => $nodes,
52+
};
53+
54+
bless $self, $class;
55+
return $self;
56+
}
57+
58+
sub init
59+
{
60+
my ($self) = @_;
61+
my $nodes = $self->{nodes};
62+
63+
foreach my $node (@$nodes)
64+
{
65+
$node->init(hba_permit_replication => 0);
66+
}
67+
}
68+
69+
sub configure
70+
{
71+
my ($self) = @_;
72+
my $nodes = $self->{nodes};
73+
74+
my $connstr = join(',', map { "${ \$_->connstr('postgres') }" } @$nodes);
75+
my $raftpeers = join(',', map { join(':', $_->{id}, $_->host, $_->{raftport}) } @$nodes);
76+
77+
foreach my $node (@$nodes)
78+
{
79+
my $id = $node->{id};
80+
my $host = $node->host;
81+
my $pgport = $node->port;
82+
my $raftport = $node->{raftport};
83+
84+
$node->append_conf("postgresql.conf", qq(
85+
listen_addresses = '$host'
86+
unix_socket_directories = ''
87+
port = $pgport
88+
max_prepared_transactions = 200
89+
max_connections = 200
90+
max_worker_processes = 100
91+
wal_level = logical
92+
fsync = off
93+
max_wal_senders = 10
94+
wal_sender_timeout = 0
95+
max_replication_slots = 10
96+
shared_preload_libraries = 'raftable,multimaster'
97+
multimaster.workers = 10
98+
multimaster.queue_size = 10485760 # 10mb
99+
multimaster.node_id = $id
100+
multimaster.conn_strings = '$connstr'
101+
multimaster.use_raftable = true
102+
multimaster.ignore_tables_without_pk = true
103+
raftable.id = $id
104+
raftable.peers = '$raftpeers'
105+
));
106+
107+
$node->append_conf("pg_hba.conf", qq(
108+
local replication all trust
109+
host replication all 127.0.0.1/32 trust
110+
host replication all ::1/128 trust
111+
));
112+
}
113+
}
114+
115+
sub start
116+
{
117+
my ($self) = @_;
118+
my $nodes = $self->{nodes};
119+
120+
foreach my $node (@$nodes)
121+
{
122+
$node->start();
123+
}
124+
}
125+
126+
sub stop
127+
{
128+
my ($self) = @_;
129+
my $nodes = $self->{nodes};
130+
131+
foreach my $node (@$nodes)
132+
{
133+
$node->stop();
134+
}
135+
}
136+
137+
sub psql
138+
{
139+
my ($self, $index, @args) = @_;
140+
my $node = $self->{nodes}->[$index];
141+
return $node->psql(@args);
142+
}
143+
144+
1;

contrib/mmts/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ 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
76
EXTRA_INSTALL = contrib/raftable contrib/mmts
87

98
EXTENSION = multimaster
109
DATA = multimaster--1.0.sql
1110

1211
.PHONY: all
1312

14-
all: multimaster.so #tests/dtmbench
13+
all: multimaster.so
1514

1615
tests/dtmbench:
1716
make -C tests

contrib/mmts/t/000_deadlock.pl

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33

4-
use PostgresNode;
4+
use Cluster;
55
use TestLib;
66
use Test::More tests => 1;
77

@@ -34,98 +34,19 @@ sub query_exec_async
3434
return $rv;
3535
}
3636

37-
my %allocated_ports = ();
38-
sub allocate_ports
39-
{
40-
my @allocated_now = ();
41-
my ($host, $ports_to_alloc) = @_;
42-
43-
while ($ports_to_alloc > 0)
44-
{
45-
my $port = int(rand() * 16384) + 49152;
46-
next if $allocated_ports{$port};
47-
diag("Checking for port $port\n");
48-
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
49-
{
50-
$allocated_ports{$port} = 1;
51-
push(@allocated_now, $port);
52-
$ports_to_alloc--;
53-
}
54-
}
55-
56-
return @allocated_now;
57-
}
58-
59-
my $nnodes = 2;
60-
my @nodes = ();
61-
62-
# Create nodes and allocate ports
63-
foreach my $i (1..$nnodes)
64-
{
65-
my $host = "127.0.0.1";
66-
my ($pgport, $raftport) = allocate_ports($host, 2);
67-
my $node = new PostgresNode("node$i", $host, $pgport);
68-
$node->{id} = $i;
69-
$node->{raftport} = $raftport;
70-
push(@nodes, $node);
71-
}
37+
my $cluster = new Cluster(2);
7238

73-
my $mm_connstr = join(',', map { "${ \$_->connstr('postgres') }" } @nodes);
74-
my $raft_peers = join(',', map { join(':', $_->{id}, $_->host, $_->{raftport}) } @nodes);
75-
76-
diag("mm_connstr = $mm_connstr\n");
77-
diag("raft_peers = $raft_peers\n");
78-
79-
# Init and Configure
80-
foreach my $node (@nodes)
81-
{
82-
my $id = $node->{id};
83-
my $host = $node->host;
84-
my $pgport = $node->port;
85-
my $raftport = $node->{raftport};
86-
87-
$node->init(hba_permit_replication => 0);
88-
$node->append_conf("postgresql.conf", qq(
89-
listen_addresses = '$host'
90-
unix_socket_directories = ''
91-
port = $pgport
92-
max_prepared_transactions = 10
93-
max_worker_processes = 10
94-
wal_level = logical
95-
fsync = off
96-
max_wal_senders = 10
97-
wal_sender_timeout = 0
98-
max_replication_slots = 10
99-
shared_preload_libraries = 'raftable,multimaster'
100-
multimaster.workers = 4
101-
multimaster.queue_size = 10485760 # 10mb
102-
multimaster.node_id = $id
103-
multimaster.conn_strings = '$mm_connstr'
104-
multimaster.use_raftable = true
105-
raftable.id = $id
106-
raftable.peers = '$raft_peers'
107-
));
108-
109-
$node->append_conf("pg_hba.conf", qq(
110-
local replication all trust
111-
host replication all 127.0.0.1/32 trust
112-
host replication all ::1/128 trust
113-
));
114-
}
115-
116-
# Start
117-
foreach my $node (@nodes)
118-
{
119-
$node->start();
120-
}
39+
$cluster->init();
40+
$cluster->configure();
41+
$cluster->start();
12142

12243
my ($rc, $out, $err);
12344
sleep(10);
12445

125-
$nodes[0]->psql('postgres', "create table t(k int primary key, v text)");
126-
$nodes[0]->psql('postgres', "insert into t values (1, 'hello'), (2, 'world')");
46+
$cluster->psql(0, 'postgres', "create table t(k int primary key, v text)");
47+
$cluster->psql(0, 'postgres', "insert into t values (1, 'hello'), (2, 'world')");
12748

128-
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @nodes;
49+
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @{$cluster->{nodes}};
12950

13051
query_exec($conns[0], "begin");
13152
query_exec($conns[1], "begin");

0 commit comments

Comments
 (0)