Skip to content

Commit

Permalink
Adds key based election
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Jul 19, 2020
1 parent 2917dd8 commit 4052e9c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions goserverapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,8 @@ func (s *GoServer) registerServer(IP string, servername string, external bool, v
return r.GetService().Port, nil
}

func (s *GoServer) runElection(elected chan error, complete chan bool) {
command := exec.Command("etcdctl", "elect", s.Registry.Name, s.Registry.Identifier)
func (s *GoServer) runElection(key string, elected chan error, complete chan bool) {
command := exec.Command("etcdctl", "elect", s.Registry.Name+key, s.Registry.Identifier)
out, _ := command.StdoutPipe()
if out != nil {
scanner := bufio.NewScanner(out)
Expand Down Expand Up @@ -1463,7 +1463,21 @@ func (s *GoServer) Elect() (func(), error) {
complete <- true
}

go s.runElection(elected, complete)
go s.runElection("", elected, complete)

err := <-elected
return rf, err
}

//Elect elect me
func (s *GoServer) ElectKey(key string) (func(), error) {
elected := make(chan error)
complete := make(chan bool)
rf := func() {
complete <- true
}

go s.runElection(key, elected, complete)

err := <-elected
return rf, err
Expand Down

0 comments on commit 4052e9c

Please sign in to comment.