Browse Source

fix dtmsrv(not contain subpackage) relevant golangci lint error

topic
liulei 5 years ago
parent
commit
3cc3895b78
  1. 4
      dtmsvr/cron.go
  2. 9
      dtmsvr/svr.go
  3. 7
      dtmsvr/trans_process.go
  4. 3
      dtmsvr/trans_type_saga.go
  5. 6
      dtmsvr/utils.go

4
dtmsvr/cron.go

@ -17,10 +17,10 @@ import (
) )
// NowForwardDuration will be set in test, trans may be timeout // NowForwardDuration will be set in test, trans may be timeout
var NowForwardDuration time.Duration = time.Duration(0) var NowForwardDuration = time.Duration(0)
// CronForwardDuration will be set in test. cron will fetch trans which expire in CronForwardDuration // CronForwardDuration will be set in test. cron will fetch trans which expire in CronForwardDuration
var CronForwardDuration time.Duration = time.Duration(0) var CronForwardDuration = time.Duration(0)
// CronTransOnce cron expired trans. use expireIn as expire time // CronTransOnce cron expired trans. use expireIn as expire time
func CronTransOnce() (gid string) { func CronTransOnce() (gid string) {

9
dtmsvr/svr.go

@ -27,7 +27,12 @@ func StartSvr() {
app = httpMetrics(app) app = httpMetrics(app)
addRoute(app) addRoute(app)
logger.Infof("dtmsvr listen at: %d", conf.HttpPort) logger.Infof("dtmsvr listen at: %d", conf.HttpPort)
go app.Run(fmt.Sprintf(":%d", conf.HttpPort)) go func() {
err := app.Run(fmt.Sprintf(":%d", conf.HttpPort))
if err != nil {
logger.Errorf("start server err: %v", err)
}
}()
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", conf.GrpcPort)) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", conf.GrpcPort))
logger.FatalIfError(err) logger.FatalIfError(err)
@ -60,8 +65,8 @@ var UpdateBranchAsyncInterval = 200 * time.Millisecond
var updateBranchAsyncChan chan branchStatus = make(chan branchStatus, 1000) var updateBranchAsyncChan chan branchStatus = make(chan branchStatus, 1000)
func updateBranchAsync() { func updateBranchAsync() {
defer dtmutil.RecoverPanic(nil)
for { // flush branches every second for { // flush branches every second
defer dtmutil.RecoverPanic(nil)
updates := []TransBranch{} updates := []TransBranch{}
started := time.Now() started := time.Now()
checkInterval := 20 * time.Millisecond checkInterval := 20 * time.Millisecond

7
dtmsvr/trans_process.go

@ -31,7 +31,12 @@ func (t *TransGlobal) process(branches []TransBranch) map[string]interface{} {
} }
if !t.WaitResult { if !t.WaitResult {
go t.processInner(branches) go func() {
err := t.processInner(branches)
if err != nil {
logger.Errorf("processInner err: %v", err)
}
}()
return dtmcli.MapSuccess return dtmcli.MapSuccess
} }
submitting := t.Status == dtmcli.StatusSubmitted submitting := t.Status == dtmcli.StatusSubmitted

3
dtmsvr/trans_type_saga.go

@ -21,7 +21,8 @@ type transSagaProcessor struct {
func init() { func init() {
registorProcessorCreator("saga", func(trans *TransGlobal) transProcessor { registorProcessorCreator("saga", func(trans *TransGlobal) transProcessor {
return &transSagaProcessor{TransGlobal: trans} }) return &transSagaProcessor{TransGlobal: trans}
})
} }
func (t *transSagaProcessor) GenBranches() []TransBranch { func (t *transSagaProcessor) GenBranches() []TransBranch {

6
dtmsvr/utils.go

@ -24,17 +24,17 @@ type branchStatus struct {
finishTime *time.Time finishTime *time.Time
} }
var p2e = dtmimp.P2E
var e2p = dtmimp.E2P var e2p = dtmimp.E2P
var conf = &config.Config var conf = &config.Config
// GetStore returns storage.Store
func GetStore() storage.Store { func GetStore() storage.Store {
return registry.GetStore() return registry.GetStore()
} }
// TransProcessedTestChan only for test usage. when transaction processed once, write gid to this chan // TransProcessedTestChan only for test usage. when transaction processed once, write gid to this chan
var TransProcessedTestChan chan string = nil var TransProcessedTestChan chan string
// GenGid generate gid, use uuid // GenGid generate gid, use uuid
func GenGid() string { func GenGid() string {
@ -44,6 +44,8 @@ func GenGid() string {
// GetTransGlobal construct trans from db // GetTransGlobal construct trans from db
func GetTransGlobal(gid string) *TransGlobal { func GetTransGlobal(gid string) *TransGlobal {
trans := GetStore().FindTransGlobalStore(gid) trans := GetStore().FindTransGlobalStore(gid)
//nolint:staticcheck
dtmimp.PanicIf(trans == nil, fmt.Errorf("no TransGlobal with gid: %s found", gid)) dtmimp.PanicIf(trans == nil, fmt.Errorf("no TransGlobal with gid: %s found", gid))
//nolint:staticcheck
return &TransGlobal{TransGlobalStore: *trans} return &TransGlobal{TransGlobalStore: *trans}
} }

Loading…
Cancel
Save