tabletserver

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2017 License: BSD-3-Clause Imports: 66 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 (
	TxClose    = "close"
	TxCommit   = "commit"
	TxRollback = "rollback"
	TxPrepare  = "prepare"
	TxKill     = "kill"
)

These consts identify how a transaction was resolved.

Variables

View Source
var RegisterFunctions []RegisterFunction

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

Functions

func Rand

func Rand() int64

Rand generates a pseudo-random int64 number.

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, mysqlctl.MysqlDaemon) 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)
}

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 MySQLChecker

type MySQLChecker interface {
	CheckMySQL()
}

MySQLChecker defines the CheckMySQL interface that lower level objects can use to call back into TabletServer.

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

func (qe *QueryEngine) GetPlan(ctx context.Context, logStats *tabletenv.LogStats, sql string) (*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) IsMySQLReachable

func (qe *QueryEngine) IsMySQLReachable() bool

IsMySQLReachable returns true if we can connect to MySQL.

func (*QueryEngine) Open

func (qe *QueryEngine) Open(dbconfigs dbconfigs.DBConfigs) error

Open must be called before sending requests to QueryEngine.

func (*QueryEngine) QueryCacheCap

func (qe *QueryEngine) QueryCacheCap() int

QueryCacheCap returns the capacity of the query cache.

func (*QueryEngine) ServeHTTP

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

func (*QueryEngine) SetQueryCacheCap

func (qe *QueryEngine) SetQueryCacheCap(size int)

SetQueryCacheCap sets the query 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) Stream

func (qre *QueryExecutor) Stream(includedFields querypb.ExecuteOptions_IncludedFields, 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 RegisterFunction

type RegisterFunction func(Controller)

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

type ReplicationWatcher

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

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

NewReplicationWatcher creates a new ReplicationWatcher.

func (*ReplicationWatcher) Close

func (rpw *ReplicationWatcher) Close()

Close stops the ReplicationWatcher service.

func (*ReplicationWatcher) ComputeExtras

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

ComputeExtras returns the requested ResultExtras based on the supplied options.

func (*ReplicationWatcher) EventToken

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

EventToken returns the current event token.

func (*ReplicationWatcher) Open

func (rpw *ReplicationWatcher) Open(dbconfigs dbconfigs.DBConfigs, mysqld mysqlctl.MysqlDaemon)

Open starts the ReplicationWatcher service.

func (*ReplicationWatcher) Process

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

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
	BeginTimeout sync2.AtomicDuration
	TerseErrors  bool
	// contains filtered or unexported fields
}

TabletServer implements the RPC interface for the query service.

func NewServer

func NewServer(topoServer topo.Server) *TabletServer

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

func NewTabletServer

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

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

func NewTabletServerWithNilTopoServer

func NewTabletServerWithNilTopoServer(config tabletenv.TabletConfig) *TabletServer

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

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) (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]interface{}, 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 []querytypes.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)

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]interface{}, 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 []querytypes.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) GetState

func (tsv *TabletServer) GetState() string

GetState returns the name of the current TabletServer state.

func (*TabletServer) HandlePanic

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

HandlePanic is part of the queryservice.QueryService interface

func (*TabletServer) InitDBConfig

func (tsv *TabletServer) InitDBConfig(target querypb.Target, dbconfigs dbconfigs.DBConfigs, mysqld mysqlctl.MysqlDaemon) error

InitDBConfig inititalizes 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 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) QueryCacheCap

func (tsv *TabletServer) QueryCacheCap() int

QueryCacheCap 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 sepcified 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) SetAutoCommit

func (tsv *TabletServer) SetAutoCommit(auto bool)

SetAutoCommit sets autocommit on or off. 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) 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) SetQueryCacheCap

func (tsv *TabletServer) SetQueryCacheCap(val int)

SetQueryCacheCap changes the pool size to the specified value. 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) SetStrictMode

func (tsv *TabletServer) SetStrictMode(strict bool)

SetStrictMode sets strict mode on or off. This only sets the mode for QueryEngine, but not for schema.Engine. 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) 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) SplitQuery

func (tsv *TabletServer) SplitQuery(
	ctx context.Context,
	target *querypb.Target,
	query querytypes.BoundQuery,
	splitColumns []string,
	splitCount int64,
	numRowsPerQueryPart int64,
	algorithm querypb.SplitQueryRequest_Algorithm,
) (splits []querytypes.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

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, dbconfigs dbconfigs.DBConfigs, mysqld mysqlctl.MysqlDaemon) (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]interface{}, 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) TxPoolSize

func (tsv *TabletServer) TxPoolSize() int

TxPoolSize returns the tx pool size.

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

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

UpdateStream streams binlog events.

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 *sqldb.ConnParams) 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 {
	*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
	// 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) 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 handles transactions.

func NewTxEngine

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

NewTxEngine creates a new TxEngine.

func (*TxEngine) Close

func (te *TxEngine) Close(immediate bool)

Close closes the TxEngine. If the immediate flag is on, then all current transactions are immediately rolled back. Otherwise, the function waits for all current transactions to conclude. If a shutdown grace period was specified, the transactions are rolled back if they're not resolved by that time.

func (*TxEngine) Init

func (te *TxEngine) Init(dbconfigs dbconfigs.DBConfigs) error

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

func (*TxEngine) Open

func (te *TxEngine) Open(dbconfigs dbconfigs.DBConfigs)

Open opens the TxEngine. If 2pc is enabled, it restores all previously prepared transactions from the redo log.

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(
	name string,
	capacity int,
	timeout time.Duration,
	idleTimeout time.Duration,
	checker MySQLChecker) *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) (int64, error)

Begin begins a transaction, and returns the associated transaction id. 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, messager *messager.Engine) 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) (*TxConnection, 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, messager *messager.Engine) 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 *sqldb.ConnParams)

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

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

Directories

Path Synopsis
Package querytypes defines internal types used in the APIs to deal with queries.
Package querytypes defines internal types used in the APIs to deal with queries.
schematest
Package schematest provides support for testing packages that depend on schema
Package schematest provides support for testing packages that depend on schema
Package splitquery contains the logic needed for implementing the tabletserver's SplitQuery RPC.
Package splitquery contains the logic needed for implementing the tabletserver's SplitQuery RPC.
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.

Jump to

Keyboard shortcuts

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