diff --git a/conf.sample.yml b/conf.sample.yml index 9d736fd..6c5919f 100644 --- a/conf.sample.yml +++ b/conf.sample.yml @@ -35,7 +35,7 @@ Store: # specify which engine to store trans status # TimeoutToFail: 35 # timeout for XA, TCC to fail. saga's timeout default to infinite, which can be overwritten in saga options # RetryInterval: 10 # the subtrans branch will be retried after this interval -### db config of examples +### dtm can run examples, and examples will use following config to connect db ExamplesDB: Driver: 'mysql' Host: 'localhost' diff --git a/dtmcli/dtmimp/db_special.go b/dtmcli/dtmimp/db_special.go index 3eb3071..d45f460 100644 --- a/dtmcli/dtmimp/db_special.go +++ b/dtmcli/dtmimp/db_special.go @@ -13,7 +13,6 @@ import ( // DBSpecial db specific operations type DBSpecial interface { - TimestampAdd(second int) string GetPlaceHoldSQL(sql string) string GetInsertIgnoreTemplate(tableAndValues string, pgConstraint string) string GetXaSQL(command string, xid string) string @@ -24,10 +23,6 @@ var currentDBType = DBTypeMysql type mysqlDBSpecial struct{} -func (*mysqlDBSpecial) TimestampAdd(second int) string { - return fmt.Sprintf("date_add(now(), interval %d second)", second) -} - func (*mysqlDBSpecial) GetPlaceHoldSQL(sql string) string { return sql } diff --git a/dtmcli/dtmimp/db_special_test.go b/dtmcli/dtmimp/db_special_test.go index 3bf7012..3966cd2 100644 --- a/dtmcli/dtmimp/db_special_test.go +++ b/dtmcli/dtmimp/db_special_test.go @@ -22,13 +22,11 @@ func TestDBSpecial(t *testing.T) { assert.Equal(t, "? ?", sp.GetPlaceHoldSQL("? ?")) assert.Equal(t, "xa start 'xa1'", sp.GetXaSQL("start", "xa1")) - assert.Equal(t, "date_add(now(), interval 1000 second)", sp.TimestampAdd(1000)) assert.Equal(t, "insert ignore into a(f) values(?)", sp.GetInsertIgnoreTemplate("a(f) values(?)", "c")) SetCurrentDBType(DBTypePostgres) sp = GetDBSpecial() assert.Equal(t, "$1 $2", sp.GetPlaceHoldSQL("? ?")) assert.Equal(t, "begin", sp.GetXaSQL("start", "xa1")) - assert.Equal(t, "current_timestamp + interval '1000 second'", sp.TimestampAdd(1000)) assert.Equal(t, "insert into a(f) values(?) on conflict ON CONSTRAINT c do nothing", sp.GetInsertIgnoreTemplate("a(f) values(?)", "c")) SetCurrentDBType(old) } diff --git a/dtmsvr/storage/sql.go b/dtmsvr/storage/sql.go index 324eddd..61e8862 100644 --- a/dtmsvr/storage/sql.go +++ b/dtmsvr/storage/sql.go @@ -112,7 +112,12 @@ func (s *SqlStore) TouchCronTime(global *TransGlobalStore, nextCronInterval int6 func (s *SqlStore) LockOneGlobalTrans(expireIn time.Duration) *TransGlobalStore { db := dbGet() - getTime := dtmimp.GetDBSpecial().TimestampAdd + getTime := func(second int) string { + return map[string]string{ + "mysql": fmt.Sprintf("date_add(now(), interval %d second)", second), + "postgres": fmt.Sprintf("current_timestamp + interval '%d second'", second), + }[config.Store.Driver] + } expire := int(expireIn / time.Second) whereTime := fmt.Sprintf("next_cron_time < %s", getTime(expire)) owner := uuid.NewString()