K - The Key typeV - The Value typeabstract class AbstractBTree<K,V> extends java.lang.Object implements BTree<K,V>
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
allowDuplicates
Flag to enable duplicate key support
|
protected java.util.Map<java.lang.Long,BTreeHeader<K,V>> |
btreeRevisions
The map of all the used BtreeHeaders
|
protected BTreeTypeEnum |
btreeType
The BTree type : either in-memory, disk backed or persisted
|
protected BTreeHeader<K,V> |
currentBtreeHeader
The current Header for a managed BTree
|
protected java.util.concurrent.atomic.AtomicLong |
currentRevision
The current revision
|
protected ElementSerializer<K> |
keySerializer
The Key serializer used for this tree.
|
protected java.lang.String |
keySerializerFQCN
The FQCN of the Key serializer
|
protected java.lang.String |
name
The BTree name
|
protected int |
pageSize
The number of elements in a page for this B-tree
|
protected long |
readTimeOut
The read transaction timeout
|
protected java.util.concurrent.ConcurrentLinkedQueue<ReadTransaction<K,V>> |
readTransactions
The list of read transactions being executed
|
protected java.lang.Thread |
readTransactionsThread
The thread responsible for the cleanup of timed out reads
|
protected TransactionManager |
transactionManager
The TransactionManager used for this BTree
|
protected java.util.concurrent.atomic.AtomicBoolean |
transactionStarted
The current transaction
|
protected ElementSerializer<V> |
valueSerializer
The Value serializer used for this tree.
|
protected java.lang.String |
valueSerializerFQCN
The FQCN of the Value serializer
|
protected int |
writeBufferSize
The size of the buffer used to write data in disk
|
ALLOW_DUPLICATES, DEFAULT_PAGE_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, FORBID_DUPLICATES| Constructor and Description |
|---|
AbstractBTree() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract ReadTransaction<K,V> |
beginReadTransaction()
Starts a Read Only transaction.
|
protected abstract ReadTransaction<K,V> |
beginReadTransaction(long revision)
Starts a Read Only 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
|
KeyCursor<K> |
browseKeys()
Creates a cursor starting at the beginning of the tree
|
boolean |
contains(K key,
V value)
Checks if the B-tree contains the given key with the given value.
|
boolean |
contains(long revision,
K key,
V value)
Checks if the B-tree contains the given key with the given value for a given revision
|
(package private) void |
createTransactionManager()
Create a thread that is responsible of cleaning the transactions when
they hit the timeout
|
Tuple<K,V> |
delete(K key)
Delete the entry which key is given as a parameter.
|
(package private) Tuple<K,V> |
delete(K key,
long revision)
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.
|
(package private) abstract Tuple<K,V> |
delete(K key,
V value,
long revision) |
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.
|
protected BTreeHeader<K,V> |
getBtreeHeader() |
protected BTreeHeader<K,V> |
getBtreeHeader(long revision) |
java.util.Comparator<K> |
getKeyComparator() |
ElementSerializer<K> |
getKeySerializer() |
java.lang.String |
getKeySerializerFQCN() |
java.lang.String |
getName() |
long |
getNbElems() |
int |
getPageSize() |
private int |
getPowerOf2(int size)
Gets the number which is a power of 2 immediately above the given positive number.
|
long |
getReadTimeOut() |
long |
getRevision() |
abstract Page<K,V> |
getRootPage()
Get the current rootPage
|
BTreeTypeEnum |
getType() |
java.util.Comparator<V> |
getValueComparator() |
ValueCursor<V> |
getValues(K key) |
ElementSerializer<V> |
getValueSerializer() |
java.lang.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.
|
V |
insert(K key,
V value)
Insert an entry in the B-tree.
|
(package private) abstract InsertResult<K,V> |
insert(K key,
V value,
long revision) |
boolean |
isAllowDuplicates() |
void |
setAllowDuplicates(boolean allowDuplicates) |
void |
setKeySerializer(ElementSerializer<K> keySerializer) |
void |
setName(java.lang.String name) |
(package private) void |
setNbElems(long nbElems) |
void |
setPageSize(int pageSize)
Set the maximum number of elements we can store in a page.
|
void |
setReadTimeOut(long readTimeOut) |
(package private) void |
setRevision(long revision) |
(package private) abstract void |
setRootPage(Page<K,V> root) |
void |
setType(BTreeTypeEnum type) |
void |
setValueSerializer(ElementSerializer<V> valueSerializer) |
void |
setWriteBufferSize(int writeBufferSize) |
protected void |
storeRevision(BTreeHeader<K,V> btreeHeader)
Store the new revision in the map of btrees, increment the current revision
|
protected void |
storeRevision(BTreeHeader<K,V> btreeHeader,
boolean keepRevisions)
Store the new revision in the map of btrees, increment the current revision
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclose, getRootPageprotected long readTimeOut
protected BTreeHeader<K,V> currentBtreeHeader
protected ElementSerializer<K> keySerializer
protected ElementSerializer<V> valueSerializer
protected java.util.concurrent.ConcurrentLinkedQueue<ReadTransaction<K,V>> readTransactions
protected int writeBufferSize
protected boolean allowDuplicates
protected int pageSize
protected java.lang.String name
protected java.lang.String keySerializerFQCN
protected java.lang.String valueSerializerFQCN
protected java.lang.Thread readTransactionsThread
protected BTreeTypeEnum btreeType
protected java.util.concurrent.atomic.AtomicBoolean transactionStarted
protected java.util.Map<java.lang.Long,BTreeHeader<K,V>> btreeRevisions
protected java.util.concurrent.atomic.AtomicLong currentRevision
protected TransactionManager transactionManager
protected abstract ReadTransaction<K,V> beginReadTransaction()
protected abstract ReadTransaction<K,V> beginReadTransaction(long revision)
public TupleCursor<K,V> browse() throws java.io.IOException, KeyNotFoundException
browse in interface BTree<K,V>java.io.IOExceptionKeyNotFoundExceptionpublic TupleCursor<K,V> browse(long revision) throws java.io.IOException, KeyNotFoundException
browse in interface BTree<K,V>revision - The revision we would like to browsejava.io.IOException - If we had an issue while fetching data from the diskKeyNotFoundException - If the key is not found in the B-treepublic TupleCursor<K,V> browseFrom(K key) throws java.io.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.java.io.IOExceptionpublic TupleCursor<K,V> browseFrom(long revision, K key) throws java.io.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.java.io.IOException - If wxe had an issue reading the B-tree from diskKeyNotFoundException - If we can't find a rootPage for this revisionpublic boolean contains(K key, V value) throws java.io.IOException
public boolean contains(long revision,
K key,
V value)
throws java.io.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 B-treejava.io.IOExceptionpublic Tuple<K,V> delete(K key) throws java.io.IOException
public Tuple<K,V> delete(K key, V value) throws java.io.IOException
Tuple<K,V> delete(K key, long revision) throws java.io.IOException
key - The key for the entry we try to removejava.io.IOExceptionabstract Tuple<K,V> delete(K key, V value, long revision) throws java.io.IOException
java.io.IOExceptionpublic V insert(K key, V value) throws java.io.IOException
We will replace the value if the provided key already exists in the B-tree.
abstract InsertResult<K,V> insert(K key, V value, long revision) throws java.io.IOException
java.io.IOExceptionpublic void flush()
throws java.io.IOException
public V get(K key) throws java.io.IOException, KeyNotFoundException
get in interface BTree<K,V>key - The key we are looking atjava.io.IOException - TODOKeyNotFoundException - If the key is not found in the B-treepublic V get(long revision, K key) throws java.io.IOException, KeyNotFoundException
get in interface BTree<K,V>revision - The revision for which we want to find a keykey - The key we are looking atjava.io.IOException - If there was an issue while fetching data from the diskKeyNotFoundException - If the key is not found in the B-treepublic abstract Page<K,V> getRootPage()
getRootPage in interface BTree<K,V>public ValueCursor<V> getValues(K key) throws java.io.IOException, KeyNotFoundException
getValues in interface BTree<K,V>java.io.IOExceptionKeyNotFoundExceptionPage.getValues(Object)public boolean hasKey(K key) throws java.io.IOException, KeyNotFoundException
hasKey in interface BTree<K,V>key - The key we are looking atjava.io.IOException - If we have an error while trying to access the pageKeyNotFoundException - If the key is not found in the B-treepublic boolean hasKey(long revision,
K key)
throws java.io.IOException,
KeyNotFoundException
hasKey in interface BTree<K,V>revision - The revision for which we want to find a keykey - The key we are looking atjava.io.IOException - If we have an error while trying to access the pageKeyNotFoundException - If the key is not found in the B-treepublic 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 java.lang.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 java.lang.String getValueSerializerFQCN()
getValueSerializerFQCN in interface BTree<K,V>public long getRevision()
getRevision in interface BTree<K,V>void setRevision(long revision)
protected void storeRevision(BTreeHeader<K,V> btreeHeader, boolean keepRevisions)
protected void storeRevision(BTreeHeader<K,V> btreeHeader)
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>void setNbElems(long nbElems)
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 java.lang.String getName()
public void setName(java.lang.String name)
public java.util.Comparator<K> getKeyComparator()
getKeyComparator in interface BTree<K,V>public java.util.Comparator<V> getValueComparator()
getValueComparator 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 B-tree will allow duplicate valuespublic BTreeTypeEnum getType()
public void setType(BTreeTypeEnum type)
type - the type to setprivate int getPowerOf2(int size)
protected BTreeHeader<K,V> getBtreeHeader()
protected BTreeHeader<K,V> getBtreeHeader(long revision)
public KeyCursor<K> browseKeys() throws java.io.IOException, KeyNotFoundException
browseKeys in interface BTree<K,V>java.io.IOExceptionKeyNotFoundExceptionvoid createTransactionManager()