mirror of https://github.com/dtm-labs/dtm.git
csharpjavadistributed-transactionsdtmgogolangmicroservicenodejsphpdatabasesagaseatatcctransactiontransactionsxapythondistributed
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
/*
|
|
* Copyright (c) 2021 yedf. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style
|
|
* license that can be found in the LICENSE file.
|
|
*/
|
|
|
|
package dtmsvr
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/dtm-labs/dtm/dtmcli"
|
|
"github.com/dtm-labs/dtm/dtmgrpc"
|
|
pb "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
// dtmServer is used to implement dtmgimp.DtmServer.
|
|
type dtmServer struct {
|
|
pb.UnimplementedDtmServer
|
|
}
|
|
|
|
func (s *dtmServer) NewGid(ctx context.Context, in *emptypb.Empty) (*pb.DtmGidReply, error) {
|
|
return &pb.DtmGidReply{Gid: GenGid()}, nil
|
|
}
|
|
|
|
func (s *dtmServer) Submit(ctx context.Context, in *pb.DtmRequest) (*emptypb.Empty, error) {
|
|
r := svcSubmit(TransFromDtmRequest(ctx, in))
|
|
return &emptypb.Empty{}, dtmgrpc.DtmError2GrpcError(r)
|
|
}
|
|
|
|
func (s *dtmServer) Prepare(ctx context.Context, in *pb.DtmRequest) (*emptypb.Empty, error) {
|
|
r := svcPrepare(TransFromDtmRequest(ctx, in))
|
|
return &emptypb.Empty{}, dtmgrpc.DtmError2GrpcError(r)
|
|
}
|
|
|
|
func (s *dtmServer) Abort(ctx context.Context, in *pb.DtmRequest) (*emptypb.Empty, error) {
|
|
r := svcAbort(TransFromDtmRequest(ctx, in))
|
|
return &emptypb.Empty{}, dtmgrpc.DtmError2GrpcError(r)
|
|
}
|
|
|
|
func (s *dtmServer) RegisterBranch(ctx context.Context, in *pb.DtmBranchRequest) (*emptypb.Empty, error) {
|
|
r := svcRegisterBranch(in.TransType, &TransBranch{
|
|
Gid: in.Gid,
|
|
BranchID: in.BranchID,
|
|
Status: dtmcli.StatusPrepared,
|
|
BinData: in.BusiPayload,
|
|
}, in.Data)
|
|
return &emptypb.Empty{}, dtmgrpc.DtmError2GrpcError(r)
|
|
}
|
|
|