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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
21 additions and
8 deletions
-
dtmsvr/cron.go
-
dtmsvr/svr.go
-
dtmsvr/trans_process.go
-
dtmsvr/trans_type_saga.go
-
dtmsvr/utils.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) { |
|
|
|
|
|
|
|
@ -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 |
|
|
|
|
|
|
|
@ -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 |
|
|
|
|
|
|
|
@ -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 { |
|
|
|
|
|
|
|
@ -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} |
|
|
|
} |
|
|
|
|