Source:
public AllocatedBlock allocateBlock(final long size, ReplicationType type, ReplicationFactor factor, String owner, ExcludeList excludeList) throws IOException { LOG.trace("Size;{} , type : {}, factor : ", size, type, factor); ScmUtils.preCheck(ScmOps.allocateBlock, safeModePrecheck); if (size < 0 || size > containerSize) { LOG.warn("Invalid block size requested : {}", size); throw new SCMException("Unsupported block size: " + size, INVALID_BLOCK_SIZE); } ContainerInfo containerInfo; while (true) { List<Pipeline> availablePipelines = pipelineManager .getPipelines(type, factor, Pipeline.PipelineState.OPEN, excludeList.getDatanodes(), excludeList.getPipelineIds()); Pipeline pipeline = null; if (availablePipelines.size() == 0) { try { pipeline = pipelineManager.createPipeline(type, factor); } catch (IOException e) { LOG.warn("Pipeline creation failed for type:{} factor:{}", type, factor, e); LOG.info("Checking one more time for suitable pipelines"); availablePipelines = pipelineManager .getPipelines(type, factor, Pipeline.PipelineState.OPEN, excludeList.getDatanodes(), excludeList.getPipelineIds()); if (availablePipelines.size() == 0) { LOG.info("Could not find available pipeline even after trying " + "once more"); break; } } } if (null == pipeline) { pipeline = availablePipelines .get((int) (Math.random() * availablePipelines.size())); } containerInfo = containerManager.getMatchingContainer(size, owner, pipeline, excludeList.getContainerIds()); if (containerInfo != null) { return newBlock(containerInfo); } } LOG.error( "Unable to allocate a block for the size: {}, type: {}, factor: {}", size, type, factor); return null; }

Target:
public AllocatedBlock allocateBlock(final long size, ReplicationType type, ReplicationFactor factor, String owner, ExcludeList excludeList) throws IOException { LOG.trace("Size;{} , type : {}, factor : ", size, type, factor); ScmUtils.preCheck(ScmOps.allocateBlock, safeModePrecheck); if (size < 0 || size > containerSize) { LOG.warn("Invalid block size requested : {}", size); throw new SCMException("Unsupported block size: " + size, INVALID_BLOCK_SIZE); } ContainerInfo containerInfo; while (true) { List<Pipeline> availablePipelines = pipelineManager .getPipelines(type, factor, Pipeline.PipelineState.OPEN, excludeList.getDatanodes(), excludeList.getPipelineIds()); Pipeline pipeline = null; if (availablePipelines.size() == 0) { try { pipeline = pipelineManager.createPipeline(type, factor); } catch (IOException e) { LOG.warn("Pipeline creation failed for type:{} factor:{}. Retrying " + "get pipelines call once.", type, factor, e); availablePipelines = pipelineManager .getPipelines(type, factor, Pipeline.PipelineState.OPEN, excludeList.getDatanodes(), excludeList.getPipelineIds()); if (availablePipelines.size() == 0) { LOG.info("Could not find available pipeline of type:{} and " + "factor:{} even after retrying", type, factor); break; } } } if (null == pipeline) { pipeline = availablePipelines .get((int) (Math.random() * availablePipelines.size())); } containerInfo = containerManager.getMatchingContainer(size, owner, pipeline, excludeList.getContainerIds()); if (containerInfo != null) { return newBlock(containerInfo); } } LOG.error( "Unable to allocate a block for the size: {}, type: {}, factor: {}", size, type, factor); return null; }