Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected DbVolume(Builder b) throws IOException {
super(b);

this.hddsDbStorePathMap = new HashMap<>();
if (!b.getFailedVolume() && getVolumeInfo().isPresent()) {
if (!b.getFailedVolume()) {
LOG.info("Creating DbVolume: {} of storage type: {}, {}",
getStorageDir(), b.getStorageType(),
getCurrentUsage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/**
* HddsVolume represents volume in a datanode. {@link MutableVolumeSet}
* maintains a list of HddsVolumes, one for each volume in the Datanode.
* {@link VolumeInfo} in encompassed by this class.
* {@link VolumeUsage} in encompassed by this class.
* <p>
* The disk layout per volume is as follows:
* <p>../hdds/VERSION
Expand Down Expand Up @@ -119,7 +119,7 @@ public HddsVolume build() throws IOException {
private HddsVolume(Builder b) throws IOException {
super(b);

if (!b.getFailedVolume() && getVolumeInfo().isPresent()) {
if (!b.getFailedVolume()) {
this.setState(VolumeState.NOT_INITIALIZED);
ConfigurationSource conf = getConf();
int[] intervals = conf.getInts(OZONE_DATANODE_IO_METRICS_PERCENTILES_INTERVALS_SECONDS_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void checkVolumeAsync(StorageVolume volume) {
}

public void refreshAllVolumeUsage() {
volumeMap.forEach((k, v) -> v.refreshVolumeInfo());
volumeMap.forEach((k, v) -> v.refreshVolumeUsage());
}

/**
Expand Down Expand Up @@ -464,18 +464,17 @@ public StorageLocationReport[] getStorageReport() {
StorageVolume volume;
for (Map.Entry<String, StorageVolume> entry : volumeMap.entrySet()) {
volume = entry.getValue();
Optional<VolumeInfo> volumeInfo = volume.getVolumeInfo();
Optional<VolumeUsage> volumeUsage = volume.getVolumeUsage();
long scmUsed = 0;
long remaining = 0;
long capacity = 0;
long committed = 0;
long spare = 0;
String rootDir = "";
String rootDir = volume.getVolumeRootDir();
failed = true;
if (volumeInfo.isPresent()) {
if (volumeUsage.isPresent()) {
try {
rootDir = volumeInfo.get().getRootDir();
SpaceUsageSource usage = volumeInfo.get().getCurrentUsage();
SpaceUsageSource usage = volumeUsage.get().getCurrentUsage();
scmUsed = usage.getUsedSpace();
remaining = usage.getAvailable();
capacity = usage.getCapacity();
Expand All @@ -485,7 +484,7 @@ public StorageLocationReport[] getStorageReport() {
failed = false;
} catch (UncheckedIOException ex) {
LOG.warn("Failed to get scmUsed and remaining for container " +
"storage location {}", volumeInfo.get().getRootDir(), ex);
"storage location {}", rootDir, ex);
// reset scmUsed and remaining if df/du failed.
scmUsed = 0;
remaining = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.fs.SpaceUsageCheckFactory;
import org.apache.hadoop.hdds.fs.SpaceUsageCheckParams;
import org.apache.hadoop.hdds.fs.SpaceUsageSource;
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
import org.apache.hadoop.hdfs.server.datanode.checker.Checkable;
Expand Down Expand Up @@ -118,12 +119,14 @@ public enum VolumeState {
private final ConfigurationSource conf;
private final DatanodeConfiguration dnConf;

private final StorageType storageType;
private final String volumeRoot;
private final File storageDir;
private String workingDirName;
private File tmpDir;
private File diskCheckDir;

private final Optional<VolumeInfo> volumeInfo;
private final Optional<VolumeUsage> volumeUsage;

private final VolumeSet volumeSet;

Expand All @@ -139,14 +142,13 @@ public enum VolumeState {
private int healthCheckFileSize;

protected StorageVolume(Builder<?> b) throws IOException {
storageType = b.storageType;
volumeRoot = b.volumeRootStr;
if (!b.failedVolume) {
StorageLocation location = StorageLocation.parse(b.volumeRootStr);
StorageLocation location = StorageLocation.parse(volumeRoot);
storageDir = new File(location.getUri().getPath(), b.storageDirStr);
this.volumeInfo = Optional.of(
new VolumeInfo.Builder(b.volumeRootStr, b.conf)
.storageType(b.storageType)
.usageCheckFactory(b.usageCheckFactory)
.build());
SpaceUsageCheckParams checkParams = getSpaceUsageCheckParams(b);
volumeUsage = Optional.of(new VolumeUsage(checkParams, b.conf));
this.volumeSet = b.volumeSet;
this.state = VolumeState.NOT_INITIALIZED;
this.clusterID = b.clusterID;
Expand All @@ -161,7 +163,7 @@ protected StorageVolume(Builder<?> b) throws IOException {
this.healthCheckFileSize = dnConf.getVolumeHealthCheckFileSize();
} else {
storageDir = new File(b.volumeRootStr);
this.volumeInfo = Optional.empty();
volumeUsage = Optional.empty();
this.volumeSet = null;
this.storageID = UUID.randomUUID().toString();
this.state = VolumeState.FAILED;
Expand Down Expand Up @@ -375,7 +377,7 @@ public abstract static class Builder<T extends Builder<T>> {
private final String volumeRootStr;
private String storageDirStr;
private ConfigurationSource conf;
private StorageType storageType;
private StorageType storageType = StorageType.DEFAULT;
private SpaceUsageCheckFactory usageCheckFactory;
private VolumeSet volumeSet;
private boolean failedVolume = false;
Expand All @@ -395,7 +397,7 @@ public T conf(ConfigurationSource config) {
}

public T storageType(StorageType st) {
this.storageType = st;
this.storageType = Objects.requireNonNull(st, "storageType == null");
return this.getThis();
}

Expand Down Expand Up @@ -443,11 +445,12 @@ public StorageType getStorageType() {
}

public String getVolumeRootDir() {
return volumeInfo.map(VolumeInfo::getRootDir).orElse(null);
return volumeRoot;
}

/** Get current usage of the volume. */
public SpaceUsageSource getCurrentUsage() {
return volumeInfo.map(VolumeInfo::getCurrentUsage)
return volumeUsage.map(VolumeUsage::getCurrentUsage)
.orElse(SpaceUsageSource.UNKNOWN);
}

Expand All @@ -468,21 +471,22 @@ public File getDiskCheckDir() {
return this.diskCheckDir;
}

public void refreshVolumeInfo() {
volumeInfo.ifPresent(VolumeInfo::refreshNow);
public void refreshVolumeUsage() {
volumeUsage.ifPresent(VolumeUsage::refreshNow);
}

public Optional<VolumeInfo> getVolumeInfo() {
return this.volumeInfo;
/** @see #getCurrentUsage() */
public Optional<VolumeUsage> getVolumeUsage() {
return volumeUsage;
}

public void incrementUsedSpace(long usedSpace) {
volumeInfo.ifPresent(volInfo -> volInfo
volumeUsage.ifPresent(usage -> usage
.incrementUsedSpace(usedSpace));
}

public void decrementUsedSpace(long reclaimedSpace) {
volumeInfo.ifPresent(volInfo -> volInfo
volumeUsage.ifPresent(usage -> usage
.decrementUsedSpace(reclaimedSpace));
}

Expand All @@ -491,8 +495,7 @@ public VolumeSet getVolumeSet() {
}

public StorageType getStorageType() {
return volumeInfo.map(VolumeInfo::getStorageType)
.orElse(StorageType.DEFAULT);
return storageType;
}

public String getStorageID() {
Expand Down Expand Up @@ -537,12 +540,12 @@ public DatanodeConfiguration getDatanodeConfig() {

public void failVolume() {
setState(VolumeState.FAILED);
volumeInfo.ifPresent(VolumeInfo::shutdownUsageThread);
volumeUsage.ifPresent(VolumeUsage::shutdown);
}

public void shutdown() {
setState(VolumeState.NON_EXISTENT);
volumeInfo.ifPresent(VolumeInfo::shutdownUsageThread);
volumeUsage.ifPresent(VolumeUsage::shutdown);
cleanTmpDiskCheckDir();
}

Expand Down Expand Up @@ -679,4 +682,22 @@ public boolean equals(Object other) {
public String toString() {
return getStorageDir().toString();
}

private static SpaceUsageCheckParams getSpaceUsageCheckParams(Builder b) throws IOException {
File root = new File(b.volumeRootStr);

boolean succeeded = root.isDirectory() || root.mkdirs();

if (!succeeded) {
LOG.error("Unable to create the volume root dir at : {}", root);
throw new IOException("Unable to create the volume root dir at " + root);
}

SpaceUsageCheckFactory usageCheckFactory = b.usageCheckFactory;
if (usageCheckFactory == null) {
usageCheckFactory = SpaceUsageCheckFactory.create(b.conf);
}

return usageCheckFactory.paramsFor(root);
}
}
Loading