mirror of https://github.com/docker/docs.git
Merge pull request #1048 from aluzzardi/leader-prefix
Leader Election: Use same path prefix as discovery.
This commit is contained in:
commit
1ab4129df6
|
@ -120,9 +120,10 @@ func setupReplication(c *cli.Context, cluster cluster.Cluster, server *api.Serve
|
||||||
log.Fatal("Leader election is only supported with consul, etcd and zookeeper discovery.")
|
log.Fatal("Leader election is only supported with consul, etcd and zookeeper discovery.")
|
||||||
}
|
}
|
||||||
client := kvDiscovery.Store()
|
client := kvDiscovery.Store()
|
||||||
|
p := path.Join(kvDiscovery.Prefix(), leaderElectionPath)
|
||||||
|
|
||||||
candidate := leadership.NewCandidate(client, leaderElectionPath, addr)
|
candidate := leadership.NewCandidate(client, p, addr)
|
||||||
follower := leadership.NewFollower(client, leaderElectionPath)
|
follower := leadership.NewFollower(client, p)
|
||||||
|
|
||||||
primary := api.NewPrimary(cluster, tlsConfig, &statusHandler{cluster, candidate, follower}, c.Bool("cors"))
|
primary := api.NewPrimary(cluster, tlsConfig, &statusHandler{cluster, candidate, follower}, c.Bool("cors"))
|
||||||
replica := api.NewReplica(primary, tlsConfig)
|
replica := api.NewReplica(primary, tlsConfig)
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Discovery struct {
|
||||||
store store.Store
|
store store.Store
|
||||||
heartbeat time.Duration
|
heartbeat time.Duration
|
||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
|
prefix string
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,20 +40,19 @@ func Init() {
|
||||||
// Initialize is exported
|
// Initialize is exported
|
||||||
func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Duration) error {
|
func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Duration) error {
|
||||||
var (
|
var (
|
||||||
parts = strings.SplitN(uris, "/", 2)
|
parts = strings.SplitN(uris, "/", 2)
|
||||||
addrs = strings.Split(parts[0], ",")
|
addrs = strings.Split(parts[0], ",")
|
||||||
prefix = ""
|
err error
|
||||||
err error
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A custom prefix to the path can be optionally used.
|
// A custom prefix to the path can be optionally used.
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
prefix = parts[1]
|
s.prefix = parts[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
s.heartbeat = heartbeat
|
s.heartbeat = heartbeat
|
||||||
s.ttl = ttl
|
s.ttl = ttl
|
||||||
s.path = path.Join(prefix, discoveryPath)
|
s.path = path.Join(s.prefix, discoveryPath)
|
||||||
|
|
||||||
// Creates a new store, will ignore options given
|
// Creates a new store, will ignore options given
|
||||||
// if not supported by the chosen store
|
// if not supported by the chosen store
|
||||||
|
@ -139,3 +139,8 @@ func (s *Discovery) Register(addr string) error {
|
||||||
func (s *Discovery) Store() store.Store {
|
func (s *Discovery) Store() store.Store {
|
||||||
return s.store
|
return s.store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefix returns the store prefix
|
||||||
|
func (s *Discovery) Prefix() string {
|
||||||
|
return s.prefix
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue