Browse Source

Merge pull request #158 from Leizhengzi/main

fix dtmsrv relevant golangci lint error
pull/162/head v1.9.0
yedf2 4 years ago
committed by GitHub
parent
commit
5e5f1a2131
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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
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
var CronForwardDuration time.Duration = time.Duration(0)
var CronForwardDuration = time.Duration(0)
// CronTransOnce cron expired trans. use expireIn as expire time
func CronTransOnce() (gid string) {

9
dtmsvr/svr.go

@ -27,7 +27,12 @@ func StartSvr() {
app = httpMetrics(app)
addRoute(app)
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))
logger.FatalIfError(err)
@ -60,8 +65,8 @@ var UpdateBranchAsyncInterval = 200 * time.Millisecond
var updateBranchAsyncChan chan branchStatus = make(chan branchStatus, 1000)
func updateBranchAsync() {
defer dtmutil.RecoverPanic(nil)
for { // flush branches every second
defer dtmutil.RecoverPanic(nil)
updates := []TransBranch{}
started := time.Now()
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 {
go t.processInner(branches)
go func() {
err := t.processInner(branches)
if err != nil {
logger.Errorf("processInner err: %v", err)
}
}()
return dtmcli.MapSuccess
}
submitting := t.Status == dtmcli.StatusSubmitted

3
dtmsvr/trans_type_saga.go

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

6
dtmsvr/utils.go

@ -24,17 +24,17 @@ type branchStatus struct {
finishTime *time.Time
}
var p2e = dtmimp.P2E
var e2p = dtmimp.E2P
var conf = &config.Config
// GetStore returns storage.Store
func GetStore() storage.Store {
return registry.GetStore()
}
// 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
func GenGid() string {
@ -44,6 +44,8 @@ func GenGid() string {
// GetTransGlobal construct trans from db
func GetTransGlobal(gid string) *TransGlobal {
trans := GetStore().FindTransGlobalStore(gid)
//nolint:staticcheck
dtmimp.PanicIf(trans == nil, fmt.Errorf("no TransGlobal with gid: %s found", gid))
//nolint:staticcheck
return &TransGlobal{TransGlobalStore: *trans}
}

Loading…
Cancel
Save