mirror of https://github.com/dtm-labs/dtm.git
committed by
GitHub
110 changed files with 3088 additions and 2899 deletions
@ -0,0 +1,14 @@ |
|||||
|
package dtmimp |
||||
|
|
||||
|
const ( |
||||
|
// ResultFailure for result of a trans/trans branch
|
||||
|
ResultFailure = "FAILURE" |
||||
|
// ResultSuccess for result of a trans/trans branch
|
||||
|
ResultSuccess = "SUCCESS" |
||||
|
// ResultOngoing for result of a trans/trans branch
|
||||
|
ResultOngoing = "ONGOING" |
||||
|
// DBTypeMysql const for driver mysql
|
||||
|
DBTypeMysql = "mysql" |
||||
|
// DBTypePostgres const for driver postgres
|
||||
|
DBTypePostgres = "postgres" |
||||
|
) |
||||
@ -1,4 +1,4 @@ |
|||||
package dtmcli |
package dtmimp |
||||
|
|
||||
import ( |
import ( |
||||
"fmt" |
"fmt" |
||||
@ -1,4 +1,4 @@ |
|||||
package dtmcli |
package dtmimp |
||||
|
|
||||
import ( |
import ( |
||||
"testing" |
"testing" |
||||
@ -0,0 +1,117 @@ |
|||||
|
package dtmimp |
||||
|
|
||||
|
import ( |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"net/url" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/go-resty/resty/v2" |
||||
|
) |
||||
|
|
||||
|
// BranchIDGen used to generate a sub branch id
|
||||
|
type BranchIDGen struct { |
||||
|
BranchID string |
||||
|
subBranchID int |
||||
|
} |
||||
|
|
||||
|
// NewSubBranchID generate a sub branch id
|
||||
|
func (g *BranchIDGen) NewSubBranchID() string { |
||||
|
if g.subBranchID >= 99 { |
||||
|
panic(fmt.Errorf("branch id is larger than 99")) |
||||
|
} |
||||
|
if len(g.BranchID) >= 20 { |
||||
|
panic(fmt.Errorf("total branch id is longer than 20")) |
||||
|
} |
||||
|
g.subBranchID = g.subBranchID + 1 |
||||
|
return g.CurrentSubBranchID() |
||||
|
} |
||||
|
|
||||
|
// CurrentSubBranchID return current branchID
|
||||
|
func (g *BranchIDGen) CurrentSubBranchID() string { |
||||
|
return g.BranchID + fmt.Sprintf("%02d", g.subBranchID) |
||||
|
} |
||||
|
|
||||
|
// TransOptions transaction options
|
||||
|
type TransOptions struct { |
||||
|
WaitResult bool `json:"wait_result,omitempty" gorm:"-"` |
||||
|
TimeoutToFail int64 `json:"timeout_to_fail,omitempty" gorm:"-"` // for trans type: xa, tcc
|
||||
|
RetryInterval int64 `json:"retry_interval,omitempty" gorm:"-"` // for trans type: msg saga xa tcc
|
||||
|
} |
||||
|
|
||||
|
// TransBase base for all trans
|
||||
|
type TransBase struct { |
||||
|
Gid string `json:"gid"` |
||||
|
TransType string `json:"trans_type"` |
||||
|
Dtm string `json:"-"` |
||||
|
CustomData string `json:"custom_data,omitempty"` |
||||
|
TransOptions |
||||
|
|
||||
|
Steps []map[string]string `json:"steps,omitempty"` // use in MSG/SAGA
|
||||
|
Payloads []string `json:"payloads,omitempty"` // used in MSG/SAGA
|
||||
|
BinPayloads [][]byte `json:"-"` |
||||
|
BranchIDGen `json:"-"` // used in XA/TCC
|
||||
|
Op string `json:"-"` // used in XA/TCC
|
||||
|
|
||||
|
QueryPrepared string `json:"query_prepared,omitempty"` // used in MSG
|
||||
|
} |
||||
|
|
||||
|
// SetOptions set options
|
||||
|
func (tb *TransBase) SetOptions(options *TransOptions) { |
||||
|
tb.TransOptions = *options |
||||
|
} |
||||
|
|
||||
|
// NewTransBase new a TransBase
|
||||
|
func NewTransBase(gid string, transType string, dtm string, branchID string) *TransBase { |
||||
|
return &TransBase{ |
||||
|
Gid: gid, |
||||
|
TransType: transType, |
||||
|
BranchIDGen: BranchIDGen{BranchID: branchID}, |
||||
|
Dtm: dtm, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// TransBaseFromQuery construct transaction info from request
|
||||
|
func TransBaseFromQuery(qs url.Values) *TransBase { |
||||
|
return NewTransBase(qs.Get("gid"), qs.Get("trans_type"), qs.Get("dtm"), qs.Get("branch_id")) |
||||
|
} |
||||
|
|
||||
|
// TransCallDtm TransBase call dtm
|
||||
|
func TransCallDtm(tb *TransBase, body interface{}, operation string) error { |
||||
|
resp, err := RestyClient.R(). |
||||
|
SetBody(body).Post(fmt.Sprintf("%s/%s", tb.Dtm, operation)) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
if !strings.Contains(resp.String(), ResultSuccess) { |
||||
|
return errors.New(resp.String()) |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
// TransRegisterBranch TransBase register a branch to dtm
|
||||
|
func TransRegisterBranch(tb *TransBase, added map[string]string, operation string) error { |
||||
|
m := map[string]string{ |
||||
|
"gid": tb.Gid, |
||||
|
"trans_type": tb.TransType, |
||||
|
} |
||||
|
for k, v := range added { |
||||
|
m[k] = v |
||||
|
} |
||||
|
return TransCallDtm(tb, m, operation) |
||||
|
} |
||||
|
|
||||
|
// TransRequestBranch TransBAse request branch result
|
||||
|
func TransRequestBranch(t *TransBase, body interface{}, branchID string, op string, url string) (*resty.Response, error) { |
||||
|
resp, err := RestyClient.R(). |
||||
|
SetBody(body). |
||||
|
SetQueryParams(map[string]string{ |
||||
|
"dtm": t.Dtm, |
||||
|
"gid": t.Gid, |
||||
|
"branch_id": branchID, |
||||
|
"trans_type": t.TransType, |
||||
|
"op": op, |
||||
|
}). |
||||
|
Post(url) |
||||
|
return resp, CheckResponse(resp, err) |
||||
|
} |
||||
@ -1,8 +1,6 @@ |
|||||
package dtmcli |
package dtmimp |
||||
|
|
||||
import ( |
import "database/sql" |
||||
"database/sql" |
|
||||
) |
|
||||
|
|
||||
// DB inteface of dtmcli db
|
// DB inteface of dtmcli db
|
||||
type DB interface { |
type DB interface { |
||||
@ -0,0 +1,19 @@ |
|||||
|
package dtmimp |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
) |
||||
|
|
||||
|
func TestTypes(t *testing.T) { |
||||
|
err := CatchP(func() { |
||||
|
idGen := BranchIDGen{BranchID: "12345678901234567890123"} |
||||
|
idGen.NewSubBranchID() |
||||
|
}) |
||||
|
assert.Error(t, err) |
||||
|
err = CatchP(func() { |
||||
|
idGen := BranchIDGen{subBranchID: 99} |
||||
|
idGen.NewSubBranchID() |
||||
|
}) |
||||
|
} |
||||
@ -1,4 +1,4 @@ |
|||||
package dtmcli |
package dtmimp |
||||
|
|
||||
import ( |
import ( |
||||
"errors" |
"errors" |
||||
@ -0,0 +1,38 @@ |
|||||
|
package dtmimp |
||||
|
|
||||
|
import ( |
||||
|
"errors" |
||||
|
|
||||
|
"github.com/go-resty/resty/v2" |
||||
|
) |
||||
|
|
||||
|
// ErrFailure error of FAILURE
|
||||
|
var ErrFailure = errors.New("FAILURE") |
||||
|
|
||||
|
// ErrOngoing error of ONGOING
|
||||
|
var ErrOngoing = errors.New("ONGOING") |
||||
|
|
||||
|
// MapSuccess HTTP result of SUCCESS
|
||||
|
var MapSuccess = map[string]interface{}{"dtm_result": ResultSuccess} |
||||
|
|
||||
|
// MapFailure HTTP result of FAILURE
|
||||
|
var MapFailure = map[string]interface{}{"dtm_result": ResultFailure} |
||||
|
|
||||
|
// RestyClient the resty object
|
||||
|
var RestyClient = resty.New() |
||||
|
|
||||
|
func init() { |
||||
|
// RestyClient.SetTimeout(3 * time.Second)
|
||||
|
// RestyClient.SetRetryCount(2)
|
||||
|
// RestyClient.SetRetryWaitTime(1 * time.Second)
|
||||
|
RestyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error { |
||||
|
r.URL = MayReplaceLocalhost(r.URL) |
||||
|
Logf("requesting: %s %s %v %v", r.Method, r.URL, r.Body, r.QueryParam) |
||||
|
return nil |
||||
|
}) |
||||
|
RestyClient.OnAfterResponse(func(c *resty.Client, resp *resty.Response) error { |
||||
|
r := resp.Request |
||||
|
Logf("requested: %s %s %s", r.Method, r.URL, resp.String()) |
||||
|
return nil |
||||
|
}) |
||||
|
} |
||||
@ -1,39 +0,0 @@ |
|||||
package dtmcli |
|
||||
|
|
||||
// Msg reliable msg type
|
|
||||
type Msg struct { |
|
||||
TransBase |
|
||||
Steps []MsgStep `json:"steps"` |
|
||||
QueryPrepared string `json:"query_prepared"` |
|
||||
} |
|
||||
|
|
||||
// MsgStep struct of one step msg
|
|
||||
type MsgStep struct { |
|
||||
Action string `json:"action"` |
|
||||
Data string `json:"data"` |
|
||||
} |
|
||||
|
|
||||
// NewMsg create new msg
|
|
||||
func NewMsg(server string, gid string) *Msg { |
|
||||
return &Msg{TransBase: *NewTransBase(gid, "msg", server, "")} |
|
||||
} |
|
||||
|
|
||||
// Add add a new step
|
|
||||
func (s *Msg) Add(action string, postData interface{}) *Msg { |
|
||||
s.Steps = append(s.Steps, MsgStep{ |
|
||||
Action: action, |
|
||||
Data: MustMarshalString(postData), |
|
||||
}) |
|
||||
return s |
|
||||
} |
|
||||
|
|
||||
// Prepare prepare the msg
|
|
||||
func (s *Msg) Prepare(queryPrepared string) error { |
|
||||
s.QueryPrepared = OrString(queryPrepared, s.QueryPrepared) |
|
||||
return s.callDtm(s, "prepare") |
|
||||
} |
|
||||
|
|
||||
// Submit submit the msg
|
|
||||
func (s *Msg) Submit() error { |
|
||||
return s.callDtm(s, "submit") |
|
||||
} |
|
||||
@ -0,0 +1,31 @@ |
|||||
|
package dtmcli |
||||
|
|
||||
|
import "github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
|
||||
|
// Msg reliable msg type
|
||||
|
type Msg struct { |
||||
|
dtmimp.TransBase |
||||
|
} |
||||
|
|
||||
|
// NewMsg create new msg
|
||||
|
func NewMsg(server string, gid string) *Msg { |
||||
|
return &Msg{TransBase: *dtmimp.NewTransBase(gid, "msg", server, "")} |
||||
|
} |
||||
|
|
||||
|
// Add add a new step
|
||||
|
func (s *Msg) Add(action string, postData interface{}) *Msg { |
||||
|
s.Steps = append(s.Steps, map[string]string{"action": action}) |
||||
|
s.Payloads = append(s.Payloads, dtmimp.MustMarshalString(postData)) |
||||
|
return s |
||||
|
} |
||||
|
|
||||
|
// Prepare prepare the msg, msg will later be submitted
|
||||
|
func (s *Msg) Prepare(queryPrepared string) error { |
||||
|
s.QueryPrepared = dtmimp.OrString(queryPrepared, s.QueryPrepared) |
||||
|
return dtmimp.TransCallDtm(&s.TransBase, s, "prepare") |
||||
|
} |
||||
|
|
||||
|
// Submit submit the msg
|
||||
|
func (s *Msg) Submit() error { |
||||
|
return dtmimp.TransCallDtm(&s.TransBase, s, "submit") |
||||
|
} |
||||
@ -1,18 +1,14 @@ |
|||||
package dtmgrpc |
package dtmgrpc |
||||
|
|
||||
import ( |
import ( |
||||
|
"context" |
||||
|
|
||||
"github.com/yedf/dtm/dtmcli" |
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmgrpc/dtmgimp" |
||||
) |
) |
||||
|
|
||||
// BranchBarrier 子事务屏障
|
// BarrierFromGrpc generate a Barrier from grpc context
|
||||
type BranchBarrier struct { |
func BarrierFromGrpc(ctx context.Context) (*dtmcli.BranchBarrier, error) { |
||||
*dtmcli.BranchBarrier |
tb := dtmgimp.TransBaseFromGrpc(ctx) |
||||
} |
return dtmcli.BarrierFrom(tb.TransType, tb.Gid, tb.BranchID, tb.Op) |
||||
|
|
||||
// BarrierFromGrpc 从BusiRequest生成一个Barrier
|
|
||||
func BarrierFromGrpc(in *BusiRequest) (*BranchBarrier, error) { |
|
||||
b, err := dtmcli.BarrierFrom(in.Info.TransType, in.Info.Gid, in.Info.BranchID, in.Info.BranchType) |
|
||||
return &BranchBarrier{ |
|
||||
BranchBarrier: b, |
|
||||
}, err |
|
||||
} |
} |
||||
|
|||||
@ -0,0 +1,558 @@ |
|||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
|
// versions:
|
||||
|
// protoc-gen-go v1.27.1
|
||||
|
// protoc v3.17.3
|
||||
|
// source: dtmgrpc/dtmgimp/dtmgimp.proto
|
||||
|
|
||||
|
package dtmgimp |
||||
|
|
||||
|
import ( |
||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect" |
||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl" |
||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb" |
||||
|
reflect "reflect" |
||||
|
sync "sync" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) |
||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) |
||||
|
) |
||||
|
|
||||
|
type DtmTransOptions struct { |
||||
|
state protoimpl.MessageState |
||||
|
sizeCache protoimpl.SizeCache |
||||
|
unknownFields protoimpl.UnknownFields |
||||
|
|
||||
|
WaitResult bool `protobuf:"varint,1,opt,name=WaitResult,proto3" json:"WaitResult,omitempty"` |
||||
|
TimeoutToFail int64 `protobuf:"varint,2,opt,name=TimeoutToFail,proto3" json:"TimeoutToFail,omitempty"` |
||||
|
RetryInterval int64 `protobuf:"varint,3,opt,name=RetryInterval,proto3" json:"RetryInterval,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (x *DtmTransOptions) Reset() { |
||||
|
*x = DtmTransOptions{} |
||||
|
if protoimpl.UnsafeEnabled { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[0] |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmTransOptions) String() string { |
||||
|
return protoimpl.X.MessageStringOf(x) |
||||
|
} |
||||
|
|
||||
|
func (*DtmTransOptions) ProtoMessage() {} |
||||
|
|
||||
|
func (x *DtmTransOptions) ProtoReflect() protoreflect.Message { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[0] |
||||
|
if protoimpl.UnsafeEnabled && x != nil { |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
if ms.LoadMessageInfo() == nil { |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
return ms |
||||
|
} |
||||
|
return mi.MessageOf(x) |
||||
|
} |
||||
|
|
||||
|
// Deprecated: Use DtmTransOptions.ProtoReflect.Descriptor instead.
|
||||
|
func (*DtmTransOptions) Descriptor() ([]byte, []int) { |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{0} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmTransOptions) GetWaitResult() bool { |
||||
|
if x != nil { |
||||
|
return x.WaitResult |
||||
|
} |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
func (x *DtmTransOptions) GetTimeoutToFail() int64 { |
||||
|
if x != nil { |
||||
|
return x.TimeoutToFail |
||||
|
} |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (x *DtmTransOptions) GetRetryInterval() int64 { |
||||
|
if x != nil { |
||||
|
return x.RetryInterval |
||||
|
} |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
// DtmRequest request sent to dtm server
|
||||
|
type DtmRequest struct { |
||||
|
state protoimpl.MessageState |
||||
|
sizeCache protoimpl.SizeCache |
||||
|
unknownFields protoimpl.UnknownFields |
||||
|
|
||||
|
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
||||
|
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` |
||||
|
TransOptions *DtmTransOptions `protobuf:"bytes,3,opt,name=TransOptions,proto3" json:"TransOptions,omitempty"` |
||||
|
CustomedData string `protobuf:"bytes,4,opt,name=CustomedData,proto3" json:"CustomedData,omitempty"` |
||||
|
BinPayloads [][]byte `protobuf:"bytes,5,rep,name=BinPayloads,proto3" json:"BinPayloads,omitempty"` // for MSG/SAGA branch payloads
|
||||
|
QueryPrepared string `protobuf:"bytes,6,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"` // for MSG
|
||||
|
Steps string `protobuf:"bytes,7,opt,name=Steps,proto3" json:"Steps,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) Reset() { |
||||
|
*x = DtmRequest{} |
||||
|
if protoimpl.UnsafeEnabled { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[1] |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) String() string { |
||||
|
return protoimpl.X.MessageStringOf(x) |
||||
|
} |
||||
|
|
||||
|
func (*DtmRequest) ProtoMessage() {} |
||||
|
|
||||
|
func (x *DtmRequest) ProtoReflect() protoreflect.Message { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[1] |
||||
|
if protoimpl.UnsafeEnabled && x != nil { |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
if ms.LoadMessageInfo() == nil { |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
return ms |
||||
|
} |
||||
|
return mi.MessageOf(x) |
||||
|
} |
||||
|
|
||||
|
// Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead.
|
||||
|
func (*DtmRequest) Descriptor() ([]byte, []int) { |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{1} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetGid() string { |
||||
|
if x != nil { |
||||
|
return x.Gid |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetTransType() string { |
||||
|
if x != nil { |
||||
|
return x.TransType |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetTransOptions() *DtmTransOptions { |
||||
|
if x != nil { |
||||
|
return x.TransOptions |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetCustomedData() string { |
||||
|
if x != nil { |
||||
|
return x.CustomedData |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetBinPayloads() [][]byte { |
||||
|
if x != nil { |
||||
|
return x.BinPayloads |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetQueryPrepared() string { |
||||
|
if x != nil { |
||||
|
return x.QueryPrepared |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmRequest) GetSteps() string { |
||||
|
if x != nil { |
||||
|
return x.Steps |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
type DtmGidReply struct { |
||||
|
state protoimpl.MessageState |
||||
|
sizeCache protoimpl.SizeCache |
||||
|
unknownFields protoimpl.UnknownFields |
||||
|
|
||||
|
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (x *DtmGidReply) Reset() { |
||||
|
*x = DtmGidReply{} |
||||
|
if protoimpl.UnsafeEnabled { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[2] |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmGidReply) String() string { |
||||
|
return protoimpl.X.MessageStringOf(x) |
||||
|
} |
||||
|
|
||||
|
func (*DtmGidReply) ProtoMessage() {} |
||||
|
|
||||
|
func (x *DtmGidReply) ProtoReflect() protoreflect.Message { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[2] |
||||
|
if protoimpl.UnsafeEnabled && x != nil { |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
if ms.LoadMessageInfo() == nil { |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
return ms |
||||
|
} |
||||
|
return mi.MessageOf(x) |
||||
|
} |
||||
|
|
||||
|
// Deprecated: Use DtmGidReply.ProtoReflect.Descriptor instead.
|
||||
|
func (*DtmGidReply) Descriptor() ([]byte, []int) { |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{2} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmGidReply) GetGid() string { |
||||
|
if x != nil { |
||||
|
return x.Gid |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
type DtmBranchInfo struct { |
||||
|
state protoimpl.MessageState |
||||
|
sizeCache protoimpl.SizeCache |
||||
|
unknownFields protoimpl.UnknownFields |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchInfo) Reset() { |
||||
|
*x = DtmBranchInfo{} |
||||
|
if protoimpl.UnsafeEnabled { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[3] |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchInfo) String() string { |
||||
|
return protoimpl.X.MessageStringOf(x) |
||||
|
} |
||||
|
|
||||
|
func (*DtmBranchInfo) ProtoMessage() {} |
||||
|
|
||||
|
func (x *DtmBranchInfo) ProtoReflect() protoreflect.Message { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[3] |
||||
|
if protoimpl.UnsafeEnabled && x != nil { |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
if ms.LoadMessageInfo() == nil { |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
return ms |
||||
|
} |
||||
|
return mi.MessageOf(x) |
||||
|
} |
||||
|
|
||||
|
// Deprecated: Use DtmBranchInfo.ProtoReflect.Descriptor instead.
|
||||
|
func (*DtmBranchInfo) Descriptor() ([]byte, []int) { |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{3} |
||||
|
} |
||||
|
|
||||
|
type DtmBranchRequest struct { |
||||
|
state protoimpl.MessageState |
||||
|
sizeCache protoimpl.SizeCache |
||||
|
unknownFields protoimpl.UnknownFields |
||||
|
|
||||
|
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
||||
|
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` |
||||
|
BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` |
||||
|
Op string `protobuf:"bytes,4,opt,name=Op,proto3" json:"Op,omitempty"` |
||||
|
Data map[string]string `protobuf:"bytes,5,rep,name=Data,proto3" json:"Data,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` |
||||
|
BusiPayload []byte `protobuf:"bytes,6,opt,name=BusiPayload,proto3" json:"BusiPayload,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) Reset() { |
||||
|
*x = DtmBranchRequest{} |
||||
|
if protoimpl.UnsafeEnabled { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[4] |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) String() string { |
||||
|
return protoimpl.X.MessageStringOf(x) |
||||
|
} |
||||
|
|
||||
|
func (*DtmBranchRequest) ProtoMessage() {} |
||||
|
|
||||
|
func (x *DtmBranchRequest) ProtoReflect() protoreflect.Message { |
||||
|
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[4] |
||||
|
if protoimpl.UnsafeEnabled && x != nil { |
||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
|
if ms.LoadMessageInfo() == nil { |
||||
|
ms.StoreMessageInfo(mi) |
||||
|
} |
||||
|
return ms |
||||
|
} |
||||
|
return mi.MessageOf(x) |
||||
|
} |
||||
|
|
||||
|
// Deprecated: Use DtmBranchRequest.ProtoReflect.Descriptor instead.
|
||||
|
func (*DtmBranchRequest) Descriptor() ([]byte, []int) { |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{4} |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetGid() string { |
||||
|
if x != nil { |
||||
|
return x.Gid |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetTransType() string { |
||||
|
if x != nil { |
||||
|
return x.TransType |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetBranchID() string { |
||||
|
if x != nil { |
||||
|
return x.BranchID |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetBranchType() string { |
||||
|
if x != nil { |
||||
|
return x.Op |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetData() map[string]string { |
||||
|
if x != nil { |
||||
|
return x.Data |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (x *DtmBranchRequest) GetBusiPayload() []byte { |
||||
|
if x != nil { |
||||
|
return x.BusiPayload |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
var File_dtmgrpc_dtmgimp_dtmgimp_proto protoreflect.FileDescriptor |
||||
|
|
||||
|
var file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDesc = []byte{ |
||||
|
0x0a, 0x1d, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, |
||||
|
0x70, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, |
||||
|
0x07, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, |
||||
|
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, |
||||
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x0f, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, |
||||
|
0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, |
||||
|
0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, |
||||
|
0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x54, 0x69, 0x6d, 0x65, |
||||
|
0x6f, 0x75, 0x74, 0x54, 0x6f, 0x46, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, |
||||
|
0x0d, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x54, 0x6f, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x24, |
||||
|
0x0a, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x79, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x18, |
||||
|
0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x79, 0x49, 0x6e, 0x74, 0x65, |
||||
|
0x72, 0x76, 0x61, 0x6c, 0x22, 0xfc, 0x01, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, |
||||
|
0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, |
||||
|
0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, |
||||
|
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, |
||||
|
0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, |
||||
|
0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x64, 0x74, 0x6d, 0x67, |
||||
|
0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, |
||||
|
0x6f, 0x6e, 0x73, 0x52, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, |
||||
|
0x73, 0x12, 0x22, 0x0a, 0x0c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x64, 0x44, 0x61, 0x74, |
||||
|
0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, |
||||
|
0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x20, 0x0a, 0x0b, 0x42, 0x69, 0x6e, 0x50, 0x61, 0x79, 0x6c, |
||||
|
0x6f, 0x61, 0x64, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x69, 0x6e, 0x50, |
||||
|
0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, |
||||
|
0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, |
||||
|
0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x12, 0x14, 0x0a, |
||||
|
0x05, 0x53, 0x74, 0x65, 0x70, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x53, 0x74, |
||||
|
0x65, 0x70, 0x73, 0x22, 0x1f, 0x0a, 0x0b, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, 0x70, |
||||
|
0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, |
||||
|
0x03, 0x47, 0x69, 0x64, 0x22, 0x0f, 0x0a, 0x0d, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, |
||||
|
0x68, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x92, 0x02, 0x0a, 0x10, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, |
||||
|
0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, |
||||
|
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, |
||||
|
0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, |
||||
|
0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, |
||||
|
0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, |
||||
|
0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, |
||||
|
0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x42, 0x72, 0x61, 0x6e, |
||||
|
0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, |
||||
|
0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, |
||||
|
0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, |
||||
|
0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, |
||||
|
0x20, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x06, |
||||
|
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, |
||||
|
0x64, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, |
||||
|
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, |
||||
|
0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, |
||||
|
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xb1, 0x02, 0x0a, 0x03, 0x44, |
||||
|
0x74, 0x6d, 0x12, 0x38, 0x0a, 0x06, 0x4e, 0x65, 0x77, 0x47, 0x69, 0x64, 0x12, 0x16, 0x2e, 0x67, |
||||
|
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, |
||||
|
0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, |
||||
|
0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, |
||||
|
0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, |
||||
|
0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, |
||||
|
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, |
||||
|
0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, |
||||
|
0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, |
||||
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, |
||||
|
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, |
||||
|
0x36, 0x0a, 0x05, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, |
||||
|
0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, |
||||
|
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, |
||||
|
0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, |
||||
|
0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x19, 0x2e, 0x64, 0x74, 0x6d, 0x67, |
||||
|
0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, |
||||
|
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, |
||||
|
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x25, |
||||
|
0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x65, 0x64, |
||||
|
0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x74, |
||||
|
0x6d, 0x67, 0x69, 0x6d, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, |
||||
|
} |
||||
|
|
||||
|
var ( |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescOnce sync.Once |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescData = file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDesc |
||||
|
) |
||||
|
|
||||
|
func file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP() []byte { |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescOnce.Do(func() { |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescData) |
||||
|
}) |
||||
|
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescData |
||||
|
} |
||||
|
|
||||
|
var file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes = make([]protoimpl.MessageInfo, 6) |
||||
|
var file_dtmgrpc_dtmgimp_dtmgimp_proto_goTypes = []interface{}{ |
||||
|
(*DtmTransOptions)(nil), // 0: dtmgimp.DtmTransOptions
|
||||
|
(*DtmRequest)(nil), // 1: dtmgimp.DtmRequest
|
||||
|
(*DtmGidReply)(nil), // 2: dtmgimp.DtmGidReply
|
||||
|
(*DtmBranchInfo)(nil), // 3: dtmgimp.DtmBranchInfo
|
||||
|
(*DtmBranchRequest)(nil), // 4: dtmgimp.DtmBranchRequest
|
||||
|
nil, // 5: dtmgimp.DtmBranchRequest.DataEntry
|
||||
|
(*emptypb.Empty)(nil), // 6: google.protobuf.Empty
|
||||
|
} |
||||
|
var file_dtmgrpc_dtmgimp_dtmgimp_proto_depIdxs = []int32{ |
||||
|
0, // 0: dtmgimp.DtmRequest.TransOptions:type_name -> dtmgimp.DtmTransOptions
|
||||
|
5, // 1: dtmgimp.DtmBranchRequest.Data:type_name -> dtmgimp.DtmBranchRequest.DataEntry
|
||||
|
6, // 2: dtmgimp.Dtm.NewGid:input_type -> google.protobuf.Empty
|
||||
|
1, // 3: dtmgimp.Dtm.Submit:input_type -> dtmgimp.DtmRequest
|
||||
|
1, // 4: dtmgimp.Dtm.Prepare:input_type -> dtmgimp.DtmRequest
|
||||
|
1, // 5: dtmgimp.Dtm.Abort:input_type -> dtmgimp.DtmRequest
|
||||
|
4, // 6: dtmgimp.Dtm.RegisterBranch:input_type -> dtmgimp.DtmBranchRequest
|
||||
|
2, // 7: dtmgimp.Dtm.NewGid:output_type -> dtmgimp.DtmGidReply
|
||||
|
6, // 8: dtmgimp.Dtm.Submit:output_type -> google.protobuf.Empty
|
||||
|
6, // 9: dtmgimp.Dtm.Prepare:output_type -> google.protobuf.Empty
|
||||
|
6, // 10: dtmgimp.Dtm.Abort:output_type -> google.protobuf.Empty
|
||||
|
6, // 11: dtmgimp.Dtm.RegisterBranch:output_type -> google.protobuf.Empty
|
||||
|
7, // [7:12] is the sub-list for method output_type
|
||||
|
2, // [2:7] is the sub-list for method input_type
|
||||
|
2, // [2:2] is the sub-list for extension type_name
|
||||
|
2, // [2:2] is the sub-list for extension extendee
|
||||
|
0, // [0:2] is the sub-list for field type_name
|
||||
|
} |
||||
|
|
||||
|
func init() { file_dtmgrpc_dtmgimp_dtmgimp_proto_init() } |
||||
|
func file_dtmgrpc_dtmgimp_dtmgimp_proto_init() { |
||||
|
if File_dtmgrpc_dtmgimp_dtmgimp_proto != nil { |
||||
|
return |
||||
|
} |
||||
|
if !protoimpl.UnsafeEnabled { |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { |
||||
|
switch v := v.(*DtmTransOptions); i { |
||||
|
case 0: |
||||
|
return &v.state |
||||
|
case 1: |
||||
|
return &v.sizeCache |
||||
|
case 2: |
||||
|
return &v.unknownFields |
||||
|
default: |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { |
||||
|
switch v := v.(*DtmRequest); i { |
||||
|
case 0: |
||||
|
return &v.state |
||||
|
case 1: |
||||
|
return &v.sizeCache |
||||
|
case 2: |
||||
|
return &v.unknownFields |
||||
|
default: |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { |
||||
|
switch v := v.(*DtmGidReply); i { |
||||
|
case 0: |
||||
|
return &v.state |
||||
|
case 1: |
||||
|
return &v.sizeCache |
||||
|
case 2: |
||||
|
return &v.unknownFields |
||||
|
default: |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { |
||||
|
switch v := v.(*DtmBranchInfo); i { |
||||
|
case 0: |
||||
|
return &v.state |
||||
|
case 1: |
||||
|
return &v.sizeCache |
||||
|
case 2: |
||||
|
return &v.unknownFields |
||||
|
default: |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { |
||||
|
switch v := v.(*DtmBranchRequest); i { |
||||
|
case 0: |
||||
|
return &v.state |
||||
|
case 1: |
||||
|
return &v.sizeCache |
||||
|
case 2: |
||||
|
return &v.unknownFields |
||||
|
default: |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
type x struct{} |
||||
|
out := protoimpl.TypeBuilder{ |
||||
|
File: protoimpl.DescBuilder{ |
||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
||||
|
RawDescriptor: file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDesc, |
||||
|
NumEnums: 0, |
||||
|
NumMessages: 6, |
||||
|
NumExtensions: 0, |
||||
|
NumServices: 1, |
||||
|
}, |
||||
|
GoTypes: file_dtmgrpc_dtmgimp_dtmgimp_proto_goTypes, |
||||
|
DependencyIndexes: file_dtmgrpc_dtmgimp_dtmgimp_proto_depIdxs, |
||||
|
MessageInfos: file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes, |
||||
|
}.Build() |
||||
|
File_dtmgrpc_dtmgimp_dtmgimp_proto = out.File |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDesc = nil |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_goTypes = nil |
||||
|
file_dtmgrpc_dtmgimp_dtmgimp_proto_depIdxs = nil |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
syntax = "proto3"; |
||||
|
|
||||
|
option go_package = "github.com/yedf/dtm/dtmgrpc/dtmgimp"; |
||||
|
import "google/protobuf/empty.proto"; |
||||
|
|
||||
|
package dtmgimp; |
||||
|
|
||||
|
// The dtm service definition. |
||||
|
service Dtm { |
||||
|
rpc NewGid(google.protobuf.Empty) returns (DtmGidReply) {} |
||||
|
rpc Submit(DtmRequest) returns (google.protobuf.Empty) {} |
||||
|
rpc Prepare(DtmRequest) returns (google.protobuf.Empty) {} |
||||
|
rpc Abort(DtmRequest) returns (google.protobuf.Empty) {} |
||||
|
rpc RegisterBranch(DtmBranchRequest) returns (google.protobuf.Empty) {} |
||||
|
} |
||||
|
|
||||
|
message DtmTransOptions { |
||||
|
bool WaitResult = 1; |
||||
|
int64 TimeoutToFail = 2; |
||||
|
int64 RetryInterval = 3; |
||||
|
} |
||||
|
|
||||
|
// DtmRequest request sent to dtm server |
||||
|
message DtmRequest { |
||||
|
string Gid = 1; |
||||
|
string TransType = 2; |
||||
|
DtmTransOptions TransOptions = 3; |
||||
|
string CustomedData = 4; |
||||
|
repeated bytes BinPayloads = 5; // for MSG/SAGA branch payloads |
||||
|
string QueryPrepared = 6; // for MSG |
||||
|
string Steps = 7; |
||||
|
} |
||||
|
|
||||
|
message DtmGidReply { |
||||
|
string Gid = 1; |
||||
|
} |
||||
|
|
||||
|
message DtmBranchRequest { |
||||
|
string Gid = 1; |
||||
|
string TransType = 2; |
||||
|
string BranchID = 3; |
||||
|
string Op = 4; |
||||
|
map<string, string> Data = 5; |
||||
|
bytes BusiPayload = 6; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,67 @@ |
|||||
|
package dtmgimp |
||||
|
|
||||
|
import ( |
||||
|
sync "sync" |
||||
|
|
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
grpc "google.golang.org/grpc" |
||||
|
) |
||||
|
|
||||
|
type rawCodec struct{} |
||||
|
|
||||
|
func (cb rawCodec) Marshal(v interface{}) ([]byte, error) { |
||||
|
return v.([]byte), nil |
||||
|
} |
||||
|
|
||||
|
func (cb rawCodec) Unmarshal(data []byte, v interface{}) error { |
||||
|
ba, _ := v.([]byte) |
||||
|
for index, byte := range data { |
||||
|
ba[index] = byte |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (cb rawCodec) Name() string { return "dtm_raw" } |
||||
|
|
||||
|
var normalClients, rawClients sync.Map |
||||
|
|
||||
|
// MustGetDtmClient 1
|
||||
|
func MustGetDtmClient(grpcServer string) DtmClient { |
||||
|
return NewDtmClient(MustGetGrpcConn(grpcServer, false)) |
||||
|
} |
||||
|
|
||||
|
// MustGetRawDtmClient must get raw codec grpc conn
|
||||
|
func MustGetRawDtmClient(grpcServer string) DtmClient { |
||||
|
return NewDtmClient(MustGetGrpcConn(grpcServer, true)) |
||||
|
} |
||||
|
|
||||
|
// GetGrpcConn 1
|
||||
|
func GetGrpcConn(grpcServer string, isRaw bool) (conn *grpc.ClientConn, rerr error) { |
||||
|
clients := &normalClients |
||||
|
if isRaw { |
||||
|
clients = &rawClients |
||||
|
} |
||||
|
grpcServer = dtmimp.MayReplaceLocalhost(grpcServer) |
||||
|
v, ok := clients.Load(grpcServer) |
||||
|
if !ok { |
||||
|
opts := grpc.WithDefaultCallOptions() |
||||
|
if isRaw { |
||||
|
opts = grpc.WithDefaultCallOptions(grpc.ForceCodec(rawCodec{})) |
||||
|
} |
||||
|
dtmimp.Logf("grpc client connecting %s", grpcServer) |
||||
|
conn, rerr := grpc.Dial(grpcServer, grpc.WithInsecure(), grpc.WithUnaryInterceptor(GrpcClientLog), opts) |
||||
|
if rerr == nil { |
||||
|
clients.Store(grpcServer, conn) |
||||
|
v = conn |
||||
|
dtmimp.Logf("grpc client inited for %s", grpcServer) |
||||
|
} |
||||
|
} |
||||
|
return v.(*grpc.ClientConn), rerr |
||||
|
} |
||||
|
|
||||
|
// MustGetGrpcConn 1
|
||||
|
func MustGetGrpcConn(grpcServer string, isRaw bool) *grpc.ClientConn { |
||||
|
conn, err := GetGrpcConn(grpcServer, isRaw) |
||||
|
dtmimp.E2P(err) |
||||
|
return conn |
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
package dtmgimp |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"google.golang.org/grpc" |
||||
|
"google.golang.org/grpc/codes" |
||||
|
"google.golang.org/grpc/status" |
||||
|
) |
||||
|
|
||||
|
// GetServerAndMethod 将grpc的url分解为server和method
|
||||
|
func GetServerAndMethod(grpcURL string) (string, string) { |
||||
|
fs := strings.Split(grpcURL, "/") |
||||
|
server := fs[0] |
||||
|
method := "/" + strings.Join(fs[1:], "/") |
||||
|
return server, method |
||||
|
} |
||||
|
|
||||
|
// GrpcServerLog 打印grpc服务端的日志
|
||||
|
func GrpcServerLog(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { |
||||
|
dtmimp.Logf("grpc server handling: %s %v", info.FullMethod, req) |
||||
|
LogDtmCtx(ctx) |
||||
|
m, err := handler(ctx, req) |
||||
|
res := fmt.Sprintf("grpc server handled: %s %v result: %v err: %v", info.FullMethod, req, m, err) |
||||
|
if err != nil { |
||||
|
dtmimp.LogRedf("%s", res) |
||||
|
} else { |
||||
|
dtmimp.Logf("%s", res) |
||||
|
} |
||||
|
return m, err |
||||
|
} |
||||
|
|
||||
|
// GrpcClientLog 打印grpc服务端的日志
|
||||
|
func GrpcClientLog(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { |
||||
|
dtmimp.Logf("grpc client calling: %s%s %v", cc.Target(), method, req) |
||||
|
LogDtmCtx(ctx) |
||||
|
err := invoker(ctx, method, req, reply, cc, opts...) |
||||
|
res := fmt.Sprintf("grpc client called: %s%s %v result: %v err: %v", cc.Target(), method, req, reply, err) |
||||
|
if err != nil { |
||||
|
dtmimp.LogRedf("%s", res) |
||||
|
} else { |
||||
|
dtmimp.Logf("%s", res) |
||||
|
} |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
// Result2Error 将通用的result转成grpc的error
|
||||
|
func Result2Error(res interface{}, err error) error { |
||||
|
e := dtmimp.CheckResult(res, err) |
||||
|
if e == dtmimp.ErrFailure { |
||||
|
dtmimp.LogRedf("failure: res: %v, err: %v", res, e) |
||||
|
return status.New(codes.Aborted, dtmcli.ResultFailure).Err() |
||||
|
} else if e == dtmimp.ErrOngoing { |
||||
|
return status.New(codes.Aborted, dtmcli.ResultOngoing).Err() |
||||
|
} |
||||
|
return e |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
package dtmgimp |
||||
|
|
||||
|
import ( |
||||
|
context "context" |
||||
|
|
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"google.golang.org/grpc/metadata" |
||||
|
"google.golang.org/protobuf/proto" |
||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb" |
||||
|
) |
||||
|
|
||||
|
// MustProtoMarshal must version of proto.Marshal
|
||||
|
func MustProtoMarshal(msg proto.Message) []byte { |
||||
|
b, err := proto.Marshal(msg) |
||||
|
dtmimp.PanicIf(err != nil, err) |
||||
|
return b |
||||
|
} |
||||
|
|
||||
|
// DtmGrpcCall make a convenient call to dtm
|
||||
|
func DtmGrpcCall(s *dtmimp.TransBase, operation string) error { |
||||
|
reply := emptypb.Empty{} |
||||
|
return MustGetGrpcConn(s.Dtm, false).Invoke(context.Background(), "/dtmgimp.Dtm/"+operation, &DtmRequest{ |
||||
|
Gid: s.Gid, |
||||
|
TransType: s.TransType, |
||||
|
TransOptions: &DtmTransOptions{ |
||||
|
WaitResult: s.WaitResult, |
||||
|
TimeoutToFail: s.TimeoutToFail, |
||||
|
RetryInterval: s.RetryInterval, |
||||
|
}, |
||||
|
QueryPrepared: s.QueryPrepared, |
||||
|
CustomedData: s.CustomData, |
||||
|
BinPayloads: s.BinPayloads, |
||||
|
Steps: dtmimp.MustMarshalString(s.Steps), |
||||
|
}, &reply) |
||||
|
} |
||||
|
|
||||
|
const mdpre string = "dtm-" |
||||
|
|
||||
|
// TransInfo2Ctx add trans info to grpc context
|
||||
|
func TransInfo2Ctx(gid, transType, branchID, op, dtm string) context.Context { |
||||
|
md := metadata.Pairs( |
||||
|
mdpre+"gid", gid, |
||||
|
mdpre+"trans_type", transType, |
||||
|
mdpre+"branch_id", branchID, |
||||
|
mdpre+"op", op, |
||||
|
mdpre+"dtm", dtm, |
||||
|
) |
||||
|
return metadata.NewOutgoingContext(context.Background(), md) |
||||
|
} |
||||
|
|
||||
|
// LogDtmCtx logout dtm info in context metadata
|
||||
|
func LogDtmCtx(ctx context.Context) { |
||||
|
tb := TransBaseFromGrpc(ctx) |
||||
|
if tb.Gid != "" { |
||||
|
dtmimp.Logf("gid: %s trans_type: %s branch_id: %s op: %s dtm: %s", tb.Gid, tb.TransType, tb.BranchID, tb.Op, tb.Dtm) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func mdGet(md metadata.MD, key string) string { |
||||
|
v := md.Get(mdpre + key) |
||||
|
if len(v) == 0 { |
||||
|
return "" |
||||
|
} |
||||
|
return v[0] |
||||
|
} |
||||
|
|
||||
|
// TransBaseFromGrpc get trans base info from a context metadata
|
||||
|
func TransBaseFromGrpc(ctx context.Context) *dtmimp.TransBase { |
||||
|
md, _ := metadata.FromIncomingContext(ctx) |
||||
|
tb := dtmimp.NewTransBase(mdGet(md, "gid"), mdGet(md, "trans_type"), mdGet(md, "dtm"), mdGet(md, "branch_id")) |
||||
|
tb.Op = mdGet(md, "op") |
||||
|
return tb |
||||
|
} |
||||
@ -1,717 +0,0 @@ |
|||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||
// versions:
|
|
||||
// protoc-gen-go v1.26.0
|
|
||||
// protoc v3.17.3
|
|
||||
// source: dtmgrpc/dtmgrpc.proto
|
|
||||
|
|
||||
package dtmgrpc |
|
||||
|
|
||||
import ( |
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect" |
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl" |
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb" |
|
||||
reflect "reflect" |
|
||||
sync "sync" |
|
||||
) |
|
||||
|
|
||||
const ( |
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) |
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) |
|
||||
) |
|
||||
|
|
||||
// DtmRequest 发给dtm服务器的消息,响应为Emtpy,error == nil为成功,== Aborted 为失败 == 其他 可以重试
|
|
||||
type DtmRequest struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
|
||||
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` |
|
||||
// QueryPrepared 对于事务消息处于prepared状态过期,责护查询QueryPrepared
|
|
||||
QueryPrepared string `protobuf:"bytes,3,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"` |
|
||||
// WaitResult 设定这个值,Submit操作会等待dtm处理一次请求,可能在返回时,就可以把分布式事务完成
|
|
||||
WaitResult bool `protobuf:"varint,4,opt,name=WaitResult,proto3" json:"WaitResult,omitempty"` |
|
||||
// Data 包含saga、msg的子事务信息
|
|
||||
Data string `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) Reset() { |
|
||||
*x = DtmRequest{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[0] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*DtmRequest) ProtoMessage() {} |
|
||||
|
|
||||
func (x *DtmRequest) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[0] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead.
|
|
||||
func (*DtmRequest) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{0} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) GetGid() string { |
|
||||
if x != nil { |
|
||||
return x.Gid |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) GetTransType() string { |
|
||||
if x != nil { |
|
||||
return x.TransType |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) GetQueryPrepared() string { |
|
||||
if x != nil { |
|
||||
return x.QueryPrepared |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) GetWaitResult() bool { |
|
||||
if x != nil { |
|
||||
return x.WaitResult |
|
||||
} |
|
||||
return false |
|
||||
} |
|
||||
|
|
||||
func (x *DtmRequest) GetData() string { |
|
||||
if x != nil { |
|
||||
return x.Data |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
type DtmGidReply struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *DtmGidReply) Reset() { |
|
||||
*x = DtmGidReply{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmGidReply) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*DtmGidReply) ProtoMessage() {} |
|
||||
|
|
||||
func (x *DtmGidReply) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use DtmGidReply.ProtoReflect.Descriptor instead.
|
|
||||
func (*DtmGidReply) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{1} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmGidReply) GetGid() string { |
|
||||
if x != nil { |
|
||||
return x.Gid |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
// BranchInfo 事务分支信息
|
|
||||
type BranchInfo struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` |
|
||||
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` |
|
||||
BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` |
|
||||
BranchType string `protobuf:"bytes,4,opt,name=BranchType,proto3" json:"BranchType,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) Reset() { |
|
||||
*x = BranchInfo{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*BranchInfo) ProtoMessage() {} |
|
||||
|
|
||||
func (x *BranchInfo) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use BranchInfo.ProtoReflect.Descriptor instead.
|
|
||||
func (*BranchInfo) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{2} |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) GetGid() string { |
|
||||
if x != nil { |
|
||||
return x.Gid |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) GetTransType() string { |
|
||||
if x != nil { |
|
||||
return x.TransType |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) GetBranchID() string { |
|
||||
if x != nil { |
|
||||
return x.BranchID |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *BranchInfo) GetBranchType() string { |
|
||||
if x != nil { |
|
||||
return x.BranchType |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
type DtmTccBranchRequest struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Info *BranchInfo `protobuf:"bytes,1,opt,name=Info,proto3" json:"Info,omitempty"` |
|
||||
BusiData string `protobuf:"bytes,2,opt,name=BusiData,proto3" json:"BusiData,omitempty"` |
|
||||
Try string `protobuf:"bytes,3,opt,name=Try,proto3" json:"Try,omitempty"` |
|
||||
Confirm string `protobuf:"bytes,4,opt,name=Confirm,proto3" json:"Confirm,omitempty"` |
|
||||
Cancel string `protobuf:"bytes,5,opt,name=Cancel,proto3" json:"Cancel,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) Reset() { |
|
||||
*x = DtmTccBranchRequest{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*DtmTccBranchRequest) ProtoMessage() {} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use DtmTccBranchRequest.ProtoReflect.Descriptor instead.
|
|
||||
func (*DtmTccBranchRequest) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{3} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) GetInfo() *BranchInfo { |
|
||||
if x != nil { |
|
||||
return x.Info |
|
||||
} |
|
||||
return nil |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) GetBusiData() string { |
|
||||
if x != nil { |
|
||||
return x.BusiData |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) GetTry() string { |
|
||||
if x != nil { |
|
||||
return x.Try |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) GetConfirm() string { |
|
||||
if x != nil { |
|
||||
return x.Confirm |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmTccBranchRequest) GetCancel() string { |
|
||||
if x != nil { |
|
||||
return x.Cancel |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
type DtmXaBranchRequest struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Info *BranchInfo `protobuf:"bytes,1,opt,name=Info,proto3" json:"Info,omitempty"` |
|
||||
BusiData string `protobuf:"bytes,2,opt,name=BusiData,proto3" json:"BusiData,omitempty"` |
|
||||
// dtm通知业务提交和回滚的地址
|
|
||||
Notify string `protobuf:"bytes,3,opt,name=Notify,proto3" json:"Notify,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) Reset() { |
|
||||
*x = DtmXaBranchRequest{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*DtmXaBranchRequest) ProtoMessage() {} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use DtmXaBranchRequest.ProtoReflect.Descriptor instead.
|
|
||||
func (*DtmXaBranchRequest) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{4} |
|
||||
} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) GetInfo() *BranchInfo { |
|
||||
if x != nil { |
|
||||
return x.Info |
|
||||
} |
|
||||
return nil |
|
||||
} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) GetBusiData() string { |
|
||||
if x != nil { |
|
||||
return x.BusiData |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *DtmXaBranchRequest) GetNotify() string { |
|
||||
if x != nil { |
|
||||
return x.Notify |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
// BusiRequest 请求业务的数据,需要携带事务信息,便于业务进行幂等处理
|
|
||||
type BusiRequest struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
Info *BranchInfo `protobuf:"bytes,1,opt,name=Info,proto3" json:"Info,omitempty"` |
|
||||
Dtm string `protobuf:"bytes,2,opt,name=Dtm,proto3" json:"Dtm,omitempty"` |
|
||||
BusiData []byte `protobuf:"bytes,3,opt,name=BusiData,proto3" json:"BusiData,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *BusiRequest) Reset() { |
|
||||
*x = BusiRequest{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *BusiRequest) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*BusiRequest) ProtoMessage() {} |
|
||||
|
|
||||
func (x *BusiRequest) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use BusiRequest.ProtoReflect.Descriptor instead.
|
|
||||
func (*BusiRequest) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{5} |
|
||||
} |
|
||||
|
|
||||
func (x *BusiRequest) GetInfo() *BranchInfo { |
|
||||
if x != nil { |
|
||||
return x.Info |
|
||||
} |
|
||||
return nil |
|
||||
} |
|
||||
|
|
||||
func (x *BusiRequest) GetDtm() string { |
|
||||
if x != nil { |
|
||||
return x.Dtm |
|
||||
} |
|
||||
return "" |
|
||||
} |
|
||||
|
|
||||
func (x *BusiRequest) GetBusiData() []byte { |
|
||||
if x != nil { |
|
||||
return x.BusiData |
|
||||
} |
|
||||
return nil |
|
||||
} |
|
||||
|
|
||||
// BusiReply 业务响应数据
|
|
||||
type BusiReply struct { |
|
||||
state protoimpl.MessageState |
|
||||
sizeCache protoimpl.SizeCache |
|
||||
unknownFields protoimpl.UnknownFields |
|
||||
|
|
||||
BusiData []byte `protobuf:"bytes,1,opt,name=BusiData,proto3" json:"BusiData,omitempty"` |
|
||||
} |
|
||||
|
|
||||
func (x *BusiReply) Reset() { |
|
||||
*x = BusiReply{} |
|
||||
if protoimpl.UnsafeEnabled { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[6] |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (x *BusiReply) String() string { |
|
||||
return protoimpl.X.MessageStringOf(x) |
|
||||
} |
|
||||
|
|
||||
func (*BusiReply) ProtoMessage() {} |
|
||||
|
|
||||
func (x *BusiReply) ProtoReflect() protoreflect.Message { |
|
||||
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[6] |
|
||||
if protoimpl.UnsafeEnabled && x != nil { |
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
|
||||
if ms.LoadMessageInfo() == nil { |
|
||||
ms.StoreMessageInfo(mi) |
|
||||
} |
|
||||
return ms |
|
||||
} |
|
||||
return mi.MessageOf(x) |
|
||||
} |
|
||||
|
|
||||
// Deprecated: Use BusiReply.ProtoReflect.Descriptor instead.
|
|
||||
func (*BusiReply) Descriptor() ([]byte, []int) { |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{6} |
|
||||
} |
|
||||
|
|
||||
func (x *BusiReply) GetBusiData() []byte { |
|
||||
if x != nil { |
|
||||
return x.BusiData |
|
||||
} |
|
||||
return nil |
|
||||
} |
|
||||
|
|
||||
var File_dtmgrpc_dtmgrpc_proto protoreflect.FileDescriptor |
|
||||
|
|
||||
var file_dtmgrpc_dtmgrpc_proto_rawDesc = []byte{ |
|
||||
0x0a, 0x15, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, |
|
||||
0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, |
|
||||
0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, |
|
||||
0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x96, 0x01, |
|
||||
0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, |
|
||||
0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, |
|
||||
0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, |
|
||||
0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, |
|
||||
0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, |
|
||||
0x01, 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, |
|
||||
0x65, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, |
|
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, |
|
||||
0x6c, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, |
|
||||
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x1f, 0x0a, 0x0b, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, |
|
||||
0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, |
|
||||
0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x22, 0x78, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, |
|
||||
0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, |
|
||||
0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, |
|
||||
0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, |
|
||||
0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, |
|
||||
0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, |
|
||||
0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x18, |
|
||||
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, |
|
||||
0x65, 0x22, 0x9e, 0x01, 0x0a, 0x13, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, |
|
||||
0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, |
|
||||
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, |
|
||||
0x63, 0x2e, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, |
|
||||
0x66, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, |
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, |
|
||||
0x0a, 0x03, 0x54, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x54, 0x72, 0x79, |
|
||||
0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, |
|
||||
0x09, 0x52, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x43, 0x61, |
|
||||
0x6e, 0x63, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x43, 0x61, 0x6e, 0x63, |
|
||||
0x65, 0x6c, 0x22, 0x71, 0x0a, 0x12, 0x44, 0x74, 0x6d, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, |
|
||||
0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, |
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, |
|
||||
0x2e, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, |
|
||||
0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, |
|
||||
0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, |
|
||||
0x06, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4e, |
|
||||
0x6f, 0x74, 0x69, 0x66, 0x79, 0x22, 0x64, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, |
|
||||
0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, |
|
||||
0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x72, 0x61, |
|
||||
0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, |
|
||||
0x03, 0x44, 0x74, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x12, |
|
||||
0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, |
|
||||
0x0c, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x22, 0x27, 0x0a, 0x09, 0x42, |
|
||||
0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, |
|
||||
0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, |
|
||||
0x44, 0x61, 0x74, 0x61, 0x32, 0x82, 0x03, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x38, 0x0a, 0x06, |
|
||||
0x4e, 0x65, 0x77, 0x47, 0x69, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, |
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, |
|
||||
0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, |
|
||||
0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, |
|
||||
0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, |
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, |
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, |
|
||||
0x38, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, |
|
||||
0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, |
|
||||
0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, |
|
||||
0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x05, 0x41, 0x62, 0x6f, |
|
||||
0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, |
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, |
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, |
|
||||
0x00, 0x12, 0x4b, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, 0x63, 0x63, |
|
||||
0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x1c, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, |
|
||||
0x2e, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, |
|
||||
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, |
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x49, |
|
||||
0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, |
|
||||
0x63, 0x68, 0x12, 0x1b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, |
|
||||
0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, |
|
||||
0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, |
|
||||
0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x1d, 0x5a, 0x1b, 0x67, 0x69, 0x74, |
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, |
|
||||
0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, |
|
||||
} |
|
||||
|
|
||||
var ( |
|
||||
file_dtmgrpc_dtmgrpc_proto_rawDescOnce sync.Once |
|
||||
file_dtmgrpc_dtmgrpc_proto_rawDescData = file_dtmgrpc_dtmgrpc_proto_rawDesc |
|
||||
) |
|
||||
|
|
||||
func file_dtmgrpc_dtmgrpc_proto_rawDescGZIP() []byte { |
|
||||
file_dtmgrpc_dtmgrpc_proto_rawDescOnce.Do(func() { |
|
||||
file_dtmgrpc_dtmgrpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmgrpc_dtmgrpc_proto_rawDescData) |
|
||||
}) |
|
||||
return file_dtmgrpc_dtmgrpc_proto_rawDescData |
|
||||
} |
|
||||
|
|
||||
var file_dtmgrpc_dtmgrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 7) |
|
||||
var file_dtmgrpc_dtmgrpc_proto_goTypes = []interface{}{ |
|
||||
(*DtmRequest)(nil), // 0: dtmgrpc.DtmRequest
|
|
||||
(*DtmGidReply)(nil), // 1: dtmgrpc.DtmGidReply
|
|
||||
(*BranchInfo)(nil), // 2: dtmgrpc.BranchInfo
|
|
||||
(*DtmTccBranchRequest)(nil), // 3: dtmgrpc.DtmTccBranchRequest
|
|
||||
(*DtmXaBranchRequest)(nil), // 4: dtmgrpc.DtmXaBranchRequest
|
|
||||
(*BusiRequest)(nil), // 5: dtmgrpc.BusiRequest
|
|
||||
(*BusiReply)(nil), // 6: dtmgrpc.BusiReply
|
|
||||
(*emptypb.Empty)(nil), // 7: google.protobuf.Empty
|
|
||||
} |
|
||||
var file_dtmgrpc_dtmgrpc_proto_depIdxs = []int32{ |
|
||||
2, // 0: dtmgrpc.DtmTccBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
|
|
||||
2, // 1: dtmgrpc.DtmXaBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
|
|
||||
2, // 2: dtmgrpc.BusiRequest.Info:type_name -> dtmgrpc.BranchInfo
|
|
||||
7, // 3: dtmgrpc.Dtm.NewGid:input_type -> google.protobuf.Empty
|
|
||||
0, // 4: dtmgrpc.Dtm.Submit:input_type -> dtmgrpc.DtmRequest
|
|
||||
0, // 5: dtmgrpc.Dtm.Prepare:input_type -> dtmgrpc.DtmRequest
|
|
||||
0, // 6: dtmgrpc.Dtm.Abort:input_type -> dtmgrpc.DtmRequest
|
|
||||
3, // 7: dtmgrpc.Dtm.RegisterTccBranch:input_type -> dtmgrpc.DtmTccBranchRequest
|
|
||||
4, // 8: dtmgrpc.Dtm.RegisterXaBranch:input_type -> dtmgrpc.DtmXaBranchRequest
|
|
||||
1, // 9: dtmgrpc.Dtm.NewGid:output_type -> dtmgrpc.DtmGidReply
|
|
||||
7, // 10: dtmgrpc.Dtm.Submit:output_type -> google.protobuf.Empty
|
|
||||
7, // 11: dtmgrpc.Dtm.Prepare:output_type -> google.protobuf.Empty
|
|
||||
7, // 12: dtmgrpc.Dtm.Abort:output_type -> google.protobuf.Empty
|
|
||||
7, // 13: dtmgrpc.Dtm.RegisterTccBranch:output_type -> google.protobuf.Empty
|
|
||||
7, // 14: dtmgrpc.Dtm.RegisterXaBranch:output_type -> google.protobuf.Empty
|
|
||||
9, // [9:15] is the sub-list for method output_type
|
|
||||
3, // [3:9] is the sub-list for method input_type
|
|
||||
3, // [3:3] is the sub-list for extension type_name
|
|
||||
3, // [3:3] is the sub-list for extension extendee
|
|
||||
0, // [0:3] is the sub-list for field type_name
|
|
||||
} |
|
||||
|
|
||||
func init() { file_dtmgrpc_dtmgrpc_proto_init() } |
|
||||
func file_dtmgrpc_dtmgrpc_proto_init() { |
|
||||
if File_dtmgrpc_dtmgrpc_proto != nil { |
|
||||
return |
|
||||
} |
|
||||
if !protoimpl.UnsafeEnabled { |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*DtmRequest); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*DtmGidReply); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*BranchInfo); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*DtmTccBranchRequest); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*DtmXaBranchRequest); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*BusiRequest); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
file_dtmgrpc_dtmgrpc_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { |
|
||||
switch v := v.(*BusiReply); i { |
|
||||
case 0: |
|
||||
return &v.state |
|
||||
case 1: |
|
||||
return &v.sizeCache |
|
||||
case 2: |
|
||||
return &v.unknownFields |
|
||||
default: |
|
||||
return nil |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
type x struct{} |
|
||||
out := protoimpl.TypeBuilder{ |
|
||||
File: protoimpl.DescBuilder{ |
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
|
||||
RawDescriptor: file_dtmgrpc_dtmgrpc_proto_rawDesc, |
|
||||
NumEnums: 0, |
|
||||
NumMessages: 7, |
|
||||
NumExtensions: 0, |
|
||||
NumServices: 1, |
|
||||
}, |
|
||||
GoTypes: file_dtmgrpc_dtmgrpc_proto_goTypes, |
|
||||
DependencyIndexes: file_dtmgrpc_dtmgrpc_proto_depIdxs, |
|
||||
MessageInfos: file_dtmgrpc_dtmgrpc_proto_msgTypes, |
|
||||
}.Build() |
|
||||
File_dtmgrpc_dtmgrpc_proto = out.File |
|
||||
file_dtmgrpc_dtmgrpc_proto_rawDesc = nil |
|
||||
file_dtmgrpc_dtmgrpc_proto_goTypes = nil |
|
||||
file_dtmgrpc_dtmgrpc_proto_depIdxs = nil |
|
||||
} |
|
||||
@ -1,66 +0,0 @@ |
|||||
syntax = "proto3"; |
|
||||
|
|
||||
option go_package = "github.com/yedf/dtm/dtmgrpc"; |
|
||||
import "google/protobuf/empty.proto"; |
|
||||
|
|
||||
package dtmgrpc; |
|
||||
|
|
||||
// The dtm service definition. |
|
||||
service Dtm { |
|
||||
rpc NewGid(google.protobuf.Empty) returns (DtmGidReply) {} |
|
||||
rpc Submit(DtmRequest) returns (google.protobuf.Empty) {} |
|
||||
rpc Prepare(DtmRequest) returns (google.protobuf.Empty) {} |
|
||||
rpc Abort(DtmRequest) returns (google.protobuf.Empty) {} |
|
||||
rpc RegisterTccBranch(DtmTccBranchRequest) returns (google.protobuf.Empty) {} |
|
||||
rpc RegisterXaBranch(DtmXaBranchRequest) returns (google.protobuf.Empty) {} |
|
||||
} |
|
||||
|
|
||||
// DtmRequest 发给dtm服务器的消息,响应为Empty,error == nil为成功,== Aborted 为失败 == 其他 可以重试 |
|
||||
message DtmRequest { |
|
||||
string Gid = 1; |
|
||||
string TransType = 2; |
|
||||
// QueryPrepared 对于事务消息处于prepared状态过期,责护查询QueryPrepared |
|
||||
string QueryPrepared = 3; |
|
||||
// WaitResult 设定这个值,Submit操作会等待dtm处理一次请求,可能在返回时,就可以把分布式事务完成 |
|
||||
bool WaitResult = 4; |
|
||||
// Data 包含saga、msg的子事务信息 |
|
||||
string Data = 5; |
|
||||
} |
|
||||
|
|
||||
message DtmGidReply { |
|
||||
string Gid = 1; |
|
||||
} |
|
||||
// BranchInfo 事务分支信息 |
|
||||
message BranchInfo { |
|
||||
string Gid = 1; |
|
||||
string TransType = 2; |
|
||||
string BranchID = 3; |
|
||||
string BranchType = 4; |
|
||||
} |
|
||||
|
|
||||
message DtmTccBranchRequest { |
|
||||
BranchInfo Info = 1; |
|
||||
string BusiData = 2; |
|
||||
string Try = 3; |
|
||||
string Confirm = 4; |
|
||||
string Cancel = 5; |
|
||||
} |
|
||||
|
|
||||
message DtmXaBranchRequest { |
|
||||
BranchInfo Info = 1; |
|
||||
string BusiData = 2; |
|
||||
// dtm通知业务提交和回滚的地址 |
|
||||
string Notify = 3; |
|
||||
} |
|
||||
|
|
||||
// BusiRequest 请求业务的数据,需要携带事务信息,便于业务进行幂等处理 |
|
||||
message BusiRequest { |
|
||||
BranchInfo Info = 1; |
|
||||
string Dtm = 2; |
|
||||
bytes BusiData = 3; |
|
||||
} |
|
||||
|
|
||||
// BusiReply 业务响应数据 |
|
||||
message BusiReply { |
|
||||
bytes BusiData = 1; |
|
||||
} |
|
||||
@ -1,50 +0,0 @@ |
|||||
package dtmgrpc |
|
||||
|
|
||||
import ( |
|
||||
"context" |
|
||||
|
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
) |
|
||||
|
|
||||
// MsgGrpc reliable msg type
|
|
||||
type MsgGrpc struct { |
|
||||
dtmcli.TransBase |
|
||||
Steps []dtmcli.MsgStep `json:"steps"` |
|
||||
QueryPrepared string `json:"query_prepared"` |
|
||||
} |
|
||||
|
|
||||
// NewMsgGrpc create new msg
|
|
||||
func NewMsgGrpc(server string, gid string) *MsgGrpc { |
|
||||
return &MsgGrpc{TransBase: *dtmcli.NewTransBase(gid, "msg", server, "")} |
|
||||
} |
|
||||
|
|
||||
// Add add a new step
|
|
||||
func (s *MsgGrpc) Add(action string, data []byte) *MsgGrpc { |
|
||||
s.Steps = append(s.Steps, dtmcli.MsgStep{ |
|
||||
Action: action, |
|
||||
Data: string(data), |
|
||||
}) |
|
||||
return s |
|
||||
} |
|
||||
|
|
||||
// Submit submit the msg
|
|
||||
func (s *MsgGrpc) Submit() error { |
|
||||
_, err := MustGetDtmClient(s.Dtm).Submit(context.Background(), &DtmRequest{ |
|
||||
Gid: s.Gid, |
|
||||
TransType: s.TransType, |
|
||||
Data: dtmcli.MustMarshalString(&s.Steps), |
|
||||
}) |
|
||||
return err |
|
||||
} |
|
||||
|
|
||||
// Prepare prepare the msg
|
|
||||
func (s *MsgGrpc) Prepare(queryPrepared string) error { |
|
||||
s.QueryPrepared = dtmcli.OrString(queryPrepared, s.QueryPrepared) |
|
||||
_, err := MustGetDtmClient(s.Dtm).Prepare(context.Background(), &DtmRequest{ |
|
||||
Gid: s.Gid, |
|
||||
TransType: s.TransType, |
|
||||
QueryPrepared: s.QueryPrepared, |
|
||||
Data: dtmcli.MustMarshalString(&s.Steps), |
|
||||
}) |
|
||||
return err |
|
||||
} |
|
||||
@ -0,0 +1,36 @@ |
|||||
|
package dtmgrpc |
||||
|
|
||||
|
import ( |
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/dtmgrpc/dtmgimp" |
||||
|
"google.golang.org/protobuf/proto" |
||||
|
) |
||||
|
|
||||
|
// MsgGrpc reliable msg type
|
||||
|
type MsgGrpc struct { |
||||
|
dtmcli.Msg |
||||
|
} |
||||
|
|
||||
|
// NewMsgGrpc create new msg
|
||||
|
func NewMsgGrpc(server string, gid string) *MsgGrpc { |
||||
|
return &MsgGrpc{Msg: *dtmcli.NewMsg(server, gid)} |
||||
|
} |
||||
|
|
||||
|
// Add add a new step
|
||||
|
func (s *MsgGrpc) Add(action string, msg proto.Message) *MsgGrpc { |
||||
|
s.Steps = append(s.Steps, map[string]string{"action": action}) |
||||
|
s.BinPayloads = append(s.BinPayloads, dtmgimp.MustProtoMarshal(msg)) |
||||
|
return s |
||||
|
} |
||||
|
|
||||
|
// Prepare prepare the msg, msg will later be submitted
|
||||
|
func (s *MsgGrpc) Prepare(queryPrepared string) error { |
||||
|
s.QueryPrepared = dtmimp.OrString(queryPrepared, s.QueryPrepared) |
||||
|
return dtmgimp.DtmGrpcCall(&s.TransBase, "Prepare") |
||||
|
} |
||||
|
|
||||
|
// Submit submit the msg
|
||||
|
func (s *MsgGrpc) Submit() error { |
||||
|
return dtmgimp.DtmGrpcCall(&s.TransBase, "Submit") |
||||
|
} |
||||
@ -1,38 +1,41 @@ |
|||||
package dtmgrpc |
package dtmgrpc |
||||
|
|
||||
import ( |
import ( |
||||
context "context" |
|
||||
|
|
||||
"github.com/yedf/dtm/dtmcli" |
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmgrpc/dtmgimp" |
||||
|
"google.golang.org/protobuf/proto" |
||||
) |
) |
||||
|
|
||||
// SagaGrpc struct of saga
|
// SagaGrpc struct of saga
|
||||
type SagaGrpc struct { |
type SagaGrpc struct { |
||||
dtmcli.TransBase |
dtmcli.Saga |
||||
Steps []dtmcli.SagaStep `json:"steps"` |
|
||||
} |
} |
||||
|
|
||||
// NewSaga create a saga
|
// NewSagaGrpc create a saga
|
||||
func NewSaga(server string, gid string) *SagaGrpc { |
func NewSagaGrpc(server string, gid string) *SagaGrpc { |
||||
return &SagaGrpc{TransBase: *dtmcli.NewTransBase(gid, "saga", server, "")} |
return &SagaGrpc{Saga: *dtmcli.NewSaga(server, gid)} |
||||
} |
} |
||||
|
|
||||
// Add add a saga step
|
// Add add a saga step
|
||||
func (s *SagaGrpc) Add(action string, compensate string, busiData []byte) *SagaGrpc { |
func (s *SagaGrpc) Add(action string, compensate string, payload proto.Message) *SagaGrpc { |
||||
s.Steps = append(s.Steps, dtmcli.SagaStep{ |
s.Steps = append(s.Steps, map[string]string{"action": action, "compensate": compensate}) |
||||
Action: action, |
s.BinPayloads = append(s.BinPayloads, dtmgimp.MustProtoMarshal(payload)) |
||||
Compensate: compensate, |
return s |
||||
Data: string(busiData), |
} |
||||
}) |
|
||||
|
// AddBranchOrder specify that branch should be after preBranches. branch should is larger than all the element in preBranches
|
||||
|
func (s *SagaGrpc) AddBranchOrder(branch int, preBranches []int) *SagaGrpc { |
||||
|
s.Saga.AddBranchOrder(branch, preBranches) |
||||
|
return s |
||||
|
} |
||||
|
|
||||
|
// EnableConcurrent enable the concurrent exec of sub trans
|
||||
|
func (s *SagaGrpc) EnableConcurrent() *SagaGrpc { |
||||
|
s.Saga.EnableConcurrent() |
||||
return s |
return s |
||||
} |
} |
||||
|
|
||||
// Submit submit the saga trans
|
// Submit submit the saga trans
|
||||
func (s *SagaGrpc) Submit() error { |
func (s *SagaGrpc) Submit() error { |
||||
_, err := MustGetDtmClient(s.Dtm).Submit(context.Background(), &DtmRequest{ |
return dtmgimp.DtmGrpcCall(&s.Saga.TransBase, "Submit") |
||||
Gid: s.Gid, |
|
||||
TransType: s.TransType, |
|
||||
Data: dtmcli.MustMarshalString(&s.Steps), |
|
||||
}) |
|
||||
return err |
|
||||
} |
} |
||||
|
|||||
@ -1,15 +1,21 @@ |
|||||
package dtmgrpc |
package dtmgrpc |
||||
|
|
||||
import ( |
import ( |
||||
|
"context" |
||||
"testing" |
"testing" |
||||
|
|
||||
"github.com/stretchr/testify/assert" |
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
) |
) |
||||
|
|
||||
func TestType(t *testing.T) { |
func TestType(t *testing.T) { |
||||
_, err := BarrierFromGrpc(&BusiRequest{Info: &BranchInfo{}}) |
_, err := BarrierFromGrpc(context.Background()) |
||||
assert.Error(t, err) |
assert.Error(t, err) |
||||
|
|
||||
_, err = TccFromRequest(&BusiRequest{Info: &BranchInfo{}}) |
_, err = TccFromGrpc(context.Background()) |
||||
assert.Error(t, err) |
assert.Error(t, err) |
||||
|
|
||||
|
old := GetCurrentDBType() |
||||
|
SetCurrentDBType(dtmcli.DBTypeMysql) |
||||
|
SetCurrentDBType(old) |
||||
} |
} |
||||
|
|||||
@ -1,30 +1,37 @@ |
|||||
syntax = "proto3"; |
syntax = "proto3"; |
||||
|
|
||||
package examples; |
package examples; |
||||
|
import "google/protobuf/empty.proto"; |
||||
|
|
||||
option go_package = "github.com/yedf/dtm/examples"; |
option go_package = "github.com/yedf/dtm/examples"; |
||||
import "dtmgrpc/dtmgrpc.proto"; |
|
||||
|
// DtmRequest request sent to dtm server |
||||
|
message BusiReq { |
||||
|
int64 Amount = 1; |
||||
|
string TransOutResult = 2; |
||||
|
string TransInResult = 3; |
||||
|
} |
||||
|
|
||||
// The dtm service definition. |
// The dtm service definition. |
||||
service Busi { |
service Busi { |
||||
rpc CanSubmit(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc CanSubmit(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransIn(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransIn(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOut(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOut(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransInRevert(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInRevert(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutRevert(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutRevert(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransInConfirm(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInConfirm(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutConfirm(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutConfirm(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc XaNotify(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc XaNotify(google.protobuf.Empty) returns (google.protobuf.Empty) {} |
||||
|
|
||||
rpc TransInXa(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInXa(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutXa(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutXa(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransInTcc(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInTcc(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutTcc(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutTcc(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransInTccNested(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInTccNested(BusiReq) returns (google.protobuf.Empty) {} |
||||
|
|
||||
rpc TransInBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInBSaga(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutBSaga(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransInRevertBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransInRevertBSaga(BusiReq) returns (google.protobuf.Empty) {} |
||||
rpc TransOutRevertBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
rpc TransOutRevertBSaga(BusiReq) returns (google.protobuf.Empty) {} |
||||
} |
} |
||||
|
|
||||
|
|||||
@ -1,19 +1,19 @@ |
|||||
package examples |
package examples |
||||
|
|
||||
import ( |
import ( |
||||
"github.com/yedf/dtm/dtmcli" |
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
||||
) |
) |
||||
|
|
||||
func init() { |
func init() { |
||||
addSample("grpc_msg", func() string { |
addSample("grpc_msg", func() string { |
||||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
req := &BusiReq{Amount: 30} |
||||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
||||
msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, gid). |
msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, gid). |
||||
Add(BusiGrpc+"/examples.Busi/TransOut", req). |
Add(BusiGrpc+"/examples.Busi/TransOut", req). |
||||
Add(BusiGrpc+"/examples.Busi/TransIn", req) |
Add(BusiGrpc+"/examples.Busi/TransIn", req) |
||||
err := msg.Submit() |
err := msg.Submit() |
||||
dtmcli.FatalIfError(err) |
dtmimp.FatalIfError(err) |
||||
return msg.Gid |
return msg.Gid |
||||
}) |
}) |
||||
} |
} |
||||
|
|||||
@ -1,30 +1,30 @@ |
|||||
package examples |
package examples |
||||
|
|
||||
import ( |
import ( |
||||
"github.com/yedf/dtm/dtmcli" |
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
||||
) |
) |
||||
|
|
||||
func init() { |
func init() { |
||||
addSample("grpc_saga", func() string { |
addSample("grpc_saga", func() string { |
||||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
req := &BusiReq{Amount: 30} |
||||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
||||
saga := dtmgrpc.NewSaga(DtmGrpcServer, gid). |
saga := dtmgrpc.NewSagaGrpc(DtmGrpcServer, gid). |
||||
Add(BusiGrpc+"/examples.Busi/TransOut", BusiGrpc+"/examples.Busi/TransOutRevert", req). |
Add(BusiGrpc+"/examples.Busi/TransOut", BusiGrpc+"/examples.Busi/TransOutRevert", req). |
||||
Add(BusiGrpc+"/examples.Busi/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
Add(BusiGrpc+"/examples.Busi/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
||||
err := saga.Submit() |
err := saga.Submit() |
||||
dtmcli.FatalIfError(err) |
dtmimp.FatalIfError(err) |
||||
return saga.Gid |
return saga.Gid |
||||
}) |
}) |
||||
addSample("grpc_saga_wait", func() string { |
addSample("grpc_saga_wait", func() string { |
||||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
req := &BusiReq{Amount: 30} |
||||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
||||
saga := dtmgrpc.NewSaga(DtmGrpcServer, gid). |
saga := dtmgrpc.NewSagaGrpc(DtmGrpcServer, gid). |
||||
Add(BusiGrpc+"/examples.Busi/TransOut", BusiGrpc+"/examples.Busi/TransOutRevert", req). |
Add(BusiGrpc+"/examples.Busi/TransOut", BusiGrpc+"/examples.Busi/TransOutRevert", req). |
||||
Add(BusiGrpc+"/examples.Busi/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
Add(BusiGrpc+"/examples.Busi/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
||||
saga.WaitResult = true |
saga.WaitResult = true |
||||
err := saga.Submit() |
err := saga.Submit() |
||||
dtmcli.FatalIfError(err) |
dtmimp.FatalIfError(err) |
||||
return saga.Gid |
return saga.Gid |
||||
}) |
}) |
||||
} |
} |
||||
|
|||||
@ -1,24 +1,26 @@ |
|||||
package examples |
package examples |
||||
|
|
||||
import ( |
import ( |
||||
"github.com/yedf/dtm/dtmcli" |
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb" |
||||
) |
) |
||||
|
|
||||
func init() { |
func init() { |
||||
addSample("grpc_tcc", func() string { |
addSample("grpc_tcc", func() string { |
||||
dtmcli.Logf("tcc simple transaction begin") |
dtmimp.Logf("tcc simple transaction begin") |
||||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
||||
err := dtmgrpc.TccGlobalTransaction(DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
err := dtmgrpc.TccGlobalTransaction(DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
||||
data := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
data := &BusiReq{Amount: 30} |
||||
_, err := tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransOutTcc", BusiGrpc+"/examples.Busi/TransOutConfirm", BusiGrpc+"/examples.Busi/TransOutRevert") |
r := &emptypb.Empty{} |
||||
|
err := tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransOutTcc", BusiGrpc+"/examples.Busi/TransOutConfirm", BusiGrpc+"/examples.Busi/TransOutRevert", r) |
||||
if err != nil { |
if err != nil { |
||||
return err |
return err |
||||
} |
} |
||||
_, err = tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransInTcc", BusiGrpc+"/examples.Busi/TransInConfirm", BusiGrpc+"/examples.Busi/TransInRevert") |
err = tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransInTcc", BusiGrpc+"/examples.Busi/TransInConfirm", BusiGrpc+"/examples.Busi/TransInRevert", r) |
||||
return err |
return err |
||||
}) |
}) |
||||
dtmcli.FatalIfError(err) |
dtmimp.FatalIfError(err) |
||||
return gid |
return gid |
||||
}) |
}) |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,44 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
const gidTestAPI = "TestAPI" |
||||
|
|
||||
|
func TestAPIQuery(t *testing.T) { |
||||
|
err := genMsg(gidTestAPI).Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(gidTestAPI) |
||||
|
resp, err := dtmimp.RestyClient.R().SetQueryParam("gid", gidTestAPI).Get(examples.DtmServer + "/query") |
||||
|
e2p(err) |
||||
|
m := map[string]interface{}{} |
||||
|
assert.Equal(t, resp.StatusCode(), 200) |
||||
|
dtmimp.MustUnmarshalString(resp.String(), &m) |
||||
|
assert.NotEqual(t, nil, m["transaction"]) |
||||
|
assert.Equal(t, 2, len(m["branches"].([]interface{}))) |
||||
|
|
||||
|
resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "").Get(examples.DtmServer + "/query") |
||||
|
e2p(err) |
||||
|
assert.Equal(t, resp.StatusCode(), 500) |
||||
|
|
||||
|
resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "1").Get(examples.DtmServer + "/query") |
||||
|
e2p(err) |
||||
|
assert.Equal(t, resp.StatusCode(), 200) |
||||
|
dtmimp.MustUnmarshalString(resp.String(), &m) |
||||
|
assert.Equal(t, nil, m["transaction"]) |
||||
|
assert.Equal(t, 0, len(m["branches"].([]interface{}))) |
||||
|
} |
||||
|
|
||||
|
func TestAPIAll(t *testing.T) { |
||||
|
_, err := dtmimp.RestyClient.R().Get(examples.DtmServer + "/all") |
||||
|
assert.Nil(t, err) |
||||
|
_, err = dtmimp.RestyClient.R().SetQueryParam("last_id", "10").Get(examples.DtmServer + "/all") |
||||
|
assert.Nil(t, err) |
||||
|
resp, err := dtmimp.RestyClient.R().SetQueryParam("last_id", "abc").Get(examples.DtmServer + "/all") |
||||
|
assert.Equal(t, resp.StatusCode(), 500) |
||||
|
} |
||||
@ -1,38 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestBarrierSaga(t *testing.T) { |
|
||||
|
|
||||
sagaBarrierNormal(t) |
|
||||
sagaBarrierRollback(t) |
|
||||
} |
|
||||
|
|
||||
func sagaBarrierNormal(t *testing.T) { |
|
||||
req := &examples.TransReq{Amount: 30} |
|
||||
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierNormal"). |
|
||||
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req). |
|
||||
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req) |
|
||||
dtmcli.Logf("busi trans submit") |
|
||||
err := saga.Submit() |
|
||||
e2p(err) |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
||||
} |
|
||||
|
|
||||
func sagaBarrierRollback(t *testing.T) { |
|
||||
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierRollback"). |
|
||||
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", &examples.TransReq{Amount: 30}). |
|
||||
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", &examples.TransReq{Amount: 30, TransInResult: dtmcli.ResultFailure}) |
|
||||
dtmcli.Logf("busi trans submit") |
|
||||
err := saga.Submit() |
|
||||
e2p(err) |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(saga.Gid)) |
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/dtmgrpc" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestGrpcBarrierSaga(t *testing.T) { |
|
||||
|
|
||||
grpcSagaBarrierNormal(t) |
|
||||
grpcSagaBarrierRollback(t) |
|
||||
} |
|
||||
|
|
||||
func grpcSagaBarrierNormal(t *testing.T) { |
|
||||
req := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) |
|
||||
saga := dtmgrpc.NewSaga(examples.DtmGrpcServer, "grpcSagaBarrierNormal"). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransOutBSaga", examples.BusiGrpc+"/examples.Busi/TransOutRevertBSaga", req). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransInBSaga", examples.BusiGrpc+"/examples.Busi/TransInRevertBSaga", req) |
|
||||
err := saga.Submit() |
|
||||
e2p(err) |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
||||
} |
|
||||
|
|
||||
func grpcSagaBarrierRollback(t *testing.T) { |
|
||||
req := dtmcli.MustMarshal(&examples.TransReq{Amount: 30, TransInResult: dtmcli.ResultFailure}) |
|
||||
saga := dtmgrpc.NewSaga(examples.DtmGrpcServer, "grpcSagaBarrierRollback"). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransOutBSaga", examples.BusiGrpc+"/examples.Busi/TransOutRevertBSaga", req). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransInBSaga", examples.BusiGrpc+"/examples.Busi/TransInRevertBSaga", req) |
|
||||
err := saga.Submit() |
|
||||
e2p(err) |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(saga.Gid)) |
|
||||
assert.Equal(t, []string{dtmcli.StatusSucceed, dtmcli.StatusSucceed, dtmcli.StatusSucceed, dtmcli.StatusFailed}, getBranchesStatus(saga.Gid)) |
|
||||
} |
|
||||
@ -1,46 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"fmt" |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/dtmgrpc" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestGrpcMsg(t *testing.T) { |
|
||||
grpcMsgNormal(t) |
|
||||
grpcMsgOngoing(t) |
|
||||
} |
|
||||
|
|
||||
func grpcMsgNormal(t *testing.T) { |
|
||||
msg := genGrpcMsg("grpc-msg-normal") |
|
||||
err := msg.Submit() |
|
||||
assert.Nil(t, err) |
|
||||
waitTransProcessed(msg.Gid) |
|
||||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(msg.Gid)) |
|
||||
} |
|
||||
|
|
||||
func grpcMsgOngoing(t *testing.T) { |
|
||||
msg := genGrpcMsg("grpc-msg-pending") |
|
||||
err := msg.Prepare(fmt.Sprintf("%s/examples.Busi/CanSubmit", examples.BusiGrpc)) |
|
||||
assert.Nil(t, err) |
|
||||
examples.MainSwitch.CanSubmitResult.SetOnce(dtmcli.ResultOngoing) |
|
||||
cronTransOnceForwardNow(180) |
|
||||
assert.Equal(t, dtmcli.StatusPrepared, getTransStatus(msg.Gid)) |
|
||||
examples.MainSwitch.TransInResult.SetOnce(dtmcli.ResultOngoing) |
|
||||
cronTransOnceForwardNow(180) |
|
||||
assert.Equal(t, dtmcli.StatusSubmitted, getTransStatus(msg.Gid)) |
|
||||
cronTransOnce() |
|
||||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(msg.Gid)) |
|
||||
} |
|
||||
|
|
||||
func genGrpcMsg(gid string) *dtmgrpc.MsgGrpc { |
|
||||
req := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) |
|
||||
return dtmgrpc.NewMsgGrpc(examples.DtmGrpcServer, gid). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransOut", req). |
|
||||
Add(examples.BusiGrpc+"/examples.Busi/TransIn", req) |
|
||||
|
|
||||
} |
|
||||
@ -1,56 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/dtmgrpc" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestGrpcSaga(t *testing.T) { |
|
||||
sagaGrpcNormal(t) |
|
||||
sagaGrpcCommittedOngoing(t) |
|
||||
sagaGrpcRollback(t) |
|
||||
} |
|
||||
|
|
||||
func sagaGrpcNormal(t *testing.T) { |
|
||||
saga := genSagaGrpc("gid-sagaGrpcNormal", false, false) |
|
||||
saga.Submit() |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
||||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(saga.Gid)) |
|
||||
transQuery(t, saga.Gid) |
|
||||
} |
|
||||
|
|
||||
func sagaGrpcCommittedOngoing(t *testing.T) { |
|
||||
saga := genSagaGrpc("gid-committedOngoingGrpc", false, false) |
|
||||
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
|
||||
saga.Submit() |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusPrepared, dtmcli.StatusPrepared, dtmcli.StatusPrepared}, getBranchesStatus(saga.Gid)) |
|
||||
cronTransOnce() |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
||||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(saga.Gid)) |
|
||||
} |
|
||||
|
|
||||
func sagaGrpcRollback(t *testing.T) { |
|
||||
saga := genSagaGrpc("gid-rollbackSaga2Grpc", false, true) |
|
||||
examples.MainSwitch.TransOutRevertResult.SetOnce(dtmcli.ResultOngoing) |
|
||||
saga.Submit() |
|
||||
waitTransProcessed(saga.Gid) |
|
||||
assert.Equal(t, dtmcli.StatusAborting, getTransStatus(saga.Gid)) |
|
||||
cronTransOnce() |
|
||||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(saga.Gid)) |
|
||||
assert.Equal(t, []string{dtmcli.StatusSucceed, dtmcli.StatusSucceed, dtmcli.StatusSucceed, dtmcli.StatusFailed}, getBranchesStatus(saga.Gid)) |
|
||||
} |
|
||||
|
|
||||
func genSagaGrpc(gid string, outFailed bool, inFailed bool) *dtmgrpc.SagaGrpc { |
|
||||
dtmcli.Logf("beginning a grpc saga test ---------------- %s", gid) |
|
||||
saga := dtmgrpc.NewSaga(examples.DtmGrpcServer, gid) |
|
||||
req := dtmcli.MustMarshal(examples.GenTransReq(30, outFailed, inFailed)) |
|
||||
saga.Add(examples.BusiGrpc+"/examples.Busi/TransOut", examples.BusiGrpc+"/examples.Busi/TransOutRevert", req) |
|
||||
saga.Add(examples.BusiGrpc+"/examples.Busi/TransIn", examples.BusiGrpc+"/examples.Busi/TransInRevert", req) |
|
||||
return saga |
|
||||
} |
|
||||
@ -1,65 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/dtmgrpc" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestGrpcTcc(t *testing.T) { |
|
||||
tccGrpcType(t) |
|
||||
tccGrpcNormal(t) |
|
||||
tccGrpcNested(t) |
|
||||
tccGrpcRollback(t) |
|
||||
} |
|
||||
|
|
||||
func tccGrpcType(t *testing.T) { |
|
||||
_, err := dtmgrpc.TccFromRequest(&dtmgrpc.BusiRequest{Info: &dtmgrpc.BranchInfo{}}) |
|
||||
assert.Error(t, err) |
|
||||
dtmcli.Logf("expecting dtmgrpcserver error") |
|
||||
err = dtmgrpc.TccGlobalTransaction("-", "", func(tcc *dtmgrpc.TccGrpc) error { return nil }) |
|
||||
assert.Error(t, err) |
|
||||
} |
|
||||
func tccGrpcNormal(t *testing.T) { |
|
||||
data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) |
|
||||
gid := "tccGrpcNormal" |
|
||||
err := dtmgrpc.TccGlobalTransaction(examples.DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
|
||||
_, err := tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransOut", examples.BusiGrpc+"/examples.Busi/TransOutConfirm", examples.BusiGrpc+"/examples.Busi/TransOutRevert") |
|
||||
assert.Nil(t, err) |
|
||||
_, err = tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransIn", examples.BusiGrpc+"/examples.Busi/TransInConfirm", examples.BusiGrpc+"/examples.Busi/TransInRevert") |
|
||||
return err |
|
||||
}) |
|
||||
assert.Nil(t, err) |
|
||||
} |
|
||||
|
|
||||
func tccGrpcNested(t *testing.T) { |
|
||||
data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) |
|
||||
gid := "tccGrpcNested" |
|
||||
err := dtmgrpc.TccGlobalTransaction(examples.DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
|
||||
_, err := tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransOutTcc", examples.BusiGrpc+"/examples.Busi/TransOutConfirm", examples.BusiGrpc+"/examples.Busi/TransOutRevert") |
|
||||
assert.Nil(t, err) |
|
||||
_, err = tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransInTccNested", examples.BusiGrpc+"/examples.Busi/TransInConfirm", examples.BusiGrpc+"/examples.Busi/TransInRevert") |
|
||||
return err |
|
||||
}) |
|
||||
assert.Nil(t, err) |
|
||||
} |
|
||||
|
|
||||
func tccGrpcRollback(t *testing.T) { |
|
||||
gid := "tccGrpcRollback" |
|
||||
data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30, TransInResult: dtmcli.ResultFailure}) |
|
||||
err := dtmgrpc.TccGlobalTransaction(examples.DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
|
||||
_, err := tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransOutTcc", examples.BusiGrpc+"/examples.Busi/TransOutConfirm", examples.BusiGrpc+"/examples.Busi/TransOutRevert") |
|
||||
assert.Nil(t, err) |
|
||||
examples.MainSwitch.TransOutRevertResult.SetOnce(dtmcli.ResultOngoing) |
|
||||
_, err = tcc.CallBranch(data, examples.BusiGrpc+"/examples.Busi/TransInTcc", examples.BusiGrpc+"/examples.Busi/TransInConfirm", examples.BusiGrpc+"/examples.Busi/TransInRevert") |
|
||||
return err |
|
||||
}) |
|
||||
assert.Error(t, err) |
|
||||
waitTransProcessed(gid) |
|
||||
assert.Equal(t, dtmcli.StatusAborting, getTransStatus(gid)) |
|
||||
cronTransOnce() |
|
||||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(gid)) |
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
package test |
|
||||
|
|
||||
import ( |
|
||||
"fmt" |
|
||||
"testing" |
|
||||
|
|
||||
"github.com/stretchr/testify/assert" |
|
||||
"github.com/yedf/dtm/dtmcli" |
|
||||
"github.com/yedf/dtm/dtmgrpc" |
|
||||
"github.com/yedf/dtm/examples" |
|
||||
) |
|
||||
|
|
||||
func TestGrpcXa(t *testing.T) { |
|
||||
xaGrpcType(t) |
|
||||
xaGrpcLocalError(t) |
|
||||
xaGrpcNormal(t) |
|
||||
xaGrpcRollback(t) |
|
||||
} |
|
||||
|
|
||||
func xaGrpcType(t *testing.T) { |
|
||||
_, err := dtmgrpc.XaGrpcFromRequest(&dtmgrpc.BusiRequest{Info: &dtmgrpc.BranchInfo{}}) |
|
||||
assert.Error(t, err) |
|
||||
|
|
||||
err = examples.XaGrpcClient.XaLocalTransaction(&dtmgrpc.BusiRequest{Info: &dtmgrpc.BranchInfo{}}, nil) |
|
||||
assert.Error(t, err) |
|
||||
|
|
||||
err = dtmcli.CatchP(func() { |
|
||||
examples.XaGrpcClient.XaGlobalTransaction("id1", func(xa *dtmgrpc.XaGrpc) error { panic(fmt.Errorf("hello")) }) |
|
||||
}) |
|
||||
assert.Error(t, err) |
|
||||
} |
|
||||
|
|
||||
func xaGrpcLocalError(t *testing.T) { |
|
||||
xc := examples.XaGrpcClient |
|
||||
err := xc.XaGlobalTransaction("xaGrpcLocalError", func(xa *dtmgrpc.XaGrpc) error { |
|
||||
return fmt.Errorf("an error") |
|
||||
}) |
|
||||
assert.Error(t, err, fmt.Errorf("an error")) |
|
||||
} |
|
||||
|
|
||||
func xaGrpcNormal(t *testing.T) { |
|
||||
xc := examples.XaGrpcClient |
|
||||
gid := "xaGrpcNormal" |
|
||||
err := xc.XaGlobalTransaction(gid, func(xa *dtmgrpc.XaGrpc) error { |
|
||||
req := dtmcli.MustMarshal(examples.GenTransReq(30, false, false)) |
|
||||
_, err := xa.CallBranch(req, examples.BusiGrpc+"/examples.Busi/TransOutXa") |
|
||||
if err != nil { |
|
||||
return err |
|
||||
} |
|
||||
_, err = xa.CallBranch(req, examples.BusiGrpc+"/examples.Busi/TransInXa") |
|
||||
return err |
|
||||
}) |
|
||||
assert.Equal(t, nil, err) |
|
||||
waitTransProcessed(gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(gid)) |
|
||||
} |
|
||||
|
|
||||
func xaGrpcRollback(t *testing.T) { |
|
||||
xc := examples.XaGrpcClient |
|
||||
gid := "xaGrpcRollback" |
|
||||
err := xc.XaGlobalTransaction(gid, func(xa *dtmgrpc.XaGrpc) error { |
|
||||
req := dtmcli.MustMarshal(&examples.TransReq{Amount: 30, TransInResult: dtmcli.ResultFailure}) |
|
||||
_, err := xa.CallBranch(req, examples.BusiGrpc+"/examples.Busi/TransOutXa") |
|
||||
if err != nil { |
|
||||
return err |
|
||||
} |
|
||||
_, err = xa.CallBranch(req, examples.BusiGrpc+"/examples.Busi/TransInXa") |
|
||||
return err |
|
||||
}) |
|
||||
assert.Error(t, err) |
|
||||
waitTransProcessed(gid) |
|
||||
assert.Equal(t, []string{dtmcli.StatusSucceed, dtmcli.StatusPrepared}, getBranchesStatus(gid)) |
|
||||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(gid)) |
|
||||
} |
|
||||
@ -0,0 +1,59 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/dtmgrpc" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
func TestMsgGrpcNormal(t *testing.T) { |
||||
|
msg := genGrpcMsg(dtmimp.GetFuncName()) |
||||
|
err := msg.Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(msg.Gid) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(msg.Gid)) |
||||
|
assert.Equal(t, []string{StatusSucceed, StatusSucceed}, getBranchesStatus(msg.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestMsgGrpcTimeoutSuccess(t *testing.T) { |
||||
|
msg := genGrpcMsg(dtmimp.GetFuncName()) |
||||
|
err := msg.Prepare("") |
||||
|
assert.Nil(t, err) |
||||
|
examples.MainSwitch.CanSubmitResult.SetOnce(dtmcli.ResultOngoing) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusSubmitted, getTransStatus(msg.Gid)) |
||||
|
assert.Equal(t, []string{StatusPrepared, StatusPrepared}, getBranchesStatus(msg.Gid)) |
||||
|
cronTransOnce() |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(msg.Gid)) |
||||
|
assert.Equal(t, []string{StatusSucceed, StatusSucceed}, getBranchesStatus(msg.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestMsgGrpcTimeoutFailed(t *testing.T) { |
||||
|
msg := genGrpcMsg(dtmimp.GetFuncName()) |
||||
|
msg.Prepare("") |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
examples.MainSwitch.CanSubmitResult.SetOnce(dtmcli.ResultOngoing) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
examples.MainSwitch.CanSubmitResult.SetOnce(dtmcli.ResultFailure) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusFailed, getTransStatus(msg.Gid)) |
||||
|
assert.Equal(t, []string{StatusPrepared, StatusPrepared}, getBranchesStatus(msg.Gid)) |
||||
|
} |
||||
|
|
||||
|
func genGrpcMsg(gid string) *dtmgrpc.MsgGrpc { |
||||
|
req := &examples.BusiReq{Amount: 30} |
||||
|
msg := dtmgrpc.NewMsgGrpc(examples.DtmGrpcServer, gid). |
||||
|
Add(examples.BusiGrpc+"/examples.Busi/TransOut", req). |
||||
|
Add(examples.BusiGrpc+"/examples.Busi/TransIn", req) |
||||
|
msg.QueryPrepared = fmt.Sprintf("%s/examples.Busi/CanSubmit", examples.BusiGrpc) |
||||
|
return msg |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
func TestMsgOptionsTimeout(t *testing.T) { |
||||
|
msg := genMsg(dtmimp.GetFuncName()) |
||||
|
msg.Prepare("") |
||||
|
cronTransOnce() |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
cronTransOnceForwardNow(60) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(msg.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestMsgOptionsTimeoutCustom(t *testing.T) { |
||||
|
msg := genMsg(dtmimp.GetFuncName()) |
||||
|
msg.TimeoutToFail = 120 |
||||
|
msg.Prepare("") |
||||
|
cronTransOnce() |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
cronTransOnceForwardNow(60) |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(msg.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestMsgOptionsTimeoutFailed(t *testing.T) { |
||||
|
msg := genMsg(dtmimp.GetFuncName()) |
||||
|
msg.TimeoutToFail = 120 |
||||
|
msg.Prepare("") |
||||
|
cronTransOnce() |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
cronTransOnceForwardNow(60) |
||||
|
assert.Equal(t, StatusPrepared, getTransStatus(msg.Gid)) |
||||
|
examples.MainSwitch.CanSubmitResult.SetOnce(dtmcli.ResultFailure) |
||||
|
cronTransOnceForwardNow(180) |
||||
|
assert.Equal(t, StatusFailed, getTransStatus(msg.Gid)) |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
func TestSagaBarrierNormal(t *testing.T) { |
||||
|
saga := genSagaBarrier(dtmimp.GetFuncName(), false, false) |
||||
|
err := saga.Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(saga.Gid) |
||||
|
assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid)) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestSagaBarrierRollback(t *testing.T) { |
||||
|
saga := genSagaBarrier(dtmimp.GetFuncName(), false, true) |
||||
|
err := saga.Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(saga.Gid) |
||||
|
assert.Equal(t, StatusFailed, getTransStatus(saga.Gid)) |
||||
|
assert.Equal(t, []string{StatusSucceed, StatusSucceed, StatusSucceed, StatusFailed}, getBranchesStatus(saga.Gid)) |
||||
|
} |
||||
|
|
||||
|
func genSagaBarrier(gid string, outFailed, inFailed bool) *dtmcli.Saga { |
||||
|
req := examples.GenTransReq(30, outFailed, inFailed) |
||||
|
return dtmcli.NewSaga(DtmServer, gid). |
||||
|
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req). |
||||
|
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req) |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
func TestSagaCompatibleNormal(t *testing.T) { // compatible with old http, which put payload in steps.data
|
||||
|
gid := dtmimp.GetFuncName() |
||||
|
body := fmt.Sprintf(`{"gid":"%s","trans_type":"saga","steps":[{"action":"%s/TransOut","compensate":"%s/TransOutRevert","data":"{\"amount\":30,\"transInResult\":\"SUCCESS\",\"transOutResult\":\"SUCCESS\"}"},{"action":"%s/TransIn","compensate":"%s/TransInRevert","data":"{\"amount\":30,\"transInResult\":\"SUCCESS\",\"transOutResult\":\"SUCCESS\"}"}]}`, |
||||
|
gid, examples.Busi, examples.Busi, examples.Busi, examples.Busi) |
||||
|
dtmimp.RestyClient.R().SetBody(body).Post(fmt.Sprintf("%s/submit", examples.DtmServer)) |
||||
|
waitTransProcessed(gid) |
||||
|
assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(gid)) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(gid)) |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/stretchr/testify/assert" |
||||
|
"github.com/yedf/dtm/dtmcli/dtmimp" |
||||
|
"github.com/yedf/dtm/dtmgrpc" |
||||
|
"github.com/yedf/dtm/examples" |
||||
|
) |
||||
|
|
||||
|
func TestSagaGrpcBarrierNormal(t *testing.T) { |
||||
|
saga := genSagaGrpcBarrier(dtmimp.GetFuncName(), false, false) |
||||
|
err := saga.Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(saga.Gid) |
||||
|
assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid)) |
||||
|
assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid)) |
||||
|
} |
||||
|
|
||||
|
func TestSagaGrpcBarrierRollback(t *testing.T) { |
||||
|
saga := genSagaGrpcBarrier(dtmimp.GetFuncName(), false, true) |
||||
|
err := saga.Submit() |
||||
|
assert.Nil(t, err) |
||||
|
waitTransProcessed(saga.Gid) |
||||
|
assert.Equal(t, StatusFailed, getTransStatus(saga.Gid)) |
||||
|
assert.Equal(t, []string{StatusSucceed, StatusSucceed, StatusSucceed, StatusFailed}, getBranchesStatus(saga.Gid)) |
||||
|
} |
||||
|
|
||||
|
func genSagaGrpcBarrier(gid string, outFailed bool, inFailed bool) *dtmgrpc.SagaGrpc { |
||||
|
saga := dtmgrpc.NewSagaGrpc(examples.DtmGrpcServer, gid) |
||||
|
req := examples.GenBusiReq(30, outFailed, inFailed) |
||||
|
saga.Add(examples.BusiGrpc+"/examples.Busi/TransOutBSaga", examples.BusiGrpc+"/examples.Busi/TransOutRevertBSaga", req) |
||||
|
saga.Add(examples.BusiGrpc+"/examples.Busi/TransInBSaga", examples.BusiGrpc+"/examples.Busi/TransInRevertBSaga", req) |
||||
|
return saga |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue