|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use PostgresNode; |
| 5 | +use TestLib; |
| 6 | +use Test::More tests => 1; |
| 7 | + |
| 8 | +my $master = get_new_node("master"); |
| 9 | +$master->init; |
| 10 | +$master->append_conf('postgresql.conf', qq( |
| 11 | + max_prepared_transactions = 10 |
| 12 | + log_checkpoints = true |
| 13 | + postgres_fdw.use_tsdtm = on |
| 14 | +)); |
| 15 | +$master->start; |
| 16 | + |
| 17 | +my $shard1 = get_new_node("shard1"); |
| 18 | +$shard1->init; |
| 19 | +$shard1->append_conf('postgresql.conf', qq( |
| 20 | + max_prepared_transactions = 10 |
| 21 | + log_checkpoints = true |
| 22 | + shared_preload_libraries = 'pg_tsdtm' |
| 23 | +)); |
| 24 | +$shard1->start; |
| 25 | + |
| 26 | +my $shard2 = get_new_node("shard2"); |
| 27 | +$shard2->init; |
| 28 | +$shard2->append_conf('postgresql.conf', qq( |
| 29 | + max_prepared_transactions = 10 |
| 30 | + log_checkpoints = true |
| 31 | + shared_preload_libraries = 'pg_tsdtm' |
| 32 | +)); |
| 33 | +$shard2->start; |
| 34 | + |
| 35 | +############################################################################### |
| 36 | + |
| 37 | +$master->psql('postgres', "CREATE EXTENSION postgres_fdw"); |
| 38 | +$master->psql('postgres', "CREATE TABLE accounts(id integer primary key, amount integer)"); |
| 39 | + |
| 40 | +foreach my $node ($shard1, $shard2) |
| 41 | +{ |
| 42 | + my $port = $node->port; |
| 43 | + my $host = $node->host; |
| 44 | + |
| 45 | + $node->psql('postgres', "CREATE EXTENSION pg_tsdtm"); |
| 46 | + $node->psql('postgres', "CREATE TABLE accounts(id integer primary key, amount integer)"); |
| 47 | + |
| 48 | + $master->psql('postgres', "CREATE SERVER shard_$port FOREIGN DATA WRAPPER postgres_fdw options(dbname 'postgres', host '$host', port '$port')"); |
| 49 | + $master->psql('postgres', "CREATE FOREIGN TABLE accounts_fdw_$port() inherits (accounts) server shard_$port options(table_name 'accounts')"); |
| 50 | + $master->psql('postgres', "CREATE USER MAPPING for stas SERVER shard_$port options (user 'stas')"); |
| 51 | + |
| 52 | + diag("done $host $port"); |
| 53 | +} |
| 54 | + |
| 55 | +$shard1->psql('postgres', "insert into accounts select 2*id-1, 0 from generate_series(1, 1000) as id;"); |
| 56 | +$shard2->psql('postgres', "insert into accounts select 2*id, 0 from generate_series(1, 1000) as id;"); |
| 57 | + |
| 58 | +############################################################################### |
| 59 | + |
| 60 | +my ($err, $rc); |
| 61 | +my $seconds = 30; |
| 62 | +my $total = 0; |
| 63 | +my $oldtotal = 0; |
| 64 | +my $isolation_error = 0; |
| 65 | + |
| 66 | +my $pgb_handle = $master->pgbench_async(-n, -c => 1, -T => $seconds, -f => "$TestLib::log_path/../../t/bank.pgb", 'postgres' ); |
| 67 | + |
| 68 | +my $started = time(); |
| 69 | +while (time() - $started < $seconds) |
| 70 | +{ |
| 71 | + ($rc, $total, $err) = $master->psql('postgres', "select sum(amount) from accounts"); |
| 72 | + if ($oldtotal != $total) |
| 73 | + { |
| 74 | + $isolation_error = 1; |
| 75 | + $oldtotal = $total; |
| 76 | + diag("Isolation error. Total = $total"); |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +$master->pgbench_await($pgb_handle); |
| 81 | + |
| 82 | +is($isolation_error, 0, 'check proper isolation'); |
| 83 | + |
| 84 | +$master->stop; |
| 85 | +$shard1->stop; |
| 86 | +$shard2->stop; |
0 commit comments