public class RecordManager extends AbstractTransactionManager
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PAGE_SIZE
The default page size
|
static boolean |
INTERNAL_BTREE
A flag used by internal btrees
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
protected static org.slf4j.Logger |
LOG_CHECK
A dedicated logger for the check
|
protected static org.slf4j.Logger |
LOG_PAGES
The LoggerFactory used by this class
|
AtomicLong |
nbCreatedPages |
AtomicLong |
nbFreedPages
Some counters to track the number of free pages
|
AtomicLong |
nbReusedPages |
AtomicLong |
nbUpdateBtreeHeader |
AtomicLong |
nbUpdatePageIOs |
AtomicLong |
nbUpdateRMHeader |
static long |
NO_PAGE
A constant for an offset on a non existing page
|
static boolean |
NORMAL_BTREE
A flag used by internal btrees
|
protected static org.slf4j.Logger |
TXN_LOG
The LoggerFactory used to trace TXN operations
|
Map<Long,Integer> |
writeCounter |
Constructor and Description |
---|
RecordManager(String fileName)
Create a Record manager which will either create the underlying file
or load an existing one.
|
RecordManager(String fileName,
int pageSize)
Create a Record manager which will either create the underlying file
or load an existing one.
|
Modifier and Type | Method and Description |
---|---|
<K,V> BTree<K,V> |
addBTree(String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
boolean allowDuplicates)
Creates a B-tree and automatically adds it to the list of managed btrees
|
void |
beginTransaction()
Starts a transaction
|
void |
close()
Close the RecordManager and flush everything on disk
|
void |
commit()
Commits a transaction
|
<K,V> org.apache.directory.mavibot.btree.Page<K,V> |
deserialize(BTree<K,V> btree,
long offset)
Deserialize a Page from a B-tree at a give position
|
void |
dump()
Dump the RecordManager file
|
static String |
dump(byte octet) |
org.apache.directory.mavibot.btree.BTreeHeader |
getBTreeHeader(String name)
Get the current BTreeHeader for a given Btree.
|
<K,V> BTree<K,V> |
getManagedTree(String name)
Get one managed trees, knowing its name.
|
Set<String> |
getManagedTrees()
Get the managed B-trees.
|
int |
getNbManagedTrees()
Get the number of managed trees.
|
org.apache.directory.mavibot.btree.BTreeHeader |
getNewBTreeHeader(String name)
Get the new BTreeHeader for a given Btree.
|
int |
getPageSize() |
boolean |
isContextOk() |
boolean |
isKeepRevisions() |
<K,V> void |
manage(BTree<K,V> btree)
Manage a B-tree.
|
<K,V> void |
manageSubBtree(BTree<K,V> btree)
Managing a btree is a matter of storing an reference to the managed B-tree in the B-tree Of B-trees.
|
void |
rollback()
Rollback a transaction
|
void |
setKeepRevisions(boolean keepRevisions) |
String |
toString() |
void |
updateNewBTreeHeaders(org.apache.directory.mavibot.btree.BTreeHeader btreeHeader)
Updates the map of new BTreeHeaders
|
void |
updateRecordManagerHeader()
Update the RecordManager header, injecting the following data :
|
void |
updateRecordManagerHeader(long newBtreeOfBtreesOffset,
long newCopiedPageBtreeOffset)
Update the RecordManager header, injecting the following data :
|
protected static final org.slf4j.Logger LOG
protected static final org.slf4j.Logger TXN_LOG
protected static final org.slf4j.Logger LOG_PAGES
protected static final org.slf4j.Logger LOG_CHECK
public AtomicLong nbFreedPages
public AtomicLong nbCreatedPages
public AtomicLong nbReusedPages
public AtomicLong nbUpdateRMHeader
public AtomicLong nbUpdateBtreeHeader
public AtomicLong nbUpdatePageIOs
public static final long NO_PAGE
public static final int DEFAULT_PAGE_SIZE
public static final boolean INTERNAL_BTREE
public static final boolean NORMAL_BTREE
public Map<Long,Integer> writeCounter
public RecordManager(String fileName)
name
- The file name, or a folder namepublic RecordManager(String fileName, int pageSize)
name
- The file name, or a folder namepageSize
- the size of a page on disk, in bytespublic void beginTransaction()
public void commit()
public boolean isContextOk()
public void rollback()
public <K,V> org.apache.directory.mavibot.btree.Page<K,V> deserialize(BTree<K,V> btree, long offset) throws EndOfFileExceededException, IOException
btree
- The B-tree we want to read a Page fromoffset
- The position in the file for this pageEndOfFileExceededException
- If we have reached the end of the file while reading the pageIOException
public <K,V> void manage(BTree<K,V> btree) throws BTreeAlreadyManagedException, IOException
btree
- The new B-tree to manage.treeType
- flag indicating if this is an internal treeBTreeAlreadyManagedException
- If the B-tree is already managedIOException
- if there was a problem while accessing the filepublic <K,V> void manageSubBtree(BTree<K,V> btree) throws BTreeAlreadyManagedException, IOException
btree
- The new B-tree to manage.treeType
- flag indicating if this is an internal treeBTreeAlreadyManagedException
- If the B-tree is already managedIOException
public void updateRecordManagerHeader()
+---------------------+ | PageSize | 4 bytes : The size of a physical page (default to 4096) +---------------------+ | NbTree | 4 bytes : The number of managed B-trees (at least 1) +---------------------+ | FirstFree | 8 bytes : The offset of the first free page +---------------------+ | current BoB offset | 8 bytes : The offset of the current B-tree of B-trees +---------------------+ | previous BoB offset | 8 bytes : The offset of the previous B-tree of B-trees +---------------------+ | current CP offset | 8 bytes : The offset of the current CopiedPages B-tree +---------------------+ | previous CP offset | 8 bytes : The offset of the previous CopiedPages B-tree +---------------------+
public void updateRecordManagerHeader(long newBtreeOfBtreesOffset, long newCopiedPageBtreeOffset)
+---------------------+ | PageSize | 4 bytes : The size of a physical page (default to 4096) +---------------------+ | NbTree | 4 bytes : The number of managed B-trees (at least 1) +---------------------+ | FirstFree | 8 bytes : The offset of the first free page +---------------------+ | current BoB offset | 8 bytes : The offset of the current B-tree of B-trees +---------------------+ | previous BoB offset | 8 bytes : The offset of the previous B-tree of B-trees +---------------------+ | current CP offset | 8 bytes : The offset of the current CopiedPages B-tree +---------------------+ | previous CP offset | 8 bytes : The offset of the previous CopiedPages B-tree +---------------------+
public int getPageSize()
public void close() throws IOException
IOException
public void dump()
IOException
public int getNbManagedTrees()
public Set<String> getManagedTrees()
public <K,V> BTree<K,V> getManagedTree(String name)
name
- The B-tree name we are looking forpublic boolean isKeepRevisions()
public void setKeepRevisions(boolean keepRevisions)
keepRevisions
- the keepRevisions flag to setpublic <K,V> BTree<K,V> addBTree(String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, boolean allowDuplicates) throws IOException, BTreeAlreadyManagedException
name
- the name of the B-treekeySerializer
- key serializervalueSerializer
- value serializerallowDuplicates
- flag for allowing duplicate keysIOException
- If we weren't able to update the file on diskBTreeAlreadyManagedException
- If the B-tree is already managedpublic org.apache.directory.mavibot.btree.BTreeHeader getBTreeHeader(String name)
name
- The Btree name we are looking the BtreeHeader forpublic org.apache.directory.mavibot.btree.BTreeHeader getNewBTreeHeader(String name)
public void updateNewBTreeHeaders(org.apache.directory.mavibot.btree.BTreeHeader btreeHeader)
btreeHeader
- The new BtreeHeaderpublic String toString()
toString
in class Object
Object.toString()
Copyright © 2012–2015 Apache Mavibot Project Parent. All rights reserved.