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) #41074

Merged

Conversation

lance6716
Copy link
Contributor

manually cherry-pick #40959

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

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 6, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • gozssky
  • lichunzhu

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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 6, 2023
@lance6716
Copy link
Contributor Author

/test build

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 6, 2023
@lance6716
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@lance6716: /merge in this pull request requires 2 approval(s).

In response to this:

/merge

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.

Copy link
Contributor

@lichunzhu lichunzhu left a comment

Choose a reason for hiding this comment

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

LGTM

@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 Feb 6, 2023
@lichunzhu
Copy link
Contributor

/merge

1 similar comment
@lance6716
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: c941af3

1 similar comment
@ti-chi-bot
Copy link
Member

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

Commit hash: c941af3

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 6, 2023
@ti-chi-bot
Copy link
Member

@lance6716: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@lance6716
Copy link
Contributor Author

/retest

1 similar comment
@lance6716
Copy link
Contributor Author

/retest

@hawkingrei
Copy link
Member

/test unit-test

@ti-chi-bot ti-chi-bot merged commit 3148557 into pingcap:release-6.5-20230122-v6.5.0 Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants