txthrottler

package
v3.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TxThrottlerName = "TransactionThrottler"

TxThrottlerName is the name the wrapped go/vt/throttler object will be registered with go/vt/throttler.GlobalManager.

Variables

This section is empty.

Functions

This section is empty.

Types

type ThrottlerInterface

type ThrottlerInterface interface {
	Throttle(threadID int) time.Duration
	ThreadFinished(threadID int)
	Close()
	MaxRate() int64
	SetMaxRate(rate int64)
	RecordReplicationLag(time time.Time, ts *discovery.TabletStats)
	GetConfiguration() *throttlerdatapb.Configuration
	UpdateConfiguration(configuration *throttlerdatapb.Configuration, copyZeroValues bool) error
	ResetConfiguration()
}

ThrottlerInterface defines the public interface that is implemented by go/vt/throttler.Throttler It is only used here to allow mocking out a throttler object.

type TopologyWatcherInterface

type TopologyWatcherInterface interface {
	WaitForInitialTopology() error
	Stop()
}

TopologyWatcherInterface defines the public interface that is implemented by discovery.TopologyWatcher. It is only used here to allow mocking out go/vt/discovery.TopologyWatcher.

type TxThrottler

type TxThrottler struct {
	// contains filtered or unexported fields
}

TxThrottler throttles transactions based on replication lag. It's a thin wrapper around the throttler found in vitess/go/vt/throttler. It uses a discovery.HealthCheck to send replication-lag updates to the wrapped throttler.

Intended Usage:

// Assuming topoServer is a topo.Server variable pointing to a Vitess topology server.
t := CreateTxThrottlerFromTabletConfig(topoServer)

// A transaction throttler must be opened before its first use:
if err := t.Open(keyspace, shard); err != nil {
  return err
}

// Checking whether to throttle can be done as follows before starting a transaction.
if t.Throttle() {
  return fmt.Errorf("Transaction throttled!")
} else {
  // execute transaction.
}

// To release the resources used by the throttler the caller should call Close().
t.Close()

A TxThrottler object is generally not thread-safe: at any given time at most one goroutine should be executing a method. The only exception is the 'Throttle' method where multiple goroutines are allowed to execute it concurrently.

func CreateTxThrottlerFromTabletConfig

func CreateTxThrottlerFromTabletConfig(topoServer *topo.Server) *TxThrottler

CreateTxThrottlerFromTabletConfig tries to construct a TxThrottler from the relevant fields in the tabletenv.Config object. It returns a disabled TxThrottler if any error occurs. This function calls tryCreateTxThrottler that does the actual creation work and returns an error if one occurred.

func (*TxThrottler) Close

func (t *TxThrottler) Close()

Close closes the TxThrottler object and releases resources. It should be called after the throttler is no longer needed. It's ok to call this method on a closed throttler--in which case the method does nothing.

func (*TxThrottler) Open

func (t *TxThrottler) Open(keyspace, shard string) error

Open opens the transaction throttler. It must be called prior to 'Throttle'.

func (*TxThrottler) Throttle

func (t *TxThrottler) Throttle() (result bool)

Throttle should be called before a new transaction is started. It returns true if the transaction should not proceed (the caller should back off). Throttle requires that Open() was previously called successfuly.

Jump to

Keyboard shortcuts

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