Class DirectWriter
java.lang.Object
org.apache.bookkeeper.bookie.storage.directentrylogger.DirectWriter
- All Implemented Interfaces:
AutoCloseable,LogWriter
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Object(package private) final BufferPool(package private) final int(package private) final String(package private) final int(package private) Buffer(package private) final NativeIO(package private) long(package private) final Slogger(package private) final ExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionDirectWriter(int id, String filename, long maxFileSize, ExecutorService writeExecutor, BufferPool bufferPool, NativeIO nativeIO, Slogger slog) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close any held resources.voidflush()Flush all buffered writes to disk.intlogId()Return the ID of the log being written.longposition()The current offset within the log at which the next call to #writeDelimited will start writing.voidposition(long offset) Set the offset within the log at which the next call to #writeDelimited will start writing.intserializedSize(io.netty.buffer.ByteBuf buf) voidwriteAt(long offset, io.netty.buffer.ByteBuf buf) Write the contents of a buffer at a predefined position in the log.intwriteDelimited(io.netty.buffer.ByteBuf buf) Write a delimited buffer the log.
-
Field Details
-
nativeIO
-
fd
final int fd -
id
final int id -
filename
-
bufferPool
-
writeExecutor
-
bufferLock
-
outstandingWrites
-
slog
-
nativeBuffer
Buffer nativeBuffer -
offset
long offset
-
-
Constructor Details
-
DirectWriter
DirectWriter(int id, String filename, long maxFileSize, ExecutorService writeExecutor, BufferPool bufferPool, NativeIO nativeIO, Slogger slog) throws IOException - Throws:
IOException
-
-
Method Details
-
logId
public int logId()Description copied from interface:LogWriterReturn the ID of the log being written. -
writeAt
Description copied from interface:LogWriterWrite the contents of a buffer at a predefined position in the log. Both the position and the size of the buffer must be page aligned (i.e. to 4096).- Specified by:
writeAtin interfaceLogWriter- Throws:
IOException
-
writeDelimited
Description copied from interface:LogWriterWrite a delimited buffer the log. The size of the buffer is first written and then the buffer itself. Note that the returned offset is for the buffer itself, not the size. So, if a buffer is written at the start of the file, the returned offset will be 4, not 0. The returned offset is an int. Consequently, entries can only be written in the first Integer.MAX_VALUE bytes of the file. This is due to how offsets are stored in the index.- Specified by:
writeDelimitedin interfaceLogWriter- Returns:
- the offset of the buffer within the file.
- Throws:
IOException
-
position
Description copied from interface:LogWriterSet the offset within the log at which the next call to #writeDelimited will start writing.- Specified by:
positionin interfaceLogWriter- Throws:
IOException
-
position
public long position()Description copied from interface:LogWriterThe current offset within the log at which the next call to #writeDelimited will start writing. -
flush
Description copied from interface:LogWriterFlush all buffered writes to disk. This call must ensure that the bytes are actually on disk before returning.- Specified by:
flushin interfaceLogWriter- Throws:
IOException
-
close
Description copied from interface:LogWriterClose any held resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLogWriter- Throws:
IOException
-
serializedSize
public int serializedSize(io.netty.buffer.ByteBuf buf) - Specified by:
serializedSizein interfaceLogWriter- Returns:
- the number of bytes consumed by the buffer when written with #writeDelimited
-