Browse Source

fix deadlock

pull/385/head v1.16.7
yedf2 4 years ago
parent
commit
0d6cf35c9a
  1. 8
      dtmsvr/storage/sql/sql.go
  2. 2
      dtmsvr/svr.go
  3. 6
      dtmsvr/topics.go
  4. 4
      go.mod
  5. 3
      go.sum
  6. 2
      test/msg_barrier_test.go
  7. 2
      test/msg_grpc_barrier_test.go

8
dtmsvr/storage/sql/sql.go

@ -148,6 +148,14 @@ func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalS
dtmimp.DBTypePostgres: fmt.Sprintf(`id in (select id from trans_global where next_cron_time < '%s' and status in ('prepared', 'aborting', 'submitted') limit 1 )`, nextCronTime), dtmimp.DBTypePostgres: fmt.Sprintf(`id in (select id from trans_global where next_cron_time < '%s' and status in ('prepared', 'aborting', 'submitted') limit 1 )`, nextCronTime),
}[conf.Store.Driver] }[conf.Store.Driver]
ssql := fmt.Sprintf(`select count(1) from trans_global where %s`, where)
var cnt int64
err := db.ToSQLDB().QueryRow(ssql).Scan(&cnt)
dtmimp.PanicIf(err != nil, err)
if cnt == 0 {
return nil
}
sql := fmt.Sprintf(`UPDATE trans_global SET update_time='%s',next_cron_time='%s', owner='%s' WHERE %s`, sql := fmt.Sprintf(`UPDATE trans_global SET update_time='%s',next_cron_time='%s', owner='%s' WHERE %s`,
getTimeStr(0), getTimeStr(0),
getTimeStr(conf.RetryInterval), getTimeStr(conf.RetryInterval),

2
dtmsvr/svr.go

@ -23,6 +23,7 @@ import (
"github.com/dtm-labs/logger" "github.com/dtm-labs/logger"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
) )
@ -60,6 +61,7 @@ func StartSvr() *gin.Engine {
logger.FatalIfError(err) logger.FatalIfError(err)
s := grpc.NewServer(grpc.ChainUnaryInterceptor(grpcRecover, grpcMetrics, dtmgimp.GrpcServerLog)) s := grpc.NewServer(grpc.ChainUnaryInterceptor(grpcRecover, grpcMetrics, dtmgimp.GrpcServerLog))
dtmgpb.RegisterDtmServer(s, &dtmServer{}) dtmgpb.RegisterDtmServer(s, &dtmServer{})
reflection.Register(s)
logger.Infof("grpc listening at %v", lis.Addr()) logger.Infof("grpc listening at %v", lis.Addr())
go func() { go func() {
err := s.Serve(lis) err := s.Serve(lis)

6
dtmsvr/topics.go

@ -13,14 +13,14 @@ const (
var topicsMap = map[string]Topic{} var topicsMap = map[string]Topic{}
//Topic define topic info // Topic define topic info
type Topic struct { type Topic struct {
Name string `json:"k"` Name string `json:"k"`
Subscribers []Subscriber `json:"v"` Subscribers []Subscriber `json:"v"`
Version uint64 `json:"version"` Version uint64 `json:"version"`
} }
//Subscriber define subscriber info // Subscriber define subscriber info
type Subscriber struct { type Subscriber struct {
URL string `json:"url"` URL string `json:"url"`
Remark string `json:"remark"` Remark string `json:"remark"`
@ -111,5 +111,5 @@ func updateTopicsMap() {
topicsMap[kv.K] = newTopic topicsMap[kv.K] = newTopic
logger.Infof("topic updated. old topic:%v new topic:%v", topicsMap[kv.K], newTopic) logger.Infof("topic updated. old topic:%v new topic:%v", topicsMap[kv.K], newTopic)
} }
logger.Infof("all topic updated. topic:%v", topicsMap) logger.Debugf("all topic updated. topic:%v", topicsMap)
} }

4
go.mod

@ -3,7 +3,7 @@ module github.com/dtm-labs/dtm
go 1.16 go 1.16
require ( require (
github.com/agiledragon/gomonkey v2.0.2+incompatible github.com/agiledragon/gomonkey/v2 v2.2.0
github.com/dtm-labs/dtmdriver v0.0.6 github.com/dtm-labs/dtmdriver v0.0.6
github.com/dtm-labs/dtmdriver-dapr v0.0.1 github.com/dtm-labs/dtmdriver-dapr v0.0.1
github.com/dtm-labs/dtmdriver-ego v0.1.8 github.com/dtm-labs/dtmdriver-ego v0.1.8
@ -13,13 +13,13 @@ require (
github.com/dtm-labs/dtmdriver-springcloud v1.2.3 github.com/dtm-labs/dtmdriver-springcloud v1.2.3
github.com/dtm-labs/logger v0.0.2 github.com/dtm-labs/logger v0.0.2
github.com/gin-gonic/gin v1.7.7 github.com/gin-gonic/gin v1.7.7
github.com/go-errors/errors v1.4.2
github.com/go-redis/redis/v8 v8.11.5 github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.7.0 github.com/go-resty/resty/v2 v2.7.0
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/lib/pq v1.10.6 github.com/lib/pq v1.10.6
github.com/lithammer/shortuuid/v3 v3.0.7 github.com/lithammer/shortuuid/v3 v3.0.7
github.com/onsi/gomega v1.18.1 github.com/onsi/gomega v1.18.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2 github.com/prometheus/client_golang v1.12.2
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.0
github.com/ugorji/go v1.2.7 // indirect github.com/ugorji/go v1.2.7 // indirect

3
go.sum

@ -215,6 +215,8 @@ github.com/aerospike/aerospike-client-go v4.5.0+incompatible/go.mod h1:zj8LBEnWB
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= 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/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/agiledragon/gomonkey/v2 v2.2.0 h1:QJWqpdEhGV/JJy70sZ/LDnhbSlMrqHAWHcNOjz1kyuI=
github.com/agiledragon/gomonkey/v2 v2.2.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo= github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b/go.mod h1:Tie46d3UWzXpj+Fh9+DQTyaUxEpFBPOLXrnx7nxlKRo=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
@ -608,7 +610,6 @@ github.com/dtm-labs/dtmdriver-polaris v0.0.5 h1:vlM3mvkgYv6GkgK49Jx1ESvYTi2Os5Od
github.com/dtm-labs/dtmdriver-polaris v0.0.5/go.mod h1:FYF5ot7LCri5oA0qyvGzDRBZiMw08WlxjmFgzFQhIvo= github.com/dtm-labs/dtmdriver-polaris v0.0.5/go.mod h1:FYF5ot7LCri5oA0qyvGzDRBZiMw08WlxjmFgzFQhIvo=
github.com/dtm-labs/dtmdriver-springcloud v1.2.3 h1:AutSnngy+inr0PYoAT6pY/4Cw4aUZNq1pX7VN4j7tD8= github.com/dtm-labs/dtmdriver-springcloud v1.2.3 h1:AutSnngy+inr0PYoAT6pY/4Cw4aUZNq1pX7VN4j7tD8=
github.com/dtm-labs/dtmdriver-springcloud v1.2.3/go.mod h1:sswcxoTofararER63EhBu9O0Ab55w20fYp1KsE1HXww= github.com/dtm-labs/dtmdriver-springcloud v1.2.3/go.mod h1:sswcxoTofararER63EhBu9O0Ab55w20fYp1KsE1HXww=
github.com/dtm-labs/logger v0.0.1 h1:187UPkYviyOXelmkbew+Q94mg/BFjxJEsHfyHawu5YQ=
github.com/dtm-labs/logger v0.0.1/go.mod h1:0woMQZ6ljx9wZIl7hW8cuV2PRQmwEKxhqYtab7zVNWg= github.com/dtm-labs/logger v0.0.1/go.mod h1:0woMQZ6ljx9wZIl7hW8cuV2PRQmwEKxhqYtab7zVNWg=
github.com/dtm-labs/logger v0.0.2 h1:UQQTjDHnZhSbAHwXO9ISva1/AGO+MW9MjztAIzqJ1Tw= github.com/dtm-labs/logger v0.0.2 h1:UQQTjDHnZhSbAHwXO9ISva1/AGO+MW9MjztAIzqJ1Tw=
github.com/dtm-labs/logger v0.0.2/go.mod h1:WgJjaTSJ0WmITqMGEWDiaamrxgMkAH8TmwIhykuGugY= github.com/dtm-labs/logger v0.0.2/go.mod h1:WgJjaTSJ0WmITqMGEWDiaamrxgMkAH8TmwIhykuGugY=

2
test/msg_barrier_test.go

@ -6,7 +6,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/agiledragon/gomonkey" "github.com/agiledragon/gomonkey/v2"
"github.com/dtm-labs/dtm/client/dtmcli" "github.com/dtm-labs/dtm/client/dtmcli"
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/client/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/test/busi" "github.com/dtm-labs/dtm/test/busi"

2
test/msg_grpc_barrier_test.go

@ -6,7 +6,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/agiledragon/gomonkey" "github.com/agiledragon/gomonkey/v2"
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/client/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/client/dtmgrpc"
"github.com/dtm-labs/dtm/test/busi" "github.com/dtm-labs/dtm/test/busi"

Loading…
Cancel
Save