From 80f36999a03caac2c4533c217f856631154d1e77 Mon Sep 17 00:00:00 2001 From: Shengzhe Yao Date: Tue, 21 Apr 2015 11:05:13 -0700 Subject: [PATCH] use an empty name to prevent publishing stats 1. add name to SqlQuery, QueryEngine and SchemaInfo. 2. queryservice component will stop publishing stats if its name is empty. --- go/vt/tabletserver/cache_pool_test.go | 10 +++- go/vt/tabletserver/query_engine.go | 48 +++++++++++++----- go/vt/tabletserver/query_executor_test.go | 2 +- go/vt/tabletserver/queryctl.go | 2 +- go/vt/tabletserver/schema_info.go | 22 +++++--- go/vt/tabletserver/schema_info_test.go | 18 +++++-- go/vt/tabletserver/sqlquery.go | 26 ++++++---- go/vt/tabletserver/sqlquery_test.go | 62 ++++++++++++++--------- go/vt/tabletserver/table_info_test.go | 3 +- go/vt/tabletserver/testutils_test.go | 20 ++++++++ go/vt/tabletserver/tx_pool.go | 10 ++-- go/vt/tabletserver/tx_pool_test.go | 19 ++++++- 12 files changed, 173 insertions(+), 69 deletions(-) diff --git a/go/vt/tabletserver/cache_pool_test.go b/go/vt/tabletserver/cache_pool_test.go index 1d02262a706..e8e3c1ae5f8 100644 --- a/go/vt/tabletserver/cache_pool_test.go +++ b/go/vt/tabletserver/cache_pool_test.go @@ -105,7 +105,7 @@ func TestCachePoolState(t *testing.T) { Binary: "ls", Connections: 100, } - cachePool := newTestCachePool(rowCacheConfig) + cachePool := newTestCachePoolWithStats(rowCacheConfig) idleTimeout := 1 * time.Second cachePool.idleTimeout = idleTimeout cachePool.Open() @@ -204,9 +204,15 @@ func TestCachePoolStatsURL(t *testing.T) { cachePool.ServeHTTP(response, request) } -func newTestCachePool(rowcacheConfig RowCacheConfig) *CachePool { +func newTestCachePoolWithStats(rowcacheConfig RowCacheConfig) *CachePool { randID := rand.Int63() name := fmt.Sprintf("TestCachePool-%d-", randID) statsURL := fmt.Sprintf("/debug/cache-%d", randID) return NewCachePool(name, rowcacheConfig, 1*time.Second, statsURL) } + +func newTestCachePool(rowcacheConfig RowCacheConfig) *CachePool { + randID := rand.Int63() + statsURL := fmt.Sprintf("/debug/cache-%d", randID) + return NewCachePool("", rowcacheConfig, 1*time.Second, statsURL) +} diff --git a/go/vt/tabletserver/query_engine.go b/go/vt/tabletserver/query_engine.go index 4c7e0436e82..1447ec53d7a 100644 --- a/go/vt/tabletserver/query_engine.go +++ b/go/vt/tabletserver/query_engine.go @@ -40,6 +40,7 @@ const spotCheckMultiplier = 1e6 // panic with NewTabletError as the error type. // TODO(sougou): Switch to error return scheme. type QueryEngine struct { + name string schemaInfo *SchemaInfo dbconfigs *dbconfigs.DBConfigs @@ -114,9 +115,25 @@ func getOrPanic(ctx context.Context, pool *ConnPool) *DBConn { // NewQueryEngine creates a new QueryEngine. // This is a singleton class. // You must call this only once. -func NewQueryEngine(config Config) *QueryEngine { - qe := &QueryEngine{} +func NewQueryEngine(config Config, name string) *QueryEngine { + qe := &QueryEngine{name: name} + + var schemaInfoName string + var cachePoolName string + var connPoolName string + var streamConnPoolName string + var txPoolName string + + if name != "" { + schemaInfoName = config.PoolNamePrefix + "SchemaInfo" + cachePoolName = config.PoolNamePrefix + "Rowcache" + connPoolName = config.PoolNamePrefix + "ConnPool" + streamConnPoolName = config.PoolNamePrefix + "StreamConnPool" + txPoolName = config.PoolNamePrefix + "TransactionPool" + } + qe.schemaInfo = NewSchemaInfo( + schemaInfoName, config.QueryCacheSize, config.StatsPrefix, map[string]string{ @@ -133,25 +150,25 @@ func NewQueryEngine(config Config) *QueryEngine { // Pools qe.cachePool = NewCachePool( - config.PoolNamePrefix+"Rowcache", + cachePoolName, config.RowCache, time.Duration(config.IdleTimeout*1e9), config.DebugURLPrefix+"/memcache/", ) qe.connPool = NewConnPool( - config.PoolNamePrefix+"ConnPool", + connPoolName, config.PoolSize, time.Duration(config.IdleTimeout*1e9), ) qe.streamConnPool = NewConnPool( - config.PoolNamePrefix+"StreamConnPool", + streamConnPoolName, config.StreamPoolSize, time.Duration(config.IdleTimeout*1e9), ) // Services qe.txPool = NewTxPool( - config.PoolNamePrefix+"TransactionPool", + txPoolName, config.StatsPrefix, config.TransactionCap, time.Duration(config.TransactionTimeout*1e9), @@ -177,11 +194,6 @@ func NewQueryEngine(config Config) *QueryEngine { // loggers qe.accessCheckerLogger = logutil.NewThrottledLogger("accessChecker", 1*time.Second) - // Stats - stats.Publish(config.StatsPrefix+"MaxResultSize", stats.IntFunc(qe.maxResultSize.Get)) - stats.Publish(config.StatsPrefix+"MaxDMLRows", stats.IntFunc(qe.maxDMLRows.Get)) - stats.Publish(config.StatsPrefix+"StreamBufferSize", stats.IntFunc(qe.streamBufferSize.Get)) - stats.Publish(config.StatsPrefix+"QueryTimeout", stats.DurationFunc(qe.queryTimeout.Get)) queryStats = stats.NewTimings(config.StatsPrefix + "Queries") qpsRates = stats.NewRates(config.StatsPrefix+"QPS", queryStats, 15, 60*time.Second) waitStats = stats.NewTimings(config.StatsPrefix + "Waits") @@ -190,11 +202,19 @@ func NewQueryEngine(config Config) *QueryEngine { errorStats = stats.NewCounters(config.StatsPrefix + "Errors") internalErrors = stats.NewCounters(config.StatsPrefix + "InternalErrors") resultStats = stats.NewHistogram(config.StatsPrefix+"Results", resultBuckets) - stats.Publish(config.StatsPrefix+"RowcacheSpotCheckRatio", stats.FloatFunc(func() float64 { - return float64(qe.spotCheckFreq.Get()) / spotCheckMultiplier - })) spotCheckCount = stats.NewInt(config.StatsPrefix + "RowcacheSpotCheckCount") + // Stats + if name != "" { + stats.Publish(config.StatsPrefix+"MaxResultSize", stats.IntFunc(qe.maxResultSize.Get)) + stats.Publish(config.StatsPrefix+"MaxDMLRows", stats.IntFunc(qe.maxDMLRows.Get)) + stats.Publish(config.StatsPrefix+"StreamBufferSize", stats.IntFunc(qe.streamBufferSize.Get)) + stats.Publish(config.StatsPrefix+"QueryTimeout", stats.DurationFunc(qe.queryTimeout.Get)) + stats.Publish(config.StatsPrefix+"RowcacheSpotCheckRatio", stats.FloatFunc(func() float64 { + return float64(qe.spotCheckFreq.Get()) / spotCheckMultiplier + })) + } + return qe } diff --git a/go/vt/tabletserver/query_executor_test.go b/go/vt/tabletserver/query_executor_test.go index 5e831f3b181..a34d4e8eff7 100644 --- a/go/vt/tabletserver/query_executor_test.go +++ b/go/vt/tabletserver/query_executor_test.go @@ -746,7 +746,7 @@ func newTestQueryExecutor(sql string, ctx context.Context, flags executorFlags) } else { config.StrictTableAcl = false } - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") txID := int64(0) dbconfigs := newTestDBConfigs() if flags&enableRowCache > 0 { diff --git a/go/vt/tabletserver/queryctl.go b/go/vt/tabletserver/queryctl.go index 74df606fcff..8ccabc78283 100644 --- a/go/vt/tabletserver/queryctl.go +++ b/go/vt/tabletserver/queryctl.go @@ -262,7 +262,7 @@ type realQueryServiceControl struct { // NewQueryServiceControl returns a real implementation of QueryServiceControl func NewQueryServiceControl() QueryServiceControl { return &realQueryServiceControl{ - sqlQueryRPCService: NewSqlQuery(qsConfig), + sqlQueryRPCService: NewSqlQuery(qsConfig, "SqlQuery"), } } diff --git a/go/vt/tabletserver/schema_info.go b/go/vt/tabletserver/schema_info.go index 85972ed224c..64acba7801d 100644 --- a/go/vt/tabletserver/schema_info.go +++ b/go/vt/tabletserver/schema_info.go @@ -100,6 +100,7 @@ type SchemaOverride struct { // keep itself and the rowcache up-to-date. type SchemaInfo struct { mu sync.Mutex + name string tables map[string]*TableInfo overrides []SchemaOverride queries *cache.LRUCache @@ -113,12 +114,14 @@ type SchemaInfo struct { // NewSchemaInfo creates a new SchemaInfo. func NewSchemaInfo( + name string, queryCacheSize int, statsPrefix string, endpoints map[string]string, reloadTime time.Duration, idleTimeout time.Duration) *SchemaInfo { si := &SchemaInfo{ + name: name, queries: cache.NewLRUCache(int64(queryCacheSize)), connPool: NewConnPool("", 2, idleTimeout), ticks: timer.NewTimer(reloadTime), @@ -131,16 +134,21 @@ func NewSchemaInfo( stats.Publish(statsPrefix+"QueryCacheOldest", stats.StringFunc(func() string { return fmt.Sprintf("%v", si.queries.Oldest()) })) - stats.Publish(statsPrefix+"SchemaReloadTime", stats.DurationFunc(si.ticks.Interval)) - _ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheStats", []string{"Table", "Stats"}, si.getRowcacheStats) - _ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheInvalidations", []string{"Table"}, si.getRowcacheInvalidations) - _ = stats.NewMultiCountersFunc(statsPrefix+"QueryCounts", []string{"Table", "Plan"}, si.getQueryCount) - _ = stats.NewMultiCountersFunc(statsPrefix+"QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime) - _ = stats.NewMultiCountersFunc(statsPrefix+"QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount) - _ = stats.NewMultiCountersFunc(statsPrefix+"QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount) + for _, ep := range endpoints { http.Handle(ep, si) } + + if name != "" { + stats.Publish(statsPrefix+"SchemaReloadTime", stats.DurationFunc(si.ticks.Interval)) + _ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheStats", []string{"Table", "Stats"}, si.getRowcacheStats) + _ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheInvalidations", []string{"Table"}, si.getRowcacheInvalidations) + _ = stats.NewMultiCountersFunc(statsPrefix+"QueryCounts", []string{"Table", "Plan"}, si.getQueryCount) + _ = stats.NewMultiCountersFunc(statsPrefix+"QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime) + _ = stats.NewMultiCountersFunc(statsPrefix+"QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount) + _ = stats.NewMultiCountersFunc(statsPrefix+"QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount) + } + return si } diff --git a/go/vt/tabletserver/schema_info_test.go b/go/vt/tabletserver/schema_info_test.go index 5c1819d08dc..8eb6fa68d2f 100644 --- a/go/vt/tabletserver/schema_info_test.go +++ b/go/vt/tabletserver/schema_info_test.go @@ -416,10 +416,10 @@ func TestSchemaInfoQueryCache(t *testing.T) { for query, result := range getSchemaInfoTestSupportedQueries() { db.AddQuery(query, result) } - schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second) + schemaInfo := newTestSchemaInfoWithStats(10, 10*time.Second, 10*time.Second) appParams := sqldb.ConnParams{} dbaParams := sqldb.ConnParams{} - cachePool := newTestSchemaInfoCachePool() + cachePool := newTestSchemaInfoCachePoolWithStats() cachePool.Open() defer cachePool.Close() schemaOverrides := getSchemaInfoTestSchemaOverride() @@ -452,10 +452,10 @@ func TestSchemaInfoExportVars(t *testing.T) { for query, result := range getSchemaInfoTestSupportedQueries() { db.AddQuery(query, result) } - schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second) + schemaInfo := newTestSchemaInfoWithStats(10, 1*time.Second, 1*time.Second) appParams := sqldb.ConnParams{} dbaParams := sqldb.ConnParams{} - cachePool := newTestSchemaInfoCachePool() + cachePool := newTestSchemaInfoCachePoolWithStats() cachePool.Open() defer cachePool.Close() schemaInfo.Open(&appParams, &dbaParams, []SchemaOverride{}, cachePool, true) @@ -507,6 +507,16 @@ func TestSchemaInfoStatsURL(t *testing.T) { } func newTestSchemaInfoCachePool() *CachePool { + rowCacheConfig := RowCacheConfig{ + Binary: "ls", + Connections: 100, + } + randID := rand.Int63() + statsURL := fmt.Sprintf("/debug/cache-%d", randID) + return NewCachePool("", rowCacheConfig, 1*time.Second, statsURL) +} + +func newTestSchemaInfoCachePoolWithStats() *CachePool { rowCacheConfig := RowCacheConfig{ Binary: "ls", Connections: 100, diff --git a/go/vt/tabletserver/sqlquery.go b/go/vt/tabletserver/sqlquery.go index cb89a9ecfb8..6b3e97c2b1c 100644 --- a/go/vt/tabletserver/sqlquery.go +++ b/go/vt/tabletserver/sqlquery.go @@ -64,6 +64,7 @@ var stateName = []string{ // SqlQuery implements the RPC interface for the query service. type SqlQuery struct { + name string config Config // mu is used to access state. It's also used to ensure // that state does not change out of StateServing or StateShuttingTx @@ -86,18 +87,25 @@ type SqlQuery struct { // NewSqlQuery creates an instance of SqlQuery. Only one instance // of SqlQuery can be created per process. -func NewSqlQuery(config Config) *SqlQuery { +func NewSqlQuery(config Config, name string) *SqlQuery { sq := &SqlQuery{ config: config, + name: name, + } + var queryEngineName string + if name != "" { + queryEngineName = name + "QueryEngine" + } + sq.qe = NewQueryEngine(config, queryEngineName) + if name != "" { + stats.Publish(config.StatsPrefix+"TabletState", stats.IntFunc(func() int64 { + sq.mu.Lock() + state := sq.state + sq.mu.Unlock() + return state + })) + stats.Publish(config.StatsPrefix+"TabletStateName", stats.StringFunc(sq.GetState)) } - sq.qe = NewQueryEngine(config) - stats.Publish(config.StatsPrefix+"TabletState", stats.IntFunc(func() int64 { - sq.mu.Lock() - state := sq.state - sq.mu.Unlock() - return state - })) - stats.Publish(config.StatsPrefix+"TabletStateName", stats.StringFunc(sq.GetState)) return sq } diff --git a/go/vt/tabletserver/sqlquery_test.go b/go/vt/tabletserver/sqlquery_test.go index e281c9eeab2..5ca460bd17c 100644 --- a/go/vt/tabletserver/sqlquery_test.go +++ b/go/vt/tabletserver/sqlquery_test.go @@ -5,8 +5,10 @@ package tabletserver import ( + "expvar" "fmt" "math/rand" + "strconv" "testing" "time" @@ -24,7 +26,7 @@ func TestSqlQueryAllowQueriesFailBadConn(t *testing.T) { db := setUpSqlQueryTest() db.EnableConnFail() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") checkSqlQueryState(t, sqlQuery, "NOT_SERVING") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -39,7 +41,7 @@ func TestSqlQueryAllowQueriesFailStrictModeConflictWithRowCache(t *testing.T) { config := newTestSqlQueryConfig() // disable strict mode config.StrictMode = false - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") checkSqlQueryState(t, sqlQuery, "NOT_SERVING") dbconfigs := newTestDBConfigs() // enable rowcache @@ -54,7 +56,7 @@ func TestSqlQueryAllowQueriesFailStrictModeConflictWithRowCache(t *testing.T) { func TestSqlQueryAllowQueries(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") checkSqlQueryState(t, sqlQuery, "NOT_SERVING") dbconfigs := newTestDBConfigs() sqlQuery.setState(StateServing) @@ -74,7 +76,7 @@ func TestSqlQueryAllowQueries(t *testing.T) { func TestSqlQueryCheckMysql(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) defer sqlQuery.disallowQueries() @@ -89,7 +91,7 @@ func TestSqlQueryCheckMysql(t *testing.T) { func TestSqlQueryCheckMysqlFailInvalidConn(t *testing.T) { db := setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) defer sqlQuery.disallowQueries() @@ -106,7 +108,7 @@ func TestSqlQueryCheckMysqlFailInvalidConn(t *testing.T) { func TestSqlQueryCheckMysqlFailUninitializedQueryEngine(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() // this causes QueryEngine not being initialized properly sqlQuery.setState(StateServing) @@ -124,19 +126,31 @@ func TestSqlQueryCheckMysqlFailUninitializedQueryEngine(t *testing.T) { func TestSqlQueryCheckMysqlInNotServingState(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "SqlQuery") // sqlquery start request fail because we are in StateNotServing; // however, checkMySQL should return true. Here, we always assume // MySQL is healthy unless we've verified it is not. if !sqlQuery.checkMySQL() { t.Fatalf("checkMySQL should return true") } + + tabletState := expvar.Get(config.StatsPrefix + "TabletState") + if tabletState == nil { + t.Fatalf("%sTabletState should be exported", config.StatsPrefix) + } + varzState, err := strconv.Atoi(tabletState.String()) + if err != nil { + t.Fatalf("invalid state reported by expvar, should be a valid state code, but got: %s", tabletState.String()) + } + if varzState != StateNotServing { + t.Fatalf("queryservice should be in NOT_SERVING state, but exported varz reports: %s", stateName[varzState]) + } } func TestSqlQueryGetSessionId(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") if err := sqlQuery.GetSessionId(nil, nil); err == nil { t.Fatalf("call GetSessionId should get an error") } @@ -180,7 +194,7 @@ func TestSqlQueryGetSessionId(t *testing.T) { func TestSqlQueryCommandFailUnMatchedSessionId(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -282,7 +296,7 @@ func TestSqlQueryCommitTransaciton(t *testing.T) { } db.AddQuery(executeSql, executeSqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -327,7 +341,7 @@ func TestSqlQueryRollback(t *testing.T) { db.AddQuery(executeSql, executeSqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -372,7 +386,7 @@ func TestSqlQueryStreamExecute(t *testing.T) { db.AddQuery(executeSql, executeSqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -420,7 +434,7 @@ func TestSqlQueryExecuteBatch(t *testing.T) { db.AddQuery(expanedSql, sqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -463,7 +477,7 @@ func TestSqlQueryExecuteBatch(t *testing.T) { func TestSqlQueryExecuteBatchFailEmptyQueryList(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -488,7 +502,7 @@ func TestSqlQueryExecuteBatchBeginFail(t *testing.T) { // make "begin" query fail db.AddRejectedQuery("begin") config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -521,7 +535,7 @@ func TestSqlQueryExecuteBatchCommitFail(t *testing.T) { // make "commit" query fail db.AddRejectedQuery("commit") config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -568,7 +582,7 @@ func TestSqlQueryExecuteBatchSqlExecFailInTransaction(t *testing.T) { db.AddRejectedQuery(expanedSql) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -626,7 +640,7 @@ func TestSqlQueryExecuteBatchFailBeginWithoutCommit(t *testing.T) { db.AddQuery(expanedSql, sqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -682,7 +696,7 @@ func TestSqlQueryExecuteBatchSqlExecFailNotInTransaction(t *testing.T) { db.AddRejectedQuery(sql) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -714,7 +728,7 @@ func TestSqlQueryExecuteBatchSqlExecFailNotInTransaction(t *testing.T) { func TestSqlQueryExecuteBatchCallCommitWithoutABegin(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) if err != nil { @@ -752,7 +766,7 @@ func TestExecuteBatchNestedTransaction(t *testing.T) { db.AddQuery(expanedSql, sqlResult) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -806,7 +820,7 @@ func TestSqlQuerySplitQuery(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -845,7 +859,7 @@ func TestSqlQuerySplitQueryInvalidQuery(t *testing.T) { setUpSqlQueryTest() config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) @@ -899,7 +913,7 @@ func TestSqlQuerySplitQueryInvalidMinMax(t *testing.T) { db.AddQuery(pkMinMaxQuery, pkMinMaxQueryResp) config := newTestSqlQueryConfig() - sqlQuery := NewSqlQuery(config) + sqlQuery := NewSqlQuery(config, "") dbconfigs := newTestDBConfigs() err := sqlQuery.allowQueries(&dbconfigs, []SchemaOverride{}, newMysqld(&dbconfigs)) diff --git a/go/vt/tabletserver/table_info_test.go b/go/vt/tabletserver/table_info_test.go index c3aa5e4374d..706526478c5 100644 --- a/go/vt/tabletserver/table_info_test.go +++ b/go/vt/tabletserver/table_info_test.go @@ -293,9 +293,8 @@ func newTestTableInfoCachePool() *CachePool { Connections: 100, } randID := rand.Int63() - name := fmt.Sprintf("TestCachePool-TableInfo-%d-", randID) statsURL := fmt.Sprintf("/debug/tableinfo-cache-%d", randID) - return NewCachePool(name, rowCacheConfig, 1*time.Second, statsURL) + return NewCachePool("", rowCacheConfig, 1*time.Second, statsURL) } func getTestTableInfoQueries() map[string]*mproto.QueryResult { diff --git a/go/vt/tabletserver/testutils_test.go b/go/vt/tabletserver/testutils_test.go index 29881e3e07f..72af798f3b5 100644 --- a/go/vt/tabletserver/testutils_test.go +++ b/go/vt/tabletserver/testutils_test.go @@ -44,12 +44,32 @@ func (util *testUtils) checkEqual(t *testing.T, expected interface{}, result int } } +func newTestSchemaInfoWithStats( + queryCacheSize int, + reloadTime time.Duration, + idleTimeout time.Duration) *SchemaInfo { + randID := rand.Int63() + return NewSchemaInfo( + fmt.Sprintf("SchemaInfo-%d-", randID), + queryCacheSize, + fmt.Sprintf("TestSchemaInfo-%d-", randID), + map[string]string{ + debugQueryPlansKey: fmt.Sprintf("/debug/query_plans_%d", randID), + debugQueryStatsKey: fmt.Sprintf("/debug/query_stats_%d", randID), + debugTableStatsKey: fmt.Sprintf("/debug/table_stats_%d", randID), + debugSchemaKey: fmt.Sprintf("/debug/schema_%d", randID), + }, + reloadTime, + idleTimeout) +} + func newTestSchemaInfo( queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration) *SchemaInfo { randID := rand.Int63() return NewSchemaInfo( + "", queryCacheSize, fmt.Sprintf("TestSchemaInfo-%d-", randID), map[string]string{ diff --git a/go/vt/tabletserver/tx_pool.go b/go/vt/tabletserver/tx_pool.go index 20c012125f9..93b698105ee 100644 --- a/go/vt/tabletserver/tx_pool.go +++ b/go/vt/tabletserver/tx_pool.go @@ -75,10 +75,12 @@ func NewTxPool( ticks: timer.NewTimer(timeout / 10), txStats: stats.NewTimings(txStatsPrefix + "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)) + if name != "" { + // 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 } diff --git a/go/vt/tabletserver/tx_pool_test.go b/go/vt/tabletserver/tx_pool_test.go index 0901e1f1ed8..a204652169a 100644 --- a/go/vt/tabletserver/tx_pool_test.go +++ b/go/vt/tabletserver/tx_pool_test.go @@ -21,7 +21,7 @@ func TestExecuteCommit(t *testing.T) { tableName := "test_table" sql := fmt.Sprintf("ALTER TABLE %s ADD test_column INT", tableName) fakesqldb.Register() - txPool := newTxPool() + txPool := newTxPoolWithStats() txPool.SetTimeout(1 * time.Second) txPool.SetPoolTimeout(1 * time.Second) appParams := sqldb.ConnParams{} @@ -238,6 +238,23 @@ func TestTxPoolExecFailDueToConnFail(t *testing.T) { } func newTxPool() *TxPool { + randID := rand.Int63() + txStatsPrefix := fmt.Sprintf("TxStats-%d-", randID) + transactionCap := 300 + transactionTimeout := time.Duration(30 * time.Second) + txPoolTimeout := time.Duration(30 * time.Second) + idleTimeout := time.Duration(30 * time.Second) + return NewTxPool( + "", + txStatsPrefix, + transactionCap, + transactionTimeout, + txPoolTimeout, + idleTimeout, + ) +} + +func newTxPoolWithStats() *TxPool { randID := rand.Int63() poolName := fmt.Sprintf("TestTransactionPool-%d", randID) txStatsPrefix := fmt.Sprintf("TxStats-%d-", randID)