Skip to content

Commit 2662ef9

Browse files
committed
snapshot stability test
1 parent eeba549 commit 2662ef9

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

contrib/postgres_fdw/t/001_bank_check.pl

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 2;
6+
use Test::More tests => 3;
77

88
my $master = get_new_node("master");
99
$master->init;
@@ -56,9 +56,6 @@
5656

5757
$master->pgbench(-n, -c => 20, -t => 30, -f => "$TestLib::log_path/../../t/bank.sql", 'postgres' );
5858

59-
# diag( $master->connstr() );
60-
# sleep(3600);
61-
6259
###############################################################################
6360
# Helpers
6461
###############################################################################
@@ -162,10 +159,59 @@ sub count_and_delete_rows
162159
is($isolation_errors, 0, 'isolation between concurrent global and local transactions');
163160

164161

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');
169215

170216
$master->stop;
171217
$shard1->stop;

contrib/postgres_fdw/t/bank1.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ BEGIN;
44
WITH upd AS (UPDATE accounts SET amount = amount - 1 WHERE id = (2*:id + 1) RETURNING *)
55
INSERT into local_transactions SELECT now() FROM upd;
66
UPDATE accounts SET amount = amount + 1 WHERE id = (2*:id + 3);
7-
-- INSERT into local_transactions values(now());
87
COMMIT;

contrib/postgres_fdw/t/bank2.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ BEGIN;
44
WITH upd AS (UPDATE accounts SET amount = amount - 1 WHERE id = 2*:id RETURNING *)
55
INSERT into local_transactions SELECT now() FROM upd;
66
UPDATE accounts SET amount = amount + 1 WHERE id = (2*:id + 2);
7-
-- INSERT into local_transactions values(now());
87
COMMIT;

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