Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema: fix load drop database schema bug and refine db-table api error. (#11573) #11586

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,22 @@ func (b *Builder) applyDropSchema(schemaID int64) []int64 {
delete(b.is.schemaMap, di.Name.L)

// Copy the sortedTables that contain the table we are going to drop.
tableIDs := make([]int64, 0, len(di.Tables))
bucketIdxMap := make(map[int]struct{})
for _, tbl := range di.Tables {
bucketIdxMap[tableBucketIdx(tbl.ID)] = struct{}{}
// TODO: If the table ID doesn't exist.
tableIDs = append(tableIDs, tbl.ID)
}
for bucketIdx := range bucketIdxMap {
b.copySortedTablesBucket(bucketIdx)
}

ids := make([]int64, 0, len(di.Tables))
di = di.Clone()
for _, tbl := range di.Tables {
b.applyDropTable(di, tbl.ID)
// TODO: If the table ID doesn't exist.
ids = append(ids, tbl.ID)
for _, id := range tableIDs {
b.applyDropTable(di, id)
}
return ids
return tableIDs
}

func (b *Builder) copySortedTablesBucket(bucketIdx int) {
Expand Down
20 changes: 20 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser/auth"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -533,3 +535,21 @@ select * from t_slim;`))
rows := re.Rows()
c.Assert(rows[0][0], Equals, sql)
}

func (s *testTableSuite) TestReloadDropDatabase(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database test_dbs")
tk.MustExec("use test_dbs")
tk.MustExec("create table t1 (a int)")
tk.MustExec("create table t2 (a int)")
tk.MustExec("create table t3 (a int)")
is := domain.GetDomain(tk.Se).InfoSchema()
t2, err := is.TableByName(model.NewCIStr("test_dbs"), model.NewCIStr("t2"))
c.Assert(err, IsNil)
tk.MustExec("drop database test_dbs")
is = domain.GetDomain(tk.Se).InfoSchema()
_, err = is.TableByName(model.NewCIStr("test_dbs"), model.NewCIStr("t2"))
c.Assert(terror.ErrorEqual(infoschema.ErrTableNotExists, err), IsTrue)
_, ok := is.TableByID(t2.Meta().ID)
c.Assert(ok, IsFalse)
}
4 changes: 2 additions & 2 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,8 @@ func (h dbTableHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
dbTblInfo.TableInfo = tbl.Meta()
dbInfo, ok := schema.SchemaByTable(dbTblInfo.TableInfo)
if !ok {
log.Warnf("can not find the database of table id: %v, table name: %v", dbTblInfo.TableInfo.ID, dbTblInfo.TableInfo.Name)
writeData(w, dbTblInfo)
logutil.Logger(context.Background()).Error("can not find the database of the table", zap.Int64("table id", dbTblInfo.TableInfo.ID), zap.String("table name", dbTblInfo.TableInfo.Name.L))
writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID))
return
}
dbTblInfo.DBInfo = dbInfo
Expand Down