K
- The type for the keysV
- The type for the stored valuespublic class PersistedBTree<K,V> extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
protected org.apache.directory.mavibot.btree.BTreeHeader |
btreeHeader
The Header for a managed BTree
|
protected net.sf.ehcache.Cache |
cache
The cache associated with this BTree
|
protected int |
cacheSize
The cache size, default to 1000 elements
|
protected ReentrantLock |
createTransaction
A lock to protect the creation of the transaction
|
protected ElementSerializer<K> |
keySerializer
The Key serializer used for this tree.
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
protected long |
readTimeOut
The read transaction timeout
|
protected ConcurrentLinkedQueue<ReadTransaction<K,V>> |
readTransactions
The list of read transactions being executed
|
protected Thread |
readTransactionsThread
The thread responsible for the cleanup of timed out reads
|
protected org.apache.directory.mavibot.btree.Page<K,V> |
rootPage
The current rootPage
|
protected ElementSerializer<V> |
valueSerializer
The Value serializer used for this tree.
|
protected int |
writeBufferSize
The size of the buffer used to write data in disk
|
protected ReentrantLock |
writeLock
A lock used to protect the write operation against concurrent access
|
protected org.apache.directory.mavibot.btree.WriteTransaction |
writeTransaction
The current transaction
|
ALLOW_DUPLICATES, DEFAULT_PAGE_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, FORBID_DUPLICATES
Modifier and Type | Method and Description |
---|---|
protected ReadTransaction<K,V> |
beginReadTransaction()
Starts a Read Only transaction.
|
void |
beginTransaction()
Starts a transaction
|
TupleCursor<K,V> |
browse()
Creates a cursor starting at the beginning of the tree
|
TupleCursor<K,V> |
browse(long revision)
Creates a cursor starting at the beginning of the tree, for a given revision
|
TupleCursor<K,V> |
browseFrom(K key)
Creates a cursor starting on the given key
|
TupleCursor<K,V> |
browseFrom(long revision,
K key)
Creates a cursor starting on the given key at the given revision
|
void |
close()
Close the BTree, cleaning up all the data structure
|
void |
commit()
Commits a transaction
|
boolean |
contains(K key,
V value)
Checks if the BTree contains the given key with the given value.
|
boolean |
contains(long revision,
K key,
V value)
Checks if the BTree contains the given key with the given value for a given revision
|
Tuple<K,V> |
delete(K key)
Delete the entry which key is given as a parameter.
|
Tuple<K,V> |
delete(K key,
V value)
Delete the value from an entry associated with the given key.
|
protected Tuple<K,V> |
delete(K key,
V value,
long revision)
Deletes the given
|
void |
flush()
Flush the latest revision to disk.
|
V |
get(K key)
Find a value in the tree, given its key.
|
V |
get(long revision,
K key)
Find a value in the tree, given its key, at a specific revision.
|
Comparator<K> |
getComparator() |
ElementSerializer<K> |
getKeySerializer() |
String |
getKeySerializerFQCN() |
String |
getName() |
long |
getNbElems() |
int |
getPageSize() |
long |
getReadTimeOut() |
long |
getRevision() |
org.apache.directory.mavibot.btree.Page<K,V> |
getRootPage()
Get the current rootPage
|
org.apache.directory.mavibot.btree.Page<K,V> |
getRootPage(long revision)
Get the rootPzge associated to a give revision.
|
BTreeTypeEnum |
getType() |
ValueCursor<V> |
getValues(K key) |
ElementSerializer<V> |
getValueSerializer() |
String |
getValueSerializerFQCN() |
int |
getWriteBufferSize() |
boolean |
hasKey(K key)
Checks if the given key exists.
|
boolean |
hasKey(long revision,
K key)
Checks if the given key exists for a given revision.
|
void |
init()
Initialize the BTree.
|
V |
insert(K key,
V value)
Insert an entry in the BTree.
|
boolean |
isAllowDuplicates() |
void |
rollback()
Rollback a transaction
|
void |
setAllowDuplicates(boolean allowDuplicates) |
void |
setKeySerializer(ElementSerializer<K> keySerializer) |
void |
setName(String name) |
void |
setPageSize(int pageSize)
Set the maximum number of elements we can store in a page.
|
void |
setReadTimeOut(long readTimeOut) |
void |
setType(BTreeTypeEnum type) |
void |
setValueSerializer(ElementSerializer<V> valueSerializer) |
void |
setWriteBufferSize(int writeBufferSize) |
String |
toString() |
protected static final org.slf4j.Logger LOG
protected net.sf.ehcache.Cache cache
protected int cacheSize
protected ReentrantLock createTransaction
protected long readTimeOut
protected org.apache.directory.mavibot.btree.BTreeHeader btreeHeader
protected volatile org.apache.directory.mavibot.btree.Page<K,V> rootPage
protected ElementSerializer<K> keySerializer
protected ElementSerializer<V> valueSerializer
protected ConcurrentLinkedQueue<ReadTransaction<K,V>> readTransactions
protected int writeBufferSize
protected ReentrantLock writeLock
protected Thread readTransactionsThread
protected org.apache.directory.mavibot.btree.WriteTransaction writeTransaction
public void init()
init
in interface BTree<K,V>
IOException
- If we get some exception while initializing the BTreepublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface BTree<K,V>
IOException
protected Tuple<K,V> delete(K key, V value, long revision) throws IOException
key
- The key to be removedvalue
- The value to be removed (can be null, and when no null value exists the key will be removed irrespective of the value)revision
- The revision to be associated with this operationIOException
public org.apache.directory.mavibot.btree.Page<K,V> getRootPage(long revision) throws IOException, KeyNotFoundException
getRootPage
in interface BTree<K,V>
revision
- The revision we are looking forIOException
- If we had an issue while accessing the underlying fileKeyNotFoundException
- If the revision does not exist for this Btreepublic void beginTransaction()
beginTransaction
in interface BTree<K,V>
public void rollback()
public String toString()
toString
in class Object
Object.toString()
protected ReadTransaction<K,V> beginReadTransaction()
public TupleCursor<K,V> browse() throws IOException
browse
in interface BTree<K,V>
IOException
public TupleCursor<K,V> browse(long revision) throws IOException, KeyNotFoundException
browse
in interface BTree<K,V>
revision
- The revision we would like to browseIOException
- If we had an issue while fetching data from the diskKeyNotFoundException
- If the key is not found in the BTreepublic TupleCursor<K,V> browseFrom(K key) throws IOException
browseFrom
in interface BTree<K,V>
key
- The key which is the starting point. If the key is not found,
then the cursor will always return null.IOException
public TupleCursor<K,V> browseFrom(long revision, K key) throws IOException, KeyNotFoundException
browseFrom
in interface BTree<K,V>
key
- The key which is the starting point. If the key is not found,
then the cursor will always return null.IOException
- If wxe had an issue reading the BTree from diskKeyNotFoundException
- If we can't find a rootPage for this revisionpublic boolean contains(K key, V value) throws IOException
contains
in interface BTree<K,V>
key
- The key we are looking forvalue
- The value associated with the given keyIOException
public boolean contains(long revision, K key, V value) throws IOException, KeyNotFoundException
contains
in interface BTree<K,V>
revision
- The revision we would like to browsekey
- The key we are looking forvalue
- The value associated with the given keyKeyNotFoundException
- If the key is not found in the BTreeIOException
public Tuple<K,V> delete(K key) throws IOException
delete
in interface BTree<K,V>
key
- The key for the entry we try to removeIOException
public Tuple<K,V> delete(K key, V value) throws IOException
delete
in interface BTree<K,V>
key
- The key for the entry we try to removevalue
- The value to delete (can be null)IOException
public V insert(K key, V value) throws IOException
We will replace the value if the provided key already exists in the btree.
insert
in interface BTree<K,V>
key
- Inserted keyvalue
- Inserted valueIOException
- TODOpublic void flush() throws IOException
flush
in interface BTree<K,V>
IOException
public V get(K key) throws IOException, KeyNotFoundException
get
in interface BTree<K,V>
key
- The key we are looking atIOException
- TODOKeyNotFoundException
- If the key is not found in the BTreepublic V get(long revision, K key) throws IOException, KeyNotFoundException
get
in interface BTree<K,V>
revision
- The revision for which we want to find a keykey
- The key we are looking atIOException
- If there was an issue while fetching data from the diskKeyNotFoundException
- If the key is not found in the BTreepublic org.apache.directory.mavibot.btree.Page<K,V> getRootPage()
getRootPage
in interface BTree<K,V>
public ValueCursor<V> getValues(K key) throws IOException, KeyNotFoundException
getValues
in interface BTree<K,V>
IOException
KeyNotFoundException
Page.getValues(Object)
public boolean hasKey(K key) throws IOException
hasKey
in interface BTree<K,V>
key
- The key we are looking atIOException
- If we have an error while trying to access the pagepublic boolean hasKey(long revision, K key) throws IOException, KeyNotFoundException
hasKey
in interface BTree<K,V>
revision
- The revision for which we want to find a keykey
- The key we are looking atIOException
- If we have an error while trying to access the pageKeyNotFoundException
- If the key is not found in the BTreepublic ElementSerializer<K> getKeySerializer()
getKeySerializer
in interface BTree<K,V>
public void setKeySerializer(ElementSerializer<K> keySerializer)
setKeySerializer
in interface BTree<K,V>
keySerializer
- the Key serializer to setpublic String getKeySerializerFQCN()
getKeySerializerFQCN
in interface BTree<K,V>
public ElementSerializer<V> getValueSerializer()
getValueSerializer
in interface BTree<K,V>
public void setValueSerializer(ElementSerializer<V> valueSerializer)
setValueSerializer
in interface BTree<K,V>
valueSerializer
- the Value serializer to setpublic String getValueSerializerFQCN()
getValueSerializerFQCN
in interface BTree<K,V>
public long getRevision()
getRevision
in interface BTree<K,V>
public long getReadTimeOut()
getReadTimeOut
in interface BTree<K,V>
public void setReadTimeOut(long readTimeOut)
setReadTimeOut
in interface BTree<K,V>
readTimeOut
- the readTimeOut to setpublic long getNbElems()
getNbElems
in interface BTree<K,V>
public int getPageSize()
getPageSize
in interface BTree<K,V>
public void setPageSize(int pageSize)
setPageSize
in interface BTree<K,V>
pageSize
- The requested page sizepublic void setName(String name)
public Comparator<K> getComparator()
getComparator
in interface BTree<K,V>
public int getWriteBufferSize()
getWriteBufferSize
in interface BTree<K,V>
public void setWriteBufferSize(int writeBufferSize)
setWriteBufferSize
in interface BTree<K,V>
writeBufferSize
- the writeBufferSize to setpublic boolean isAllowDuplicates()
isAllowDuplicates
in interface BTree<K,V>
public void setAllowDuplicates(boolean allowDuplicates)
setAllowDuplicates
in interface BTree<K,V>
allowDuplicates
- True if the BTree will allow duplicate valuespublic BTreeTypeEnum getType()
public void setType(BTreeTypeEnum type)
type
- the type to setCopyright © 2012-2014 Apache Mavibot Project Parent. All Rights Reserved.