-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-10160. Cache sort results in ContainerBalancerSelectionCriteria #6032
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 all commits
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 |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ | |
| import org.slf4j.LoggerFactory; | ||
|
|
||
| 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 +54,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 +69,7 @@ public ContainerBalancerSelectionCriteria( | |
| selectedContainers = new HashSet<>(); | ||
| excludeContainers = balancerConfiguration.getExcludeContainers(); | ||
| this.findSourceStrategy = findSourceStrategy; | ||
| this.setMap = new HashMap<>(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -92,15 +96,31 @@ private boolean isContainerReplicatingOrDeleting(ContainerID containerID) { | |
| */ | ||
| public NavigableSet<ContainerID> getCandidateContainers( | ||
| DatanodeDetails node, long sizeMovedAlready) { | ||
| NavigableSet<ContainerID> containerIDSet = | ||
| new TreeSet<>(orderContainersByUsedBytes().reversed()); | ||
| // Initialize containerSet for node | ||
| if (!setMap.containsKey(node)) { | ||
| NavigableSet<ContainerID> newSet = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can return Set<> and can change NavigableSet<> to Set in usages, but implementation can refer TreeMap. |
||
| new TreeSet<>(orderContainersByUsedBytes().reversed()); | ||
| try { | ||
| newSet.addAll(nodeManager.getContainers(node)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, sorting can be done on filtered containers only to avoid sorting of containers not meeting criteria. |
||
| } catch (NodeNotFoundException e) { | ||
| LOG.warn("Could not find Datanode {} while selecting candidate " + | ||
| "containers for Container Balancer.", node.toString(), e); | ||
| return newSet; | ||
| } | ||
| setMap.put(node, newSet); | ||
| } | ||
|
|
||
| // In case the node is removed | ||
| try { | ||
| containerIDSet.addAll(nodeManager.getContainers(node)); | ||
| nodeManager.getContainers(node); | ||
| } catch (NodeNotFoundException e) { | ||
| LOG.warn("Could not find Datanode {} while selecting candidate " + | ||
| "containers for Container Balancer.", node.toString(), e); | ||
| return containerIDSet; | ||
| setMap.remove(node); | ||
| return new TreeSet<>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can return Collections.emptySet() |
||
| } | ||
|
|
||
| NavigableSet<ContainerID> containerIDSet = setMap.get(node); | ||
| if (excludeContainers != null) { | ||
| containerIDSet.removeAll(excludeContainers); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContaienrBalancerSelectionCriteria is applicable within one iteration
Suggested to use getCandidateContainers() to update setMap wrapping in another method.