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

executor: fix a panic when batch point get is used for partition table #23652

Merged
merged 4 commits into from
Mar 30, 2021

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Mar 30, 2021

What problem does this PR solve?

5.0.0-rc panic stack:

{"level":"INFO","time":"2021/03/25 10:54:26.757 +08:00","caller":"conn.go:809","message":"command dispatched failed","conn":49,"connInfo":"id:49, addr:11.186.250.167:57210 status:10, collation:utf8mb4_general_ci, user:media_inter_r","command":"Execute","status":"inTxn:0, autocommit:1","sql":"SELECT `imp_date`, `media_id`, `app`, `article_likepv`, `article_collectpv`, `article_relaypv`, `article_commentpv`, `video_likevv`, `video_collectvv`, `video_relayvv`, `video_commentvv` FROM `media_interact_daily_6`.`t_media_interact_daily_4` WHERE (media_id=? AND app=? AND ((imp_date>=? AND imp_date<=?) OR (imp_date>=? AND imp_date<=?) OR (imp_date>=? AND imp_date<=?) OR (imp_date>=? AND imp_date<=?))) [arguments: (19790046, all, 2021-03-24, 2021-03-24, 2021-03-23, 2021-03-23, 2021-03-17, 2021-03-17, 2021-02-22, 2021-02-22)]","txn_mode":"OPTIMISTIC","err":"runtime error: integer divide by zero
github.com/pingcap/tidb/executor.(*recordSet).Next.func1
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/adapter.go:125
runtime.gopanic
	/usr/local/go/src/runtime/panic.go:679
runtime.panicdivide
	/usr/local/go/src/runtime/panic.go:178
github.com/pingcap/tidb/executor.getPhysID
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/batch_point_get.go:427
github.com/pingcap/tidb/executor.(*BatchPointGetExec).initialize
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/batch_point_get.go:195
github.com/pingcap/tidb/executor.(*BatchPointGetExec).Next
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/batch_point_get.go:143
github.com/pingcap/tidb/executor.Next
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/executor.go:278
github.com/pingcap/tidb/executor.(*recordSet).Next
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/executor/adapter.go:129
github.com/pingcap/tidb/server.(*tidbResultSet).Next
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/driver_tidb.go:298
github.com/pingcap/tidb/server.(*clientConn).writeChunks
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/conn.go:1732
github.com/pingcap/tidb/server.(*clientConn).writeResultset
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/conn.go:1692
github.com/pingcap/tidb/server.(*clientConn).handleStmtExecute
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/conn_stmt.go:213
github.com/pingcap/tidb/server.(*clientConn).dispatch
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/conn.go:1050
github.com/pingcap/tidb/server.(*clientConn).Run
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/conn.go:792
github.com/pingcap/tidb/server.(*Server).onConn
	/home/jenkins/agent/workspace/build-linux-amd64-enterprise/go/src/github.com/pingcap/tidb/server/server.go:461
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1357

Problem Summary:

The 'divide by zero' error should not happen, and in fact, partition table should not use BatchPointGet executor in the physical plan phase.

The root cause should be our improper handle of the partition meta info.
For historical reason, the meta information of a partition table maybe not nil, but its Enable field is false.
That means it's not really a partition table.
We should use GetPartitionInfo() check is a table a real partition table or not.

What is changed and how it works?

What's Changed:

Change direct access of struct field tableInfo.Partition to tableInfo.GetPartition()

How it Works:

GetPartitionInfo() will check the Enable field, we should always use it instead of using tableInfo.Partition .

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Release note

  • Fix a panic on batch point get for non-partitioned table with partition meta information. When a cluster is upgrade from a old version, its partition meta information maybe not null, but the Enable field is false, it should be treat as a non-partitioned table.

For historical reason, the meta information of a partition table may be
not nil, but its Enable field is false. That means it's not really a
partition table. We should use GetPartitionInfo() check is a table a
real partition table or not.
@tiancaiamao tiancaiamao requested review from a team as code owners March 30, 2021 02:50
@tiancaiamao tiancaiamao requested review from qw4990 and XuHuaiyu and removed request for a team March 30, 2021 02:50
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 30, 2021
@tiancaiamao tiancaiamao requested review from djshow832 and a team March 30, 2021 02:56
@tiancaiamao tiancaiamao added the sig/execution SIG execution label Mar 30, 2021
Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does any modification need to be cherry-picked to 4.0?

@tiancaiamao
Copy link
Contributor Author

Does any modification need to be cherry-picked to 4.0?

Oh, yes, 4.0 also use this function:

func getPhysID(tblInfo *model.TableInfo, val int64) int64 {
	pi := tblInfo.Partition
	if pi == nil {
		return tblInfo.ID
	}
	partIdx := math.Abs(val % int64(pi.Num))
	return pi.Definitions[partIdx].ID
}

@djshow832
Copy link
Contributor

/lgtm

@ti-chi-bot
Copy link
Member

@djshow832: /lgtm is only allowed for the reviewers in list.

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@djshow832 djshow832 removed the sig/execution SIG execution label Mar 30, 2021
@djshow832
Copy link
Contributor

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 30, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Mar 30, 2021
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • djshow832
  • qw4990

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 30, 2021
@qw4990
Copy link
Contributor

qw4990 commented Mar 30, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 5697839

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 30, 2021
@ti-chi-bot ti-chi-bot merged commit 67874c5 into pingcap:master Mar 30, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 30, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #23682

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 30, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #23683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants