func NewTxPool(name string, capacity int, timeout, poolTimeout, idleTimeout time.Duration) *TxPool { axp := &TxPool{ pool: dbconnpool.NewConnectionPool(name, capacity, idleTimeout), activePool: pools.NewNumbered(), lastId: sync2.AtomicInt64(time.Now().UnixNano()), timeout: sync2.AtomicDuration(timeout), poolTimeout: sync2.AtomicDuration(poolTimeout), ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings("Transactions"), } // Careful: pool also exports name+"xxx" vars, // but we know it doesn't export Timeout. stats.Publish(name+"Timeout", stats.DurationFunc(axp.timeout.Get)) stats.Publish(name+"PoolTimeout", stats.DurationFunc(axp.poolTimeout.Get)) return axp }
// NewMysqld creates a Mysqld object based on the provided configuration // and connection parameters. // name is the base for stats exports, use 'Dba', except in tests func NewMysqld(name string, config *Mycnf, dba, repl *mysql.ConnectionParams) *Mysqld { if *dba == dbconfigs.DefaultDBConfigs.Dba { dba.UnixSocket = config.SocketFile } // create and open the connection pool for dba access mysqlStats := stats.NewTimings("Mysql" + name) dbaPool := dbconnpool.NewConnectionPool(name+"ConnPool", *dbaPoolSize, *dbaIdleTimeout) dbaPool.Open(dbconnpool.DBConnectionCreator(dba, mysqlStats)) return &Mysqld{ config: config, dba: dba, dbaPool: dbaPool, replParams: repl, TabletDir: TabletDir(config.ServerId), SnapshotDir: SnapshotDir(config.ServerId), } }
// Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package tabletserver import ( "encoding/binary" "strconv" "time" "github.com/henryanand/vitess/go/sqltypes" "github.com/henryanand/vitess/go/stats" "github.com/henryanand/vitess/go/vt/schema" ) var cacheStats = stats.NewTimings("Rowcache") var pack = binary.BigEndian const ( RC_DELETED = 1 // MAX_KEY_LEN is a value less than memcache's limit of 250. MAX_KEY_LEN = 200 // MAX_DATA_LEN prevents large rows from being inserted in rowcache. MAX_DATA_LEN = 8000 ) type RowCache struct { tableInfo *TableInfo
// NewQueryEngine creates a new QueryEngine. // This is a singleton class. // You must call this only once. func NewQueryEngine(config Config) *QueryEngine { qe := &QueryEngine{} qe.schemaInfo = NewSchemaInfo( config.QueryCacheSize, time.Duration(config.SchemaReloadTime*1e9), time.Duration(config.IdleTimeout*1e9), ) qe.queryRuleInfo = NewQueryRuleInfo() mysqlStats = stats.NewTimings("Mysql") // Pools qe.cachePool = NewCachePool( "Rowcache", config.RowCache, time.Duration(config.QueryTimeout*1e9), time.Duration(config.IdleTimeout*1e9), ) qe.connPool = dbconnpool.NewConnectionPool( "ConnPool", config.PoolSize, time.Duration(config.IdleTimeout*1e9), ) qe.streamConnPool = dbconnpool.NewConnectionPool( "StreamConnPool", config.StreamPoolSize, time.Duration(config.IdleTimeout*1e9), ) // Services qe.txPool = NewTxPool( "TransactionPool", config.TransactionCap, time.Duration(config.TransactionTimeout*1e9), time.Duration(config.TxPoolTimeout*1e9), time.Duration(config.IdleTimeout*1e9), ) qe.connKiller = NewConnectionKiller(1, time.Duration(config.IdleTimeout*1e9)) qe.consolidator = NewConsolidator() qe.invalidator = NewRowcacheInvalidator(qe) qe.streamQList = NewQueryList(qe.connKiller) // Vars qe.queryTimeout.Set(time.Duration(config.QueryTimeout * 1e9)) qe.spotCheckFreq = sync2.AtomicInt64(config.SpotCheckRatio * spotCheckMultiplier) if config.StrictMode { qe.strictMode.Set(1) } qe.strictTableAcl = config.StrictTableAcl qe.maxResultSize = sync2.AtomicInt64(config.MaxResultSize) qe.maxDMLRows = sync2.AtomicInt64(config.MaxDMLRows) qe.streamBufferSize = sync2.AtomicInt64(config.StreamBufferSize) // loggers qe.accessCheckerLogger = logutil.NewThrottledLogger("accessChecker", 1*time.Second) // Stats stats.Publish("MaxResultSize", stats.IntFunc(qe.maxResultSize.Get)) stats.Publish("MaxDMLRows", stats.IntFunc(qe.maxDMLRows.Get)) stats.Publish("StreamBufferSize", stats.IntFunc(qe.streamBufferSize.Get)) stats.Publish("QueryTimeout", stats.DurationFunc(qe.queryTimeout.Get)) queryStats = stats.NewTimings("Queries") QPSRates = stats.NewRates("QPS", queryStats, 15, 60*time.Second) waitStats = stats.NewTimings("Waits") killStats = stats.NewCounters("Kills") infoErrors = stats.NewCounters("InfoErrors") errorStats = stats.NewCounters("Errors") internalErrors = stats.NewCounters("InternalErrors") resultStats = stats.NewHistogram("Results", resultBuckets) stats.Publish("RowcacheSpotCheckRatio", stats.FloatFunc(func() float64 { return float64(qe.spotCheckFreq.Get()) / spotCheckMultiplier })) spotCheckCount = stats.NewInt("RowcacheSpotCheckCount") return qe }
// NewBinlogPlayerStats creates a new BinlogPlayerStats structure func NewBinlogPlayerStats() *BinlogPlayerStats { bps := &BinlogPlayerStats{} bps.Timings = stats.NewTimings("") bps.Rates = stats.NewRates("", bps.Timings, 15, 60e9) return bps }