Package com.mckoi.store
Class JournalledFileStore
- java.lang.Object
-
- com.mckoi.store.AbstractStore
-
- com.mckoi.store.JournalledFileStore
-
- All Implemented Interfaces:
Store
public final class JournalledFileStore extends AbstractStore
An implementation of AbstractStore that persists to an underlying data format via a robust journalling system that supports check point and crash recovery. Note that this object is a bridge between the Store API and the journalled behaviour defined in LoggingBufferManager, JournalledSystem and the StoreDataAccessor implementations.Note that access to the resources is abstracted via a 'resource_name' string. The LoggingBufferManager object converts the resource name into a concrete object that accesses the actual data.
- Author:
- Tobias Downer
-
-
Field Summary
-
Fields inherited from class com.mckoi.store.AbstractStore
BIN_AREA_OFFSET, BIN_ENTRIES, DATA_AREA_OFFSET, FIXED_AREA_OFFSET, free_bin_list, header_buf, MAGIC, read_only, total_allocated_space, wilderness_pointer
-
-
Constructor Summary
Constructors Constructor Description JournalledFileStore(java.lang.String resource_name, LoggingBufferManager buffer_manager, boolean read_only)Constructs the ScatteringFileStore.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete()Deletes this store from the file system.protected longendOfDataAreaPointer()Returns a pointer to the end of the current data area.booleanexists()Returns true if this store exists in the file system.protected voidinternalClose()Internally closes the backing area.protected voidinternalOpen(boolean read_only)Internally opens the backing area.voidlockForWrite()It is often useful to guarentee that a certain sequence of updates to a store is completed and not broken in the middle.protected intreadByteArrayFrom(long position, byte[] buf, int off, int len)Reads a byte array from the given position in the file.protected intreadByteFrom(long position)Reads a byte from the given position in the file.protected voidsetDataAreaSize(long new_size)Sets the size of the data area.java.lang.StringtoString()voidunlockForWrite()See the 'lockForWrite' method description.protected voidwriteByteArrayTo(long position, byte[] buf, int off, int len)Writes a byte array to the given position in the file.protected voidwriteByteTo(long position, int b)Writes a byte to the given position in the file.-
Methods inherited from class com.mckoi.store.AbstractStore
checkPointer, close, coalescArea, createArea, deleteArea, expandDataArea, findAllocatedAreasNotIn, getAllAreas, getArea, getAreaHeader, getAreaInputStream, getMutableArea, getNextAreaHeader, getPreviousAreaHeader, isValidBoundarySize, lastCloseClean, open, openScanAndFix, readBins, reboundArea, splitArea, statsScan, totalAllocatedSinceStart, writeAllBins, writeBinIndex
-
-
-
-
Constructor Detail
-
JournalledFileStore
public JournalledFileStore(java.lang.String resource_name, LoggingBufferManager buffer_manager, boolean read_only)Constructs the ScatteringFileStore.
-
-
Method Detail
-
delete
public boolean delete() throws java.io.IOExceptionDeletes this store from the file system. This operation should only be used when the store is NOT open.- Throws:
java.io.IOException
-
exists
public boolean exists() throws java.io.IOExceptionReturns true if this store exists in the file system.- Throws:
java.io.IOException
-
lockForWrite
public void lockForWrite()
Description copied from interface:StoreIt is often useful to guarentee that a certain sequence of updates to a store is completed and not broken in the middle. For example, when inserting data into a table you don't want a record to be partially written when a check point is made. You want the entire sequence of modifications to be completed before the check point can run. This means that if a crash occurs, a check point will not recover to a possible corrupt file.To achieve this, the 'lockForWrite' and 'unlockForWrite' methods are available. When 'lockForWrite' has been called, a check point can not created until there are no write locks obtained on the table.
-
unlockForWrite
public void unlockForWrite()
Description copied from interface:StoreSee the 'lockForWrite' method description.
-
internalOpen
protected void internalOpen(boolean read_only) throws java.io.IOExceptionInternally opens the backing area. If 'read_only' is true then the store is opened in read only mode.- Specified by:
internalOpenin classAbstractStore- Throws:
java.io.IOException
-
internalClose
protected void internalClose() throws java.io.IOExceptionInternally closes the backing area.- Specified by:
internalClosein classAbstractStore- Throws:
java.io.IOException
-
readByteFrom
protected int readByteFrom(long position) throws java.io.IOExceptionDescription copied from class:AbstractStoreReads a byte from the given position in the file.- Specified by:
readByteFromin classAbstractStore- Throws:
java.io.IOException
-
readByteArrayFrom
protected int readByteArrayFrom(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from class:AbstractStoreReads a byte array from the given position in the file. Returns the number of bytes read.- Specified by:
readByteArrayFromin classAbstractStore- Throws:
java.io.IOException
-
writeByteTo
protected void writeByteTo(long position, int b) throws java.io.IOExceptionDescription copied from class:AbstractStoreWrites a byte to the given position in the file.- Specified by:
writeByteToin classAbstractStore- Throws:
java.io.IOException
-
writeByteArrayTo
protected void writeByteArrayTo(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from class:AbstractStoreWrites a byte array to the given position in the file.- Specified by:
writeByteArrayToin classAbstractStore- Throws:
java.io.IOException
-
endOfDataAreaPointer
protected long endOfDataAreaPointer() throws java.io.IOExceptionDescription copied from class:AbstractStoreReturns a pointer to the end of the current data area.- Specified by:
endOfDataAreaPointerin classAbstractStore- Throws:
java.io.IOException
-
setDataAreaSize
protected void setDataAreaSize(long new_size) throws java.io.IOExceptionDescription copied from class:AbstractStoreSets the size of the data area.- Specified by:
setDataAreaSizein classAbstractStore- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-