Skip to content

Commit

Permalink
Revert "*: run a bootstrap session before store is ready" (pingcap#2490)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and shenli committed Jan 17, 2017
1 parent e1ecc10 commit 999517c
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 158 deletions.
6 changes: 2 additions & 4 deletions bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func (s *testSessionSuite) TestBootstrap(c *C) {
defer testleak.AfterTest(c)()
store := newStoreWithBootstrap(c, s.dbName)
store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName)
mustExecSQL(c, se, "USE mysql;")
r := mustExecSQL(c, se, `select * from user;`)
Expand Down Expand Up @@ -121,7 +121,6 @@ func (s *testSessionSuite) TestBootstrapWithError(c *C) {
store := newStore(c, s.dbNameBootstrap)
s.bootstrapWithOnlyDDLWork(store, c)

BootstrapSession(store)
se := newSession(c, store, s.dbNameBootstrap)
mustExecSQL(c, se, "USE mysql;")
r := mustExecSQL(c, se, `select * from user;`)
Expand Down Expand Up @@ -154,7 +153,7 @@ func (s *testSessionSuite) TestBootstrapWithError(c *C) {
// Test case for upgrade
func (s *testSessionSuite) TestUpgrade(c *C) {
defer testleak.AfterTest(c)()
store := newStoreWithBootstrap(c, s.dbName)
store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName)
mustExecSQL(c, se, "USE mysql;")

Expand Down Expand Up @@ -196,7 +195,6 @@ func (s *testSessionSuite) TestUpgrade(c *C) {
c.Assert(ver, Equals, int64(0))

// Create a new session then upgrade() will run automatically.
BootstrapSession(store)
se2 := newSession(c, store, s.dbName)
r = mustExecSQL(c, se2, `SELECT VARIABLE_VALUE from mysql.TiDB where VARIABLE_NAME="tidb_server_version";`)
row, err = r.Next()
Expand Down
4 changes: 0 additions & 4 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (s *testDBSuite) SetUpSuite(c *C) {
s.schemaName = "test_db"
s.store, err = tidb.NewStore(tidb.EngineGoLevelDBMemory)
c.Assert(err, IsNil)
tidb.BootstrapSession(s.store)
localstore.MockRemoteStore = true
s.s, err = tidb.CreateSession(s.store)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -756,7 +755,6 @@ func (s *testDBSuite) TestUpdateMultipleTable(c *C) {
defer testleak.AfterTest(c)
store, err := tidb.NewStore("memory://update_multiple_table")
c.Assert(err, IsNil)
tidb.BootstrapSession(store)
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test")
tk.MustExec("create table t1 (c1 int, c2 int)")
Expand Down Expand Up @@ -816,7 +814,6 @@ func (s *testDBSuite) TestTruncateTable(c *C) {
defer testleak.AfterTest(c)
store, err := tidb.NewStore("memory://truncate_table")
c.Assert(err, IsNil)
tidb.BootstrapSession(store)
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test")
tk.MustExec("create table t (c1 int, c2 int)")
Expand Down Expand Up @@ -867,7 +864,6 @@ func (s *testDBSuite) TestRenameTable(c *C) {
defer testleak.AfterTest(c)
store, err := tidb.NewStore("memory://rename_table")
c.Assert(err, IsNil)
tidb.BootstrapSession(store)
s.tk = testkit.NewTestKit(c, store)
s.tk.MustExec("use test")

Expand Down
2 changes: 0 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func (s *testSuite) SetUpSuite(c *C) {
c.Assert(err, IsNil)
s.store = store
}
err := tidb.BootstrapSession(s.store)
c.Assert(err, IsNil)
logLevel := os.Getenv("log_level")
log.SetLevelByString(logLevel)
executor.BaseLookupTableTaskSize = 2
Expand Down
6 changes: 0 additions & 6 deletions perfschema/perfschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func (p *testPerfSchemaSuit) TestInsert(c *C) {
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
c.Assert(err, IsNil)
defer store.Close()
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
se := newSession(c, store, "")
defer se.Close()
mustExec(c, se, `insert into performance_schema.setup_actors values("localhost", "nieyy", "contributor", "NO", "NO");`)
Expand Down Expand Up @@ -110,8 +108,6 @@ func (p *testPerfSchemaSuit) TestInstrument(c *C) {
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory + "/test_instrument_db")
c.Assert(err, IsNil)
defer store.Close()
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
se := newSession(c, store, "test_instrument_db")
defer se.Close()

Expand All @@ -126,8 +122,6 @@ func (p *testPerfSchemaSuit) TestConcurrentStatement(c *C) {
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory + "/test_con_stmt")
c.Assert(err, IsNil)
defer store.Close()
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
se := newSession(c, store, "test_con_stmt")

mustExec(c, se, "drop table if exists test")
Expand Down
3 changes: 2 additions & 1 deletion plan/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package plan_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/parser"
Expand Down Expand Up @@ -80,7 +81,7 @@ var resolverTestCases = []resolverTestCase{
}

func (ts *testNameResolverSuite) TestNameResolver(c *C) {
store, err := newStoreWithBootstrap()
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
c.Assert(err, IsNil)
defer store.Close()
testKit := testkit.NewTestKit(c, store)
Expand Down
15 changes: 2 additions & 13 deletions plan/typeinferer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
package plan_test

import (
"github.com/juju/errors"
. "github.com/pingcap/check"
"github.com/pingcap/tidb"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/plan"
Expand All @@ -36,7 +34,7 @@ type testTypeInferrerSuite struct {
}

func (ts *testTypeInferrerSuite) TestInferType(c *C) {
store, err := newStoreWithBootstrap()
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
c.Assert(err, IsNil)
defer store.Close()
testKit := testkit.NewTestKit(c, store)
Expand Down Expand Up @@ -198,7 +196,7 @@ func (ts *testTypeInferrerSuite) TestInferType(c *C) {

func (s *testTypeInferrerSuite) TestColumnInfoModified(c *C) {
defer testleak.AfterTest(c)()
store, err := newStoreWithBootstrap()
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
c.Assert(err, IsNil)
defer store.Close()
testKit := testkit.NewTestKit(c, store)
Expand All @@ -212,12 +210,3 @@ func (s *testTypeInferrerSuite) TestColumnInfoModified(c *C) {
col := table.FindCol(tbl.Cols(), "col1")
c.Assert(col.Tp, Equals, mysql.TypeLong)
}

func newStoreWithBootstrap() (kv.Storage, error) {
store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
if err != nil {
return nil, errors.Trace(err)
}
err = tidb.BootstrapSession(store)
return store, errors.Trace(err)
}
2 changes: 0 additions & 2 deletions privilege/privileges/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type testCacheSuite struct {
func (s *testCacheSuite) SetUpSuite(c *C) {
store, err := tidb.NewStore("memory://mysql")
c.Assert(err, IsNil)
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
s.store = store
}

Expand Down
2 changes: 0 additions & 2 deletions privilege/privileges/privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ func mustExec(c *C, se tidb.Session, sql string) {
func newStore(c *C, dbPath string) kv.Storage {
store, err := tidb.NewStore("memory" + "://" + dbPath)
c.Assert(err, IsNil)
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
return store
}

Expand Down
2 changes: 0 additions & 2 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ func (ts *TidbTestSuite) SetUpSuite(c *C) {
log.SetLevelByString("error")
store, err := tidb.NewStore("memory:///tmp/tidb")
c.Assert(err, IsNil)
err = tidb.BootstrapSession(store)
c.Assert(err, IsNil)
ts.tidbdrv = NewTiDBDriver(store)
cfg := &Config{
Addr: ":4001",
Expand Down
20 changes: 4 additions & 16 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,29 +702,14 @@ func chooseMinLease(n1 time.Duration, n2 time.Duration) time.Duration {

// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
s, err := createSession(store)
if err != nil {
return nil, errors.Trace(err)
}

// TODO: Add auth here
privChecker := &privileges.UserPrivileges{}
privilege.BindPrivilegeChecker(s, privChecker)

return s, nil
}

// BootstrapSession runs the first time when the TiDB server start.
func BootstrapSession(store kv.Storage) error {
ver := getStoreBootstrapVersion(store)
if ver == notBootstrapped {
runInBootstrapSession(store, bootstrap)
} else if ver < currentBootstrapVersion {
runInBootstrapSession(store, upgrade)
}

_, err := domap.Get(store)
return errors.Trace(err)
return createSession(store)
}

// runInBootstrapSession create a special session for boostrap to run.
Expand Down Expand Up @@ -768,6 +753,9 @@ func createSession(store kv.Storage) (*session, error) {
// session implements variable.GlobalVarAccessor. Bind it to ctx.
s.sessionVars.GlobalVarsAccessor = s

// TODO: Add auth here
privChecker := &privileges.UserPrivileges{}
privilege.BindPrivilegeChecker(s, privChecker)
return s, nil
}

Expand Down
Loading

0 comments on commit 999517c

Please sign in to comment.