Package org.apache.bookkeeper.bookie
Class BufferedChannel
java.lang.Object
org.apache.bookkeeper.bookie.BufferedChannelBase
org.apache.bookkeeper.bookie.BufferedReadChannel
org.apache.bookkeeper.bookie.BufferedChannel
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DefaultEntryLogger.BufferedLogChannel,SlowBufferedChannel
Provides a buffering layer in front of a FileChannel.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
BufferedChannelBase.BufferedChannelClosedException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longThe absolute position of the next write operation.protected final AtomicLongprotected final longprotected final io.netty.buffer.ByteBufThe buffer used to write operations.protected AtomicLongThe position of the file channel's write pointer.protected final intThe capacity of the write buffer.Fields inherited from class org.apache.bookkeeper.bookie.BufferedReadChannel
cacheHitCount, invocationCount, readBuffer, readBufferStartPosition, readCapacity, sealedFields inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
fileChannel -
Constructor Summary
ConstructorsConstructorDescriptionBufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int capacity) BufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int writeCapacity, int readCapacity, long unpersistedBytesBound) BufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int capacity, long unpersistedBytesBound) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()voidflush()Write any data in the buffer to the file and advance the writeBufferPosition.voidflushAndForceWrite(boolean forceMetadata) calls both flush and forceWrite methods.voidflushAndForceWriteIfRegularFlush(boolean forceMetadata) calls both flush and forceWrite methods if regular flush is enabled.longforceWrite(boolean forceMetadata) force a sync operation so that data is persisted to the disk.longGet the position of the file channel's write pointer.int(package private) longlongposition()Get the position where the next write operation will begin writing from.intread(io.netty.buffer.ByteBuf dest, long pos, int length) voidwrite(io.netty.buffer.ByteBuf src) Write all the data in src to theFileChannel.Methods inherited from class org.apache.bookkeeper.bookie.BufferedReadChannel
read, sizeMethods inherited from class org.apache.bookkeeper.bookie.BufferedChannelBase
validateAndGetFileChannel
-
Field Details
-
writeCapacity
protected final int writeCapacityThe capacity of the write buffer. -
writeBufferStartPosition
The position of the file channel's write pointer. -
writeBuffer
protected final io.netty.buffer.ByteBuf writeBufferThe buffer used to write operations. -
position
protected volatile long positionThe absolute position of the next write operation. -
unpersistedBytesBound
protected final long unpersistedBytesBound -
unpersistedBytes
-
-
Constructor Details
-
BufferedChannel
public BufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int capacity) throws IOException - Throws:
IOException
-
BufferedChannel
public BufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int capacity, long unpersistedBytesBound) throws IOException - Throws:
IOException
-
BufferedChannel
public BufferedChannel(io.netty.buffer.ByteBufAllocator allocator, FileChannel fc, int writeCapacity, int readCapacity, long unpersistedBytesBound) throws IOException - Throws:
IOException
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
write
Write all the data in src to theFileChannel. Note that this function can buffer or re-order writes based on the implementation. These writes will be flushed to the disk only when flush() is invoked.- Parameters:
src- The source ByteBuffer which contains the data to be written.- Throws:
IOException- if a write operation fails.
-
position
public long position()Get the position where the next write operation will begin writing from.- Returns:
-
getFileChannelPosition
public long getFileChannelPosition()Get the position of the file channel's write pointer.- Returns:
-
flushAndForceWrite
calls both flush and forceWrite methods.- Parameters:
forceMetadata- - If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written- Throws:
IOException
-
flushAndForceWriteIfRegularFlush
calls both flush and forceWrite methods if regular flush is enabled.- Parameters:
forceMetadata- - If true then this method is required to force changes to both the file's content and metadata to be written to storage; otherwise, it need only force content changes to be written- Throws:
IOException
-
flush
Write any data in the buffer to the file and advance the writeBufferPosition. Callers are expected to synchronize appropriately- Throws:
IOException- if the write fails.
-
forceWrite
force a sync operation so that data is persisted to the disk.- Parameters:
forceMetadata-- Returns:
- Throws:
IOException
-
read
- Overrides:
readin classBufferedReadChannel- Throws:
IOException
-
clear
public void clear()- Overrides:
clearin classBufferedReadChannel
-
getNumOfBytesInWriteBuffer
public int getNumOfBytesInWriteBuffer() -
getUnpersistedBytes
long getUnpersistedBytes()
-