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 @@ -28,7 +28,7 @@
@InterfaceAudience.Private
@InterfaceStability.Evolving
public interface SpaceUsageSource {
SpaceUsageSource UNKNOWN = new Fixed(0, 0, 0);
Fixed UNKNOWN = new Fixed(0, 0, 0);

/**
* @return space usage in bytes
Expand All @@ -41,7 +41,7 @@ public interface SpaceUsageSource {

long getAvailable();

default SpaceUsageSource snapshot() {
default Fixed snapshot() {
return new Fixed(getCapacity(), getAvailable(), getUsedSpace());
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public long getUsedSpace() {
}

@Override
public SpaceUsageSource snapshot() {
public Fixed snapshot() {
return this; // immutable
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MutableVolumeSet implements VolumeSet {
* Maintains a map of all active volumes in the DataNode.
* Each volume has one-to-one mapping with a volumeInfo object.
*/
private Map<String, StorageVolume> volumeMap;
private final Map<String, StorageVolume> volumeMap = new ConcurrentHashMap<>();
/**
* Maintains a map of volumes which have failed. The keys in this map and
* {@link #volumeMap} are mutually exclusive.
Expand Down Expand Up @@ -147,7 +147,6 @@ public StorageVolumeChecker getVolumeChecker() {
* Add DN volumes configured through ConfigKeys to volumeMap.
*/
private void initializeVolumeSet() throws IOException {
volumeMap = new ConcurrentHashMap<>();
failedVolumeMap = new ConcurrentHashMap<>();
volumeStateMap = new EnumMap<>(StorageType.class);

Expand Down Expand Up @@ -452,8 +451,9 @@ public Map<String, StorageVolume> getVolumeMap() {
}

@VisibleForTesting
public void setVolumeMap(Map<String, StorageVolume> map) {
this.volumeMap = map;
public void setVolumeMapForTesting(Map<String, StorageVolume> map) {
volumeMap.clear();
volumeMap.putAll(map);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public String getVolumeRootDir() {
}

/** Get current usage of the volume. */
public SpaceUsageSource getCurrentUsage() {
public SpaceUsageSource.Fixed getCurrentUsage() {
return volumeUsage != null ? volumeUsage.getCurrentUsage() : SpaceUsageSource.UNKNOWN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class VolumeUsage {
Preconditions.assertTrue(reservedInBytes >= 0, reservedInBytes + " < 0");
}

SpaceUsageSource realUsage() {
SpaceUsageSource.Fixed realUsage() {
return source.snapshot();
}

Expand All @@ -123,9 +123,8 @@ SpaceUsageSource realUsage() {
* </pre>
* B) avail = fsAvail - Max(reserved - other, 0);
*/
public SpaceUsageSource getCurrentUsage() {
SpaceUsageSource real = realUsage();

public SpaceUsageSource.Fixed getCurrentUsage() {
final SpaceUsageSource.Fixed real = realUsage();
return reservedInBytes == 0
? real
: new SpaceUsageSource.Fixed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void testFinalizeFailure(boolean schemaV3Enabled) throws Exception {
createDbStore(any());
Map volumeMap = new HashMap<String, StorageVolume>();
volumeMap.put(dataVolume.getStorageID(), volume);
dsm.getContainer().getVolumeSet().setVolumeMap(volumeMap);
dsm.getContainer().getVolumeSet().setVolumeMapForTesting(volumeMap);

// Finalize will fail because of DB creation failure
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class CachingSpaceUsageSource implements SpaceUsageSource {
private long cachedUsedSpace;
private long cachedAvailable;
private long cachedCapacity;
private SpaceUsageSource cachedUsage;
private Fixed cachedUsage;
private final Duration refresh;
private final SpaceUsageSource source;
private final SpaceUsagePersistence persistence;
Expand Down Expand Up @@ -102,7 +102,7 @@ public long getUsedSpace() {
}

@Override
public SpaceUsageSource snapshot() {
public Fixed snapshot() {
try (AutoCloseableLock ignored = lock.readLock(null, null)) {
if (cachedUsage != null) {
return cachedUsage;
Expand Down