@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()); } }
/** * To be used by tests only. Not safe if mutation slots are being allocated concurrently. */ void awaitManagementTasksCompletion() { if (availableSegment == null && !atSegmentBufferLimit()) { awaitAvailableSegment(allocatingFrom); } }
/** * Stops CL, for testing purposes. DO NOT USE THIS OUTSIDE OF TESTS. * Only call this after the AbstractCommitLogService is shut down. */ public void stopUnsafe(boolean deleteSegments) { logger.debug("CLSM closing and clearing existing commit log segments..."); shutdown(); try { awaitTermination(); } catch (InterruptedException e) { throw new RuntimeException(e); } for (CommitLogSegment segment : activeSegments) closeAndDeleteSegmentUnsafe(segment, deleteSegments); activeSegments.clear(); size.set(0L); logger.trace("CLSM done with closing and clearing existing commit log segments."); }
/** * Shuts down the threads used by the commit log, blocking until completion. */ public void shutdownBlocking() throws InterruptedException { executor.shutdown(); executor.awaitTermination(); segmentManager.shutdown(); segmentManager.awaitTermination(); }
advanceAllocatingFrom(last); Future<?> future = flushDataFrom(segmentsToRecycle, true); try archiveAndDiscard(segment);
@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()); } }
for (Iterator<CommitLogSegment> iter = segmentManager.getActiveSegments().iterator(); iter.hasNext();) segmentManager.archiveAndDiscard(segment);
Allocation alloc = segmentManager.allocate(mutation, totalSize); throw new FSWriteError(e, segmentManager.allocatingFrom().getPath());
availableSegment = createSegment(); if (shutdown)
advanceAllocatingFrom(last); Future<?> future = flushDataFrom(segmentsToRecycle, true); try archiveAndDiscard(segment);
@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()); } }
/** * Shuts down the threads used by the commit log, blocking until completion. */ public void shutdownBlocking() throws InterruptedException { executor.shutdown(); executor.awaitTermination(); segmentManager.shutdown(); segmentManager.awaitTermination(); }
for (Iterator<CommitLogSegment> iter = segmentManager.getActiveSegments().iterator(); iter.hasNext();) segmentManager.archiveAndDiscard(segment);
Allocation alloc = segmentManager.allocate(mutation, totalSize); throw new FSWriteError(e, segmentManager.allocatingFrom().getPath());
availableSegment = createSegment(); if (shutdown)
/** * Stops CL, for testing purposes. DO NOT USE THIS OUTSIDE OF TESTS. * Only call this after the AbstractCommitLogService is shut down. */ public void stopUnsafe(boolean deleteSegments) { logger.debug("CLSM closing and clearing existing commit log segments..."); shutdown(); try { awaitTermination(); } catch (InterruptedException e) { throw new RuntimeException(e); } for (CommitLogSegment segment : activeSegments) closeAndDeleteSegmentUnsafe(segment, deleteSegments); activeSegments.clear(); size.set(0L); logger.trace("CLSM done with closing and clearing existing commit log segments."); }