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