client

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DebugableTxnOperator added in v0.6.0

type DebugableTxnOperator interface {
	TxnOperator

	// Debug send debug request to DN, after use, SendResult needs to call the Release
	// method.
	Debug(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error)
}

DebugableTxnOperator debugable txn operator

type TxnClient

type TxnClient interface {
	// New returns a TxnOperator to handle read and write operation for a
	// transaction.
	New(options ...TxnOption) (TxnOperator, error)
	// NewWithSnapshot create a txn operator from a snapshot. The snapshot must
	// be from a CN coordinator txn operator.
	NewWithSnapshot(snapshot []byte) (TxnOperator, error)
	// Close closes client.sender
	Close() error
}

TxnClient transaction client, the operational entry point for transactions. Each CN node holds one instance of TxnClient.

func NewTxnClient

func NewTxnClient(
	rt runtime.Runtime,
	sender rpc.TxnSender,
	options ...TxnClientCreateOption) TxnClient

NewTxnClient create a txn client with TxnSender and Options

type TxnClientCreateOption

type TxnClientCreateOption func(*txnClient)

TxnClientCreateOption options for create txn

func WithTxnIDGenerator

func WithTxnIDGenerator(generator TxnIDGenerator) TxnClientCreateOption

WithTxnIDGenerator setup txn id generator

type TxnIDGenerator

type TxnIDGenerator interface {
	// Generate returns a unique transaction id
	Generate() []byte
}

TxnIDGenerator txn id generator

type TxnOperator

type TxnOperator interface {
	// Txn returns the current txn metadata
	Txn() txn.TxnMeta
	// Snapshot a snapshot of the transaction handle that can be passed around the
	// network. In some scenarios, operations of a transaction are executed on multiple
	// CN nodes for performance acceleration. But with only one CN coordinator, Snapshot
	// can be used to recover the transaction operation handle at a non-CN coordinator
	// node, or it can be used to pass information back to the transaction coordinator
	// after the non-CN coordinator completes the transaction operation.
	Snapshot() ([]byte, error)
	// ApplySnapshot CN coordinator applies a snapshot of the non-coordinator's transaction
	// operation information.
	ApplySnapshot(data []byte) error
	// Read transaction read operation, the operator routes the message based
	// on the given DN node information and waits for the read data synchronously.
	// The transaction has been aborted if ErrTxnAborted returned.
	// After use, SendResult needs to call the Release method
	Read(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error)
	// Write transaction write operation, and the operator will record the DN
	// nodes written by the current transaction, and when it finds that multiple
	// DN nodes are written, it will start distributed transaction processing.
	// The transaction has been aborted if ErrTxnAborted returned.
	// After use, SendResult needs to call the Release method
	Write(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error)
	// WriteAndCommit is similar to Write, but commit the transaction after write.
	// After use, SendResult needs to call the Release method
	WriteAndCommit(ctx context.Context, ops []txn.TxnRequest) (*rpc.SendResult, error)
	// Commit the transaction. If data has been written to multiple DN nodes, a
	// 2pc distributed transaction commit process is used.
	Commit(ctx context.Context) error
	// Rollback the transaction.
	Rollback(ctx context.Context) error
}

TxnOperator operator for transaction clients, handling read and write requests for transactions, and handling distributed transactions across DN nodes. Note: For Error returned by Read/Write/WriteAndCommit/Commit/Rollback, need to check if it is a moerr.ErrDNShardNotFound error, if so, the DN information held is out of date and needs to be reloaded by HAKeeper.

type TxnOption

type TxnOption func(*txnOperator)

TxnOption options for setup transaction

func WithSnapshotTS added in v0.7.0

func WithSnapshotTS(ts timestamp.Timestamp) TxnOption

WithSnapshotTS use a spec snapshot timestamp to build TxnOperator.

func WithTxnCNCoordinator

func WithTxnCNCoordinator() TxnOption

WithTxnCNCoordinator set cn txn coodinator

func WithTxnCacheWrite

func WithTxnCacheWrite() TxnOption

WithTxnCacheWrite Set cache write requests, after each Write call, the request will not be sent to the DN node immediately, but stored in the Coordinator's memory, and the Coordinator will choose the right time to send the cached requests. The following scenarios trigger the sending of requests to DN:

  1. Before read, because the Coordinator is not aware of the format and content of the written data, it is necessary to send the cached write requests to the corresponding DN node each time Read is called, used to implement "read your write".
  2. Before commit, obviously, the cached write requests needs to be sent to the corresponding DN node before commit.

func WithTxnDisable1PCOpt

func WithTxnDisable1PCOpt() TxnOption

WithTxnDisable1PCOpt disable 1pc optimisation on distributed transaction. By default, mo enables 1pc optimization for distributed transactions. For write operations, if all partitions' prepares are executed successfully, then the transaction is considered committed and returned directly to the client. Partitions' prepared data are committed asynchronously.

func WithTxnReadyOnly

func WithTxnReadyOnly() TxnOption

WithTxnReadyOnly setup readyonly flag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL