Skip to content

Commit 737f38a

Browse files
committed
2 parents b4e4de7 + d76d609 commit 737f38a

File tree

5 files changed

+192
-13
lines changed

5 files changed

+192
-13
lines changed

contrib/mmts/tests2/provision.yml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
3+
- hosts: all
4+
5+
vars:
6+
pg_port: 15432
7+
pg_prefix: "{{ansible_env.HOME}}/pg_cluster"
8+
pg_src: "{{pg_prefix}}/src"
9+
pg_dst: "{{pg_prefix}}/install"
10+
pg_datadir: "{{pg_prefix}}/data_{{pg_port}}"
11+
pg_repo: https://github.com/postgrespro/postgres_cluster.git
12+
pg_version_tag: master
13+
pg_destroy_and_init: true
14+
makejobs: 4
15+
16+
tasks:
17+
18+
- name: ensure dependencies (Debian)
19+
apt: pkg={{item}} state=installed
20+
with_items:
21+
- git
22+
- automake
23+
- libtool
24+
- build-essential
25+
- bison
26+
- flex
27+
- libreadline-dev
28+
when: ansible_os_family == "Debian"
29+
become: yes
30+
31+
- name: ensure dependencies (RedHat)
32+
yum: name="@Development tools" state=present
33+
when: ansible_os_family == "RedHat"
34+
become: yes
35+
36+
- name: ensure dependencies (RedHat)
37+
yum: name={{item}} state=installed
38+
with_items:
39+
- git
40+
- automake
41+
- libtool
42+
- bison
43+
- flex
44+
- readline-devel
45+
when: ansible_os_family == "RedHat"
46+
become: yes
47+
48+
- name: increase semaphores
49+
sysctl: name=kernel.sem value="1000 128000 128 512"
50+
become: yes
51+
52+
- name: increase open files
53+
lineinfile:
54+
dest: /etc/security/limits.d/cluster.conf
55+
line: "{{ansible_ssh_user}} soft nofile 65535"
56+
state: present
57+
create: yes
58+
become: yes
59+
60+
- name: clone postgres sources
61+
git: repo={{pg_repo}}
62+
dest={{pg_src}}
63+
version={{pg_version_tag}}
64+
depth=1
65+
accept_hostkey=True
66+
register: pg_sources
67+
68+
- name: build and install
69+
shell: env CFLAGS="-O0" ./configure --prefix={{pg_dst}} --enable-debug --without-zlib && make clean && make -j {{makejobs}} && make install
70+
args:
71+
chdir: "{{pg_src}}"
72+
creates: "{{pg_dst}}/bin/postgres"
73+
74+
- name: build raftable
75+
shell: "make clean && make -j {{makejobs}} install"
76+
args:
77+
chdir: "{{pg_src}}/contrib/raftable"
78+
79+
- name: build multimaster
80+
shell: "make clean && make -j {{makejobs}} install"
81+
args:
82+
chdir: "{{pg_src}}/contrib/mmts"
83+
84+
###############################################################
85+
86+
- name: stop postgres if it was running
87+
shell: "pkill -9 postgres || true"
88+
when: pg_destroy_and_init
89+
90+
- name: remove datadirs on datanodes
91+
command: "rm -rf {{pg_datadir}}"
92+
when: pg_destroy_and_init
93+
94+
- name: create datadirs on datanodes
95+
command: "{{pg_dst}}/bin/initdb {{pg_datadir}}"
96+
environment:
97+
LD_LIBRARY_PATH: "{{pg_dst}}/lib/"
98+
args:
99+
creates: "{{pg_datadir}}"
100+
101+
- name: generate mmts connstrings
102+
set_fact:
103+
connstr: "host={{item}} user={{ansible_ssh_user}} port={{pg_port}} dbname=postgres"
104+
raft_connstr: "{{ hostvars[item]['node_id'] }}:{{item}}:8989"
105+
with_items:
106+
"{{ groups['nodes'] | reverse | batch(nnodes | d(3) | int) | first }}"
107+
register: connstrs
108+
109+
- name: collect raftable connstrings
110+
set_fact:
111+
mm_connstr: "{{ connstrs.results | map(attribute='ansible_facts.connstr') | join(', ') }}"
112+
raft_connstr: "{{ connstrs.results | map(attribute='ansible_facts.raft_connstr') | join(', ') }}"
113+
114+
- name: configure postgres on datanodes
115+
lineinfile:
116+
dest: "{{pg_datadir}}/postgresql.conf"
117+
line: "{{item}}"
118+
state: present
119+
with_items:
120+
- "listen_addresses = '*'"
121+
- "max_prepared_transactions = 800"
122+
- "shared_buffers = 3GB"
123+
- "max_connections = 2048"
124+
- "port = {{pg_port}}"
125+
- "synchronous_commit = off"
126+
- "wal_level = logical"
127+
- "max_worker_processes = 15"
128+
- "max_replication_slots = 10"
129+
- "max_wal_senders = 10"
130+
- "log_checkpoints = on"
131+
- "log_autovacuum_min_duration = 0"
132+
- "shared_preload_libraries = 'raftable,multimaster'"
133+
- "default_transaction_isolation = 'repeatable read'"
134+
- "raftable.id = {{ node_id }}"
135+
- "raftable.peers = '{{ raft_connstr }}'"
136+
- "multimaster.workers = 4"
137+
- "multimaster.arbiter_port = {{ 7777 }}"
138+
- "multimaster.use_raftable = true"
139+
- "multimaster.queue_size=52857600"
140+
- "multimaster.ignore_tables_without_pk = 1"
141+
- "multimaster.node_id = {{ node_id }}"
142+
- "multimaster.conn_strings = '{{ mm_connstr }}'"
143+
- "multimaster.heartbeat_recv_timeout = 1000"
144+
- "multimaster.heartbeat_send_timeout = 250"
145+
- "multimaster.twopc_min_timeout = 40000"
146+
147+
- name: enable blind trust on datanodes
148+
lineinfile:
149+
dest: "{{pg_datadir}}/pg_hba.conf"
150+
line: "{{item}}"
151+
state: present
152+
with_items:
153+
- "host all all 0.0.0.0/0 trust"
154+
- "host replication all 0.0.0.0/0 trust"
155+
- "local replication all trust"
156+
157+
- name: start postgrespro
158+
shell: "ulimit -c unlimited && {{pg_dst}}/bin/pg_ctl start -w -D {{pg_datadir}} -l {{pg_datadir}}/pg.log"
159+
environment:
160+
LD_LIBRARY_PATH: "{{pg_dst}}/lib/"
161+

contrib/raftable/raft/src/raft.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,13 @@ int raft_emit(raft_t r, raft_update_t update) {
753753
bool raft_applied(raft_t r, int id, int index) {
754754
if (r->me == id)
755755
{
756-
return r->log.applied >= index;
756+
return r->log.applied > index;
757757
}
758758
else
759759
{
760760
raft_peer_t *p = r->peers + id;
761761
if (!p->up) return false;
762-
return p->applied >= index;
762+
return p->applied > index;
763763
}
764764
}
765765

contrib/raftable/t/000_basic.pl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,33 @@ sub start_nodes
6868
world => genstr(3000),
6969
);
7070

71+
my $retries = 100;
7172
my $timeout_ms = 1000;
7273

73-
$able->psql('postgres', "select raftable('hello', '$tests{hello}', $timeout_ms);");
74-
$baker->psql('postgres', "select raftable('and', '$tests{and}', $timeout_ms);");
75-
$charlie->psql('postgres', "select raftable('goodbye', '$tests{goodbye}', $timeout_ms);");
74+
sub trysql {
75+
my ($noderef, $sql) = @_;
76+
while ($retries > 0) {
77+
diag("try sql: ". substr($sql, 0, 60));
78+
my ($rc, $stdout, $stderr) = $noderef->psql('postgres', $sql);
79+
if (index($stderr, "after") == -1) {
80+
return;
81+
} else {
82+
$retries--;
83+
diag($stderr);
84+
diag("psql failed, $retries retries left");
85+
}
86+
}
87+
BAIL_OUT('no psql retries left');
88+
}
89+
90+
trysql($able, "select raftable('hello', '$tests{hello}', $timeout_ms);");
91+
trysql($baker, "select raftable('and', '$tests{and}', $timeout_ms);");
92+
trysql($charlie, "select raftable('goodbye', '$tests{goodbye}', $timeout_ms);");
7693
$baker->stop;
77-
$able->psql('postgres', "select raftable('world', '$tests{world}', $timeout_ms);");
94+
trysql($able, "select raftable('world', '$tests{world}', $timeout_ms);");
7895

7996
$baker->start;
80-
$baker->psql('postgres', "select raftable_sync($timeout_ms);");
97+
trysql($baker, "select raftable_sync($timeout_ms);");
8198
while (my ($key, $value) = each(%tests))
8299
{
83100
my ($rc, $stdout, $stderr) = $baker->psql('postgres', "select raftable('$key');");

contrib/raftable/tests/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if [ ! -s "$PGDATA/PG_VERSION" ]; then
5353

5454
############################################################################
5555

56-
RAFT_PEERS='1:172.18.0.2:6666, 2:172.18.0.4:6666, 3:172.18.0.3:6666'
56+
RAFT_PEERS='1:node1:6666, 2:node2:6666, 3:node3:6666'
5757

5858
cat <<-EOF >> $PGDATA/postgresql.conf
5959
listen_addresses='*'

contrib/raftable/worker.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static void attend(Client *c)
334334
c->good = false;
335335
} else {
336336
// a sync command
337-
c->expect.index = raft_progress(raft);
337+
c->expect.index = raft_progress(raft) - 1;
338338
if (raft_applied(raft, c->expect.id, c->expect.index))
339339
{
340340
int ok = 1;
@@ -389,9 +389,12 @@ static bool tick(int timeout_ms)
389389
int numready;
390390
Client *c;
391391
bool raft_ready = false;
392-
393-
fd_set readfds = server.all;
392+
fd_set readfds;
394393
struct timeval timeout = ms2tv(timeout_ms);
394+
395+
drop_bads();
396+
397+
readfds = server.all;
395398
numready = select(server.maxfd + 1, &readfds, NULL, NULL, &timeout);
396399
if (numready == -1)
397400
{
@@ -423,8 +426,6 @@ static bool tick(int timeout_ms)
423426
c++;
424427
}
425428

426-
drop_bads();
427-
428429
return raft_ready;
429430
}
430431

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy