Skip to content

Commit

Permalink
HDDS-10869. SCMNodeManager#getUsageInfo memory occupancy optimization (
Browse files Browse the repository at this point in the history
  • Loading branch information
guohao-rosicky authored Jun 6, 2024
1 parent d11752f commit 23e350b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ public Set<ContainerID> getContainers(UUID uuid)
return nodeStateMap.getContainers(uuid);
}

public int getContainerCount(UUID uuid)
throws NodeNotFoundException {
return nodeStateMap.getContainerCount(uuid);
}

/**
* Move Stale or Dead node to healthy if we got a heartbeat from them.
* Move healthy nodes to stale nodes if it is needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,7 @@ public DatanodeUsageInfo getUsageInfo(DatanodeDetails dn) {
SCMNodeStat stat = getNodeStatInternal(dn);
DatanodeUsageInfo usageInfo = new DatanodeUsageInfo(dn, stat);
try {
int containerCount = getContainers(dn).size();
usageInfo.setContainerCount(containerCount);
usageInfo.setContainerCount(getContainerCount(dn));
} catch (NodeNotFoundException ex) {
LOG.error("Unknown datanode {}.", dn, ex);
}
Expand Down Expand Up @@ -1458,6 +1457,11 @@ public Set<ContainerID> getContainers(DatanodeDetails datanodeDetails)
return nodeStateManager.getContainers(datanodeDetails.getUuid());
}

public int getContainerCount(DatanodeDetails datanodeDetails)
throws NodeNotFoundException {
return nodeStateManager.getContainerCount(datanodeDetails.getUuid());
}

@Override
public void addDatanodeCommand(UUID dnId, SCMCommand command) {
writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,16 @@ public Set<ContainerID> getContainers(UUID uuid)
}
}

public int getContainerCount(UUID uuid) throws NodeNotFoundException {
lock.readLock().lock();
try {
checkIfNodeExist(uuid);
return nodeToContainer.get(uuid).size();
} finally {
lock.readLock().unlock();
}
}

public void removeContainer(UUID uuid, ContainerID containerID) throws
NodeNotFoundException {
lock.writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public Response getDatanodes() {
}
});
try {
Set<ContainerID> allContainers = nodeManager.getContainers(datanode);

builder.withContainers(allContainers.size());
builder.withContainers(nodeManager.getContainerCount(datanode));
builder.withOpenContainers(openContainers.get());
} catch (NodeNotFoundException ex) {
LOG.warn("Cannot get containers, datanode {} not found.",
Expand Down

0 comments on commit 23e350b

Please sign in to comment.