|
@@ -51,7 +51,7 @@ import static org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes
|
|
* Container State Map acts like a unified map for various attributes that are
|
|
* Container State Map acts like a unified map for various attributes that are
|
|
* used to select containers when we need allocated blocks.
|
|
* used to select containers when we need allocated blocks.
|
|
* <p>
|
|
* <p>
|
|
- * This class provides the ability to query 4 classes of attributes. They are
|
|
|
|
|
|
+ * This class provides the ability to query 5 classes of attributes. They are
|
|
* <p>
|
|
* <p>
|
|
* 1. LifeCycleStates - LifeCycle States of container describe in which state
|
|
* 1. LifeCycleStates - LifeCycle States of container describe in which state
|
|
* a container is. For example, a container needs to be in Open State for a
|
|
* a container is. For example, a container needs to be in Open State for a
|
|
@@ -72,6 +72,9 @@ import static org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes
|
|
* Replica and THREE Replica. User can specify how many copies should be made
|
|
* Replica and THREE Replica. User can specify how many copies should be made
|
|
* for a ozone key.
|
|
* for a ozone key.
|
|
* <p>
|
|
* <p>
|
|
|
|
+ * 5.Pipeline - The pipeline constitute the set of Datanodes on which the
|
|
|
|
+ * open container resides physically.
|
|
|
|
+ * <p>
|
|
* The most common access pattern of this class is to select a container based
|
|
* The most common access pattern of this class is to select a container based
|
|
* on all these parameters, for example, when allocating a block we will
|
|
* on all these parameters, for example, when allocating a block we will
|
|
* select a container that belongs to user1, with Ratis replication which can
|
|
* select a container that belongs to user1, with Ratis replication which can
|
|
@@ -86,6 +89,14 @@ public class ContainerStateMap {
|
|
private final ContainerAttribute<String> ownerMap;
|
|
private final ContainerAttribute<String> ownerMap;
|
|
private final ContainerAttribute<ReplicationFactor> factorMap;
|
|
private final ContainerAttribute<ReplicationFactor> factorMap;
|
|
private final ContainerAttribute<ReplicationType> typeMap;
|
|
private final ContainerAttribute<ReplicationType> typeMap;
|
|
|
|
+ // This map constitutes the pipeline to open container mappings.
|
|
|
|
+ // This map will be queried for the list of open containers on a particular
|
|
|
|
+ // pipeline and issue a close on corresponding containers in case of
|
|
|
|
+ // following events:
|
|
|
|
+ //1. Dead datanode.
|
|
|
|
+ //2. Datanode out of space.
|
|
|
|
+ //3. Volume loss or volume out of space.
|
|
|
|
+ private final ContainerAttribute<String> openPipelineMap;
|
|
|
|
|
|
private final Map<ContainerID, ContainerInfo> containerMap;
|
|
private final Map<ContainerID, ContainerInfo> containerMap;
|
|
// Map to hold replicas of given container.
|
|
// Map to hold replicas of given container.
|
|
@@ -106,6 +117,7 @@ public class ContainerStateMap {
|
|
ownerMap = new ContainerAttribute<>();
|
|
ownerMap = new ContainerAttribute<>();
|
|
factorMap = new ContainerAttribute<>();
|
|
factorMap = new ContainerAttribute<>();
|
|
typeMap = new ContainerAttribute<>();
|
|
typeMap = new ContainerAttribute<>();
|
|
|
|
+ openPipelineMap = new ContainerAttribute<>();
|
|
containerMap = new HashMap<>();
|
|
containerMap = new HashMap<>();
|
|
autoLock = new AutoCloseableLock();
|
|
autoLock = new AutoCloseableLock();
|
|
contReplicaMap = new HashMap<>();
|
|
contReplicaMap = new HashMap<>();
|
|
@@ -140,6 +152,9 @@ public class ContainerStateMap {
|
|
ownerMap.insert(info.getOwner(), id);
|
|
ownerMap.insert(info.getOwner(), id);
|
|
factorMap.insert(info.getReplicationFactor(), id);
|
|
factorMap.insert(info.getReplicationFactor(), id);
|
|
typeMap.insert(info.getReplicationType(), id);
|
|
typeMap.insert(info.getReplicationType(), id);
|
|
|
|
+ if (info.isContainerOpen()) {
|
|
|
|
+ openPipelineMap.insert(info.getPipelineName(), id);
|
|
|
|
+ }
|
|
LOG.trace("Created container with {} successfully.", id);
|
|
LOG.trace("Created container with {} successfully.", id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -329,6 +344,11 @@ public class ContainerStateMap {
|
|
throw new SCMException("Updating the container map failed.", ex,
|
|
throw new SCMException("Updating the container map failed.", ex,
|
|
FAILED_TO_CHANGE_CONTAINER_STATE);
|
|
FAILED_TO_CHANGE_CONTAINER_STATE);
|
|
}
|
|
}
|
|
|
|
+ // In case the container is set to closed state, it needs to be removed from
|
|
|
|
+ // the pipeline Map.
|
|
|
|
+ if (newState == LifeCycleState.CLOSED) {
|
|
|
|
+ openPipelineMap.remove(info.getPipelineName(), id);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -359,6 +379,20 @@ public class ContainerStateMap {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns Open containers in the SCM by the Pipeline
|
|
|
|
+ *
|
|
|
|
+ * @param pipeline - Pipeline name.
|
|
|
|
+ * @return NavigableSet<ContainerID>
|
|
|
|
+ */
|
|
|
|
+ public NavigableSet<ContainerID> getOpenContainerIDsByPipeline(String pipeline) {
|
|
|
|
+ Preconditions.checkNotNull(pipeline);
|
|
|
|
+
|
|
|
|
+ try (AutoCloseableLock lock = autoLock.acquire()) {
|
|
|
|
+ return openPipelineMap.getCollection(pipeline);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns Containers by replication factor.
|
|
* Returns Containers by replication factor.
|
|
*
|
|
*
|