|
2 | 2 | use warnings;
|
3 | 3 | use Cluster;
|
4 | 4 | use TestLib;
|
5 |
| -use Test::More tests => 3; |
| 5 | +use Test::More tests => 4; |
6 | 6 |
|
7 | 7 | my $cluster = new Cluster(3);
|
8 | 8 | $cluster->init();
|
9 | 9 | $cluster->configure();
|
10 | 10 | $cluster->start();
|
11 | 11 | sleep(10);
|
12 | 12 |
|
| 13 | +######################################################## |
| 14 | +# Check data integrity before and after recovery |
| 15 | +######################################################## |
| 16 | + |
| 17 | +$cluster->pgbench(1, ('-i', -s => '10') ); |
| 18 | +$cluster->pgbench(0, ('-n','-N', -T => '4') ); |
| 19 | +$cluster->pgbench(1, ('-n','-N', -T => '4') ); |
| 20 | +$cluster->pgbench(2, ('-n','-N', -T => '4') ); |
| 21 | + |
| 22 | + |
| 23 | +my $hash0; my $hash1; my $hash2; my $oldhash; |
| 24 | +my $hash_query = " |
| 25 | +select |
| 26 | + md5('(' || string_agg(aid::text || ', ' || abalance::text , '),(') || ')') |
| 27 | +from |
| 28 | + (select * from pgbench_accounts order by aid) t;"; |
| 29 | + |
| 30 | +$cluster->{nodes}->[2]->stop('fast'); |
| 31 | +sleep(3); |
| 32 | + |
| 33 | +$cluster->pgbench(0, ('-n','-N', -T => '4') ); |
| 34 | +$cluster->pgbench(1, ('-n','-N', -T => '4') ); |
| 35 | + |
| 36 | +$cluster->psql(0, 'postgres', $hash_query, stdout => \$hash0); |
| 37 | +$cluster->psql(1, 'postgres', $hash_query, stdout => \$hash1); |
| 38 | +# $cluster->psql(2, 'postgres', $hash_query, stdout => \$hash2); |
| 39 | + |
| 40 | +is( ($hash0 == $hash1) , 1, "Check that hash is the same before recovery"); |
| 41 | +$oldhash = $hash0; |
| 42 | + |
| 43 | +$cluster->{nodes}->[2]->start; |
| 44 | +sleep(10); |
| 45 | + |
| 46 | +$cluster->psql(0, 'postgres', $hash_query, stdout => \$hash0); |
| 47 | +$cluster->psql(1, 'postgres', $hash_query, stdout => \$hash1); |
| 48 | +$cluster->psql(2, 'postgres', $hash_query, stdout => \$hash2); |
| 49 | + |
| 50 | +diag("$oldhash, $hash0, $hash1, $hash2"); |
| 51 | +is( (($hash0 == $hash1) and ($hash1 == $hash2) and ($oldhash == $hash0)) , 1, "Check that hash is the same after recovery"); |
| 52 | + |
| 53 | +######################################################## |
| 54 | +# Check start after all nodes were disconnected |
| 55 | +######################################################## |
| 56 | + |
13 | 57 | $cluster->psql(0, 'postgres', "create extension multimaster;
|
14 | 58 | create table if not exists t(k int primary key, v int);");
|
15 | 59 |
|
|
18 | 62 | $cluster->psql(2, 'postgres', "insert into t values(3, 30);");
|
19 | 63 | sleep(2);
|
20 | 64 |
|
21 |
| - |
22 |
| -my $sum0; |
23 |
| -my $sum1; |
24 |
| -my $sum2; |
25 |
| - |
26 |
| -######################################################## |
27 |
| -# Check start after all nodes were disconnected |
28 |
| -######################################################## |
| 65 | +my $sum0; my $sum1; my $sum2; |
29 | 66 |
|
30 | 67 | $cluster->{nodes}->[1]->stop('fast');
|
31 | 68 | $cluster->{nodes}->[2]->stop('fast');
|
|
67 | 104 | sleep(10);
|
68 | 105 |
|
69 | 106 | # check data identity
|
70 |
| -$cluster->psql(0, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum0); |
71 |
| -$cluster->psql(1, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum1); |
72 |
| -$cluster->psql(2, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum2); |
73 |
| - |
74 |
| -diag("Sums: $sum0, $sum1, $sum2"); |
75 |
| -is($sum2, $sum0, "Check that sum_2 == sum_0"); |
76 |
| -is($sum2, $sum1, "Check that sum_2 == sum_1"); |
| 107 | +$cluster->psql(0, 'postgres', $hash_query, stdout => \$hash0); |
| 108 | +$cluster->psql(1, 'postgres', $hash_query, stdout => \$hash1); |
| 109 | +$cluster->psql(2, 'postgres', $hash_query, stdout => \$hash2); |
| 110 | +diag("$hash0, $hash1, $hash2"); |
| 111 | +is( (($hash0 == $hash1) and ($hash1 == $hash2)) , 1, "Check that hash is the same"); |
| 112 | + |
| 113 | +# $cluster->psql(0, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum0); |
| 114 | +# $cluster->psql(1, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum1); |
| 115 | +# $cluster->psql(2, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum2); |
| 116 | + |
| 117 | +# diag("Sums: $sum0, $sum1, $sum2"); |
| 118 | +# is($sum2, $sum0, "Check that sum_2 == sum_0"); |
| 119 | +# is($sum2, $sum1, "Check that sum_2 == sum_1"); |
77 | 120 |
|
78 | 121 | $cluster->{nodes}->[0]->stop('fast');
|
79 | 122 | $cluster->{nodes}->[1]->stop('fast');
|
|
0 commit comments