Class PageFile
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPageFile.MetaDataThe MetaData object hold the persistent data associated with a PageFile object.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_PAGE_CACHE_SIZEstatic intDEFAULT_PAGE_SIZEstatic intDEFAULT_WRITE_BATCH_SIZE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallowIOResumption()voidarchive()voiddelete()Deletes the files used by the PageFile object.voidflush()Flush and sync all write buffers to disk.voidfreePage(long pageId)FilegetDirectory()longgetDiskSize()FilegetFile()FilegetFreeFile()longgetFreePageCount()floatgetLFUEvictionFactor()intgetPageCacheSize()intgetPageContentSize()longgetPageCount()intgetPageSize()FilegetRecoveryFile()intgetRecoveryFileMaxPageCount()intgetRecoveryFileMinPageCount()intgetWriteBatchSize()booleanisCleanShutdown()booleanisEnableDiskSyncs()booleanisEnabledWriteThread()booleanisEnablePageCaching()booleanisEnableRecoveryFile()Is the recovery buffer used to double buffer page writes.booleanisFreePage(long pageId)booleanisLoaded()booleanisUseLFRUEviction()voidload()Loads the page file so that it can be accessed for read/write purposes.voidremoveTmpFile(File file, RandomAccessFile randomAccessFile)voidsetEnableDiskSyncs(boolean syncWrites)Allows you enable syncing writes to disk.voidsetEnablePageCaching(boolean enablePageCaching)voidsetEnableRecoveryFile(boolean doubleBuffer)Sets if the recovery buffer uses to double buffer page writes.voidsetEnableWriteThread(boolean enableAsyncWrites)voidsetLFUEvictionFactor(float LFUEvictionFactor)voidsetPageCacheSize(int pageCacheSize)voidsetPageSize(int pageSize)Configures the page size used by the page file.voidsetRecoveryFileMaxPageCount(int recoveryFileMaxPageCount)voidsetRecoveryFileMinPageCount(int recoveryFileMinPageCount)voidsetUseLFRUEviction(boolean useLFRUEviction)voidsetWriteBatchSize(int writeBatchSize)longtoOffset(long pageId)StringtoString()Transactiontx()voidunload()Unloads a previously loaded PageFile.
-
-
-
Method Detail
-
tx
public Transaction tx()
-
delete
public void delete() throws IOExceptionDeletes 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, IllegalStateExceptionLoads 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 IOExceptionUnloads 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 IOExceptionFlush and sync all write buffers to disk.- Throws:
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.- 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 IllegalStateExceptionConfigures 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()
-
-