go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/txthrottler Index | Files

package txthrottler

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletserver/txthrottler"

Index

Package Files

tx_throttler.go

Constants

const TxThrottlerName = "TransactionThrottler"

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

type ThrottlerInterface Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

func (*TxThrottler) Throttle Uses

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.

Package txthrottler imports 12 packages (graph) and is imported by 1 packages. Updated 2019-06-13. Refresh now. Tools for package owners.