Skip to content

Commit

Permalink
Merge branch 'master' into options-match-store-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing committed May 12, 2021
2 parents 8675433 + 6228e22 commit f929637
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6 deletions.
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,11 @@ error = '''
Unknown SEQUENCE: '%-.300s'
'''

["schema:8003"]
error = '''
TiDB admin check table failed.
'''

["schema:8020"]
error = '''
Table '%s' was locked in %s by %v
Expand Down
16 changes: 16 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) {
check()
}

func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists temporary_admin_test;")
tk.MustExec("create global temporary table temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;")
tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);")
tk.MustGetErrCode("admin check table temporary_admin_test;", mysql.ErrAdminCheckTable)
tk.MustExec("drop table if exists temporary_admin_test;")

tk.MustExec("drop table if exists non_temporary_admin_test;")
tk.MustExec("create table non_temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2));")
tk.MustExec("insert non_temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);")
tk.MustExec("admin check table non_temporary_admin_test;")
tk.MustExec("drop table if exists non_temporary_admin_test;")
}

func (s *testSuite5) TestAdminRecoverIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
8 changes: 6 additions & 2 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx
if isSystemTable(tn.Schema.L, tn.Name.L) {
return errors.Errorf("Drop tidb system table '%s.%s' is forbidden", tn.Schema.L, tn.Name.L)
}

if obt == tableObject && config.CheckTableBeforeDrop {
tableInfo, err := e.is.TableByName(tn.Schema, tn.Name)
if err != nil {
return err
}
tempTableType := tableInfo.Meta().TempTableType
if obt == tableObject && config.CheckTableBeforeDrop && tempTableType == model.TempTableNone {
logutil.BgLogger().Warn("admin check table before drop",
zap.String("database", fullti.Schema.O),
zap.String("table", fullti.Name.O),
Expand Down
2 changes: 2 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9161,8 +9161,10 @@ func (s *testIntegrationSuite) TestIssue24429(c *C) {

tk.MustExec("set @@sql_mode = ANSI_QUOTES;")
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int);")
tk.MustQuery(`select t."a"=10 from t;`).Check(testkit.Rows())
tk.MustExec("drop table if exists t;")
}

func (s *testIntegrationSuite) TestVitessHash(c *C) {
Expand Down
2 changes: 2 additions & 0 deletions infoschema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ var (
ErrTableLocked = dbterror.ClassSchema.NewStd(mysql.ErrTableLocked)
// ErrWrongObject returns when the table/view/sequence is not the expected object.
ErrWrongObject = dbterror.ClassSchema.NewStd(mysql.ErrWrongObject)
// ErrAdminCheckTable returns when the check table in temporary mode.
ErrAdminCheckTable = dbterror.ClassSchema.NewStd(mysql.ErrAdminCheckTable)
)
27 changes: 27 additions & 0 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type preprocessor struct {

func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
switch node := in.(type) {
case *ast.AdminStmt:
p.checkAdminCheckTableGrammar(node)
case *ast.DeleteStmt:
p.stmtTp = TypeDelete
case *ast.SelectStmt:
Expand Down Expand Up @@ -557,6 +559,31 @@ func (p *preprocessor) checkDropDatabaseGrammar(stmt *ast.DropDatabaseStmt) {
}
}

func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) {
for _, table := range stmt.Tables {
currentDB := p.ctx.GetSessionVars().CurrentDB
if table.Schema.String() != "" {
currentDB = table.Schema.L
}
if currentDB == "" {
p.err = errors.Trace(ErrNoDB)
return
}
sName := model.NewCIStr(currentDB)
tName := table.Name
tableInfo, err := p.is.TableByName(sName, tName)
if err != nil {
p.err = err
return
}
tempTableType := tableInfo.Meta().TempTableType
if stmt.Tp == ast.AdminCheckTable && tempTableType != model.TempTableNone {
p.err = infoschema.ErrAdminCheckTable
return
}
}
}

func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) {
tName := stmt.Table.Name.String()
if isIncorrectName(tName) {
Expand Down
2 changes: 2 additions & 0 deletions store/driver/txn/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (s *tikvSnapshot) SetOption(opt int, val interface{}) {
s.KVSnapshot.SetReplicaRead(val.(tikvstore.ReplicaReadType))
case tikvstore.TaskID:
s.KVSnapshot.SetTaskID(val.(uint64))
case tikvstore.IsStalenessReadOnly:
s.KVSnapshot.SetIsStatenessReadOnly(val.(bool))
case tikvstore.MatchStoreLabels:
s.KVSnapshot.SetMatchStoreLabels(val.([]*metapb.StoreLabel))
default:
Expand Down
2 changes: 2 additions & 0 deletions store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) {
txn.SetEnable1PC(val.(bool))
case tikvstore.TxnScope:
txn.SetScope(val.(string))
case tikvstore.IsStalenessReadOnly:
txn.KVTxn.GetSnapshot().SetIsStatenessReadOnly(val.(bool))
case tikvstore.MatchStoreLabels:
txn.KVTxn.GetSnapshot().SetMatchStoreLabels(val.([]*metapb.StoreLabel))
default:
Expand Down
11 changes: 7 additions & 4 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,6 @@ func (s *KVSnapshot) SetOption(opt int, val interface{}) {
s.mu.Unlock()
case kv.SampleStep:
s.sampleStep = val.(uint32)
case kv.IsStalenessReadOnly:
s.mu.Lock()
s.mu.isStaleness = val.(bool)
s.mu.Unlock()
}
}

Expand Down Expand Up @@ -624,6 +620,13 @@ func (s *KVSnapshot) SetTaskID(id uint64) {
s.mu.taskID = id
}

// SetIsStatenessReadOnly indicates whether the transaction is staleness read only transaction
func (s *KVSnapshot) SetIsStatenessReadOnly(b bool) {
s.mu.Lock()
defer s.mu.Unlock()
s.mu.isStaleness = b
}

// SetMatchStoreLabels sets up labels to filter target stores.
func (s *KVSnapshot) SetMatchStoreLabels(labels []*metapb.StoreLabel) {
s.mu.Lock()
Expand Down

0 comments on commit f929637

Please sign in to comment.