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 @@ -619,13 +619,9 @@ private boolean isVolumeFull(Container container) {
if (isOpen) {
HddsVolume volume = container.getContainerData().getVolume();
SpaceUsageSource usage = volume.getCurrentUsage();
long volumeCapacity = usage.getCapacity();
long volumeFreeSpaceToSpare =
freeSpaceCalculator.get(volumeCapacity);
long volumeFree = usage.getAvailable();
long volumeCommitted = volume.getCommittedBytes();
long volumeAvailable = volumeFree - volumeCommitted;
return (volumeAvailable <= volumeFreeSpaceToSpare);
long volumeFreeSpaceToSpare = freeSpaceCalculator.get(usage.getCapacity());
return !VolumeUsage.hasVolumeEnoughSpace(usage.getAvailable(), volume.getCommittedBytes(), 0,
volumeFreeSpaceToSpare);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public static boolean hasVolumeEnoughSpace(long volumeAvailableSpace,
long volumeCommittedBytesCount,
long requiredSpace,
long volumeFreeSpaceToSpare) {
return (volumeAvailableSpace - volumeCommittedBytesCount) >
Math.max(requiredSpace, volumeFreeSpaceToSpare);
Copy link
Contributor

Choose a reason for hiding this comment

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

@peterxcli , thanks for working on this. I would prefer following statement which is more straight forward.

return (volumeAvailableSpace - volumeCommittedBytesCount - volumeFreeSpaceToSpare) > requiredSpace;

Besides, could you help to refactor the HddsDispatcher#isVolumeFull in this patch too, make isVolumeFull call hasVolumeEnoughSpace, so that we will have single central place to control how the disk full is detected.

return (volumeAvailableSpace - volumeCommittedBytesCount - volumeFreeSpaceToSpare) > requiredSpace;
}

private static long getReserved(ConfigurationSource conf, String rootDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ public void testContainerCloseActionWhenVolumeFull(
HddsVolume.Builder volumeBuilder =
new HddsVolume.Builder(testDirPath).datanodeUuid(dd.getUuidString())
.conf(conf).usageCheckFactory(MockSpaceUsageCheckFactory.NONE);
// state of cluster : available (140) > 100 ,datanode volume
// state of cluster : available (160) > 100 ,datanode volume
// utilisation threshold not yet reached. container creates are successful.
AtomicLong usedSpace = new AtomicLong(360);
AtomicLong usedSpace = new AtomicLong(340);
SpaceUsageSource spaceUsage = MockSpaceUsageSource.of(500, usedSpace);

SpaceUsageCheckFactory factory = MockSpaceUsageCheckFactory.of(
Expand All @@ -268,6 +268,7 @@ public void testContainerCloseActionWhenVolumeFull(
ContainerSet containerSet = newContainerSet();
StateContext context = ContainerTestUtils.getMockContext(dd, conf);
// create a 50 byte container
// available (160) > 100 (min free space) + 50 (container size)
KeyValueContainerData containerData = new KeyValueContainerData(1L,
layoutVersion,
50, UUID.randomUUID().toString(),
Expand Down