We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
This is the original code
synchronized (knownMaxTermInGroup) { switch (x.getVoteResult()) { case ACCEPT: acceptedNum.incrementAndGet(); break; case REJECT_ALREADY_HAS_LEADER: alreadyHasLeader.compareAndSet(false, true); break; case REJECT_TERM_SMALL_THAN_LEDGER: case REJECT_EXPIRED_VOTE_TERM: if (x.getTerm() > knownMaxTermInGroup.get()) { knownMaxTermInGroup.set(x.getTerm()); } break; case REJECT_EXPIRED_LEDGER_TERM: case REJECT_SMALL_LEDGER_END_INDEX: biggerLedgerNum.incrementAndGet(); break; case REJECT_TERM_NOT_READY: notReadyTermNum.incrementAndGet(); break; case REJECT_ALREADY_VOTED: case REJECT_TAKING_LEADERSHIP: default: break; } }
We can delete the synchronized by use CAS. code as following
switch (x.getVoteResult()) { case ACCEPT: acceptedNum.incrementAndGet(); break; case REJECT_ALREADY_HAS_LEADER: alreadyHasLeader.compareAndSet(false, true); break; case REJECT_TERM_SMALL_THAN_LEDGER: case REJECT_EXPIRED_VOTE_TERM: // cas update for (;;) { long maxTermInGroup = knownMaxTermInGroup.get(); if (x.getTerm() <= maxTermInGroup) { break; } if (knownMaxTermInGroup.compareAndSet(maxTermInGroup, x.getTerm())) { break; } } break; case REJECT_EXPIRED_LEDGER_TERM: case REJECT_SMALL_LEDGER_END_INDEX: biggerLedgerNum.incrementAndGet(); break; case REJECT_TERM_NOT_READY: notReadyTermNum.incrementAndGet(); break; case REJECT_ALREADY_VOTED: case REJECT_TAKING_LEADERSHIP: default: break; }
The text was updated successfully, but these errors were encountered:
[ISSUE openmessaging#312] Optimize DLedgerLeaderElector.maintainAsCan…
376d9c8
…didate Lock
No branches or pull requests
This is the original code
We can delete the synchronized by use CAS. code as following
The text was updated successfully, but these errors were encountered: