Search in sources :

Example 1 with ContainerState

use of org.apache.hadoop.hdds.scm.container.states.ContainerState in project ozone by apache.

the class ContainerStateManagerImpl method getMatchingContainer.

public ContainerInfo getMatchingContainer(final long size, String owner, PipelineID pipelineID, NavigableSet<ContainerID> containerIDs) {
    if (containerIDs.isEmpty()) {
        return null;
    }
    // Get the last used container and find container above the last used
    // container ID.
    final ContainerState key = new ContainerState(owner, pipelineID);
    final ContainerID lastID = lastUsedMap.getOrDefault(key, containerIDs.first());
    // There is a small issue here. The first time, we will skip the first
    // container. But in most cases it will not matter.
    NavigableSet<ContainerID> resultSet = containerIDs.tailSet(lastID, false);
    if (resultSet.isEmpty()) {
        resultSet = containerIDs;
    }
    lock.readLock().lock();
    try {
        ContainerInfo selectedContainer = findContainerWithSpace(size, resultSet);
        if (selectedContainer == null) {
            // If we did not find any space in the tailSet, we need to look for
            // space in the headset, we need to pass true to deal with the
            // situation that we have a lone container that has space. That is we
            // ignored the last used container under the assumption we can find
            // other containers with space, but if have a single container that is
            // not true. Hence we need to include the last used container as the
            // last element in the sorted set.
            resultSet = containerIDs.headSet(lastID, true);
            selectedContainer = findContainerWithSpace(size, resultSet);
        }
        // TODO: cleanup entries in lastUsedMap
        if (selectedContainer != null) {
            lastUsedMap.put(key, selectedContainer.containerID());
        }
        return selectedContainer;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : ContainerState(org.apache.hadoop.hdds.scm.container.states.ContainerState)

Aggregations

ContainerState (org.apache.hadoop.hdds.scm.container.states.ContainerState)1