Skip to content

Commit

Permalink
fix node set
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent f4a05d8 commit 62ac3b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 3 additions & 1 deletion cluster/calcium/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
if len(opts.Resources) == 0 {
return nil
}
origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, opts.Resources, nil, opts.Delta, plugins.Incr)
origin, _, err = c.rmgr.SetNodeResourceCapacity(ctx, n.Name, nil, opts.Resources, opts.Delta, plugins.Incr)
return err
},
// then: update node metadata
Expand All @@ -233,6 +233,8 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ
n.ResourceInfo.Capacity, n.ResourceInfo.Usage, n.ResourceInfo.Diffs, _ = c.rmgr.GetNodeResourceInfo(ctx, node.Name, nil, false)
// use send to update the usage
_ = c.pool.Invoke(func() { c.doSendNodeMetrics(context.TODO(), n) })
// remap all container
_ = c.pool.Invoke(func() { c.RemapResourceAndLog(ctx, logger, node) })
return nil
},
// rollback: update node resource capacity in reverse
Expand Down
6 changes: 6 additions & 0 deletions resource/cobalt/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n
// commit: call plugins to set node resource
func(ctx context.Context) error {
resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.SetNodeResourceCapacityResponse, error) {
if nodeResource[plugin.Name()] == nil && nodeResourceRequest[plugin.Name()] == nil {
return nil, nil
}
resp, err := plugin.SetNodeResourceCapacity(ctx, nodename, nodeResource[plugin.Name()], nodeResourceRequest[plugin.Name()], delta, incr)
if err != nil {
logger.Errorf(ctx, err, "plugin %+v failed to set node resource capacity", plugin.Name())
Expand All @@ -333,6 +336,9 @@ func (m Manager) SetNodeResourceCapacity(ctx context.Context, nodename string, n

if err != nil {
for plugin, resp := range resps {
if resp == nil {
continue
}
rollbackPlugins = append(rollbackPlugins, plugin)
before[plugin.Name()] = resp.Before
after[plugin.Name()] = resp.After
Expand Down
26 changes: 14 additions & 12 deletions resource/plugins/cpumem/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ func (n *NodeResourceInfo) RemoveEmptyCores() {
}

func (n *NodeResourceInfo) Validate() error {
if n.Capacity == nil || len(n.Capacity.CPUMap) == 0 {
if n.Capacity == nil {
return ErrInvalidCapacity
}

if len(n.Capacity.CPUMap) == 0 {
return ErrInvalidCPUMap
}

if n.Usage == nil {
n.Usage = &NodeResource{
CPU: 0,
Expand All @@ -125,12 +130,9 @@ func (n *NodeResourceInfo) Validate() error {
n.Usage.NUMA[cpuID] = numaNodeID
}
}
if len(n.Capacity.CPUMap) == 0 {
return ErrInvalidCPUMap
}

for cpu, piecesUsed := range n.Usage.CPUMap {
if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || piecesUsed < 0 || totalPieces < 0 || piecesUsed > totalPieces {
if totalPieces, ok := n.Capacity.CPUMap[cpu]; !ok || totalPieces < 0 || piecesUsed > totalPieces {
return ErrInvalidCPUMap
}
}
Expand Down Expand Up @@ -221,9 +223,9 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet
}
}

for index, numaMemoryNode := range rawParams.StringSlice("numa-memory") {
for index, nodeMemory := range rawParams.StringSlice("numa-memory") {
nodeID := fmt.Sprintf("%d", index)
mem, err := coreutils.ParseRAMInHuman(numaMemoryNode)
mem, err := coreutils.ParseRAMInHuman(nodeMemory)
if err != nil {
return err
}
Expand All @@ -233,20 +235,20 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet
return nil
}

func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, rawParams resourcetypes.RawParams) {
func (n *NodeResourceRequest) LoadFromOrigin(nodeResource *NodeResource, resourceRequest resourcetypes.RawParams) {
if n == nil {
return
}
if !rawParams.IsSet("cpu") {
if !resourceRequest.IsSet("cpu") {
n.CPUMap = nodeResource.CPUMap
}
if !rawParams.IsSet("memory") {
if !resourceRequest.IsSet("memory") {
n.Memory = nodeResource.Memory
}
if !rawParams.IsSet("numa-cpu") {
if !resourceRequest.IsSet("numa-cpu") {
n.NUMA = nodeResource.NUMA
}
if !rawParams.IsSet("numa-memory") {
if !resourceRequest.IsSet("numa-memory") {
n.NUMAMemory = nodeResource.NUMAMemory
}
}

0 comments on commit 62ac3b7

Please sign in to comment.