/** * Creates a new segment file and flushes buffered writes to disk. * Provided metadata is written to record_log_directory_root/metadata.json * * @param metadata a mutable map of metadata to be written, may be empty. * @throws IOException if an I/O error occurs */ public synchronized void flushWriter(@Nonnull Map<String, String> metadata) throws IOException { writer.roll(); maxSegment = (int)(lastPosition >>> (64-RecordLogDirectory.DEFAULT_FILE_INDEX_BITS)); metadata.put(LAST_POSITION_KEY, String.valueOf(lastPosition)); metadata.put(MAX_SEGMENT_KEY, String.valueOf(maxSegment)); writeStringToFile(metadataPath, mapper.writeValueAsString(metadata)); writeStringToFile(lastPositionPath, String.valueOf(lastPosition)); writeStringToFile(maxSegmentPath, String.valueOf(maxSegment)); }
/** * Creates a new segment file and flushes buffered writes to disk. * Provided metadata is written to record_log_directory_root/metadata.json * * @param metadata a mutable map of metadata to be written, may be empty. * @throws IOException if an I/O error occurs */ public synchronized void flushWriter(@Nonnull Map<String, String> metadata) throws IOException { writer.roll(); maxSegment = (int)(lastPosition >>> (64-RecordLogDirectory.DEFAULT_FILE_INDEX_BITS)); metadata.put(LAST_POSITION_KEY, String.valueOf(lastPosition)); metadata.put(MAX_SEGMENT_KEY, String.valueOf(maxSegment)); writeStringToFile(metadataPath, mapper.writeValueAsString(metadata)); writeStringToFile(lastPositionPath, String.valueOf(lastPosition)); writeStringToFile(maxSegmentPath, String.valueOf(maxSegment)); }