Class LogWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ILogWriter
    Direct Known Subclasses:
    CheckpointWriter, WALWriter

    public abstract class LogWriter
    extends java.lang.Object
    implements ILogWriter
    LogWriter writes the binary logs into a file, including writing WALEntry into .wal file and writing Checkpoint into .checkpoint file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.nio.channels.FileChannel logChannel  
      protected java.io.File logFile  
      protected java.io.FileOutputStream logStream  
      protected long size  
    • Constructor Summary

      Constructors 
      Constructor Description
      LogWriter​(java.io.File logFile)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void force()
      Forces any updates to this file to be written to the storage device that contains it.
      void force​(boolean metaData)
      Forces any updates to this file to be written to the storage device that contains it.
      java.io.File getLogFile()
      Gets the log file
      long size()
      Returns the current size of this file.
      void write​(java.nio.ByteBuffer buffer)
      Write given logs to a persistent medium.
      • Methods inherited from class java.lang.Object

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

      • logFile

        protected final java.io.File logFile
      • logStream

        protected final java.io.FileOutputStream logStream
      • logChannel

        protected final java.nio.channels.FileChannel logChannel
      • size

        protected long size
    • Constructor Detail

      • LogWriter

        public LogWriter​(java.io.File logFile)
                  throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • write

        public void write​(java.nio.ByteBuffer buffer)
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        Write given logs to a persistent medium. NOTICE: the logs may be cached in the storage device, if the storage device you are using do not guarantee strong persistence, and you want the logs to be persisted immediately, please call ILogWriter.force() after calling this method. Notice: do not flip the buffer before calling this method
        Specified by:
        write in interface ILogWriter
        Parameters:
        buffer - content that have been converted to bytes
        Throws:
        java.io.IOException - if an I/O error occurs
      • force

        public void force()
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        Forces any updates to this file to be written to the storage device that contains it.
        Specified by:
        force in interface ILogWriter
        Throws:
        java.io.IOException - if an I/O error occurs
      • force

        public void force​(boolean metaData)
                   throws java.io.IOException
        Description copied from interface: ILogWriter
        Forces any updates to this file to be written to the storage device that contains it.
        Specified by:
        force in interface ILogWriter
        Parameters:
        metaData - 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 needs only force content changes to be written
        Throws:
        java.io.IOException - if an I/O error occurs
      • size

        public long size()
        Description copied from interface: ILogWriter
        Returns the current size of this file.
        Specified by:
        size in interface ILogWriter
        Returns:
        size
      • getLogFile

        public java.io.File getLogFile()
        Description copied from interface: ILogWriter
        Gets the log file
        Specified by:
        getLogFile in interface ILogWriter
        Returns:
        log file
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException