Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b6ae844

Browse files
committed
Adapted devops/ for 'broadcast' version.
1 parent ea256a5 commit b6ae844

16 files changed

+343
-228
lines changed

bin/shardman_init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ done
3737
start_nodes
3838
for port in $lord_port "${worker_ports[@]}"; do
3939
createdb -p $port `whoami`
40+
echo "creating pg_shardman extension..."
4041
psql -p $port -c "create extension pg_shardman cascade;"
4142
done
4243

devops/ec2.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
vpc_subnet_id: subnet-e0e2d99a
1212
image: ami-1e339e71 # ubuntu xenial backed by ebs
1313
region: eu-central-1
14+
instance_type: c3.2xlarge
1415

1516
tasks:
1617

1718
# image here is
18-
- import_tasks: tasks/ec2.yml instance_type="t2.micro"
19+
- import_tasks: tasks/ec2.yml
1920
tags:
20-
- micro
21+
- launch
2122

22-
# image here is ubuntu xenial backed by instance store
23-
- import_tasks: tasks/ec2.yml instance_type="c3.2xlarge" image="ami-4199282e"
23+
# image ubuntu xenial backed by instance store
24+
- import_tasks: tasks/ec2.yml image="ami-4199282e"
2425
tags:
25-
- c3.2xlarge
26+
- launch_instance_store
2627

2728
# good for both launch and termination
2829
- import_tasks: tasks/clean_ec2_cache.yml

devops/init.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
### initdb, send configs and add all workers.
1+
### initdb, send configs, create extension and add all workers.
2+
# controlling vars: use_pgbouncer, nodes_in_repgroup
23

34
---
45
- hosts: nodes
@@ -11,9 +12,6 @@
1112
tags:
1213
- initdb
1314

14-
- name: kill bouncer
15-
shell: 'pkill -SIGINT pgbouncer || true'
16-
1715
- name: remove datadirs on datanodes
1816
file: path={{pg_datadir}} state=absent
1917
tags:
@@ -56,22 +54,30 @@
5654
- create_ext
5755

5856
- hosts: shardlord
57+
vars:
58+
nodes_in_repgroup: 999999
59+
5960
environment:
6061
PATH: "{{ pg_dst }}/bin:{{ ansible_env.PATH }}"
6162

6263
tasks:
63-
- name: add ec2 workers
64+
- name: add ec2 workers, nodes_in_repgroup is {{ nodes_in_repgroup }}
6465
command: >
6566
psql -p {{ pg_port }} -c "select shardman.add_node(
66-
'hostaddr={{ hostvars[item]['ec2_private_ip_address'] }} port={{ ( use_pgbouncer | bool ) | ternary(pgbouncer_port, pg_port) }}')"
67-
with_items: "{{ groups.ec2_workers }}"
67+
'hostaddr={{ hostvars[item.1]['ec2_private_ip_address'] }} port={{ pg_port }}',
68+
'hostaddr={{ hostvars[item.1]['ec2_private_ip_address'] }} port={{ ( use_pgbouncer | bool ) | ternary(pgbouncer_port, pg_port) }}',
69+
'group_{{ item.0 // (nodes_in_repgroup | int) }}')
70+
"
71+
with_indexed_items: "{{ groups.ec2_workers }}"
6872
tags:
6973
- add_nodes
7074

71-
- name: add manual workers
75+
- name: add manual workers, nodes_in_repgroup is {{ nodes_in_repgroup }}
7276
command: >
7377
psql -p {{ pg_port }} -c "select shardman.add_node(
74-
'hostaddr={{ item }} port={{ pg_port }}')"
75-
with_items: "{{ groups.manual_workers }}"
78+
'hostaddr={{ item.1 }} port={{ pg_port }}',
79+
'hostaddr={{ item.1 }} port={{ ( use_pgbouncer | bool ) | ternary(pgbouncer_port, pg_port) }}',
80+
'group_{{ item.0 // (nodes_in_repgroup | int) }}')"
81+
with_indexed_items: "{{ groups.manual_workers }}"
7682
tags:
7783
- add_nodes

devops/inventory

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ pg_prefix="/tmp/pg"
2727
pg_src="{{pg_prefix}}/src"
2828
cflags="-O2"
2929
pg_dst="{{pg_prefix}}/install"
30-
pg_datadir="{{pg_prefix}}/data_{{pg_port}}"
30+
# pg_datadir="{{pg_prefix}}/data_{{pg_port}}"
31+
pg_datadir="/mnt/data_{{pg_port}}"
3132
pg_logfile="{{pg_datadir}}/pg.log"
3233
pg_conffile="{{pg_datadir}}/postgresql.conf"
3334
pg_port=5432
@@ -37,17 +38,21 @@ pgbouncer_dst = "{{ pg_prefix }}/pgbouncer_install"
3738
pgbouncer_conf = "/home/{{ ansible_user }}/pgbouncer.conf"
3839
pgbouncer_port = 6543
3940
pgbouncer_logfile = /tmp/pgbouncer.log
41+
pgbouncer_pool_mode = session
42+
pgbouncer_pool_size = 10
4043
use_pgbouncer = False
4144

