Browse Source

Ctx moved to TransBase

pull/273/head
yedf2 4 years ago
parent
commit
01419516ca
  1. 5
      dtmcli/dtmimp/trans_base.go
  2. 6
      dtmgrpc/dtmgimp/utils.go
  3. 1
      dtmsvr/trans_class.go

5
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(),
}
}

6
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

1
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
}

Loading…
Cancel
Save