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 boolean
delete()
Deletes this store from the file system.protected long
endOfDataAreaPointer()
Returns a pointer to the end of the current data area.boolean
exists()
Returns true if this store exists in the file system.protected void
internalClose()
Internally closes the backing area.protected void
internalOpen(boolean read_only)
Internally opens the backing area.void
lockForWrite()
It is often useful to guarentee that a certain sequence of updates to a store is completed and not broken in the middle.protected int
readByteArrayFrom(long position, byte[] buf, int off, int len)
Reads a byte array from the given position in the file.protected int
readByteFrom(long position)
Reads a byte from the given position in the file.protected void
setDataAreaSize(long new_size)
Sets the size of the data area.java.lang.String
toString()
void
unlockForWrite()
See the 'lockForWrite' method description.protected void
writeByteArrayTo(long position, byte[] buf, int off, int len)
Writes a byte array to the given position in the file.protected void
writeByteTo(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.IOException
Deletes 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.IOException
Returns true if this store exists in the file system.- Throws:
java.io.IOException
-
lockForWrite
public void lockForWrite()
Description copied from interface:Store
It 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:Store
See the 'lockForWrite' method description.
-
internalOpen
protected void internalOpen(boolean read_only) throws java.io.IOException
Internally opens the backing area. If 'read_only' is true then the store is opened in read only mode.- Specified by:
internalOpen
in classAbstractStore
- Throws:
java.io.IOException
-
internalClose
protected void internalClose() throws java.io.IOException
Internally closes the backing area.- Specified by:
internalClose
in classAbstractStore
- Throws:
java.io.IOException
-
readByteFrom
protected int readByteFrom(long position) throws java.io.IOException
Description copied from class:AbstractStore
Reads a byte from the given position in the file.- Specified by:
readByteFrom
in classAbstractStore
- Throws:
java.io.IOException
-
readByteArrayFrom
protected int readByteArrayFrom(long position, byte[] buf, int off, int len) throws java.io.IOException
Description copied from class:AbstractStore
Reads a byte array from the given position in the file. Returns the number of bytes read.- Specified by:
readByteArrayFrom
in classAbstractStore
- Throws:
java.io.IOException
-
writeByteTo
protected void writeByteTo(long position, int b) throws java.io.IOException
Description copied from class:AbstractStore
Writes a byte to the given position in the file.- Specified by:
writeByteTo
in classAbstractStore
- Throws:
java.io.IOException
-
writeByteArrayTo
protected void writeByteArrayTo(long position, byte[] buf, int off, int len) throws java.io.IOException
Description copied from class:AbstractStore
Writes a byte array to the given position in the file.- Specified by:
writeByteArrayTo
in classAbstractStore
- Throws:
java.io.IOException
-
endOfDataAreaPointer
protected long endOfDataAreaPointer() throws java.io.IOException
Description copied from class:AbstractStore
Returns a pointer to the end of the current data area.- Specified by:
endOfDataAreaPointer
in classAbstractStore
- Throws:
java.io.IOException
-
setDataAreaSize
protected void setDataAreaSize(long new_size) throws java.io.IOException
Description copied from class:AbstractStore
Sets the size of the data area.- Specified by:
setDataAreaSize
in classAbstractStore
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-