diff options
author | Nanda kumar <nanda@apache.org> | 2018-03-06 08:41:33 +0530 |
---|---|---|
committer | Owen O'Malley <omalley@apache.org> | 2018-04-26 05:36:04 -0700 |
commit | 9a914126a71b5b4b79fa299c63857814720ec931 (patch) | |
tree | 1a896ef73147afdd7ccdad3ba65e5d65a6426ead /hadoop-hdfs-project/hadoop-hdfs/src/main | |
parent | bf206f014a3e6335f24c718c520e2bf2a91cb4f4 (diff) |
HDFS-13008. Ozone: Add DN container open/close state to container report. Contributed by Xiaoyu Yao.
Diffstat (limited to 'hadoop-hdfs-project/hadoop-hdfs/src/main')
4 files changed, 42 insertions, 22 deletions
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerData.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerData.java index 58853edc62..d0886e11a9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerData.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerData.java @@ -45,24 +45,26 @@ public class ContainerData { private String dbPath; // Path to Level DB Store. // Path to Physical file system where container and checksum are stored. private String containerFilePath; - private boolean open; private String hash; private AtomicLong bytesUsed; private long maxSize; + private Long containerID; + private OzoneProtos.LifeCycleState state; /** * Constructs a ContainerData Object. * * @param containerName - Name */ - public ContainerData(String containerName, Configuration conf) { + public ContainerData(String containerName, Long containerID, + Configuration conf) { this.metadata = new TreeMap<>(); this.containerName = containerName; - this.open = true; this.maxSize = conf.getLong(ScmConfigKeys.SCM_CONTAINER_CLIENT_MAX_SIZE_KEY, ScmConfigKeys.SCM_CONTAINER_CLIENT_MAX_SIZE_DEFAULT) * OzoneConsts.GB; this.bytesUsed = new AtomicLong(0L); - + this.containerID = containerID; + this.state = OzoneProtos.LifeCycleState.OPEN; } /** @@ -74,7 +76,8 @@ public class ContainerData { public static ContainerData getFromProtBuf( ContainerProtos.ContainerData protoData, Configuration conf) throws IOException { - ContainerData data = new ContainerData(protoData.getName(), conf); + ContainerData data = new ContainerData(protoData.getName(), + protoData.getContainerID(), conf); for (int x = 0; x < protoData.getMetadataCount(); x++) { data.addMetadata(protoData.getMetadata(x).getKey(), protoData.getMetadata(x).getValue()); @@ -88,10 +91,8 @@ public class ContainerData { data.setDBPath(protoData.getDbPath()); } - if (protoData.hasOpen()) { - data.setOpen(protoData.getOpen()); - } else { - data.setOpen(true); + if (protoData.hasState()) { + data.setState(protoData.getState()); } if(protoData.hasHash()) { @@ -117,6 +118,7 @@ public class ContainerData { ContainerProtos.ContainerData.Builder builder = ContainerProtos .ContainerData.newBuilder(); builder.setName(this.getContainerName()); + builder.setContainerID(this.getContainerID()); if (this.getDBPath() != null) { builder.setDbPath(this.getDBPath()); @@ -130,7 +132,7 @@ public class ContainerData { builder.setContainerPath(this.getContainerPath()); } - builder.setOpen(this.isOpen()); + builder.setState(this.getState()); for (Map.Entry<String, String> entry : metadata.entrySet()) { OzoneProtos.KeyValue.Builder keyValBuilder = @@ -143,6 +145,10 @@ public class ContainerData { builder.setBytesUsed(this.getBytesUsed()); } + if (this.getKeyCount() >= 0) { + builder.setKeyCount(this.getKeyCount()); + } + if (this.getMaxSize() >= 0) { builder.setSize(this.getMaxSize()); } @@ -246,18 +252,35 @@ public class ContainerData { } /** + * Get container ID. + * @return - container ID. + */ + public synchronized Long getContainerID() { + return containerID; + } + + public synchronized void setState(OzoneProtos.LifeCycleState state) { + this.state = state; + } + + public synchronized OzoneProtos.LifeCycleState getState() { + return this.state; + } + + /** * checks if the container is open. * @return - boolean */ public synchronized boolean isOpen() { - return open; + return OzoneProtos.LifeCycleState.OPEN == state; } /** * Marks this container as closed. */ public synchronized void closeContainer() { - setOpen(false); + // TODO: closed or closing here + setState(OzoneProtos.LifeCycleState.CLOSED); // Some thing brain dead for now. name + Time stamp of when we get the close // container message. @@ -277,14 +300,6 @@ public class ContainerData { this.hash = hash; } - /** - * Sets the open or closed values. - * @param open - */ - public synchronized void setOpen(boolean open) { - this.open = open; - } - public void setMaxSize(long maxSize) { this.maxSize = maxSize; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java index 4245fe09ff..3eb6dc1e39 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java @@ -618,7 +618,8 @@ public class StorageContainerManager extends ServiceRuntimeInfoImpl } @VisibleForTesting - ContainerInfo getContainerInfo(String containerName) throws IOException { + public ContainerInfo getContainerInfo(String containerName) + throws IOException { return scmContainerManager.getContainer(containerName); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/container/InfoContainerHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/container/InfoContainerHandler.java index fc9ef0c372..f54a2b86cd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/container/InfoContainerHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/cli/container/InfoContainerHandler.java @@ -25,6 +25,7 @@ import org.apache.commons.cli.Options; import org.apache.hadoop.hdfs.ozone.protocol.proto.ContainerProtos.ContainerData; import org.apache.hadoop.hdfs.protocol.DatanodeID; +import org.apache.hadoop.ozone.protocol.proto.OzoneProtos; import org.apache.hadoop.ozone.scm.cli.OzoneCommandHandler; import org.apache.hadoop.scm.client.ScmClient; import org.apache.hadoop.scm.container.common.helpers.Pipeline; @@ -75,7 +76,9 @@ public class InfoContainerHandler extends OzoneCommandHandler { // Print container report info. logOut("Container Name: %s", containerData.getName()); - String openStatus = containerData.getOpen() ? "OPEN" : "CLOSED"; + String openStatus = + containerData.getState() == OzoneProtos.LifeCycleState.OPEN ? "OPEN" : + "CLOSED"; logOut("Container State: %s", openStatus); if (!containerData.getHash().isEmpty()) { logOut("Container Hash: %s", containerData.getHash()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/StorageContainerDatanodeProtocol.proto b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/StorageContainerDatanodeProtocol.proto index 6f2717cb33..7306b81b37 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/StorageContainerDatanodeProtocol.proto +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/StorageContainerDatanodeProtocol.proto @@ -104,6 +104,7 @@ message ContainerInfo { optional int64 readBytes = 8; optional int64 writeBytes = 9; required int64 containerID = 10; + optional hadoop.hdfs.ozone.LifeCycleState state = 11; } // The deleted blocks which are stored in deletedBlock.db of scm. |