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

fix:use reentrantLock instead of spinlock #987

Merged
merged 2 commits into from
May 8, 2019

Conversation

CoffeeLatte007
Copy link
Contributor

Ⅰ. Describe what this PR did

I'm sorry that I used spinLock in the wrong way before. The advantage of spinLock is that there is no need for thread context switch, but locksupport.park caused thread switch.

And SpinLock is good for locking parts to execute quickly, but we have IO operations in our changeStatus which is locking part, so to prevent CPU waste, I think ReentrantLock is more appropriate.

SpinLock can be seen as doing CAS all the time.The ReentrantLock lock the first time is CAS then it will be parked.

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented May 7, 2019

Codecov Report

Merging #987 into develop will decrease coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #987      +/-   ##
=============================================
- Coverage      38.45%   38.44%   -0.02%     
  Complexity      1046     1046              
=============================================
  Files            218      218              
  Lines           8687     8681       -6     
  Branches        1081     1078       -3     
=============================================
- Hits            3341     3337       -4     
  Misses          4924     4924              
+ Partials         422      420       -2
Impacted Files Coverage Δ Complexity Δ
...in/java/io/seata/server/session/GlobalSession.java 80.68% <66.66%> (+0.46%) 50 <3> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45239fe...fe0f796. Read the comment docs.

Copy link
Contributor

@leizhiyuan leizhiyuan left a comment

Choose a reason for hiding this comment

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

LGTM,

ps: if without considering more powerful lock in the future, maybe we can use ReentrantLock directly. do not need to be warpped by GlobalSessionLock

Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

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

LGTM

@CoffeeLatte007 CoffeeLatte007 merged commit aea407e into apache:develop May 8, 2019
nick-tan pushed a commit to nick-tan/seata that referenced this pull request Jul 12, 2019
@wangliang181230 wangliang181230 added this to the 0.5.* milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants