-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-10160. Cache sort results in ContainerBalancerSelectionCriteria #6050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
63b257a
e18496a
968cde7
2f4ec85
05c5a05
54d336f
7f3b085
92c7ba0
7b590d2
b2c3bcb
8c00ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,11 @@ | |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.NavigableSet; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
@@ -52,6 +55,7 @@ public class ContainerBalancerSelectionCriteria { | |
| private Set<ContainerID> selectedContainers; | ||
| private Set<ContainerID> excludeContainers; | ||
| private FindSourceStrategy findSourceStrategy; | ||
| private Map<DatanodeDetails, NavigableSet<ContainerID>> setMap; | ||
|
|
||
| public ContainerBalancerSelectionCriteria( | ||
| ContainerBalancerConfiguration balancerConfiguration, | ||
|
|
@@ -66,6 +70,7 @@ public ContainerBalancerSelectionCriteria( | |
| selectedContainers = new HashSet<>(); | ||
| excludeContainers = balancerConfiguration.getExcludeContainers(); | ||
| this.findSourceStrategy = findSourceStrategy; | ||
| this.setMap = new HashMap<>(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -79,38 +84,37 @@ private boolean isContainerReplicatingOrDeleting(ContainerID containerID) { | |
| } | ||
|
|
||
| /** | ||
| * Gets containers that are suitable for moving based on the following | ||
| * required criteria: | ||
| * 1. Container must not be undergoing replication. | ||
| * 2. Container must not already be selected for balancing. | ||
| * 3. Container size should be closer to 5GB. | ||
| * 4. Container must not be in the configured exclude containers list. | ||
| * 5. Container should be closed. | ||
| * 6. If the {@link LegacyReplicationManager} is enabled, then the container should not be an EC container. | ||
| * @param node DatanodeDetails for which to find candidate containers. | ||
| * @return NavigableSet of candidate containers that satisfy the criteria. | ||
| * Get ContainerID Set for the Datanode, it will be returned as NavigableSet | ||
| * Since sorting will be time-consuming, the Set will be cached. | ||
| * | ||
| * @param node source datanode | ||
| * @return cached Navigable ContainerID Set | ||
| */ | ||
| public NavigableSet<ContainerID> getCandidateContainers( | ||
| DatanodeDetails node, long sizeMovedAlready) { | ||
| NavigableSet<ContainerID> containerIDSet = | ||
| new TreeSet<>(orderContainersByUsedBytes().reversed()); | ||
| try { | ||
| containerIDSet.addAll(nodeManager.getContainers(node)); | ||
| } catch (NodeNotFoundException e) { | ||
| LOG.warn("Could not find Datanode {} while selecting candidate " + | ||
| "containers for Container Balancer.", node.toString(), e); | ||
| return containerIDSet; | ||
| } | ||
| if (excludeContainers != null) { | ||
| containerIDSet.removeAll(excludeContainers); | ||
| public Set<ContainerID> getContainerIDSet(DatanodeDetails node) { | ||
| // Check if the node is registered at the beginning | ||
| if (!nodeManager.isNodeRegistered(node)) { | ||
| return Collections.emptySet(); | ||
| } | ||
| if (selectedContainers != null) { | ||
| containerIDSet.removeAll(selectedContainers); | ||
|
|
||
| try { | ||
| // Initialize containerSet for node | ||
| setMap.computeIfAbsent(node, n -> { | ||
| try { | ||
| addNodeToSetMap(n); | ||
| return setMap.get(n); | ||
| } catch (NodeNotFoundException e) { | ||
| LOG.warn("Could not find Datanode {} while selecting candidate " + | ||
| "containers for Container Balancer.", n.toString(), e); | ||
| return null; | ||
| } | ||
| }); | ||
| } catch (Exception e) { | ||
| LOG.error("An unexpected error occurred while processing the node.", e); | ||
| setMap.remove(node); | ||
| return Collections.emptySet(); | ||
| } | ||
|
|
||
| containerIDSet.removeIf( | ||
| containerID -> shouldBeExcluded(containerID, node, sizeMovedAlready)); | ||
| return containerIDSet; | ||
| return setMap.get(node); | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -165,7 +169,21 @@ private boolean isECContainerAndLegacyRMEnabled(ContainerInfo container) { | |
| && replicationManager.getConfig().isLegacyEnabled(); | ||
| } | ||
|
|
||
| private boolean shouldBeExcluded(ContainerID containerID, | ||
| /** | ||
| * Gets containers that are suitable for moving based on the following | ||
| * required criteria: | ||
| * 1. Container must not be in ExcludedContainers. | ||
| * 2. Container must not be in SelectedContainers. | ||
|
||
| * 3. Container must not be undergoing replication. | ||
| * 4. Container must not already be selected for balancing. | ||
| * 5. Container size should be closer to 5GB. | ||
| * 6. Container must not be in the configured exclude containers list. | ||
| * 7. Container should be closed. | ||
| * 8. If the {@link LegacyReplicationManager} is enabled, then the container should not be an EC container. | ||
| * @param node DatanodeDetails for which to find candidate containers. | ||
| * @return Set of candidate containers that satisfy the criteria. | ||
|
||
| */ | ||
| public boolean shouldBeExcluded(ContainerID containerID, | ||
| DatanodeDetails node, long sizeMovedAlready) { | ||
| ContainerInfo container; | ||
| try { | ||
|
|
@@ -175,7 +193,8 @@ private boolean shouldBeExcluded(ContainerID containerID, | |
| "candidate container. Excluding it.", containerID); | ||
| return true; | ||
| } | ||
| return !isContainerClosed(container, node) || isECContainerAndLegacyRMEnabled(container) || | ||
| return excludeContainers.contains(containerID) || selectedContainers.contains(containerID) || | ||
| !isContainerClosed(container, node) || isECContainerAndLegacyRMEnabled(container) || | ||
| isContainerReplicatingOrDeleting(containerID) || | ||
| !findSourceStrategy.canSizeLeaveSource(node, container.getUsedBytes()) | ||
| || breaksMaxSizeToMoveLimit(container.containerID(), | ||
|
|
@@ -242,4 +261,19 @@ public void setSelectedContainers( | |
| this.selectedContainers = selectedContainers; | ||
| } | ||
|
|
||
|
|
||
| private void addNodeToSetMap(DatanodeDetails node) | ||
sumitagrawl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throws NodeNotFoundException { | ||
| NavigableSet<ContainerID> newSet = | ||
| new TreeSet<>(orderContainersByUsedBytes().reversed()); | ||
| Set<ContainerID> idSet = nodeManager.getContainers(node); | ||
| if (excludeContainers != null) { | ||
| idSet.removeAll(excludeContainers); | ||
| } | ||
| if (selectedContainers != null) { | ||
| idSet.removeAll(selectedContainers); | ||
| } | ||
| newSet.addAll(idSet); | ||
| setMap.put(node, newSet); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.