Class DirectWriter

  • All Implemented Interfaces:
    java.lang.AutoCloseable, LogWriter

    class DirectWriter
    extends java.lang.Object
    implements LogWriter
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fd

        final int fd
      • id

        final int id
      • filename

        final java.lang.String filename
      • writeExecutor

        final java.util.concurrent.ExecutorService writeExecutor
      • bufferLock

        final java.lang.Object bufferLock
      • outstandingWrites

        final java.util.List<java.util.concurrent.Future<?>> outstandingWrites
      • 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.
        Specified by:
        logId in interface LogWriter
      • 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).
        Specified by:
        writeAt in interface LogWriter
        Throws:
        java.io.IOException
      • 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 interface LogWriter
        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.
        Specified by:
        position in interface LogWriter
        Throws:
        java.io.IOException
      • 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.
        Specified by:
        position in interface LogWriter
      • 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.
        Specified by:
        flush in interface LogWriter
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: LogWriter
        Close any held resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface LogWriter
        Throws:
        java.io.IOException
      • serializedSize

        public int serializedSize​(io.netty.buffer.ByteBuf buf)
        Specified by:
        serializedSize in interface LogWriter
        Returns:
        the number of bytes consumed by the buffer when written with #writeDelimited