From c8ad5259d7dd6a7f0d8ff2d0585e396904a36467 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 19:55:07 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=81=9C=E6=AD=A2=E6=9C=AA=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?gid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dtmcli/consts.go | 1 + dtmsvr/api.go | 18 ++++++++++++++++++ dtmsvr/api_http.go | 5 +++++ dtmsvr/storage/boltdb/boltdb.go | 17 +++++++++++++++++ dtmsvr/storage/redis/redis.go | 27 +++++++++++++++++++++++++++ dtmsvr/storage/sql/sql.go | 13 +++++++++++++ dtmsvr/storage/store.go | 1 + dtmsvr/storage/trans.go | 1 + dtmsvr/trans_status.go | 21 +++++++++++++++++++++ go.sum | 18 ------------------ sqls/dtmsvr.storage.mysql.sql | 2 +- 11 files changed, 105 insertions(+), 19 deletions(-) diff --git a/dtmcli/consts.go b/dtmcli/consts.go index ef71a67..f76fd84 100644 --- a/dtmcli/consts.go +++ b/dtmcli/consts.go @@ -12,6 +12,7 @@ import ( const ( // StatusPrepared status for global/branch trans status. + // first step, tx preparation period StatusPrepared = "prepared" // StatusSubmitted status for global trans status. StatusSubmitted = "submitted" diff --git a/dtmsvr/api.go b/dtmsvr/api.go index f2855f9..785be64 100644 --- a/dtmsvr/api.go +++ b/dtmsvr/api.go @@ -7,6 +7,7 @@ package dtmsvr import ( + "encoding/json" "fmt" "github.com/dtm-labs/dtm/dtmcli" @@ -58,6 +59,23 @@ func svcAbort(t *TransGlobal) interface{} { return dbt.Process(branches) } +func svcForceStop(t *TransGlobal) interface{} { + dbt := GetTransGlobal(t.Gid) + if dbt.Status == dtmcli.StatusSucceed || dbt.Status == dtmcli.StatusFailed { + return nil + } + extData, err := json.Marshal(&ExtData{ + Type: ExtDataTypeForceStop, + Msg: t.ForceStopReason, + }) + if err != nil { + return err + } + dbt.statusFailed(string(extData)) + branches := GetStore().FindBranches(t.Gid) + return dbt.Process(branches) +} + func svcRegisterBranch(transType string, branch *TransBranch, data map[string]string) error { branches := []TransBranch{*branch, *branch} if transType == "tcc" { diff --git a/dtmsvr/api_http.go b/dtmsvr/api_http.go index 3d2e67a..2ba8373 100644 --- a/dtmsvr/api_http.go +++ b/dtmsvr/api_http.go @@ -23,6 +23,7 @@ func addRoute(engine *gin.Engine) { engine.POST("/api/dtmsvr/prepare", dtmutil.WrapHandler2(prepare)) engine.POST("/api/dtmsvr/submit", dtmutil.WrapHandler2(submit)) engine.POST("/api/dtmsvr/abort", dtmutil.WrapHandler2(abort)) + engine.POST("/api/dtmsvr/forceStop", dtmutil.WrapHandler2(forceStop)) // change global status to failed can stop trigger (Use with caution in production environment) engine.POST("/api/dtmsvr/registerBranch", dtmutil.WrapHandler2(registerBranch)) engine.POST("/api/dtmsvr/registerXaBranch", dtmutil.WrapHandler2(registerBranch)) // compatible for old sdk engine.POST("/api/dtmsvr/registerTccBranch", dtmutil.WrapHandler2(registerBranch)) // compatible for old sdk @@ -54,6 +55,10 @@ func abort(c *gin.Context) interface{} { return svcAbort(TransFromContext(c)) } +func forceStop(c *gin.Context) interface{} { + return svcForceStop(TransFromContext(c)) +} + func registerBranch(c *gin.Context) interface{} { data := map[string]string{} err := c.BindJSON(&data) diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 1f53fb2..0c38708 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -8,6 +8,7 @@ package boltdb import ( "fmt" + "github.com/dtm-labs/dtm/dtmcli" "strings" "time" @@ -26,6 +27,8 @@ type Store struct { retryInterval int64 } +var _ storage.Store = &Store{} + // NewStore will return the boltdb implement // TODO: change to options func NewStore(dataExpire int64, retryInterval int64) *Store { @@ -361,6 +364,20 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s dtmimp.E2P(err) } +func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { + old := global.Status + global.Status = dtmcli.StatusFailed + err := s.boltDb.Update(func(t *bolt.Tx) error { + g := tGetGlobal(t, global.Gid) + if g == nil || g.Status != old { + return storage.ErrNotFound + } + tPutGlobal(t, global) + return nil + }) + dtmimp.E2P(err) +} + // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { oldUnix := global.NextCronTime.Unix() diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 7e6bbfa..0d86099 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/dtm-labs/dtm/dtmcli" "sync" "time" @@ -26,6 +27,8 @@ var ctx = context.Background() type Store struct { } +var _ storage.Store = &Store{} + // Ping execs ping cmd to redis func (s *Store) Ping() error { _, err := redisGet().Ping(ctx).Result() @@ -229,6 +232,30 @@ end dtmimp.E2P(err) } +func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { + old := global.Status + global.Status = dtmcli.StatusFailed + args := newArgList(). + AppendGid(global.Gid). + AppendObject(global). + AppendRaw(old). + AppendRaw(false). + AppendRaw(global.Gid). + AppendRaw(dtmcli.StatusFailed) + _, err := callLua(args, `-- ChangeGlobalStatus +local old = redis.call('GET', KEYS[4]) +if old ~= ARGV[4] then + return 'NOT_FOUND' +end +redis.call('SET', KEYS[1], ARGV[3], 'EX', ARGV[2]) +redis.call('SET', KEYS[4], ARGV[7], 'EX', ARGV[2]) +if ARGV[5] == '1' then + redis.call('ZREM', KEYS[3], ARGV[6]) +end +`) + dtmimp.E2P(err) +} + // LockOneGlobalTrans finds GlobalTrans func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalStore { expired := time.Now().Add(expireIn).Unix() diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index d87297a..a4b8945 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -8,6 +8,7 @@ package sql import ( "fmt" + "github.com/dtm-labs/dtm/dtmcli" "math" "time" @@ -26,6 +27,8 @@ var conf = &config.Config type Store struct { } +var _ storage.Store = &Store{} + // Ping execs ping cmd to db func (s *Store) Ping() error { db, err := dtmimp.StandaloneDB(conf.Store.GetDBConf()) @@ -125,6 +128,16 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s } } +// StatusFailed changes global trans status to failed +func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { + old := global.Status + global.Status = dtmcli.StatusFailed + dbr := dbGet().Must().Model(global).Where("status=? and gid=?", old, global.Gid).Select(updates).Updates(global) + if dbr.RowsAffected == 0 { + dtmimp.E2P(storage.ErrNotFound) + } +} + // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { global.UpdateTime = dtmutil.GetNextTime(0) diff --git a/dtmsvr/storage/store.go b/dtmsvr/storage/store.go index 391c4dd..8a6c62a 100644 --- a/dtmsvr/storage/store.go +++ b/dtmsvr/storage/store.go @@ -28,6 +28,7 @@ type Store interface { LockGlobalSaveBranches(gid string, status string, branches []TransBranchStore, branchStart int) MaySaveNewTrans(global *TransGlobalStore, branches []TransBranchStore) error ChangeGlobalStatus(global *TransGlobalStore, newStatus string, updates []string, finished bool) + StatusFailed(global *TransGlobalStore, updates []string) TouchCronTime(global *TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) LockOneGlobalTrans(expireIn time.Duration) *TransGlobalStore ResetCronTime(timeout time.Duration, limit int64) (succeedCount int64, hasRemaining bool, err error) diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index 4f37122..ed80f6d 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -39,6 +39,7 @@ type TransGlobalStore struct { NextCronTime *time.Time `json:"next_cron_time,omitempty"` Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` + ForceStopReason string `json:"force_stop_reason" gorm:"-"` ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 2c1c16a..6d27df2 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -58,6 +58,27 @@ func (t *TransGlobal) changeStatus(status string) { t.Status = status } +type ExtDataType string + +const ( + ExtDataTypeDefault ExtDataType = "" + ExtDataTypeForceStop ExtDataType = "forceStop" +) + +type ExtData struct { + Type ExtDataType `json:"type"` + Msg string `json:"msg"` +} + +func (t *TransGlobal) statusFailed(extData string) { + updates := []string{"status", "update_time", "ext_data"} + now := time.Now() + t.UpdateTime = &now + t.ExtData = extData + GetStore().StatusFailed(&t.TransGlobalStore, updates) + logger.Infof("StatusFailed to %s ok for %s", dtmcli.StatusFailed, t.TransGlobalStore.String()) +} + func (t *TransGlobal) changeBranchStatus(b *TransBranch, status string, branchPos int) { now := time.Now() b.Status = status diff --git a/go.sum b/go.sum index 814610b..17103b6 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs= github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0= -github.com/agiledragon/gomonkey v0.0.0-20190517145658-8fa491f7b918 h1:a88Ln+jbIokfi6xoKtq10dbgp4VMg1CmHF1J42p8EyE= -github.com/agiledragon/gomonkey v0.0.0-20190517145658-8fa491f7b918/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -108,8 +106,6 @@ github.com/dtm-labs/dtmdriver v0.0.1 h1:dHUZQ6g2ZN6eRUqds9kKq/3K7u9bcUGatUlbthD9 github.com/dtm-labs/dtmdriver v0.0.1/go.mod h1:fLiEeD2BPwM9Yq96TfcP9KpbTwFsn5nTxa/PP0jmFuk= github.com/dtm-labs/dtmdriver-gozero v0.0.2 h1:T+JH9kwVNMmISPU1BNviiTrvPdMA7UMFD+nfTqGPSyA= github.com/dtm-labs/dtmdriver-gozero v0.0.2/go.mod h1:5AAKwYok5f56e0kATOXvc+DAsfu4elISDuCV+G3+fYE= -github.com/dtm-labs/dtmdriver-polaris v0.0.3 h1:oqvYq7X6iDUCECjSE82gsGP1Du0vhcpHNmxM8Uo7470= -github.com/dtm-labs/dtmdriver-polaris v0.0.3/go.mod h1:yGdzgar7r8SmzTDeEn0CuVq9xo1NX7x327MhxuU9sxM= github.com/dtm-labs/dtmdriver-polaris v0.0.4 h1:yli0YmAsEgl47ymJHTxIzULeNe5dnmfN2ixLJRWm2Ok= github.com/dtm-labs/dtmdriver-polaris v0.0.4/go.mod h1:zwNFE3z0B7Ky35W2Ks9LkpMGiuIt9YFuocy4qaedCLE= github.com/dtm-labs/dtmdriver-protocol1 v0.0.1 h1:nwGpGWi7XlUAcDhEw1qZ3TheBskqCvfE96n1uVjmDf4= @@ -141,8 +137,6 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU= -github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= @@ -279,8 +273,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -413,7 +405,6 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= @@ -453,12 +444,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/grpc-go-polaris v1.2.0 h1:dcQyyGy1TwUDEehx4xvpKIl6RM/Mcp9N02qZmeH8OSQ= -github.com/polarismesh/grpc-go-polaris v1.2.0/go.mod h1:bQ591/6rNXmo+tKTy7tc0PLgAro/3U+IJOpmubqcHDw= github.com/polarismesh/grpc-go-polaris v1.2.1-0.20220306155244-f0b83ba62878 h1:IhlY8X1AZT33oB920PES1L/SPURx+tjb62nWHZ7s0Ss= github.com/polarismesh/grpc-go-polaris v1.2.1-0.20220306155244-f0b83ba62878/go.mod h1:DxKBmYOXsLNqbrMqJgwnGwu9RkqWl005kXosGaVxbTg= -github.com/polarismesh/polaris-go v1.0.0 h1:JIBANM5nfhu5knbg269kldQ58bSSV7a6AzTQk1OZwt8= -github.com/polarismesh/polaris-go v1.0.0/go.mod h1:uzNFDShCN+UhBncwwNqNVhPpI1ZXYwPlb9N/aE+/vE0= github.com/polarismesh/polaris-go v1.0.1 h1:Zqr8ZtxsJQsxt0MGyC/fFsF861ogoJCz16yWFJ/t54Q= github.com/polarismesh/polaris-go v1.0.1/go.mod h1:3NOqn3QquPdEdY6YhPrsWGvBVCpKhPBGt0Hspq3yEqY= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -502,8 +489,6 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -582,7 +567,6 @@ go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpK go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -668,7 +652,6 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -861,7 +844,6 @@ google.golang.org/genproto v0.0.0-20220112215332-a9c7c0acf9f2/go.mod h1:5CzLGKJ6 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= diff --git a/sqls/dtmsvr.storage.mysql.sql b/sqls/dtmsvr.storage.mysql.sql index 09c82f5..94050c0 100644 --- a/sqls/dtmsvr.storage.mysql.sql +++ b/sqls/dtmsvr.storage.mysql.sql @@ -15,7 +15,7 @@ CREATE TABLE if not EXISTS dtm.trans_global ( `finish_time` datetime DEFAULT NULL, `rollback_time` datetime DEFAULT NULL, `options` varchar(1024) DEFAULT '', - `custom_data` varchar(256) DEFAULT '', + `custom_data` varchar(256) DEFAULT '' COMMENT 'nosql json存储,用于记录一些策略', `next_cron_interval` int(11) default null comment '下次定时处理的间隔', `next_cron_time` datetime default null comment '下次定时处理的时间', `owner` varchar(128) not null default '' comment '正在处理全局事务的锁定者', From 8fd58a2601839793374a2787378bba0b7dd049a8 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 20:05:10 +0800 Subject: [PATCH 2/8] fix: lint and request param set --- dtmsvr/api.go | 1 + dtmsvr/storage/boltdb/boltdb.go | 1 + dtmsvr/storage/redis/redis.go | 1 + dtmsvr/storage/sql/sql.go | 2 +- dtmsvr/storage/trans.go | 2 +- dtmsvr/trans_status.go | 3 ++- 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dtmsvr/api.go b/dtmsvr/api.go index 785be64..fbe7cf9 100644 --- a/dtmsvr/api.go +++ b/dtmsvr/api.go @@ -71,6 +71,7 @@ func svcForceStop(t *TransGlobal) interface{} { if err != nil { return err } + t.ForceStopReason = "" dbt.statusFailed(string(extData)) branches := GetStore().FindBranches(t.Gid) return dbt.Process(branches) diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 0c38708..4a124d7 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -364,6 +364,7 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s dtmimp.E2P(err) } +// StatusFailed change global trans status to failed with reason func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { old := global.Status global.Status = dtmcli.StatusFailed diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 0d86099..3b63d0a 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -232,6 +232,7 @@ end dtmimp.E2P(err) } +// StatusFailed change global trans status to failed with reason func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { old := global.Status global.Status = dtmcli.StatusFailed diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index a4b8945..923b60c 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -128,7 +128,7 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s } } -// StatusFailed changes global trans status to failed +// StatusFailed change global trans status to failed with reason func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { old := global.Status global.Status = dtmcli.StatusFailed diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index ed80f6d..b535065 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -39,7 +39,7 @@ type TransGlobalStore struct { NextCronTime *time.Time `json:"next_cron_time,omitempty"` Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` - ForceStopReason string `json:"force_stop_reason" gorm:"-"` + ForceStopReason string `json:"force_stop_reason,omitempty" gorm:"-"` // only for request ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 6d27df2..70cd54a 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -58,13 +58,14 @@ func (t *TransGlobal) changeStatus(status string) { t.Status = status } +// ExtDataType case extData type type ExtDataType string const ( - ExtDataTypeDefault ExtDataType = "" ExtDataTypeForceStop ExtDataType = "forceStop" ) +// ExtData custom extData struct type ExtData struct { Type ExtDataType `json:"type"` Msg string `json:"msg"` From 819b49372965f34d2aa412097512877c8a586ddb Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 20:11:53 +0800 Subject: [PATCH 3/8] docs: add comment --- dtmsvr/trans_status.go | 1 + 1 file changed, 1 insertion(+) diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 70cd54a..41ca28a 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -62,6 +62,7 @@ func (t *TransGlobal) changeStatus(status string) { type ExtDataType string const ( + // ExtDataTypeForceStop Type of user forced stop global gid ExtDataTypeForceStop ExtDataType = "forceStop" ) From ef7573b011ab3b2665906e94f06c6de550a36a99 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 20:27:08 +0800 Subject: [PATCH 4/8] fmt: import sort --- dtmsvr/storage/boltdb/boltdb.go | 2 +- dtmsvr/storage/redis/redis.go | 2 +- dtmsvr/storage/sql/sql.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 4a124d7..8d1cb36 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -8,10 +8,10 @@ package boltdb import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli" "strings" "time" + "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/storage" diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 3b63d0a..f3e08de 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -4,12 +4,12 @@ import ( "context" "errors" "fmt" - "github.com/dtm-labs/dtm/dtmcli" "sync" "time" "github.com/go-redis/redis/v8" + "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" diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 923b60c..0f10255 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -8,10 +8,10 @@ package sql import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli" "math" "time" + "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" From 321ef28c8caec325b4e0656ccf9f8ba087acb7f1 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 20:50:18 +0800 Subject: [PATCH 5/8] refact: rm StatsFailed func --- dtmsvr/storage/boltdb/boltdb.go | 16 ---------------- dtmsvr/storage/redis/redis.go | 26 -------------------------- dtmsvr/storage/sql/sql.go | 11 ----------- dtmsvr/storage/store.go | 1 - dtmsvr/storage/trans.go | 2 +- dtmsvr/trans_status.go | 3 ++- 6 files changed, 3 insertions(+), 56 deletions(-) diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 8d1cb36..83d234c 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "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/storage" @@ -364,21 +363,6 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s dtmimp.E2P(err) } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - err := s.boltDb.Update(func(t *bolt.Tx) error { - g := tGetGlobal(t, global.Gid) - if g == nil || g.Status != old { - return storage.ErrNotFound - } - tPutGlobal(t, global) - return nil - }) - dtmimp.E2P(err) -} - // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { oldUnix := global.NextCronTime.Unix() diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index f3e08de..d2cca87 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -9,7 +9,6 @@ import ( "github.com/go-redis/redis/v8" - "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" @@ -232,31 +231,6 @@ end dtmimp.E2P(err) } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - args := newArgList(). - AppendGid(global.Gid). - AppendObject(global). - AppendRaw(old). - AppendRaw(false). - AppendRaw(global.Gid). - AppendRaw(dtmcli.StatusFailed) - _, err := callLua(args, `-- ChangeGlobalStatus -local old = redis.call('GET', KEYS[4]) -if old ~= ARGV[4] then - return 'NOT_FOUND' -end -redis.call('SET', KEYS[1], ARGV[3], 'EX', ARGV[2]) -redis.call('SET', KEYS[4], ARGV[7], 'EX', ARGV[2]) -if ARGV[5] == '1' then - redis.call('ZREM', KEYS[3], ARGV[6]) -end -`) - dtmimp.E2P(err) -} - // LockOneGlobalTrans finds GlobalTrans func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalStore { expired := time.Now().Add(expireIn).Unix() diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 0f10255..fa8bcdd 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -11,7 +11,6 @@ import ( "math" "time" - "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" @@ -128,16 +127,6 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s } } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - dbr := dbGet().Must().Model(global).Where("status=? and gid=?", old, global.Gid).Select(updates).Updates(global) - if dbr.RowsAffected == 0 { - dtmimp.E2P(storage.ErrNotFound) - } -} - // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { global.UpdateTime = dtmutil.GetNextTime(0) diff --git a/dtmsvr/storage/store.go b/dtmsvr/storage/store.go index 8a6c62a..391c4dd 100644 --- a/dtmsvr/storage/store.go +++ b/dtmsvr/storage/store.go @@ -28,7 +28,6 @@ type Store interface { LockGlobalSaveBranches(gid string, status string, branches []TransBranchStore, branchStart int) MaySaveNewTrans(global *TransGlobalStore, branches []TransBranchStore) error ChangeGlobalStatus(global *TransGlobalStore, newStatus string, updates []string, finished bool) - StatusFailed(global *TransGlobalStore, updates []string) TouchCronTime(global *TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) LockOneGlobalTrans(expireIn time.Duration) *TransGlobalStore ResetCronTime(timeout time.Duration, limit int64) (succeedCount int64, hasRemaining bool, err error) diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index b535065..07a06ba 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -40,7 +40,7 @@ type TransGlobalStore struct { Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` ForceStopReason string `json:"force_stop_reason,omitempty" gorm:"-"` // only for request - ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options + ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 41ca28a..8952d17 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -77,8 +77,9 @@ func (t *TransGlobal) statusFailed(extData string) { now := time.Now() t.UpdateTime = &now t.ExtData = extData - GetStore().StatusFailed(&t.TransGlobalStore, updates) + GetStore().ChangeGlobalStatus(&t.TransGlobalStore, dtmcli.StatusFailed, updates, false) logger.Infof("StatusFailed to %s ok for %s", dtmcli.StatusFailed, t.TransGlobalStore.String()) + t.Status = dtmcli.StatusFailed } func (t *TransGlobal) changeBranchStatus(b *TransBranch, status string, branchPos int) { From d94e56642c095b17c5a7e6d51696f51524f597bc Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 21:46:28 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20test-cover.sh=20=E6=8E=92=E9=99=A4te?= =?UTF-8?q?st=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/test-cover.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 helper/test-cover.sh diff --git a/helper/test-cover.sh b/helper/test-cover.sh old mode 100644 new mode 100755 index 13bd654..d1a3d26 --- a/helper/test-cover.sh +++ b/helper/test-cover.sh @@ -1,7 +1,7 @@ set -x echo "" > coverage.txt for store in redis mysql boltdb; do - for d in $(go list ./... | grep -v vendor); do + for d in $(go list ./... | grep -v vendor | grep -v test); do TEST_STORE=$store go test -covermode count -coverprofile=profile.out -coverpkg=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/dtmgrpc,github.com/dtm-labs/dtm/dtmgrpc/dtmgimp,github.com/dtm-labs/dtm/dtmsvr,github.com/dtm-labs/dtm/dtmsvr/config,github.com/dtm-labs/dtm/dtmsvr/storage,github.com/dtm-labs/dtm/dtmsvr/storage/boltdb,github.com/dtm-labs/dtm/dtmsvr/storage/redis,github.com/dtm-labs/dtm/dtmsvr/storage/registry,github.com/dtm-labs/dtm/dtmsvr/storage/sql,github.com/dtm-labs/dtm/dtmutil -gcflags=-l $d || exit 1 if [ -f profile.out ]; then cat profile.out >> coverage.txt From 38e05c48ba672a5ca43ed2d0ef2d5aa28fabcd47 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Fri, 11 Mar 2022 19:47:39 +0800 Subject: [PATCH 7/8] =?UTF-8?q?refact:=20=E5=BC=BA=E5=88=B6=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E4=B8=8D=E8=AE=B0=E5=BD=95=E5=8E=9F=E5=9B=A0=E5=88=B0?= =?UTF-8?q?extData=E4=B8=AD=EF=BC=8C=E4=B9=8B=E5=90=8E=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=80=83=E8=99=91=E5=A6=82=E4=BD=95=E5=8C=BA=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dtmsvr/api.go | 11 +---------- dtmsvr/storage/trans.go | 1 - dtmsvr/trans_status.go | 19 ++----------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/dtmsvr/api.go b/dtmsvr/api.go index fbe7cf9..b2dbefa 100644 --- a/dtmsvr/api.go +++ b/dtmsvr/api.go @@ -7,7 +7,6 @@ package dtmsvr import ( - "encoding/json" "fmt" "github.com/dtm-labs/dtm/dtmcli" @@ -64,15 +63,7 @@ func svcForceStop(t *TransGlobal) interface{} { if dbt.Status == dtmcli.StatusSucceed || dbt.Status == dtmcli.StatusFailed { return nil } - extData, err := json.Marshal(&ExtData{ - Type: ExtDataTypeForceStop, - Msg: t.ForceStopReason, - }) - if err != nil { - return err - } - t.ForceStopReason = "" - dbt.statusFailed(string(extData)) + dbt.statusFailed() branches := GetStore().FindBranches(t.Gid) return dbt.Process(branches) } diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index 07a06ba..789ba0c 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -39,7 +39,6 @@ type TransGlobalStore struct { NextCronTime *time.Time `json:"next_cron_time,omitempty"` Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` - ForceStopReason string `json:"force_stop_reason,omitempty" gorm:"-"` // only for request ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 8952d17..876703b 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -58,25 +58,10 @@ func (t *TransGlobal) changeStatus(status string) { t.Status = status } -// ExtDataType case extData type -type ExtDataType string - -const ( - // ExtDataTypeForceStop Type of user forced stop global gid - ExtDataTypeForceStop ExtDataType = "forceStop" -) - -// ExtData custom extData struct -type ExtData struct { - Type ExtDataType `json:"type"` - Msg string `json:"msg"` -} - -func (t *TransGlobal) statusFailed(extData string) { - updates := []string{"status", "update_time", "ext_data"} +func (t *TransGlobal) statusFailed() { + updates := []string{"status", "update_time"} now := time.Now() t.UpdateTime = &now - t.ExtData = extData GetStore().ChangeGlobalStatus(&t.TransGlobalStore, dtmcli.StatusFailed, updates, false) logger.Infof("StatusFailed to %s ok for %s", dtmcli.StatusFailed, t.TransGlobalStore.String()) t.Status = dtmcli.StatusFailed From a754a0cabcd7dc8a6b8b669d634e180c8ba812fa Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Fri, 11 Mar 2022 20:54:07 +0800 Subject: [PATCH 8/8] feature: add makefile --- Makefile | 23 +++++++++++++++++++++++ dtmsvr/storage/trans.go | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0096486 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# dev env https://www.dtm.pub/other/develop.html +all: fmt lint test_all cover_test +.PHONY: all + +fmt: + @gofmt -s -w ./ + +lint: + @golangci-lint run + +.PHONY: test +test: + @go test ./... + +test_all: + TEST_STORE=redis go test ./... + TEST_STORE=boltdb go test ./... + TEST_STORE=mysql go test ./... + TEST_STORE=postgres go test ./... + +cover_test: + ./helper/test-cover.sh + diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index 789ba0c..4f37122 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -39,7 +39,7 @@ type TransGlobalStore struct { NextCronTime *time.Time `json:"next_cron_time,omitempty"` Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` - ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options + ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions }