Class DirectWriter
- java.lang.Object
-
- org.apache.bookkeeper.bookie.storage.directentrylogger.DirectWriter
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.ObjectbufferLock(package private) BufferPoolbufferPool(package private) intfd(package private) java.lang.Stringfilename(package private) intid(package private) BuffernativeBuffer(package private) NativeIOnativeIO(package private) longoffset(package private) java.util.List<java.util.concurrent.Future<?>>outstandingWrites(package private) Sloggerslog(package private) java.util.concurrent.ExecutorServicewriteExecutor
-
Constructor Summary
Constructors Constructor Description DirectWriter(int id, java.lang.String filename, long maxFileSize, java.util.concurrent.ExecutorService writeExecutor, BufferPool bufferPool, NativeIO nativeIO, Slogger slog)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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 Detail
-
nativeIO
final NativeIO nativeIO
-
fd
final int fd
-
id
final int id
-
filename
final java.lang.String filename
-
bufferPool
final BufferPool bufferPool
-
writeExecutor
final java.util.concurrent.ExecutorService writeExecutor
-
bufferLock
final java.lang.Object bufferLock
-
outstandingWrites
final java.util.List<java.util.concurrent.Future<?>> outstandingWrites
-
slog
final Slogger slog
-
nativeBuffer
Buffer nativeBuffer
-
offset
long offset
-
-
Constructor Detail
-
DirectWriter
DirectWriter(int id, java.lang.String filename, long maxFileSize, java.util.concurrent.ExecutorService writeExecutor, BufferPool bufferPool, NativeIO nativeIO, Slogger slog) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
logId
public int logId()
Description copied from interface:LogWriterReturn the ID of the log being written.
-
writeAt
public void writeAt(long offset, io.netty.buffer.ByteBuf buf) throws java.io.IOExceptionDescription 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).
-
writeDelimited
public int writeDelimited(io.netty.buffer.ByteBuf buf) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
position
public void position(long offset) throws java.io.IOExceptionDescription copied from interface:LogWriterSet the offset within the log at which the next call to #writeDelimited will start writing.
-
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
public void flush() throws java.io.IOExceptionDescription copied from interface:LogWriterFlush all buffered writes to disk. This call must ensure that the bytes are actually on disk before returning.
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:LogWriterClose any held resources.
-
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
-
-