Skip to content

Commit

Permalink
executor: let flush privileges do nothing when skip-grant-table is …
Browse files Browse the repository at this point in the history
…configured pingcap#10986
  • Loading branch information
tiancaiamao committed Oct 18, 2019
1 parent c72efd1 commit afb63b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var _ = Suite(&testBypassSuite{})
var _ = Suite(&testUpdateSuite{})
var _ = Suite(&testOOMSuite{})
var _ = Suite(&testPointGetSuite{})
var _ = Suite(&testFlushSuite{})

type testSuite struct {
cluster *mocktikv.Cluster
Expand Down
7 changes: 7 additions & 0 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func (e *SimpleExec) executeFlush(s *ast.FlushStmt) error {
case ast.FlushTables:
// TODO: A dummy implement
case ast.FlushPrivileges:
// If skip-grant-table is configured, do not flush privileges.
// Because LoadPrivilegeLoop does not run and the privilege Handle is nil,
// Call dom.PrivilegeHandle().Update would panic.
if config.GetGlobalConfig().Security.SkipGrantTable {
return nil
}

dom := domain.GetDomain(e.ctx)
sysSessionPool := dom.SysSessionPool()
ctx, err := sysSessionPool.Get()
Expand Down
29 changes: 29 additions & 0 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mocktikv"
"github.com/pingcap/tidb/util/testkit"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -263,6 +267,31 @@ func (s *testSuite) TestFlushPrivileges(c *C) {
// After flush.
_, err = se.Execute(ctx, `SELECT Password FROM mysql.User WHERE User="testflush" and Host="localhost"`)
c.Check(err, IsNil)

}

type testFlushSuite struct{}

func (s *testFlushSuite) TestFlushPrivilegesPanic(c *C) {
// Run in a separate suite because this test need to set SkipGrantTable config.
cluster := mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(cluster)
mvccStore := mocktikv.MustNewMVCCStore()
store, err := mockstore.NewMockTikvStore(
mockstore.WithCluster(cluster),
mockstore.WithMVCCStore(mvccStore),
)
c.Assert(err, IsNil)
defer store.Close()

config.GetGlobalConfig().Security.SkipGrantTable = true
dom, err := session.BootstrapSession(store)
c.Assert(err, IsNil)
defer dom.Close()

tk := testkit.NewTestKit(c, store)
tk.MustExec("FLUSH PRIVILEGES")
config.GetGlobalConfig().Security.SkipGrantTable = false
}

func (s *testSuite) TestDropStats(c *C) {
Expand Down

0 comments on commit afb63b0

Please sign in to comment.