Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
huachaohuang committed Dec 6, 2016
1 parent 21a0191 commit e0f0ae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,17 @@ func parseConstraint(cfg *ConstraintConfig) (*Constraint, error) {
for _, label := range cfg.Labels {
kv := strings.Split(strings.ToLower(label), "=")
if len(kv) != 2 {
return nil, errors.Errorf("invalid constraint %q", label)
return nil, errors.Errorf("invalid label %q", label)
}
k, v := kv[0], kv[1]
if !validLabel.MatchString(k) || !validLabel.MatchString(v) {
return nil, errors.Errorf("invalid constraint %q, must match %s", label, validLabel)
if !validLabel.MatchString(k) {
return nil, errors.Errorf("invalid label key %q, must match %s", k, validLabel)
}
if !validLabel.MatchString(v) {
return nil, errors.Errorf("invalid label value %q, must match %s", k, validLabel)
}
if _, ok := labels[k]; ok {
return nil, errors.Errorf("duplicated constraint %q", label)
return nil, errors.Errorf("duplicated label %q", label)
}
labels[k] = v
}
Expand Down
2 changes: 1 addition & 1 deletion server/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (stores storesByID) Less(i, j int) bool { return stores[i].GetId() < stores
// Although we can use a more optimize algorithm, but it may be hard
// to understand by most users.
// So we decide to use a straight forward algorithm to match stores
// and constraints one by one in order, and it works find in most
// and constraints one by one in order, and it works fine in most
// cases. However, if we add more complicated constraints in the
// future, we may need to reconsider the algorithm.
func (c *Constraints) Match(stores []*storeInfo) *MatchResult {
Expand Down

0 comments on commit e0f0ae0

Please sign in to comment.