Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class HddsVolume extends StorageVolume {

private VolumeState state;
private final VolumeIOStats volumeIOStats;
private final VolumeInfoStats volumeInfoStats;

// VERSION file properties
private String storageID; // id of the file system
Expand All @@ -76,6 +77,8 @@ public class HddsVolume extends StorageVolume {
private int layoutVersion; // layout version of the storage data
private final AtomicLong committedBytes; // till Open containers become full

// Mentions the type of volume
private final VolumeType type = VolumeType.DATA_VOLUME;
/**
* Builder for HddsVolume.
*/
Expand Down Expand Up @@ -115,6 +118,7 @@ private HddsVolume(Builder b) throws IOException {
this.clusterID = b.clusterID;
this.datanodeUuid = b.datanodeUuid;
this.volumeIOStats = new VolumeIOStats(b.getVolumeRootStr());
this.volumeInfoStats = new VolumeInfoStats(b.getVolumeRootStr(), this);
this.committedBytes = new AtomicLong(0);

LOG.info("Creating HddsVolume: {} of storage type : {} capacity : {}",
Expand All @@ -125,6 +129,7 @@ private HddsVolume(Builder b) throws IOException {
// Builder is called with failedVolume set, so create a failed volume
// HddsVolume Object.
volumeIOStats = null;
volumeInfoStats = null;
storageID = UUID.randomUUID().toString();
state = VolumeState.FAILED;
committedBytes = null;
Expand Down Expand Up @@ -300,6 +305,10 @@ public int getLayoutVersion() {
return layoutVersion;
}

public VolumeType getType() {
return type;
}

public VolumeState getStorageState() {
return state;
}
Expand All @@ -316,13 +325,20 @@ public VolumeIOStats getVolumeIOStats() {
return volumeIOStats;
}

public VolumeInfoStats getVolumeInfoStats() {
return volumeInfoStats;
}

@Override
public void failVolume() {
setState(VolumeState.FAILED);
super.failVolume();
if (volumeIOStats != null) {
volumeIOStats.unregister();
}
if (volumeInfoStats != null) {
volumeInfoStats.unregister();
}
}

@Override
Expand All @@ -332,6 +348,9 @@ public void shutdown() {
if (volumeIOStats != null) {
volumeIOStats.unregister();
}
if (volumeInfoStats != null) {
volumeInfoStats.unregister();
}
}

/**
Expand Down Expand Up @@ -371,4 +390,4 @@ public long incCommittedBytes(long delta) {
public long getCommittedBytes() {
return committedBytes.get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
*/
public class MetadataVolume extends StorageVolume {

private final VolumeType type = VolumeType.META_VOLUME;

protected MetadataVolume(Builder b) throws IOException {
super(b);
}

public VolumeType getType() {
return type;
}

/**
* Builder class for MetadataVolume.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* 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.ozone.container.common.volume;

import org.apache.hadoop.metrics2.MetricsSystem;
import org.apache.hadoop.metrics2.annotation.Metric;
import org.apache.hadoop.metrics2.annotation.Metrics;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.ozone.OzoneConsts;

/**
* This class is used to track Volume Info stats for each HDDS Volume.
*/
@Metrics(about = "Ozone Volume Information Metrics",
context = OzoneConsts.OZONE)
public class VolumeInfoStats {
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated

private String metricsSourceName = VolumeInfoStats.class.getSimpleName();
private String volumeRootStr;
private HddsVolume volume;

private long spaceUsed;
private long spaceAvailable;
private long spaceReserved;
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated


/**
* @param identifier Typically, path to volume root. e.g. /data/hdds
*/
public VolumeInfoStats(String identifier, HddsVolume ref) {
this.metricsSourceName +=
'-' + identifier + StorageVolume.VolumeType.DATA_VOLUME.toString();
this.volumeRootStr = identifier;
this.volume = ref;
init();
}

public void init() {
MetricsSystem ms = DefaultMetricsSystem.instance();
ms.register(metricsSourceName, "Volume Info Statistics", this);
}

public void unregister() {
MetricsSystem ms = DefaultMetricsSystem.instance();
ms.unregisterSource(metricsSourceName);
}

@Metric("Metric to return the Storage Type")
public String getStorageType() {
return volume.getStorageType().toString();
}

@Metric("Returns the Directory name for the volume")
public String getStorageDirectory() {
return volume.getStorageDir().toString();
}

@Metric("Return the DataNode UID for the respective volume")
public String getDatanodeUuid() {
return volume.getDatanodeUuid();
}

@Metric("Return the Layout Version for the volume")
public int getLayoutVersion() {
return volume.getLayoutVersion();
}

@Metric("Returns the Volume Type")
public String getVolumeType() {
return volume.getType().name();
}

public String getMetricsSourceName() {
return metricsSourceName;
}

/**
* Test conservative avail space.
* |----used----| (avail) |++++++++reserved++++++++|
* |<------- capacity ------->|
* |<------------------- Total capacity -------------->|
* A) avail = capacity - used
* B) capacity = used + avail
* C) Total capacity = used + avail + reserved
*/

/**
* Return the Storage type for the Volume.
*/
@Metric("Returns the Used space")
public long getUsed() {
spaceUsed = volume.getVolumeInfo().getScmUsed();
return spaceUsed;
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated
}

/**
* Return the Total Available capacity of the Volume.
*/
@Metric("Returns the Available space")
public long getAvailable() {
spaceAvailable = volume.getVolumeInfo().getAvailable();
return spaceAvailable;
}

/**
* Return the Total Reserved of the Volume.
*/
@Metric("Fetches the Reserved Space")
public long getReserved() {
spaceReserved = volume.getVolumeInfo().getReservedInBytes();
return spaceReserved;
}

/**
* Return the Total capacity of the Volume.
*/
@Metric("Returns the Capacity of the Volume")
public long getCapacity() {
return spaceUsed + spaceAvailable;
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated
}

/**
* Return the Total capacity of the Volume.
*/
@Metric("Returns the Total Capacity of the Volume")
public long getTotalCapacity() {
return (spaceUsed + spaceAvailable + spaceReserved);
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated
}

}