|
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Properties;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* HddsVolume represents volume in a datanode. {@link VolumeSet} maitains a
|
|
@@ -84,6 +85,7 @@ public final class HddsVolume {
|
|
|
|
|
|
private String datanodeUuid;
|
|
|
private String clusterID;
|
|
|
+ private boolean failedVolume = false;
|
|
|
|
|
|
public Builder(String rootDirStr) {
|
|
|
this.volumeRootStr = rootDirStr;
|
|
@@ -114,29 +116,47 @@ public final class HddsVolume {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ // This is added just to create failed volume objects, which will be used
|
|
|
+ // to create failed HddsVolume objects in the case of any exceptions caused
|
|
|
+ // during creating HddsVolume object.
|
|
|
+ public Builder failedVolume(boolean failed) {
|
|
|
+ this.failedVolume = failed;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public HddsVolume build() throws IOException {
|
|
|
return new HddsVolume(this);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private HddsVolume(Builder b) throws IOException {
|
|
|
- StorageLocation location = StorageLocation.parse(b.volumeRootStr);
|
|
|
- hddsRootDir = new File(location.getUri().getPath(), HDDS_VOLUME_DIR);
|
|
|
- this.state = VolumeState.NOT_INITIALIZED;
|
|
|
- this.clusterID = b.clusterID;
|
|
|
- this.datanodeUuid = b.datanodeUuid;
|
|
|
- this.volumeIOStats = new VolumeIOStats();
|
|
|
-
|
|
|
- VolumeInfo.Builder volumeBuilder =
|
|
|
- new VolumeInfo.Builder(b.volumeRootStr, b.conf)
|
|
|
- .storageType(b.storageType)
|
|
|
- .configuredCapacity(b.configuredCapacity);
|
|
|
- this.volumeInfo = volumeBuilder.build();
|
|
|
-
|
|
|
- LOG.info("Creating Volume: " + this.hddsRootDir + " of storage type : " +
|
|
|
- b.storageType + " and capacity : " + volumeInfo.getCapacity());
|
|
|
-
|
|
|
- initialize();
|
|
|
+ if (!b.failedVolume) {
|
|
|
+ StorageLocation location = StorageLocation.parse(b.volumeRootStr);
|
|
|
+ hddsRootDir = new File(location.getUri().getPath(), HDDS_VOLUME_DIR);
|
|
|
+ this.state = VolumeState.NOT_INITIALIZED;
|
|
|
+ this.clusterID = b.clusterID;
|
|
|
+ this.datanodeUuid = b.datanodeUuid;
|
|
|
+ this.volumeIOStats = new VolumeIOStats();
|
|
|
+
|
|
|
+ VolumeInfo.Builder volumeBuilder =
|
|
|
+ new VolumeInfo.Builder(b.volumeRootStr, b.conf)
|
|
|
+ .storageType(b.storageType)
|
|
|
+ .configuredCapacity(b.configuredCapacity);
|
|
|
+ this.volumeInfo = volumeBuilder.build();
|
|
|
+
|
|
|
+ LOG.info("Creating Volume: " + this.hddsRootDir + " of storage type : " +
|
|
|
+ b.storageType + " and capacity : " + volumeInfo.getCapacity());
|
|
|
+
|
|
|
+ initialize();
|
|
|
+ } else {
|
|
|
+ // Builder is called with failedVolume set, so create a failed volume
|
|
|
+ // HddsVolumeObject.
|
|
|
+ hddsRootDir = new File(b.volumeRootStr);
|
|
|
+ volumeIOStats = null;
|
|
|
+ volumeInfo = null;
|
|
|
+ storageID = UUID.randomUUID().toString();
|
|
|
+ state = VolumeState.FAILED;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public VolumeInfo getVolumeInfo() {
|
|
@@ -285,7 +305,10 @@ public final class HddsVolume {
|
|
|
}
|
|
|
|
|
|
public StorageType getStorageType() {
|
|
|
- return volumeInfo.getStorageType();
|
|
|
+ if(volumeInfo != null) {
|
|
|
+ return volumeInfo.getStorageType();
|
|
|
+ }
|
|
|
+ return StorageType.DEFAULT;
|
|
|
}
|
|
|
|
|
|
public String getStorageID() {
|
|
@@ -313,11 +336,17 @@ public final class HddsVolume {
|
|
|
}
|
|
|
|
|
|
public long getCapacity() throws IOException {
|
|
|
- return volumeInfo.getCapacity();
|
|
|
+ if(volumeInfo != null) {
|
|
|
+ return volumeInfo.getCapacity();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
public long getAvailable() throws IOException {
|
|
|
- return volumeInfo.getAvailable();
|
|
|
+ if(volumeInfo != null) {
|
|
|
+ return volumeInfo.getAvailable();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
public void setState(VolumeState state) {
|
|
@@ -334,12 +363,16 @@ public final class HddsVolume {
|
|
|
|
|
|
public void failVolume() {
|
|
|
setState(VolumeState.FAILED);
|
|
|
- volumeInfo.shutdownUsageThread();
|
|
|
+ if (volumeInfo != null) {
|
|
|
+ volumeInfo.shutdownUsageThread();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void shutdown() {
|
|
|
this.state = VolumeState.NON_EXISTENT;
|
|
|
- volumeInfo.shutdownUsageThread();
|
|
|
+ if (volumeInfo != null) {
|
|
|
+ volumeInfo.shutdownUsageThread();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -368,6 +401,8 @@ public final class HddsVolume {
|
|
|
*/
|
|
|
@VisibleForTesting
|
|
|
public void setScmUsageForTesting(GetSpaceUsed scmUsageForTest) {
|
|
|
- volumeInfo.setScmUsageForTesting(scmUsageForTest);
|
|
|
+ if (volumeInfo != null) {
|
|
|
+ volumeInfo.setScmUsageForTesting(scmUsageForTest);
|
|
|
+ }
|
|
|
}
|
|
|
}
|