tabletenv

package
v2.2.0-rc.1+incompatible Latest Latest
Warning

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

Go to latest
Published: May 18, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package tabletenv maintains environment variables and types that are common for all packages of tabletserver.

Index

Constants

View Source
const (
	// QuerySourceConsolidator means query result is found in consolidator.
	QuerySourceConsolidator = 1 << iota
	// QuerySourceMySQL means query result is returned from MySQL.
	QuerySourceMySQL
)

Variables

View Source
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)
)
View Source
var (
	// MySQLStats shows the time histogram for operations spent on mysql side.
	MySQLStats = stats.NewTimings("Mysql", "MySQl query time", "operation")
	// QueryStats shows the time histogram for each type of queries.
	QueryStats = stats.NewTimings("Queries", "MySQL query timings", "plan_type")
	// 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", "Wait operations", "type")
	// KillStats shows number of connections being killed.
	KillStats = stats.NewCountersWithSingleLabel("Kills", "Number of connections being killed", "query_type", "Transactions", "Queries")
	// ErrorStats shows number of critial errors happened.
	ErrorStats = stats.NewCountersWithSingleLabel(
		"Errors",
		"Critical errors",
		"error_code",
		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.NewCountersWithSingleLabel("InternalErrors", "Internal component errors", "type", "Task", "StrayTransactions", "Panic", "HungQuery", "Schema", "TwopcCommit", "TwopcResurrection", "WatchdogFail", "Messages")
	// Warnings shows number of warnings
	Warnings = stats.NewCountersWithSingleLabel("Warnings", "Warnings", "type", "ResultsExceeded")
	// Unresolved tracks unresolved items. For now it's just Prepares.
	Unresolved = stats.NewGaugesWithSingleLabel("Unresolved", "Unresolved items", "item_type", "Prepares")
	// UserTableQueryCount shows number of queries received for each CallerID/table combination.
	UserTableQueryCount = stats.NewCountersWithMultiLabels(
		"UserTableQueryCount",
		"Queries received for each CallerID/table combination",
		[]string{"TableName", "CallerID", "Type"})
	// UserTableQueryTimesNs shows total latency for each CallerID/table combination.
	UserTableQueryTimesNs = stats.NewCountersWithMultiLabels(
		"UserTableQueryTimesNs",
		"Total latency for each CallerID/table combination",
		[]string{"TableName", "CallerID", "Type"})
	// UserTransactionCount shows number of transactions received for each CallerID.
	UserTransactionCount = stats.NewCountersWithMultiLabels(
		"UserTransactionCount",
		"transactions received for each CallerID",
		[]string{"CallerID", "Conclusion"})
	// UserTransactionTimesNs shows total transaction latency for each CallerID.
	UserTransactionTimesNs = stats.NewCountersWithMultiLabels(
		"UserTransactionTimesNs",
		"Total transaction latency for each CallerID",
		[]string{"CallerID", "Conclusion"})
	// ResultStats shows the histogram of number of rows returned.
	ResultStats = stats.NewHistogram("Results",
		"Distribution of rows returned",
		[]int64{0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000})
	// TableaclAllowed tracks the number allows.
	TableaclAllowed = stats.NewCountersWithMultiLabels(
		"TableACLAllowed",
		"ACL acceptances",
		[]string{"TableName", "TableGroup", "PlanID", "Username"})
	// TableaclDenied tracks the number of denials.
	TableaclDenied = stats.NewCountersWithMultiLabels(
		"TableACLDenied",
		"ACL denials",
		[]string{"TableName", "TableGroup", "PlanID", "Username"})
	// TableaclPseudoDenied tracks the number of pseudo denies.
	TableaclPseudoDenied = stats.NewCountersWithMultiLabels(
		"TableACLPseudoDenied",
		"ACL pseudodenials",
		[]string{"TableName", "TableGroup", "PlanID", "Username"})
	// Infof can be overridden during tests
	Infof = log.Infof
	// Warningf can be overridden during tests
	Warningf = log.Warningf
	// Errorf can be overridden during tests
	Errorf = log.Errorf
)
View Source
var DefaultQsConfig = TabletConfig{
	PoolSize:                16,
	StreamPoolSize:          200,
	MessagePoolSize:         5,
	TransactionCap:          20,
	MessagePostponeCap:      4,
	FoundRowsPoolSize:       20,
	TransactionTimeout:      30,
	TxShutDownGracePeriod:   0,
	MaxResultSize:           10000,
	WarnResultSize:          0,
	MaxDMLRows:              500,
	PassthroughDMLs:         false,
	QueryPlanCacheSize:      5000,
	SchemaReloadTime:        30 * 60,
	QueryTimeout:            30,
	QueryPoolTimeout:        0,
	TxPoolTimeout:           1,
	IdleTimeout:             30 * 60,
	QueryPoolWaiterCap:      50000,
	TxPoolWaiterCap:         50000,
	StreamBufferSize:        32 * 1024,
	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,

	HotRowProtectionConcurrentTransactions: 5,

	TransactionLimitConfig: defaultTransactionLimitConfig(),

	HeartbeatEnable:   false,
	HeartbeatInterval: 1 * time.Second,

	EnforceStrictTransTables: true,
}

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

func IsLocalContext(ctx context.Context) bool

IsLocalContext returns true if the context is based on LocalContext.

func LocalContext

func LocalContext() context.Context

LocalContext returns a context that's local to the process.

func LogError

func LogError()

LogError logs panics and increments InternalErrors.

func RecordUserQuery

func RecordUserQuery(ctx context.Context, tableName sqlparser.TableIdent, queryType string, duration int64)

RecordUserQuery records the query data against the user.

func VerifyConfig

func VerifyConfig() error

VerifyConfig checks "Config" for contradicting flags.

Types

type LogStats

type LogStats struct {
	Ctx           context.Context
	Method        string
	Target        *querypb.Target
	PlanType      string
	OriginalSQL   string
	BindVariables map[string]*querypb.BindVariable

	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

func NewLogStats(ctx context.Context, methodName string) *LogStats

NewLogStats constructs a new LogStats with supplied Method and ctx field values, and the StartTime field set to the present time.

func (*LogStats) AddRewrittenSQL

func (stats *LogStats) AddRewrittenSQL(sql string, start time.Time)

AddRewrittenSQL adds a single sql statement to the rewritten list

func (*LogStats) Context

func (stats *LogStats) Context() context.Context

Context returns the context used by LogStats.

func (*LogStats) ContextHTML

func (stats *LogStats) ContextHTML() template.HTML

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

func (stats *LogStats) EffectiveCaller() string

EffectiveCaller returns the effective caller stored in LogStats.Ctx

func (*LogStats) ErrorStr

func (stats *LogStats) ErrorStr() string

ErrorStr returns the error string or ""

func (*LogStats) EventTime

func (stats *LogStats) EventTime() time.Time

EventTime returns the time the event was created.

func (*LogStats) FmtBindVariables

func (stats *LogStats) FmtBindVariables(full bool) string

FmtBindVariables returns the map of bind variables as a string or a json string depending on the streamlog.QueryLogFormat value. If RedactDebugUIQueries is true then this returns the string "[REDACTED]"

For values that are strings or byte slices it only reports their type and length unless full is true.

func (*LogStats) FmtQuerySources

func (stats *LogStats) FmtQuerySources() string

FmtQuerySources returns a comma separated list of query sources. If there were no query sources, it returns the string "none".

func (*LogStats) Format

func (stats *LogStats) Format(params url.Values) string

Format returns a tab separated list of logged fields.

func (*LogStats) ImmediateCaller

func (stats *LogStats) ImmediateCaller() string

ImmediateCaller returns the immediate caller stored in LogStats.Ctx

func (*LogStats) RemoteAddrUsername

func (stats *LogStats) RemoteAddrUsername() (string, string)

RemoteAddrUsername returns some parts of CallInfo if set

func (*LogStats) RewrittenSQL

func (stats *LogStats) RewrittenSQL() string

RewrittenSQL returns a semicolon separated list of SQL statements that were executed.

func (*LogStats) Send

func (stats *LogStats) Send()

Send finalizes a record and sends it

func (*LogStats) SizeOfResponse

func (stats *LogStats) SizeOfResponse() int

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.

func (*LogStats) TotalTime

func (stats *LogStats) TotalTime() time.Duration

TotalTime returns how long this query has been running

type TabletConfig

type TabletConfig struct {
	PoolSize                int
	StreamPoolSize          int
	MessagePoolSize         int
	TransactionCap          int
	MessagePostponeCap      int
	FoundRowsPoolSize       int
	TransactionTimeout      float64
	TxShutDownGracePeriod   float64
	MaxResultSize           int
	WarnResultSize          int
	MaxDMLRows              int
	PassthroughDMLs         bool
	StreamBufferSize        int
	QueryPlanCacheSize      int
	SchemaReloadTime        float64
	QueryTimeout            float64
	QueryPoolTimeout        float64
	TxPoolTimeout           float64
	IdleTimeout             float64
	QueryPoolWaiterCap      int
	TxPoolWaiterCap         int
	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
	HotRowProtectionConcurrentTransactions int

	TransactionLimitConfig

	HeartbeatEnable   bool
	HeartbeatInterval time.Duration

	EnforceStrictTransTables bool
}

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.

type TransactionLimitConfig

type TransactionLimitConfig struct {
	EnableTransactionLimit         bool
	EnableTransactionLimitDryRun   bool
	TransactionLimitPerUser        float64
	TransactionLimitByUsername     bool
	TransactionLimitByPrincipal    bool
	TransactionLimitByComponent    bool
	TransactionLimitBySubcomponent bool
}

TransactionLimitConfig captures configuration of transaction pool slots limiter configuration.

Jump to

Keyboard shortcuts

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