42-
pathman_repo=https://github.com/postgrespro/pg_pathman.git
45+
pathman_repo=https://github.com/arssher/pg_pathman
4346
pathman_src="{{pg_prefix}}/pg_pathman"
44-
pathman_version_tag=master
47+
pathman_version_tag=foreign_copy_from
4548

4649
shardman_repo=https://github.com/postgrespro/pg_shardman.git
4750
shardman_src="{{pg_prefix}}/pg_shardman"
48-
shardman_version_tag=master
51+
# shardman_version_tag=master
4952
# trigger based replication
5053
# shardman_version_tag=tbr-2pc
54+
# sync version
55+
shardman_version_tag=broadcast
5156

5257
shardman_shardlord_connstring="host={{ shardlord_ip }} port={{ pg_port }} user={{ ansible_user }}"
5358

devops/logs.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717
tags:
1818
fetch
1919

20-
- name: find out node id from log
21-
local_action: shell grep -m 1 -o -P 'SHND \d' logs/{{ inventory_hostname }}.log | sed 's/SHND //'
22-
register: node_id
23-
tags:
24-
node_symlink
25-
26-
- name: create symlink 'node_id'.log -> 'ip'.log
27-
local_action: file
28-
src={{ inventory_hostname }}.log
29-
dest={{ logs }}/{{ node_id.stdout }}.log
30-
force=yes
31-
state=link
32-
3320
- name: touch logs/united.log
3421
local_action: copy content="" dest={{ logs }}/united.log
3522
run_once: true

devops/monitor_wal_lag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
app_name=`psql -qtA -c "select application_name from pg_stat_replication where application_name ~ '.*accounts.*' limit 1;"`
4+
app_name=$(psql -qtA -c "select application_name from pg_stat_replication where application_name ~ '.*sub_[0-9]+_[0-9]+.*' limit 1;")
55

66
> wal_lag.txt
77
while true; do

devops/pgbench_ddl.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
drop table if exists pgbench_accounts;
2+
create table pgbench_accounts (
3+
aid int not null,
4+
bid int,
5+
abalance int,
6+
filler char(84)
7+
);
8+
9+
drop table if exists pgbench_tellers;
10+
create table pgbench_tellers (
11+
tid int not null,
12+
bid int,
13+
tbalance int,
14+
filler char(84)
15+
);
16+
17+
18+
drop table if exists pgbench_branches;
19+
create table pgbench_branches (
20+
bid int not null,
21+
bbalance int,
22+
filler char(88)
23+
);
24+
25+
alter table pgbench_branches add primary key (bid);
26+
alter table pgbench_tellers add primary key (tid);
27+
alter table pgbench_accounts add primary key (aid);

devops/pgbench_prepare.yml

Lines changed: 40 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
### create pgbench_history everywhere, create pgbench tables on init node,
2-
# shard them. TODO: drop sharded tables.
3-
# Controlling vars: scale, nparts, repfactor, use_pgbouncer
1+
### create pgbench_history everywhere, create pgbench tables,
2+
# shard them.
3+
# Controlling vars: scale, nparts, redundancy, use_pgbouncer, pgbouncer_pool_mode,
4+
# nodes_in_repgroup
45

5-
# We need this since we don't drop tables yet
66
- import_playbook: init.yml
77
tags:
88
- init
@@ -12,93 +12,66 @@
1212
PATH: "{{ pg_dst }}/bin:{{ ansible_env.PATH }}"
1313

1414
tasks:
15-
- name: recreate pgbench_history on workers
15+
- name: recreate pgbench_history on workers, drop other pgbench tables
1616
command: >
1717
psql -p {{ pg_port }} -c "drop table if exists pgbench_history;
18+
do $$
19+
declare
20+
rname text;
21+
begin
22+
for rname in (select relname from pg_class where relname ~ 'pgbench_.*' and relkind = 'r') loop
23+
execute format('drop table if exists %I cascade', rname);
24+
end loop;
25+
end
26+
$$ LANGUAGE 'plpgsql';
27+
drop table if exists pgbench_accounts cascade;
28+
drop table if exists pgbench_tellers cascade;
29+
drop table if exists pgbench_branches cascade;
1830
create table pgbench_history (tid int, bid int, aid int,
1931
delta int, mtime timestamp, filler char(22));"
2032
tags:
2133
- pgbench_history
2234

23-
- name: initialize pgbench everywhere to avoid count(*) failure, scale {{ scale }}
24-
command: >
25-
pgbench -p {{ pg_port }} -s {{ scale }} -i
26-
tags:
27-
- pgbench_init
28-
29-
30-
- hosts: init_node
35+
- hosts: shardlord
3136
vars:
32-
scale: 10
3337
nparts: 10
34-
repfactor: 0
35-
rebalance: true
36-
tellers_branches: true
38+
redundancy: 0
3739
environment:
3840
PATH: "{{ pg_dst }}/bin:{{ ansible_env.PATH }}"
3941

