Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4998c0

Browse files
committed
isolation bench
1 parentcc2bb93 commitb4998c0

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

‎contrib/postgres_fdw/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DATA = postgres_fdw--1.0.sql
1212

1313
REGRESS = postgres_fdw
1414

15+
EXTRA_INSTALL += contrib/pg_tsdtm
16+
1517
ifdefUSE_PGXS
1618
PG_CONFIG = pg_config
1719
PGXS :=$(shell$(PG_CONFIG) --pgxs)
@@ -23,3 +25,9 @@ top_builddir = ../..
2325
include$(top_builddir)/src/Makefile.global
2426
include$(top_srcdir)/contrib/contrib-global.mk
2527
endif
28+
29+
# Poor's man overload of already defined target: just copy it
30+
check: submake$(REGRESS_PREP)
31+
$(pg_regress_check)$(REGRESS_OPTS)$(REGRESS)
32+
env DESTDIR='$(abs_top_builddir)'/tmp_install make install
33+
$(prove_check)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::Moretests=> 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+
foreachmy$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;

‎contrib/postgres_fdw/t/bank.pgb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\set id random(1, 2000)
2+
3+
BEGIN;
4+
UPDATE accounts SET amount = amount - 1 WHERE id = :id;
5+
UPDATE accounts SET amount = amount + 1 WHERE id = (:id + 1);
6+
COMMIT;

‎src/test/perl/PostgresNode.pm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,37 @@ sub pg_recvlogical_upto
17281728
}
17291729
}
17301730

1731+
subpgbench()
1732+
{
1733+
my ($self,$node,@args) =@_;
1734+
my$pgbench_handle =$self->pgbench_async($node,@args);
1735+
$self->pgbench_await($pgbench_handle);
1736+
}
1737+
1738+
subpgbench_async()
1739+
{
1740+
my ($self,@args) =@_;
1741+
1742+
my ($in,$out,$err,$rc);
1743+
$in ='';
1744+
$out ='';
1745+
1746+
my@pgbench_command = (
1747+
'pgbench',
1748+
-h=>$self->host,
1749+
-p=>$self->port,
1750+
@args
1751+
);
1752+
my$handle = IPC::Run::start(\@pgbench_command,$in,$out);
1753+
return$handle;
1754+
}
1755+
1756+
subpgbench_await()
1757+
{
1758+
my ($self,$pgbench_handle) =@_;
1759+
IPC::Run::finish($pgbench_handle) || BAIL_OUT("pgbench exited with$?");
1760+
}
1761+
17311762
=pod
17321763
17331764
=back

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp