Skip to content

Commit accef4c

Browse files
committed
2 parents e2b5356 + ec9e963 commit accef4c

File tree

15 files changed

+306
-68
lines changed

15 files changed

+306
-68
lines changed

contrib/mmts/testeaux/RemoteCluster.pm renamed to contrib/mmts/testeaux/lib/RemoteCluster.pm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,21 @@ sub configure
8080
max_wal_senders = 10
8181
wal_sender_timeout = 0
8282
max_replication_slots = 10
83+
84+
tcp_keepalives_idle = 2
85+
tcp_keepalives_interval = 1
86+
tcp_keepalives_count = 2
87+
8388
shared_preload_libraries = 'raftable,multimaster'
8489
multimaster.workers = 10
8590
multimaster.queue_size = 10485760 # 10mb
8691
multimaster.node_id = $id
8792
multimaster.conn_strings = '$connstr'
88-
multimaster.use_raftable = true
93+
multimaster.use_raftable = false
8994
multimaster.ignore_tables_without_pk = true
9095
multimaster.twopc_min_timeout = 60000
96+
multimaster.twopc_prepare_ratio = 1000 #%
97+
9198
raftable.id = $id
9299
raftable.peers = '$raftpeers'
93100
));
@@ -130,9 +137,9 @@ sub psql
130137
}
131138

132139
# XXX: test
133-
my $cluster = new RemoteCluster('ssh-config');
134-
$cluster->init;
135-
$cluster->configure;
136-
$cluster->start;
137-
140+
#my $cluster = new RemoteCluster('ssh-config');
141+
# $cluster->init;
142+
# $cluster->configure;
143+
# $cluster->start;
144+
#
138145
1;

contrib/mmts/testeaux/RemoteNode.pm renamed to contrib/mmts/testeaux/lib/RemoteNode.pm

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package RemoteNode;
33
use strict;
44
use warnings;
55
use Net::OpenSSH;
6+
use IPC::Run;
67

78
sub new
89
{
@@ -24,9 +25,8 @@ sub new
2425

2526
bless $self, $class;
2627

27-
# kill postgres here to ensure
28-
# predictable initial state.
29-
$self->execute("pkill -9 postgres || true");
28+
$self->execute("sudo iptables -F");
29+
$self->execute("sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT");
3030

3131
return $self;
3232
}
@@ -35,7 +35,7 @@ sub connstr
3535
{
3636
my ($self, $dbname) = @_;
3737

38-
"host=$self->{_host} dbname=$dbname";
38+
"host=$self->{_host} dbname=$dbname user=$self->{_user}";
3939
}
4040

4141
sub execute
@@ -71,6 +71,10 @@ sub init
7171
my $pgbin = $self->{_pgbin};
7272
my $pgdata = $self->{_pgdata};
7373

74+
# kill postgres here to ensure
75+
# predictable initial state.
76+
$self->execute("pkill -9 postgres || true");
77+
7478
$self->execute("rm -rf $pgdata");
7579
$self->execute("env LANG=C LC_ALL=C $pgbin/initdb -D $pgdata -A trust -N");
7680

@@ -114,4 +118,42 @@ sub append_conf
114118
$self->execute($cmd);
115119
}
116120

121+
sub psql
122+
{
123+
my ($self, $dbname, $sql) = @_;
124+
my $stderr;
125+
my $stdout;
126+
127+
my @psql_command =
128+
('psql', '-XAtq', '-d', $self->connstr($dbname), '-f', '-');
129+
130+
my @ipcrun_command = (\@psql_command, '<', \$sql);
131+
#push @ipcrun_command, '>', $stdout;
132+
#push @ipcrun_command, '2>', $stderr;
133+
134+
IPC::Run::run @ipcrun_command;
135+
my $ret = $?;
136+
137+
return $ret;
138+
}
139+
140+
sub net_deny_in
141+
{
142+
my ($self) = @_;
143+
$self->execute("sudo iptables -A INPUT -j DROP");
144+
}
145+
146+
sub net_deny_out
147+
{
148+
my ($self) = @_;
149+
$self->execute("sudo iptables -A OUTPUT -j DROP");
150+
}
151+
152+
sub net_allow
153+
{
154+
my ($self) = @_;
155+
$self->execute("sudo iptables -D INPUT -j DROP");
156+
$self->execute("sudo iptables -D OUTPUT -j DROP");
157+
}
158+
117159
1;

contrib/mmts/testeaux/provision.yml

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,9 @@
33
- hosts: all
44

55
roles:
6-
- role: kelvich.postgres
6+
- role: postgres
77
pg_port: 5432
88
pg_repo: https://github.com/postgrespro/postgres_cluster.git
99
pg_version_tag: master
1010
pg_destroy_and_init: true
11-
pg_config_role:
12-
- line: "multimaster.buffer_size = 65536"
13-
14-
tasks:
15-
- name: generate connstrings
16-
set_fact:
17-
connstr: "host={{item}} user={{ansible_ssh_user}} dbname=postgres"
18-
with_items:
19-
groups['all'] | reverse | batch(nnodes | d(3) | int) | first
20-
register: connstrs
21-
22-
- name: make a list
23-
set_fact:
24-
connections: "{{ connstrs.results | map(attribute='ansible_facts.connstr') | join(', ') }}"
25-
26-
- debug: var=hostvars
27-
28-
- debug: var=inventory_hostname
29-
30-
#- debug: var=hostvars[inventory_hostname]
31-
32-
- name: build raftable
33-
shell: "make clean && make -j {{makejobs}} install"
34-
args:
35-
chdir: "{{pg_src}}/contrib/raftable"
36-
37-
- name: build multimaster
38-
shell: "make clean && make -j {{makejobs}} install"
39-
args:
40-
chdir: "{{pg_src}}/contrib/mmts"
41-
42-
- name: enable dtm extension on datanodes
43-
lineinfile:
44-
dest: "{{pg_datadir}}/postgresql.conf"
45-
line: "{{item}}"
46-
state: present
47-
with_items:
48-
- "wal_level = logical"
49-
- "max_wal_senders = 10"
50-
- "wal_sender_timeout = 0"
51-
- "max_replication_slots = 10"
52-
- "max_connections = 200"
53-
- "max_worker_processes = 100"
54-
- "shared_preload_libraries = 'raftable,multimaster'"
55-
- "multimaster.conn_strings = '{{connections}}'"
56-
- "multimaster.node_id = {{ inventory_hostname | regex_replace('([0-9]+)', '\\1') }}"
57-
- "multimaster.buffer_size = 65536"
58-
- "multimaster.queue_size = 1073741824"
59-
- "multimaster.arbiter_port = 5600"
60-
- "multimaster.vacuum_delay = 1"
61-
- "multimaster.workers = 32"
62-
- "multimaster.use_dtm = 1"
63-
64-
- name: restart postgrespro
65-
command: "{{pg_dst}}/bin/pg_ctl restart -w -D {{pg_datadir}} -l {{pg_datadir}}/pg.log"
66-
environment:
67-
LD_LIBRARY_PATH: "{{pg_dst}}/lib/"
6811

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Role Name
2+
=========
3+
4+
A brief description of the role goes here.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
10+
11+
Role Variables
12+
--------------
13+
14+
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
15+
16+
Dependencies
17+
------------
18+
19+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
20+
21+
Example Playbook
22+
----------------
23+
24+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25+
26+
- hosts: servers
27+
roles:
28+
- { role: username.rolename, x: 42 }
29+
30+
License
31+
-------
32+
33+
BSD
34+
35+
Author Information
36+
------------------
37+
38+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# defaults file for ansible-postgres

0 commit comments

Comments
 (0)