github.com/matrixorigin/matrixone@v1.2.0/pkg/txn/rpc/types.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rpc 16 17 import ( 18 "context" 19 "sync" 20 21 "github.com/matrixorigin/matrixone/pkg/common/morpc" 22 "github.com/matrixorigin/matrixone/pkg/pb/metadata" 23 "github.com/matrixorigin/matrixone/pkg/pb/txn" 24 ) 25 26 // Config config 27 type Config = morpc.Config 28 29 // TxnSender is used to send transaction requests to the TN nodes. 30 type TxnSender interface { 31 // Send send request to the specified TN node, and wait for response synchronously. 32 // For any reason, if no response is received, the internal will keep retrying until 33 // the Context times out. 34 Send(context.Context, []txn.TxnRequest) (*SendResult, error) 35 // Close the txn sender 36 Close() error 37 } 38 39 // TxnServer receives and processes txn requests from TxnSender. 40 type TxnServer interface { 41 // Start start the txn server 42 Start() error 43 // Close the txn server 44 Close() error 45 // RegisterMethodHandler register txn request handler func 46 RegisterMethodHandler(txn.TxnMethod, TxnRequestHandleFunc) 47 } 48 49 // TxnRequestHandleFunc txn request handle func 50 type TxnRequestHandleFunc func(context.Context, *txn.TxnRequest, *txn.TxnResponse) error 51 52 // SenderOption option for create Sender 53 type SenderOption func(*sender) 54 55 // ServerOption option for create TxnServer 56 type ServerOption func(*server) 57 58 // LocalDispatch used to returns request handler on local, avoid rpc 59 type LocalDispatch func(metadata.TNShard) TxnRequestHandleFunc 60 61 // SendResult wrapping []txn.TxnResponse for reuse 62 type SendResult struct { 63 Responses []txn.TxnResponse 64 streams map[uint64]morpc.Stream 65 pool *sync.Pool 66 }