diff --git a/bootstrap.go b/bootstrap.go index 06cdcc0036..0805b2b6d9 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -148,6 +148,7 @@ func checkBootstrappedVar(s Session) (bool, error) { } return false, errors.Trace(err) } + if len(rs) != 1 { return false, errors.New("Wrong number of Recordset") } @@ -156,7 +157,17 @@ func checkBootstrappedVar(s Session) (bool, error) { if err != nil || row == nil { return false, errors.Trace(err) } - return row.Data[0].(string) == bootstrappedVarTrue, nil + + isBootstrapped := row.Data[0].(string) == bootstrappedVarTrue + if isBootstrapped { + // Make sure that doesn't affect the following operations. + + if err = s.FinishTxn(false); err != nil { + return false, errors.Trace(err) + } + } + + return isBootstrapped, nil } // Execute DDL statements in bootstrap stage. diff --git a/session_test.go b/session_test.go index aacdcb9609..1c2a5dc3b7 100644 --- a/session_test.go +++ b/session_test.go @@ -719,6 +719,7 @@ func (s *testSessionSuite) TestBootstrap(c *C) { se := newSession(c, store, s.dbName) mustExecSQL(c, se, "USE mysql;") r := mustExecSQL(c, se, `select * from user;`) + c.Assert(r, NotNil) row, err := r.Next() c.Assert(err, IsNil) c.Assert(row, NotNil) @@ -734,9 +735,31 @@ func (s *testSessionSuite) TestBootstrap(c *C) { mustExecSQL(c, se, "SELECT * from mysql.columns_priv;") // Check privilege tables. r = mustExecSQL(c, se, "SELECT COUNT(*) from mysql.global_variables;") + c.Assert(r, NotNil) v, err := r.FirstRow() c.Assert(err, IsNil) c.Assert(v[0], Equals, int64(len(variable.SysVars))) + + // Check a storage operations are default autocommit after the second start. + mustExecSQL(c, se, "USE test;") + mustExecSQL(c, se, "drop table if exists t") + mustExecSQL(c, se, "create table t (id int)") + delete(storeBootstrapped, store.UUID()) + se.Close() + se, err = CreateSession(store) + c.Assert(err, IsNil) + mustExecSQL(c, se, "USE test;") + mustExecSQL(c, se, "insert t values (?)", 3) + se, err = CreateSession(store) + c.Assert(err, IsNil) + mustExecSQL(c, se, "USE test;") + r = mustExecSQL(c, se, "select * from t") + c.Assert(r, NotNil) + v, err = r.FirstRow() + c.Assert(err, IsNil) + match(c, v, 3) + mustExecSQL(c, se, "drop table if exists t") + se.Close() } // Create a new session on store but only do ddl works.