Source:
private void ensureCapacity(long writeSize) throws StoreException { long segmentCapacity = activeSegment.getCapacityInBytes(); if (writeSize > segmentCapacity - LogSegment.HEADER_SIZE) { metrics.overflowWriteError.inc(); throw new IllegalArgumentException("Write of size [" + writeSize + "] cannot be serviced because it is greater " + "than a single segment's capacity [" + (segmentCapacity - LogSegment.HEADER_SIZE) + "]"); } if (remainingUnallocatedSegments.decrementAndGet() < 0) { remainingUnallocatedSegments.incrementAndGet(); metrics.overflowWriteError.inc(); throw new IllegalStateException( "There is no more capacity left in [" + dataDir + "]. Max capacity is [" + capacityInBytes + "]"); } Pair<String, String> segmentNameAndFilename = getNextSegmentNameAndFilename(); logger.info("Allocating new segment with name: " + segmentNameAndFilename.getFirst()); File newSegmentFile = allocate(segmentNameAndFilename.getSecond(), segmentCapacity); try { LogSegment newSegment = new LogSegment(segmentNameAndFilename.getFirst(), newSegmentFile, segmentCapacity, metrics, true); segmentsByName.put(segmentNameAndFilename.getFirst(), newSegment); } catch (StoreException e) { try { diskSpaceAllocator.free(newSegmentFile, segmentCapacity); remainingUnallocatedSegments.incrementAndGet(); throw e; } catch (IOException exception) { StoreErrorCodes errorCode = StoreException.resolveErrorCode(exception); throw new StoreException( e.getMessage() + " And then " + errorCode.toString() + " occurred while freeing the log segment " + segmentNameAndFilename.getFirst(), exception, errorCode); } finally { metrics.overflowWriteError.inc(); } } }

Target:
private void ensureCapacity(long writeSize) throws StoreException { long segmentCapacity = activeSegment.getCapacityInBytes(); if (writeSize > segmentCapacity - LogSegment.HEADER_SIZE) { metrics.overflowWriteError.inc(); throw new IllegalArgumentException("Write of size [" + writeSize + "] cannot be serviced because it is greater " + "than a single segment's capacity [" + (segmentCapacity - LogSegment.HEADER_SIZE) + "]"); } if (remainingUnallocatedSegments.decrementAndGet() < 0) { remainingUnallocatedSegments.incrementAndGet(); metrics.overflowWriteError.inc(); throw new IllegalStateException( "There is no more capacity left in [" + dataDir + "]. Max capacity is [" + capacityInBytes + "]"); } Pair<String, String> segmentNameAndFilename = getNextSegmentNameAndFilename(); logger.info("Allocating new segment with name: " + segmentNameAndFilename.getFirst()); File newSegmentFile = null; try { newSegmentFile = allocate(segmentNameAndFilename.getSecond(), segmentCapacity); LogSegment newSegment = new LogSegment(segmentNameAndFilename.getFirst(), newSegmentFile, segmentCapacity, metrics, true); segmentsByName.put(segmentNameAndFilename.getFirst(), newSegment); } catch (StoreException e) { try { if (newSegmentFile != null) { diskSpaceAllocator.free(newSegmentFile, segmentCapacity); } remainingUnallocatedSegments.incrementAndGet(); throw e; } catch (IOException exception) { StoreErrorCodes errorCode = StoreException.resolveErrorCode(exception); throw new StoreException( e.getMessage() + " And then " + errorCode.toString() + " occurred while freeing the log segment " + segmentNameAndFilename.getFirst(), exception, errorCode); } finally { metrics.overflowWriteError.inc(); } } }