/** * 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)); }
@Override public long append(final E entry) throws IOException { if (System.currentTimeMillis()-lastRollTime > rollFrequency) { roll(); } final long writerAddress = currentWriter.append(entry); if (writerAddress >= 1L<< segmentShift) throw new IOException("current writer has exceeded maximum size"); return (((long)currentSegmentNum)<< segmentShift)+writerAddress; }
@Override public void close() throws IOException { try { roll(); } finally { currentWriter.close(); } }
@Override public long append(final E entry) throws IOException { if (System.currentTimeMillis()-lastRollTime > rollFrequency) { roll(); } final long writerAddress = currentWriter.append(entry); if (writerAddress >= 1L<< segmentShift) throw new IOException("current writer has exceeded maximum size"); return (((long)currentSegmentNum)<< segmentShift)+writerAddress; }
@Override public void close() throws IOException { try { roll(); } finally { currentWriter.close(); } }