Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10fe0d0

Browse files
committed
2 parents305bb17 +c8c219c commit10fe0d0

File tree

6 files changed

+255
-12
lines changed

6 files changed

+255
-12
lines changed

‎contrib/mmts/testeaux/Cluster.pm‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
packageCluster;
2+
3+
use strict;
4+
use warnings;
5+
6+
use PostgresNode;
7+
use TestLib;
8+
use Test::More;
9+
use Cwd;
10+
11+
my$max_port = 5431;
12+
suballocate_ports
13+
{
14+
my@allocated_now = ();
15+
my ($host,$ports_to_alloc) =@_;
16+
my$port =$max_port + 1;
17+
18+
while ($ports_to_alloc > 0)
19+
{
20+
diag("checking for port$port\n");
21+
if (!TestLib::run_log(['pg_isready','-h',$host,'-p',$port]))
22+
{
23+
$max_port =$port;
24+
push(@allocated_now,$port);
25+
$ports_to_alloc--;
26+
}
27+
$port++;
28+
}
29+
30+
return@allocated_now;
31+
}
32+
33+
subnew
34+
{
35+
my ($class,$nodenum) =@_;
36+
37+
my$nodes = [];
38+
39+
foreachmy$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+
subinit
59+
{
60+
my ($self) =@_;
61+
my$nodes =$self->{nodes};
62+
63+
foreachmy$node (@$nodes)
64+
{
65+
$node->init(hba_permit_replication=> 0);
66+
}
67+
}
68+
69+
subdetach
70+
{
71+
my ($self) =@_;
72+
my$nodes =$self->{nodes};
73+
74+
foreachmy$node (@$nodes)
75+
{
76+
delete$node->{_pid};
77+
}
78+
}
79+
80+
subconfigure
81+
{
82+
my ($self) =@_;
83+
my$nodes =$self->{nodes};
84+
85+
my$connstr =join(',',map {"${\$_->connstr('postgres') }" }@$nodes);
86+
my$raftpeers =join(',',map {join(':',$_->{id},$_->host,$_->{raftport}) }@$nodes);
87+
88+
foreachmy$node (@$nodes)
89+
{
90+
my$id =$node->{id};
91+
my$host =$node->host;
92+
my$pgport =$node->port;
93+
my$raftport =$node->{raftport};
94+
95+
$node->append_conf("postgresql.conf",qq(
96+
listen_addresses = '$host'
97+
unix_socket_directories = ''
98+
port =$pgport
99+
max_prepared_transactions = 200
100+
max_connections = 200
101+
max_worker_processes = 100
102+
wal_level = logical
103+
fsync = off
104+
max_wal_senders = 10
105+
wal_sender_timeout = 0
106+
max_replication_slots = 10
107+
shared_preload_libraries = 'raftable,multimaster'
108+
multimaster.workers = 10
109+
multimaster.queue_size = 10485760 # 10mb
110+
multimaster.node_id =$id
111+
multimaster.conn_strings = '$connstr'
112+
multimaster.use_raftable = true
113+
multimaster.ignore_tables_without_pk = true
114+
multimaster.twopc_min_timeout = 60000
115+
raftable.id =$id
116+
raftable.peers = '$raftpeers'
117+
));
118+
119+
$node->append_conf("pg_hba.conf",qq(
120+
local replication all trust
121+
host replication all 127.0.0.1/32 trust
122+
host replication all ::1/128 trust
123+
));
124+
}
125+
}
126+
127+
substart
128+
{
129+
my ($self) =@_;
130+
my$nodes =$self->{nodes};
131+
132+
foreachmy$node (@$nodes)
133+
{
134+
$node->start();
135+
}
136+
}
137+
138+
substop
139+
{
140+
my ($self) =@_;
141+
my$nodes =$self->{nodes};
142+
143+
foreachmy$node (@$nodes)
144+
{
145+
$node->stop();
146+
}
147+
}
148+
149+
subpsql
150+
{
151+
my ($self,$index,@args) =@_;
152+
my$node =$self->{nodes}->[$index];
153+
return$node->psql(@args);
154+
}
155+
156+
1;

‎contrib/mmts/testeaux/Makefile‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
.PHONY: all
3+
4+
5+
subdir = contrib/multimaster/testeaux
6+
top_builddir = ../../..
7+
include$(top_builddir)/src/Makefile.global
8+
include$(top_srcdir)/contrib/contrib-global.mk
9+
10+
start:
11+
echo"Installing postgres to SRCDIR/tmp_install"
12+
cd$(abs_top_builddir)&& env DESTDIR='$(abs_top_builddir)'/tmp_install make install> /dev/null
13+
echo"Installing raftable to SRCDIR/tmp_install"
14+
cd$(abs_top_builddir)/contrib/raftable&& env DESTDIR='$(abs_top_builddir)'/tmp_install make install
15+
echo"Installing mmts to SRCDIR/tmp_install"
16+
cd$(abs_top_builddir)/contrib/mmts&& env DESTDIR='$(abs_top_builddir)'/tmp_install make install
17+
rm -rf$(CURDIR)/tmp_check/log
18+
echo"Ininializing new postgres cluster in contrib/mmts/tmp_install"
19+
cd$(srcdir)&& TESTDIR='$(CURDIR)' PERL5LIB=$(abs_top_builddir)/src/test/perl:$(PERL5LIB)$(with_temp_install) PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' perl run.pl
20+
21+
stop:
22+
echo"Stopping all instances in tmp_install"
23+
forDIRin ./tmp_check/data_node*;do \
24+
pg_ctl stop -m immediate -D$$DIR/pgdata;\
25+
rm -rf$$DIR;\
26+
done

‎contrib/mmts/Testeaux.pm‎renamed to ‎contrib/mmts/testeaux/Testeaux.pm‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
packageTesteaux;
22

3-
packagecombineaux
3+
packageCombineaux
44
{
55
subcombine
66
{
77
my ($workloads,$troubles) =@_;
88

9-
my$cluster =starteaux->deploy('lxc');
9+
my$cluster =Starteaux->deploy('lxc');
1010

1111
foreachmy$workload (@$workloads)
1212
{
1313
foreachmy$trouble (@$troubles)
1414
{
1515
print("run workload$workload during trouble$trouble\n");
1616
# FIXME: generate proper id instead of 'hello'
17-
stresseaux::start('hello',$workload,$cluster);
18-
# FIXME:add a time gap here
19-
troubleaux::cause($cluster,$trouble);
20-
# FIXME:add a time gap here
21-
stresseaux::stop('hello');
22-
troubleaux::fix($cluster);
17+
Stresseaux::start('hello',$workload,$cluster);
18+
sleep(1);# FIXME:will this work?
19+
Troubleaux::cause($cluster,$trouble);
20+
sleep(1);# FIXME:will this work?
21+
Stresseaux::stop('hello');
22+
Troubleaux::fix($cluster);
2323
}
2424
}
25+
26+
$cluster->destroy();
2527
}
2628
}
2729

28-
packagestresseaux
30+
packageStresseaux
2931
{
3032
substart
3133
{
@@ -42,15 +44,15 @@ package stresseaux
4244
}
4345
}
4446

45-
packagestarteaux
47+
packageStarteaux
4648
{
4749
subdeploy
4850
{
4951
my ($class,$driver,@args) =@_;
5052
my$self = {};
5153
print("deploy cluster using driver$driver\n");
5254
# fixme: implement
53-
returnbless$self,'starteaux';
55+
returnbless$self,'Starteaux';
5456
}
5557

5658
subup
@@ -62,7 +64,7 @@ package starteaux
6264

6365
subdown
6466
{
65-
my ($self,$id =@_;
67+
my ($self,$id) =@_;
6668
print("down node$id\n");
6769
# FIXME: implement
6870
}
@@ -80,6 +82,30 @@ package starteaux
8082
print("delay packets from$src to$dst by$msec msec\n");
8183
# FIXME: implement
8284
}
85+
86+
subdestroy
87+
{
88+
my ($self) =@_;
89+
print("destroy cluster$cluster\n");
90+
# FIXME: implement
91+
}
92+
}
93+
94+
packageTroubleaux
95+
{
96+
subcause
97+
{
98+
my ($cluster,$trouble) =@_;
99+
print("cause$trouble in cluster$cluster\n");
100+
# fixme: implement
101+
}
102+
103+
subfix
104+
{
105+
my ($cluster) =@_;
106+
print("fix cluster$cluster\n");
107+
# fixme: implement
108+
}
83109
}
84110

85111
1;

‎contrib/mmts/testeaux/Vagrantfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2)do |config|
5+
config.vm.box="ubuntu/ubuntu-15.04-snappy-core-stable"
6+
7+
5.timesdo |i|
8+
config.vm.define"n#{i+1}l"
9+
end
10+
11+
end
12+

‎contrib/mmts/testeaux/eaux.pl‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/perl
2+
3+
use Testeaux;
4+
5+
Combineaux::combine(
6+
['bank-transfers','pgbench-default'],
7+
['split-brain','time-shift'],
8+
)

‎contrib/mmts/testeaux/run.pl‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use strict;
2+
use warnings;
3+
use Cluster;
4+
use TestLib;
5+
use DBI;
6+
use File::Temp ();
7+
8+
$File::Temp::KEEP_ALL = 1;
9+
10+
my$cluster = new Cluster(3);
11+
$cluster->init;
12+
$cluster->configure;
13+
$cluster->start;
14+
$cluster->detach;
15+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp