From c7656041a5eb21dcf88a3ce930de78552a5a8273 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 13 Aug 2018 14:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3:=20=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E5=99=A8=E6=8C=87=E5=AE=9A=E7=BD=91=E7=BB=9C=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/scheduler/core/context.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/scheduler/core/context.go b/pkg/scheduler/core/context.go index a05f4987de..133fb1e87e 100644 --- a/pkg/scheduler/core/context.go +++ b/pkg/scheduler/core/context.go @@ -163,15 +163,20 @@ func (c *MinCounters) Add(counter Counter) { } func (c *MinCounters) GetCount() int64 { - n := EmptyCapacity - for _, c0 := range c.counters { + if len(c.counters) == 0 { + return EmptyCapacity + } + minCount := c.counters[0].GetCount() + if len(c.counters) == 1 { + return minCount + } + for _, c0 := range c.counters[1:] { count := c0.GetCount() - if count != EmptyCapacity && count < n { - n = count + if count < minCount { + minCount = count } } - - return n + return minCount } type Capacity struct { @@ -448,7 +453,9 @@ func (u *Unit) SetCapacity(id string, name string, capacity Counter) error { // Capacity must >= 0 if !validateCapacityInput(capacity) { - return fmt.Errorf("Capacity invalid: %d", capacity) + err := fmt.Errorf("Capacity counter invalid: %#v, count: %d", capacity, capacity.GetCount()) + log.Errorf("SetCapacity error: %v", err) + return err } log.V(10).Debugf("%q setCapacity id: %s, capacity: %d", name, id, capacity.GetCount())