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

package tabletserver

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

Index

Package Files

codex.go controller.go query_engine.go query_executor.go query_list.go querylogz.go queryz.go replication_watcher.go status.go stream_queryz.go tabletserver.go twopc.go twopcz.go tx_engine.go tx_executor.go tx_pool.go tx_prep_pool.go txlogz.go

Constants

const (
    // StateNotConnected is the state where tabletserver is not
    // connected to an underlying mysql instance.
    StateNotConnected = iota
    // StateNotServing is the state where tabletserver is connected
    // to an underlying mysql instance, but is not serving queries.
    StateNotServing
    // StateServing is where queries are allowed.
    StateServing
    // StateTransitioning is a transient state indicating that
    // the tabletserver is tranisitioning to a new state.
    // In order to achieve clean transitions, no requests are
    // allowed during this state.
    StateTransitioning
    // StateShuttingDown indicates that the tabletserver
    // is shutting down. In this state, we wait for outstanding
    // requests and transactions to conclude.
    StateShuttingDown
)
const (

    // RedoStateFailed represents the Failed state for redo_state.
    RedoStateFailed = 0
    // RedoStatePrepared represents the Prepared state for redo_state.
    RedoStatePrepared = 1

    // DTStatePrepare represents the PREPARE state for dt_state.
    DTStatePrepare = querypb.TransactionState_PREPARE
    // DTStateCommit represents the COMMIT state for dt_state.
    DTStateCommit = querypb.TransactionState_COMMIT
    // DTStateRollback represents the ROLLBACK state for dt_state.
    DTStateRollback = querypb.TransactionState_ROLLBACK
)
const (
    NotServing txEngineState = iota
    Transitioning
    AcceptingReadAndWrite
    AcceptingReadOnly
)

The TxEngine can be in any of these states

const (
    TxClose    = "close"
    TxCommit   = "commit"
    TxRollback = "rollback"
    TxPrepare  = "prepare"
    TxKill     = "kill"
)

These consts identify how a transaction was resolved.

Variables

var RegisterFunctions []RegisterFunction

RegisterFunctions is a list of all the RegisterFunction that will be called upon Register() on a TabletServer

type Controller Uses

type Controller interface {
    // Register registers this query service with the RPC layer.
    Register()
    // AddStatusPart adds the status part to the status page
    AddStatusPart()

    // InitDBConfig sets up the db config vars.
    InitDBConfig(querypb.Target, *dbconfigs.DBConfigs) error

    // SetServingType transitions the query service to the required serving type.
    // Returns true if the state of QueryService or the tablet type changed.
    SetServingType(tabletType topodatapb.TabletType, serving bool, alsoAllow []topodatapb.TabletType) (bool, error)

    // EnterLameduck causes tabletserver to enter the lameduck state.
    EnterLameduck()

    // IsServing returns true if the query service is running
    IsServing() bool

    // IsHealthy returns the health status of the QueryService
    IsHealthy() error

    // ClearQueryPlanCache clears internal query plan cache
    ClearQueryPlanCache()

    // ReloadSchema makes the quey service reload its schema cache
    ReloadSchema(ctx context.Context) error

    // RegisterQueryRuleSource adds a query rule source
    RegisterQueryRuleSource(ruleSource string)

    // RegisterQueryRuleSource removes a query rule source
    UnRegisterQueryRuleSource(ruleSource string)

    // SetQueryRules sets the query rules for this QueryService
    SetQueryRules(ruleSource string, qrs *rules.Rules) error

    // QueryService returns the QueryService object used by this Controller
    QueryService() queryservice.QueryService

    // SchemaEngine returns the SchemaEngine object used by this Controller
    SchemaEngine() *schema.Engine

    // BroadcastHealth sends the current health to all listeners
    BroadcastHealth(terTimestamp int64, stats *querypb.RealtimeStats, maxCache time.Duration)

    // HeartbeatLag returns the current lag as calculated by the heartbeat
    // package, if heartbeat is enabled. Otherwise returns 0.
    HeartbeatLag() (time.Duration, error)

    // TopoServer returns the topo server.
    TopoServer() *topo.Server
}

Controller defines the control interface for TabletServer.

type DistributedTx Uses

type DistributedTx struct {
    Dtid         string
    State        string
    Created      time.Time
    Participants []querypb.Target
}

DistributedTx is similar to querypb.TransactionMetadata, but is display friendly.

type PreparedTx Uses

type PreparedTx struct {
    Dtid    string
    Queries []string
    Time    time.Time
}

PreparedTx represents a displayable version of a prepared transaction.

type QueryDetail Uses

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

QueryDetail is a simple wrapper for Query, Context and a killable conn.

func NewQueryDetail Uses

func NewQueryDetail(ctx context.Context, conn killable) *QueryDetail

NewQueryDetail creates a new QueryDetail

type QueryDetailzRow Uses

type QueryDetailzRow struct {
    Query             string
    ContextHTML       template.HTML
    Start             time.Time
    Duration          time.Duration
    ConnID            int64
    State             string
    ShowTerminateLink bool
}

QueryDetailzRow is used for rendering QueryDetail in a template

type QueryEngine Uses

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

QueryEngine implements the core functionality of tabletserver. It assumes that no requests will be sent to it before Open is called and succeeds. Shutdown is done in the following order:

Close: There should be no more pending queries when this function is called.

func NewQueryEngine Uses

func NewQueryEngine(checker connpool.MySQLChecker, se *schema.Engine, config tabletenv.TabletConfig) *QueryEngine

NewQueryEngine creates a new QueryEngine. This is a singleton class. You must call this only once.

func (*QueryEngine) AddStats Uses

func (qe *QueryEngine) AddStats(planName, tableName string, queryCount int64, duration, mysqlTime time.Duration, rowCount, errorCount int64)

AddStats adds the given stats for the planName.tableName

func (*QueryEngine) ClearQueryPlanCache Uses

func (qe *QueryEngine) ClearQueryPlanCache()

ClearQueryPlanCache should be called if query plan cache is potentially obsolete

func (*QueryEngine) Close Uses

func (qe *QueryEngine) Close()

Close must be called to shut down QueryEngine. You must ensure that no more queries will be sent before calling Close.

func (*QueryEngine) GetMessageStreamPlan Uses

func (qe *QueryEngine) GetMessageStreamPlan(name string) (*TabletPlan, error)

GetMessageStreamPlan builds a plan for Message streaming.

func (*QueryEngine) GetPlan Uses

func (qe *QueryEngine) GetPlan(ctx context.Context, logStats *tabletenv.LogStats, sql string, skipQueryPlanCache bool) (*TabletPlan, error)

GetPlan returns the TabletPlan that for the query. Plans are cached in a cache.LRUCache.

func (*QueryEngine) GetStreamPlan Uses

func (qe *QueryEngine) GetStreamPlan(sql string) (*TabletPlan, error)

GetStreamPlan is similar to GetPlan, but doesn't use the cache and doesn't enforce a limit. It just returns the parsed query.

func (*QueryEngine) InitDBConfig Uses

func (qe *QueryEngine) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Open.

func (*QueryEngine) IsMySQLReachable Uses

func (qe *QueryEngine) IsMySQLReachable() bool

IsMySQLReachable returns true if we can connect to MySQL.

func (*QueryEngine) Open Uses

func (qe *QueryEngine) Open() error

Open must be called before sending requests to QueryEngine.

func (*QueryEngine) QueryPlanCacheCap Uses

func (qe *QueryEngine) QueryPlanCacheCap() int

QueryPlanCacheCap returns the capacity of the query cache.

func (*QueryEngine) ServeHTTP Uses

func (qe *QueryEngine) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*QueryEngine) SetQueryPlanCacheCap Uses

func (qe *QueryEngine) SetQueryPlanCacheCap(size int)

SetQueryPlanCacheCap sets the query plan cache capacity.

type QueryExecutor Uses

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

QueryExecutor is used for executing a query request.

func (*QueryExecutor) Execute Uses

func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error)

Execute performs a non-streaming query execution.

func (*QueryExecutor) MessageStream Uses

func (qre *QueryExecutor) MessageStream(callback func(*sqltypes.Result) error) error

MessageStream streams messages from a message table.

func (*QueryExecutor) Stream Uses

func (qre *QueryExecutor) Stream(callback func(*sqltypes.Result) error) error

Stream performs a streaming query execution.

type QueryList Uses

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

QueryList holds a thread safe list of QueryDetails

func NewQueryList Uses

func NewQueryList() *QueryList

NewQueryList creates a new QueryList

func (*QueryList) Add Uses

func (ql *QueryList) Add(qd *QueryDetail)

Add adds a QueryDetail to QueryList

func (*QueryList) GetQueryzRows Uses

func (ql *QueryList) GetQueryzRows() []QueryDetailzRow

GetQueryzRows returns a list of QueryDetailzRow sorted by start time

func (*QueryList) Remove Uses

func (ql *QueryList) Remove(qd *QueryDetail)

Remove removes a QueryDetail from QueryList

func (*QueryList) Terminate Uses

func (ql *QueryList) Terminate(connID int64) error

Terminate updates the query status and kills the connection

func (*QueryList) TerminateAll Uses

func (ql *QueryList) TerminateAll()

TerminateAll terminates all queries and kills the MySQL connections

type QueryStats Uses

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

QueryStats tracks query stats for export per planName/tableName

type RegisterFunction Uses

type RegisterFunction func(Controller)

RegisterFunction is a callback type to be called when we Register() a TabletServer

type ReplicationWatcher Uses

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

ReplicationWatcher is a tabletserver service that watches the replication stream. It can tell you the current event token, and it will trigger schema reloads if a DDL is encountered.

func NewReplicationWatcher Uses

func NewReplicationWatcher(se *schema.Engine, config tabletenv.TabletConfig) *ReplicationWatcher

NewReplicationWatcher creates a new ReplicationWatcher.

func (*ReplicationWatcher) Close Uses

func (rpw *ReplicationWatcher) Close()

Close stops the ReplicationWatcher service.

func (*ReplicationWatcher) ComputeExtras Uses

func (rpw *ReplicationWatcher) ComputeExtras(options *querypb.ExecuteOptions) *querypb.ResultExtras

ComputeExtras returns the requested ResultExtras based on the supplied options.

func (*ReplicationWatcher) EventToken Uses

func (rpw *ReplicationWatcher) EventToken() *querypb.EventToken

EventToken returns the current event token.

func (*ReplicationWatcher) InitDBConfig Uses

func (rpw *ReplicationWatcher) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Open.

func (*ReplicationWatcher) Open Uses

func (rpw *ReplicationWatcher) Open()

Open starts the ReplicationWatcher service.

func (*ReplicationWatcher) Process Uses

func (rpw *ReplicationWatcher) Process(ctx context.Context, dbconfigs *dbconfigs.DBConfigs)

Process processes the replication stream.

type TabletPlan Uses

type TabletPlan struct {
    *planbuilder.Plan
    Fields     []*querypb.Field
    Rules      *rules.Rules
    Authorized []*tableacl.ACLResult

    QueryCount int64
    Time       time.Duration
    MysqlTime  time.Duration
    RowCount   int64
    ErrorCount int64
    // contains filtered or unexported fields
}

TabletPlan wraps the planbuilder's exec plan to enforce additional rules and track stats.

func (*TabletPlan) AddStats Uses

func (ep *TabletPlan) AddStats(queryCount int64, duration, mysqlTime time.Duration, rowCount, errorCount int64)

AddStats updates the stats for the current TabletPlan.

func (*TabletPlan) Size Uses

