Skip to content

Commit

Permalink
Revert "topsql: enable topsql feature by default (#33195)" (#33493)
Browse files Browse the repository at this point in the history
close #33492
  • Loading branch information
crazycs520 authored Mar 28, 2022
1 parent 8f8dfaf commit 5c931aa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 70 deletions.
17 changes: 1 addition & 16 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,11 @@ const (
version84 = 84
// version85 updates bindings with status 'using' in mysql.bind_info table to 'enabled' status
version85 = 85
// version86 changes global variable `tidb_enable_top_sql` value from false to true.
version86 = 86
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version86
var currentBootstrapVersion int64 = version85

var (
bootstrapVersion = []func(Session, int64){
Expand Down Expand Up @@ -678,7 +676,6 @@ var (
upgradeToVer83,
upgradeToVer84,
upgradeToVer85,
upgradeToVer86,
}
)

Expand Down Expand Up @@ -1755,14 +1752,6 @@ func upgradeToVer85(s Session, ver int64) {
mustExecute(s, fmt.Sprintf("UPDATE HIGH_PRIORITY mysql.bind_info SET status= '%s' WHERE status = '%s'", bindinfo.Enabled, bindinfo.Using))
}

func upgradeToVer86(s Session, ver int64) {
if ver >= version86 {
return
}
// Enable Top SQL by default after upgrade
mustExecute(s, "set @@global.tidb_enable_top_sql = 1")
}

func writeOOMAction(s Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down Expand Up @@ -1915,10 +1904,6 @@ func doDMLWorks(s Session) {
}
value := fmt.Sprintf(`("%s", "%s")`, strings.ToLower(k), vVal)
values = append(values, value)

if v.GlobalConfigName != "" {
domain.GetDomain(s).NotifyGlobalConfigChange(v.GlobalConfigName, variable.OnOffToTrueFalse(vVal))
}
}
}
sql := fmt.Sprintf("INSERT HIGH_PRIORITY INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable,
Expand Down
53 changes: 0 additions & 53 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/parser/auth"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -1095,55 +1094,3 @@ func TestUpgradeToVer85(t *testing.T) {
require.NoError(t, r.Close())
mustExec(t, se, "delete from mysql.bind_info where default_db = 'test'")
}

func TestUpgradeVersion86(t *testing.T) {
ctx := context.Background()
store, dom := createStoreAndBootstrap(t)
defer func() { require.NoError(t, store.Close()) }()

seV85 := createSessionAndSetID(t, store)
txn, err := store.Begin()
require.NoError(t, err)
m := meta.NewMeta(txn)
err = m.FinishBootstrap(int64(85))
require.NoError(t, err)
err = txn.Commit(context.Background())
require.NoError(t, err)
mustExec(t, seV85, "update mysql.tidb set variable_value='85' where variable_name='tidb_server_version'")
mustExec(t, seV85, "set @@global.tidb_enable_top_sql = 0")
mustExec(t, seV85, "commit")
unsetStoreBootstrapped(store.UUID())
ver, err := getBootstrapVersion(seV85)
require.NoError(t, err)
require.Equal(t, int64(85), ver)
// Top SQL is disabled in old version TiDB by default.
r := mustExec(t, seV85, `SELECT @@global.tidb_enable_top_sql`)
req := r.NewChunk(nil)
require.NoError(t, r.Next(ctx, req))
require.Equal(t, 1, req.NumRows())
row := req.GetRow(0)
require.Equal(t, int64(0), row.GetInt64(0))
dom.Close()

// after upgrade.
domV86, err := BootstrapSession(store)
require.NoError(t, err)
defer domV86.Close()
seV86 := createSessionAndSetID(t, store)
ver, err = getBootstrapVersion(seV86)
require.NoError(t, err)
require.Equal(t, currentBootstrapVersion, ver)
r = mustExec(t, seV86, `SELECT @@global.tidb_enable_top_sql`)
req = r.NewChunk(nil)
require.NoError(t, r.Next(ctx, req))
require.Equal(t, 1, req.NumRows())
row = req.GetRow(0)
require.Equal(t, int64(1), row.GetInt64(0))

storeWithePD, ok := store.(kv.StorageWithPD)
require.True(t, ok)
items, err := storeWithePD.GetPDClient().LoadGlobalConfig(ctx, []string{"enable_resource_metering"})
require.NoError(t, err)
require.Equal(t, 1, len(items))
require.Equal(t, "true", items[0].Value)
}
2 changes: 1 addition & 1 deletion util/topsql/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "go.uber.org/atomic"

// Default Top-SQL state values.
const (
DefTiDBTopSQLEnable = true
DefTiDBTopSQLEnable = false
DefTiDBTopSQLPrecisionSeconds = 1
DefTiDBTopSQLMaxTimeSeriesCount = 100
DefTiDBTopSQLMaxMetaCount = 5000
Expand Down

0 comments on commit 5c931aa

Please sign in to comment.