@@ -11,12 +11,10 @@ import (
11
11
const (
12
12
TRANSFER_CONNECTIONS = 8
13
13
INIT_AMOUNT = 10000
14
- N_ITERATIONS = 100000
14
+ N_ITERATIONS = 10000
15
15
N_ACCOUNTS = TRANSFER_CONNECTIONS //100000
16
- //ISOLATION_LEVEL = "repeatable read"
17
- ISOLATION_LEVEL = "read committed"
18
- GLOBAL_UPDATES = true
19
- LOCAL_UPDATES = false
16
+ ISOLATION_LEVEL = "repeatable read"
17
+ //ISOLATION_LEVEL = "read committed"
20
18
)
21
19
22
20
@@ -50,8 +48,6 @@ func commit(conn1, conn2 *pgx.Conn) {
50
48
}
51
49
52
50
func prepare_db () {
53
- // var xid int32
54
-
55
51
conn1 ,err := pgx .Connect (cfg1 )
56
52
checkErr (err )
57
53
defer conn1 .Close ()
@@ -70,9 +66,6 @@ func prepare_db() {
70
66
exec (conn2 ,"drop table if exists t" )
71
67
exec (conn2 ,"create table t(u int primary key, v int)" )
72
68
73
- // xid = execQuery(conn1, "select dtm_begin_transaction(2)")
74
- // exec(conn2, "select dtm_join_transaction($1)", xid)
75
-
76
69
// strt transaction
77
70
exec (conn1 ,"begin transaction isolation level " + ISOLATION_LEVEL )
78
71
exec (conn2 ,"begin transaction isolation level " + ISOLATION_LEVEL )
@@ -134,63 +127,27 @@ func transfer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
134
127
account1 := rand .Intn (N_ACCOUNTS )
135
128
account2 := rand .Intn (N_ACCOUNTS )
136
129
137
- if (account1 >= account2 ) {
138
- continue
139
- }
130
+ src := conn [0 ]
131
+ dst := conn [1 ]
140
132
141
- srci := rand .Intn (2 )
142
- dsti := rand .Intn (2 )
143
- if (srci > dsti ) {
144
- continue
145
- }
133
+ xid = execQuery (src ,"select dtm_begin_transaction(2)" )
134
+ exec (dst ,"select dtm_join_transaction($1)" ,xid )
146
135
147
- src := conn [srci ]
148
- dst := conn [dsti ]
136
+ // start transaction
137
+ exec (src ,"begin transaction isolation level " + ISOLATION_LEVEL )
138
+ exec (dst ,"begin transaction isolation level " + ISOLATION_LEVEL )
149
139
150
- if src == dst {
151
- // local update
152
- if ! LOCAL_UPDATES {
153
- // which we do not want
154
- continue
155
- }
140
+ ok1 := execUpdate (src ,"update t set v = v - $1 where u=$2" ,amount ,account1 )
141
+ ok2 := execUpdate (dst ,"update t set v = v + $1 where u=$2" ,amount ,account2 )
156
142
157
- exec (src ,"begin transaction isolation level " + ISOLATION_LEVEL )
158
- ok1 := execUpdate (src ,"update t set v = v - $1 where u=$2" ,amount ,account1 )
159
- ok2 := execUpdate (src ,"update t set v = v + $1 where u=$2" ,amount ,account2 )
160
- if ! ok1 || ! ok2 {
161
- exec (src ,"rollback" )
162
- nAborts += 1
163
- }else {
164
- exec (src ,"commit" )
165
- nCommits += 1
166
- myCommits += 1
167
- }
143
+ if ! ok1 || ! ok2 {
144
+ exec (src ,"rollback" )
145
+ exec (dst ,"rollback" )
146
+ nAborts += 1
168
147
}else {
169
- // global update
170
- if ! GLOBAL_UPDATES {
171
- // which we do not want
172
- continue
173
- }
174
-
175
- xid = execQuery (src ,"select dtm_begin_transaction(2)" )
176
- exec (dst ,"select dtm_join_transaction($1)" ,xid )
177
-
178
- // start transaction
179
- exec (src ,"begin transaction isolation level " + ISOLATION_LEVEL )
180
- exec (dst ,"begin transaction isolation level " + ISOLATION_LEVEL )
181
-
182
- ok1 := execUpdate (src ,"update t set v = v - $1 where u=$2" ,amount ,account1 )
183
- ok2 := execUpdate (dst ,"update t set v = v + $1 where u=$2" ,amount ,account2 )
184
-
185
- if ! ok1 || ! ok2 {
186
- exec (src ,"rollback" )
187
- exec (dst ,"rollback" )
188
- nAborts += 1
189
- }else {
190
- commit (src ,dst )
191
- nCommits += 1
192
- myCommits += 1
193
- }
148
+ commit (src ,dst )
149
+ nCommits += 1
150
+ myCommits += 1
194
151
}
195
152
196
153
if time .Since (start ).Seconds ()> 1 {
@@ -285,9 +242,9 @@ func execUpdate(conn *pgx.Conn, stmt string, arguments ...interface{}) bool {
285
242
var err error
286
243
// fmt.Println(stmt)
287
244
_ ,err = conn .Exec (stmt ,arguments ... )
288
- if err != nil {
289
- fmt .Println (err )
290
- }
245
+ // if err != nil {
246
+ // fmt.Println(err)
247
+ // }
291
248
return err == nil
292
249
}
293
250