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 boolean |
allowDuplicates
Flag to enable duplicate key support
|
protected Map<Long,org.apache.directory.mavibot.btree.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 org.apache.commons.collections.map.LRUMap |
cache
The cache associated with this B-tree
|
protected int |
cacheSize
The cache size, default to 1000 elements
|
protected org.apache.directory.mavibot.btree.BTreeHeader<K,V> |
currentBtreeHeader
The current Header for a managed BTree
|
protected AtomicLong |
currentRevision
The current revision
|
static int |
DEFAULT_CACHE_SIZE
The default number of pages to keep in memory
|
protected ElementSerializer<K> |
keySerializer
The Key serializer used for this tree.
|
protected String |
keySerializerFQCN
The FQCN of the Key serializer
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
protected static org.slf4j.Logger |
LOG_PAGES |
protected 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 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 TransactionManager |
transactionManager
The TransactionManager used for this BTree
|
protected AtomicBoolean |
transactionStarted
The current transaction
|
protected ElementSerializer<V> |
valueSerializer
The Value serializer used for this tree.
|
protected 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
Modifier and Type | Method and Description |
---|---|
protected ReadTransaction<K,V> |
beginReadTransaction()
Starts a Read Only transaction.
|
protected 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
|
void |
close()
Close the BTree, cleaning up all the data structure
|
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
|
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.
|
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 org.apache.directory.mavibot.btree.BTreeHeader<K,V> |
getBtreeHeader() |
protected org.apache.directory.mavibot.btree.BTreeHeader<K,V> |
getBtreeHeader(long revision) |
long |
getBtreeInfoOffset() |
Comparator<K> |
getKeyComparator() |
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() |
Comparator<V> |
getValueComparator() |
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(BTree<K,V> parentBTree)
Initialize the BTree.
|
V |
insert(K key,
V value)
Insert an entry in the B-tree.
|
boolean |
isAllowDuplicates() |
void |
setAllowDuplicates(boolean allowDuplicates) |
void |
setBtreeInfoOffset(long btreeInfoOffset) |
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) |
protected void |
storeRevision(org.apache.directory.mavibot.btree.BTreeHeader<K,V> btreeHeader)
Store the new revision in the map of btrees, increment the current revision
|
protected void |
storeRevision(org.apache.directory.mavibot.btree.BTreeHeader<K,V> btreeHeader,
boolean keepRevisions)
Store the new revision in the map of btrees, increment the current revision
|
String |
toString() |
protected static final org.slf4j.Logger LOG
protected static final org.slf4j.Logger LOG_PAGES
protected org.apache.commons.collections.map.LRUMap cache
public static final int DEFAULT_CACHE_SIZE
protected int cacheSize
protected long readTimeOut
protected org.apache.directory.mavibot.btree.BTreeHeader<K,V> currentBtreeHeader
protected ElementSerializer<K> keySerializer
protected ElementSerializer<V> valueSerializer
protected ConcurrentLinkedQueue<ReadTransaction<K,V>> readTransactions
protected int writeBufferSize
protected boolean allowDuplicates
protected int pageSize
protected String keySerializerFQCN
protected String valueSerializerFQCN
protected Thread readTransactionsThread
protected BTreeTypeEnum btreeType
protected AtomicBoolean transactionStarted
protected Map<Long,org.apache.directory.mavibot.btree.BTreeHeader<K,V>> btreeRevisions
protected AtomicLong currentRevision
protected TransactionManager transactionManager
public void init(BTree<K,V> parentBTree)
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
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 org.apache.directory.mavibot.btree.Page<K,V> getRootPage()
getRootPage
in interface BTree<K,V>
public long getBtreeInfoOffset()
public void setBtreeInfoOffset(long btreeInfoOffset)
btreeInfoOffset
- the btreeInfoOffset to setprotected ReadTransaction<K,V> beginReadTransaction()
protected ReadTransaction<K,V> beginReadTransaction(long revision)
public String toString()
toString
in class Object
Object.toString()
public TupleCursor<K,V> browse() throws IOException, KeyNotFoundException
browse
in interface BTree<K,V>
IOException
KeyNotFoundException
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 B-treepublic 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 B-tree 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 B-treeIOException
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 B-tree.
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 B-treepublic 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 B-treepublic 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, KeyNotFoundException
hasKey
in interface BTree<K,V>
key
- 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 B-treepublic 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 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 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>
protected void storeRevision(org.apache.directory.mavibot.btree.BTreeHeader<K,V> btreeHeader, boolean keepRevisions)
protected void storeRevision(org.apache.directory.mavibot.btree.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>
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 Comparator<K> getKeyComparator()
getKeyComparator
in interface BTree<K,V>
public 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 setprotected org.apache.directory.mavibot.btree.BTreeHeader<K,V> getBtreeHeader()
protected org.apache.directory.mavibot.btree.BTreeHeader<K,V> getBtreeHeader(long revision)
public KeyCursor<K> browseKeys() throws IOException, KeyNotFoundException
browseKeys
in interface BTree<K,V>
IOException
KeyNotFoundException
Copyright © 2012–2015 Apache Mavibot Project Parent. All rights reserved.