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

Feat/etcd leader #209

Merged
merged 7 commits into from Aug 26, 2020
Merged

Feat/etcd leader #209

merged 7 commits into from Aug 26, 2020

Conversation

nioshield
Copy link
Contributor

Closes: #91

@nioshield nioshield added this to In progress in Release 1.0 via automation May 21, 2020
@shafreeck
Copy link
Contributor

Nice improvement! I love the idea to use Etcd to do the election.

However, I have some different ideas about the design of the election flow.

Use the synchronous way to run an election

What you did in this PR is in an asynchronous way, which is:

  1. Register to campaign the leader
  2. Set the leader flag as true
  3. Check the flag in a loop and call runExpire in the loop.

I prefer to use the synchronous way in fact, which is:

  1. Campaign the leader and block until it is elected
  2. Start the expiration goroutine, and keeps watching on the session's leadership
  3. Exit the goroutine and return to run Campaign if the session's leadership is lost.

Describe in the pseudo-code

for{
 sess = NewSession
 elec = NewElection(sess)
 elec.Campaign() // block until being elected
 StartExpire(sess)
}

func StartExpire(sess){
  for {
    select {
      case sess.Done():
        return
    }
  ...
 }
}

Avoid using a name like xxxutil

These general words like util, common should be avoided as can as possible. After refactoring like above, etcdutil is probably not used anymore. If it is needed, use the name to describe the feature like election, if you really need to wrap etcd as a thin layer, use the name etcd directly.

@arthurkiller
Copy link
Contributor

agreed

}

func (e *Elect) Campaign() {
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个 for 做的事情有点多, 感觉全哥说的那个方式挺好的

Copy link
Contributor

Choose a reason for hiding this comment

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

即:
for {
campaign()
waitExpire()
}

Release 1.0 automation moved this from In progress to Review in progress Jul 24, 2020
Release 1.0 automation moved this from Review in progress to Reviewer approved Aug 26, 2020
Copy link
Contributor

@arthurkiller arthurkiller left a comment

Choose a reason for hiding this comment

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

LGTM

@arthurkiller arthurkiller merged commit d9d9695 into master Aug 26, 2020
Release 1.0 automation moved this from Reviewer approved to Done Aug 26, 2020
@arthurkiller arthurkiller deleted the feat/etcd-leader branch August 26, 2020 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Release 1.0
  
Done
Development

Successfully merging this pull request may close these issues.

Improve the election of the GC/Expiration/Transfer leader
3 participants