Source:
void allocate(File destinationFile, long sizeInBytes, String storeId, boolean isSwapSegment) throws IOException { long startTime = System.currentTimeMillis(); try { if (enablePooling && poolState != PoolState.INITIALIZED) { logger.info("Allocating segment of size to before pool is fully initialized", sizeInBytes, destinationFile.getAbsolutePath()); metrics.diskSpaceAllocatorAllocBeforeInitCount.inc(); } else { logger.debug("Allocating segment of size to {}", sizeInBytes, destinationFile.getAbsolutePath()); } if (destinationFile.exists()) { throw new IOException("Destination file already exists: " + destinationFile.getAbsolutePath()); } File reserveFile = null; if (poolState != PoolState.NOT_INVENTORIED) { if (isSwapSegment) { reserveFile = swapReserveFiles.remove(sizeInBytes); } else { if (storeReserveFiles.containsKey(storeId)) { reserveFile = storeReserveFiles.get(storeId).remove(sizeInBytes); } } } if (reserveFile == null) { if (enablePooling) { logger.info( "Segment of size not found in pool; attempting to create a new preallocated file; poolState: {}", sizeInBytes, poolState); metrics.diskSpaceAllocatorSegmentNotFoundCount.inc(); } Utils.preAllocateFileIfNeeded(destinationFile, sizeInBytes); } else { try { Files.move(reserveFile.toPath(), destinationFile.toPath()); } catch (Exception e) { if (isSwapSegment) { swapReserveFiles.add(sizeInBytes, reserveFile); } else { storeReserveFiles.get(storeId).add(sizeInBytes, reserveFile); } throw e; } } } finally { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("allocate took ms", elapsedTime); metrics.diskSpaceAllocatorAllocTimeMs.update(elapsedTime); } }

Target:
void allocate(File destinationFile, long sizeInBytes, String storeId, boolean isSwapSegment) throws IOException { long startTime = System.currentTimeMillis(); try { if (enablePooling && poolState != PoolState.INITIALIZED) { logger.info("Allocating segment of size to before pool is fully initialized", sizeInBytes, destinationFile.getAbsolutePath()); metrics.diskSpaceAllocatorAllocBeforeInitCount.inc(); } else { logger.info("Allocating segment of size to {}", sizeInBytes, destinationFile.getAbsolutePath()); } if (destinationFile.exists()) { throw new IOException("Destination file already exists: " + destinationFile.getAbsolutePath()); } File reserveFile = null; if (poolState != PoolState.NOT_INVENTORIED) { if (isSwapSegment) { reserveFile = swapReserveFiles.remove(sizeInBytes); } else { if (storeReserveFiles.containsKey(storeId)) { reserveFile = storeReserveFiles.get(storeId).remove(sizeInBytes); } } } if (reserveFile == null) { if (enablePooling) { logger.info("Segment of size not found in {}; attempting to create a new preallocated file; poolState: {}", sizeInBytes, isSwapSegment ? SWAP_DIR_NAME + " directory" : STORE_DIR_PREFIX + storeId + " directory", poolState); metrics.diskSpaceAllocatorSegmentNotFoundCount.inc(); } Utils.preAllocateFileIfNeeded(destinationFile, sizeInBytes); } else { logger.info("Moving segment with size from to {}", sizeInBytes, isSwapSegment ? SWAP_DIR_NAME + " directory" : STORE_DIR_PREFIX + storeId + " directory", destinationFile.getAbsolutePath()); try { Files.move(reserveFile.toPath(), destinationFile.toPath()); } catch (Exception e) { if (isSwapSegment) { swapReserveFiles.add(sizeInBytes, reserveFile); } else { storeReserveFiles.get(storeId).add(sizeInBytes, reserveFile); } throw e; } } } finally { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("allocating new segment took ms for {}", elapsedTime, "store[" + storeId + "]"); metrics.diskSpaceAllocatorAllocTimeMs.update(elapsedTime); } }