Class PageArray

java.lang.Object
org.cojen.tupl.io.PageArray
All Implemented Interfaces:
Closeable, AutoCloseable, CauseCloseable
Direct Known Subclasses:
FilePageArray, MappedPageArray, SpilloverPageArray, StripedPageArray

public abstract class PageArray extends Object implements CauseCloseable
Defines a persistent, array of fixed sized pages. Each page is uniquely identified by a 64-bit index, starting at zero.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    PageArray(int pageSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    abstract void
     
    long
    copyPage(long srcIndex, long dstIndex)
     
    long
    copyPageFromAddress(long srcAddr, long dstIndex)
     
    long
    directPageAddress(long index)
     
    int
    Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.
    long
    dirtyPage(long index)
    Indicate that the contents of the given page will be modified.
    long
    evictPage(long index, long bufAddr)
    Same as writePage, except that the given buffer might be altered and a replacement might be returned.
    abstract void
    expandPageCount(long count)
    Attempt to expand the total count of pages.
    abstract boolean
     
    final boolean
     
    abstract boolean
     
    boolean
     
    abstract boolean
     
    abstract long
    Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.
    long
    Return maximum allowed page count, or -1 if not applicable.
    final int
    Returns the fixed size of all pages in the array, in bytes.
    void
    readPage(long index, long dstAddr)
     
    abstract void
    readPage(long index, long dstAddr, int offset, int length)
     
    abstract void
    sync(boolean metadata)
    Durably flushes all writes to the underlying device.
    void
    syncPage(long index)
    Durably flushes the page at the given index, but implementation might flush more pages.
    abstract void
    truncatePageCount(long count)
    Attempt to truncate the total count of pages.
    void
    writePage(long index, long srcAddr)
    Writes a page, which is lazily flushed.
    abstract void
    writePage(long index, long srcAddr, int offset)
    Writes a page, which is lazily flushed.

    Methods inherited from class java.lang.Object

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

    • PageArray

      protected PageArray(int pageSize)
  • Method Details

    • isDirectIO

      public final boolean isDirectIO()
    • pageSize

      public final int pageSize()
      Returns the fixed size of all pages in the array, in bytes.
    • directPageSize

      public int directPageSize()
      Returns a positive page size if not using direct I/O, else negate to get the page size to allocate for direct I/O.
    • isFullyMapped

      public boolean isFullyMapped()
    • isReadOnly

      public abstract boolean isReadOnly()
    • isEmpty

      public abstract boolean isEmpty() throws IOException
      Throws:
      IOException
    • pageCount

      public abstract long pageCount() throws IOException
      Returns the total count of pages in the array, or Long.MAX_VALUE if not applicable.
      Throws:
      IOException
    • truncatePageCount

      public abstract void truncatePageCount(long count) throws IOException
      Attempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.
      Throws:
      IllegalArgumentException - if count is negative
      IOException
    • expandPageCount

      public abstract void expandPageCount(long count) throws IOException
      Attempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.
      Throws:
      IllegalArgumentException - if count is negative
      IOException
    • pageCountLimit

      public long pageCountLimit() throws IOException
      Return maximum allowed page count, or -1 if not applicable.
      Throws:
      IOException
    • readPage

      public void readPage(long index, long dstAddr) throws IOException
      Parameters:
      index - zero-based page index to read
      dstAddr - receives read data
      Throws:
      IndexOutOfBoundsException - if index is negative
      IOException - if index is greater than or equal to page count
    • readPage

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

      public void writePage(long index, long srcAddr) throws IOException
      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.
      Parameters:
      index - zero-based page index to write
      srcAddr - data to write
      Throws:
      IndexOutOfBoundsException - if index is negative
      IOException
    • writePage

      public abstract void writePage(long index, long srcAddr, int offset) throws IOException
      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.
      Parameters:
      index - zero-based page index to write
      srcAddr - data to write
      offset - offset into data buffer
      Throws:
      IndexOutOfBoundsException - if index is negative
      IOException
    • evictPage

      public long evictPage(long index, long bufAddr) throws IOException
      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.
      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:
      IndexOutOfBoundsException - if index is negative
      IOException
    • directPageAddress

      public long directPageAddress(long index) throws IOException
      Throws:
      IOException
    • dirtyPage

      public long dirtyPage(long index) throws IOException
      Indicate that the contents of the given page will be modified. Permits the implementation to make a copy of the existing page contents, if it supports snapshotting.
      Returns:
      direct pointer to destination
      Throws:
      IOException
    • copyPage

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

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

      public abstract void sync(boolean metadata) throws IOException
      Durably flushes all writes to the underlying device.
      Parameters:
      metadata - pass true to flush all file metadata
      Throws:
      IOException
    • syncPage

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

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • close

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

      public abstract boolean isClosed()