K - The type for the keysV - The type for the stored valuespublic class PersistedBTree<K,V> extends AbstractBTree<K,V> implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
private long |
btreeInfoOffset
The BtreeInfo offset
|
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
|
static int |
DEFAULT_CACHE_SIZE
The default number of pages to keep in memory
|
private static int |
DEFAULT_VALUE_THRESHOLD_LOW
The number of stored Values before we switch back to an array
|
private static int |
DEFAULT_VALUE_THRESHOLD_UP
The number of stored Values before we switch to a B-tree
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
protected static org.slf4j.Logger |
LOG_PAGES |
private RecordManager |
recordManager
The internal recordManager
|
(package private) static int |
valueThresholdLow |
(package private) static int |
valueThresholdUp
The configuration for the array <-> B-tree switch
|
allowDuplicates, btreeRevisions, btreeType, currentBtreeHeader, currentRevision, keySerializer, keySerializerFQCN, name, pageSize, readTimeOut, readTransactions, readTransactionsThread, transactionManager, transactionStarted, valueSerializer, valueSerializerFQCN, writeBufferSizeALLOW_DUPLICATES, DEFAULT_PAGE_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, FORBID_DUPLICATES| Constructor and Description |
|---|
PersistedBTree()
Creates a new BTree, with no initialization.
|
PersistedBTree(PersistedBTreeConfiguration<K,V> configuration)
Creates a new persisted B-tree using the BTreeConfiguration to initialize the
BTree
|
| 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.
|
void |
close()
Close the BTree, cleaning up all the data structure
|
(package private) Tuple<K,V> |
delete(K key,
V value,
long revision)
Deletes the given
|
private BTreeHeader<K,V> |
getBTreeHeader(java.lang.String name) |
long |
getBtreeInfoOffset() |
(package private) long |
getBtreeOffset() |
(package private) org.apache.commons.collections.map.LRUMap |
getCache()
Return the cache we use in this BTree
|
private BTreeHeader<K,V> |
getNewBTreeHeader(java.lang.String name) |
(package private) java.util.concurrent.ConcurrentLinkedQueue<ReadTransaction<K,V>> |
getReadTransactions()
Return the cache we use in this BTree
|
(package private) RecordManager |
getRecordManager()
Gets the RecordManager for a managed BTree
|
Page<K,V> |
getRootPage()
Get the current rootPage
|
Page<K,V> |
getRootPage(long revision)
Get the rootPzge associated to a give revision.
|
(package private) long |
getRootPageOffset() |
void |
init(BTree<K,V> parentBTree)
Initialize the BTree.
|
(package private) InsertResult<K,V> |
insert(K key,
V value,
long revision)
Insert an entry in the BTree.
|
private DeleteResult<K,V> |
processDelete(K key,
V value,
long revision)
Insert the tuple into the B-tree rootPage, get back the new rootPage
|
private InsertResult<K,V> |
processInsert(K key,
V value,
long revision)
Insert the tuple into the B-tree rootPage, get back the new rootPage
|
(package private) void |
setBtreeHeaderOffset(long btreeHeaderOffset) |
void |
setBtreeInfoOffset(long btreeInfoOffset) |
(package private) void |
setRecordManager(RecordManager recordManager)
Inject a RecordManager for a managed BTree
|
(package private) void |
setRootPage(Page<K,V> root) |
java.lang.String |
toString() |
private void |
writeBuffer(java.nio.channels.FileChannel channel,
java.nio.ByteBuffer bb,
byte[] buffer)
Write the data in the ByteBuffer, and eventually on disk if needed.
|
private PageHolder<K,V> |
writePage(Page<K,V> modifiedPage,
long revision)
Write a page either in the pending pages if the transaction is started,
or directly on disk.
|
browse, browse, browseFrom, browseFrom, browseKeys, contains, contains, createTransactionManager, delete, delete, delete, flush, get, get, getBtreeHeader, getBtreeHeader, getKeyComparator, getKeySerializer, getKeySerializerFQCN, getName, getNbElems, getPageSize, getReadTimeOut, getRevision, getType, getValueComparator, getValues, getValueSerializer, getValueSerializerFQCN, getWriteBufferSize, hasKey, hasKey, insert, isAllowDuplicates, setAllowDuplicates, setKeySerializer, setName, setNbElems, setPageSize, setReadTimeOut, setRevision, setType, setValueSerializer, setWriteBufferSize, storeRevision, storeRevisionprotected 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
private static final int DEFAULT_VALUE_THRESHOLD_UP
private static final int DEFAULT_VALUE_THRESHOLD_LOW
static int valueThresholdUp
static int valueThresholdLow
private long btreeInfoOffset
private RecordManager recordManager
PersistedBTree()
PersistedBTree(PersistedBTreeConfiguration<K,V> configuration)
configuration - The configuration to usepublic void init(BTree<K,V> parentBTree)
java.io.IOException - If we get some exception while initializing the BTreeorg.apache.commons.collections.map.LRUMap getCache()
java.util.concurrent.ConcurrentLinkedQueue<ReadTransaction<K,V>> getReadTransactions()
public void close()
throws java.io.IOException
long getBtreeOffset()
void setBtreeHeaderOffset(long btreeHeaderOffset)
btreeOffset - the B-tree header Offset to setlong getRootPageOffset()
RecordManager getRecordManager()
void setRecordManager(RecordManager recordManager)
recordManager - The injected RecordManagerTuple<K,V> delete(K key, V value, long revision) throws java.io.IOException
delete in class AbstractBTree<K,V>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 operationjava.io.IOExceptionprivate DeleteResult<K,V> processDelete(K key, V value, long revision) throws java.io.IOException
java.io.IOExceptionInsertResult<K,V> insert(K key, V value, long revision) throws java.io.IOException
We will replace the value if the provided key already exists in the btree.
The revision number is the revision to use to insert the data.
insert in class AbstractBTree<K,V>key - Inserted keyvalue - Inserted valuerevision - The revision to usejava.io.IOExceptionprivate BTreeHeader<K,V> getBTreeHeader(java.lang.String name)
private BTreeHeader<K,V> getNewBTreeHeader(java.lang.String name)
private InsertResult<K,V> processInsert(K key, V value, long revision) throws java.io.IOException
java.io.IOExceptionprivate void writeBuffer(java.nio.channels.FileChannel channel,
java.nio.ByteBuffer bb,
byte[] buffer)
throws java.io.IOException
channel - The channel we want to write tobb - The ByteBuffer we want to feedbuffer - The data to injectjava.io.IOException - If the write failedprivate PageHolder<K,V> writePage(Page<K,V> modifiedPage, long revision) throws java.io.IOException
java.io.IOExceptionpublic Page<K,V> getRootPage(long revision) throws java.io.IOException, KeyNotFoundException
getRootPage in interface BTree<K,V>revision - The revision we are looking forjava.io.IOException - If we had an issue while accessing the underlying fileKeyNotFoundException - If the revision does not exist for this Btreepublic Page<K,V> getRootPage()
getRootPage in interface BTree<K,V>getRootPage in class AbstractBTree<K,V>void setRootPage(Page<K,V> root)
AbstractBTreesetRootPage in class AbstractBTree<K,V>public long getBtreeInfoOffset()
public void setBtreeInfoOffset(long btreeInfoOffset)
btreeInfoOffset - the btreeInfoOffset to setprotected ReadTransaction<K,V> beginReadTransaction()
beginReadTransaction in class AbstractBTree<K,V>protected ReadTransaction<K,V> beginReadTransaction(long revision)
beginReadTransaction in class AbstractBTree<K,V>public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()