Skip to content
Browse files

client: ignore stale nodes in random node selection

This could, of course be a problem if all nodes are stale, but it's a
bigger problem for me now where I have one node that's almost, but not
completely dead.
  • Loading branch information...
1 parent 2cb2696 commit 35cce9f89b6a0c9fdf08521aae8e1dd4b047cd69 @dustin dustin committed Dec 11, 2013
Showing with 14 additions and 2 deletions.
  1. +14 −2 client/nodes.go
View
16 client/nodes.go
@@ -43,15 +43,27 @@ func (c *Client) Nodes() (map[string]StorageNode, error) {
return c.nodes, err
}
+const staleDuration = time.Minute
+
+func stale(s string) bool {
+ d, err := time.ParseDuration(s)
+ if err != nil {
+ return true
+ }
+ return d > staleDuration
+}
+
func (c *Client) RandomNode() (string, StorageNode, error) {
nodeMap, err := c.Nodes()
if err != nil {
return "", StorageNode{}, err
}
nodes := make([]string, 0, len(nodeMap))
- for k := range nodeMap {
- nodes = append(nodes, k)
+ for k, node := range nodeMap {
+ if !stale(node.HBAgeStr) {
+ nodes = append(nodes, k)
+ }
}
name := nodes[rand.Intn(len(nodes))]

0 comments on commit 35cce9f

Please sign in to comment.
Something went wrong with that request. Please try again.