4042
tasks:
41-
- name: drop old pgbench tables with deps
42-
command: >
43-
psql -p {{ pg_port }} -c "
44-
drop table if exists pgbench_accounts cascade;
45-
drop table if exists pgbench_tellers cascade;
46-
drop table if exists pgbench_branches cascade;
47-
drop table if exists pgbench_tellers cascade;
48-
drop table if exists pgbench_accounts cascade;
49-
"
50-
tags:
51-
- pgbench_init
43+
- name: copy pgbench_ddl.sql
44+
copy:
45+
src: pgbench_ddl.sql
46+
dest: "/home/{{ ansible_user }}/pgbench_ddl.sql"
5247

53-
- name: learn init node id
48+
- name: create pgbench tables on shardlord
5449
command: >
55-
psql -p {{ pg_port }} -qtA -c "select shardman.my_id();"
56-
register: my_id
57-
until: my_id.stdout != ""
58-
retries: 19481948 # oh my
59-
tags:
60-
- pgbench_init
50+
psql -p {{ pg_port }} -f pgbench_ddl.sql
6151
62-
- name: initialize pgbench, scale {{ scale }}
63-
command: >
64-
pgbench -p {{ pg_port }} -s {{ scale }} -i
65-
tags:
66-
- pgbench_init
67-
68-
- name: create_hash_partitions for pgbench_accounts, nparts {{ nparts }}
52+
- name: create_hash_partitions for pgbench_accounts, nparts {{ nparts }}, redundancy {{ redundancy }}
6953
command: >
7054
psql -p {{ pg_port }} -c "
71-
select shardman.create_hash_partitions({{ my_id.stdout }}, 'pgbench_accounts', 'aid', {{ nparts }}, {{ rebalance }});
72-
select shardman.set_replevel('pgbench_accounts', {{ repfactor }});
55+
select shardman.create_hash_partitions('pgbench_accounts', 'aid', {{ nparts }}, {{ redundancy }});
56+
select shardman.create_hash_partitions('pgbench_tellers', 'tid', {{ nparts }}, {{ redundancy }});
57+
select shardman.create_hash_partitions('pgbench_branches', 'bid', {{ nparts }}, {{ redundancy }});
7358
"
7459
tags:
75-
- create_hash_partitions_accounts
60+
- create_hash_partitions
7661

77-
- name: create_hash_partitions for branches & tellers, nparts {{ nparts }}, repfactor {{ repfactor }}
78-
command: >
79-
psql -p {{ pg_port }} -c "
80-
select shardman.create_hash_partitions({{ my_id.stdout }}, 'pgbench_tellers', 'tid', {{ nparts }}, {{ rebalance }});
81-
select shardman.create_hash_partitions({{ my_id.stdout }}, 'pgbench_branches', 'bid', {{ nparts }}, {{ rebalance }});
82-
select shardman.set_replevel('pgbench_tellers', {{ repfactor }});
83-
select shardman.set_replevel('pgbench_branches', {{ repfactor }});
84-
"
85-
tags:
86-
- create_hash_partitions_tellers_branches
87-
when: tellers_branches | bool
88-
89-
- hosts: shardlord
62+
- hosts: init_node
63+
vars:
64+
scale: 10
65+
nparts: 10
66+
redundancy: 0
67+
rebalance: true
9068
environment:
9169
PATH: "{{ pg_dst }}/bin:{{ ansible_env.PATH }}"
9270

9371
tasks:
94-
- name: wait for cmd finishing
72+
# requires patched pgbench
73+
- name: initialize pgbench, scale {{ scale }}
9574
command: >
96-
psql -p {{ pg_port }} -qtA -c "
97-
select count(*) from shardman.cmd_log
98-
where status in ('waiting', 'in progress');
99-
"
100-
register: jobs_count
101-
until: jobs_count.stdout == "0"
102-
retries: 19481948 # oh my
75+
pgbench -p {{ pg_port }} -s {{ scale }} -i --no-ddl
10376
tags:
104-
- wait
77+
- pgbench_init

devops/pgbench_run.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### Run pgbench benchmark.
2-
# Controlling vars: tmstmp (true/false), tname, pgbench_opts
2+
# Controlling vars: tmstmp (true/false), tname, pgbench_opts, active_workers
33

44

55
# set global var to use in all plays, oh my

devops/postgresql.conf.common.example

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ log_timezone = 'Europe/Moscow'
33

44
listen_addresses = '*'
55

6-
log_min_messages = NOTICE
6+
log_min_messages = WARNING
77
client_min_messages = NOTICE
88
log_replication_commands = on
9+
log_line_prefix = '%m [%r][%p]'
10+
# log_statement = 'all'
911

1012
# log_statement = 'all'
1113
# logging_collector = on
@@ -30,10 +32,7 @@ fsync = on
3032
autovacuum = off
3133
synchronous_commit = on
3234
# synchronous_commit = local
33-
shardman.sync_replicas = on
34-
35-
shardman.shardlord_dbname = ubuntu
36-
shardman.poll_interval = 500 # long operations poll frequency in milliseconds
35+
shardman.sync_replication = on
3736

3837
max_prepared_transactions = 100000
3938
postgres_fdw.use_2pc = on

0 commit comments

Comments
 (0)