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: implement duplicate detector #43460

Merged
merged 4 commits into from May 15, 2023

Conversation

sleepymole
Copy link
Contributor

@sleepymole sleepymole commented Apr 27, 2023

What problem does this PR solve?

Issue Number: ref #41629

Problem Summary:

What is changed and how it works?

Implement a duplicate detector to detect key duplicates.

Check List

Tests

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

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

ti-chi-bot bot commented Apr 27, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • 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
Copy link

ti-chi-bot bot commented Apr 27, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 27, 2023
@sleepymole sleepymole added the component/lightning This issue is related to Lightning of TiDB. label Apr 27, 2023
@sleepymole sleepymole force-pushed the dup-detector branch 9 times, most recently from 4ce7382 to 4a661d2 Compare May 6, 2023 08:29
@sleepymole sleepymole marked this pull request as ready for review May 6, 2023 08:29
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 6, 2023
@sleepymole
Copy link
Contributor Author

/test unit-test

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

will review worker later

"github.com/stretchr/testify/require"
)

func TestInternalKey(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems it's a good case to try FuzzXxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it seems FuzzXxx will not run automatically. If you think we need some fuzz tests, I can add some random tests using rand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really need, I just find a good place to try new technique.

br/pkg/lightning/duplicate/detector_test.go Show resolved Hide resolved
br/pkg/lightning/duplicate/detector_test.go Outdated Show resolved Hide resolved
@sleepymole sleepymole requested a review from lance6716 May 9, 2023 01:59
Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

Rest lgtm

br/pkg/lightning/duplicate/detector.go Outdated Show resolved Hide resolved
br/pkg/lightning/duplicate/worker.go Outdated Show resolved Hide resolved
br/pkg/lightning/duplicate/worker.go Show resolved Hide resolved
br/pkg/lightning/duplicate/worker.go Show resolved Hide resolved
Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

rest lgtm

br/pkg/lightning/duplicate/worker.go Show resolved Hide resolved
br/pkg/lightning/duplicate/detector.go Outdated Show resolved Hide resolved
return splitKey
}

c1, c2 := startKey[l], endKey[l]
Copy link
Contributor

Choose a reason for hiding this comment

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

will endKey equal to empty slice? so we will meet index out of range

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's guaranteed that endKey is greater than startKey here.

br/pkg/lightning/duplicate/worker.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 9, 2023
@lance6716 lance6716 changed the title lightning: implement duplciate detector lightning: implement duplicate detector May 9, 2023
@sleepymole
Copy link
Contributor Author

@D3Hunter @GMHDBJD PTAL

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

rest lgtm

// KeyAdder is used to add keys to the Detector.
type KeyAdder struct {
w extsort.Writer
buf []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in Add function.


// Detect detects duplicate keys that have been added to the Detector.
// It returns the number of duplicate keys detected and any error encountered.
func (d *Detector) Detect(ctx context.Context, opts *DetectOptions) (numDups int64, _ error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move Detector code up, close with it's definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in c2d6a17.

}
opts.ensureDefaults()

logTask := d.logger.Begin(zap.InfoLevel, "[dup-detector] sort keys")
Copy link
Contributor

Choose a reason for hiding this comment

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

use a zapper field to indicate [dup-detector] part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in c2d6a17.

@ti-chi-bot ti-chi-bot bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 15, 2023
@sleepymole
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 15, 2023

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

Commit hash: c2d6a17

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 15, 2023
@ti-chi-bot ti-chi-bot bot merged commit 433ac5c into pingcap:master May 15, 2023
11 checks passed
@sleepymole sleepymole deleted the dup-detector branch May 15, 2023 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/lightning This issue is related to Lightning of TiDB. release-note-none size/XXL Denotes a PR that changes 1000+ 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.

None yet

3 participants