|
3 | 3 |
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 2; |
| 6 | +use Test::More tests => 3; |
7 | 7 |
|
8 | 8 | my $master = get_new_node("master");
|
9 | 9 | $master->init;
|
|
56 | 56 |
|
57 | 57 | $master->pgbench(-n, -c => 20, -t => 30, -f => "$TestLib::log_path/../../t/bank.sql", 'postgres' );
|
58 | 58 |
|
59 |
| -# diag( $master->connstr() ); |
60 |
| -# sleep(3600); |
61 |
| - |
62 | 59 | ###############################################################################
|
63 | 60 | # Helpers
|
64 | 61 | ###############################################################################
|
@@ -162,10 +159,59 @@ sub count_and_delete_rows
|
162 | 159 | is($isolation_errors, 0, 'isolation between concurrent global and local transactions');
|
163 | 160 |
|
164 | 161 |
|
165 |
| -# diag( $master->connstr('postgres'), "\n" ); |
166 |
| -# diag( $shard1->connstr('postgres'), "\n" ); |
167 |
| -# diag( $shard2->connstr('postgres'), "\n" ); |
168 |
| -# sleep(3600); |
| 162 | +############################################################################### |
| 163 | +# Snapshot stability |
| 164 | +############################################################################### |
| 165 | + |
| 166 | +my ($hashes, $hash1, $hash2); |
| 167 | +my $stability_errors = 0; |
| 168 | +my $stable; |
| 169 | + |
| 170 | +# global txses |
| 171 | +$pgb_handle1 = $master->pgbench_async(-n, -c => 5, -T => $seconds, -f => "$TestLib::log_path/../../t/bank.sql", 'postgres' ); |
| 172 | +# concurrent local |
| 173 | +$pgb_handle2 = $shard1->pgbench_async(-n, -c => 5, -T => $seconds, -f => "$TestLib::log_path/../../t/bank1.sql", 'postgres' ); |
| 174 | +$pgb_handle3 = $shard2->pgbench_async(-n, -c => 5, -T => $seconds, -f => "$TestLib::log_path/../../t/bank2.sql", 'postgres' ); |
| 175 | + |
| 176 | +$selects = 0; |
| 177 | +$started = time(); |
| 178 | +while (time() - $started < $seconds) |
| 179 | +{ |
| 180 | + foreach my $node ($master, $shard1, $shard2) |
| 181 | + { |
| 182 | + ($hash1, $_, $hash2) = split "\n", $node->safe_psql('postgres', qq[ |
| 183 | + begin isolation level repeatable read; |
| 184 | + select md5(array_agg((t.*)::text)::text) from (select * from accounts order by id) as t; |
| 185 | + select pg_sleep(1); |
| 186 | + select md5(array_agg((t.*)::text)::text) from (select * from accounts order by id) as t; |
| 187 | + commit; |
| 188 | + ]); |
| 189 | + |
| 190 | + if ($hash1 ne $hash2) |
| 191 | + { |
| 192 | + $stability_errors++; |
| 193 | + } |
| 194 | + elsif ($hash1 eq '' or $hash2 eq '') |
| 195 | + { |
| 196 | + die; |
| 197 | + } |
| 198 | + else |
| 199 | + { |
| 200 | + $selects++; |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +$master->pgbench_await($pgb_handle1); |
| 206 | +$shard1->pgbench_await($pgb_handle2); |
| 207 | +$shard2->pgbench_await($pgb_handle3); |
| 208 | + |
| 209 | +die "" unless ( $selects > 0 && |
| 210 | + count_and_delete_rows($master, 'global_transactions') > 0 && |
| 211 | + count_and_delete_rows($shard1, 'local_transactions') > 0 && |
| 212 | + count_and_delete_rows($shard2, 'local_transactions') > 0); |
| 213 | + |
| 214 | +is($stability_errors, 0, 'snapshot is stable during concurrent global and local transactions'); |
169 | 215 |
|
170 | 216 | $master->stop;
|
171 | 217 | $shard1->stop;
|
|
0 commit comments