Skip to content
Open
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 @@ -22,7 +22,6 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.hadoop.hdds.fs.SpaceUsageSource;
import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
Expand Down Expand Up @@ -167,13 +166,15 @@ public static final class VolumeFixedUsage {
private final HddsVolume volume;
private final SpaceUsageSource.Fixed usage;
private final long effectiveUsed;
private final Double utilization;
private final double utilization;

private VolumeFixedUsage(HddsVolume volume, long delta) {
this.volume = volume;
this.usage = volume.getCurrentUsage();
this.effectiveUsed = computeEffectiveUsage(usage, volume.getCommittedBytes(), delta);
this.utilization = usage.getCapacity() > 0 ? computeUtilization(usage, volume.getCommittedBytes(), delta) : null;
this.utilization = usage.getCapacity() > 0
? computeUtilization(usage, volume.getCommittedBytes(), delta)
: 0.0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no Capacity, should utilization be 100%? Would 0 utilization be treated that volume is a candidate for moving data or creating containers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. 0.0 is only used as a safe value for zero-capacity volumes to avoid reporting them as over-utilized. Such volumes should not become DiskBalancer candidates because DefaultContainerChoosingPolicy filters out volumes with capacity <= 0 before selecting source/destination volumes, and destination selection also requires positive usable space.

}

public HddsVolume getVolume() {
Expand All @@ -189,7 +190,7 @@ public long getEffectiveUsed() {
}

public double getUtilization() {
return Objects.requireNonNull(utilization, "utilization == null");
return utilization;
}

public long computeUsableSpace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ void calculateVolumeDataDensityIgnoresZeroCapacityVolumes()
Arrays.asList(zeroCapacity, lowUsage, highUsage)), 0.0);
}

@Test
void getUtilizationReturnsZeroForZeroCapacityVolume()
throws IOException {
HddsVolume volume = createVolume("zero-capacity-utilization", 0, 0);

assertEquals(0.0, DiskBalancerVolumeCalculation.newVolumeFixedUsage(
volume, null).getUtilization());
}

@Test
void buildVolumeReportProtoReportsZeroUtilizationForZeroCapacityVolume()
throws IOException {
HddsVolume volume = createVolume("zero-capacity-report", 0, 0);

assertEquals(0.0, DiskBalancerService.buildVolumeReportProto(
Collections.singletonList(
DiskBalancerVolumeCalculation.newVolumeFixedUsage(volume, null)))
.get(0).getUtilization());
}

@Test
void getIdealUsageRejectsNegativeCapacity() throws IOException {
HddsVolume negativeCapacityVolume = createVolume(
Expand Down