*: rename mockStatist to mockStatistics, and

do tiny clean
This commit is contained in:
xia
2015-11-18 13:33:38 +08:00
parent a7531125e8
commit 200686bd57
9 changed files with 23 additions and 81 deletions

View File

@ -39,16 +39,10 @@ var (
ddlJobArgs = "ddl_job_args"
)
var specificStatusScopes = map[string]variable.ScopeFlag{}
// GetScope gets the status variables scope.
func (d *ddl) GetScope(status string) variable.ScopeFlag {
scope, ok := specificStatusScopes[status]
if !ok {
scope = variable.DefaultScopeFlag
}
return scope
// Now ddl status variables scope are all default scope.
return variable.DefaultScopeFlag
}
// Stat returns the DDL statistics.

View File

@ -31,8 +31,6 @@ import (
var ddlLastReloadSchemaTS = "ddl_last_reload_schema_ts"
var specificStatusScopes = map[string]variable.ScopeFlag{}
// Domain represents a storage space. Different domains can use the same database name.
// Multiple domains can be used in parallel without synchronization.
type Domain struct {
@ -123,12 +121,8 @@ func (do *Domain) Stats() (map[string]interface{}, error) {
// GetScope gets the status variables scope.
func (do *Domain) GetScope(status string) variable.ScopeFlag {
scope, ok := specificStatusScopes[status]
if !ok {
scope = variable.DefaultScopeFlag
}
return scope
// Now domain status variables scope are all default scope.
return variable.DefaultScopeFlag
}
func (do *Domain) tryReload() {

View File

@ -32,9 +32,9 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/stmt"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/charset"
"github.com/pingcap/tidb/util/format"
"github.com/pingcap/tidb/util/types"
)
var (
@ -469,39 +469,22 @@ func (s *ShowPlan) fetchShowVariables(ctx context.Context) error {
}
func getSessionStatusVar(ctx context.Context, sessionVars *variable.SessionVars,
globalVars variable.GlobalVarAccessor, name string) (string, error) {
name string, globalVal *variable.StatusVal) (string, error) {
sv, ok := sessionVars.StatusVars[name]
if ok {
return sv, nil
}
value, err := globalVars.GetGlobalStatusVar(ctx, name)
if err != nil && terror.UnknownStatusVar.Equal(err) {
gv, err := types.ToString(globalVal.Value)
if err != nil {
return "", errors.Trace(err)
}
return value, nil
}
func getGlobalStatusVar(ctx context.Context, sessionVars *variable.SessionVars,
globalVars variable.GlobalVarAccessor, name string) (string, error) {
value, err := globalVars.GetGlobalStatusVar(ctx, name)
if err == nil {
return value, nil
}
if terror.UnknownStatusVar.Equal(err) {
return "", errors.Trace(err)
}
sv, _ := sessionVars.StatusVars[name]
return sv, nil
return gv, nil
}
func (s *ShowPlan) fetchShowStatus(ctx context.Context) error {
sessionVars := variable.GetSessionVars(ctx)
globalVars := variable.GetGlobalVarAccessor(ctx)
m := map[interface{}]interface{}{}
statusVars, err := variable.GetStatusVars()
@ -532,12 +515,12 @@ func (s *ShowPlan) fetchShowStatus(ctx context.Context) error {
var value string
if !s.GlobalScope {
value, err = getSessionStatusVar(ctx, sessionVars, globalVars, status)
value, err = getSessionStatusVar(ctx, sessionVars, status, v)
if err != nil {
return errors.Trace(err)
}
} else if v.Scope != variable.ScopeSession {
value, err = getGlobalStatusVar(ctx, sessionVars, globalVars, status)
value, err = types.ToString(v.Value)
if err != nil {
return errors.Trace(err)
}

View File

@ -35,7 +35,7 @@ import (
type testShowSuit struct {
txn kv.Transaction
ctx context.Context
ms *MockStatist
ms *MockStatistics
store kv.Storage
dbName string
@ -184,8 +184,8 @@ func (p *testShowSuit) TestShowSysVariables(c *C) {
c.Assert(v, Equals, "on")
}
// MockStatist represents mocked statist.
type MockStatist struct{}
// MockStatistics represents mocked statistics.
type MockStatistics struct{}
const (
testStatusSessionScope = "test_status_session_scope"
@ -199,11 +199,11 @@ var statusScopes map[string]variable.ScopeFlag = map[string]variable.ScopeFlag{
testStatusBothScopes: variable.ScopeGlobal,
}
func (ms *MockStatist) GetScope(status string) variable.ScopeFlag {
func (ms *MockStatistics) GetScope(status string) variable.ScopeFlag {
return statusScopes[status]
}
func (ms *MockStatist) Stats() (map[string]interface{}, error) {
func (ms *MockStatistics) Stats() (map[string]interface{}, error) {
m := make(map[string]interface{}, len(statusScopes))
m[testStatusSessionScope] = testStatusValSessionScope
m[testStatusBothScopes] = testStatusValBothScope

View File

@ -319,11 +319,6 @@ func (s *session) getExecRet(ctx context.Context, sql string) (string, error) {
// GetGlobalStatusVar implements GlobalVarAccessor.GetGlobalStatusVar interface.
func (s *session) GetGlobalStatusVar(ctx context.Context, name string) (string, error) {
sv := variable.GetStatusVar(name)
if sv != nil {
return types.ToString(sv.Value)
}
sql := fmt.Sprintf(`SELECT VARIABLE_VALUE FROM %s.%s WHERE VARIABLE_NAME="%s";`,
mysql.SystemDB, mysql.GlobalStatusTable, name)
val, err := s.getExecRet(ctx, sql)

View File

@ -82,7 +82,7 @@ func GetStatusVar(name string) *StatusVal {
}
// GetDefaultStatusVars gets status variables from the global status variables table.
// TODO: Fill status variables.
// TODO: Fill default status variables.
func GetDefaultStatusVars() (map[string]*StatusVal, error) {
return nil, nil
}

View File

@ -20,16 +20,16 @@ import (
var _ = Suite(&testStatusVarSuite{})
type testStatusVarSuite struct {
ms *mockStatist
ms *mockStatistics
}
func (s *testStatusVarSuite) SetUpSuite(c *C) {
s.ms = &mockStatist{}
s.ms = &mockStatistics{}
RegisterStatistics(s.ms)
}
// mockStatist represents mocked statist.
type mockStatist struct{}
// mockStatistics represents mocked statistics.
type mockStatistics struct{}
const (
testStatus = "test_status"
@ -41,7 +41,7 @@ var specificStatusScopes = map[string]ScopeFlag{
testSessionStatus: ScopeSession,
}
func (ms *mockStatist) GetScope(status string) ScopeFlag {
func (ms *mockStatistics) GetScope(status string) ScopeFlag {
scope, ok := specificStatusScopes[status]
if !ok {
return DefaultScopeFlag
@ -50,7 +50,7 @@ func (ms *mockStatist) GetScope(status string) ScopeFlag {
return scope
}
func (ms *mockStatist) Stats() (map[string]interface{}, error) {
func (ms *mockStatistics) Stats() (map[string]interface{}, error) {
m := make(map[string]interface{}, len(specificStatusScopes))
m[testStatus] = testStatusVal

View File

@ -580,10 +580,6 @@ type GlobalVarAccessor interface {
GetGlobalSysVar(ctx context.Context, name string) (string, error)
// SetGlobalSysVar sets the global system variable name to value.
SetGlobalSysVar(ctx context.Context, name string, value string) error
// GetGlobalStatusVar gets the global status variable value for name.
GetGlobalStatusVar(ctx context.Context, name string) (string, error)
// SetGlobalStatusVar sets the global status variable name to value.
SetGlobalStatusVar(ctx context.Context, name, value string) error
}
// globalSysVarAccessorKeyType is a dummy type to avoid naming collision in context.

View File

@ -21,7 +21,6 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/types"
)
var _ context.Context = (*Context)(nil)
@ -58,25 +57,6 @@ func (c *Context) FinishTxn(rollback bool) error {
return nil
}
// GetGlobalStatusVar implements GlobalVarAccessor GetGlobalStatusVar interface.
func (c *Context) GetGlobalStatusVar(ctx context.Context, name string) (string, error) {
v := variable.GetStatusVar(name)
if v == nil {
return "", terror.UnknownStatusVar.Gen("unknown status variable: %s", name)
}
return types.ToString(v.Value)
}
// SetGlobalStatusVar implements GlobalVarAccessor SetGlobalStatusVar interface.
func (c *Context) SetGlobalStatusVar(ctx context.Context, name, value string) error {
v := variable.GetStatusVar(name)
if v == nil {
return terror.UnknownStatusVar.Gen("unknown status variable: %s", name)
}
v = &variable.StatusVal{Scope: variable.DefaultScopeFlag, Value: value}
return nil
}
// GetGlobalSysVar implements GlobalVarAccessor GetGlobalSysVar interface.
func (c *Context) GetGlobalSysVar(ctx context.Context, name string) (string, error) {
v := variable.GetSysVar(name)