tabletserver

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
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
)
View Source
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
)
View Source
const (
	NotServing txEngineState = iota
	Transitioning
	AcceptingReadAndWrite
	AcceptingReadOnly
)

The TxEngine can be in any of these states

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

These consts identify how a transaction was resolved.

Variables

View Source
var RegisterFunctions []func(Controller)

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

Functions

This section is empty.

Types

type Controller

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

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

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

PreparedTx represents a displayable version of a prepared transaction.

type QueryDetail

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

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

func NewQueryDetail

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

NewQueryDetail creates a new QueryDetail

type QueryDetailzRow

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

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

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

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

func (qe *QueryEngine) ClearQueryPlanCache()

ClearQueryPlanCache should be called if query plan cache is potentially obsolete

func (*QueryEngine) Close

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

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

GetMessageStreamPlan builds a plan for Message streaming.

func (*QueryEngine) GetPlan

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

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

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

InitDBConfig must be called before Open.

func (*QueryEngine) IsMySQLReachable

func (qe *QueryEngine) IsMySQLReachable() bool

IsMySQLReachable returns true if we can connect to MySQL.

func (*QueryEngine) Open

func (qe *QueryEngine) Open() error

Open must be called before sending requests to QueryEngine.

func (*QueryEngine) QueryPlanCacheCap

func (qe *QueryEngine) QueryPlanCacheCap() int

QueryPlanCacheCap returns the capacity of the query cache.

func (*QueryEngine) ServeHTTP

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

func (*QueryEngine) SetQueryPlanCacheCap

func (qe *QueryEngine) SetQueryPlanCacheCap(size int)

SetQueryPlanCacheCap sets the query plan cache capacity.

type QueryExecutor

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

QueryExecutor is used for executing a query request.

func (*QueryExecutor) Execute

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

Execute performs a non-streaming query execution.

func (*QueryExecutor) MessageStream

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

MessageStream streams messages from a message table.

func (*QueryExecutor) Stream

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

Stream performs a streaming query execution.

type QueryList

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

QueryList holds a thread safe list of QueryDetails

func NewQueryList

func NewQueryList() *QueryList

NewQueryList creates a new QueryList

func (*QueryList) Add

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

Add adds a QueryDetail to QueryList

func (*QueryList) GetQueryzRows

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

GetQueryzRows returns a list of QueryDetailzRow sorted by start time

func (*QueryList) Remove

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

Remove removes a QueryDetail from QueryList

func (*QueryList) Terminate

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

Terminate updates the query status and kills the connection

func (*QueryList) TerminateAll

func (ql *QueryList) TerminateAll()

TerminateAll terminates all queries and kills the MySQL connections

type ReplicationWatcher

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

ReplicationWatcher is a tabletserver service that watches the replication stream. It will trigger schema reloads if a DDL is encountered.

func NewReplicationWatcher

func NewReplicationWatcher(vs VStreamer, config tabletenv.TabletConfig) *ReplicationWatcher

NewReplicationWatcher creates a new ReplicationWatcher.

func (*ReplicationWatcher) Close

func (rpw *ReplicationWatcher) Close()

Close stops the ReplicationWatcher service.

func (*ReplicationWatcher) Open

func (rpw *ReplicationWatcher) Open()

Open starts the ReplicationWatcher service.

func (*ReplicationWatcher) Process

func (rpw *ReplicationWatcher) Process(ctx context.Context)

Process processes the replication stream.

type TabletPlan

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

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

AddStats updates the stats for the current TabletPlan.

func (*TabletPlan) Size

func (*TabletPlan) Size() int

Size allows TabletPlan to be in cache.LRUCache.

func (*TabletPlan) Stats

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

Stats returns the current stats of TabletPlan.

type TabletServer

