Class 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 Detail


        public static final int DEFAULT_PAGE_SIZE

        public static final int DEFAULT_WRITE_BATCH_SIZE

        public static final int DEFAULT_PAGE_CACHE_SIZE
    • Constructor Detail

      • PageFile

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

      • 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.
        IOException - if the files cannot be deleted.
        IllegalStateException - if this PageFile is loaded
      • load

        public void load()
                  throws IOException,
        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.
        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.
        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.
        IOException - If an disk error occurred.
      • 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.
        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()
        Are page writes synced to disk?
      • setEnableDiskSyncs

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

        public int getPageSize()
        the page size
      • getPageContentSize

        public int getPageContentSize()
        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.
        pageSize - the pageSize to set
        IllegalStateException - once the page file is loaded.
      • isEnablePageCaching

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

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

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

        public void setPageCacheSize​(int pageCacheSize)
        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)
      • isFreePage

        public boolean isFreePage​(long pageId)
      • getPageCount

        public long getPageCount()
        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)
      • getFile

        public File getFile()
      • getDirectory

        public File getDirectory()