tabletenv

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 24 Imported by: 16

Documentation

Overview

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

Index

Constants

View Source
const (
	Enable  = "enable"
	Disable = "disable"
	Dryrun  = "dryRun"
	// TODO(deepthi): Deprecated. Should be deleted after v12.0
	NotOnMaster  = "notOnMaster"
	NotOnPrimary = "notOnPrimary"
	Polling      = "polling"
	Heartbeat    = "heartbeat"
)

These constants represent values for various config parameters.

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

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 SecondsVar

func SecondsVar(p *Seconds, name string, value Seconds, usage string)

SecondsVar is like a flag.Float64Var, but it works for Seconds.

Types

type ConnPoolConfig

type ConnPoolConfig struct {
	Size               int     `json:"size,omitempty"`
	TimeoutSeconds     Seconds `json:"timeoutSeconds,omitempty"`
	IdleTimeoutSeconds Seconds `json:"idleTimeoutSeconds,omitempty"`
	PrefillParallelism int     `json:"prefillParallelism,omitempty"`
	MaxWaiters         int     `json:"maxWaiters,omitempty"`
}

ConnPoolConfig contains the config for a conn pool.

type Env

type Env interface {
	CheckMySQL()
	Config() *TabletConfig
	Exporter() *servenv.Exporter
	Stats() *Stats
	LogError()
}

Env defines the functions supported by TabletServer that the sub-componennts need to access.

func NewEnv

func NewEnv(config *TabletConfig, exporterName string) Env

NewEnv creates an Env that can be used for tabletserver subcomponents without an actual TabletServer.

type GracePeriodsConfig

type GracePeriodsConfig struct {
	ShutdownSeconds   Seconds `json:"shutdownSeconds,omitempty"`
	TransitionSeconds Seconds `json:"transitionSeconds,omitempty"`
}

GracePeriodsConfig contains various grace periods. TODO(sougou): move lameduck here?

type HealthcheckConfig

type HealthcheckConfig struct {
	IntervalSeconds           Seconds `json:"intervalSeconds,omitempty"`
	DegradedThresholdSeconds  Seconds `json:"degradedThresholdSeconds,omitempty"`
	UnhealthyThresholdSeconds Seconds `json:"unhealthyThresholdSeconds,omitempty"`
}

HealthcheckConfig contains the config for healthcheck.

type HotRowProtectionConfig

type HotRowProtectionConfig struct {
	// Mode can be disable, dryRun or enable. Default is disable.
	Mode               string `json:"mode,omitempty"`
	MaxQueueSize       int    `json:"maxQueueSize,omitempty"`
	MaxGlobalQueueSize int    `json:"maxGlobalQueueSize,omitempty"`
	MaxConcurrency     int    `json:"maxConcurrency,omitempty"`
}

HotRowProtectionConfig contains the config for hot row protection.

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
	ReservedID           int64
	Error                error
	CachedPlan           bool
	// 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) CallInfo

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

CallInfo returns some parts of CallInfo if set

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

func (stats *LogStats) ImmediateCaller() string

ImmediateCaller returns the immediate caller stored in LogStats.Ctx

func (*LogStats) Logf

func (stats *LogStats) Logf(w io.Writer, params url.Values) error

Logf formats the log record to the given writer, either as tab-separated list of logged fields or as JSON.

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 OltpConfig

type OltpConfig struct {
	QueryTimeoutSeconds Seconds `json:"queryTimeoutSeconds,omitempty"`
	TxTimeoutSeconds    Seconds `json:"txTimeoutSeconds,omitempty"`
	MaxRows             int     `json:"maxRows,omitempty"`
	WarnRows            int     `json:"warnRows,omitempty"`
}

OltpConfig contains the config for oltp settings.

type ReplicationTrackerConfig

type ReplicationTrackerConfig struct {
	// Mode can be disable, polling or heartbeat. Default is disable.
	Mode                     string  `json:"mode,omitempty"`
	HeartbeatIntervalSeconds Seconds `json:"heartbeatIntervalSeconds,omitempty"`
}

ReplicationTrackerConfig contains the config for the replication tracker.

type Seconds

type Seconds float64

Seconds provides convenience functions for extracting duration from flaot64 seconds values.

func (Seconds) Get

func (s Seconds) Get() time.Duration

Get converts Seconds to time.Duration

func (*Seconds) Set

func (s *Seconds) Set(d time.Duration)

Set sets the value from time.Duration

type Stats

type Stats struct {
	MySQLTimings           *servenv.TimingsWrapper        // Time spent executing MySQL commands
	QueryTimings           *servenv.TimingsWrapper        // Query timings
	QPSRates               *stats.Rates                   // Human readable QPS rates
	WaitTimings            *servenv.TimingsWrapper        // waits like Consolidations etc
	KillCounters           *stats.CountersWithSingleLabel // Connection and transaction kills
	ErrorCounters          *stats.CountersWithSingleLabel
	InternalErrors         *stats.CountersWithSingleLabel
	Warnings               *stats.CountersWithSingleLabel
	Unresolved             *stats.GaugesWithSingleLabel   // For now, only Prepares are tracked
	UserTableQueryCount    *stats.CountersWithMultiLabels // Per CallerID/table counts
	UserTableQueryTimesNs  *stats.CountersWithMultiLabels // Per CallerID/table latencies
	UserTransactionCount   *stats.CountersWithMultiLabels // Per CallerID transaction counts
	UserTransactionTimesNs *stats.CountersWithMultiLabels // Per CallerID transaction latencies
	ResultHistogram        *stats.Histogram               // Row count histograms
	TableaclAllowed        *stats.CountersWithMultiLabels // Number of allows
	TableaclDenied         *stats.CountersWithMultiLabels // Number of denials
	TableaclPseudoDenied   *stats.CountersWithMultiLabels // Number of pseudo denials

	UserActiveReservedCount *stats.CountersWithSingleLabel // Per CallerID active reserved connection counts
	UserReservedCount       *stats.CountersWithSingleLabel // Per CallerID reserved connection counts
	UserReservedTimesNs     *stats.CountersWithSingleLabel // Per CallerID reserved connection duration
}

Stats contains tracked by various parts of TabletServer.

func NewStats

func NewStats(exporter *servenv.Exporter) *Stats

NewStats instantiates a new set of stats scoped by exporter.

type TabletConfig

type TabletConfig struct {
	DB *dbconfigs.DBConfigs `json:"db,omitempty"`

	OltpReadPool ConnPoolConfig `json:"oltpReadPool,omitempty"`
	OlapReadPool ConnPoolConfig `json:"olapReadPool,omitempty"`
	TxPool       ConnPoolConfig `json:"txPool,omitempty"`

	Oltp             OltpConfig             `json:"oltp,omitempty"`
	HotRowProtection HotRowProtectionConfig `json:"hotRowProtection,omitempty"`

	Healthcheck  HealthcheckConfig  `json:"healthcheck,omitempty"`
	GracePeriods GracePeriodsConfig `json:"gracePeriods,omitempty"`

	ReplicationTracker ReplicationTrackerConfig `json:"replicationTracker,omitempty"`

	// Consolidator can be enable, disable, or notOnPrimary. Default is enable.
	// notOnMaster is the deprecated value that is the same as notOnPrimary.
	Consolidator                            string  `json:"consolidator,omitempty"`
	PassthroughDML                          bool    `json:"passthroughDML,omitempty"`
	StreamBufferSize                        int     `json:"streamBufferSize,omitempty"`
	ConsolidatorStreamTotalSize             int64   `json:"consolidatorStreamTotalSize,omitempty"`
	ConsolidatorStreamQuerySize             int64   `json:"consolidatorStreamQuerySize,omitempty"`
	QueryCacheSize                          int     `json:"queryCacheSize,omitempty"`
	QueryCacheMemory                        int64   `json:"queryCacheMemory,omitempty"`
	QueryCacheLFU                           bool    `json:"queryCacheLFU,omitempty"`
	SchemaReloadIntervalSeconds             Seconds `json:"schemaReloadIntervalSeconds,omitempty"`
	SignalSchemaChangeReloadIntervalSeconds Seconds `json:"signalSchemaChangeReloadIntervalSeconds,omitempty"`
	WatchReplication                        bool    `json:"watchReplication,omitempty"`
	TrackSchemaVersions                     bool    `json:"trackSchemaVersions,omitempty"`
	TerseErrors                             bool    `json:"terseErrors,omitempty"`
	AnnotateQueries                         bool    `json:"annotateQueries,omitempty"`
	MessagePostponeParallelism              int     `json:"messagePostponeParallelism,omitempty"`
	CacheResultFields                       bool    `json:"cacheResultFields,omitempty"`
	SignalWhenSchemaChange                  bool    `json:"signalWhenSchemaChange,omitempty"`

	ExternalConnections map[string]*dbconfigs.DBConfigs `json:"externalConnections,omitempty"`

	StrictTableACL          bool    `json:"-"`
	EnableTableACLDryRun    bool    `json:"-"`
	TableACLExemptACL       string  `json:"-"`
	TwoPCEnable             bool    `json:"-"`
	TwoPCCoordinatorAddress string  `json:"-"`
	TwoPCAbandonAge         Seconds `json:"-"`

	EnableTxThrottler           bool     `json:"-"`
	TxThrottlerConfig           string   `json:"-"`
	TxThrottlerHealthCheckCells []string `json:"-"`

	EnableLagThrottler bool `json:"-"`

	TransactionLimitConfig `json:"-"`

	EnforceStrictTransTables bool `json:"-"`
	EnableOnlineDDL          bool `json:"-"`
}

TabletConfig contains all the configuration for query service

func NewCurrentConfig

func NewCurrentConfig() *TabletConfig

NewCurrentConfig returns a copy of the current config.

func NewDefaultConfig

func NewDefaultConfig() *TabletConfig

NewDefaultConfig returns a new TabletConfig with pre-initialized defaults.

func (*TabletConfig) Clone

func (c *TabletConfig) Clone() *TabletConfig

Clone creates a clone of TabletConfig.

func (*TabletConfig) Verify

func (c *TabletConfig) Verify() error

Verify checks for contradicting flags.

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