@Override void writeLogHeader() { super.writeLogHeader(); try { channel.write((ByteBuffer) buffer.duplicate().flip()); manager.addSize(lastWrittenPos = buffer.position()); } catch (IOException e) { throw new FSWriteError(e, getPath()); } }
@Override void writeLogHeader() { super.writeLogHeader(); try { channel.write((ByteBuffer) buffer.duplicate().flip()); manager.addSize(lastWrittenPos = buffer.position()); } catch (IOException e) { throw new FSWriteError(e, getPath()); } }
@Override void writeLogHeader() { super.writeLogHeader(); try { channel.write((ByteBuffer) buffer.duplicate().flip()); manager.addSize(lastWrittenPos = buffer.position()); } catch (IOException e) { throw new FSWriteError(e, getPath()); } }
ByteBuffer createBuffer(CommitLog commitLog) { try { MappedByteBuffer mappedFile = channel.map(FileChannel.MapMode.READ_WRITE, 0, DatabaseDescriptor.getCommitLogSegmentSize()); manager.addSize(DatabaseDescriptor.getCommitLogSegmentSize()); return mappedFile; } catch (IOException e) { throw new FSWriteError(e, logFile); } }
ByteBuffer createBuffer(CommitLog commitLog) { try { MappedByteBuffer mappedFile = channel.map(FileChannel.MapMode.READ_WRITE, 0, DatabaseDescriptor.getCommitLogSegmentSize()); manager.addSize(DatabaseDescriptor.getCommitLogSegmentSize()); return mappedFile; } catch (IOException e) { throw new FSWriteError(e, logFile); } }
ByteBuffer createBuffer(CommitLog commitLog) { try { MappedByteBuffer mappedFile = channel.map(FileChannel.MapMode.READ_WRITE, 0, DatabaseDescriptor.getCommitLogSegmentSize()); manager.addSize(DatabaseDescriptor.getCommitLogSegmentSize()); return mappedFile; } catch (IOException e) { throw new FSWriteError(e, logFile); } }
/** * Discards a segment file when the log no longer requires it. The file may be left on disk if the archive script * requires it. (Potentially blocking operation) */ void discard(boolean deleteFile) { close(); if (deleteFile) FileUtils.deleteWithConfirm(logFile); manager.addSize(-onDiskSize()); }
@Override void write(int startMarker, int nextMarker) { int contentStart = startMarker + SYNC_MARKER_SIZE; int length = nextMarker - contentStart; // The length may be 0 when the segment is being closed. assert length > 0 || length == 0 && !isStillAllocating(); try { int neededBufferSize = compressor.initialCompressedBufferLength(length) + COMPRESSED_MARKER_SIZE; ByteBuffer compressedBuffer = manager.getBufferPool().getThreadLocalReusableBuffer(neededBufferSize); ByteBuffer inputBuffer = buffer.duplicate(); inputBuffer.limit(contentStart + length).position(contentStart); compressedBuffer.limit(compressedBuffer.capacity()).position(COMPRESSED_MARKER_SIZE); compressor.compress(inputBuffer, compressedBuffer); compressedBuffer.flip(); compressedBuffer.putInt(SYNC_MARKER_SIZE, length); // Only one thread can be here at a given time. // Protected by synchronization on CommitLogSegment.sync(). writeSyncMarker(id, compressedBuffer, 0, (int) channel.position(), (int) channel.position() + compressedBuffer.remaining()); manager.addSize(compressedBuffer.limit()); channel.write(compressedBuffer); assert channel.position() - lastWrittenPos == compressedBuffer.limit(); lastWrittenPos = channel.position(); } catch (Exception e) { throw new FSWriteError(e, getPath()); } }
/** * Discards a segment file when the log no longer requires it. The file may be left on disk if the archive script * requires it. (Potentially blocking operation) */ void discard(boolean deleteFile) { close(); if (deleteFile) FileUtils.deleteWithConfirm(logFile); manager.addSize(-onDiskSize()); }
@Override void write(int startMarker, int nextMarker) { int contentStart = startMarker + SYNC_MARKER_SIZE; int length = nextMarker - contentStart; // The length may be 0 when the segment is being closed. assert length > 0 || length == 0 && !isStillAllocating(); try { int neededBufferSize = compressor.initialCompressedBufferLength(length) + COMPRESSED_MARKER_SIZE; ByteBuffer compressedBuffer = manager.getBufferPool().getThreadLocalReusableBuffer(neededBufferSize); ByteBuffer inputBuffer = buffer.duplicate(); inputBuffer.limit(contentStart + length).position(contentStart); compressedBuffer.limit(compressedBuffer.capacity()).position(COMPRESSED_MARKER_SIZE); compressor.compress(inputBuffer, compressedBuffer); compressedBuffer.flip(); compressedBuffer.putInt(SYNC_MARKER_SIZE, length); // Only one thread can be here at a given time. // Protected by synchronization on CommitLogSegment.sync(). writeSyncMarker(id, compressedBuffer, 0, (int) channel.position(), (int) channel.position() + compressedBuffer.remaining()); manager.addSize(compressedBuffer.limit()); channel.write(compressedBuffer); assert channel.position() - lastWrittenPos == compressedBuffer.limit(); lastWrittenPos = channel.position(); } catch (Exception e) { throw new FSWriteError(e, getPath()); } }
/** * Discards a segment file when the log no longer requires it. The file may be left on disk if the archive script * requires it. (Potentially blocking operation) */ void discard(boolean deleteFile) { close(); if (deleteFile) FileUtils.deleteWithConfirm(logFile); manager.addSize(-onDiskSize()); }
@Override void write(int startMarker, int nextMarker) { int contentStart = startMarker + SYNC_MARKER_SIZE; int length = nextMarker - contentStart; // The length may be 0 when the segment is being closed. assert length > 0 || length == 0 && !isStillAllocating(); try { int neededBufferSize = compressor.initialCompressedBufferLength(length) + COMPRESSED_MARKER_SIZE; ByteBuffer compressedBuffer = manager.getBufferPool().getThreadLocalReusableBuffer(neededBufferSize); ByteBuffer inputBuffer = buffer.duplicate(); inputBuffer.limit(contentStart + length).position(contentStart); compressedBuffer.limit(compressedBuffer.capacity()).position(COMPRESSED_MARKER_SIZE); compressor.compress(inputBuffer, compressedBuffer); compressedBuffer.flip(); compressedBuffer.putInt(SYNC_MARKER_SIZE, length); // Only one thread can be here at a given time. // Protected by synchronization on CommitLogSegment.sync(). writeSyncMarker(id, compressedBuffer, 0, (int) channel.position(), (int) channel.position() + compressedBuffer.remaining()); manager.addSize(compressedBuffer.limit()); channel.write(compressedBuffer); assert channel.position() - lastWrittenPos == compressedBuffer.limit(); lastWrittenPos = channel.position(); } catch (Exception e) { throw new FSWriteError(e, getPath()); } }