Skip to content

Commit 266dc06

Browse files
committed
fix a known issue in SetNode
1 parent b83ff93 commit 266dc06

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cluster/calcium/node.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
7777
err := c.store.SetNodeStatus(ctx, node, -1)
7878
if err != nil {
7979
// don't return here
80-
log.Errorf(ctx, "[SetNode] failed to set node status, err: %v", err)
80+
log.Errorf(ctx, "[SetNode] failed to set node status, err: %+v", errors.WithStack(err))
8181
}
8282
}
8383
if opts.WorkloadsDown {
@@ -154,15 +154,17 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
154154
case !ok && cpuShare > 0: // incr CPU
155155
n.CPU[cpuID] = cpuShare
156156
n.InitCPU[cpuID] = cpuShare
157-
case ok && cpuShare == 0: // decr CPU
158-
delete(n.CPU, cpuID)
159-
delete(n.InitCPU, cpuID)
160157
case ok: // decr share
161158
n.CPU[cpuID] += cpuShare
162159
n.InitCPU[cpuID] += cpuShare
163160
if n.CPU[cpuID] < 0 {
164161
return logger.Err(ctx, errors.WithStack(types.ErrBadCPU))
165162
}
163+
if n.InitCPU[cpuID] == 0 {
164+
// decr CPU
165+
delete(n.CPU, cpuID)
166+
delete(n.InitCPU, cpuID)
167+
}
166168
}
167169
}
168170
// update volume

cluster/calcium/node_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ func TestSetNode(t *testing.T) {
250250
n, err = c.SetNode(ctx, setOpts)
251251
assert.Error(t, err)
252252
// succ set cpu, add and del
253-
n.CPU = types.CPUMap{"1": 1, "2": 2}
253+
n.CPU = types.CPUMap{"1": 10, "2": 2}
254254
n.InitCPU = types.CPUMap{"1": 10, "2": 10}
255-
setOpts.DeltaCPU = types.CPUMap{"1": 0, "2": -1, "3": 10}
255+
setOpts.DeltaCPU = types.CPUMap{"1": -10, "2": -1, "3": 10}
256256
n, err = c.SetNode(ctx, setOpts)
257257
assert.NoError(t, err)
258258
_, ok := n.CPU["1"]

0 commit comments

Comments
 (0)