-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Proxies & Config API #582
Proxies & Config API #582
Changes from 1 commit
1d961b8
f5698d3
fddbf35
c8d6b26
063f3b5
c3b4afc
fe4dee0
ddce52c
2a7fdfe
3cd83c6
c324775
3fff1a8
c916883
c0a59b3
e9a1ac1
7d4fda5
174b9ff
62b89a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,6 @@ func (s *PeerServer) ClusterConfig() *ClusterConfig { | |
// SetClusterConfig updates the current cluster configuration. | ||
// Adjusting the active size will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't leave me hanging! :) |
||
func (s *PeerServer) SetClusterConfig(c *ClusterConfig) error { | ||
prevActiveSize := s.clusterConfig.ActiveSize | ||
s.clusterConfig = c | ||
|
||
// Validate configuration. | ||
|
@@ -294,9 +293,10 @@ func (s *PeerServer) HTTPHandler() http.Handler { | |
router.HandleFunc("/version/{version:[0-9]+}/check", s.VersionCheckHttpHandler) | ||
router.HandleFunc("/upgrade", s.UpgradeHttpHandler) | ||
router.HandleFunc("/join", s.JoinHttpHandler) | ||
router.HandleFunc("/promote", s.PromoteHttpHandler).Methods("POST") | ||
router.HandleFunc("/remove/{name:.+}", s.RemoveHttpHandler) | ||
router.HandleFunc("/config", s.getClusterConfigHttpHandler).Methods("GET") | ||
router.HandleFunc("/config", s.setClusterConfigHttpHandler).Methods("POST") | ||
router.HandleFunc("/config", s.setClusterConfigHttpHandler).Methods("PUT") | ||
router.HandleFunc("/vote", s.VoteHttpHandler) | ||
router.HandleFunc("/log", s.GetLogHttpHandler) | ||
router.HandleFunc("/log/append", s.AppendEntriesHttpHandler) | ||
|
@@ -632,18 +632,45 @@ func (s *PeerServer) monitorActive(closeChan chan bool) { | |
peerCount := s.registry.PeerCount() | ||
proxies := s.registry.Proxies() | ||
peers := s.registry.Peers() | ||
fmt.Println("active.3»", peers) | ||
if index := sort.SearchStrings(peers, s.Config.Name); index < len(peers) && peers[index] == s.Config.Name { | ||
peers = append(peers[:index], peers[index+1:]...) | ||
} | ||
|
||
fmt.Println("active.1»", activeSize, peerCount) | ||
fmt.Println("active.2»", proxies) | ||
|
||
// If we have more active nodes than we should then demote. | ||
if peerCount > activeSize { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like a logabble event. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benbjohnson I do not think we should handle this case here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benbjohnson Any thought on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiangli-cmu I'd rather keep the cluster size management in one spot. The goal of the command is to set a target size but this function provides an abstraction about how to move the cluster to that size. Moving the functionality to the actual request poses two problems:
|
||
peer := peers[rand.Intn(len(peers))] | ||
fmt.Println("active.demote»", peer) | ||
if _, err := s.raftServer.Do(&RemoveCommand{Name: peer}); err != nil { | ||
log.Infof("%s: warning: demotion error: %v", s.Config.Name, err) | ||
} | ||
continue | ||
} | ||
|
||
// If we don't have enough active nodes then try to promote a proxy. | ||
if peerCount < activeSize && len(proxies) > 0 { | ||
proxy := proxies[rand.Intn(len(proxies))] | ||
proxyPeerURL, _ := s.registry.ProxyPeerURL(proxy) | ||
log.Infof("%s: promoting: %v (%s)", s.Config.Name, proxy, proxyPeerURL) | ||
|
||
// Notify proxy to promote itself. | ||
client := &http.Client{ | ||
Transport: &http.Transport{ | ||
DisableKeepAlives: false, | ||
ResponseHeaderTimeout: ActiveMonitorTimeout, | ||
}, | ||
} | ||
resp, err := client.Post(fmt.Sprintf("%s/promote", proxyPeerURL), "application/json", nil) | ||
if err != nil { | ||
log.Infof("%s: warning: promotion error: %v", s.Config.Name, err) | ||
} else if resp.StatusCode != http.StatusOK { | ||
log.Infof("%s: warning: promotion failure: %v", s.Config.Name, resp.StatusCode) | ||
} | ||
continue | ||
} | ||
} | ||
} | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"net/url" | ||
"path" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
"sync" | ||
|
||
|
@@ -48,6 +49,7 @@ func (r *Registry) Peers() []string { | |
for name, _ := range r.peers { | ||
names = append(names, name) | ||
} | ||
sort.Sort(sort.StringSlice(names)) | ||
return names | ||
} | ||
|
||
|
@@ -57,6 +59,7 @@ func (r *Registry) Proxies() []string { | |
for name, _ := range r.proxies { | ||
names = append(names, name) | ||
} | ||
sort.Sort(sort.StringSlice(names)) | ||
return names | ||
} | ||
|
||
|
@@ -70,7 +73,11 @@ func (r *Registry) RegisterPeer(name string, peerURL string, machURL string) err | |
// RegisterProxy adds a proxy to the registry. | ||
func (r *Registry) RegisterProxy(name string, peerURL string, machURL string) error { | ||
// TODO(benbjohnson): Disallow proxies that are already peers. | ||
return r.register(RegistryProxyKey, name, peerURL, machURL) | ||
if err := r.register(RegistryProxyKey, name, peerURL, machURL); err != nil { | ||
return err | ||
} | ||
r.proxies[name] = r.load(RegistryProxyKey, name) | ||
return nil | ||
} | ||
|
||
func (r *Registry) register(key, name string, peerURL string, machURL string) error { | ||
|
@@ -153,7 +160,9 @@ func (r *Registry) ClientURL(name string) (string, bool) { | |
|
||
func (r *Registry) clientURL(key, name string) (string, bool) { | ||
if r.peers[name] == nil { | ||
r.peers[name] = r.load(key, name) | ||
if node := r.load(key, name); node != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/node/peer ? |
||
r.peers[name] = node | ||
} | ||
} | ||
|
||
if node := r.peers[name]; node != nil { | ||
|
@@ -184,7 +193,9 @@ func (r *Registry) PeerURL(name string) (string, bool) { | |
|
||
func (r *Registry) peerURL(key, name string) (string, bool) { | ||
if r.peers[name] == nil { | ||
r.peers[name] = r.load(key, name) | ||
if node := r.load(key, name); node != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/node/peer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it as |
||
r.peers[name] = node | ||
} | ||
} | ||
|
||
if node := r.peers[name]; node != nil { | ||
|
@@ -203,7 +214,9 @@ func (r *Registry) ProxyClientURL(name string) (string, bool) { | |
|
||
func (r *Registry) proxyClientURL(key, name string) (string, bool) { | ||
if r.proxies[name] == nil { | ||
r.proxies[name] = r.load(key, name) | ||
if node := r.load(key, name); node != nil { | ||
r.proxies[name] = node | ||
} | ||
} | ||
if node := r.proxies[name]; node != nil { | ||
return node.url, true | ||
|
@@ -215,12 +228,14 @@ func (r *Registry) proxyClientURL(key, name string) (string, bool) { | |
func (r *Registry) ProxyPeerURL(name string) (string, bool) { | ||
r.Lock() | ||
defer r.Unlock() | ||
return r.proxyPeerURL(RegistryProxyKey,name) | ||
return r.proxyPeerURL(RegistryProxyKey, name) | ||
} | ||
|
||
func (r *Registry) proxyPeerURL(key, name string) (string, bool) { | ||
if r.proxies[name] == nil { | ||
r.proxies[name] = r.load(key, name) | ||
if node := r.load(key, name); node != nil { | ||
r.proxies[name] = node | ||
} | ||
} | ||
if node := r.proxies[name]; node != nil { | ||
return node.peerURL, true | ||
|
@@ -278,7 +293,7 @@ func (r *Registry) load(key, name string) *node { | |
} | ||
|
||
// Retrieve from store. | ||
e, err := r.store.Get(path.Join(RegistryPeerKey, name), false, false) | ||
e, err := r.store.Get(path.Join(key, name), false, false) | ||
if err != nil { | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the plan here? Just flag and ignore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want it as a deprecation warning or an actual CLI error? It seems important enough that users should be notified to remove their
-max-cluster-size
.