Source:
public void write() throws StoreException { final Timer.Context context = metrics.indexFlushTime.time(); try { if (indexes.size() > 0) { Map.Entry<Offset, IndexSegment> lastEntry = indexes.lastEntry(); IndexSegment currentInfo = lastEntry.getValue(); Offset currentIndexEndOffsetBeforeFlush = currentInfo.getEndOffset(); Offset logEndOffsetBeforeFlush = log.getEndOffset(); if (logEndOffsetBeforeFlush.compareTo(currentIndexEndOffsetBeforeFlush) < 0) { throw new StoreException("LogEndOffset " + logEndOffsetBeforeFlush + " before flush cannot be less than " + "currentEndOffSet of index " + currentIndexEndOffsetBeforeFlush, StoreErrorCodes.Illegal_Index_State); } hardDeleter.preLogFlush(); log.flush(); hardDeleter.postLogFlush(); IndexSegment prevInfo = indexes.size() > 1 ? indexes.lowerEntry(lastEntry.getKey()).getValue() : null; Offset currentLogEndPointer = log.getEndOffset(); while (prevInfo != null && !prevInfo.isMapped()) { if (prevInfo.getEndOffset().compareTo(currentLogEndPointer) > 0) { String message = "The read only index cannot have a file end pointer " + prevInfo.getEndOffset() + " greater than the log end offset " + currentLogEndPointer; throw new StoreException(message, StoreErrorCodes.IOError); } logger.trace("Index : " + dataDir + " writing prev index with end offset " + prevInfo.getEndOffset()); prevInfo.writeIndexToFile(prevInfo.getEndOffset()); prevInfo.map(true); Map.Entry<Offset, IndexSegment> infoEntry = indexes.lowerEntry(prevInfo.getStartOffset()); prevInfo = infoEntry != null ? infoEntry.getValue() : null; } currentInfo.writeIndexToFile(currentIndexEndOffsetBeforeFlush); } } catch (IOException e) { throw new StoreException("IO error while writing index to file", e, StoreErrorCodes.IOError); } finally { context.stop(); } }

Target:
public void write() throws StoreException { final Timer.Context context = metrics.indexFlushTime.time(); try { if (indexes.size() > 0) { Map.Entry<Offset, IndexSegment> lastEntry = indexes.lastEntry(); IndexSegment currentInfo = lastEntry.getValue(); Offset indexEndOffsetBeforeFlush = currentInfo.getEndOffset(); Offset logEndOffsetBeforeFlush = log.getEndOffset(); if (logEndOffsetBeforeFlush.compareTo(indexEndOffsetBeforeFlush) < 0) { throw new StoreException("LogEndOffset " + logEndOffsetBeforeFlush + " before flush cannot be less than " + "currentEndOffSet of index " + indexEndOffsetBeforeFlush, StoreErrorCodes.Illegal_Index_State); } hardDeleter.preLogFlush(); log.flush(); hardDeleter.postLogFlush(); IndexSegment prevInfo = indexes.size() > 1 ? indexes.lowerEntry(lastEntry.getKey()).getValue() : null; Offset currentLogEndPointer = log.getEndOffset(); while (prevInfo != null && !prevInfo.isMapped()) { if (prevInfo.getEndOffset().compareTo(currentLogEndPointer) > 0) { String message = "The read only index cannot have a file end pointer " + prevInfo.getEndOffset() + " greater than the log end offset " + currentLogEndPointer; throw new StoreException(message, StoreErrorCodes.IOError); } logger.trace("Index : " + dataDir + " writing prev index with end offset " + prevInfo.getEndOffset()); prevInfo.writeIndexSegmentToFile(prevInfo.getEndOffset()); prevInfo.map(true); Map.Entry<Offset, IndexSegment> infoEntry = indexes.lowerEntry(prevInfo.getStartOffset()); prevInfo = infoEntry != null ? infoEntry.getValue() : null; } currentInfo.writeIndexSegmentToFile(indexEndOffsetBeforeFlush); } } catch (IOException e) { throw new StoreException("IO error while writing index to file", e, StoreErrorCodes.IOError); } finally { context.stop(); } }