Class SchemaPage

  • All Implemented Interfaces:
    ISchemaPage

    public class SchemaPage
    extends java.lang.Object
    implements ISchemaPage
    This class is aimed to manage space inside one page.

    A segment inside a page has 3 representation: index, offset and instance.

    • Index is meant to decouple file-wide indexing with in-page compaction
    • Offset is meant for in-page indexing
    • Segment instance is meant for records manipulations
    • Constructor Summary

      Constructors 
      Constructor Description
      SchemaPage​(java.nio.ByteBuffer buffer, int index, boolean override)
      This method will init page header for a blank page buffer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      short allocNewSegment​(short size)
      Allocate space for a new segment inside this page
      void deleteSegment​(short segId)  
      protected void extendsSegmentTo​(java.nio.ByteBuffer dstBuffer, short segId)  
      java.util.Queue<IMNode> getChildren​(short segId)  
      long getNextSegAddress​(short segId)  
      void getPageBuffer​(java.nio.ByteBuffer dst)  
      int getPageIndex()  
      long getPrevSegAddress​(short segId)  
      short getSegmentSize​(short segId)  
      Segment getSegmentTest​(short idx)  
      short getSpareSize()
      Calculated with accurate total segment size by examine segment buffers.
      This accuracy will save much space for schema file at the cost of more frequent rearrangement.
      boolean hasRecordKeyInSegment​(java.lang.String key, short segId)
      Check if record exists with name or alias.
      static ISchemaPage initPage​(java.nio.ByteBuffer buffer, int index)  
      java.lang.String inspect()
      Invoke all segments, translate into string, concatenate and return.
      boolean isCapableForSize​(short size)  
      boolean isSegmentCapableFor​(short segId, short size)  
      static ISchemaPage loadPage​(java.nio.ByteBuffer buffer, int index)  
      IMNode read​(short segIdx, java.lang.String key)  
      void removeRecord​(short segId, java.lang.String key)  
      void setNextSegAddress​(short segId, long address)  
      void setPrevSegAddress​(short segId, long address)  
      void syncPageBuffer()
      While segments are always synchronized with buffer pageBuffer, header and tail are not.
      long transplantSegment​(ISchemaPage srcPage, short segId, short newSegSize)
      Transplant designated segment from srcPage, to spare space of the page
      void update​(short segIdx, java.lang.String key, java.nio.ByteBuffer buffer)
      The record is definitely inside specified segment.
      protected void updateRecordSegAddr​(short segId, java.lang.String key, long newSegAddr)  
      long write​(short segIdx, java.lang.String key, java.nio.ByteBuffer buffer)
      Insert a content directly into specified segment, without considering preallocate and reallocate segment.
      • Methods inherited from class java.lang.Object

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

      • SchemaPage

        public SchemaPage​(java.nio.ByteBuffer buffer,
                          int index,
                          boolean override)
        This method will init page header for a blank page buffer.

        Page Header Structure:

        • 1 int (4 bytes): page index, a non-negative number
        • 1 short (2 bytes): pageSpareOffset, spare offset
        • 1 short (2 bytes): segNum, amount of the segment
        • 1 short (2 bytes): last deleted segment offset
        • 1 boolean (1 bytes): delete flag
        Page Structure:
    • fixed length: Page Header
    • var length: Segment
      ... spare space ...
    • var length: Segment Offset List, a sorted list of Short, length at 2*segNum