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

close #42268
  • Loading branch information
ti-chi-bot authored Jun 26, 2023
1 parent 7bfa8e6 commit 3b11b30
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ddl/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ddl_test

import (
"context"
"fmt"
"testing"

"github.com/pingcap/failpoint"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
"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 @@ -93,3 +95,38 @@ func buildCreateIdxJob(dbInfo *model.DBInfo, tblInfo *model.TableInfo, unique bo
Length: types.UnspecifiedLength}}},
}
}

func TestIssue42268(t *testing.T) {
// issue 42268 missing table name in 'admin show ddl' result during drop table
store, dom, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()

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{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 @@ -530,6 +530,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 3b11b30

Please sign in to comment.