type TabletServer struct {
	QueryTimeout 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

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

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

func NewTabletServer

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 (*TabletServer) AddStatusPart

func (tsv *TabletServer) AddStatusPart()

AddStatusPart registers the status part for the status page.

func (*TabletServer) Begin

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

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

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

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

BroadcastHealth will broadcast the current health to all listeners

func (*TabletServer) CheckMySQL

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

func (tsv *TabletServer) ClearQueryPlanCache()

ClearQueryPlanCache clears internal query plan cache

func (*TabletServer) Close

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

Close is a no-op.

func (*TabletServer) Commit

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

Commit commits the specified transaction.

func (*TabletServer) CommitPrepared

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

CommitPrepared commits the prepared transaction.

func (*TabletServer) ConcludeTransaction

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

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

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

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

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

func (tsv *TabletServer) ExitLameduck()

ExitLameduck causes the tabletserver to exit the lameduck mode.

func (*TabletServer) GetQueryPoolTimeout

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

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

func (tsv *TabletServer) GetState() string

GetState returns the name of the current TabletServer state.

func (*TabletServer) GetTxPoolWaiterCap

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

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

HandlePanic is part of the queryservice.QueryService interface

func (*TabletServer) HeartbeatLag

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

func (tsv *TabletServer) InitACL(tableACLConfigFile string, enforceTableACLConfig bool, reloadACLConfigFileInterval time.Duration)

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

func (*TabletServer) InitDBConfig

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

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

func (tsv *TabletServer) IsServing() bool

IsServing returns true if TabletServer is in SERVING state.

func (*TabletServer) MaxDMLRows

func (tsv *TabletServer) MaxDMLRows() int

MaxDMLRows returns the max result size.

func (*TabletServer) MaxResultSize

func (tsv *TabletServer) MaxResultSize() int

MaxResultSize returns the max result size.

func (*TabletServer) MessageAck

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

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

func (tsv *TabletServer) PoolSize() int

PoolSize returns the pool size.

func (*TabletServer) PostponeMessages

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

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

Prepare prepares the specified transaction.

func (*TabletServer) PurgeMessages

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

func (tsv *TabletServer) QueryPlanCacheCap() int

QueryPlanCacheCap returns the pool size.

func (*TabletServer) QueryService

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

QueryService returns the QueryService part of TabletServer.

func (*TabletServer) ReadTransaction

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

ReadTransaction returns the metadata for the specified dtid.

func (*TabletServer) Register

func (tsv *TabletServer) Register()

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

func (*TabletServer) RegisterQueryRuleSource

func (tsv *TabletServer) RegisterQueryRuleSource(ruleSource string)

RegisterQueryRuleSource registers ruleSource for setting query rules.

func (*TabletServer) ReloadSchema

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

ReloadSchema reloads the schema.

func (*TabletServer) Rollback

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

Rollback rollsback the specified transaction.

func (*TabletServer) RollbackPrepared

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

RollbackPrepared commits the prepared transaction.

func (*TabletServer) SchemaEngine

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

SchemaEngine returns the SchemaEngine part of TabletServer.

func (*TabletServer) SetConsolidatorEnabled

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) SetConsolidatorReplicasEnabled added in v1.0.1

func (tsv *TabletServer) SetConsolidatorReplicasEnabled(enabled bool)

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

func (*TabletServer) SetMaxDMLRows

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

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

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

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

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

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

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

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

SetQueryRules sets the query rules for a registered ruleSource.

func (*TabletServer) SetRollback

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

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

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

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) SetTxPoolTimeout added in v1.0.1

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

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

func (*TabletServer) SetTxPoolWaiterCap

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

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

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) StartCommit

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

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

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

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

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

func (tsv *TabletServer) StreamPoolSize() int

StreamPoolSize returns the pool size.

func (*TabletServer) TopoServer

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

TopoServer returns the topo server.

func (*TabletServer) TxPoolSize

func (tsv *TabletServer) TxPoolSize() int

TxPoolSize returns the tx pool size.

func (*TabletServer) TxPoolTimeout added in v1.0.1

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

TxPoolTimeout returns the transaction pool timeout.

func (*TabletServer) TxTimeout

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

TxTimeout returns the transaction timeout.

func (*TabletServer) UnRegisterQueryRuleSource

func (tsv *TabletServer) UnRegisterQueryRuleSource(ruleSource string)

UnRegisterQueryRuleSource unregisters ruleSource from query rules.

func (*TabletServer) VStream added in v1.0.1

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) VStreamResults added in v1.0.1

func (tsv *TabletServer) VStreamResults(ctx context.Context, target *querypb.Target, query string, send func(*binlogdatapb.VStreamResultsResponse) error) error

VStreamResults streams rows from the specified starting point.

func (*TabletServer) VStreamRows added in v1.0.1

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

func (tsv *TabletServer) WarnResultSize() int

WarnResultSize returns the warn result size.

type TwoPC

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

TwoPC performs 2PC metadata management (MM) functions.

func NewTwoPC

func NewTwoPC(readPool *connpool.Pool) *TwoPC

NewTwoPC creates a TwoPC variable.

func (*TwoPC) Close

func (tpc *TwoPC) Close()

Close closes the TwoPC service.

func (*TwoPC) CountUnresolvedRedo

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

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

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

DeleteRedo deletes the redo log for the dtid.

func (*TwoPC) DeleteTransaction

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

DeleteTransaction deletes the metadata for the specified transaction.

func (*TwoPC) Init

func (tpc *TwoPC) Init(sidecarDBName string, dbaparams dbconfigs.Connector) error

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

func (*TwoPC) Open

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

Open starts the TwoPC service.

