Skip to content

Commit 4500b8c

Browse files
committed
Implement two async transactions in the deadlock tap test.
1 parent c7b5fcb commit 4500b8c

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

contrib/mmts/t/000_deadlock.pl

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ sub query_exec
2222
{
2323
my ($dbi, $sql) = @_;
2424
my $rv = $dbi->do($sql) || die;
25-
print "query_exec('$sql')\n";
25+
print "query_exec('$sql') = $rv\n";
2626
return $rv;
2727
}
2828

2929
sub query_exec_async
3030
{
3131
my ($dbi, $sql) = @_;
3232
my $rv = $dbi->do($sql, {pg_async => PG_ASYNC}) || die;
33-
print "query_exec('$sql')\n";
33+
print "query_exec_async('$sql') = $rv\n";
3434
return $rv;
3535
}
3636

@@ -56,7 +56,7 @@ sub allocate_ports
5656
return @allocated_now;
5757
}
5858

59-
my $nnodes = 2;
59+
my $nnodes = 3;
6060
my @nodes = ();
6161

6262
# Create nodes and allocate ports
@@ -89,22 +89,19 @@ sub allocate_ports
8989
listen_addresses = '$host'
9090
unix_socket_directories = ''
9191
port = $pgport
92-
max_connections = 200
93-
shared_buffers = 1GB
94-
max_prepared_transactions = 200
95-
max_worker_processes = 100
92+
max_prepared_transactions = 10
93+
max_worker_processes = 10
9694
wal_level = logical
9795
fsync = off
98-
max_wal_size = 100GB
99-
min_wal_size = 1GB
10096
max_wal_senders = 10
10197
wal_sender_timeout = 0
10298
max_replication_slots = 10
10399
shared_preload_libraries = 'raftable,multimaster'
104-
multimaster.workers = 8
105-
multimaster.queue_size = 104857600 # 100mb
100+
multimaster.workers = 4
101+
multimaster.queue_size = 10485760 # 10mb
106102
multimaster.node_id = $id
107103
multimaster.conn_strings = '$mm_connstr'
104+
multimaster.use_raftable = true
108105
raftable.id = $id
109106
raftable.peers = '$raft_peers'
110107
));
@@ -122,27 +119,39 @@ sub allocate_ports
122119
$node->start();
123120
}
124121

125-
$nodes[0]->psql("create table t(k int primary key, v text)");
126-
$nodes[0]->psql("insert into t values (1, 'hello'), (2, 'world')");
122+
my ($rc, $out, $err);
123+
sleep(10);
127124

128-
#my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @nodes;
129-
#
130-
#query_exec($conns[0], "begin");
131-
#query_exec($conns[1], "begin");
132-
#
133-
#query_exec($conns[0], "update t set v = 'foo' where k = 1");
134-
#query_exec($conns[1], "update t set v = 'bar' where k = 2");
135-
#
136-
#query_exec($conns[0], "update t set v = 'bar' where k = 2");
137-
#query_exec($conns[1], "update t set v = 'foo' where k = 1");
138-
#
139-
#query_exec_async($conns[0], "commit");
140-
#query_exec_async($conns[1], "commit");
141-
#
142-
#my $ready = 0;
143-
#$ready++ if $conns[0]->pg_ready;
144-
#$ready++ if $conns[1]->pg_ready;
145-
#
146-
#is($ready, 1, "one of the connections is deadlocked");
125+
$nodes[0]->psql('postgres', "create table t(k int primary key, v text)");
126+
$nodes[0]->psql('postgres', "insert into t values (1, 'hello'), (2, 'world')");
127+
128+
#sub space2semicol
129+
#{
130+
# my $str = shift;
131+
# $str =~ tr/ /;/;
132+
# return $str;
133+
#}
147134
#
135+
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @nodes;
136+
137+
query_exec($conns[0], "begin");
138+
query_exec($conns[1], "begin");
139+
140+
query_exec($conns[0], "update t set v = 'asd' where k = 1");
141+
query_exec($conns[1], "update t set v = 'bsd' where k = 2");
142+
143+
query_exec($conns[0], "update t set v = 'bar' where k = 2");
144+
query_exec($conns[1], "update t set v = 'foo' where k = 1");
145+
146+
query_exec_async($conns[0], "commit");
147+
query_exec_async($conns[1], "commit");
148+
149+
for my $i (1..2)
150+
{
151+
($rc, $out, $err) = $nodes[$i]->psql('postgres', "select * from t");
152+
print(" rc[$i] = $rc\n");
153+
print("out[$i] = $out\n");
154+
print("err[$i] = $err\n");
155+
}
156+
148157
#sleep(2);

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