txserializer

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package txserializer provides the vttablet hot row protection. See the TxSerializer struct for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoneFunc

type DoneFunc func()

DoneFunc is returned by Wait() and must be called by the caller.

type TxSerializer

type TxSerializer struct {
	*sync2.ConsolidatorCache
	// contains filtered or unexported fields
}

TxSerializer serializes incoming transactions which target the same row range i.e. table name and WHERE clause are identical. Additional transactions are queued and woken up in arrival order.

This implementation has some parallels to the sync2.Consolidator class. However, there are many substantial differences:

  • Results are not shared between queued transactions.
  • Only one waiting transaction and not all are notified when the current one has finished.
  • Waiting transactions are woken up in FIFO order.
  • Waiting transactions are unblocked if their context is done.
  • Both the local queue (per row range) and global queue (whole process) are limited to avoid that queued transactions can consume the full capacity of vttablet. This is important if the capaciy is finite. For example, the number of RPCs in flight could be limited by the RPC subsystem.

func New

func New(dryRun bool, maxQueueSize, maxGlobalQueueSize, concurrentTransactions int) *TxSerializer

New returns a TxSerializer object.

func (*TxSerializer) Pending

func (t *TxSerializer) Pending(key string) int

Pending returns the number of queued transactions (including the ones which are currently in flight.)

func (*TxSerializer) ServeHTTP

func (t *TxSerializer) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP lists the most recent, cached queries and their count.

func (*TxSerializer) Wait

func (t *TxSerializer) Wait(ctx context.Context, key, table string) (done DoneFunc, waited bool, err error)

Wait blocks if another transaction for the same range is already in flight. It returns when this transaction has its turn. "done" is != nil if err == nil and must be called once the transaction is done and the next waiting transaction can be unblocked. "waited" is true if Wait() had to wait for other transactions. "err" is not nil if a) the context is done or b) a queue limit was reached.

Jump to

Keyboard shortcuts

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