Skip to content

Commit eeb95fe

Browse files
committed
Add parameters into transfers test to make it use local and/or global updates.
1 parent 4d371d9 commit eeb95fe

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

contrib/pg_xtm/tests/transfers.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
N_ACCOUNTS = TRANSFER_CONNECTIONS//100000
1616
//ISOLATION_LEVEL = "repeatable read"
1717
ISOLATION_LEVEL = "read committed"
18+
GLOBAL_UPDATES = true
19+
LOCAL_UPDATES = false
1820
)
1921

2022

@@ -132,11 +134,20 @@ func transfer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
132134
account1 := rand.Intn(N_ACCOUNTS)
133135
account2 := rand.Intn(N_ACCOUNTS)
134136

137+
if (account1 >= account2) {
138+
continue
139+
}
140+
135141
src := conn[rand.Intn(2)]
136142
dst := conn[rand.Intn(2)]
137143

138144
if src == dst {
139-
// local transaction
145+
// local update
146+
if !LOCAL_UPDATES {
147+
// which we do not want
148+
continue
149+
}
150+
140151
exec(src, "begin transaction isolation level " + ISOLATION_LEVEL)
141152
ok1 := execUpdate(src, "update t set v = v - $1 where u=$2", amount, account1)
142153
ok2 := execUpdate(src, "update t set v = v + $1 where u=$2", amount, account2)
@@ -149,7 +160,12 @@ func transfer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
149160
myCommits += 1
150161
}
151162
} else {
152-
// global transaction
163+
// global update
164+
if !GLOBAL_UPDATES {
165+
// which we do not want
166+
continue
167+
}
168+
153169
xid = execQuery(src, "select dtm_begin_transaction(2)")
154170
exec(dst, "select dtm_join_transaction($1)", xid)
155171

@@ -263,6 +279,9 @@ func execUpdate(conn *pgx.Conn, stmt string, arguments ...interface{}) bool {
263279
var err error
264280
// fmt.Println(stmt)
265281
_, err = conn.Exec(stmt, arguments... )
282+
if err != nil {
283+
fmt.Println(err)
284+
}
266285
return err == nil
267286
}
268287

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