HDFS-1739. Add available volume size to the error message when datanode throws DiskOutOfSpaceException. Contributed by Uma Maheswara Rao G

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1150067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-07-23 08:45:55 +00:00
parent 89537b7710
commit 598b85c9e2
3 changed files with 45 additions and 2 deletions

View File

@ -593,6 +593,9 @@ Trunk (unreleased changes)
HDFS-2112. Move ReplicationMonitor to block management. (Uma Maheswara
Rao G via szetszwo)
HDFS-1739. Add available volume size to the error message when datanode
throws DiskOutOfSpaceException. (Uma Maheswara Rao G via szetszwo)
OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

View File

@ -41,13 +41,24 @@ public synchronized FSVolume chooseVolume(List<FSVolume> volumes, long blockSize
}
int startVolume = curVolume;
long maxAvailable = 0;
while (true) {
FSVolume volume = volumes.get(curVolume);
curVolume = (curVolume + 1) % volumes.size();
if (volume.getAvailable() > blockSize) { return volume; }
long availableVolumeSize = volume.getAvailable();
if (availableVolumeSize > blockSize) { return volume; }
if (availableVolumeSize > maxAvailable) {
maxAvailable = availableVolumeSize;
}
if (curVolume == startVolume) {
throw new DiskOutOfSpaceException("Insufficient space for an additional block");
throw new DiskOutOfSpaceException(
"Insufficient space for an additional block. Volume with the most available space has "
+ maxAvailable
+ " bytes free, configured block size is "
+ blockSize);
}
}
}

View File

@ -24,6 +24,7 @@
import junit.framework.Assert;
import org.apache.hadoop.hdfs.server.datanode.FSDataset.FSVolume;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException;
import org.junit.Test;
import org.mockito.Mockito;
@ -64,4 +65,32 @@ public void testRR() throws Exception {
}
}
// ChooseVolume should throw DiskOutOfSpaceException with volume and block sizes in exception message.
@Test
public void testRRPolicyExceptionMessage()
throws Exception {
final List<FSVolume> volumes = new ArrayList<FSVolume>();
// First volume, with 500 bytes of space.
volumes.add(Mockito.mock(FSVolume.class));
Mockito.when(volumes.get(0).getAvailable()).thenReturn(500L);
// Second volume, with 600 bytes of space.
volumes.add(Mockito.mock(FSVolume.class));
Mockito.when(volumes.get(1).getAvailable()).thenReturn(600L);
RoundRobinVolumesPolicy policy = new RoundRobinVolumesPolicy();
int blockSize = 700;
try {
policy.chooseVolume(volumes, blockSize);
Assert.fail("expected to throw DiskOutOfSpaceException");
} catch (DiskOutOfSpaceException e) {
Assert
.assertEquals(
"Not returnig the expected message",
"Insufficient space for an additional block. Volume with the most available space has 600 bytes free, configured block size is " + blockSize, e
.getMessage());
}
}
}