public class BtreeDatabase extends java.lang.Object implements SinglevaluedIndex, MDRCache.OverflowHandler
The data file, with an extension of ".btd", which contains the serialized versions of the Streamable objects. This is accessed via the BtreeDatafile class.
The index file, with an extension of ".btx", which translates MOFIDs to the corresponding offset in the data file. This is accessed via the SinglevaluedBtree class.
The transactional log file has the extnsion ".btb". It exists only between the time a trasaction starts to be comitted and the time it is fully comitted or rolled back.
The data file contains enough information to regenerate the index file if the index file is lost or damaged. If the index file is missing when the btree database is opened, it is silently regenerated.
A Btree storage is transactional. This is implemented using the logging feature of the FileCache. Objects stored in a Btree storage have identity in memory. That is, fetching the same object multiple times will result in multiple references to the same object, not mutilple copies. This is implemented by MDRCache.
Performance of the Btree can be tuned by adjusting these parameters:
PAGE_SIZE is the size of the pages in the file cache.
FILE_CACHE_SIZE in the number of pages cached in memory. Increasing this will minimize the amount of reading done from the btree files, though at the cost of decreased memory for other purposes.
MDR_CACHE_SIZE is the number of currently unreferenced persistent objects kept in memory. Increasing this will reduce the number of reads done from the btree storage, though again at the cost of decreased memory for other purposes.
MDR_CACHE_THRESHHOLD is the number of changed objects to keep in memory before saving them to disk. Increasing this will reduce the amount of disk I/O done, though yet again at the cost of decreased memory for other purposes.
| Modifier and Type | Method and Description |
|---|---|
void |
add(MOFID mKey,
java.lang.Object value)
Adds a repository record, throwing an exception if it already exists
|
void |
add(java.lang.Object key,
java.lang.Object value)
Adds a repository record, throwing an exception if it already exists
|
void |
cacheThreshholdReached(MDRCache cach,
int size)
cache has reached threshhold
|
int |
checkConsistency(java.io.PrintWriter strm)
Check consistency of btree database
|
void |
commitChanges()
Commits changes to transaction cache,
if cache treshold is reached, flushes cache to disk.
|
void |
compress()
Compress repository.
|
java.lang.Object |
get(MOFID mKey)
Gets a record from the repository.
|
java.lang.Object |
get(java.lang.Object key)
Gets a record from the repository.
|
java.lang.Object |
getIfExists(MOFID mKey)
Gets a record from the repository.
|
java.lang.Object |
getIfExists(java.lang.Object key)
Gets a record from the repository.
|
Storage.EntryType |
getKeyType()
Returns the type of keys in index.
|
MofidGenerator |
getMofidGenerator()
Return the MOFID generator for this repository
|
java.util.Map |
getMofidMap()
Return the map of MOFID UUIDs we know about
|
java.lang.String |
getName()
Returns the unique name of the index in the Storage.
|
java.lang.Object |
getObject(java.lang.Object key,
SinglevaluedIndex dummy)
Like get, since we don't return keys
|
java.lang.Object |
getObjectIfExists(java.lang.Object key,
SinglevaluedIndex dummy)
Like getIfExists, since we don't return keys
|
Storage.EntryType |
getValueType()
Returns the type of values indexed by this index.
|
java.util.Set |
keySet()
Returns a set view of the keys contained in this index.
|
java.lang.String[] |
listIndexes()
List all index names
|
void |
objectStateChanged(MOFID mKey)
Mark that the object has changed, and so needs to be saved on commit
|
void |
objectStateChanged(java.lang.Object key)
Mark that the object has changed, and so needs to be saved on commit
|
boolean |
put(java.lang.Object key,
java.lang.Object value)
Adds or replaces a repository record
|
java.util.Collection |
queryByKeyPrefix(java.lang.Object prefix,
SinglevaluedIndex repos)
Returns a collection view of
Map.Entry key-value pairs in the index,
where key matches the queried prefix. |
boolean |
remove(MOFID mKey)
Deletes a repository record based on a MOFID
|
boolean |
remove(java.lang.Object key)
Deletes a repository record
|
void |
replace(MOFID mKey,
java.lang.Object value)
Replaces the original value associated with the specified key in this
index with new value.
|
void |
replace(java.lang.Object key,
java.lang.Object value)
Replaces the original value associated with the specified key in this
index with new value.
|
void |
rollbackChanges()
roll back all changes
|
void |
saveChanges()
save all changes to disk without comitting
|
void |
setLoggingStream(java.io.PrintStream strm)
Set our logging stream
|
void |
shutDown()
Called on exit, commited data cached in transaction cache need to be written to disk.
|
int |
size()
returns the number of objects in the repository
|
java.util.Collection |
values()
Returns a collection view of the values contained in the repository.
|
public void compress()
throws StorageException
StorageExceptionpublic int size()
public java.lang.String getName()
public Storage.EntryType getValueType()
getValueType in interface Indexpublic Storage.EntryType getKeyType()
getKeyType in interface Indexpublic void cacheThreshholdReached(MDRCache cach, int size) throws StorageException
cacheThreshholdReached in interface MDRCache.OverflowHandlercach - cache which reached threshholdsize - number of changed objects currently in cacheStorageExceptionpublic void commitChanges()
throws StorageException
StorageExceptionpublic void shutDown()
throws StorageException
StorageExceptionpublic void saveChanges()
throws StorageException
StorageExceptionpublic void rollbackChanges()
throws StorageException
StorageExceptionpublic boolean remove(java.lang.Object key)
throws StorageException
remove in interface Indexkey - -- a StringStorageExceptionpublic boolean remove(MOFID mKey) throws StorageException
mKey - StorageExceptionpublic void add(java.lang.Object key,
java.lang.Object value)
throws StorageException
add in interface Indexkey - -- a Stringvalue - StorageExceptionpublic void add(MOFID mKey, java.lang.Object value) throws StorageException
mKey - value - StorageExceptionpublic void replace(java.lang.Object key,
java.lang.Object value)
throws StorageException
replace in interface SinglevaluedIndexkey - value - StorageExceptionStorageBadRequestExceptionpublic void replace(MOFID mKey, java.lang.Object value) throws StorageException
mKey - value - StorageExceptionpublic boolean put(java.lang.Object key,
java.lang.Object value)
throws StorageException
put in interface SinglevaluedIndexkey - -- a Stringvalue - StorageExceptionpublic java.lang.Object getIfExists(java.lang.Object key)
throws StorageException
getIfExists in interface SinglevaluedIndexkey - -- a StringStorageExceptionpublic java.lang.Object getObjectIfExists(java.lang.Object key,
SinglevaluedIndex dummy)
throws StorageException
getObjectIfExists in interface SinglevaluedIndexStorageExceptionpublic java.lang.Object getIfExists(MOFID mKey) throws StorageException
key - StorageExceptionpublic java.lang.Object get(java.lang.Object key)
throws StorageException
get in interface SinglevaluedIndexkey - StorageExceptionStorageBadRequestExceptionpublic java.lang.Object getObject(java.lang.Object key,
SinglevaluedIndex dummy)
throws StorageException
getObject in interface SinglevaluedIndexStorageExceptionpublic java.lang.Object get(MOFID mKey) throws StorageException
mKey - StorageExceptionpublic java.util.Collection queryByKeyPrefix(java.lang.Object prefix,
SinglevaluedIndex repos)
SinglevaluedIndexMap.Entry key-value pairs in the index,
where key matches the queried prefix. Values are objects (as returned by getObject
method).queryByKeyPrefix in interface SinglevaluedIndexprefix - queried prefixrepos - primary indexpublic void objectStateChanged(java.lang.Object key)
throws StorageException
key - key of object whch changed (a String)StorageExceptionpublic void objectStateChanged(MOFID mKey) throws StorageException
mKey - key of object whch changedStorageExceptionpublic java.lang.String[] listIndexes()
throws StorageException
StorageExceptionpublic java.util.Set keySet()
throws StorageException
keySet in interface IndexStorageExceptionpublic java.util.Collection values()
throws StorageException
values in interface SinglevaluedIndexStorageExceptionpublic void setLoggingStream(java.io.PrintStream strm)
public MofidGenerator getMofidGenerator()
public java.util.Map getMofidMap()
public int checkConsistency(java.io.PrintWriter strm)
throws StorageException
strm - where to write inconsistenciesStorageExceptionCopyright © 2005-2012 Apache Software Foundation. All Rights Reserved.