Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
control: Improve node classification (#37)
Browse files Browse the repository at this point in the history
- Make classification in `NodeIsNew()` less overfit.
- Return a clear error when the scaling values in Nomad and Consul are
  mismatched

Resolves #36 
Resolves #11
  • Loading branch information
beautifulentropy authored Aug 17, 2022
1 parent 0db713b commit a2eb24f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion cmd/attache-control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ func (l *leader) joinOrCreateRedisCluster() error {
return nil
}

// This should never happen as long as the job and scaling opts match.
clusterNodesCount := len(primaryNodesInCluster) + len(replicaNodesInCluster)
if l.scalingOpts.NodesMissing(clusterNodesCount) == 0 {
// This will only happen when the Nomad job is scaled without a
// corresponding change to the scaling opts in Consul.
return fmt.Errorf("%s Nomad group count was scaled without a corresponding change to scaling opts", l.RedisOpts.NodeAddr)
}

// This should never happen.
return fmt.Errorf("%s couldn't be added to an existing cluster", l.RedisOpts.NodeAddr)
}

Expand Down
14 changes: 11 additions & 3 deletions src/redis/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ type Client struct {
Client *redis.Client
}

// IsNew returns 'true' if the contents of 'CLUSTER INFO' match those expected
// of a node that has never been joined a cluster. 'cluster_state' will be
// 'fail' as a minumum of 3 nodes is required. 'cluster_known_nodes' will be '1'
// (self) since it's never been introduced to other nodes. 'cluster_slots_count'
// and cluster_size' will both be '0' since slots are only assigned as part of
// the inital clustering or during cluster rebalancing. If any of these fields
// holds a different value, 'false' is returned.
func (h *Client) IsNew() (bool, error) {
var infoMatchingNewNodes = clusterInfo{"fail", 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}
clusterInfo, err := h.GetClusterInfo()
c, err := h.GetClusterInfo()
if err != nil {
return false, err
} else if *clusterInfo == infoMatchingNewNodes {
}

if c.State == "fail" && c.SlotsAssigned == 0 && c.KnownNodes == 1 && c.Size == 0 {
return true, nil
} else {
return false, nil
Expand Down

0 comments on commit a2eb24f

Please sign in to comment.