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

txn: avoid useless calculation and wake-up msgs #4813

Merged
merged 20 commits into from Jun 10, 2019

Conversation

@youjiali1995
Copy link
Contributor

youjiali1995 commented May 30, 2019

Signed-off-by: youjiali1995 zlwgx1023@gmail.com

What have you changed? (mandatory)

Add atomic variable WAIT_TABLE_IS_EMPTY. If it is true, the wait table is empty and there is no need to calculate keys' hashes and wake up waiters.

What are the type of the changes? (mandatory)

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

How has this PR been tested? (mandatory)

Please describe the tests that you ran to verify your changes. Have you finished unit tests, integration tests, or manual tests? What additional tests would give you greater confidence in this change?

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

No

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

No

Add a few positive/negative examples (optional)

Now there is no wake-up msg sent to waiter manager if only uses the optimistic transaction.
image

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
bugfix
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@@ -91,6 +95,9 @@ impl WaitTable {
}

fn add_waiter(&mut self, ts: u64, waiter: Waiter) -> bool {
if self.wait_table.is_empty() {

This comment has been minimized.

Copy link
@siddontang

siddontang May 30, 2019

Contributor

better to abstract this to a function.

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 May 31, 2019

Author Contributor

fixed

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

This comment has been minimized.

Copy link
Contributor Author

youjiali1995 commented May 31, 2019

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…into avoid-useless-wake-up
fix test
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@coocood

This comment has been minimized.

Copy link
Contributor

coocood commented May 31, 2019

LGTM

@youjiali1995

This comment has been minimized.

Copy link
Contributor Author

youjiali1995 commented Jun 4, 2019

} else {
None
};
let key_hashes = gen_key_hashes_if_needed(&waiter_mgr_scheduler, &keys);

This comment has been minimized.

Copy link
@zhangjinpeng1987

zhangjinpeng1987 Jun 5, 2019

Member

Every commit will load atomic variable, can we avoid it?

youjiali1995 added 2 commits Jun 5, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
WAIT_TABLE_IS_EMPTY.store(is_empty, Ordering::Relaxed);
}

pub fn load_wait_table_is_empty() -> bool {

This comment has been minimized.

Copy link
@zhangjinpeng1987

zhangjinpeng1987 Jun 5, 2019

Member

s/load_wait_table_is_empty/wait_table_is_empty

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 Jun 5, 2019

Author Contributor

done

youjiali1995 added 2 commits Jun 5, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
…into avoid-useless-wake-up
Copy link
Member

zhangjinpeng1987 left a comment

LGTM

@youjiali1995 youjiali1995 added the S: LGT1 label Jun 6, 2019
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@AndreMouche AndreMouche self-assigned this Jun 6, 2019
Copy link
Member

AndreMouche left a comment

Rest LGTM

notify_waiter_mgr(&waiter_mgr_scheduler, lock_ts, key_hashes, commit_ts);
notify_deadlock_detector(&detector_scheduler, is_pessimistic_txn, lock_ts);
notify_waiter_mgr_if_needed(&waiter_mgr_scheduler, lock_ts, key_hashes, commit_ts);
notify_deadlock_detector_if_needed(&detector_scheduler, is_pessimistic_txn, lock_ts);

This comment has been minimized.

Copy link
@AndreMouche

AndreMouche Jun 6, 2019

Member

Could we merge these two functions into one since they are always used together? Maybe define a new function which call these two functions?

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 Jun 6, 2019

Author Contributor

The function needs many parameters, and I think it is a bit redundant.

if wait_table_is_empty {
None
} else {
Some(vec![])

This comment has been minimized.

Copy link
@AndreMouche

AndreMouche Jun 6, 2019

Member

I think we should insert current keys into the empty vec here.

This comment has been minimized.

Copy link
@youjiali1995

youjiali1995 Jun 6, 2019

Author Contributor

Nice catch!

youjiali1995 added 4 commits Jun 6, 2019
bugfix
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
Copy link
Member

AndreMouche left a comment

Rest LGTM

src/storage/txn/process.rs Outdated Show resolved Hide resolved
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
@youjiali1995 youjiali1995 force-pushed the youjiali1995:avoid-useless-wake-up branch from 0d87c69 to acc89d1 Jun 10, 2019
@youjiali1995

This comment has been minimized.

Copy link
Contributor Author

youjiali1995 commented Jun 10, 2019

Copy link
Member

zhangjinpeng1987 left a comment

LGTM

@youjiali1995 youjiali1995 merged commit de35885 into tikv:master Jun 10, 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:avoid-useless-wake-up branch Jun 10, 2019
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jun 13, 2019
* pessimistic-txn: avoid useless wake-up msgs if wait talbe is empty

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

* bugfix

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

* fix conflict

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

* address comment

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

* fix data race

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

* fix test

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

* address comment

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

* address comment

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

* bugfix

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

* address comment

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
youjiali1995 added a commit to youjiali1995/tikv that referenced this pull request Jun 13, 2019
* pessimistic-txn: avoid useless wake-up msgs if wait talbe is empty

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

* bugfix

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

* fix conflict

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

* address comment

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

* fix data race

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

* fix test

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

* address comment

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

* address comment

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

* bugfix

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

* address comment

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
sticnarf pushed a commit to sticnarf/tikv that referenced this pull request Oct 27, 2019
* pessimistic-txn: avoid useless wake-up msgs if wait talbe is empty

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

* bugfix

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

* fix conflict

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

* address comment

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

* fix data race

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

* fix test

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

* address comment

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

* address comment

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

* bugfix

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

* address comment

Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
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.