func (*TwoPC) ReadAbandoned

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

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

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

ReadAllTransactions returns info about all distributed transactions.

func (*TwoPC) ReadTransaction

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

ReadTransaction returns the metadata for the transaction.

func (*TwoPC) SaveRedo

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

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

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

type TxConnection struct {
	TransactionID int64

	StartTime         time.Time
	EndTime           time.Time
	Queries           []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

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

BeginAgain commits the existing transaction and begins a new one

func (*TxConnection) Close added in v1.0.1

func (txc *TxConnection) Close()

Close closes the connection.

func (*TxConnection) EventTime

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

EventTime returns the time the event was created.

func (*TxConnection) Exec

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

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

Format returns a printable version of the connection info.

func (*TxConnection) RecordQuery

func (txc *TxConnection) RecordQuery(query string)

RecordQuery records the query against this transaction.

func (*TxConnection) Recycle

func (txc *TxConnection) Recycle()

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

type TxEngine

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

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

NewTxEngine creates a new TxEngine.

func (*TxEngine) AcceptReadOnly added in v1.0.1

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 added in v1.0.1

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 added in v1.0.1

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 added in v1.0.1

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

Commit commits the specified transaction.

func (*TxEngine) Init

func (te *TxEngine) Init() error

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

func (*TxEngine) InitDBConfig

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

InitDBConfig must be called before Init.

func (*TxEngine) Rollback added in v1.0.1

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

Rollback rolls back the specified transaction.

func (*TxEngine) Stop added in v1.0.1

func (te *TxEngine) Stop() error

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

func (*TxEngine) StopGently added in v1.0.1

func (te *TxEngine) StopGently()

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

type TxExecutor

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

TxExecutor is used for executing a transactional request.

func (*TxExecutor) CommitPrepared

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

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

ConcludeTransaction deletes the 2pc transaction metadata essentially resolving it.

func (*TxExecutor) CreateTransaction

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

CreateTransaction creates the metadata for a 2PC transaction.

func (*TxExecutor) Prepare

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

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

ReadTransaction returns the metadata for the sepcified dtid.

func (*TxExecutor) ReadTwopcInflight

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

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

func (*TxExecutor) RollbackPrepared

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

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

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

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

TxPool is the transaction pool for the query service.

func NewTxPool

func NewTxPool(
	prefix string,
	capacity int,
	foundRowsCapacity int,
	prefillParallelism int,
	transactionTimeout time.Duration,
	transactionPoolTimeout 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

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

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

func (axp *TxPool) Close()

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

func (*TxPool) Commit

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

Commit commits the specified transaction.

func (*TxPool) Get

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

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

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

LocalCommit is the commit function for LocalBegin.

func (*TxPool) LocalConclude

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

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

func (axp *TxPool) Open(appParams, dbaParams, appDebugParams dbconfigs.Connector)

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

func (*TxPool) PoolTimeout added in v1.0.1

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

PoolTimeout returns the transaction pool timeout.

func (*TxPool) Rollback

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

Rollback rolls back the specified transaction.

func (*TxPool) RollbackNonBusy

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) SetPoolTimeout added in v1.0.1

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

SetPoolTimeout sets the transaction pool timeout.

func (*TxPool) SetTimeout

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

SetTimeout sets the transaction timeout.

func (*TxPool) Timeout

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

Timeout returns the transaction timeout.

func (*TxPool) WaitForEmpty

func (axp *TxPool) WaitForEmpty()

WaitForEmpty waits until all active transactions are completed.

type TxPreparedPool

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

func NewTxPreparedPool(capacity int) *TxPreparedPool

NewTxPreparedPool creates a new TxPreparedPool.

func (*TxPreparedPool) FetchAll

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

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

func (*TxPreparedPool) FetchForCommit

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

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

func (pp *TxPreparedPool) Forget(dtid string)

Forget removes the dtid from the reserved list.

func (*TxPreparedPool) Put

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

func (pp *TxPreparedPool) SetFailed(dtid string)

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

type VStreamer added in v1.0.1

type VStreamer interface {
	Stream(ctx context.Context, startPos string, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error
}

VStreamer defines the functions of VStreamer that the replicationWatcher needs.

Directories

Path Synopsis
schematest
Package schematest provides support for testing packages that depend on schema
Package schematest provides support for testing packages that depend on schema
Package tabletenv maintains environment variables and types that are common for all packages of tabletserver.
Package tabletenv maintains environment variables and types that are common for all packages of tabletserver.
Package txserializer provides the vttablet hot row protection.
Package txserializer provides the vttablet hot row protection.
testenv
Package testenv supplies test functions for testing vstreamer.
Package testenv supplies test functions for testing vstreamer.

Jump to

Keyboard shortcuts

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