Class LogBufferElement


  • class LogBufferElement
    extends java.lang.Object
    ReplicationLogBuffer consists of n LogBufferElements, each of which can store a number of log records in a single byte[].

    The format of each log record in the LogBufferElement is the same as is written to log file in LogAccessFile:
    (int) total_length (data[].length + optionaldata[].length)
    (long) instant
    (byte[]) data+optionaldata
    (int) total_length

    In addition to adding a chunk of log records to the byte[], the greatestInstant variable is updated for every append so that getLastInstant can be used to get the highest log instant in this LogBufferElement.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected LogBufferElement​(int bufferSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int appendBytes​(byte[] b, int offset, int pos, int length)
      Append a byte[] to this LogBufferElement.
      protected void appendLog​(long greatestInstant, byte[] log, int logOffset, int logLength)
      Append a chunk of log records to this LogBufferElement.
      protected int freeSize()  
      protected byte[] getData()  
      protected long getLastInstant()  
      protected void init()
      Resets all variables to default values.
      protected boolean isRecyclable()  
      protected void setRecyclable​(boolean r)  
      protected int size()  
      • Methods inherited from class java.lang.Object

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

      • bufferdata

        private final byte[] bufferdata
      • position

        private int position
      • greatestInstant

        private long greatestInstant
      • recycleMe

        private boolean recycleMe
    • Constructor Detail

      • LogBufferElement

        protected LogBufferElement​(int bufferSize)
    • Method Detail

      • init

        protected void init()
        Resets all variables to default values. Should be called before a LogBufferElement is reused.
      • appendLog

        protected void appendLog​(long greatestInstant,
                                 byte[] log,
                                 int logOffset,
                                 int logLength)
        Append a chunk of log records to this LogBufferElement.
        Parameters:
        greatestInstant - the instant of the log record that was added last to this chunk of log
        log - the chunk of log records
        logOffset - offset in log to start copy from
        logLength - number of bytes to copy, starting from logOffset
      • getData

        protected byte[] getData()
        Returns:
        A byte[] representation of the log records appended to this LogBufferElement
      • getLastInstant

        protected long getLastInstant()
        Returns:
        The highest log instant appended to this LogBufferElement
      • freeSize

        protected int freeSize()
        Returns:
        Number of unused bytes in this LogBufferElement
      • size

        protected int size()
        Returns:
        Number of used bytes in this LogBufferElement
      • isRecyclable

        protected boolean isRecyclable()
        Returns:
        true if this LogBufferElement should be reused, i.e. added to freeBuffers after being consumed.
      • setRecyclable

        protected void setRecyclable​(boolean r)
      • appendBytes

        private int appendBytes​(byte[] b,
                                int offset,
                                int pos,
                                int length)
        Append a byte[] to this LogBufferElement.
        Parameters:
        b - where the bytes are copied from
        offset - offset in b to start copying from
        pos - the position in this LogBufferElement to start copying to
        length - number of bytes to copy from b, starting from offset
        Returns:
        new position