long getRemaining() throws IOException { long remaining = 0L; for (FsVolumeSpi vol : volumes) { try (FsVolumeReference ref = vol.obtainReference()) { remaining += vol.getAvailable(); } catch (ClosedChannelException e) { // ignore } } return remaining; }
final V volume = volumes.get(curVolume); curVolume = (curVolume + 1) % volumes.size(); long availableVolumeSize = volume.getAvailable(); if (availableVolumeSize > blockSize) { curVolumes[curVolumeIndex] = curVolume;
if (dest.getAvailable() > item.getBytesToCopy()) { long begin = System.nanoTime(); this.dataset.moveBlockAcrossVolumes(block, dest);
long getRemaining() throws IOException { long remaining = 0L; for (FsVolumeSpi vol : volumes.get()) { try (FsVolumeReference ref = vol.obtainReference()) { remaining += vol.getAvailable(); } catch (ClosedChannelException e) { // ignore } } return remaining; }
long getRemaining() throws IOException { long remaining = 0L; for (FsVolumeSpi vol : volumes.get()) { try (FsVolumeReference ref = vol.obtainReference()) { remaining += vol.getAvailable(); } catch (ClosedChannelException e) { // ignore } } return remaining; }
final V volume = volumes.get(curVolume); curVolume = (curVolume + 1) % volumes.size(); long availableVolumeSize = volume.getAvailable(); if (availableVolumeSize > blockSize) { return volume;
final V volume = volumes.get(curVolume); curVolume = (curVolume + 1) % volumes.size(); long availableVolumeSize = volume.getAvailable(); if (availableVolumeSize > blockSize) { return volume;
public static void testRRPolicyExceptionMessage( VolumeChoosingPolicy<FsVolumeSpi> policy) throws Exception { final List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>(); // First volume, with 500 bytes of space. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(0).getAvailable()).thenReturn(500L); // Second volume, with 600 bytes of space. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(1).getAvailable()).thenReturn(600L); int blockSize = 700; try { policy.chooseVolume(volumes, blockSize); Assert.fail("expected to throw DiskOutOfSpaceException"); } catch(DiskOutOfSpaceException e) { Assert.assertEquals("Not returnig the expected message", "Out of space: The volume with the most available space (=" + 600 + " B) is less than the block size (=" + blockSize + " B).", e.getMessage()); } }
@Test(timeout=60000) public void testAvailableSpaceChanges() throws Exception { @SuppressWarnings("unchecked") final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy = ReflectionUtils.newInstance(AvailableSpaceVolumeChoosingPolicy.class, null); initPolicy(policy, 1.0f); List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>(); // First volume with 1MB free space volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(0).getAvailable()).thenReturn(1024L * 1024L); // Second volume with 3MB free space, which is a difference of 2MB, more // than the threshold of 1MB. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(1).getAvailable()) .thenReturn(1024L * 1024L * 3) .thenReturn(1024L * 1024L * 3) .thenReturn(1024L * 1024L * 3) .thenReturn(1024L * 1024L * 1); // After the third check, return 1MB. // Should still be able to get a volume for the replica even though the // available space on the second volume changed. Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 100)); }
@Test(timeout=60000) public void testNotEnoughSpaceOnSelectedVolume() throws Exception { @SuppressWarnings("unchecked") final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy = ReflectionUtils.newInstance(AvailableSpaceVolumeChoosingPolicy.class, null); List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>(); // First volume with 1MB free space volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(0).getAvailable()).thenReturn(1024L * 1024L); // Second volume with 3MB free space, which is a difference of 2MB, more // than the threshold of 1MB. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(1).getAvailable()).thenReturn(1024L * 1024L * 3); // All writes should be assigned to the volume with the least free space. // However, if the volume with the least free space doesn't have enough // space to accept the replica size, and another volume does have enough // free space, that should be chosen instead. initPolicy(policy, 0.0f); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 1024L * 1024L * 2)); }
@Test(timeout=60000) public void testTwoUnbalancedVolumes() throws Exception { @SuppressWarnings("unchecked") final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy = ReflectionUtils.newInstance(AvailableSpaceVolumeChoosingPolicy.class, null); initPolicy(policy, 1.0f); List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>(); // First volume with 1MB free space volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(0).getAvailable()).thenReturn(1024L * 1024L); // Second volume with 3MB free space, which is a difference of 2MB, more // than the threshold of 1MB. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(1).getAvailable()).thenReturn(1024L * 1024L * 3); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 100)); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 100)); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 100)); }
Mockito.when(volume.getAvailable()).thenReturn(1024L * 1024L); volumes.add(volume); Mockito.when(volume.getAvailable()).thenReturn(1024L * 1024L * 3); volumes.add(volume);
public static void testRR(VolumeChoosingPolicy<FsVolumeSpi> policy) throws Exception { final List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>(); // First volume, with 100 bytes of space. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(0).getAvailable()).thenReturn(100L); // Second volume, with 200 bytes of space. volumes.add(Mockito.mock(FsVolumeSpi.class)); Mockito.when(volumes.get(1).getAvailable()).thenReturn(200L); // Test two rounds of round-robin choosing Assert.assertEquals(volumes.get(0), policy.chooseVolume(volumes, 0)); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 0)); Assert.assertEquals(volumes.get(0), policy.chooseVolume(volumes, 0)); Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 0)); // The first volume has only 100L space, so the policy should // wisely choose the second one in case we ask for more. Assert.assertEquals(volumes.get(1), policy.chooseVolume(volumes, 150)); // Fail if no volume can be chosen? try { policy.chooseVolume(volumes, Long.MAX_VALUE); Assert.fail(); } catch (IOException e) { // Passed. } }
Mockito.when(volumes.get(0).getAvailable()).thenReturn(1024L * 1024L); Mockito.when(volumes.get(1).getAvailable()).thenReturn(1024L * 1024L + 1); Mockito.when(volumes.get(2).getAvailable()).thenReturn(1024L * 1024L * 3); Mockito.when(volumes.get(3).getAvailable()).thenReturn(1024L * 1024L * 3);
Mockito.when(volumes.get(0).getAvailable()).thenReturn(1024L * 1024L); Mockito.when(volumes.get(1).getAvailable()).thenReturn(1024L * 1024L * 3); Mockito.when(volumes.get(2).getAvailable()).thenReturn(1024L * 1024L * 3);