Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -66,6 +69,7 @@ public ContainerBalancerSelectionCriteria(
selectedContainers = new HashSet<>();
excludeContainers = balancerConfiguration.getExcludeContainers();
this.findSourceStrategy = findSourceStrategy;
this.setMap = new HashMap<>();
}

/**
Expand All @@ -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)) {
Copy link
Contributor

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

  1. all filtering can be done before setting to setMap
  2. Next filtering can be basic including selectedContainers and shouldBeExcluded

Suggested to use getCandidateContainers() to update setMap wrapping in another method.

NavigableSet<ContainerID> newSet =
Copy link
Contributor

Choose a reason for hiding this comment

The 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));
Copy link
Contributor

Choose a reason for hiding this comment

The 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<>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
Expand Down