From e9bf3bb84f585b2759bdfc09eadbb0ce7b3292c1 Mon Sep 17 00:00:00 2001 From: Huachao Huang Date: Tue, 6 Dec 2016 15:20:23 +0800 Subject: [PATCH] address comment --- server/config.go | 11 +++++++---- server/constraints.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/config.go b/server/config.go index 5db8518852f..7d795253595 100644 --- a/server/config.go +++ b/server/config.go @@ -415,14 +415,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 } diff --git a/server/constraints.go b/server/constraints.go index e0a233afd4a..4c314533c4b 100644 --- a/server/constraints.go +++ b/server/constraints.go @@ -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 {