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

Commite5fdc93

Browse files
committed
start/stop cluster
1 parent0621b7b commite5fdc93

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

‎testeaux/Cluster.pm

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

‎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
File renamed without changes.

‎testeaux/run.pl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use strict;
2+
use warnings;
3+
use Cluster;
4+
use TestLib;
5+
use DBI;
6+
use File::Temp ();
7+
8+
#use DBD::Pg ':async';
9+
10+
#@{; eval { TestLib::end_av->object_2svref } || [] } = ();
11+
12+
$File::Temp::KEEP_ALL = 1;
13+
14+
my$cluster = new Cluster(3);
15+
$cluster->init;
16+
$cluster->configure;
17+
$cluster->start;
18+
$cluster->detach;
19+
20+
21+
#sleep(3600);
22+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp