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

recover table by job ID would cause panic #55113

Closed
wjhuang2016 opened this issue Jul 31, 2024 · 1 comment · Fixed by #56965
Closed

recover table by job ID would cause panic #55113

wjhuang2016 opened this issue Jul 31, 2024 · 1 comment · Fixed by #56965
Assignees
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. component/ddl This issue is related to DDL of TiDB. impact/panic severity/moderate type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
	dom := domain.GetDomain(e.Ctx())
	var job *model.Job
	var err error
	var tblInfo *model.TableInfo
	// Let check table first. Related isssue #46296.
	if s.Table != nil {
		job, tblInfo, err = e.getRecoverTableByTableName(s.Table)
	} else {
		job, tblInfo, err = e.getRecoverTableByJobID(s, dom)
	}
	if err != nil {
		return err
	}
	// Check the table ID was not exists.
	tbl, ok := dom.InfoSchema().TableByID(tblInfo.ID)
	if ok {
		return infoschema.ErrTableExists.GenWithStack("Table '%-.192s' already been recover to '%-.192s', can't be recover repeatedly", s.Table.Name.O, tbl.Meta().Name.O)
	}

ErrTableExists uses s.Table, but it's nil in recover table by job ID.

2. What did you expect to see? (Required)

N/A

3. What did you see instead (Required)

N/A

4. What is your TiDB version? (Required)

master

@crazycs520 crazycs520 added affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.2 affects-8.3 affects-8.4 labels Oct 29, 2024
@crazycs520
Copy link
Contributor

crazycs520 commented Oct 29, 2024

Nice catch, I will fix it.

This will only occur in some abnormal situations, and the panic will only affect the current query and will not cause tidb-server to panic.

And the minimal reproduce step is:

test> create table t (a int);
Query OK, 0 rows affected
Time: 0.085s
test> drop table t;
Query OK, 0 rows affected
Time: 0.330s
test> admin show ddl jobs 1; 
+--------+---------+------------+---------------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE      | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | CREATE_TIME                | START_TIME                 | END_TIME                   | STATE  |
+--------+---------+------------+---------------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+
| 106    | test    | t          | drop table    | none         | 2         | 104      | 0         | 2024-10-29 19:48:08.829000 | 2024-10-29 19:48:08.879000 | 2024-10-29 19:48:09.180000 | synced |
+--------+---------+------------+---------------+--------------+-----------+----------+-----------+----------------------------+----------------------------+----------------------------+--------+
1 row in set
Time: 0.009s
test> recover table by job 106;
Query OK, 0 rows affected
Time: 0.224s
test> recover table by job 106;
(1105, 'runtime error: invalid memory address or nil pointer dereference')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. component/ddl This issue is related to DDL of TiDB. impact/panic severity/moderate type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants