github.com/matrixorigin/matrixone@v0.7.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  // TxnSender is used to send transaction requests to the DN nodes.
    27  type TxnSender interface {
    28  	// Send send request to the specified DN node, and wait for response synchronously.
    29  	// For any reason, if no response is received, the internal will keep retrying until
    30  	// the Context times out.
    31  	Send(context.Context, []txn.TxnRequest) (*SendResult, error)
    32  	// Close the txn sender
    33  	Close() error
    34  }
    35  
    36  // TxnServer receives and processes txn requests from TxnSender.
    37  type TxnServer interface {
    38  	// Start start the txn server
    39  	Start() error
    40  	// Close the txn server
    41  	Close() error
    42  	// RegisterMethodHandler register txn request handler func
    43  	RegisterMethodHandler(txn.TxnMethod, TxnRequestHandleFunc)
    44  }
    45  
    46  // TxnRequestHandleFunc txn request handle func
    47  type TxnRequestHandleFunc func(context.Context, *txn.TxnRequest, *txn.TxnResponse) error
    48  
    49  // SenderOption option for create Sender
    50  type SenderOption func(*sender)
    51  
    52  // ServerOption option for create TxnServer
    53  type ServerOption func(*server)
    54  
    55  // LocalDispatch used to returns request handler on local, avoid rpc
    56  type LocalDispatch func(metadata.DNShard) TxnRequestHandleFunc
    57  
    58  // SendResult wrapping []txn.TxnResponse for reuse
    59  type SendResult struct {
    60  	Responses []txn.TxnResponse
    61  	streams   map[uint64]morpc.Stream
    62  	pool      *sync.Pool
    63  }