Class PageFile
java.lang.Object
org.apache.activemq.store.kahadb.disk.page.PageFile
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 ClassesModifier and TypeClassDescriptionstatic classThe MetaData object hold the persistent data associated with a PageFile object. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidarchive()voiddelete()Deletes the files used by the PageFile object.voidflush()Flush and sync all write buffers to disk.voidfreePage(long pageId) longgetFile()longfloatintintlongintintintintbooleanbooleanbooleanbooleanbooleanIs the recovery buffer used to double buffer page writes.booleanisFreePage(long pageId) booleanisLoaded()booleanvoidload()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) toString()tx()voidunload()Unloads a previously loaded PageFile.
-
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
Creates a PageFile in the specified directory who's data files are named by name.
-
-
Method Details
-
tx
-
delete
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
- Throws:
IOException
-
load
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
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
Flush and sync all write buffers to disk.- Throws:
IOException- If an disk error occurred.
-
toString
-
getFreeFile
-
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
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
- 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
- Throws:
IOException
-
getFile
-
getDirectory
-