func (*TabletPlan) Size() int

Size allows TabletPlan to be in cache.LRUCache.

func (*TabletPlan) Stats Uses

func (ep *TabletPlan) Stats() (queryCount int64, duration, mysqlTime time.Duration, rowCount, errorCount int64)

Stats returns the current stats of TabletPlan.

type TabletServer Uses

type TabletServer struct {
    QueryTimeout sync2.AtomicDuration
    BeginTimeout sync2.AtomicDuration
    TerseErrors  bool
    // contains filtered or unexported fields
}

TabletServer implements the RPC interface for the query service. TabletServer is initialized in the following sequence: NewTabletServer->InitDBConfig->SetServingType. Subcomponents of TabletServer are initialized using one of the following sequences: New->InitDBConfig->Init->Open, or New->InitDBConfig->Open. Essentially, InitDBConfig is a continuation of New. However, the db config is not initially available. For this reason, the initialization is done in two phases. Some subcomponents have Init functions. Such functions usually perform one-time initializations like creating metadata tables in the sidecar database. These functions must be idempotent. Open and Close can be called repeatedly during the lifetime of a subcomponent. These should also be idempotent.

func NewServer Uses

func NewServer(topoServer *topo.Server, alias topodatapb.TabletAlias) *TabletServer

NewServer creates a new TabletServer based on the command line flags.

func NewTabletServer Uses

func NewTabletServer(config tabletenv.TabletConfig, topoServer *topo.Server, alias topodatapb.TabletAlias) *TabletServer

NewTabletServer creates an instance of TabletServer. Only the first instance of TabletServer will expose its state variables.

func NewTabletServerWithNilTopoServer Uses

func NewTabletServerWithNilTopoServer(config tabletenv.TabletConfig) *TabletServer

NewTabletServerWithNilTopoServer is typically used in tests that don't need a topoServer member.

func (*TabletServer) AddStatusPart Uses

func (tsv *TabletServer) AddStatusPart()

AddStatusPart registers the status part for the status page.

func (*TabletServer) Begin Uses

func (tsv *TabletServer) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (transactionID int64, err error)

Begin starts a new transaction. This is allowed only if the state is StateServing.

func (*TabletServer) BeginExecute Uses

func (tsv *TabletServer) BeginExecute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error)

BeginExecute combines Begin and Execute.

func (*TabletServer) BeginExecuteBatch Uses

func (tsv *TabletServer) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, error)

BeginExecuteBatch combines Begin and ExecuteBatch.

func (*TabletServer) BroadcastHealth Uses

func (tsv *TabletServer) BroadcastHealth(terTimestamp int64, stats *querypb.RealtimeStats, maxCache time.Duration)

BroadcastHealth will broadcast the current health to all listeners

func (*TabletServer) CheckMySQL Uses

func (tsv *TabletServer) CheckMySQL()

CheckMySQL initiates a check to see if MySQL is reachable. If not, it shuts down the query service. The check is rate-limited to no more than once per second.

func (*TabletServer) ClearQueryPlanCache Uses

func (tsv *TabletServer) ClearQueryPlanCache()

ClearQueryPlanCache clears internal query plan cache

func (*TabletServer) Close Uses

func (tsv *TabletServer) Close(ctx context.Context) error

Close is a no-op.

func (*TabletServer) Commit Uses

func (tsv *TabletServer) Commit(ctx context.Context, target *querypb.Target, transactionID int64) (err error)

Commit commits the specified transaction.

func (*TabletServer) CommitPrepared Uses

func (tsv *TabletServer) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error)

CommitPrepared commits the prepared transaction.

func (*TabletServer) ConcludeTransaction Uses

func (tsv *TabletServer) ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error)

ConcludeTransaction deletes the 2pc transaction metadata essentially resolving it.

func (*TabletServer) CreateTransaction Uses

func (tsv *TabletServer) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error)

CreateTransaction creates the metadata for a 2PC transaction.

func (*TabletServer) EnterLameduck Uses

func (tsv *TabletServer) EnterLameduck()

EnterLameduck causes tabletserver to enter the lameduck state. This state causes health checks to fail, but the behavior of tabletserver otherwise remains the same. Any subsequent calls to SetServingType will cause the tabletserver to exit this mode.

func (*TabletServer) Execute Uses

func (tsv *TabletServer) Execute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (result *sqltypes.Result, err error)

Execute executes the query and returns the result as response.

func (*TabletServer) ExecuteBatch Uses

func (tsv *TabletServer) ExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, transactionID int64, options *querypb.ExecuteOptions) (results []sqltypes.Result, err error)

ExecuteBatch executes a group of queries and returns their results as a list. ExecuteBatch can be called for an existing transaction, or it can be called with the AsTransaction flag which will execute all statements inside an independent transaction. If AsTransaction is true, TransactionId must be 0.

func (*TabletServer) ExitLameduck Uses

func (tsv *TabletServer) ExitLameduck()

ExitLameduck causes the tabletserver to exit the lameduck mode.

func (*TabletServer) GetQueryPoolTimeout Uses

func (tsv *TabletServer) GetQueryPoolTimeout() time.Duration

GetQueryPoolTimeout returns the timeout to get a connection from the query pool This function should only be used for testing.

func (*TabletServer) GetQueryPoolWaiterCap Uses

func (tsv *TabletServer) GetQueryPoolWaiterCap() int64

GetQueryPoolWaiterCap returns the limit on the number of queries that can be waiting for a connection from the pool This function should only be used for testing.

func (*TabletServer) GetState Uses

func (tsv *TabletServer) GetState() string

GetState returns the name of the current TabletServer state.

func (*TabletServer) GetTxPoolWaiterCap Uses

func (tsv *TabletServer) GetTxPoolWaiterCap() int64

GetTxPoolWaiterCap returns the limit on the number of queries that can be waiting for a connection from the pool This function should only be used for testing.

