From 01419516ca5ca12465fc69ae2eef6b8600adfcb3 Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Sun, 17 Apr 2022 17:34:29 +0800 Subject: [PATCH] Ctx moved to TransBase --- dtmcli/dtmimp/trans_base.go | 5 +++-- dtmgrpc/dtmgimp/utils.go | 6 +++++- dtmsvr/trans_class.go | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dtmcli/dtmimp/trans_base.go b/dtmcli/dtmimp/trans_base.go index 00304d9..dc0c370 100644 --- a/dtmcli/dtmimp/trans_base.go +++ b/dtmcli/dtmimp/trans_base.go @@ -50,7 +50,6 @@ type TransOptions struct { PassthroughHeaders []string `json:"passthrough_headers,omitempty" gorm:"-"` // for inherit the specified gin context headers BranchHeaders map[string]string `json:"branch_headers,omitempty" gorm:"-"` // custom branch headers, dtm server => service api Concurrent bool `json:"concurrent" gorm:"-"` // for trans type: saga msg - Ctx context.Context `json:"-" gorm:"-"` } // TransBase base for all trans @@ -60,6 +59,7 @@ type TransBase struct { Dtm string `json:"-"` CustomData string `json:"custom_data,omitempty"` // nosql data persistence TransOptions + Ctx context.Context `json:"-" gorm:"-"` Steps []map[string]string `json:"steps,omitempty"` // use in MSG/SAGA Payloads []string `json:"payloads,omitempty"` // used in MSG/SAGA @@ -78,7 +78,8 @@ func NewTransBase(gid string, transType string, dtm string, branchID string) *Tr TransType: transType, BranchIDGen: BranchIDGen{BranchID: branchID}, Dtm: dtm, - TransOptions: TransOptions{PassthroughHeaders: PassthroughHeaders,Ctx: context.Background()}, + TransOptions: TransOptions{PassthroughHeaders: PassthroughHeaders}, + Ctx: context.Background(), } } diff --git a/dtmgrpc/dtmgimp/utils.go b/dtmgrpc/dtmgimp/utils.go index 02d9176..dd731f1 100644 --- a/dtmgrpc/dtmgimp/utils.go +++ b/dtmgrpc/dtmgimp/utils.go @@ -56,7 +56,11 @@ func TransInfo2Ctx(ctx context.Context, gid, transType, branchID, op, dtm string dtmpre+"op", op, dtmpre+"dtm", dtm, ) - return metadata.NewOutgoingContext(ctx, md) + nctx := ctx + if ctx == nil { + nctx = context.Background() + } + return metadata.NewOutgoingContext(nctx, md) } // Map2Kvs map to metadata kv diff --git a/dtmsvr/trans_class.go b/dtmsvr/trans_class.go index bedb590..b5ccc0f 100644 --- a/dtmsvr/trans_class.go +++ b/dtmsvr/trans_class.go @@ -16,6 +16,7 @@ import ( // TransGlobal global transaction type TransGlobal struct { storage.TransGlobalStore + Ctx context.Context lastTouched time.Time // record the start time of process updateBranchSync bool }