mirror of https://github.com/dtm-labs/dtm.git
100 changed files with 2621 additions and 2367 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 ( |
|||
"fmt" |
|||
@ -1,4 +1,4 @@ |
|||
package dtmcli |
|||
package dtmimp |
|||
|
|||
import ( |
|||
"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
|
|||
BranchType string `json:"-"` // used in XA/TCC
|
|||
|
|||
QueryPrepared string `json:"query_prepared"` // 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, branchType 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, |
|||
"branch_type": branchType, |
|||
}). |
|||
Post(url) |
|||
return resp, CheckResponse(resp, err) |
|||
} |
|||
@ -1,8 +1,6 @@ |
|||
package dtmcli |
|||
package dtmimp |
|||
|
|||
import ( |
|||
"database/sql" |
|||
) |
|||
import "database/sql" |
|||
|
|||
// DB inteface of dtmcli db
|
|||
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 ( |
|||
"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 |
|||
|
|||
import ( |
|||
"context" |
|||
|
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/dtmgrpc/dtmgimp" |
|||
) |
|||
|
|||
// BranchBarrier 子事务屏障
|
|||
type BranchBarrier struct { |
|||
*dtmcli.BranchBarrier |
|||
} |
|||
|
|||
// 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 |
|||
// BarrierFromGrpc generate a Barrier from grpc context
|
|||
func BarrierFromGrpc(ctx context.Context) (*dtmcli.BranchBarrier, error) { |
|||
tb := dtmgimp.TransBaseFromGrpc(ctx) |
|||
return dtmcli.BarrierFrom(tb.TransType, tb.Gid, tb.BranchID, tb.BranchType) |
|||
} |
|||
|
|||
@ -0,0 +1,674 @@ |
|||
// 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 |
|||
|
|||
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 *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} |
|||
} |
|||
|
|||
func (x *DtmBranchInfo) GetGid() string { |
|||
if x != nil { |
|||
return x.Gid |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
func (x *DtmBranchInfo) GetTransType() string { |
|||
if x != nil { |
|||
return x.TransType |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
func (x *DtmBranchInfo) GetBranchID() string { |
|||
if x != nil { |
|||
return x.BranchID |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
func (x *DtmBranchInfo) GetBranchType() string { |
|||
if x != nil { |
|||
return x.BranchType |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
type DtmTccBranchRequest struct { |
|||
state protoimpl.MessageState |
|||
sizeCache protoimpl.SizeCache |
|||
unknownFields protoimpl.UnknownFields |
|||
|
|||
Info *DtmBranchInfo `protobuf:"bytes,1,opt,name=Info,proto3" json:"Info,omitempty"` |
|||
BusiPayload []byte `protobuf:"bytes,2,opt,name=BusiPayload,proto3" json:"BusiPayload,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_dtmgimp_dtmgimp_proto_msgTypes[4] |
|||
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_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 DtmTccBranchRequest.ProtoReflect.Descriptor instead.
|
|||
func (*DtmTccBranchRequest) Descriptor() ([]byte, []int) { |
|||
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{4} |
|||
} |
|||
|
|||
func (x *DtmTccBranchRequest) GetInfo() *DtmBranchInfo { |
|||
if x != nil { |
|||
return x.Info |
|||
} |
|||
return nil |
|||
} |
|||
|
|||
func (x *DtmTccBranchRequest) GetBusiPayload() []byte { |
|||
if x != nil { |
|||
return x.BusiPayload |
|||
} |
|||
return nil |
|||
} |
|||
|
|||
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 *DtmBranchInfo `protobuf:"bytes,1,opt,name=Info,proto3" json:"Info,omitempty"` |
|||
BusiPayload []byte `protobuf:"bytes,2,opt,name=BusiPayload,proto3" json:"BusiPayload,omitempty"` |
|||
Notify string `protobuf:"bytes,3,opt,name=Notify,proto3" json:"Notify,omitempty"` // dtm will call this url to commit/rollback
|
|||
} |
|||
|
|||
func (x *DtmXaBranchRequest) Reset() { |
|||
*x = DtmXaBranchRequest{} |
|||
if protoimpl.UnsafeEnabled { |
|||
mi := &file_dtmgrpc_dtmgimp_dtmgimp_proto_msgTypes[5] |
|||
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_dtmgimp_dtmgimp_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 DtmXaBranchRequest.ProtoReflect.Descriptor instead.
|
|||
func (*DtmXaBranchRequest) Descriptor() ([]byte, []int) { |
|||
return file_dtmgrpc_dtmgimp_dtmgimp_proto_rawDescGZIP(), []int{5} |
|||
} |
|||
|
|||
func (x *DtmXaBranchRequest) GetInfo() *DtmBranchInfo { |
|||
if x != nil { |
|||
return x.Info |
|||
} |
|||
return nil |
|||
} |
|||
|
|||
func (x *DtmXaBranchRequest) GetBusiPayload() []byte { |
|||
if x != nil { |
|||
return x.BusiPayload |
|||
} |
|||
return nil |
|||
} |
|||
|
|||
func (x *DtmXaBranchRequest) GetNotify() string { |
|||
if x != nil { |
|||
return x.Notify |
|||
} |
|||
return "" |
|||
} |
|||
|
|||
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, 0x7b, 0x0a, 0x0d, 0x44, 0x74, 0x6d, 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, 0xa7, 0x01, 0x0a, 0x13, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, |
|||
0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x04, 0x49, 0x6e, 0x66, |
|||
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, |
|||
0x70, 0x2e, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, |
|||
0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x20, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, |
|||
0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x75, 0x73, 0x69, |
|||
0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 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, 0x7a, 0x0a, 0x12, 0x44, |
|||
0x74, 0x6d, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, |
|||
0x74, 0x12, 0x2a, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, |
|||
0x16, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, |
|||
0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x20, 0x0a, |
|||
0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, |
|||
0x28, 0x0c, 0x52, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, |
|||
0x16, 0x0a, 0x06, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, |
|||
0x06, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 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, 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, 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, |
|||
0x69, 0x6d, 0x70, 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, 0x69, 0x6d, 0x70, 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, 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
|
|||
(*DtmTccBranchRequest)(nil), // 4: dtmgimp.DtmTccBranchRequest
|
|||
(*DtmXaBranchRequest)(nil), // 5: dtmgimp.DtmXaBranchRequest
|
|||
(*emptypb.Empty)(nil), // 6: google.protobuf.Empty
|
|||
} |
|||
var file_dtmgrpc_dtmgimp_dtmgimp_proto_depIdxs = []int32{ |
|||
0, // 0: dtmgimp.DtmRequest.TransOptions:type_name -> dtmgimp.DtmTransOptions
|
|||
3, // 1: dtmgimp.DtmTccBranchRequest.Info:type_name -> dtmgimp.DtmBranchInfo
|
|||
3, // 2: dtmgimp.DtmXaBranchRequest.Info:type_name -> dtmgimp.DtmBranchInfo
|
|||
6, // 3: dtmgimp.Dtm.NewGid:input_type -> google.protobuf.Empty
|
|||
1, // 4: dtmgimp.Dtm.Submit:input_type -> dtmgimp.DtmRequest
|
|||
1, // 5: dtmgimp.Dtm.Prepare:input_type -> dtmgimp.DtmRequest
|
|||
1, // 6: dtmgimp.Dtm.Abort:input_type -> dtmgimp.DtmRequest
|
|||
4, // 7: dtmgimp.Dtm.RegisterTccBranch:input_type -> dtmgimp.DtmTccBranchRequest
|
|||
5, // 8: dtmgimp.Dtm.RegisterXaBranch:input_type -> dtmgimp.DtmXaBranchRequest
|
|||
2, // 9: dtmgimp.Dtm.NewGid:output_type -> dtmgimp.DtmGidReply
|
|||
6, // 10: dtmgimp.Dtm.Submit:output_type -> google.protobuf.Empty
|
|||
6, // 11: dtmgimp.Dtm.Prepare:output_type -> google.protobuf.Empty
|
|||
6, // 12: dtmgimp.Dtm.Abort:output_type -> google.protobuf.Empty
|
|||
6, // 13: dtmgimp.Dtm.RegisterTccBranch:output_type -> google.protobuf.Empty
|
|||
6, // 14: dtmgimp.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_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.(*DtmTccBranchRequest); 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[5].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 |
|||
} |
|||
} |
|||
} |
|||
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,58 @@ |
|||
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 RegisterTccBranch(DtmTccBranchRequest) returns (google.protobuf.Empty) {} |
|||
rpc RegisterXaBranch(DtmXaBranchRequest) 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 DtmBranchInfo { |
|||
string Gid = 1; |
|||
string TransType = 2; |
|||
string BranchID = 3; |
|||
string BranchType = 4; |
|||
} |
|||
|
|||
message DtmTccBranchRequest { |
|||
DtmBranchInfo Info = 1; |
|||
bytes BusiPayload = 2; |
|||
string Try = 3; |
|||
string Confirm = 4; |
|||
string Cancel = 5; |
|||
} |
|||
|
|||
message DtmXaBranchRequest { |
|||
DtmBranchInfo Info = 1; |
|||
bytes BusiPayload = 2; |
|||
string Notify = 3; // dtm will call this url to commit/rollback |
|||
} |
|||
@ -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, branchType, dtm string) context.Context { |
|||
md := metadata.Pairs( |
|||
mdpre+"gid", gid, |
|||
mdpre+"trans_type", transType, |
|||
mdpre+"branch_id", branchID, |
|||
mdpre+"branch_type", branchType, |
|||
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 branch_type: %s dtm: %s", tb.Gid, tb.TransType, tb.BranchID, tb.BranchType, 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.BranchType = mdGet(md, "branch_type") |
|||
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服务器的消息,响应为Emtpy,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 |
|||
|
|||
import ( |
|||
context "context" |
|||
|
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/dtmgrpc/dtmgimp" |
|||
"google.golang.org/protobuf/proto" |
|||
) |
|||
|
|||
// SagaGrpc struct of saga
|
|||
type SagaGrpc struct { |
|||
dtmcli.TransBase |
|||
Steps []dtmcli.SagaStep `json:"steps"` |
|||
dtmcli.Saga |
|||
} |
|||
|
|||
// NewSaga create a saga
|
|||
func NewSaga(server string, gid string) *SagaGrpc { |
|||
return &SagaGrpc{TransBase: *dtmcli.NewTransBase(gid, "saga", server, "")} |
|||
// NewSagaGrpc create a saga
|
|||
func NewSagaGrpc(server string, gid string) *SagaGrpc { |
|||
return &SagaGrpc{Saga: *dtmcli.NewSaga(server, gid)} |
|||
} |
|||
|
|||
// Add add a saga step
|
|||
func (s *SagaGrpc) Add(action string, compensate string, busiData []byte) *SagaGrpc { |
|||
s.Steps = append(s.Steps, dtmcli.SagaStep{ |
|||
Action: action, |
|||
Compensate: compensate, |
|||
Data: string(busiData), |
|||
}) |
|||
func (s *SagaGrpc) Add(action string, compensate string, payload proto.Message) *SagaGrpc { |
|||
s.Steps = append(s.Steps, map[string]string{"action": action, "compensate": compensate}) |
|||
s.BinPayloads = append(s.BinPayloads, dtmgimp.MustProtoMarshal(payload)) |
|||
return s |
|||
} |
|||
|
|||
// 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 |
|||
} |
|||
|
|||
// Submit submit the saga trans
|
|||
func (s *SagaGrpc) Submit() error { |
|||
_, err := MustGetDtmClient(s.Dtm).Submit(context.Background(), &DtmRequest{ |
|||
Gid: s.Gid, |
|||
TransType: s.TransType, |
|||
Data: dtmcli.MustMarshalString(&s.Steps), |
|||
}) |
|||
return err |
|||
return dtmgimp.DtmGrpcCall(&s.Saga.TransBase, "Submit") |
|||
} |
|||
|
|||
@ -1,15 +1,16 @@ |
|||
package dtmgrpc |
|||
|
|||
import ( |
|||
"context" |
|||
"testing" |
|||
|
|||
"github.com/stretchr/testify/assert" |
|||
) |
|||
|
|||
func TestType(t *testing.T) { |
|||
_, err := BarrierFromGrpc(&BusiRequest{Info: &BranchInfo{}}) |
|||
_, err := BarrierFromGrpc(context.Background()) |
|||
assert.Error(t, err) |
|||
|
|||
_, err = TccFromRequest(&BusiRequest{Info: &BranchInfo{}}) |
|||
_, err = TccFromGrpc(context.Background()) |
|||
assert.Error(t, err) |
|||
} |
|||
|
|||
@ -1,30 +1,37 @@ |
|||
syntax = "proto3"; |
|||
|
|||
package examples; |
|||
import "google/protobuf/empty.proto"; |
|||
|
|||
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. |
|||
service Busi { |
|||
rpc CanSubmit(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransIn(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOut(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInRevert(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutRevert(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInConfirm(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutConfirm(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc XaNotify(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc CanSubmit(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransIn(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOut(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransInRevert(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutRevert(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransInConfirm(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutConfirm(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc XaNotify(google.protobuf.Empty) returns (google.protobuf.Empty) {} |
|||
|
|||
rpc TransInXa(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutXa(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInTcc(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutTcc(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInTccNested(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInXa(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutXa(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransInTcc(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutTcc(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransInTccNested(BusiReq) returns (google.protobuf.Empty) {} |
|||
|
|||
rpc TransInBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInRevertBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransOutRevertBSaga(dtmgrpc.BusiRequest) returns (dtmgrpc.BusiReply) {} |
|||
rpc TransInBSaga(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutBSaga(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransInRevertBSaga(BusiReq) returns (google.protobuf.Empty) {} |
|||
rpc TransOutRevertBSaga(BusiReq) returns (google.protobuf.Empty) {} |
|||
} |
|||
|
|||
|
|||
@ -1,19 +1,19 @@ |
|||
package examples |
|||
|
|||
import ( |
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/dtmcli/dtmimp" |
|||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
|||
) |
|||
|
|||
func init() { |
|||
addSample("grpc_msg", func() string { |
|||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
|||
req := &BusiReq{Amount: 30} |
|||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
|||
msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, gid). |
|||
Add(BusiGrpc+"/examples.Busi/TransOut", req). |
|||
Add(BusiGrpc+"/examples.Busi/TransIn", req) |
|||
err := msg.Submit() |
|||
dtmcli.FatalIfError(err) |
|||
dtmimp.FatalIfError(err) |
|||
return msg.Gid |
|||
}) |
|||
} |
|||
|
|||
@ -1,30 +1,30 @@ |
|||
package examples |
|||
|
|||
import ( |
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/dtmcli/dtmimp" |
|||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
|||
) |
|||
|
|||
func init() { |
|||
addSample("grpc_saga", func() string { |
|||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
|||
req := &BusiReq{Amount: 30} |
|||
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/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
|||
err := saga.Submit() |
|||
dtmcli.FatalIfError(err) |
|||
dtmimp.FatalIfError(err) |
|||
return saga.Gid |
|||
}) |
|||
addSample("grpc_saga_wait", func() string { |
|||
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
|||
req := &BusiReq{Amount: 30} |
|||
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/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req) |
|||
saga.WaitResult = true |
|||
err := saga.Submit() |
|||
dtmcli.FatalIfError(err) |
|||
dtmimp.FatalIfError(err) |
|||
return saga.Gid |
|||
}) |
|||
} |
|||
|
|||
@ -1,24 +1,26 @@ |
|||
package examples |
|||
|
|||
import ( |
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/dtmcli/dtmimp" |
|||
dtmgrpc "github.com/yedf/dtm/dtmgrpc" |
|||
emptypb "google.golang.org/protobuf/types/known/emptypb" |
|||
) |
|||
|
|||
func init() { |
|||
addSample("grpc_tcc", func() string { |
|||
dtmcli.Logf("tcc simple transaction begin") |
|||
dtmimp.Logf("tcc simple transaction begin") |
|||
gid := dtmgrpc.MustGenGid(DtmGrpcServer) |
|||
err := dtmgrpc.TccGlobalTransaction(DtmGrpcServer, gid, func(tcc *dtmgrpc.TccGrpc) error { |
|||
data := dtmcli.MustMarshal(&TransReq{Amount: 30}) |
|||
_, err := tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransOutTcc", BusiGrpc+"/examples.Busi/TransOutConfirm", BusiGrpc+"/examples.Busi/TransOutRevert") |
|||
data := &BusiReq{Amount: 30} |
|||
r := &emptypb.Empty{} |
|||
err := tcc.CallBranch(data, BusiGrpc+"/examples.Busi/TransOutTcc", BusiGrpc+"/examples.Busi/TransOutConfirm", BusiGrpc+"/examples.Busi/TransOutRevert", r) |
|||
if err != nil { |
|||
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 |
|||
}) |
|||
dtmcli.FatalIfError(err) |
|||
dtmimp.FatalIfError(err) |
|||
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) |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
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/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{dtmcli.StatusPrepared, dtmcli.StatusSucceed, dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(gid)) |
|||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(gid)) |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
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 TestSagaOptionsRetryOngoing(t *testing.T) { |
|||
saga := genSaga1(dtmimp.GetFuncName(), false, false) |
|||
saga.RetryInterval = 150 // CronForwardDuration is larger than RetryInterval
|
|||
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
|||
err := saga.Submit() |
|||
assert.Nil(t, err) |
|||
waitTransProcessed(saga.Gid) |
|||
cronTransOnce() |
|||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(saga.Gid)) |
|||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|||
} |
|||
|
|||
func TestSagaOptionsRetryError(t *testing.T) { |
|||
saga := genSaga1(dtmimp.GetFuncName(), false, false) |
|||
saga.RetryInterval = 150 // CronForwardDuration is less than 2*RetryInterval
|
|||
examples.MainSwitch.TransOutResult.SetOnce("ERROR") |
|||
err := saga.Submit() |
|||
assert.Nil(t, err) |
|||
waitTransProcessed(saga.Gid) |
|||
cronTransOnce() |
|||
assert.Equal(t, dtmcli.StatusSubmitted, getTransStatus(saga.Gid)) |
|||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusPrepared}, getBranchesStatus(saga.Gid)) |
|||
cronTransOnceForwardCron(360) |
|||
assert.Equal(t, dtmcli.StatusSucceed, getTransStatus(saga.Gid)) |
|||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusSucceed}, getBranchesStatus(saga.Gid)) |
|||
} |
|||
|
|||
func TestSagaOptionsTimeout(t *testing.T) { |
|||
saga := genSaga(dtmimp.GetFuncName(), false, false) |
|||
saga.TimeoutToFail = 1800 |
|||
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
|||
saga.Submit() |
|||
waitTransProcessed(saga.Gid) |
|||
assert.Equal(t, dtmcli.StatusSubmitted, getTransStatus(saga.Gid)) |
|||
cronTransOnceForwardNow(3600) |
|||
assert.Equal(t, dtmcli.StatusFailed, getTransStatus(saga.Gid)) |
|||
} |
|||
|
|||
func TestSagaOptionsNormalWait(t *testing.T) { |
|||
saga := genSaga(dtmimp.GetFuncName(), false, false) |
|||
saga.SetOptions(&dtmimp.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Nil(t, err) |
|||
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)) |
|||
} |
|||
|
|||
func TestSagaOptionsCommittedOngoingWait(t *testing.T) { |
|||
saga := genSaga(dtmimp.GetFuncName(), false, false) |
|||
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
|||
saga.SetOptions(&dtmimp.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Error(t, err) |
|||
assert.Equal(t, []string{dtmcli.StatusPrepared, dtmcli.StatusPrepared, dtmcli.StatusPrepared, dtmcli.StatusPrepared}, getBranchesStatus(saga.Gid)) |
|||
assert.Equal(t, dtmcli.StatusSubmitted, getTransStatus(saga.Gid)) |
|||
waitTransProcessed(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 TestSagaOptionsRollbackWait(t *testing.T) { |
|||
saga := genSaga(dtmimp.GetFuncName(), false, true) |
|||
saga.SetOptions(&dtmimp.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Error(t, 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,50 +0,0 @@ |
|||
package test |
|||
|
|||
import ( |
|||
"testing" |
|||
|
|||
"github.com/stretchr/testify/assert" |
|||
"github.com/yedf/dtm/dtmcli" |
|||
"github.com/yedf/dtm/examples" |
|||
) |
|||
|
|||
func TestWaitSaga(t *testing.T) { |
|||
|
|||
sagaNormalWait(t) |
|||
sagaCommittedOngoingWait(t) |
|||
sagaRollbackWait(t) |
|||
} |
|||
|
|||
func sagaNormalWait(t *testing.T) { |
|||
saga := genSaga("gid-noramlSagaWait", false, false) |
|||
saga.SetOptions(&dtmcli.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Nil(t, err) |
|||
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 sagaCommittedOngoingWait(t *testing.T) { |
|||
saga := genSaga("gid-committedOngoingWait", false, false) |
|||
examples.MainSwitch.TransOutResult.SetOnce(dtmcli.ResultOngoing) |
|||
saga.SetOptions(&dtmcli.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Error(t, err) |
|||
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 sagaRollbackWait(t *testing.T) { |
|||
saga := genSaga("gid-rollbackSaga2Wait", false, true) |
|||
saga.SetOptions(&dtmcli.TransOptions{WaitResult: true}) |
|||
err := saga.Submit() |
|||
assert.Error(t, 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)) |
|||
} |
|||
Loading…
Reference in new issue