|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use PostgresNode; |
| 4 | +use Cluster; |
| 5 | +use TestLib; |
| 6 | +use Test::More tests => 5; |
| 7 | + |
| 8 | +my $cluster = new Cluster(3); |
| 9 | +$cluster->init(); |
| 10 | +$cluster->configure(); |
| 11 | +$cluster->start(); |
| 12 | + |
| 13 | +# XXXX: delete all '-n' ? |
| 14 | + |
| 15 | +# await online status |
| 16 | +$cluster->{nodes}->[0]->poll_query_until('postgres', "select 't'"); |
| 17 | + |
| 18 | +# init |
| 19 | +$cluster->pgbench(0, ('-i', -s => '10') ); |
| 20 | +$cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 21 | +$cluster->pgbench(1, ('-N', '-n', -T => '1') ); |
| 22 | +$cluster->pgbench(2, ('-N', '-n', -T => '1') ); |
| 23 | +$cluster->psql(0, 'postgres', "create extension multimaster"); |
| 24 | + |
| 25 | + |
| 26 | +# ################################################################################ |
| 27 | +# # auto recovery |
| 28 | +# ################################################################################ |
| 29 | +$cluster->{nodes}->[2]->stop('fast'); |
| 30 | +$cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 31 | +$cluster->{nodes}->[2]->start; |
| 32 | +$cluster->{nodes}->[2]->poll_query_until('postgres', "select 't'"); |
| 33 | +is($cluster->is_data_identic( (0,1,2) ), 1, "check auto recovery"); |
| 34 | + |
| 35 | +# ################################################################################ |
| 36 | +# # auto recovery with dead slots |
| 37 | +# ################################################################################ |
| 38 | + |
| 39 | +# ## TBD |
| 40 | + |
| 41 | +# ################################################################################ |
| 42 | +# # basebackup and add node |
| 43 | +# ################################################################################ |
| 44 | + |
| 45 | +my $new_connstr; |
| 46 | + |
| 47 | +$cluster->add_node(); |
| 48 | +$new_connstr = $cluster->{nodes}->[3]->{mmconnstr}; |
| 49 | +$cluster->psql(0, 'postgres', "SELECT mtm.add_node('$new_connstr')"); |
| 50 | +# await for comletion? |
| 51 | +$cluster->{nodes}->[3]->start; |
| 52 | +$cluster->{nodes}->[3]->poll_query_until('postgres', "select 't'"); |
| 53 | +$cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 54 | +$cluster->pgbench(3, ('-N', '-n', -T => '1') ); |
| 55 | +is($cluster->is_data_identic( (0,1,2,3) ), 1, "basebackup and add node"); |
| 56 | + |
| 57 | +# ################################################################################ |
| 58 | +# # soft stop / resume |
| 59 | +# ################################################################################ |
| 60 | + |
| 61 | +my ($stopped_out, $stopped_err); |
| 62 | + |
| 63 | +$cluster->psql(0, 'postgres', "select mtm.stop_node(3,'f')"); |
| 64 | +# await for comletion? |
| 65 | +$cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 66 | +$cluster->pgbench(1, ('-N', '-n', -T => '1') ); |
| 67 | +$cluster->pgbench(3, ('-N', '-n', -T => '1') ); |
| 68 | +$cluster->{nodes}->[2]->psql('postgres', "select 't'", |
| 69 | + stdout => \$stopped_out, stderr => \$stopped_err); |
| 70 | +is($cluster->is_data_identic( (0,1,3) ), 1, "soft stop / resume"); |
| 71 | +is($stopped_out eq '' && $stopped_err ne '', 1, "soft stop / resume"); |
| 72 | + |
| 73 | +$cluster->psql(0, 'postgres', "select mtm.resume_node(3)"); |
| 74 | +$cluster->{nodes}->[2]->poll_query_until('postgres', "select 't'"); |
| 75 | +$cluster->pgbench(2, ('-N', '-n', -T => '1') ); |
| 76 | +is($cluster->is_data_identic( (0,1,2,3) ), 1, "soft stop / resume"); |
| 77 | + |
| 78 | +# ################################################################################ |
| 79 | +# # hard stop / basebackup / recover |
| 80 | +# ################################################################################ |
| 81 | + |
| 82 | +# diag('Stopping node with slot drop'); |
| 83 | +# $cluster->psql(0, 'postgres', "select mtm.stop_node(3,'t')"); |
| 84 | +# # await for comletion? |
| 85 | +# $cluster->{nodes}->[2]->stop(); |
| 86 | + |
| 87 | +# $cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 88 | +# $cluster->pgbench(1, ('-N', '-n', -T => '1') ); |
| 89 | +# $cluster->pgbench(3, ('-N', '-n', -T => '1') ); |
| 90 | +# is($cluster->is_data_identic( (0,1,3) ), 1, "hard stop / resume"); |
| 91 | + |
| 92 | +# $cluster->psql(0, 'postgres', "select mtm.recover_node(3)"); |
| 93 | + |
| 94 | +# # now we need to perform backup from live node |
| 95 | +# $cluster->add_node(port => $cluster->{nodes}->[2]->{port}, |
| 96 | +# arbiter_port => $cluster->{nodes}->[2]->{arbiter_port}, |
| 97 | +# node_id => 3); |
| 98 | +# diag("preparing to start"); |
| 99 | +# $cluster->{nodes}->[4]->start; |
| 100 | +# $cluster->{nodes}->[4]->poll_query_until('postgres', "select 't'"); |
| 101 | + |
| 102 | +# $cluster->pgbench(0, ('-N', '-n', -T => '1') ); |
| 103 | +# $cluster->pgbench(1, ('-N', '-n', -T => '1') ); |
| 104 | +# $cluster->pgbench(3, ('-N', '-n', -T => '1') ); |
| 105 | +# $cluster->pgbench(4, ('-N', '-n', -T => '1') ); |
| 106 | +# is($cluster->is_data_identic( (0,1,3,4) ), 1, "hard stop / resume"); |
0 commit comments