Skip to content

Commit 388084e

Browse files
committed
Merge branch 'am' into HDDS-5713
2 parents df08861 + 6759708 commit 388084e

6 files changed

Lines changed: 14 additions & 15 deletions

File tree

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/fs/SpaceUsageSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@InterfaceAudience.Private
2929
@InterfaceStability.Evolving
3030
public interface SpaceUsageSource {
31-
SpaceUsageSource UNKNOWN = new Fixed(0, 0, 0);
31+
Fixed UNKNOWN = new Fixed(0, 0, 0);
3232

3333
/**
3434
* @return space usage in bytes
@@ -41,7 +41,7 @@ public interface SpaceUsageSource {
4141

4242
long getAvailable();
4343

44-
default SpaceUsageSource snapshot() {
44+
default Fixed snapshot() {
4545
return new Fixed(getCapacity(), getAvailable(), getUsedSpace());
4646
}
4747

@@ -77,7 +77,7 @@ public long getUsedSpace() {
7777
}
7878

7979
@Override
80-
public SpaceUsageSource snapshot() {
80+
public Fixed snapshot() {
8181
return this; // immutable
8282
}
8383

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/MutableVolumeSet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MutableVolumeSet implements VolumeSet {
5757
* Maintains a map of all active volumes in the DataNode.
5858
* Each volume has one-to-one mapping with a volumeInfo object.
5959
*/
60-
private Map<String, StorageVolume> volumeMap;
60+
private final Map<String, StorageVolume> volumeMap = new ConcurrentHashMap<>();
6161
/**
6262
* Maintains a map of volumes which have failed. The keys in this map and
6363
* {@link #volumeMap} are mutually exclusive.
@@ -147,7 +147,6 @@ public StorageVolumeChecker getVolumeChecker() {
147147
* Add DN volumes configured through ConfigKeys to volumeMap.
148148
*/
149149
private void initializeVolumeSet() throws IOException {
150-
volumeMap = new ConcurrentHashMap<>();
151150
failedVolumeMap = new ConcurrentHashMap<>();
152151
volumeStateMap = new EnumMap<>(StorageType.class);
153152

@@ -452,8 +451,9 @@ public Map<String, StorageVolume> getVolumeMap() {
452451
}
453452

454453
@VisibleForTesting
455-
public void setVolumeMap(Map<String, StorageVolume> map) {
456-
this.volumeMap = map;
454+
public void setVolumeMapForTesting(Map<String, StorageVolume> map) {
455+
volumeMap.clear();
456+
volumeMap.putAll(map);
457457
}
458458

459459
@VisibleForTesting

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolume.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public String getVolumeRootDir() {
468468
}
469469

470470
/** Get current usage of the volume. */
471-
public SpaceUsageSource getCurrentUsage() {
471+
public SpaceUsageSource.Fixed getCurrentUsage() {
472472
return volumeUsage != null ? volumeUsage.getCurrentUsage() : SpaceUsageSource.UNKNOWN;
473473
}
474474

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/VolumeUsage.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class VolumeUsage {
107107
Preconditions.assertTrue(reservedInBytes >= 0, reservedInBytes + " < 0");
108108
}
109109

110-
SpaceUsageSource realUsage() {
110+
SpaceUsageSource.Fixed realUsage() {
111111
return source.snapshot();
112112
}
113113

@@ -123,9 +123,8 @@ SpaceUsageSource realUsage() {
123123
* </pre>
124124
* B) avail = fsAvail - Max(reserved - other, 0);
125125
*/
126-
public SpaceUsageSource getCurrentUsage() {
127-
SpaceUsageSource real = realUsage();
128-
126+
public SpaceUsageSource.Fixed getCurrentUsage() {
127+
final SpaceUsageSource.Fixed real = realUsage();
129128
return reservedInBytes == 0
130129
? real
131130
: new SpaceUsageSource.Fixed(

hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/upgrade/TestDatanodeUpgradeToSchemaV3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public void testFinalizeFailure(boolean schemaV3Enabled) throws Exception {
556556
createDbStore(any());
557557
Map volumeMap = new HashMap<String, StorageVolume>();
558558
volumeMap.put(dataVolume.getStorageID(), volume);
559-
dsm.getContainer().getVolumeSet().setVolumeMap(volumeMap);
559+
dsm.getContainer().getVolumeSet().setVolumeMapForTesting(volumeMap);
560560

561561
// Finalize will fail because of DB creation failure
562562
try {

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/fs/CachingSpaceUsageSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class CachingSpaceUsageSource implements SpaceUsageSource {
5050
private long cachedUsedSpace;
5151
private long cachedAvailable;
5252
private long cachedCapacity;
53-
private SpaceUsageSource cachedUsage;
53+
private Fixed cachedUsage;
5454
private final Duration refresh;
5555
private final SpaceUsageSource source;
5656
private final SpaceUsagePersistence persistence;
@@ -102,7 +102,7 @@ public long getUsedSpace() {
102102
}
103103

104104
@Override
105-
public SpaceUsageSource snapshot() {
105+
public Fixed snapshot() {
106106
try (AutoCloseableLock ignored = lock.readLock(null, null)) {
107107
if (cachedUsage != null) {
108108
return cachedUsage;

0 commit comments

Comments
 (0)