From 7f2eaa7a86f6dd2ec29ceadde46f00c793b4dedf Mon Sep 17 00:00:00 2001 From: xia Date: Mon, 23 Nov 2015 20:52:26 +0800 Subject: [PATCH 1/3] *: fix disable the default autocommit mode after the second start --- bootstrap.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bootstrap.go b/bootstrap.go index 06cdcc0036..0f95484a7b 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,14 @@ 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 next operations. + s.FinishTxn(false) + } + + return isBootstrapped, nil } // Execute DDL statements in bootstrap stage. From cf5833e6a3fb856e2bae7763dc1ac22b5f0c00d3 Mon Sep 17 00:00:00 2001 From: xia Date: Mon, 23 Nov 2015 20:54:56 +0800 Subject: [PATCH 2/3] *: add test --- session_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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. From bad75a169301b25570dcd84623c1ea09cb77490a Mon Sep 17 00:00:00 2001 From: xia Date: Tue, 24 Nov 2015 10:37:42 +0800 Subject: [PATCH 3/3] *: update comments --- bootstrap.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bootstrap.go b/bootstrap.go index 0f95484a7b..0805b2b6d9 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -160,8 +160,11 @@ func checkBootstrappedVar(s Session) (bool, error) { isBootstrapped := row.Data[0].(string) == bootstrappedVarTrue if isBootstrapped { - // Make sure that doesn't affect the next operations. - s.FinishTxn(false) + // Make sure that doesn't affect the following operations. + + if err = s.FinishTxn(false); err != nil { + return false, errors.Trace(err) + } } return isBootstrapped, nil