Documentation of 'org.apache.derby.impl.store.raw.log.LogAccessFile' Java class
LogAccessFile
org.apache.derby.impl.store.raw.log

Class LogAccessFile



  • public class LogAccessFile
    extends java.lang.Object
    Wraps a RandomAccessFile file to provide buffering on log writes. Only supports the write calls required for the log! MT - unsafe. Caller of this class must provide synchronization. The one exception is with the log file access, LogAccessFile will touch the log only inside synchronized block protected by the semaphore, which is defined by the creator of this object. Write to the log buffers are allowed when there are free buffers even when dirty buffers are being written(flushed) to the disk by a different thread. Only one flush writes to log file at a time, other wait for it to finish. Except for flushLogAccessFile , SyncAccessLogFile other function callers must provide syncronization that will allow only one of them to write to the buffers. Log Buffers are used in circular fashion, each buffer moves through following stages: freeBuffers --> dirtyBuffers --> freeBuffers. Movement of buffers from one stage to another stage is synchronized using the object(this) of this class. A Checksum log record that has the checksum value for the data that is being written to the disk is generated and written before the actual data. Except for the large log records that does not fit into a single buffer, checksum is calcualted for a group of log records that are in the buffer when buffers is switched. Checksum log record is written into the reserved space in the beginning buffer. In case of a large log record that does not fit into a buffer, the checksum is written to the byte[] allocated for the big log record. Checksum log records helps in identifying the incomplete log disk writes during recovery. This is done by recalculating the checksum value for the data on the disk and comparing it to the the value stored in the checksum log record.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void close() 
      void corrupt()
      The database is being marked corrupted, get rid of file pointer without writing out anything more.
      void flushLogAccessFile() 
      int getChecksumLogRecordSize()
      Return the length of a checksum record
      void switchLogBuffer()
      Appends the current Buffer to the dirty Buffer list and assigns a free buffer to be the currrent active buffer .
      void syncLogAccessFile()
      Guarantee all writes up to the last call to flushLogAccessFile on disk.
      void write(byte[] b, int off, int len) 
      void write(int b) 
      void writeInt(int i) 
      void writeLogRecord(int length, long instant, byte[] data, int data_offset, byte[] optional_data, int optional_data_offset, int optional_data_length)
      Write a single log record to the stream.
      void writeLong(long l) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • writeLogRecord

        public void writeLogRecord(int length,
                                   long instant,
                                   byte[] data,
                                   int data_offset,
                                   byte[] optional_data,
                                   int optional_data_offset,
                                   int optional_data_length)
                            throws StandardException,
                                   java.io.IOException
        Write a single log record to the stream.

        For performance pass all parameters rather into a specialized routine rather than maintaining the writeInt, writeLong, and write interfaces that this class provides as a standard OutputStream. It will make it harder to use other OutputStream implementations, but makes for less function calls and allows optimizations knowing when to switch buffers.

        This routine handles all log records which are smaller than one log buffer. If a log record is bigger than a log buffer it calls writeUnbufferedLogRecord().

        The log record written will always look the same as if the following code had been executed: writeInt(length) writeLong(instant) write(data, data_offset, (length - optional_data_length) ) if (optional_data_length != 0) write(optional_data, optional_data_offset, optional_data_length) writeInt(length)

        Parameters:
        length - (data + optional_data) length bytes to write
        instant - the log address of this log record.
        data - "from" array to copy "data" portion of rec
        data_offset - offset in "data" to start copying from.
        optional_data - "from" array to copy "optional data" from
        optional_data_offset - offset in "optional_data" to start copy from
        optional_data_length - length of optional data to copy.
        Throws:
        StandardException - Standard exception policy.
        java.io.IOException
      • writeInt

        public void writeInt(int i)
      • writeLong

        public void writeLong(long l)
      • write

        public void write(int b)
      • write

        public void write(byte[] b,
                          int off,
                          int len)
      • switchLogBuffer

        public void switchLogBuffer()
                             throws java.io.IOException,
                                    StandardException
        Appends the current Buffer to the dirty Buffer list and assigns a free buffer to be the currrent active buffer . Flushing of the buffer to disk is delayed if there is a free buffer available. dirty buffers will be flushed to the disk when flushDirtyBuffers() is invoked by a commit call or when no more free buffers are available.
        Throws:
        java.io.IOException
        StandardException
      • syncLogAccessFile

        public void syncLogAccessFile()
                               throws java.io.IOException,
                                      StandardException
        Guarantee all writes up to the last call to flushLogAccessFile on disk.

        A call for clients of LogAccessFile to insure that all data written up to the last call to flushLogAccessFile() are written to disk. This call will not return until those writes have hit disk.

        Note that this routine may block waiting for I/O to complete so callers should limit the number of resource held locked while this operation is called. It is expected that the caller Note that this routine only "writes" the data to the file, this does not mean that the data has been synced to disk. The only way to insure that is to first call switchLogBuffer() and then follow by a call of sync().

        Throws:
        java.io.IOException
        StandardException
      • corrupt

        public void corrupt()
                     throws java.io.IOException
        The database is being marked corrupted, get rid of file pointer without writing out anything more.
        Throws:
        java.io.IOException
      • getChecksumLogRecordSize

        public int getChecksumLogRecordSize()
        Return the length of a checksum record

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.