Documentation ¶
Overview ¶
Package tabletenv maintains environment variables and types that are common for all packages of tabletserver.
Index ¶
- Constants
- Variables
- func Init()
- func IsLocalContext(ctx context.Context) bool
- func LocalContext() context.Context
- func LogError()
- func RecordUserQuery(ctx context.Context, tableName sqlparser.TableIdent, queryType string, ...)
- func VerifyConfig() error
- type LogStats
- func (stats *LogStats) AddRewrittenSQL(sql string, start time.Time)
- func (stats *LogStats) Context() context.Context
- func (stats *LogStats) ContextHTML() template.HTML
- func (stats *LogStats) EffectiveCaller() string
- func (stats *LogStats) ErrorStr() string
- func (stats *LogStats) EventTime() time.Time
- func (stats *LogStats) FmtBindVariables(full bool) string
- func (stats *LogStats) FmtQuerySources() string
- func (stats *LogStats) Format(params url.Values) string
- func (stats *LogStats) ImmediateCaller() string
- func (stats *LogStats) RemoteAddrUsername() (string, string)
- func (stats *LogStats) RewrittenSQL() string
- func (stats *LogStats) Send()
- func (stats *LogStats) SizeOfResponse() int
- func (stats *LogStats) TotalTime() time.Duration
- type MySQLChecker
- type TabletConfig
Constants ¶
const ( // QuerySourceConsolidator means query result is found in consolidator. QuerySourceConsolidator = 1 << iota // QuerySourceMySQL means query result is returned from MySQL. QuerySourceMySQL )
Variables ¶
var ( // TxLogger can be used to enable logging of transactions. // Call TxLogger.ServeLogs in your main program to enable logging. // The log format can be inferred by looking at TxConnection.Format. TxLogger = streamlog.New("TxLog", 10) // StatsLogger is the main stream logger object StatsLogger = streamlog.New("TabletServer", 50) )
var ( // MySQLStats shows the time histogram for operations spent on mysql side. MySQLStats = stats.NewTimings("Mysql") // QueryStats shows the time histogram for each type of queries. QueryStats = stats.NewTimings("Queries") // QPSRates shows the qps of QueryStats. Sample every 5 seconds and keep samples for up to 15 mins. QPSRates = stats.NewRates("QPS", QueryStats, 15*60/5, 5*time.Second) // WaitStats shows the time histogram for wait operations WaitStats = stats.NewTimings("Waits") // KillStats shows number of connections being killed. KillStats = stats.NewCounters("Kills", "Transactions", "Queries") // ErrorStats shows number of critial erros happened. ErrorStats = stats.NewCounters( "Errors", vtrpcpb.Code_OK.String(), vtrpcpb.Code_CANCELED.String(), vtrpcpb.Code_UNKNOWN.String(), vtrpcpb.Code_INVALID_ARGUMENT.String(), vtrpcpb.Code_DEADLINE_EXCEEDED.String(), vtrpcpb.Code_NOT_FOUND.String(), vtrpcpb.Code_ALREADY_EXISTS.String(), vtrpcpb.Code_PERMISSION_DENIED.String(), vtrpcpb.Code_UNAUTHENTICATED.String(), vtrpcpb.Code_RESOURCE_EXHAUSTED.String(), vtrpcpb.Code_FAILED_PRECONDITION.String(), vtrpcpb.Code_ABORTED.String(), vtrpcpb.Code_OUT_OF_RANGE.String(), vtrpcpb.Code_UNIMPLEMENTED.String(), vtrpcpb.Code_INTERNAL.String(), vtrpcpb.Code_UNAVAILABLE.String(), vtrpcpb.Code_DATA_LOSS.String(), ) // InternalErrors shows number of errors from internal components. InternalErrors = stats.NewCounters("InternalErrors", "Task", "StrayTransactions", "Panic", "HungQuery", "Schema", "TwopcCommit", "TwopcResurrection", "WatchdogFail") // Unresolved tracks unresolved items. For now it's just Prepares. Unresolved = stats.NewCounters("Unresolved", "Prepares") // UserTableQueryCount shows number of queries received for each CallerID/table combination. UserTableQueryCount = stats.NewMultiCounters("UserTableQueryCount", []string{"TableName", "CallerID", "Type"}) // UserTableQueryTimesNs shows total latency for each CallerID/table combination. UserTableQueryTimesNs = stats.NewMultiCounters("UserTableQueryTimesNs", []string{"TableName", "CallerID", "Type"}) // UserTransactionCount shows number of transactions received for each CallerID. UserTransactionCount = stats.NewMultiCounters("UserTransactionCount", []string{"CallerID", "Conclusion"}) // UserTransactionTimesNs shows total transaction latency for each CallerID. UserTransactionTimesNs = stats.NewMultiCounters("UserTransactionTimesNs", []string{"CallerID", "Conclusion"}) // ResultStats shows the histogram of number of rows returned. ResultStats = stats.NewHistogram("Results", []int64{0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000}) // TableaclAllowed tracks the number allows. TableaclAllowed = stats.NewMultiCounters("TableACLAllowed", []string{"TableName", "TableGroup", "PlanID", "Username"}) // TableaclDenied tracks the number of denials. TableaclDenied = stats.NewMultiCounters("TableACLDenied", []string{"TableName", "TableGroup", "PlanID", "Username"}) // TableaclPseudoDenied tracks the number of pseudo denies. TableaclPseudoDenied = stats.NewMultiCounters("TableACLPseudoDenied", []string{"TableName", "TableGroup", "PlanID", "Username"}) )
var DefaultQsConfig = TabletConfig{ PoolSize: 16, StreamPoolSize: 200, MessagePoolSize: 5, TransactionCap: 20, TransactionTimeout: 30, TxShutDownGracePeriod: 0, MaxResultSize: 10000, MaxDMLRows: 500, QueryCacheSize: 5000, SchemaReloadTime: 30 * 60, QueryTimeout: 30, TxPoolTimeout: 1, IdleTimeout: 30 * 60, StreamBufferSize: 32 * 1024, StrictMode: true, StrictTableACL: false, TerseErrors: false, EnableAutoCommit: false, EnableTableACLDryRun: false, PoolNamePrefix: "", TableACLExemptACL: "", WatchReplication: false, TwoPCEnable: false, TwoPCCoordinatorAddress: "", TwoPCAbandonAge: 0, EnableTxThrottler: false, TxThrottlerConfig: defaultTxThrottlerConfig(), TxThrottlerHealthCheckCells: []string{}, EnableHotRowProtection: false, EnableHotRowProtectionDryRun: false, HotRowProtectionMaxQueueSize: 20, HotRowProtectionMaxGlobalQueueSize: 1000, }
DefaultQsConfig is the default value for the query service config. The value for StreamBufferSize was chosen after trying out a few of them. Too small buffers force too many packets to be sent. Too big buffers force the clients to read them in multiple chunks and make memory copies. so with the encoding overhead, this seems to work great (the overhead makes the final packets on the wire about twice bigger than this).
Functions ¶
func Init ¶
func Init()
Init must be called after flag.Parse, and before doing any other operations.
func IsLocalContext ¶
IsLocalContext returns true if the context is based on LocalContext.
func LocalContext ¶
LocalContext returns a context that's local to the process.
func RecordUserQuery ¶
func RecordUserQuery(ctx context.Context, tableName sqlparser.TableIdent, queryType string, duration int64)
RecordUserQuery records the query data against the user.
Types ¶
type LogStats ¶
type LogStats struct { Ctx context.Context Method string Target *querypb.Target PlanType string OriginalSQL string BindVariables map[string]interface{} RowsAffected int NumberOfQueries int StartTime time.Time EndTime time.Time MysqlResponseTime time.Duration WaitingForConnection time.Duration QuerySources byte Rows [][]sqltypes.Value TransactionID int64 Error error // contains filtered or unexported fields }
LogStats records the stats for a single query
func NewLogStats ¶
NewLogStats constructs a new LogStats with supplied Method and ctx field values, and the StartTime field set to the present time.
func (*LogStats) AddRewrittenSQL ¶
AddRewrittenSQL adds a single sql statement to the rewritten list
func (*LogStats) ContextHTML ¶
ContextHTML returns the HTML version of the context that was used, or "". This is a method on LogStats instead of a field so that it doesn't need to be passed by value everywhere.
func (*LogStats) EffectiveCaller ¶
EffectiveCaller returns the effective caller stored in LogStats.Ctx
func (*LogStats) FmtBindVariables ¶
FmtBindVariables returns the map of bind variables as JSON. For values that are strings or byte slices it only reports their type and length.
func (*LogStats) FmtQuerySources ¶
FmtQuerySources returns a comma separated list of query sources. If there were no query sources, it returns the string "none".
func (*LogStats) ImmediateCaller ¶
ImmediateCaller returns the immediate caller stored in LogStats.Ctx
func (*LogStats) RemoteAddrUsername ¶
RemoteAddrUsername returns some parts of CallInfo if set
func (*LogStats) RewrittenSQL ¶
RewrittenSQL returns a semicolon separated list of SQL statements that were executed.
func (*LogStats) SizeOfResponse ¶
SizeOfResponse returns the approximate size of the response in bytes (this does not take in account protocol encoding). It will return 0 for streaming requests.
type MySQLChecker ¶
type MySQLChecker interface {
CheckMySQL()
}
MySQLChecker defines the CheckMySQL interface that lower level objects can use to call back into TabletServer.
type TabletConfig ¶
type TabletConfig struct { PoolSize int StreamPoolSize int MessagePoolSize int TransactionCap int TransactionTimeout float64 TxShutDownGracePeriod float64 MaxResultSize int MaxDMLRows int StreamBufferSize int QueryCacheSize int SchemaReloadTime float64 QueryTimeout float64 TxPoolTimeout float64 IdleTimeout float64 StrictMode bool StrictTableACL bool TerseErrors bool EnableAutoCommit bool EnableTableACLDryRun bool PoolNamePrefix string TableACLExemptACL string WatchReplication bool TwoPCEnable bool TwoPCCoordinatorAddress string TwoPCAbandonAge float64 EnableTxThrottler bool TxThrottlerConfig string TxThrottlerHealthCheckCells []string EnableHotRowProtection bool EnableHotRowProtectionDryRun bool HotRowProtectionMaxQueueSize int HotRowProtectionMaxGlobalQueueSize int }
TabletConfig contains all the configuration for query service
var Config TabletConfig
Config contains all the current config values. It's read-only, except for tests.