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

*: add a reference count for StmtCtx #39368

Merged
merged 21 commits into from
Nov 28, 2022
Merged

Conversation

XuHuaiyu
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #27725

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Manual test (add detailed scripts or steps below)
    Using commit: 17e6297
    run
select 1;
select sleep(3);
select 1;
select 1;

Before this commit, tidb-server will panic.
After this commit, tidb-server run successfully.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@XuHuaiyu XuHuaiyu added the type/bugfix This PR fixes a bug. label Nov 24, 2022
@XuHuaiyu XuHuaiyu requested a review from a team as a code owner November 24, 2022 09:38
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 24, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker
  • wshwsh12

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 submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 24, 2022
@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. and removed do-not-merge/needs-triage-completed labels Nov 25, 2022
@XuHuaiyu XuHuaiyu removed needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. labels Nov 25, 2022
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 25, 2022
@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. labels Nov 25, 2022
@@ -294,6 +294,7 @@ func (record *memoryUsageAlarm) getTop10SqlInfo(cmp func(i, j *util.ProcessInfo)
}
buf.WriteString("\n")
}
totalCnt--
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need to update info here?

util/util.go Outdated
@@ -106,6 +106,11 @@ func Str2Int64Map(str string) map[int64]struct{} {

// GenLogFields generate log fields.
func GenLogFields(costTime time.Duration, info *ProcessInfo, needTruncateSQL bool) []zap.Field {
if !info.RefCountOfStmtCtx.TryIncrease() {
Copy link
Contributor

Choose a reason for hiding this comment

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

So other threads can only access StmtCtx by this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. But it seems we only encounter problems here.😅

@hawkingrei
Copy link
Member

@XuHuaiyu PTAL

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4aa405]

goroutine 130 [running]:
testing.tRunner.func1.2({0x1ac2d80, 0x3047a00})
	GOROOT/src/testing/testing.go:1396 +0x372
testing.tRunner.func1()
	GOROOT/src/testing/testing.go:1399 +0x5f0
panic({0x1ac2d80, 0x3047a00})
	GOROOT/src/runtime/panic.go:890 +0x262
sync/atomic.LoadInt32()
	src/runtime/race_amd64.s:202 +0xc
github.com/pingcap/tidb/sessionctx/stmtctx.(*ReferenceCount).TryIncrease(0x0?)
	sessionctx/stmtctx/stmtctx.go:118 +0x45
github.com/pingcap/tidb/util.GenLogFields(0x0, 0xc0001a37a0, 0x0)
	util/util.go:109 +0xa5
github.com/pingcap/tidb/util/memoryusagealarm.(*memoryUsageAlarm).getTop10SqlInfo(0xc000611cd0, 0x0?, {0xc00059a798?, 0x3, 0x3})
	util/memoryusagealarm/memoryusagealarm.go:274 +0x2d4
github.com/pingcap/tidb/util/memoryusagealarm.(*memoryUsageAlarm).getTop10SqlInfoByMemoryUsage(0xc00080bb70?, {0xc00059a798, 0x3, 0x3})
	util/memoryusagealarm/memoryusagealarm.go:304 +0x67
github.com/pingcap/tidb/util/memoryusagealarm.TestGetTop10Sql(0x0?)
	util/memoryusagealarm/memoryusagealarm_test.go:87 +0x205
testing.tRunner(0xc000603040, 0x1d17040)
	GOROOT/src/testing/testing.go:1446 +0x217
created by testing.(*T).Run
	GOROOT/src/testing/testing.go:1493 +0x75e

@XuHuaiyu
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: b9f9e37

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 28, 2022
@qw4990
Copy link
Contributor

qw4990 commented Nov 28, 2022

/merge

@ti-chi-bot ti-chi-bot merged commit f8a6bde into pingcap:master Nov 28, 2022
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39424.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 28, 2022
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39425.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 28, 2022
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 28, 2022
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #39426.

@sre-bot
Copy link
Contributor

sre-bot commented Nov 28, 2022

TiDB MergeCI notify

✅ Well Done! New fixed [1] after this pr merged.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test ✅ all 6 tests passed 5 min 10 sec Fixed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 26 min Existing passed
idc-jenkins-ci/integration-cdc-test 🟢 all 40 tests passed 23 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 9 min 22 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 12 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 5 min 50 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 20 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 4 min 22 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 50 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note-none Denotes a PR that doesn't merit a release note. 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. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fatal error: sync: unlock of unlocked mutex
7 participants