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

mvcc: abstract a general forward scanner #6218

Merged
merged 14 commits into from Dec 13, 2019

Conversation

sticnarf
Copy link
Contributor

What have you changed?

In order to reduce repeated code for forward scanner, txn entry scanner and delta scanner, we want to reuse the forward scanner code.

I introduce ScanPolicy trait to define the behavior when the scanner meets a lock or a key.

Now this PR is a work in progress. It's just a refactor of the existing forward scanner.

What is the type of the changes?

  • Improvement (a change which is an improvement to an existing feature)

How is the PR tested?

  • Unit test
  • Integration test

Does this PR affect documentation (docs) or should it be mentioned in the release notes?

Does this PR affect tidb-ansible?

Refer to a related PR or issue link (optional)

Benchmark result if necessary (optional)

Any examples? (optional)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
@sticnarf sticnarf added sig/transaction SIG: Transaction S: WIP labels Dec 11, 2019
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
@sticnarf
Copy link
Contributor Author

/bench +tpch

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
@sticnarf sticnarf removed the S: WIP label Dec 11, 2019
@sticnarf sticnarf changed the title [WIP] mvcc: abstract a general forward scanner mvcc: abstract a general forward scanner Dec 11, 2019
@sticnarf
Copy link
Contributor Author

/test

@sre-bot
Copy link
Contributor

sre-bot commented Dec 11, 2019

Benchmark Report

Run TPC-H 10G Performance Test on VMs

@@                               Benchmark Diff                               @@
================================================================================
tidb: a94cff903cd1e7f3b050db782da84273ef5592f4
--- tikv: 134c5663340c8e868f23bc2f3273b84168aed862
+++ tikv: 066a950cf6078d7b273e27a76b3cef177da18dc5
pd: 13ea87a019a51d143e4c44365b39c49a87047d72
================================================================================
01.sql duration: 17933.71 ms ± 0.59% (std=62.06) delta: -4.40% (p=0.205)
02.sql duration: 6755.99 ms ± 3.32% (std=122.95) delta: 0.68% (p=0.716)
03.sql duration: 17070.60 ms ± 2.93% (std=282.66) delta: -4.86% (p=0.000)
04.sql duration: 7305.43 ms ± 3.29% (std=136.09) delta: -2.57% (p=0.007)
06.sql duration: 9517.13 ms ± 8.15% (std=331.54) delta: -2.08% (p=0.496)
07.sql duration: 14008.61 ms ± 1.96% (std=153.83) delta: -1.93% (p=0.003)
08.sql duration: 12217.36 ms ± 2.21% (std=176.95) delta: -1.11% (p=0.055)
09.sql duration: 35329.91 ms ± 1.80% (std=350.91) delta: 0.26% (p=0.830)
10.sql duration: 9804.63 ms ± 2.42% (std=130.00) delta: -0.38% (p=0.889)
11.sql duration: 3555.22 ms ± 4.13% (std=77.16) delta: 2.94% (p=0.319)
12.sql duration: 11943.37 ms ± 4.52% (std=271.64) delta: 0.56% (p=0.930)
13.sql duration: 10187.38 ms ± 1.77% (std=125.55) delta: 1.18% (p=0.453)
14.sql duration: 10752.69 ms ± 0.47% (std=31.11) delta: -3.78% (p=0.003)
15.sql duration: 19747.68 ms ± 2.82% (std=346.68) delta: -3.38% (p=0.004)
16.sql duration: 3597.96 ms ± 5.34% (std=112.53) delta: 0.08% (p=0.576)
17.sql duration: 34445.30 ms ± 1.36% (std=250.00) delta: -1.99% (p=0.000)
18.sql duration: 49621.62 ms ± 6.84% (std=1681.65) delta: -0.45% (p=0.265)
19.sql duration: 15204.40 ms ± 3.45% (std=316.35) delta: -1.67% (p=0.070)
20.sql duration: 10860.65 ms ± 4.71% (std=239.24) delta: -2.37% (p=0.151)
21.sql duration: 28671.07 ms ± 1.26% (std=201.60) delta: -1.08% (p=0.005)
22.sql duration: 5295.88 ms ± 3.02% (std=82.92) delta: 1.13% (p=0.590)

…canner

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Member

@overvenus overvenus 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

@@ -140,73 +233,44 @@ impl<S: Snapshot> ForwardScanner<S> {
}
};

// Use `from_encoded_slice` to reserve space for ts, so later we can append ts to
// the key or its clones without reallocation.
// // Use `from_encoded_slice` to reserve space for ts, so later we can append ts to
Copy link
Member

Choose a reason for hiding this comment

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

Double //?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/// Use `ScannerBuilder` to build `BackwardScanner`.
pub struct BackwardScanner<S: Snapshot> {
/// Use `ScannerBuilder` to build `BackwardKvScanner`.
pub struct BackwardKvScanner<S: Snapshot> {
Copy link
Member

Choose a reason for hiding this comment

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

KV is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to Rust's naming conventions, acronyms count as one word.

src/storage/mvcc/reader/scanner/forward.rs Outdated Show resolved Hide resolved
// Even if there is a lock error, we still need to step the cursor for future
// calls.
if result.is_err() {
cursors.move_write_cursor_to_next_user_key(&current_user_key, statistics)?;
Copy link
Member

Choose a reason for hiding this comment

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

when encountering conflict lock, now it moves write cursor to next user key no matter whether it has write for current user key.
seems it doesn't follow the previous behavior. It may skip a user key for the latter call?

Copy link
Member

Choose a reason for hiding this comment

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

oh, I misread the code. it will check current_user_key

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@sticnarf
Copy link
Contributor Author

@overvenus PTAL

if self.cfg.omit_value {
return Ok(Some(vec![]));
if cfg.omit_value {
break Some(vec![]);
Copy link
Member

Choose a reason for hiding this comment

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

This is the first time I know this syntax.

@breezewish
Copy link
Member

@MyonKeminta PTAL

@sticnarf sticnarf added the status/can-merge Status: Can merge to base branch label Dec 13, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Dec 13, 2019

/run-all-tests

@sticnarf
Copy link
Contributor Author

/merge

@sre-bot
Copy link
Contributor

sre-bot commented Dec 13, 2019

/run-all-tests

@sre-bot sre-bot merged commit 321c286 into tikv:master Dec 13, 2019
zhang555 pushed a commit to zhang555/tikv that referenced this pull request Dec 16, 2019
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
sticnarf added a commit to sticnarf/tikv that referenced this pull request Dec 19, 2019
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
overvenus added a commit that referenced this pull request Dec 26, 2019
* mvcc: abstract a general forward scanner (#6218)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* backup: support incremental backup (#6222)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* adapt to 3.1

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* fix

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

Co-authored-by: Neil Shen <overvenus@gmail.com>
c1ay pushed a commit to c1ay/tikv that referenced this pull request May 9, 2020
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/transaction SIG: Transaction status/can-merge Status: Can merge to base branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants