Skip to content

Commit d6559e2

Browse files
committed
2 parents e436c65 + 1ae7141 commit d6559e2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

contrib/pg_dtm/tests/transfers.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var cfg struct {
3131
ConnStrs ConnStrings
3232

3333
Verbose bool
34+
UseDtm bool
3435
Isolation string // "repeatable read" or "read committed"
3536

3637
Accounts struct {
@@ -102,6 +103,7 @@ func init() {
102103
flag.IntVar(&cfg.Writers.Num, "w", 8, "The number of writers")
103104
flag.IntVar(&cfg.Writers.Updates, "u", 10000, "The number updates each writer performs")
104105
flag.BoolVar(&cfg.Verbose, "v", false, "Show progress and other stuff for mortals")
106+
flag.BoolVar(&cfg.UseDtm, "m", false, "Use DTM to keep global consistency")
105107
flag.BoolVar(&cfg.Writers.AllowGlobal, "g", false, "Allow global updates")
106108
flag.BoolVar(&cfg.Writers.AllowLocal, "l", false, "Allow local updates")
107109
flag.BoolVar(&cfg.Writers.PrivateRows, "p", false, "Private rows (avoid waits/aborts caused by concurrent updates of the same rows)")
@@ -199,8 +201,10 @@ func prepare_one(connstr string, wg *sync.WaitGroup) {
199201

200202
defer conn.Close()
201203

202-
exec(conn, "drop extension if exists pg_dtm")
203-
exec(conn, "create extension pg_dtm")
204+
if cfg.UseDtm {
205+
exec(conn, "drop extension if exists pg_dtm")
206+
exec(conn, "create extension pg_dtm")
207+
}
204208
exec(conn, "drop table if exists t")
205209
exec(conn, "create table t(u int primary key, v int)")
206210

@@ -317,7 +321,9 @@ func writer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
317321
}
318322

319323
// global single-node update
320-
execQuery(src, "select dtm_begin_transaction()")
324+
if cfg.UseDtm {
325+
execQuery(src, "select dtm_begin_transaction()")
326+
}
321327

322328
// start transaction
323329
exec(src, "begin transaction isolation level " + cfg.Isolation)
@@ -367,8 +373,10 @@ func writer(id int, cCommits chan int, cAborts chan int, wg *sync.WaitGroup) {
367373
continue
368374
}
369375

370-
xid := execQuery(src, "select dtm_begin_transaction()")
371-
exec(dst, "select dtm_join_transaction($1)", xid)
376+
if cfg.UseDtm {
377+
xid := execQuery(src, "select dtm_begin_transaction()")
378+
exec(dst, "select dtm_join_transaction($1)", xid)
379+
}
372380

373381
// start transaction
374382
exec(src, "begin transaction isolation level " + cfg.Isolation)
@@ -453,10 +461,12 @@ func reader(wg *sync.WaitGroup, inconsistency *bool) {
453461
var sum int64 = 0
454462
var xid int32
455463
for i, conn := range conns {
456-
if i == 0 {
457-
xid = execQuery(conn, "select dtm_begin_transaction()")
458-
} else {
459-
exec(conn, "select dtm_join_transaction($1)", xid)
464+
if cfg.UseDtm {
465+
if i == 0 {
466+
xid = execQuery(conn, "select dtm_begin_transaction()")
467+
} else {
468+
exec(conn, "select dtm_join_transaction($1)", xid)
469+
}
460470
}
461471

462472
exec(conn, "begin transaction isolation level " + cfg.Isolation)

0 commit comments

Comments
 (0)