Skip to content

Commit

Permalink
Merge pull request dtm-labs#158 from Leizhengzi/main
Browse files Browse the repository at this point in the history
fix dtmsrv relevant golangci lint error
  • Loading branch information
yedf2 authored Jan 6, 2022
2 parents 44f66b8 + 3cc3895 commit 5e5f1a2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dtmsvr/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions dtmsvr/svr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion dtmsvr/trans_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion dtmsvr/trans_type_saga.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions dtmsvr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
}

0 comments on commit 5e5f1a2

Please sign in to comment.