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

lightning: fix panic when nextKey twice (#40959) #41017

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #40959

Signed-off-by: lance6716 lance6716@gmail.com

What problem does this PR solve?

Issue Number: close #40934

Problem Summary:

What is changed and how it works?

Avoid to let CommonHandle++ and decode it because the result may not be a valid value. The string datum encoding will not be ended with 0xff and we may increase 0xfe to 0xff.

tidb/util/codec/bytes.go

Lines 35 to 49 in 151cd7e

// EncodeBytes guarantees the encoded value is in ascending order for comparison,
// encoding with the following rule:
//
// [group1][marker1]...[groupN][markerN]
// group is 8 bytes slice which is padding with 0.
// marker is `0xFF - padding 0 count`
//
// For example:
//
// [] -> [0, 0, 0, 0, 0, 0, 0, 0, 247]
// [1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250]
// [1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251]
// [1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]
//
// Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Run the changed tests and failpoints will trigger this panic. And after the fix it is avoided.

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

goroutine 436 [running]:
github.com/pingcap/tidb/br/pkg/lightning/backend/local.nextKey({0xc000874f18, 0x0?, 0x119?})
        /home/lance/Projects/tidb/br/pkg/lightning/backend/local/local.go:2069 +0x85
github.com/pingcap/tidb/br/pkg/lightning/backend/local.(*local).SplitAndScatterRegionByRanges(0xc000fe6dc0, {0x4fc3aa8?, 0xc001150140?}, {0xc0011a4900, 0x1, 0x576921f?}, 0xc00069e330, 0x1, 0x6000000)
        /home/lance/Projects/tidb/br/pkg/lightning/backend/local/localhelper.go:328 +0x1dd9
github.com/pingcap/tidb/br/pkg/lightning/backend/local.(*local).SplitAndScatterRegionInBatches(0x489294d?, {0x4fc3aa8, 0xc001150140}, {0xc0011a4900, 0x1, 0x1}, 0xc000fde240?, 0x1b?, 0x0?, 0x1000)
        /home/lance/Projects/tidb/br/pkg/lightning/backend/local/localhelper.go:80 +0x125
github.com/pingcap/tidb/br/pkg/lightning/backend/local.(*local).ImportEngine(0xc000fe6dc0, {0x4fc3aa8, 0xc001150140}, {0xf, 0x31, 0x82, 0xea, 0x38, 0xf9, 0x59, ...}, ...)
        /home/lance/Projects/tidb/br/pkg/lightning/backend/local/local.go:1661 +0x13ed
github.com/pingcap/tidb/br/pkg/lightning/backend.(*ClosedEngine).Import(0xc0006da960, {0x4fc3aa8, 0xc001150140}, 0xc0005370a0?, 0x0?)
        /home/lance/Projects/tidb/br/pkg/lightning/backend/backend.go:477 +0x23b
github.com/pingcap/tidb/br/pkg/lightning/restore.(*TableRestore).importKV(0xc000deaf80, {0x4fc3aa8, 0xc001150140}, 0xc0006da960, 0xc0009ff6c0, 0x7523580?)
        /home/lance/Projects/tidb/br/pkg/lightning/restore/table_restore.go:1004 +0x207
github.com/pingcap/tidb/br/pkg/lightning/restore.(*TableRestore).importEngine(0xc001254540?, {0x4fc3aa8?, 0xc001150140}, 0x0?, 0xc0009ff6c0, 0x0?, 0x0?)
        /home/lance/Projects/tidb/br/pkg/lightning/restore/table_restore.go:703 +0x4c
github.com/pingcap/tidb/br/pkg/lightning/restore.(*TableRestore).restoreEngines.func3(0x0?, 0x0, 0xc0005a1400)
        /home/lance/Projects/tidb/br/pkg/lightning/restore/table_restore.go:331 +0x2ed
created by github.com/pingcap/tidb/br/pkg/lightning/restore.(*TableRestore).restoreEngines
        /home/lance/Projects/tidb/br/pkg/lightning/restore/table_restore.go:322 +0x1499
make: *** [Makefile:324: br_integration_test] Error 2

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

Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot
Copy link
Member Author

ti-chi-bot commented Feb 2, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • gozssky
  • lance6716

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/cherry-pick-not-approved labels Feb 2, 2023
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.1 This PR is cherry-picked to release-6.1 from a source PR. labels Feb 2, 2023
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 2, 2023
@VelocityLight VelocityLight added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Mar 29, 2023
@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 29, 2023
@sleepymole
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member Author

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

Commit hash: 5c74ded

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 29, 2023
@sleepymole
Copy link
Contributor

/retest

2 similar comments
@sleepymole
Copy link
Contributor

/retest

@sleepymole
Copy link
Contributor

/retest

@ti-chi-bot ti-chi-bot merged commit 00c7ffc into pingcap:release-6.1 Mar 30, 2023
@VelocityLight VelocityLight added do-not-merge/cherry-pick-not-approved cherry-pick-approved Cherry pick PR approved by release team. and removed cherry-pick-approved Cherry pick PR approved by release team. do-not-merge/cherry-pick-not-approved labels Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. 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/cherry-pick-for-release-6.1 This PR is cherry-picked to release-6.1 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants