diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerQueryKey.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerQueryKey.java deleted file mode 100644 index ab9f0be7bd36..000000000000 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerQueryKey.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hdds.scm.container.states; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.hadoop.hdds.client.ReplicationConfig; -import org.apache.hadoop.hdds.protocol.proto.HddsProtos; - -/** - * Key for the Caching layer for Container Query. - */ -public class ContainerQueryKey { - private final HddsProtos.LifeCycleState state; - private final String owner; - private final ReplicationConfig repConfig; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - ContainerQueryKey that = (ContainerQueryKey) o; - - return new EqualsBuilder() - .append(getState(), that.getState()) - .append(getOwner(), that.getOwner()) - .append(getReplicationConfig(), that.getReplicationConfig()) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(61, 71) - .append(getState()) - .append(getOwner()) - .append(getReplicationConfig()) - .toHashCode(); - } - - /** - * Constructor for ContainerQueryKey. - * @param state LifeCycleState - * @param owner - Name of the Owner. - * @param repConfig - Replication Config. - */ - public ContainerQueryKey(HddsProtos.LifeCycleState state, String owner, - ReplicationConfig repConfig) { - this.state = state; - this.owner = owner; - this.repConfig = repConfig; - } - - /** - * Returns the state of containers which this key represents. - * @return LifeCycleState - */ - public HddsProtos.LifeCycleState getState() { - return state; - } - - /** - * Returns the owner of containers which this key represents. - * @return Owner - */ - public String getOwner() { - return owner; - } - - /** - * Returns the replication Config of containers which this key represents. - * @return ReplicationConfig - */ - public ReplicationConfig getReplicationConfig() { - return repConfig; - } - -} diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerStateMap.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerStateMap.java index a895aa4bed9b..71a6f7824a89 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerStateMap.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerStateMap.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.NavigableSet; import java.util.Set; -import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import org.apache.hadoop.hdds.client.ReplicationConfig; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState; @@ -75,16 +74,12 @@ public class ContainerStateMap { private static final Logger LOG = LoggerFactory.getLogger(ContainerStateMap.class); - private static final NavigableSet EMPTY_SET = - Collections.unmodifiableNavigableSet(new TreeSet<>()); - private final ContainerAttribute lifeCycleStateMap; private final ContainerAttribute ownerMap; private final ContainerAttribute repConfigMap; private final ContainerAttribute typeMap; private final Map containerMap; private final Map> replicaMap; - private final Map> resultCache; /** * Create a ContainerStateMap. @@ -96,7 +91,6 @@ public ContainerStateMap() { this.typeMap = new ContainerAttribute<>(); this.containerMap = new ConcurrentHashMap<>(); this.replicaMap = new ConcurrentHashMap<>(); - this.resultCache = new ConcurrentHashMap<>(); } /** @@ -117,9 +111,6 @@ public void addContainer(final ContainerInfo info) typeMap.insert(info.getReplicationType(), id); replicaMap.put(id, Collections.emptySet()); - // Flush the cache of this container type, will be added later when - // get container queries are executed. - flushCache(info); LOG.trace("Container {} added to ContainerStateMap.", id); } } @@ -144,8 +135,6 @@ public void removeContainer(final ContainerID id) { repConfigMap.remove(info.getReplicationConfig(), id); typeMap.remove(info.getReplicationType(), id); replicaMap.remove(id); - // Flush the cache of this container type. - flushCache(info); LOG.trace("Container {} removed from ContainerStateMap.", id); } } @@ -210,20 +199,6 @@ private void replaceReplicaSet(ContainerID containerID, replicaMap.put(containerID, Collections.unmodifiableSet(newSet)); } - /** - * Just update the container State. - * @param info ContainerInfo. - */ - public void updateContainerInfo(final ContainerInfo info) { - Preconditions.checkNotNull(info); - final ContainerID id = info.containerID(); - if (contains(id)) { - final ContainerInfo currentInfo = containerMap.get(id); - flushCache(info, currentInfo); - containerMap.put(id, info); - } - } - /** * Update the State of a container. * @@ -265,9 +240,6 @@ public void updateState(ContainerID containerID, LifeCycleState currentState, LOG.trace("Updated the container {} to new state. Old = {}, new = " + "{}", containerID, currentState, newState); } - - // Just flush both old and new data sets from the result cache. - flushCache(currentInfo); } catch (SCMException ex) { LOG.error("Unable to update the container state.", ex); // we need to revert the change in this attribute since we are not @@ -293,17 +265,6 @@ public Set getAllContainerIDs() { return ImmutableSet.copyOf(containerMap.keySet()); } - /** - * Returns A list of containers owned by a name service. - * - * @param ownerName - Name of the NameService. - * @return - NavigableSet of ContainerIDs. - */ - NavigableSet getContainerIDsByOwner(final String ownerName) { - Preconditions.checkNotNull(ownerName); - return ownerMap.getCollection(ownerName); - } - /** * Returns Containers in the System by the Type. * @@ -315,18 +276,6 @@ public NavigableSet getContainerIDsByType(final ReplicationType typ return typeMap.getCollection(type); } - /** - * Returns Containers by replication factor. - * - * @param repConfig - ReplicationConfig. - * @return NavigableSet. - */ - NavigableSet getContainerIDsByRepConfig( - final ReplicationConfig repConfig) { - Preconditions.checkNotNull(repConfig); - return repConfigMap.getCollection(repConfig); - } - /** * Returns Containers by State. * @@ -338,123 +287,4 @@ public NavigableSet getContainerIDsByState( Preconditions.checkNotNull(state); return lifeCycleStateMap.getCollection(state); } - - /** - * Gets the containers that matches the following filters. - * - * @param state - LifeCycleState - * @param owner - Owner - * @param repConfig - Replication Config - * @return ContainerInfo or Null if not container satisfies the criteria. - */ - public NavigableSet getMatchingContainerIDs( - final LifeCycleState state, final String owner, - final ReplicationConfig repConfig) { - - Preconditions.checkNotNull(state, "State cannot be null"); - Preconditions.checkNotNull(owner, "Owner cannot be null"); - Preconditions.checkNotNull(repConfig, "RepConfig cannot be null"); - - final ContainerQueryKey queryKey = - new ContainerQueryKey(state, owner, repConfig); - if (resultCache.containsKey(queryKey)) { - return resultCache.get(queryKey); - } - - // If we cannot meet any one condition we return EMPTY_SET immediately. - // Since when we intersect these sets, the result will be empty if any - // one is empty. - final NavigableSet stateSet = - lifeCycleStateMap.getCollection(state); - if (stateSet.isEmpty()) { - return EMPTY_SET; - } - - final NavigableSet ownerSet = - ownerMap.getCollection(owner); - if (ownerSet.isEmpty()) { - return EMPTY_SET; - } - - final NavigableSet factorSet = - repConfigMap.getCollection(repConfig); - if (factorSet.isEmpty()) { - return EMPTY_SET; - } - - final NavigableSet typeSet = - typeMap.getCollection(repConfig.getReplicationType()); - if (typeSet.isEmpty()) { - return EMPTY_SET; - } - - - // if we add more constraints we will just add those sets here.. - final NavigableSet[] sets = sortBySize(stateSet, - ownerSet, factorSet, typeSet); - - NavigableSet currentSet = sets[0]; - // We take the smallest set and intersect against the larger sets. This - // allows us to reduce the lookups to the least possible number. - for (int x = 1; x < sets.length; x++) { - currentSet = intersectSets(currentSet, sets[x]); - } - resultCache.put(queryKey, currentSet); - return currentSet; - } - - /** - * Calculates the intersection between sets and returns a new set. - * - * @param smaller - First Set - * @param bigger - Second Set - * @return resultSet which is the intersection of these two sets. - */ - private NavigableSet intersectSets( - final NavigableSet smaller, - final NavigableSet bigger) { - Preconditions.checkState(smaller.size() <= bigger.size(), - "This function assumes the first set is lesser or equal to second " + - "set"); - final NavigableSet resultSet = new TreeSet<>(); - for (ContainerID id : smaller) { - if (bigger.contains(id)) { - resultSet.add(id); - } - } - return resultSet; - } - - /** - * Sorts a list of Sets based on Size. This is useful when we are - * intersecting the sets. - * - * @param sets - varargs of sets - * @return Returns a sorted array of sets based on the size of the set. - */ - @SafeVarargs - private final NavigableSet[] sortBySize( - final NavigableSet... sets) { - for (int x = 0; x < sets.length - 1; x++) { - for (int y = 0; y < sets.length - x - 1; y++) { - if (sets[y].size() > sets[y + 1].size()) { - final NavigableSet temp = sets[y]; - sets[y] = sets[y + 1]; - sets[y + 1] = temp; - } - } - } - return sets; - } - - private void flushCache(final ContainerInfo... containerInfos) { - for (ContainerInfo containerInfo : containerInfos) { - final ContainerQueryKey key = new ContainerQueryKey( - containerInfo.getState(), - containerInfo.getOwner(), - containerInfo.getReplicationConfig()); - resultCache.remove(key); - } - } - }