diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-04-23 12:17:11 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-04-23 12:17:11 +0300 |
commit | 6dccdf977c4983dea51cb9abf8772659c76d81a9 (patch) | |
tree | b9dc7200e3941d2f05ae5f1475959825739f1196 | |
parent | 7681d70808936e3f70d5f992b3b125fb8f6d3727 (diff) | |
parent | c820b0920740b021de5b2570413125daddca92e5 (diff) |
Merge branch 'pks-2pc-transaction-service' into 'master'
Implement reference transaction service
See merge request gitlab-org/gitaly!2077
-rw-r--r-- | changelogs/unreleased/pks-2pc-transaction-service.yml | 5 | ||||
-rw-r--r-- | internal/praefect/server.go | 2 | ||||
-rw-r--r-- | internal/praefect/service/transaction/server.go | 99 | ||||
-rw-r--r-- | internal/praefect/transaction_test.go | 88 | ||||
-rw-r--r-- | proto/go/gitalypb/protolist.go | 1 | ||||
-rw-r--r-- | proto/go/gitalypb/transaction.pb.go | 519 | ||||
-rw-r--r-- | proto/transaction.proto | 72 | ||||
-rw-r--r-- | ruby/proto/gitaly.rb | 2 | ||||
-rw-r--r-- | ruby/proto/gitaly/transaction_pb.rb | 45 | ||||
-rw-r--r-- | ruby/proto/gitaly/transaction_services_pb.rb | 24 |
10 files changed, 857 insertions, 0 deletions
diff --git a/changelogs/unreleased/pks-2pc-transaction-service.yml b/changelogs/unreleased/pks-2pc-transaction-service.yml new file mode 100644 index 000000000..df56e7a8a --- /dev/null +++ b/changelogs/unreleased/pks-2pc-transaction-service.yml @@ -0,0 +1,5 @@ +--- +title: Implement reference transaction service +merge_request: 2077 +author: +type: added diff --git a/internal/praefect/server.go b/internal/praefect/server.go index a29ce8e09..50af53059 100644 --- a/internal/praefect/server.go +++ b/internal/praefect/server.go @@ -24,6 +24,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/internal/praefect/service/server" + "gitlab.com/gitlab-org/gitaly/internal/praefect/service/transaction" "gitlab.com/gitlab-org/gitaly/internal/server/auth" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" @@ -127,6 +128,7 @@ func (srv *Server) RegisterServices(nm nodes.Manager, conf config.Config, ds dat // ServerServiceServer is necessary for the ServerInfo RPC gitalypb.RegisterServerServiceServer(srv.s, server.NewServer(conf, nm)) gitalypb.RegisterPraefectInfoServiceServer(srv.s, info.NewServer(nm, conf, ds)) + gitalypb.RegisterRefTransactionServer(srv.s, transaction.NewServer()) healthpb.RegisterHealthServer(srv.s, health.NewServer()) grpc_prometheus.Register(srv.s) diff --git a/internal/praefect/service/transaction/server.go b/internal/praefect/service/transaction/server.go new file mode 100644 index 000000000..aa17eee9f --- /dev/null +++ b/internal/praefect/service/transaction/server.go @@ -0,0 +1,99 @@ +package transaction + +import ( + "context" + "crypto/sha1" + "fmt" + "math/rand" + "sync" + + "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" +) + +type Server struct { + gitalypb.UnimplementedRefTransactionServer + + lock sync.Mutex + transactions map[uint64]string +} + +func NewServer() gitalypb.RefTransactionServer { + return &Server{ + transactions: make(map[uint64]string), + } +} + +// RegisterTransaction registers a new reference transaction for a set of nodes +// taking part in the transaction. +func (s *Server) RegisterTransaction(ctx context.Context, in *gitalypb.RegisterTransactionRequest) (*gitalypb.RegisterTransactionResponse, error) { + s.lock.Lock() + defer s.lock.Unlock() + + transactionID := rand.Uint64() + if _, ok := s.transactions[transactionID]; ok { + return nil, helper.ErrInternalf("transaction exists already") + } + + // We only accept a single node in transactions right now, which is + // usually the primary. This limitation will be lifted at a later point + // to allow for real transaction voting and multi-phase commits. + if len(in.Nodes) != 1 { + return nil, helper.ErrInvalidArgumentf("transaction requires exactly one node") + } + s.transactions[transactionID] = in.Nodes[0] + + return &gitalypb.RegisterTransactionResponse{ + TransactionId: transactionID, + }, nil +} + +// StartTransaction is called by a client who's starting a reference +// transaction. As we currently only have primary nodes which perform reference +// transactions, this RPC doesn't yet do anything of interest but will +// immediately return "COMMIT". In future, the RPC will wait for all clients of +// a given transaction to start the transaction and perform a vote. +func (s *Server) StartTransaction(ctx context.Context, in *gitalypb.StartTransactionRequest) (*gitalypb.StartTransactionResponse, error) { + s.lock.Lock() + defer s.lock.Unlock() + + // While the reference updates hash is not used yet, we already verify + // it's there. At a later point, the hash will be used to verify that + // all voting nodes agree on the same updates. + if len(in.ReferenceUpdatesHash) != sha1.Size { + return nil, helper.ErrInvalidArgumentf("invalid reference hash: %q", in.ReferenceUpdatesHash) + } + + transaction, ok := s.transactions[in.TransactionId] + if !ok { + return nil, helper.ErrNotFound(fmt.Errorf("no such transaction: %d", in.TransactionId)) + } + + if transaction != in.Node { + return nil, helper.ErrInternalf("invalid node for transaction: %q", in.Node) + } + + // Currently, only the primary node will perform transactions. We can + // thus just delete the transaction as soon as it starts the + // transaction and instruct it to commit. + delete(s.transactions, in.TransactionId) + + return &gitalypb.StartTransactionResponse{ + State: gitalypb.StartTransactionResponse_COMMIT, + }, nil +} + +// CancelTransaction cancels a registered transaction, removing all data +// associated with it. +func (s *Server) CancelTransaction(ctx context.Context, in *gitalypb.CancelTransactionRequest) (*gitalypb.CancelTransactionResponse, error) { + s.lock.Lock() + defer s.lock.Unlock() + + _, ok := s.transactions[in.TransactionId] + if !ok { + return nil, helper.ErrNotFound(fmt.Errorf("no such transaction: %d", in.TransactionId)) + } + delete(s.transactions, in.TransactionId) + + return &gitalypb.CancelTransactionResponse{}, nil +} diff --git a/internal/praefect/transaction_test.go b/internal/praefect/transaction_test.go new file mode 100644 index 000000000..ded0a8425 --- /dev/null +++ b/internal/praefect/transaction_test.go @@ -0,0 +1,88 @@ +package praefect + +import ( + "context" + "crypto/sha1" + "testing" + "time" + + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func TestTransactionSucceeds(t *testing.T) { + cc, _, cleanup := runPraefectServerWithGitaly(t, testConfig(1)) + defer cleanup() + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + client := gitalypb.NewRefTransactionClient(cc) + + registration, err := client.RegisterTransaction(ctx, &gitalypb.RegisterTransactionRequest{ + Nodes: []string{"node1"}, + }) + require.NoError(t, err) + require.NotZero(t, registration.TransactionId) + + hash := sha1.Sum([]byte{}) + + response, err := client.StartTransaction(ctx, &gitalypb.StartTransactionRequest{ + TransactionId: registration.TransactionId, + Node: "node1", + ReferenceUpdatesHash: hash[:], + }) + require.NoError(t, err) + require.Equal(t, gitalypb.StartTransactionResponse_COMMIT, response.State) +} + +func TestTransactionFailures(t *testing.T) { + cc, _, cleanup := runPraefectServerWithGitaly(t, testConfig(1)) + defer cleanup() + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + client := gitalypb.NewRefTransactionClient(cc) + + hash := sha1.Sum([]byte{}) + _, err := client.StartTransaction(ctx, &gitalypb.StartTransactionRequest{ + TransactionId: 1, + Node: "node1", + ReferenceUpdatesHash: hash[:], + }) + require.Error(t, err) + require.Equal(t, codes.NotFound, status.Code(err)) +} + +func TestTransactionCancellation(t *testing.T) { + cc, _, cleanup := runPraefectServerWithGitaly(t, testConfig(1)) + defer cleanup() + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + client := gitalypb.NewRefTransactionClient(cc) + + registration, err := client.RegisterTransaction(ctx, &gitalypb.RegisterTransactionRequest{ + Nodes: []string{"node1"}, + }) + require.NoError(t, err) + require.NotZero(t, registration.TransactionId) + + _, err = client.CancelTransaction(ctx, &gitalypb.CancelTransactionRequest{ + TransactionId: registration.TransactionId, + }) + require.NoError(t, err) + + hash := sha1.Sum([]byte{}) + _, err = client.StartTransaction(ctx, &gitalypb.StartTransactionRequest{ + TransactionId: registration.TransactionId, + Node: "node1", + ReferenceUpdatesHash: hash[:], + }) + require.Error(t, err) + require.Equal(t, codes.NotFound, status.Code(err)) +} diff --git a/proto/go/gitalypb/protolist.go b/proto/go/gitalypb/protolist.go index d2b27af02..a15916f70 100644 --- a/proto/go/gitalypb/protolist.go +++ b/proto/go/gitalypb/protolist.go @@ -23,5 +23,6 @@ var GitalyProtos = []string{ "shared.proto", "smarthttp.proto", "ssh.proto", + "transaction.proto", "wiki.proto", } diff --git a/proto/go/gitalypb/transaction.pb.go b/proto/go/gitalypb/transaction.pb.go new file mode 100644 index 000000000..59cf4085e --- /dev/null +++ b/proto/go/gitalypb/transaction.pb.go @@ -0,0 +1,519 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: transaction.proto + +package gitalypb + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// The outcome of the given transaction telling the client whether the +// transaction should be committed or rolled back. +type StartTransactionResponse_TransactionState int32 + +const ( + StartTransactionResponse_COMMIT StartTransactionResponse_TransactionState = 0 + StartTransactionResponse_ABORT StartTransactionResponse_TransactionState = 1 +) + +var StartTransactionResponse_TransactionState_name = map[int32]string{ + 0: "COMMIT", + 1: "ABORT", +} + +var StartTransactionResponse_TransactionState_value = map[string]int32{ + "COMMIT": 0, + "ABORT": 1, +} + +func (x StartTransactionResponse_TransactionState) String() string { + return proto.EnumName(StartTransactionResponse_TransactionState_name, int32(x)) +} + +func (StartTransactionResponse_TransactionState) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{3, 0} +} + +type RegisterTransactionRequest struct { + Repository *Repository `protobuf:"bytes,1,opt,name=repository,proto3" json:"repository,omitempty"` + // Nodes taking part in the transaction + Nodes []string `protobuf:"bytes,2,rep,name=nodes,proto3" json:"nodes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RegisterTransactionRequest) Reset() { *m = RegisterTransactionRequest{} } +func (m *RegisterTransactionRequest) String() string { return proto.CompactTextString(m) } +func (*RegisterTransactionRequest) ProtoMessage() {} +func (*RegisterTransactionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{0} +} + +func (m *RegisterTransactionRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RegisterTransactionRequest.Unmarshal(m, b) +} +func (m *RegisterTransactionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RegisterTransactionRequest.Marshal(b, m, deterministic) +} +func (m *RegisterTransactionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisterTransactionRequest.Merge(m, src) +} +func (m *RegisterTransactionRequest) XXX_Size() int { + return xxx_messageInfo_RegisterTransactionRequest.Size(m) +} +func (m *RegisterTransactionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_RegisterTransactionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisterTransactionRequest proto.InternalMessageInfo + +func (m *RegisterTransactionRequest) GetRepository() *Repository { + if m != nil { + return m.Repository + } + return nil +} + +func (m *RegisterTransactionRequest) GetNodes() []string { + if m != nil { + return m.Nodes + } + return nil +} + +type RegisterTransactionResponse struct { + TransactionId uint64 `protobuf:"varint,1,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RegisterTransactionResponse) Reset() { *m = RegisterTransactionResponse{} } +func (m *RegisterTransactionResponse) String() string { return proto.CompactTextString(m) } +func (*RegisterTransactionResponse) ProtoMessage() {} +func (*RegisterTransactionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{1} +} + +func (m *RegisterTransactionResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RegisterTransactionResponse.Unmarshal(m, b) +} +func (m *RegisterTransactionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RegisterTransactionResponse.Marshal(b, m, deterministic) +} +func (m *RegisterTransactionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisterTransactionResponse.Merge(m, src) +} +func (m *RegisterTransactionResponse) XXX_Size() int { + return xxx_messageInfo_RegisterTransactionResponse.Size(m) +} +func (m *RegisterTransactionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_RegisterTransactionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisterTransactionResponse proto.InternalMessageInfo + +func (m *RegisterTransactionResponse) GetTransactionId() uint64 { + if m != nil { + return m.TransactionId + } + return 0 +} + +type StartTransactionRequest struct { + Repository *Repository `protobuf:"bytes,1,opt,name=repository,proto3" json:"repository,omitempty"` + // ID of the transaction we're processing + TransactionId uint64 `protobuf:"varint,2,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + // Name of the Gitaly node that's starting a transaction. + Node string `protobuf:"bytes,3,opt,name=node,proto3" json:"node,omitempty"` + // SHA1 of the references that are to be updated + ReferenceUpdatesHash []byte `protobuf:"bytes,4,opt,name=reference_updates_hash,json=referenceUpdatesHash,proto3" json:"reference_updates_hash,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StartTransactionRequest) Reset() { *m = StartTransactionRequest{} } +func (m *StartTransactionRequest) String() string { return proto.CompactTextString(m) } +func (*StartTransactionRequest) ProtoMessage() {} +func (*StartTransactionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{2} +} + +func (m *StartTransactionRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StartTransactionRequest.Unmarshal(m, b) +} +func (m *StartTransactionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StartTransactionRequest.Marshal(b, m, deterministic) +} +func (m *StartTransactionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StartTransactionRequest.Merge(m, src) +} +func (m *StartTransactionRequest) XXX_Size() int { + return xxx_messageInfo_StartTransactionRequest.Size(m) +} +func (m *StartTransactionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StartTransactionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StartTransactionRequest proto.InternalMessageInfo + +func (m *StartTransactionRequest) GetRepository() *Repository { + if m != nil { + return m.Repository + } + return nil +} + +func (m *StartTransactionRequest) GetTransactionId() uint64 { + if m != nil { + return m.TransactionId + } + return 0 +} + +func (m *StartTransactionRequest) GetNode() string { + if m != nil { + return m.Node + } + return "" +} + +func (m *StartTransactionRequest) GetReferenceUpdatesHash() []byte { + if m != nil { + return m.ReferenceUpdatesHash + } + return nil +} + +type StartTransactionResponse struct { + State StartTransactionResponse_TransactionState `protobuf:"varint,1,opt,name=state,proto3,enum=gitaly.StartTransactionResponse_TransactionState" json:"state,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StartTransactionResponse) Reset() { *m = StartTransactionResponse{} } +func (m *StartTransactionResponse) String() string { return proto.CompactTextString(m) } +func (*StartTransactionResponse) ProtoMessage() {} +func (*StartTransactionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{3} +} + +func (m *StartTransactionResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StartTransactionResponse.Unmarshal(m, b) +} +func (m *StartTransactionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StartTransactionResponse.Marshal(b, m, deterministic) +} +func (m *StartTransactionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StartTransactionResponse.Merge(m, src) +} +func (m *StartTransactionResponse) XXX_Size() int { + return xxx_messageInfo_StartTransactionResponse.Size(m) +} +func (m *StartTransactionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StartTransactionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StartTransactionResponse proto.InternalMessageInfo + +func (m *StartTransactionResponse) GetState() StartTransactionResponse_TransactionState { + if m != nil { + return m.State + } + return StartTransactionResponse_COMMIT +} + +type CancelTransactionRequest struct { + Repository *Repository `protobuf:"bytes,1,opt,name=repository,proto3" json:"repository,omitempty"` + // ID of the transaction we're about to cancel + TransactionId uint64 `protobuf:"varint,2,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CancelTransactionRequest) Reset() { *m = CancelTransactionRequest{} } +func (m *CancelTransactionRequest) String() string { return proto.CompactTextString(m) } +func (*CancelTransactionRequest) ProtoMessage() {} +func (*CancelTransactionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{4} +} + +func (m *CancelTransactionRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CancelTransactionRequest.Unmarshal(m, b) +} +func (m *CancelTransactionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CancelTransactionRequest.Marshal(b, m, deterministic) +} +func (m *CancelTransactionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CancelTransactionRequest.Merge(m, src) +} +func (m *CancelTransactionRequest) XXX_Size() int { + return xxx_messageInfo_CancelTransactionRequest.Size(m) +} +func (m *CancelTransactionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CancelTransactionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CancelTransactionRequest proto.InternalMessageInfo + +func (m *CancelTransactionRequest) GetRepository() *Repository { + if m != nil { + return m.Repository + } + return nil +} + +func (m *CancelTransactionRequest) GetTransactionId() uint64 { + if m != nil { + return m.TransactionId + } + return 0 +} + +type CancelTransactionResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CancelTransactionResponse) Reset() { *m = CancelTransactionResponse{} } +func (m *CancelTransactionResponse) String() string { return proto.CompactTextString(m) } +func (*CancelTransactionResponse) ProtoMessage() {} +func (*CancelTransactionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{5} +} + +func (m *CancelTransactionResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CancelTransactionResponse.Unmarshal(m, b) +} +func (m *CancelTransactionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CancelTransactionResponse.Marshal(b, m, deterministic) +} +func (m *CancelTransactionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CancelTransactionResponse.Merge(m, src) +} +func (m *CancelTransactionResponse) XXX_Size() int { + return xxx_messageInfo_CancelTransactionResponse.Size(m) +} +func (m *CancelTransactionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CancelTransactionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CancelTransactionResponse proto.InternalMessageInfo + +func init() { + proto.RegisterEnum("gitaly.StartTransactionResponse_TransactionState", StartTransactionResponse_TransactionState_name, StartTransactionResponse_TransactionState_value) + proto.RegisterType((*RegisterTransactionRequest)(nil), "gitaly.RegisterTransactionRequest") + proto.RegisterType((*RegisterTransactionResponse)(nil), "gitaly.RegisterTransactionResponse") + proto.RegisterType((*StartTransactionRequest)(nil), "gitaly.StartTransactionRequest") + proto.RegisterType((*StartTransactionResponse)(nil), "gitaly.StartTransactionResponse") + proto.RegisterType((*CancelTransactionRequest)(nil), "gitaly.CancelTransactionRequest") + proto.RegisterType((*CancelTransactionResponse)(nil), "gitaly.CancelTransactionResponse") +} + +func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } + +var fileDescriptor_2cc4e03d2c28c490 = []byte{ + // 439 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x65, 0xd3, 0x24, 0x22, 0x43, 0x89, 0xd2, 0xa5, 0x02, 0xe3, 0x1e, 0x30, 0x8b, 0x90, 0x8c, + 0x04, 0x36, 0x04, 0x0e, 0x5c, 0x49, 0x91, 0xa0, 0x87, 0xaa, 0xd2, 0x36, 0x5c, 0x90, 0x50, 0xd8, + 0xd8, 0x13, 0xdb, 0x92, 0xf1, 0x9a, 0xdd, 0xed, 0xa1, 0xe2, 0x1f, 0xb8, 0xc2, 0xaf, 0x70, 0x47, + 0x7c, 0x14, 0x27, 0x14, 0x6f, 0x71, 0x4d, 0x63, 0x97, 0x0b, 0x12, 0xb7, 0x9d, 0x79, 0xf3, 0xe6, + 0xed, 0x9b, 0x59, 0x2d, 0xec, 0x18, 0x25, 0x0a, 0x2d, 0x22, 0x93, 0xc9, 0x22, 0x28, 0x95, 0x34, + 0x92, 0x0e, 0x93, 0xcc, 0x88, 0xfc, 0xd4, 0x85, 0x3c, 0x2b, 0x8c, 0xcd, 0xb9, 0xdb, 0x3a, 0x15, + 0x0a, 0x63, 0x1b, 0xb1, 0x1c, 0x5c, 0x8e, 0x49, 0xa6, 0x0d, 0xaa, 0xf9, 0x39, 0x9d, 0xe3, 0xc7, + 0x13, 0xd4, 0x86, 0x3e, 0x07, 0x50, 0x58, 0x4a, 0x9d, 0x19, 0xa9, 0x4e, 0x1d, 0xe2, 0x11, 0xff, + 0xda, 0x94, 0x06, 0xb6, 0x69, 0xc0, 0x6b, 0x64, 0xd6, 0xff, 0xfa, 0xe3, 0x21, 0xe1, 0x8d, 0x5a, + 0xba, 0x0b, 0x83, 0x42, 0xc6, 0xa8, 0x9d, 0x9e, 0xb7, 0xe5, 0x8f, 0xb8, 0x0d, 0xd8, 0x4b, 0xd8, + 0x6b, 0x55, 0xd3, 0xa5, 0x2c, 0x34, 0xd2, 0xfb, 0x30, 0x6e, 0x78, 0x58, 0x64, 0x71, 0x25, 0xd9, + 0xe7, 0xd7, 0x1b, 0xd9, 0x83, 0x98, 0x7d, 0x27, 0x70, 0xeb, 0xd8, 0x08, 0x65, 0xfe, 0xe9, 0x8d, + 0x37, 0xc5, 0x7b, 0x2d, 0xe2, 0x94, 0x42, 0x7f, 0xed, 0xc5, 0xd9, 0xf2, 0x88, 0x3f, 0xe2, 0xd5, + 0x99, 0x3e, 0x83, 0x9b, 0x0a, 0x57, 0xa8, 0xb0, 0x88, 0x70, 0x71, 0x52, 0xc6, 0xc2, 0xa0, 0x5e, + 0xa4, 0x42, 0xa7, 0x4e, 0xdf, 0x23, 0xfe, 0x36, 0xdf, 0xad, 0xd1, 0x37, 0x16, 0x7c, 0x2d, 0x74, + 0xca, 0x3e, 0x13, 0x70, 0x36, 0x6d, 0x9c, 0x8d, 0xe2, 0x15, 0x0c, 0xb4, 0x11, 0x06, 0x2b, 0x0b, + 0xe3, 0xe9, 0x93, 0xdf, 0x16, 0xba, 0x08, 0x41, 0x23, 0x77, 0xbc, 0x26, 0x72, 0xcb, 0x67, 0x0f, + 0x60, 0x72, 0x11, 0xa2, 0x00, 0xc3, 0xfd, 0xa3, 0xc3, 0xc3, 0x83, 0xf9, 0xe4, 0x0a, 0x1d, 0xc1, + 0xe0, 0xc5, 0xec, 0x88, 0xcf, 0x27, 0x84, 0x7d, 0x02, 0x67, 0x5f, 0x14, 0x11, 0xe6, 0xff, 0x61, + 0xae, 0x6c, 0x0f, 0x6e, 0xb7, 0x88, 0x5b, 0x73, 0xd3, 0x6f, 0x3d, 0x18, 0x73, 0x5c, 0x35, 0x20, + 0xba, 0x82, 0x1b, 0x2d, 0x4f, 0x89, 0xb2, 0xf3, 0x3b, 0x75, 0xbd, 0x6a, 0xf7, 0xde, 0xa5, 0x35, + 0x56, 0x92, 0x0d, 0x7f, 0x7e, 0xf1, 0x7b, 0x57, 0x09, 0x7d, 0x07, 0x93, 0x8b, 0x33, 0xa7, 0x77, + 0xba, 0xb7, 0x61, 0x15, 0xbc, 0xbf, 0xad, 0xab, 0x6e, 0xff, 0x1e, 0x76, 0x36, 0x6c, 0xd3, 0x9a, + 0xde, 0xb5, 0x0e, 0xf7, 0xee, 0x25, 0x15, 0x7f, 0x2a, 0xcc, 0x1e, 0xbf, 0x5d, 0xd7, 0xe6, 0x62, + 0x19, 0x44, 0xf2, 0x43, 0x68, 0x8f, 0x8f, 0xa4, 0x4a, 0x42, 0xdb, 0x21, 0xac, 0xfe, 0x81, 0x30, + 0x91, 0x67, 0x71, 0xb9, 0x5c, 0x0e, 0xab, 0xd4, 0xd3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x77, + 0xd4, 0x86, 0x22, 0x51, 0x04, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RefTransactionClient is the client API for RefTransaction service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RefTransactionClient interface { + RegisterTransaction(ctx context.Context, in *RegisterTransactionRequest, opts ...grpc.CallOption) (*RegisterTransactionResponse, error) + StartTransaction(ctx context.Context, in *StartTransactionRequest, opts ...grpc.CallOption) (*StartTransactionResponse, error) + CancelTransaction(ctx context.Context, in *CancelTransactionRequest, opts ...grpc.CallOption) (*CancelTransactionResponse, error) +} + +type refTransactionClient struct { + cc *grpc.ClientConn +} + +func NewRefTransactionClient(cc *grpc.ClientConn) RefTransactionClient { + return &refTransactionClient{cc} +} + +func (c *refTransactionClient) RegisterTransaction(ctx context.Context, in *RegisterTransactionRequest, opts ...grpc.CallOption) (*RegisterTransactionResponse, error) { + out := new(RegisterTransactionResponse) + err := c.cc.Invoke(ctx, "/gitaly.RefTransaction/RegisterTransaction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *refTransactionClient) StartTransaction(ctx context.Context, in *StartTransactionRequest, opts ...grpc.CallOption) (*StartTransactionResponse, error) { + out := new(StartTransactionResponse) + err := c.cc.Invoke(ctx, "/gitaly.RefTransaction/StartTransaction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *refTransactionClient) CancelTransaction(ctx context.Context, in *CancelTransactionRequest, opts ...grpc.CallOption) (*CancelTransactionResponse, error) { + out := new(CancelTransactionResponse) + err := c.cc.Invoke(ctx, "/gitaly.RefTransaction/CancelTransaction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RefTransactionServer is the server API for RefTransaction service. +type RefTransactionServer interface { + RegisterTransaction(context.Context, *RegisterTransactionRequest) (*RegisterTransactionResponse, error) + StartTransaction(context.Context, *StartTransactionRequest) (*StartTransactionResponse, error) + CancelTransaction(context.Context, *CancelTransactionRequest) (*CancelTransactionResponse, error) +} + +// UnimplementedRefTransactionServer can be embedded to have forward compatible implementations. +type UnimplementedRefTransactionServer struct { +} + +func (*UnimplementedRefTransactionServer) RegisterTransaction(ctx context.Context, req *RegisterTransactionRequest) (*RegisterTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterTransaction not implemented") +} +func (*UnimplementedRefTransactionServer) StartTransaction(ctx context.Context, req *StartTransactionRequest) (*StartTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StartTransaction not implemented") +} +func (*UnimplementedRefTransactionServer) CancelTransaction(ctx context.Context, req *CancelTransactionRequest) (*CancelTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CancelTransaction not implemented") +} + +func RegisterRefTransactionServer(s *grpc.Server, srv RefTransactionServer) { + s.RegisterService(&_RefTransaction_serviceDesc, srv) +} + +func _RefTransaction_RegisterTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RefTransactionServer).RegisterTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gitaly.RefTransaction/RegisterTransaction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RefTransactionServer).RegisterTransaction(ctx, req.(*RegisterTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _RefTransaction_StartTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StartTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RefTransactionServer).StartTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gitaly.RefTransaction/StartTransaction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RefTransactionServer).StartTransaction(ctx, req.(*StartTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _RefTransaction_CancelTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RefTransactionServer).CancelTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gitaly.RefTransaction/CancelTransaction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RefTransactionServer).CancelTransaction(ctx, req.(*CancelTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _RefTransaction_serviceDesc = grpc.ServiceDesc{ + ServiceName: "gitaly.RefTransaction", + HandlerType: (*RefTransactionServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterTransaction", + Handler: _RefTransaction_RegisterTransaction_Handler, + }, + { + MethodName: "StartTransaction", + Handler: _RefTransaction_StartTransaction_Handler, + }, + { + MethodName: "CancelTransaction", + Handler: _RefTransaction_CancelTransaction_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "transaction.proto", +} diff --git a/proto/transaction.proto b/proto/transaction.proto new file mode 100644 index 000000000..645833b2d --- /dev/null +++ b/proto/transaction.proto @@ -0,0 +1,72 @@ +syntax = "proto3"; + +package gitaly; + +option go_package = "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"; + +import "lint.proto"; +import "shared.proto"; + +service RefTransaction { + + rpc RegisterTransaction (RegisterTransactionRequest) returns (RegisterTransactionResponse) { + option (op_type) = { + op: MUTATOR + scope_level: REPOSITORY + }; + } + + rpc StartTransaction (StartTransactionRequest) returns (StartTransactionResponse) { + option (op_type) = { + op: MUTATOR + scope_level: REPOSITORY + }; + } + + rpc CancelTransaction (CancelTransactionRequest) returns (CancelTransactionResponse) { + option (op_type) = { + op: MUTATOR + scope_level: REPOSITORY + }; + } + +} + +message RegisterTransactionRequest { + Repository repository = 1[(target_repository)=true]; + // Nodes taking part in the transaction + repeated string nodes = 2; +} + +message RegisterTransactionResponse { + uint64 transaction_id = 1; +} + +message StartTransactionRequest { + Repository repository = 1[(target_repository)=true]; + // ID of the transaction we're processing + uint64 transaction_id = 2; + // Name of the Gitaly node that's starting a transaction. + string node = 3; + // SHA1 of the references that are to be updated + bytes reference_updates_hash = 4; +} + +message StartTransactionResponse { + // The outcome of the given transaction telling the client whether the + // transaction should be committed or rolled back. + enum TransactionState { + COMMIT = 0; + ABORT = 1; + } + + TransactionState state = 1; +} + +message CancelTransactionRequest { + Repository repository = 1[(target_repository)=true]; + // ID of the transaction we're about to cancel + uint64 transaction_id = 2; +} + +message CancelTransactionResponse {} diff --git a/ruby/proto/gitaly.rb b/ruby/proto/gitaly.rb index 8674ab879..9c80cea63 100644 --- a/ruby/proto/gitaly.rb +++ b/ruby/proto/gitaly.rb @@ -37,5 +37,7 @@ require 'gitaly/smarthttp_services_pb' require 'gitaly/ssh_services_pb' +require 'gitaly/transaction_services_pb' + require 'gitaly/wiki_services_pb' diff --git a/ruby/proto/gitaly/transaction_pb.rb b/ruby/proto/gitaly/transaction_pb.rb new file mode 100644 index 000000000..c3d9d0ad6 --- /dev/null +++ b/ruby/proto/gitaly/transaction_pb.rb @@ -0,0 +1,45 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: transaction.proto + +require 'google/protobuf' + +require 'lint_pb' +require 'shared_pb' +Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "gitaly.RegisterTransactionRequest" do + optional :repository, :message, 1, "gitaly.Repository" + repeated :nodes, :string, 2 + end + add_message "gitaly.RegisterTransactionResponse" do + optional :transaction_id, :uint64, 1 + end + add_message "gitaly.StartTransactionRequest" do + optional :repository, :message, 1, "gitaly.Repository" + optional :transaction_id, :uint64, 2 + optional :node, :string, 3 + optional :reference_updates_hash, :bytes, 4 + end + add_message "gitaly.StartTransactionResponse" do + optional :state, :enum, 1, "gitaly.StartTransactionResponse.TransactionState" + end + add_enum "gitaly.StartTransactionResponse.TransactionState" do + value :COMMIT, 0 + value :ABORT, 1 + end + add_message "gitaly.CancelTransactionRequest" do + optional :repository, :message, 1, "gitaly.Repository" + optional :transaction_id, :uint64, 2 + end + add_message "gitaly.CancelTransactionResponse" do + end +end + +module Gitaly + RegisterTransactionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.RegisterTransactionRequest").msgclass + RegisterTransactionResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.RegisterTransactionResponse").msgclass + StartTransactionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.StartTransactionRequest").msgclass + StartTransactionResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.StartTransactionResponse").msgclass + StartTransactionResponse::TransactionState = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.StartTransactionResponse.TransactionState").enummodule + CancelTransactionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CancelTransactionRequest").msgclass + CancelTransactionResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CancelTransactionResponse").msgclass +end diff --git a/ruby/proto/gitaly/transaction_services_pb.rb b/ruby/proto/gitaly/transaction_services_pb.rb new file mode 100644 index 000000000..b465426ec --- /dev/null +++ b/ruby/proto/gitaly/transaction_services_pb.rb @@ -0,0 +1,24 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# Source: transaction.proto for package 'gitaly' + +require 'grpc' +require 'transaction_pb' + +module Gitaly + module RefTransaction + class Service + + include GRPC::GenericService + + self.marshal_class_method = :encode + self.unmarshal_class_method = :decode + self.service_name = 'gitaly.RefTransaction' + + rpc :RegisterTransaction, RegisterTransactionRequest, RegisterTransactionResponse + rpc :StartTransaction, StartTransactionRequest, StartTransactionResponse + rpc :CancelTransaction, CancelTransactionRequest, CancelTransactionResponse + end + + Stub = Service.rpc_stub_class + end +end |