func (*TabletServer) HandlePanic Uses

func (tsv *TabletServer) HandlePanic(err *error)

HandlePanic is part of the queryservice.QueryService interface

func (*TabletServer) HeartbeatLag Uses

func (tsv *TabletServer) HeartbeatLag() (time.Duration, error)

HeartbeatLag returns the current lag as calculated by the heartbeat package, if heartbeat is enabled. Otherwise returns 0.

func (*TabletServer) InitACL Uses

func (tsv *TabletServer) InitACL(tableACLConfigFile string, enforceTableACLConfig bool)

InitACL loads the table ACL and sets up a SIGHUP handler for reloading it.

func (*TabletServer) InitDBConfig Uses

func (tsv *TabletServer) InitDBConfig(target querypb.Target, dbcfgs *dbconfigs.DBConfigs) error

InitDBConfig initializes the db config variables for TabletServer. You must call this function before calling SetServingType.

func (*TabletServer) IsHealthy Uses

func (tsv *TabletServer) IsHealthy() error

IsHealthy returns nil for non-serving types or if the query service is healthy (able to connect to the database and serving traffic), or an error explaining the unhealthiness otherwise.

func (*TabletServer) IsServing Uses

func (tsv *TabletServer) IsServing() bool

IsServing returns true if TabletServer is in SERVING state.

func (*TabletServer) MaxDMLRows Uses

func (tsv *TabletServer) MaxDMLRows() int

MaxDMLRows returns the max result size.

func (*TabletServer) MaxResultSize Uses

func (tsv *TabletServer) MaxResultSize() int

MaxResultSize returns the max result size.

func (*TabletServer) MessageAck Uses

func (tsv *TabletServer) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error)

MessageAck acks the list of messages for a given message table. It returns the number of messages successfully acked.

func (*TabletServer) MessageStream Uses

func (tsv *TabletServer) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error)

MessageStream streams messages from the requested table.

func (*TabletServer) PoolSize Uses

func (tsv *TabletServer) PoolSize() int

PoolSize returns the pool size.

func (*TabletServer) PostponeMessages Uses

func (tsv *TabletServer) PostponeMessages(ctx context.Context, target *querypb.Target, name string, ids []string) (count int64, err error)

PostponeMessages postpones the list of messages for a given message table. It returns the number of messages successfully postponed.

func (*TabletServer) Prepare Uses

func (tsv *TabletServer) Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)

Prepare prepares the specified transaction.

func (*TabletServer) PurgeMessages Uses

func (tsv *TabletServer) PurgeMessages(ctx context.Context, target *querypb.Target, name string, timeCutoff int64) (count int64, err error)

PurgeMessages purges messages older than specified time in Unix Nanoseconds. It purges at most 500 messages. It returns the number of messages successfully purged.

func (*TabletServer) QueryPlanCacheCap Uses

func (tsv *TabletServer) QueryPlanCacheCap() int

QueryPlanCacheCap returns the pool size.

func (*TabletServer) QueryService Uses

func (tsv *TabletServer) QueryService() queryservice.QueryService

QueryService returns the QueryService part of TabletServer.

func (*TabletServer) ReadTransaction Uses

func (tsv *TabletServer) ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error)

ReadTransaction returns the metadata for the sepcified dtid.

func (*TabletServer) Register Uses

func (tsv *TabletServer) Register()

Register prepares TabletServer for serving by calling all the registrations functions.

func (*TabletServer) RegisterQueryRuleSource Uses

func (tsv *TabletServer) RegisterQueryRuleSource(ruleSource string)

RegisterQueryRuleSource registers ruleSource for setting query rules.

func (*TabletServer) ReloadSchema Uses

func (tsv *TabletServer) ReloadSchema(ctx context.Context) error

ReloadSchema reloads the schema.

func (*TabletServer) Rollback Uses

func (tsv *TabletServer) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (err error)

Rollback rollsback the specified transaction.

func (*TabletServer) RollbackPrepared Uses

func (tsv *TabletServer) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error)

RollbackPrepared commits the prepared transaction.

func (*TabletServer) SchemaEngine Uses

func (tsv *TabletServer) SchemaEngine() *schema.Engine

SchemaEngine returns the SchemaEngine part of TabletServer.

func (*TabletServer) SetAllowUnsafeDMLs Uses

func (tsv *TabletServer) SetAllowUnsafeDMLs(val bool)

SetAllowUnsafeDMLs changes the setting to allow unsafe DML statements in SBR mode. It should be used only on initialization or for testing.

func (*TabletServer) SetAutoCommit Uses

func (tsv *TabletServer) SetAutoCommit(auto bool)

SetAutoCommit sets autocommit on or off. This function should only be used for testing.

func (*TabletServer) SetConsolidatorEnabled Uses

func (tsv *TabletServer) SetConsolidatorEnabled(enabled bool)

SetConsolidatorEnabled (true) will enable the query consolidator. SetConsolidatorEnabled (false) will disable the query consolidator. This function should only be used for testing.

func (*TabletServer) SetMaxDMLRows Uses

func (tsv *TabletServer) SetMaxDMLRows(val int)

SetMaxDMLRows changes the max result size to the specified value. This function should only be used for testing.

func (*TabletServer) SetMaxResultSize Uses

func (tsv *TabletServer) SetMaxResultSize(val int)

SetMaxResultSize changes the max result size to the specified value. This function should only be used for testing.

func (*TabletServer) SetPassthroughDMLs Uses

func (tsv *TabletServer) SetPassthroughDMLs(val bool)

SetPassthroughDMLs changes the setting to pass through all DMLs It should only be used for testing

func (*TabletServer) SetPoolSize Uses

func (tsv *TabletServer) SetPoolSize(val int)

SetPoolSize changes the pool size to the specified value. This function should only be used for testing.

func (*TabletServer) SetQueryPlanCacheCap Uses

