private FsVolumeReference chooseVolume(List<FsVolumeImpl> list, long blockSize, String storageId) throws IOException { while (true) { FsVolumeImpl volume = blockChooser.chooseVolume(list, blockSize, storageId); try { return volume.obtainReference(); } catch (ClosedChannelException e) { FsDatasetImpl.LOG.warn("Chosen a closed volume: " + volume); // blockChooser.chooseVolume returns DiskOutOfSpaceException when the list // is empty, indicating that all volumes are closed. list.remove(volume); } } }
V volume = roundRobinPolicyBalanced.chooseVolume(volumes, replicaSize, storageId); if (LOG.isDebugEnabled()) { if (mostAvailableAmongLowVolumes < replicaSize || random.nextFloat() < scaledPreferencePercent) { volume = roundRobinPolicyHighAvailable.chooseVolume( highAvailableVolumes, replicaSize, storageId); if (LOG.isDebugEnabled()) { volume = roundRobinPolicyLowAvailable.chooseVolume( lowAvailableVolumes, replicaSize, storageId); if (LOG.isDebugEnabled()) {
private FsVolumeReference chooseVolume(List<FsVolumeImpl> list, long blockSize) throws IOException { while (true) { FsVolumeImpl volume = blockChooser.chooseVolume(list, blockSize); try { return volume.obtainReference(); } catch (ClosedChannelException e) { FsDatasetImpl.LOG.warn("Chosen a closed volume: " + volume); // blockChooser.chooseVolume returns DiskOutOfSpaceException when the list // is empty, indicating that all volumes are closed. list.remove(volume); } } }
private FsVolumeReference chooseVolume(List<FsVolumeImpl> list, long blockSize) throws IOException { while (true) { FsVolumeImpl volume = blockChooser.chooseVolume(list, blockSize); try { return volume.obtainReference(); } catch (ClosedChannelException e) { FsDatasetImpl.LOG.warn("Chosen a closed volume: " + volume); // blockChooser.chooseVolume returns DiskOutOfSpaceException when the list // is empty, indicating that all volumes are closed. list.remove(volume); } } }
V volume = roundRobinPolicyBalanced.chooseVolume(volumes, replicaSize); if (LOG.isDebugEnabled()) { LOG.debug("All volumes are within the configured free space balance " + if (mostAvailableAmongLowVolumes < replicaSize || random.nextFloat() < scaledPreferencePercent) { volume = roundRobinPolicyHighAvailable.chooseVolume( highAvailableVolumes, replicaSize); if (LOG.isDebugEnabled()) { volume = roundRobinPolicyLowAvailable.chooseVolume( lowAvailableVolumes, replicaSize); if (LOG.isDebugEnabled()) {
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. } }
V volume = roundRobinPolicyBalanced.chooseVolume(volumes, replicaSize); if (LOG.isDebugEnabled()) { LOG.debug("All volumes are within the configured free space balance " + if (mostAvailableAmongLowVolumes < replicaSize || random.nextFloat() < scaledPreferencePercent) { volume = roundRobinPolicyHighAvailable.chooseVolume( highAvailableVolumes, replicaSize); if (LOG.isDebugEnabled()) { volume = roundRobinPolicyLowAvailable.chooseVolume( lowAvailableVolumes, replicaSize); if (LOG.isDebugEnabled()) {
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()); } }