From 2c7e53cfe74224ccafe5b0401c260e427472853a Mon Sep 17 00:00:00 2001 From: xyctruth <398041993@qq.com> Date: Thu, 24 Feb 2022 11:32:18 +0800 Subject: [PATCH] golang ci lint --- dtmsvr/api_http.go | 2 ++ dtmsvr/storage/boltdb/boltdb.go | 5 ++--- dtmsvr/storage/redis/redis.go | 1 + dtmsvr/storage/sql/sql.go | 2 ++ test/store_test.go | 9 +++++---- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dtmsvr/api_http.go b/dtmsvr/api_http.go index de85586..e3507b8 100644 --- a/dtmsvr/api_http.go +++ b/dtmsvr/api_http.go @@ -83,6 +83,8 @@ func all(c *gin.Context) interface{} { return map[string]interface{}{"transactions": globals, "next_position": position} } +// resetCronTime rest nextCronTime +// Prevent multiple backoff from causing NextCronTime to be too long func resetCronTime(c *gin.Context) interface{} { sTimeoutSecond := dtmimp.OrString(c.Query("timeout"), strconv.FormatInt(3*conf.TimeoutToFail, 10)) sLimit := dtmimp.OrString(c.Query("limit"), "100") diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index e6fe28c..a09eb12 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -14,14 +14,11 @@ import ( "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmutil" bolt "go.etcd.io/bbolt" ) -var conf = &config.Config - // Store implements storage.Store, and storage with boltdb type Store struct { boltDb *bolt.DB @@ -412,6 +409,8 @@ func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalS return trans } +// ResetCronTime rest nextCronTime +// Prevent multiple backoff from causing NextCronTime to be too long func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error { next := time.Now() var trans *storage.TransGlobalStore diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index fa4b5b8..d4200c7 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -261,6 +261,7 @@ return gid } // ResetCronTime rest nextCronTime +// Prevent multiple backoff from causing NextCronTime to be too long func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error { next := time.Now().Unix() timeoutTimestamp := time.Now().Add(timeout).Unix() diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 3ec146b..d263955 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -156,6 +156,8 @@ func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalS return global } +// ResetCronTime rest nextCronTime +// Prevent multiple backoff from causing NextCronTime to be too long func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error { db := dbGet() getTime := func(second int) string { diff --git a/test/store_test.go b/test/store_test.go index bdcca7e..75503f1 100644 --- a/test/store_test.go +++ b/test/store_test.go @@ -136,7 +136,8 @@ func testStoreResetCronTime(t *testing.T, funcName string, restCronHandler func( assert.Nil(t, g) // Rest 1 count - err = restCronHandler(restTimeTimeout, limit) + err1 := restCronHandler(restTimeTimeout, limit) + assert.Nil(t, err1) // Fount 1 count g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second) assert.NotNil(t, g) @@ -146,9 +147,9 @@ func testStoreResetCronTime(t *testing.T, funcName string, restCronHandler func( g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second) assert.Nil(t, g) - // Increase the restTimeTimeout, Rest 1 count - err = restCronHandler(restTimeTimeout-12, limit) - assert.Nil(t, err) + // reduce the restTimeTimeout, Rest 1 count + err2 := restCronHandler(restTimeTimeout-12, limit) + assert.Nil(t, err2) // Fount 1 count g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second) assert.NotNil(t, g)