K - The type for the keysV - The type for the stored valuesclass InMemoryBTree<K,V> extends AbstractBTree<K,V> implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DATA_SUFFIX
The default data file suffix
|
static java.lang.String |
DEFAULT_JOURNAL
The default journal name
|
private java.io.File |
envDir
The directory where the journal will be stored
|
private java.io.File |
file
The associated file.
|
private java.io.File |
journal
The associated journal.
|
static java.lang.String |
JOURNAL_SUFFIX
The default journal file suffix
|
private java.nio.channels.FileChannel |
journalChannel
The Journal channel
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
private boolean |
withJournal
A flag used to tell the BTree that the journal is activated
|
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 |
|---|
InMemoryBTree()
Creates a new BTree, with no initialization.
|
InMemoryBTree(InMemoryBTreeConfiguration<K,V> configuration)
Creates a new in-memory BTree using the BTreeConfiguration to initialize the
BTree
|
| Modifier and Type | Method and Description |
|---|---|
private void |
applyJournal()
Inject all the modification from the journal into the btree
|
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
|
private BTreeHeader<K,V> |
createNewBtreeHeader(BTreeHeader<K,V> btreeHeader,
long revision)
Create a new B-tree header to be used for update operations
|
protected Tuple<K,V> |
delete(K key,
V value,
long revision)
Deletes the given
|
void |
flush()
Flush the latest revision to disk.
|
void |
flush(java.io.File file)
Flush the latest revision to disk
|
java.io.File |
getFile() |
java.io.File |
getJournal() |
Page<K,V> |
getRootPage()
Get the current rootPage
|
Page<K,V> |
getRootPage(long revision)
Get the rootPage associated to a give revision.
|
private void |
init()
Initialize the BTree.
|
(package private) InsertResult<K,V> |
insert(K key,
V value,
long revision)
Insert an entry in the BTree.
|
boolean |
isInMemory() |
boolean |
isPersistent() |
void |
load(java.io.File file)
Read the data from the disk into this BTree.
|
void |
setFilePath(java.lang.String filePath)
Set the file path where the journal will be stored
|
(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 void |
writeToJournal(Modification<K,V> modification) |
browse, browse, browseFrom, browseFrom, browseKeys, contains, contains, createTransactionManager, delete, delete, delete, 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
public static final java.lang.String DEFAULT_JOURNAL
public static final java.lang.String DATA_SUFFIX
public static final java.lang.String JOURNAL_SUFFIX
private java.io.File file
private boolean withJournal
private java.io.File journal
private java.io.File envDir
private java.nio.channels.FileChannel journalChannel
InMemoryBTree()
InMemoryBTree(InMemoryBTreeConfiguration<K,V> configuration)
configuration - The configuration to useprivate void init()
throws java.io.IOException
java.io.IOException - If we get some exception while initializing the BTreeprotected ReadTransaction<K,V> beginReadTransaction()
beginReadTransaction in class AbstractBTree<K,V>protected ReadTransaction<K,V> beginReadTransaction(long revision)
beginReadTransaction in class AbstractBTree<K,V>public void close()
throws java.io.IOException
protected Tuple<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.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 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 failedpublic void flush(java.io.File file)
throws java.io.IOException
file - The file into which the data will be writtenjava.io.IOExceptionprivate void applyJournal()
throws java.io.IOException
java.io.IOException - If we had some issue while reading the journalpublic void load(java.io.File file)
throws java.io.IOException
file - 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 void flush()
throws java.io.IOException
public java.io.File getFile()
public void setFilePath(java.lang.String filePath)
filePath - The file pathpublic java.io.File getJournal()
public boolean isInMemory()
public boolean isPersistent()
private void writeToJournal(Modification<K,V> modification) throws java.io.IOException
java.io.IOExceptionprivate BTreeHeader<K,V> createNewBtreeHeader(BTreeHeader<K,V> btreeHeader, long revision)
revision - The reclaimed revisionpublic java.lang.String toString()
toString in class java.lang.ObjectObject.toString()