@@ -73,14 +73,15 @@ sub PostgresNode::psql_fails {
73
73
$node2 -> psql(' postgres' , " create table t(u int primary key, v int)" );
74
74
$node2 -> psql(' postgres' , " insert into t (select generate_series(0, 9), 0)" );
75
75
76
- my $conn1 = DBI-> connect (' DBI:Pg:' . $node1 -> connstr(' postgres' ));
77
- my $conn2 = DBI-> connect (' DBI:Pg:' . $node2 -> connstr(' postgres' ));
76
+ # we need two connections to each node (run two simultameous global tx)
77
+ my $conn11 = DBI-> connect (' DBI:Pg:' . $node1 -> connstr(' postgres' ));
78
+ my $conn21 = DBI-> connect (' DBI:Pg:' . $node2 -> connstr(' postgres' ));
79
+ my $conn12 = DBI-> connect (' DBI:Pg:' . $node1 -> connstr(' postgres' ));
80
+ my $conn22 = DBI-> connect (' DBI:Pg:' . $node2 -> connstr(' postgres' ));
78
81
79
82
sub count_total
80
83
{
81
- # my ($c1, $c2) = @_;
82
- my $c1 = DBI-> connect (' DBI:Pg:' . $node1 -> connstr(' postgres' ));
83
- my $c2 = DBI-> connect (' DBI:Pg:' . $node2 -> connstr(' postgres' ));
84
+ my ($c1 , $c2 ) = @_ ;
84
85
85
86
query_exec($c1 , " begin" );
86
87
query_exec($c2 , " begin" );
@@ -101,54 +102,33 @@ sub count_total
101
102
}
102
103
103
104
# ##############################################################################
104
- # Check for dirty reads
105
+ # Sanity check on dirty reads
105
106
# ##############################################################################
106
107
107
- my $gtid = " tx1" ;
108
-
109
- query_exec($conn1 , " begin transaction" );
110
- query_exec($conn2 , " begin transaction" );
111
- my $snapshot = query_row($conn1 , " select dtm_extend('$gtid ')" );
112
- query_exec($conn2 , " select dtm_access($snapshot , '$gtid ')" );
113
- query_exec($conn1 , " update t set v = v - 10 where u=1" );
114
-
115
- my $intermediate_total = count_total();
116
-
117
- query_exec($conn2 , " update t set v = v + 10 where u=2" );
118
- query_exec($conn1 , " prepare transaction '$gtid '" );
119
- query_exec($conn2 , " prepare transaction '$gtid '" );
120
- query_exec($conn1 , " select dtm_begin_prepare('$gtid ')" );
121
- query_exec($conn2 , " select dtm_begin_prepare('$gtid ')" );
122
- my $csn = query_row($conn1 , " select dtm_prepare('$gtid ', 0)" );
123
- query_exec($conn2 , " select dtm_prepare('$gtid ', $csn )" );
124
- query_exec($conn1 , " select dtm_end_prepare('$gtid ', $csn )" );
125
- query_exec($conn2 , " select dtm_end_prepare('$gtid ', $csn )" );
126
- query_exec($conn1 , " commit prepared '$gtid '" );
127
- query_exec($conn2 , " commit prepared '$gtid '" );
108
+ my $gtid1 = " gtx1" ;
109
+
110
+ # start global tx
111
+ query_exec($conn11 , " begin transaction" );
112
+ query_exec($conn21 , " begin transaction" );
113
+ my $snapshot = query_row($conn11 , " select dtm_extend('$gtid1 ')" );
114
+ query_exec($conn21 , " select dtm_access($snapshot , '$gtid1 ')" );
115
+
116
+ # transfer some amount of integers to different node
117
+ query_exec($conn11 , " update t set v = v - 10 where u=1" );
118
+ my $intermediate_total = count_total($conn12 , $conn22 );
119
+ query_exec($conn21 , " update t set v = v + 10 where u=2" );
120
+
121
+ # commit our global tx
122
+ query_exec($conn11 , " prepare transaction '$gtid1 '" );
123
+ query_exec($conn21 , " prepare transaction '$gtid1 '" );
124
+ query_exec($conn11 , " select dtm_begin_prepare('$gtid1 ')" );
125
+ query_exec($conn21 , " select dtm_begin_prepare('$gtid1 ')" );
126
+ my $csn = query_row($conn11 , " select dtm_prepare('$gtid1 ', 0)" );
127
+ query_exec($conn21 , " select dtm_prepare('$gtid1 ', $csn )" );
128
+ query_exec($conn11 , " select dtm_end_prepare('$gtid1 ', $csn )" );
129
+ query_exec($conn21 , " select dtm_end_prepare('$gtid1 ', $csn )" );
130
+ query_exec($conn11 , " commit prepared '$gtid1 '" );
131
+ query_exec($conn21 , " commit prepared '$gtid1 '" );
128
132
129
133
is($intermediate_total , 0, " Check for absence of dirty reads" );
130
134
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
0 commit comments