func (tsv *TabletServer) SetQueryPlanCacheCap(val int)

SetQueryPlanCacheCap changes the pool size to the specified value. This function should only be used for testing.

func (*TabletServer) SetQueryPoolTimeout Uses

func (tsv *TabletServer) SetQueryPoolTimeout(val time.Duration)

SetQueryPoolTimeout changes the timeout to get a connection from the query pool This function should only be used for testing.

func (*TabletServer) SetQueryPoolWaiterCap Uses

func (tsv *TabletServer) SetQueryPoolWaiterCap(val int64)

SetQueryPoolWaiterCap changes the limit on the number of queries that can be waiting for a connection from the pool This function should only be used for testing.

func (*TabletServer) SetQueryRules Uses

func (tsv *TabletServer) SetQueryRules(ruleSource string, qrs *rules.Rules) error

SetQueryRules sets the query rules for a registered ruleSource.

func (*TabletServer) SetRollback Uses

func (tsv *TabletServer) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)

SetRollback transitions the 2pc transaction to the Rollback state. If a transaction id is provided, that transaction is also rolled back.

func (*TabletServer) SetServingType Uses

func (tsv *TabletServer) SetServingType(tabletType topodatapb.TabletType, serving bool, alsoAllow []topodatapb.TabletType) (stateChanged bool, err error)

SetServingType changes the serving type of the tabletserver. It starts or stops internal services as deemed necessary. The tabletType determines the primary serving type, while alsoAllow specifies other tablet types that should also be honored for serving. Returns true if the state of QueryService or the tablet type changed.

func (*TabletServer) SetStreamPoolSize Uses

func (tsv *TabletServer) SetStreamPoolSize(val int)

SetStreamPoolSize changes the pool size to the specified value. This function should only be used for testing.

func (*TabletServer) SetTxPoolSize Uses

func (tsv *TabletServer) SetTxPoolSize(val int)

SetTxPoolSize changes the tx pool size to the specified value. This function should only be used for testing.

func (*TabletServer) SetTxPoolWaiterCap Uses

func (tsv *TabletServer) SetTxPoolWaiterCap(val int64)

SetTxPoolWaiterCap changes the limit on the number of queries that can be waiting for a connection from the pool This function should only be used for testing.

func (*TabletServer) SetTxTimeout Uses

func (tsv *TabletServer) SetTxTimeout(val time.Duration)

SetTxTimeout changes the transaction timeout to the specified value. This function should only be used for testing.

func (*TabletServer) SetWarnResultSize Uses

func (tsv *TabletServer) SetWarnResultSize(val int)

SetWarnResultSize changes the warn result size to the specified value. This function should only be used for testing.

func (*TabletServer) SplitQuery Uses

func (tsv *TabletServer) SplitQuery(
    ctx context.Context,
    target *querypb.Target,
    query *querypb.BoundQuery,
    splitColumns []string,
    splitCount int64,
    numRowsPerQueryPart int64,
    algorithm querypb.SplitQueryRequest_Algorithm,
) (splits []*querypb.QuerySplit, err error)

SplitQuery splits a query + bind variables into smaller queries that return a subset of rows from the original query. This is the new version that supports multiple split columns and multiple split algortihms. See the documentation of SplitQueryRequest in proto/vtgate.proto for more details.

func (*TabletServer) StartCommit Uses

func (tsv *TabletServer) StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)

StartCommit atomically commits the transaction along with the decision to commit the associated 2pc transaction.

func (*TabletServer) StartService Uses

func (tsv *TabletServer) StartService(target querypb.Target, dbcfgs *dbconfigs.DBConfigs) (err error)

StartService is a convenience function for InitDBConfig->SetServingType with serving=true.

func (*TabletServer) StopService Uses

func (tsv *TabletServer) StopService()

StopService shuts down the tabletserver to the uninitialized state. It first transitions to StateShuttingDown, then waits for active services to shut down. Then it shuts down QueryEngine. This function should be called before process termination, or if MySQL is unreachable. Under normal circumstances, SetServingType should be called, which will keep QueryEngine open.

func (*TabletServer) StreamExecute Uses

func (tsv *TabletServer) StreamExecute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (err error)

StreamExecute executes the query and streams the result. The first QueryResult will have Fields set (and Rows nil). The subsequent QueryResult will have Rows set (and Fields nil).

func (*TabletServer) StreamHealth Uses

func (tsv *TabletServer) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error

StreamHealth streams the health status to callback. At the beginning, if TabletServer has a valid health state, that response is immediately sent.

func (*TabletServer) StreamPoolSize Uses

func (tsv *TabletServer) StreamPoolSize() int

StreamPoolSize returns the pool size.

func (*TabletServer) TopoServer Uses

func (tsv *TabletServer) TopoServer() *topo.Server

TopoServer returns the topo server.

func (*TabletServer) TxPoolSize Uses

func (tsv *TabletServer) TxPoolSize() int

TxPoolSize returns the tx pool size.

func (*TabletServer) TxTimeout Uses

func (tsv *TabletServer) TxTimeout() time.Duration

TxTimeout returns the transaction timeout.

func (*TabletServer) UnRegisterQueryRuleSource Uses

func (tsv *TabletServer) UnRegisterQueryRuleSource(ruleSource string)

UnRegisterQueryRuleSource unregisters ruleSource from query rules.

func (*TabletServer) UpdateStream Uses

func (tsv *TabletServer) UpdateStream(ctx context.Context, target *querypb.Target, position string, timestamp int64, callback func(*querypb.StreamEvent) error) error

UpdateStream streams binlog events.

func (*TabletServer) VStream Uses

