|
@@ -23,6 +23,7 @@ import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto;
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto;
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
|
|
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
|
|
+import org.apache.hadoop.hdds.scm.container.metrics.SCMContainerManagerMetrics;
|
|
import org.apache.hadoop.hdds.scm.exceptions.SCMException;
|
|
import org.apache.hadoop.hdds.scm.exceptions.SCMException;
|
|
import org.apache.hadoop.hdds.scm.node.NodeManager;
|
|
import org.apache.hadoop.hdds.scm.node.NodeManager;
|
|
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
|
|
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
|
|
@@ -72,6 +73,8 @@ public class SCMContainerManager implements ContainerManager {
|
|
private final ContainerStateManager containerStateManager;
|
|
private final ContainerStateManager containerStateManager;
|
|
private final int numContainerPerOwnerInPipeline;
|
|
private final int numContainerPerOwnerInPipeline;
|
|
|
|
|
|
|
|
+ private final SCMContainerManagerMetrics scmContainerManagerMetrics;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Constructs a mapping class that creates mapping between container names
|
|
* Constructs a mapping class that creates mapping between container names
|
|
* and pipelines.
|
|
* and pipelines.
|
|
@@ -109,6 +112,8 @@ public class SCMContainerManager implements ContainerManager {
|
|
ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT_DEFAULT);
|
|
ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT_DEFAULT);
|
|
|
|
|
|
loadExistingContainers();
|
|
loadExistingContainers();
|
|
|
|
+
|
|
|
|
+ scmContainerManagerMetrics = SCMContainerManagerMetrics.create();
|
|
}
|
|
}
|
|
|
|
|
|
private void loadExistingContainers() throws IOException {
|
|
private void loadExistingContainers() throws IOException {
|
|
@@ -204,6 +209,7 @@ public class SCMContainerManager implements ContainerManager {
|
|
int count) {
|
|
int count) {
|
|
lock.lock();
|
|
lock.lock();
|
|
try {
|
|
try {
|
|
|
|
+ scmContainerManagerMetrics.incNumListContainersOps();
|
|
final long startId = startContainerID == null ?
|
|
final long startId = startContainerID == null ?
|
|
0 : startContainerID.getId();
|
|
0 : startContainerID.getId();
|
|
final List<ContainerID> containersIds =
|
|
final List<ContainerID> containersIds =
|
|
@@ -241,11 +247,17 @@ public class SCMContainerManager implements ContainerManager {
|
|
public ContainerInfo allocateContainer(final ReplicationType type,
|
|
public ContainerInfo allocateContainer(final ReplicationType type,
|
|
final ReplicationFactor replicationFactor, final String owner)
|
|
final ReplicationFactor replicationFactor, final String owner)
|
|
throws IOException {
|
|
throws IOException {
|
|
- lock.lock();
|
|
|
|
try {
|
|
try {
|
|
- final ContainerInfo containerInfo =
|
|
|
|
- containerStateManager.allocateContainer(pipelineManager, type,
|
|
|
|
|
|
+ lock.lock();
|
|
|
|
+ ContainerInfo containerInfo = null;
|
|
|
|
+ try {
|
|
|
|
+ containerInfo =
|
|
|
|
+ containerStateManager.allocateContainer(pipelineManager, type,
|
|
replicationFactor, owner);
|
|
replicationFactor, owner);
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ scmContainerManagerMetrics.incNumFailureCreateContainers();
|
|
|
|
+ throw ex;
|
|
|
|
+ }
|
|
// Add container to DB.
|
|
// Add container to DB.
|
|
try {
|
|
try {
|
|
addContainerToDB(containerInfo);
|
|
addContainerToDB(containerInfo);
|
|
@@ -286,7 +298,9 @@ public class SCMContainerManager implements ContainerManager {
|
|
LOG.warn("Unable to remove the container {} from container store," +
|
|
LOG.warn("Unable to remove the container {} from container store," +
|
|
" it's missing!", containerID);
|
|
" it's missing!", containerID);
|
|
}
|
|
}
|
|
|
|
+ scmContainerManagerMetrics.incNumSuccessfulDeleteContainers();
|
|
} catch (ContainerNotFoundException cnfe) {
|
|
} catch (ContainerNotFoundException cnfe) {
|
|
|
|
+ scmContainerManagerMetrics.incNumFailureDeleteContainers();
|
|
throw new SCMException(
|
|
throw new SCMException(
|
|
"Failed to delete container " + containerID + ", reason : " +
|
|
"Failed to delete container " + containerID + ", reason : " +
|
|
"container doesn't exist.",
|
|
"container doesn't exist.",
|
|
@@ -447,9 +461,16 @@ public class SCMContainerManager implements ContainerManager {
|
|
containerInfo.getContainerID());
|
|
containerInfo.getContainerID());
|
|
containerStore.put(containerIDBytes,
|
|
containerStore.put(containerIDBytes,
|
|
containerInfo.getProtobuf().toByteArray());
|
|
containerInfo.getProtobuf().toByteArray());
|
|
|
|
+ // Incrementing here, as allocateBlock to create a container calls
|
|
|
|
+ // getMatchingContainer() and finally calls this API to add newly
|
|
|
|
+ // created container to DB.
|
|
|
|
+ // Even allocateContainer calls this API to add newly allocated
|
|
|
|
+ // container to DB. So we need to increment metrics here.
|
|
|
|
+ scmContainerManagerMetrics.incNumSuccessfulCreateContainers();
|
|
} catch (IOException ex) {
|
|
} catch (IOException ex) {
|
|
// If adding to containerStore fails, we should remove the container
|
|
// If adding to containerStore fails, we should remove the container
|
|
// from in-memory map.
|
|
// from in-memory map.
|
|
|
|
+ scmContainerManagerMetrics.incNumFailureCreateContainers();
|
|
LOG.error("Add Container to DB failed for ContainerID #{}",
|
|
LOG.error("Add Container to DB failed for ContainerID #{}",
|
|
containerInfo.getContainerID());
|
|
containerInfo.getContainerID());
|
|
try {
|
|
try {
|
|
@@ -546,5 +567,9 @@ public class SCMContainerManager implements ContainerManager {
|
|
if (containerStore != null) {
|
|
if (containerStore != null) {
|
|
containerStore.close();
|
|
containerStore.close();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (scmContainerManagerMetrics != null) {
|
|
|
|
+ this.scmContainerManagerMetrics.unRegister();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|