Class SpilloverPageArray

java.lang.Object
org.cojen.tupl.io.PageArray
org.cojen.tupl.io.SpilloverPageArray
All Implemented Interfaces:
Closeable, AutoCloseable, CauseCloseable

public class SpilloverPageArray extends PageArray
Combines PageArrays together in a sequential fashion. This is useful for supporting overflow capacity when the first array fills up. In an emergency when all drives are full, a spillover page array can be defined such that the second array is a remote file, or a non-durable file, or an anonymous MappedPageArray. With this configuration in place, delete non-essential entries and then compact the database. After verifying that space is available again, the original page array configuration can be swapped back in.
  • Method Details

    • factory

      public static Supplier<PageArray> factory(Supplier<? extends PageArray> first, long spilloverIndex, Supplier<? extends PageArray> second)
      Parameters:
      first - source for all pages lower than the spillover index
      spilloverIndex - index which separates the two sources
      second - source for all pages at or higher than the spillover index
      Throws:
      IllegalArgumentException - if page sizes don't match or if spillover index isn't greater than 0
      IllegalStateException - if the highest index of the first source is higher than the spillover index
    • make

      public static PageArray make(PageArray first, long spilloverIndex, PageArray second) throws IOException
      Parameters:
      first - source for all pages lower than the spillover index
      spilloverIndex - index which separates the two sources
      second - source for all pages at or higher than the spillover index
      Throws:
      IllegalArgumentException - if page sizes don't match or if spillover index isn't greater than 0
      IllegalStateException - if the highest index of the first source is higher than the spillover index
      IOException
    • directPageSize

      public final int directPageSize()
      Description copied from class: PageArray
      Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.
      Overrides:
      directPageSize in class PageArray
    • isReadOnly

      public boolean isReadOnly()
      Specified by:
      isReadOnly in class PageArray
    • isFullyMapped

      public boolean isFullyMapped()
      Overrides:
      isFullyMapped in class PageArray
    • isEmpty

      public boolean isEmpty() throws IOException
      Specified by:
      isEmpty in class PageArray
      Throws:
      IOException
    • pageCount

      public long pageCount() throws IOException
      Description copied from class: PageArray
      Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.
      Specified by:
      pageCount in class PageArray
      Throws:
      IOException
    • truncatePageCount

      public void truncatePageCount(long count) throws IOException
      Description copied from class: PageArray
      Attempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.
      Specified by:
      truncatePageCount in class PageArray
      Throws:
      IOException
    • expandPageCount

      public void expandPageCount(long count) throws IOException
      Description copied from class: PageArray
      Attempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.
      Specified by:
      expandPageCount in class PageArray
      Throws:
      IOException
    • pageCountLimit

      public long pageCountLimit() throws IOException
      Description copied from class: PageArray
      Return maximum allowed page count, or -1 if not applicable.
      Overrides:
      pageCountLimit in class PageArray
      Throws:
      IOException
    • readPage

      public void readPage(long index, long dstAddr, int offset, int length) throws IOException
      Specified by:
      readPage in class PageArray
      Parameters:
      index - zero-based page index to read
      dstAddr - receives read data
      offset - offset into data buffer
      Throws:
      IOException - if index is greater than or equal to page count
    • writePage

      public void writePage(long index, long srcAddr, int offset) throws IOException
      Description copied from class: PageArray
      Writes a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.
      Specified by:
      writePage in class PageArray
      Parameters:
      index - zero-based page index to write
      srcAddr - data to write
      offset - offset into data buffer
      Throws:
      IOException
    • evictPage

      public long evictPage(long index, long bufAddr) throws IOException
      Description copied from class: PageArray
      Same as writePage, except that the given buffer might be altered and a replacement might be returned. Caller must not alter the original buffer if a replacement was provided, and the contents of the replacement are undefined.
      Overrides:
      evictPage in class PageArray
      Parameters:
      index - zero-based page index to write
      bufAddr - data to write; implementation might alter the contents
      Returns:
      replacement buffer, or same instance if replacement was not performed
      Throws:
      IOException
    • directPageAddress

      public long directPageAddress(long index) throws IOException
      Overrides:
      directPageAddress in class PageArray
      Throws:
      IOException
    • copyPage

      public long copyPage(long srcIndex, long dstIndex) throws IOException
      Overrides:
      copyPage in class PageArray
      Returns:
      direct pointer to destination
      Throws:
      IOException
    • copyPageFromAddress

      public long copyPageFromAddress(long srcAddr, long dstIndex) throws IOException
      Overrides:
      copyPageFromAddress in class PageArray
      Returns:
      direct pointer to destination
      Throws:
      IOException
    • sync

      public void sync(boolean metadata) throws IOException
      Description copied from class: PageArray
      Durably flushes all writes to the underlying device.
      Specified by:
      sync in class PageArray
      Parameters:
      metadata - pass true to flush all file metadata
      Throws:
      IOException
    • syncPage

      public void syncPage(long index) throws IOException
      Description copied from class: PageArray
      Durably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.
      Overrides:
      syncPage in class PageArray
      Throws:
      IOException
    • close

      public void close(Throwable cause) throws IOException
      Specified by:
      close in interface CauseCloseable
      Specified by:
      close in class PageArray
      Parameters:
      cause - null if close is not caused by a failure
      Throws:
      IOException
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in class PageArray