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

pessimistic-txn: implement pessimistic rollback #4848

Merged
merged 47 commits into from Jun 11, 2019

Conversation

@youjiali1995
Copy link
Contributor

youjiali1995 commented Jun 6, 2019

What have you changed? (mandatory)

  • Add pessimistic_rollback API to delete any pessimistic locks with small for_update_ts belongs to the transaction.
  • acquire_pessimistic_lock will overwrite own pessimistic locks with small for_update_ts.
  • Now key hash is generated from raw key, which consumes more CPU.

What are the type of the changes? (mandatory)

  • New feature (change which adds functionality)

How has this PR been tested? (mandatory)

unit tests and manual tests.

Does this PR affect documentation (docs) or release note? (mandatory)

No

Does this PR affect tidb-ansible update? (mandatory)

No

Refer to a related PR or issue link (optional)

pingcap/tidb#10654

youjiali1995 added 30 commits May 28, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
request's for_update_ts is greater than lock's for_update_ts

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…prewrite-conflict

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into solve-pessimistic-prewrite-conflict
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into solve-pessimistic-prewrite-conflict
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into implement-pessimistic-rollback
less than request's.

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into solve-pessimistic-prewrite-conflict
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into solve-pessimistic-prewrite-conflict
…iali1995/tikv into implement-pessimistic-rollback
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into solve-pessimistic-prewrite-conflict
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…iali1995/tikv into implement-pessimistic-rollback
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@youjiali1995

This comment has been minimized.

Copy link
Contributor Author

youjiali1995 commented Jun 6, 2019

}

pub fn gen_key_hashes(keys: &[Key]) -> Vec<u64> {
keys.iter().map(|key| gen_key_hash(key)).collect()
}

pub fn extract_raw_key_from_process_result(pr: &ProcessResult) -> &[u8] {
match pr {
ProcessResult::MultiRes { results } => {

This comment has been minimized.

Copy link
@coocood

coocood Jun 6, 2019

Contributor

I think we don't need to panic if failed to extract the key, as it will only be used for logging.

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 Jun 6, 2019

Author Contributor

It never occurs. If panicked, it's a bug in implementation.

youjiali1995 added 3 commits Jun 6, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…995/tikv into implement-pessimistic-rollback
@coocood

This comment has been minimized.

Copy link
Contributor

coocood commented Jun 6, 2019

LGTM

@youjiali1995

This comment has been minimized.

Copy link
Contributor Author

youjiali1995 commented Jun 6, 2019

/run-tests

let mut s = DefaultHasher::new();
key.hash(&mut s);
s.finish()
farmhash::fingerprint64(&key.to_raw().unwrap())

This comment has been minimized.

Copy link
@zhangjinpeng1987

zhangjinpeng1987 Jun 7, 2019

Member

Please give some benchmark for farmhash.

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 Jun 10, 2019

Author Contributor
running 2 tests
test bench_farmhash ... bench:          19 ns/iter (+/- 0)
test bench_std_hash ... bench:          35 ns/iter (+/- 1)

TiDB will check deadlock_key_hash to judge is it a single statement deadlock. So TiKV should use the same hash algorithm with TiDB.

Copy link
Member

zhangjinpeng1987 left a comment

LGTM

Copy link
Member

AndreMouche left a comment

LGTM

Copy link
Member

zhangjinpeng1987 left a comment

LGTM

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@youjiali1995 youjiali1995 dismissed stale reviews from zhangjinpeng1987 and AndreMouche via a4cd645 Jun 10, 2019
…tic-rollback

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Copy link
Member

zhangjinpeng1987 left a comment

LGTM

@AndreMouche AndreMouche merged commit 28e5358 into tikv:master Jun 11, 2019
2 checks passed
2 checks passed
DCO All commits are signed off!
Details
idc-jenkins-ci/test Jenkins job succeeded.
Details
@youjiali1995 youjiali1995 deleted the youjiali1995:implement-pessimistic-rollback branch Jun 11, 2019
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jun 13, 2019
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jun 13, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jun 13, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
sticnarf pushed a commit to sticnarf/tikv that referenced this pull request Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.