java.lang.Object
org.apache.activemq.store.kahadb.disk.page.PageFile

public class PageFile extends Object
A PageFile provides you random access to fixed sized disk pages. This object is not thread safe and therefore access to it should be externally synchronized.

The file has 3 parts: Metadata Space: 4k : Reserved metadata area. Used to store persistent config about the file. Recovery Buffer Space: Page Size * 1000 : This is a redo log used to prevent partial page writes from making the file inconsistent Page Space: The pages in the page file.

  • Field Details

    • DEFAULT_PAGE_SIZE

      public static final int DEFAULT_PAGE_SIZE
    • DEFAULT_WRITE_BATCH_SIZE

      public static final int DEFAULT_WRITE_BATCH_SIZE
    • DEFAULT_PAGE_CACHE_SIZE

      public static final int DEFAULT_PAGE_CACHE_SIZE
  • Constructor Details

    • PageFile

      public PageFile(File directory, String name)
      Creates a PageFile in the specified directory who's data files are named by name.
  • Method Details

    • tx

      public Transaction tx()
    • delete

      public void delete() throws IOException
      Deletes the files used by the PageFile object. This method can only be used when this object is not loaded.
      Throws:
      IOException - if the files cannot be deleted.
      IllegalStateException - if this PageFile is loaded
    • archive

      public void archive() throws IOException
      Throws:
      IOException
    • load

      public void load() throws IOException, IllegalStateException
      Loads the page file so that it can be accessed for read/write purposes. This allocates OS resources. If this is the first time the page file is loaded, then this creates the page file in the file system.
      Throws:
      IOException - If the page file cannot be loaded. This could be cause the existing page file is corrupt is a bad version or if there was a disk error.
      IllegalStateException - If the page file was already loaded.
    • unload

      public void unload() throws IOException
      Unloads a previously loaded PageFile. This deallocates OS related resources like file handles. once unloaded, you can no longer use the page file to read or write Pages.
      Throws:
      IOException - if there was a disk error occurred while closing the down the page file.
      IllegalStateException - if the PageFile is not loaded
    • isLoaded

      public boolean isLoaded()
    • isCleanShutdown

      public boolean isCleanShutdown()
    • allowIOResumption

      public void allowIOResumption()
    • flush

      public void flush() throws IOException
      Flush and sync all write buffers to disk.
      Throws:
      IOException - If an disk error occurred.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getFreeFile

      public File getFreeFile()
    • getRecoveryFile

      public File getRecoveryFile()
    • toOffset

      public long toOffset(long pageId)
    • isEnableRecoveryFile

      public boolean isEnableRecoveryFile()
      Is the recovery buffer used to double buffer page writes. Enabled by default.
      Returns:
      is the recovery buffer enabled.
    • setEnableRecoveryFile

      public void setEnableRecoveryFile(boolean doubleBuffer)
      Sets if the recovery buffer uses to double buffer page writes. Enabled by default. Disabling this may potentially cause partial page writes which can lead to page file corruption.
    • isEnableDiskSyncs

      public boolean isEnableDiskSyncs()
      Returns:
      Are page writes synced to disk?
    • setEnableDiskSyncs

      public void setEnableDiskSyncs(boolean syncWrites)
      Allows you enable syncing writes to disk.
    • getPageSize

      public int getPageSize()
      Returns:
      the page size
    • getPageContentSize

      public int getPageContentSize()
      Returns:
      the amount of content data that a page can hold.
    • setPageSize

      public void setPageSize(int pageSize) throws IllegalStateException
      Configures the page size used by the page file. By default it is 4k. Once a page file is created on disk, subsequent loads of that file will use the original pageSize. Once the PageFile is loaded, this setting can no longer be changed.
      Parameters:
      pageSize - the pageSize to set
      Throws:
      IllegalStateException - once the page file is loaded.
    • isEnablePageCaching

      public boolean isEnablePageCaching()
      Returns:
      true if read page caching is enabled
    • setEnablePageCaching

      public void setEnablePageCaching(boolean enablePageCaching)
      Parameters:
      enablePageCaching - allows you to enable read page caching
    • getPageCacheSize

      public int getPageCacheSize()
      Returns:
      the maximum number of pages that will get stored in the read page cache.
    • setPageCacheSize

      public void setPageCacheSize(int pageCacheSize)
      Parameters:
      pageCacheSize - Sets the maximum number of pages that will get stored in the read page cache.
    • isEnabledWriteThread

      public boolean isEnabledWriteThread()
    • setEnableWriteThread

      public void setEnableWriteThread(boolean enableAsyncWrites)
    • getDiskSize

      public long getDiskSize() throws IOException
      Throws:
      IOException
    • isFreePage

      public boolean isFreePage(long pageId)
    • getPageCount

      public long getPageCount()
      Returns:
      the number of pages allocated in the PageFile
    • getRecoveryFileMinPageCount

      public int getRecoveryFileMinPageCount()
    • getFreePageCount

      public long getFreePageCount()
    • setRecoveryFileMinPageCount

      public void setRecoveryFileMinPageCount(int recoveryFileMinPageCount)
    • getRecoveryFileMaxPageCount

      public int getRecoveryFileMaxPageCount()
    • setRecoveryFileMaxPageCount

      public void setRecoveryFileMaxPageCount(int recoveryFileMaxPageCount)
    • getWriteBatchSize

      public int getWriteBatchSize()
    • setWriteBatchSize

      public void setWriteBatchSize(int writeBatchSize)
    • getLFUEvictionFactor

      public float getLFUEvictionFactor()
    • setLFUEvictionFactor

      public void setLFUEvictionFactor(float LFUEvictionFactor)
    • isUseLFRUEviction

      public boolean isUseLFRUEviction()
    • setUseLFRUEviction

      public void setUseLFRUEviction(boolean useLFRUEviction)
    • freePage

      public void freePage(long pageId)
    • removeTmpFile

      public void removeTmpFile(File file, RandomAccessFile randomAccessFile) throws IOException
      Throws:
      IOException
    • getFile

      public File getFile()
    • getDirectory

      public File getDirectory()