Skip to content

Commit

Permalink
*: fix bug that table name in 'admin show ddl jobs' is missing for on…
Browse files Browse the repository at this point in the history
…going drop table operation (#42904)

close #42268
  • Loading branch information
tiancaiamao authored Apr 11, 2023
1 parent 5466ce2 commit b7330bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ddl/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/internal/callback"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/external"
"github.com/pingcap/tidb/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -179,3 +181,36 @@ func buildCreateIdxJob(dbInfo *model.DBInfo, tblInfo *model.TableInfo, unique bo
},
}
}

func TestIssue42268(t *testing.T) {
// issue 42268 missing table name in 'admin show ddl' result during drop table
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t_0")
tk.MustExec("create table t_0 (c1 int, c2 int)")

tbl := external.GetTableByName(t, tk, "test", "t_0")
require.NotNil(t, tbl)
require.Equal(t, 2, len(tbl.Cols()))

tk1 := testkit.NewTestKit(t, store)
tk1.MustExec("use test")

hook := &callback.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if tbl.Meta().ID != job.TableID {
return
}
switch job.SchemaState {
case model.StateNone:
case model.StateDeleteOnly, model.StateWriteOnly, model.StateWriteReorganization:
rs := tk1.MustQuery("admin show ddl jobs")
tblName := fmt.Sprintf("%s", rs.Rows()[0][2])
require.Equal(t, tblName, "t_0")
}
}
dom.DDL().SetHook(hook)

tk.MustExec("drop table t_0")
}
3 changes: 3 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che
schemaName = job.BinlogInfo.DBInfo.Name.L
}
}
if len(tableName) == 0 {
tableName = job.TableName
}
// For compatibility, the old version of DDL Job wasn't store the schema name and table name.
if len(schemaName) == 0 {
schemaName = getSchemaName(e.is, job.SchemaID)
Expand Down

0 comments on commit b7330bd

Please sign in to comment.