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 (#42905)

close #42268
  • Loading branch information
tiancaiamao authored Apr 11, 2023
1 parent 6d3aed4 commit e3f3aa3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ddl/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/tablecodec"
"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 @@ -192,3 +193,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 := &ddl.TestDDLCallback{}
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 @@ -553,6 +553,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 e3f3aa3

Please sign in to comment.