Skip to content

Commit 35fe68a

Browse files
committed
fix a known issue in SetNode
1 parent b83ff93 commit 35fe68a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

cluster/calcium/node.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -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)