Class DirectWriter
- java.lang.Object
-
- org.apache.bookkeeper.bookie.storage.directentrylogger.DirectWriter
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Object
bufferLock
(package private) BufferPool
bufferPool
(package private) int
fd
(package private) java.lang.String
filename
(package private) int
id
(package private) Buffer
nativeBuffer
(package private) NativeIO
nativeIO
(package private) long
offset
(package private) java.util.List<java.util.concurrent.Future<?>>
outstandingWrites
(package private) Slogger
slog
(package private) java.util.concurrent.ExecutorService
writeExecutor
-
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 void
close()
Close any held resources.void
flush()
Flush all buffered writes to disk.int
logId()
Return the ID of the log being written.long
position()
The current offset within the log at which the next call to #writeDelimited will start writing.void
position(long offset)
Set the offset within the log at which the next call to #writeDelimited will start writing.int
serializedSize(io.netty.buffer.ByteBuf buf)
void
writeAt(long offset, io.netty.buffer.ByteBuf buf)
Write the contents of a buffer at a predefined position in the log.int
writeDelimited(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:LogWriter
Return the ID of the log being written.
-
writeAt
public void writeAt(long offset, io.netty.buffer.ByteBuf buf) throws java.io.IOException
Description copied from interface:LogWriter
Write 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.IOException
Description copied from interface:LogWriter
Write 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:
writeDelimited
in interfaceLogWriter
- Returns:
- the offset of the buffer within the file.
- Throws:
java.io.IOException
-
position
public void position(long offset) throws java.io.IOException
Description copied from interface:LogWriter
Set the offset within the log at which the next call to #writeDelimited will start writing.
-
position
public long position()
Description copied from interface:LogWriter
The current offset within the log at which the next call to #writeDelimited will start writing.
-
flush
public void flush() throws java.io.IOException
Description copied from interface:LogWriter
Flush 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.IOException
Description copied from interface:LogWriter
Close any held resources.
-
serializedSize
public int serializedSize(io.netty.buffer.ByteBuf buf)
- Specified by:
serializedSize
in interfaceLogWriter
- Returns:
- the number of bytes consumed by the buffer when written with #writeDelimited
-
-