Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for ansible-postgres
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
galaxy_info:
3+
author: Stas Kelvich
4+
description: Role to build and install postgres from sources
5+
company: PostgresPro
6+
license: MIT
7+
min_ansible_version: 1.9
8+
platforms:
9+
- name: Debian
10+
versions:
11+
- all
12+
- name: CentOS
13+
versions:
14+
- all
15+
galaxy_tags:
16+
- postgres
17+
- installer
18+
- db
19+
20+
dependencies: []
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# vim: ts=2 sts=2 sw=2 expandtab
2+
---
3+
4+
- name: ensure dependencies (Debian)
5+
apt: pkg={{item}} state=installed
6+
with_items:
7+
- git
8+
- automake
9+
- libtool
10+
- build-essential
11+
- bison
12+
- flex
13+
- libreadline-dev
14+
when: ansible_os_family == "Debian"
15+
become: yes
16+
17+
- name: ensure dependencies (RedHat)
18+
yum: name="@Development tools" state=present
19+
when: ansible_os_family == "RedHat"
20+
become: yes
21+
22+
- name: ensure dependencies (RedHat)
23+
yum: name={{item}} state=installed
24+
with_items:
25+
- git
26+
- automake
27+
- libtool
28+
- bison
29+
- flex
30+
- readline-devel
31+
when: ansible_os_family == "RedHat"
32+
become: yes
33+
34+
- name: increase semaphores
35+
sysctl: name=kernel.sem value="1000 128000 128 512"
36+
become: yes
37+
38+
- name: increase open files
39+
lineinfile:
40+
dest: /etc/security/limits.d/cluster.conf
41+
line: "{{ansible_ssh_user}} soft nofile 65535"
42+
state: present
43+
create: yes
44+
become: yes
45+
46+
#############################################################################
47+
48+
- name: clone postgres sources
49+
git: repo={{pg_repo}}
50+
dest={{pg_src}}
51+
version={{pg_version_tag}}
52+
depth=1
53+
accept_hostkey=True
54+
key_file={{pg_repo_key}}
55+
register: pg_sources
56+
57+
# XXX: Consider using file module with state=absent rather than running rm
58+
- name: force rebuild on changed sources
59+
#command: "rm -f {{pg_dst}}/bin/postgres"
60+
file: path="{{pg_dst}}/bin/postgres" state=absent
61+
when: pg_sources.changed
62+
63+
- name: build and install
64+
shell: env CFLAGS="-O0" ./configure --prefix={{pg_dst}} --enable-debug --without-zlib && make clean && make -j {{makejobs}} && make install
65+
args:
66+
chdir: "{{pg_src}}"
67+
creates: "{{pg_dst}}/bin/postgres"
68+
69+
#############################################################################
70+
71+
- name: stop postgres if it was running
72+
shell: "pkill -9 postgres || true"
73+
when: pg_destroy_and_init
74+
75+
- name: remove datadirs
76+
#command: "rm -rf {{pg_datadir}}"
77+
file: path="{{pg_datadir}}" state=absent
78+
when: pg_destroy_and_init
79+
80+
- name: create datadirs
81+
command: "{{pg_dst}}/bin/initdb {{pg_datadir}}"
82+
environment:
83+
LD_LIBRARY_PATH: "{{pg_dst}}/lib/"
84+
args:
85+
creates: "{{pg_datadir}}"
86+
when: pg_destroy_and_init
87+
88+
- name: configure postgres on datanodes
89+
lineinfile:
90+
dest: "{{pg_datadir}}/postgresql.conf"
91+
line: "{{item.line}}"
92+
state: present
93+
with_items: "{{pg_config}}"
94+
when: pg_destroy_and_init
95+
96+
- name: enable blind trust on datanodes
97+
lineinfile:
98+
dest: "{{pg_datadir}}/pg_hba.conf"
99+
line: "{{item}}"
100+
state: present
101+
with_items:
102+
- "host all all 0.0.0.0/0 trust"
103+
- "host replication all 0.0.0.0/0 trust"
104+
- "local replication all trust"
105+
when: pg_destroy_and_init
106+
107+
- name: start postgrespro
108+
shell: "{{pg_dst}}/bin/pg_ctl start -w -D {{pg_datadir}} -l {{pg_datadir}}/pg.log"
109+
environment:
110+
LD_LIBRARY_PATH: "{{pg_dst}}/lib/"
111+
when: pg_destroy_and_init
112+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# vim: ts=2 sts=2 sw=2 expandtab
2+
---
3+
makejobs: 4
4+
5+
pg_repo: git://git.postgresql.org/git/postgresql.git
6+
pg_repo_key: None
7+
pg_version_tag: master
8+
9+
pg_destroy_and_init: false
10+
11+
pg_port: 5432
12+
pg_config:
13+
- line: "synchronous_commit = off"
14+
- line: "listen_addresses = '*'"
15+
- line: "max_connections = 100"
16+
- line: "max_prepared_transactions = 100"
17+
- line: "port = {{pg_port}}"
18+
19+
pg_prefix: "{{ansible_env.HOME}}/pg_cluster"
20+
pg_src: "{{pg_prefix}}/src"
21+
pg_dst: "{{pg_prefix}}/install"
22+
pg_datadir: "{{pg_prefix}}/data_{{pg_port}}"
23+

0 commit comments

Comments
 (0)