func (tsv *TabletServer) VStream(ctx context.Context, target *querypb.Target, startPos string, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error

VStream streams VReplication events.

func (*TabletServer) VStreamRows Uses

func (tsv *TabletServer) VStreamRows(ctx context.Context, target *querypb.Target, query string, lastpk *querypb.QueryResult, send func(*binlogdatapb.VStreamRowsResponse) error) error

VStreamRows streams rows from the specified starting point.

func (*TabletServer) WarnResultSize Uses

func (tsv *TabletServer) WarnResultSize() int

WarnResultSize returns the warn result size.

type TwoPC Uses

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

TwoPC performs 2PC metadata management (MM) functions.

func NewTwoPC Uses

func NewTwoPC(readPool *connpool.Pool) *TwoPC

NewTwoPC creates a TwoPC variable.

func (*TwoPC) Close Uses

func (tpc *TwoPC) Close()

Close closes the TwoPC service.

func (*TwoPC) CountUnresolvedRedo Uses

func (tpc *TwoPC) CountUnresolvedRedo(ctx context.Context, unresolvedTime time.Time) (int64, error)

CountUnresolvedRedo returns the number of prepared transactions that are still unresolved.

func (*TwoPC) CreateTransaction Uses

func (tpc *TwoPC) CreateTransaction(ctx context.Context, conn *TxConnection, dtid string, participants []*querypb.Target) error

CreateTransaction saves the metadata of a 2pc transaction as Prepared.

func (*TwoPC) DeleteRedo Uses

func (tpc *TwoPC) DeleteRedo(ctx context.Context, conn *TxConnection, dtid string) error

DeleteRedo deletes the redo log for the dtid.

func (*TwoPC) DeleteTransaction Uses

func (tpc *TwoPC) DeleteTransaction(ctx context.Context, conn *TxConnection, dtid string) error

DeleteTransaction deletes the metadata for the specified transaction.

func (*TwoPC) Init Uses

func (tpc *TwoPC) Init(sidecarDBName string, dbaparams *mysql.ConnParams) error

Init initializes TwoPC. If the metadata database or tables are not present, they are created.

func (*TwoPC) Open Uses

func (tpc *TwoPC) Open(dbconfigs *dbconfigs.DBConfigs)

Open starts the TwoPC service.

func (*TwoPC) ReadAbandoned Uses

func (tpc *TwoPC) ReadAbandoned(ctx context.Context, abandonTime time.Time) (map[string]time.Time, error)

ReadAbandoned returns the list of abandoned transactions and their associated start time.

func (*TwoPC) ReadAllRedo Uses

func (tpc *TwoPC) ReadAllRedo(ctx context.Context) (prepared, failed []*PreparedTx, err error)

ReadAllRedo returns all the prepared transactions from the redo logs.

func (*TwoPC) ReadAllTransactions Uses

func (tpc *TwoPC) ReadAllTransactions(ctx context.Context) ([]*DistributedTx, error)

ReadAllTransactions returns info about all distributed transactions.

func (*TwoPC) ReadTransaction Uses

func (tpc *TwoPC) ReadTransaction(ctx context.Context, dtid string) (*querypb.TransactionMetadata, error)

ReadTransaction returns the metadata for the transaction.

func (*TwoPC) SaveRedo Uses

func (tpc *TwoPC) SaveRedo(ctx context.Context, conn *TxConnection, dtid string, queries []string) error

SaveRedo saves the statements in the redo log using the supplied connection.

func (*TwoPC) Transition Uses

func (tpc *TwoPC) Transition(ctx context.Context, conn *TxConnection, dtid string, state querypb.TransactionState) error

Transition performs a transition from Prepare to the specified state. If the transaction is not a in the Prepare state, an error is returned.

func (*TwoPC) UpdateRedo Uses

func (tpc *TwoPC) UpdateRedo(ctx context.Context, conn *TxConnection, dtid string, state int) error

UpdateRedo changes the state of the redo log for the dtid.

type TxConnection Uses

type TxConnection struct {
    *connpool.DBConn
    TransactionID int64

    StartTime         time.Time
    EndTime           time.Time
    Queries           []string
    NewMessages       map[string][]*messager.MessageRow
    ChangedMessages   map[string][]string
    Conclusion        string
    LogToFile         sync2.AtomicInt32
    ImmediateCallerID *querypb.VTGateCallerID
    EffectiveCallerID *vtrpcpb.CallerID
    Autocommit        bool
    // contains filtered or unexported fields
}

TxConnection is meant for executing transactions. It can return itself to the tx pool correctly. It also does not retry statements if there are failures.

func (*TxConnection) BeginAgain Uses

func (txc *TxConnection) BeginAgain(ctx context.Context) error

BeginAgain commits the existing transaction and begins a new one

func (*TxConnection) EventTime Uses

func (txc *TxConnection) EventTime() time.Time

EventTime returns the time the event was created.

func (*TxConnection) Exec Uses

func (txc *TxConnection) Exec(ctx context.Context, query string, maxrows int, wantfields bool) (*sqltypes.Result, error)

Exec executes the statement for the current transaction.

func (*TxConnection) Format Uses

func (txc *TxConnection) Format(params url.Values) string

Format returns a printable version of the connection info.

func (*TxConnection) RecordQuery Uses

func (txc *TxConnection) RecordQuery(query string)

RecordQuery records the query against this transaction.

func (*TxConnection) Recycle Uses

func (txc *TxConnection) Recycle()

Recycle returns the connection to the pool. The transaction remains active.

type TxEngine Uses

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

TxEngine is responsible for handling the tx-pool and keeping read-write, read-only or not-serving states. It will start and shut down the underlying tx-pool as required. It does this in a concurrently safe way.

func NewTxEngine Uses

func NewTxEngine(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *TxEngine

NewTxEngine creates a new TxEngine.

func (*TxEngine) AcceptReadOnly Uses

func (te *TxEngine) AcceptReadOnly() error

AcceptReadOnly will start accepting read-only transactions, but not full read and write transactions. If the engine is currently accepting full read and write transactions, they need to be rolled back.

func (*TxEngine) AcceptReadWrite Uses

func (te *TxEngine) AcceptReadWrite() error

AcceptReadWrite will start accepting all transactions. If transitioning from RO mode, transactions might need to be rolled back before new transactions can be accepts.

func (*TxEngine) Begin Uses

func (te *TxEngine) Begin(ctx context.Context, options *querypb.ExecuteOptions) (int64, string, error)

Begin begins a transaction, and returns the associated transaction id and the statement(s) used to execute the begin (if any).

Subsequent statements can access the connection through the transaction id.

func (*TxEngine) Commit Uses

func (te *TxEngine) Commit(ctx context.Context, transactionID int64, mc messageCommitter) (string, error)

Commit commits the specified transaction.

func (*TxEngine) Init Uses

func (te *TxEngine) Init() error

Init must be called once when vttablet starts for setting up the metadata tables.

func (*TxEngine) InitDBConfig Uses

func (te *TxEngine) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Init.

func (*TxEngine) Rollback Uses

func (te *TxEngine) Rollback(ctx context.Context, transactionID int64) error

Rollback rolls back the specified transaction.

func (*TxEngine) Stop Uses

func (te *TxEngine) Stop() error

Stop will stop accepting any new transactions. Transactions are immediately aborted.

func (*TxEngine) StopGently Uses

func (te *TxEngine) StopGently()

StopGently will disregard common rules for when to kill transactions and wait forever for transactions to wrap up

type TxExecutor Uses

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

TxExecutor is used for executing a transactional request.

func (*TxExecutor) CommitPrepared Uses

func (txe *TxExecutor) CommitPrepared(dtid string) error

CommitPrepared commits a prepared transaction. If the operation fails, an error counter is incremented and the transaction is marked as failed in the redo log.

func (*TxExecutor) ConcludeTransaction Uses

func (txe *TxExecutor) ConcludeTransaction(dtid string) error

ConcludeTransaction deletes the 2pc transaction metadata essentially resolving it.

func (*TxExecutor) CreateTransaction Uses

func (txe *TxExecutor) CreateTransaction(dtid string, participants []*querypb.Target) error

CreateTransaction creates the metadata for a 2PC transaction.

func (*TxExecutor) Prepare Uses

func (txe *TxExecutor) Prepare(transactionID int64, dtid string) error

Prepare performs a prepare on a connection including the redo log work. If there is any failure, an error is returned. No cleanup is performed. A subsequent call to RollbackPrepared, which is required by the 2PC protocol, will perform all the cleanup.

func (*TxExecutor) ReadTransaction Uses

func (txe *TxExecutor) ReadTransaction(dtid string) (*querypb.TransactionMetadata, error)

ReadTransaction returns the metadata for the sepcified dtid.

func (*TxExecutor) ReadTwopcInflight Uses

func (txe *TxExecutor) ReadTwopcInflight() (distributed []*DistributedTx, prepared, failed []*PreparedTx, err error)

ReadTwopcInflight returns info about all in-flight 2pc transactions.

func (*TxExecutor) RollbackPrepared Uses

func (txe *TxExecutor) RollbackPrepared(dtid string, originalID int64) error

RollbackPrepared rolls back a prepared transaction. This function handles the case of an incomplete prepare.

If the prepare completely failed, it will just rollback the original transaction identified by originalID.

If the connection was moved to the prepared pool, but redo log creation failed, then it will rollback that transaction and return the conn to the txPool.

If prepare was fully successful, it will also delete the redo log. If the redo log deletion fails, it returns an error indicating that a retry is needed.

In recovery mode, the original transaction id will not be available. If so, it must be set to 0, and the function will not attempt that step. If the original transaction is still alive, the transaction killer will be the one to eventually roll it back.

func (*TxExecutor) SetRollback Uses

func (txe *TxExecutor) SetRollback(dtid string, transactionID int64) error

SetRollback transitions the 2pc transaction to the Rollback state. If a transaction id is provided, that transaction is also rolled back.

func (*TxExecutor) StartCommit Uses

func (txe *TxExecutor) StartCommit(transactionID int64, dtid string) error

StartCommit atomically commits the transaction along with the decision to commit the associated 2pc transaction.

type TxPool Uses

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

TxPool is the transaction pool for the query service.

func NewTxPool Uses

func NewTxPool(
    prefix string,
    capacity int,
    foundRowsCapacity int,
    timeout time.Duration,
    idleTimeout time.Duration,
    waiterCap int,
    checker connpool.MySQLChecker,
    limiter txlimiter.TxLimiter) *TxPool

NewTxPool creates a new TxPool. It's not operational until it's Open'd.

func (*TxPool) AdjustLastID Uses

func (axp *TxPool) AdjustLastID(id int64)

AdjustLastID adjusts the last transaction id to be at least as large as the input value. This will ensure that there are no dtid collisions with future transactions.

func (*TxPool) Begin Uses

func (axp *TxPool) Begin(ctx context.Context, options *querypb.ExecuteOptions) (int64, string, error)

Begin begins a transaction, and returns the associated transaction id and the statements (if any) executed to initiate the transaction. In autocommit mode the statement will be "".

Subsequent statements can access the connection through the transaction id.

func (*TxPool) Close Uses

func (axp *TxPool) Close()

Close closes the TxPool. A closed pool can be reopened.

func (*TxPool) Commit Uses

func (axp *TxPool) Commit(ctx context.Context, transactionID int64, mc messageCommitter) (string, error)

Commit commits the specified transaction.

func (*TxPool) Get Uses

func (axp *TxPool) Get(transactionID int64, reason string) (*TxConnection, error)

Get fetches the connection associated to the transactionID. You must call Recycle on TxConnection once done.

func (*TxPool) LocalBegin Uses

func (axp *TxPool) LocalBegin(ctx context.Context, options *querypb.ExecuteOptions) (*TxConnection, string, error)

LocalBegin is equivalent to Begin->Get. It's used for executing transactions within a request. It's safe to always call LocalConclude at the end.

func (*TxPool) LocalCommit Uses

func (axp *TxPool) LocalCommit(ctx context.Context, conn *TxConnection, mc messageCommitter) (string, error)

LocalCommit is the commit function for LocalBegin.

func (*TxPool) LocalConclude Uses

func (axp *TxPool) LocalConclude(ctx context.Context, conn *TxConnection)

LocalConclude concludes a transaction started by LocalBegin. If the transaction was not previously concluded, it's rolled back.

func (*TxPool) LogActive Uses

func (axp *TxPool) LogActive()

LogActive causes all existing transactions to be logged when they complete. The logging is throttled to no more than once every txLogInterval.

func (*TxPool) Open Uses

func (axp *TxPool) Open(appParams, dbaParams, appDebugParams *mysql.ConnParams)

Open makes the TxPool operational. This also starts the transaction killer that will kill long-running transactions.

func (*TxPool) Rollback Uses

func (axp *TxPool) Rollback(ctx context.Context, transactionID int64) error

Rollback rolls back the specified transaction.

func (*TxPool) RollbackNonBusy Uses

func (axp *TxPool) RollbackNonBusy(ctx context.Context)

RollbackNonBusy rolls back all transactions that are not in use. Transactions can be in use for situations like executing statements or in prepared state.

func (*TxPool) SetTimeout Uses

func (axp *TxPool) SetTimeout(timeout time.Duration)

SetTimeout sets the transaction timeout.

func (*TxPool) Timeout Uses

func (axp *TxPool) Timeout() time.Duration

Timeout returns the transaction timeout.

func (*TxPool) WaitForEmpty Uses

func (axp *TxPool) WaitForEmpty()

WaitForEmpty waits until all active transactions are completed.

type TxPoolController Uses

type TxPoolController interface {
    // Stop will stop accepting any new transactions. Transactions are immediately aborted.
    Stop() error

    // Will start accepting all transactions. If transitioning from RO mode, transactions
    // might need to be rolled back before new transactions can be accepts.
    AcceptReadWrite() error

    // Will start accepting read-only transactions, but not full read and write transactions.
    // If the engine is currently accepting full read and write transactions, they need to
    // given a chance to clean up before they are forcefully rolled back.
    AcceptReadOnly() error

    // InitDBConfig must be called before Init.
    InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

    // Init must be called once when vttablet starts for setting
    // up the metadata tables.
    Init() error

    // StopGently will change the state to NotServing but first wait for transactions to wrap up
    StopGently()

    // Begin begins a transaction, and returns the associated transaction id and the
    // statement(s) used to execute the begin (if any).
    //
    // Subsequent statements can access the connection through the transaction id.
    Begin(ctx context.Context, options *querypb.ExecuteOptions) (int64, string, error)

    // Commit commits the specified transaction, returning the statement used to execute
    // the commit or "" in autocommit settings.
    Commit(ctx context.Context, transactionID int64, mc messageCommitter) (string, error)

    // Rollback rolls back the specified transaction.
    Rollback(ctx context.Context, transactionID int64) error
}

TxPoolController is how the tablet server interacts with the tx-pool. It is responsible for keeping it's own state - knowing when different types of transactions are allowed, and how to do state transitions.

type TxPreparedPool Uses

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

TxPreparedPool manages connections for prepared transactions. The Prepare functionality and associated orchestration is done by TxPool.

func NewTxPreparedPool Uses

func NewTxPreparedPool(capacity int) *TxPreparedPool

NewTxPreparedPool creates a new TxPreparedPool.

func (*TxPreparedPool) FetchAll Uses

func (pp *TxPreparedPool) FetchAll() []*TxConnection

FetchAll removes all connections and returns them as a list. It also forgets all reserved dtids.

func (*TxPreparedPool) FetchForCommit Uses

func (pp *TxPreparedPool) FetchForCommit(dtid string) (*TxConnection, error)

FetchForCommit returns the connection for commit. Before returning, it remembers the dtid in its reserved list as "committing". If the dtid is already in the reserved list, it returns an error. If the commit is successful, the dtid can be removed from the reserved list by calling Forget. If the commit failed, SetFailed must be called. This will inform future retries that the previous commit failed.

func (*TxPreparedPool) FetchForRollback Uses

func (pp *TxPreparedPool) FetchForRollback(dtid string) *TxConnection

FetchForRollback returns the connection and removes it from the pool. If the connection is not found, it returns nil. If the dtid is in the reserved list, it means that an operator is trying to resolve a previously failed commit. So, it removes the entry and returns nil.

func (*TxPreparedPool) Forget Uses

func (pp *TxPreparedPool) Forget(dtid string)

Forget removes the dtid from the reserved list.

func (*TxPreparedPool) Put Uses

func (pp *TxPreparedPool) Put(c *TxConnection, dtid string) error

Put adds the connection to the pool. It returns an error if the pool is full or on duplicate key.

func (*TxPreparedPool) SetFailed Uses

func (pp *TxPreparedPool) SetFailed(dtid string)

SetFailed marks the reserved dtid as failed. If there was no previous entry, one is created.

Directories

PathSynopsis
connpool
messager
planbuilder
rules
schema
schema/schematestPackage schematest provides support for testing packages that depend on schema
splitqueryPackage splitquery contains the logic needed for implementing the tabletserver's SplitQuery RPC.
tabletenvPackage tabletenv maintains environment variables and types that are common for all packages of tabletserver.
txlimiter
txserializerPackage txserializer provides the vttablet hot row protection.
txthrottler
vstreamer
vstreamer/testenvPackage testenv supplies test functions for testing vstreamer.

Package tabletserver imports 67 packages (graph) and is imported by 8 packages. Updated 2019-06-13. Refresh now. Tools for package owners.