public class RecordManager extends AbstractTransactionManager
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<PageIO> |
allocatedPages
The list of PageIO that can be freed after a roolback
|
(package private) static java.lang.String |
BTREE_OF_BTREES_NAME
The B-tree of B-trees management btree name
|
private java.util.concurrent.locks.ReadWriteLock |
btreeHeadersLock
A lock to protect the BtreeHeader maps
|
(package private) BTree<NameRevision,java.lang.Long> |
btreeOfBtrees
The B-tree of B-trees
|
private static int |
BYTE_SIZE
Some constants
|
private java.util.Queue<RevisionName> |
closedTransactionsQueue
The queue of recently closed transactions
|
private int |
commitCount
variable to keep track of the write commit count
|
private static java.lang.ThreadLocal<java.lang.Integer> |
context
A ThreadLocalStorage used to store the current transaction
|
(package private) static java.lang.String |
COPIED_PAGE_BTREE_NAME
The CopiedPages management btree name
|
(package private) BTree<RevisionName,long[]> |
copiedPageBtree
A B-tree used to manage the page that has been copied in a new version.
|
private java.util.Map<java.lang.String,BTreeHeader<?,?>> |
currentBTreeHeaders
A Map keeping the latest revisions for each managed BTree
|
(package private) long |
currentBtreeOfBtreesOffset
The current B-tree of B-trees header offset
|
(package private) long |
currentCopiedPagesBtreeOffset
The offset on the current copied pages B-tree
|
private static java.lang.String |
DEFAULT_FILE_NAME
The default file name
|
static int |
DEFAULT_PAGE_SIZE
The default page size
|
private boolean |
disableReclaimer |
private long |
endOfFileOffset
The offset of the end of the file
|
private java.io.File |
file
The associated file
|
(package private) java.nio.channels.FileChannel |
fileChannel
The channel used to read and write data
|
(package private) long |
firstFreePage
The first and last free page
|
(package private) java.util.List<PageIO> |
freedPages
The list of PageIO that can be freed after a commit
|
private java.util.concurrent.locks.ReentrantLock |
freePageLock
A lock to protect the freepage pointers
|
private static byte[] |
HEX_CHAR
Hex chars
|
(package private) static int |
INT_SIZE |
static boolean |
INTERNAL_BTREE
A flag used by internal btrees
|
private boolean |
keepRevisions
A flag set to true if we want to keep old revisions
|
private static int |
LINK_SIZE
The size of the link to next page
|
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
|
private byte[] |
LONG_LENGTH
The length of an Offset, as a negative value
|
(package private) static int |
LONG_SIZE |
private java.util.Map<java.lang.String,BTree<java.lang.Object,java.lang.Object>> |
managedBtrees
The set of managed B-trees
|
private static int |
MIN_PAGE_SIZE
The minimal page size.
|
(package private) int |
nbBtree
The number of managed B-trees
|
java.util.concurrent.atomic.AtomicLong |
nbCreatedPages |
java.util.concurrent.atomic.AtomicLong |
nbFreedPages
Some counters to track the number of free pages
|
java.util.concurrent.atomic.AtomicLong |
nbReusedPages |
java.util.concurrent.atomic.AtomicLong |
nbUpdateBtreeHeader |
java.util.concurrent.atomic.AtomicLong |
nbUpdatePageIOs |
java.util.concurrent.atomic.AtomicLong |
nbUpdateRMHeader |
private java.util.Map<java.lang.String,BTreeHeader<?,?>> |
newBTreeHeaders
A Map storing the new revisions when some change have been made in some BTrees
|
static long |
NO_PAGE
A constant for an offset on a non existing page
|
static boolean |
NORMAL_BTREE
A flag used by internal btrees
|
private static int |
PAGE_SIZE
The number of bytes used to store the size of a page
|
private int |
pageReclaimerThreshold
the threshold at which the PageReclaimer will be run to free the copied pages
|
(package private) int |
pageSize
The RecordManager underlying page size.
|
private long |
previousBtreeOfBtreesOffset
The previous B-tree of B-trees header offset
|
private long |
previousCopiedPagesBtreeOffset
The offset on the previous copied pages B-tree
|
private PageReclaimer |
reclaimer
the space reclaimer
|
private java.nio.ByteBuffer |
RECORD_MANAGER_HEADER_BUFFER
A global buffer used to store the RecordManager header
|
private byte[] |
RECORD_MANAGER_HEADER_BYTES
A static buffer used to store the RecordManager header
|
(package private) static int |
RECORD_MANAGER_HEADER_SIZE
The RecordManager header size
|
private static int |
ROLLBACKED_TXN
A value stored into the transaction context for rollbacked transactions
|
private java.util.concurrent.locks.ReentrantLock |
transactionLock
A lock to protect the transaction handling
|
protected static org.slf4j.Logger |
TXN_LOG
The LoggerFactory used to trace TXN operations
|
java.util.Map<java.lang.Long,java.lang.Integer> |
writeCounter |
| Constructor and Description |
|---|
RecordManager(java.lang.String fileName)
Create a Record manager which will either create the underlying file
or load an existing one.
|
RecordManager(java.lang.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 |
|---|---|
(package private) void |
_disableReclaimer(boolean toggle) |
<K,V> BTree<K,V> |
addBTree(java.lang.String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
boolean allowDuplicates)
Creates a B-tree and automatically adds it to the list of managed btrees
|
(package private) <K,V> void |
addInBtreeOfBtrees(java.lang.String name,
long revision,
long btreeHeaderOffset)
Add a new
|
(package private) <K,V> void |
addInCopiedPagesBtree(java.lang.String name,
long revision,
java.util.List<Page<K,V>> pages)
Add a new
|
void |
beginTransaction()
Starts a transaction
|
private void |
checkFreePages() |
(package private) void |
checkOffset(long offset)
Check the offset to be sure it's a valid one :
It's >= 0
It's below the end of the file
It's a multipl of the pageSize
|
void |
close()
Close the RecordManager and flush everything on disk
|
void |
commit()
Commits a transaction
|
private int |
computeNbPages(int dataSize)
Compute the number of pages needed to store some specific size of data.
|
private int |
computePageNb(long offset)
Compute the page in which we will store data given an offset, when
we have a list of pages.
|
private void |
createBtreeOfBtrees()
Create the B-treeOfBtrees
|
private void |
createCopiedPagesBtree()
Create the CopiedPagesBtree
|
private boolean |
createFile(java.io.File mavibotFile)
Create the mavibot file if it does not exist
|
private int |
decrementTxnLevel()
Decrement the transactionLevel
|
<K,V> 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 java.lang.String |
dump(byte octet) |
private void |
dump(PageIO pageIo)
Dump a pageIO
|
private long |
dumpBtreeHeader(long btreeOffset)
Dump a B-tree Header
|
private void |
dumpFreePages(long freePageOffset)
Dump the free pages
|
private PageIO |
fetchNewPage()
Return a new Page.
|
(package private) PageIO |
fetchPage(long offset)
fetch a page from disk, knowing its position in the file.
|
private void |
flushPages(PageIO... pageIos)
Write the pages on disk, either at the end of the file, or at
the position they were taken from.
|
(package private) void |
free(long... offsets)
Add an array of PageIOs to the list of free PageIOs
|
(package private) void |
free(PageIO pageIo)
Add a PageIO to the list of free PageIOs
|
(package private) <K,V> void |
freePages(BTree<K,V> btree,
long revision,
java.util.List<Page<K,V>> pages)
Move a list of pages to the free page list.
|
BTreeHeader |
getBTreeHeader(java.lang.String name)
Get the current BTreeHeader for a given Btree.
|
private PageIO[] |
getFreePageIOs(int dataSize)
Get as many pages as needed to store the data of the given size.
|
<K,V> BTree<K,V> |
getManagedTree(java.lang.String name)
Get one managed trees, knowing its name.
|
java.util.Set<java.lang.String> |
getManagedTrees()
Get the managed B-trees.
|
int |
getNbManagedTrees()
Get the number of managed trees.
|
BTreeHeader |
getNewBTreeHeader(java.lang.String name)
Get the new BTreeHeader for a given Btree.
|
int |
getPageSize() |
(package private) <K,V> Page<K,V> |
getRootPage(BTree<K,V> btree,
long revision)
Fetch the rootPage of a given B-tree for a given revision.
|
private int |
getTxnLevel()
Get the transactionLevel, ie the number of encapsulated update ops
|
private void |
incrementTxnLevel()
Increment the transactionLevel
|
private void |
initRecordManager()
We will create a brand new RecordManager file, containing nothing, but the RecordManager header,
a B-tree to manage the old revisions we want to keep and
a B-tree used to manage pages associated with old versions.
|
boolean |
isContextOk() |
boolean |
isKeepRevisions() |
private <K,V> void |
loadBtree(PageIO[] pageIos,
BTree<K,V> btree)
Read a B-tree from the disk.
|
(package private) <K,V> void |
loadBtree(PageIO[] pageIos,
BTree btree,
BTree<K,V> parentBTree)
Read a B-tree from the disk.
|
(package private) <K,V> BTree<V,V> |
loadDupsBtree(long btreeHeaderOffset,
BTree<K,V> parentBtree)
Loads a B-tree holding the values of a duplicate key
This tree is also called as dups tree or sub tree
|
private void |
loadRecordManager()
Load the BTrees from the disk.
|
(package private) static void |
logPageIos(PageIO[] pageIos) |
<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.
|
private byte |
readByte(PageIO[] pageIos,
long position)
Read a byte from pages
|
(package private) java.nio.ByteBuffer |
readBytes(PageIO[] pageIos,
long position)
Read a byte[] from pages.
|
(package private) int |
readInt(PageIO[] pageIos,
long position)
Read an int from pages
|
private <K,V> PersistedLeaf<K,V> |
readLeafKeysAndValues(BTree<K,V> btree,
int nbElems,
long revision,
java.nio.ByteBuffer byteBuffer,
PageIO[] pageIos)
Deserialize a Leaf from some PageIOs
|
(package private) long |
readLong(PageIO[] pageIos,
long position)
Read a long from pages
|
private <K,V> PersistedNode<K,V> |
readNodeKeysAndValues(BTree<K,V> btree,
int nbElems,
long revision,
java.nio.ByteBuffer byteBuffer,
PageIO[] pageIos)
Deserialize a Node from some PageIos
|
private <K,V> Page<K,V> |
readPage(BTree<K,V> btree,
PageIO[] pageIos)
Read a page from some PageIO for a given B-tree
|
(package private) PageIO[] |
readPageIOs(long position,
long limit)
Reads all the PageIOs that are linked to the page at the given position, including
the first page.
|
private <K,V> Page<K,V> |
readRootPage(BTree<K,V> btree,
long btreeHeaderOffset)
Read a root page from the B-tree header offset
|
(package private) <K,V> void |
releaseTransaction(ReadTransaction<K,V> readTransaction)
Add a newly closd transaction into the closed transaction queue
|
private void |
revertBtreeHeaders()
revert the new BTreeHeaders Map to the current BTreeHeader Map.
|
void |
rollback()
Rollback a transaction
|
private void |
runReclaimer()
runs the PageReclaimer to free the copied pages
|
private <K,V> int |
serializeLeafKey(PersistedLeaf<K,V> leaf,
int pos,
java.util.List<byte[]> serializedData)
Serialize a Leaf's key
|
private <K,V> int |
serializeLeafValue(PersistedLeaf<K,V> leaf,
int pos,
java.util.List<byte[]> serializedData)
Serialize a Leaf's Value.
|
private <K,V> int |
serializeNodeKey(PersistedNode<K,V> node,
int pos,
java.util.List<byte[]> serializedData)
Serialize a Node's key
|
private <K,V> int |
serializeNodeValue(PersistedNode<K,V> node,
int pos,
java.util.List<byte[]> serializedData)
Serialize a Node's Value.
|
private <K,V> PageIO[] |
serializePage(BTree<K,V> btree,
long revision,
Page<K,V> page)
Serialize a new Page.
|
private PageIO[] |
serializeRootPage(long revision)
Write a root page with no elements in it
|
(package private) void |
setBtreeOfBtreesOffset(long btreeOfBtreesOffset)
Internal method used to update the B-tree of B-trees offset
|
void |
setKeepRevisions(boolean keepRevisions) |
(package private) void |
setPageReclaimerThreshold(int pageReclaimerThreshold)
sets the threshold of the number of commits to be performed before
reclaiming the free pages.
|
(package private) void |
setPageSize(int pageSize)
Set the page size, ie the number of bytes a page can store.
|
private long |
store(long position,
byte[] bytes,
PageIO... pageIos)
Stores a byte[] into one ore more pageIO (depending if the long is stored
across a boundary or not)
|
private long |
store(long position,
int value,
PageIO... pageIos)
Stores an Integer into one ore more pageIO (depending if the int is stored
across a boundary or not)
|
private long |
store(long position,
long value,
PageIO... pageIos)
Stores a Long into one ore more pageIO (depending if the long is stored
across a boundary or not)
|
(package private) void |
storeCopiedPages(java.lang.String name,
long revision,
long[] copiedPages)
Stores the copied pages into the CopiedPages B-tree
|
private long |
storeRaw(long position,
byte[] bytes,
PageIO... pageIos)
Stores a byte[] into one ore more pageIO (depending if the long is stored
across a boundary or not).
|
(package private) <K,V> void |
storeRootPage(BTree<K,V> btree,
Page<K,V> rootPage)
Store a reference to an old rootPage into the Revision B-tree
|
private void |
swapCurrentBtreeHeaders()
Swap the current BtreeHeader map with the new one.
|
java.lang.String |
toString() |
(package private) <K,V> long |
updateBtreeHeader(BTree<K,V> btree,
long btreeHeaderOffset)
Update the B-tree header after a B-tree modification.
|
private <K,V> long |
updateBtreeHeader(BTree<K,V> btree,
long btreeHeaderOffset,
boolean onPlace)
Update the B-tree header after a B-tree modification.
|
(package private) <K,V> void |
updateBtreeHeaderOnPlace(BTree<K,V> btree,
long btreeHeaderOffset)
Update the B-tree header after a B-tree modification.
|
void |
updateNewBTreeHeaders(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 :
|
(package private) <K,V> long |
writeBtreeHeader(BTree<K,V> btree,
BTreeHeader<K,V> btreeHeader)
Write the B-tree header on disk.
|
private <K,V> long |
writeBtreeInfo(BTree<K,V> btree)
Write the B-tree informations on disk.
|
private int |
writeData(byte[] buffer,
int position,
int value)
Inject an int into a byte[] at a given position.
|
private int |
writeData(byte[] buffer,
int position,
long value)
Inject a long into a byte[] at a given position.
|
(package private) <K,V> PageHolder<K,V> |
writePage(BTree<K,V> btree,
Page<K,V> newPage,
long newRevision)
Write the page in a serialized form.
|
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
private java.io.File file
java.nio.channels.FileChannel fileChannel
int nbBtree
long firstFreePage
public java.util.concurrent.atomic.AtomicLong nbFreedPages
public java.util.concurrent.atomic.AtomicLong nbCreatedPages
public java.util.concurrent.atomic.AtomicLong nbReusedPages
public java.util.concurrent.atomic.AtomicLong nbUpdateRMHeader
public java.util.concurrent.atomic.AtomicLong nbUpdateBtreeHeader
public java.util.concurrent.atomic.AtomicLong nbUpdatePageIOs
private long endOfFileOffset
BTree<RevisionName,long[]> copiedPageBtree
public static final long NO_PAGE
private static final int PAGE_SIZE
private static final int LINK_SIZE
private static final int BYTE_SIZE
static final int INT_SIZE
static final int LONG_SIZE
public static final int DEFAULT_PAGE_SIZE
private static final int MIN_PAGE_SIZE
static int RECORD_MANAGER_HEADER_SIZE
private java.nio.ByteBuffer RECORD_MANAGER_HEADER_BUFFER
private byte[] RECORD_MANAGER_HEADER_BYTES
private byte[] LONG_LENGTH
int pageSize
private java.util.Map<java.lang.String,BTree<java.lang.Object,java.lang.Object>> managedBtrees
private java.util.Queue<RevisionName> closedTransactionsQueue
private static final java.lang.String DEFAULT_FILE_NAME
private boolean keepRevisions
public static final boolean INTERNAL_BTREE
public static final boolean NORMAL_BTREE
BTree<NameRevision,java.lang.Long> btreeOfBtrees
static final java.lang.String BTREE_OF_BTREES_NAME
static final java.lang.String COPIED_PAGE_BTREE_NAME
long currentBtreeOfBtreesOffset
private long previousBtreeOfBtreesOffset
long currentCopiedPagesBtreeOffset
private long previousCopiedPagesBtreeOffset
private java.util.concurrent.locks.ReentrantLock transactionLock
private static final java.lang.ThreadLocal<java.lang.Integer> context
java.util.List<PageIO> freedPages
private java.util.List<PageIO> allocatedPages
private java.util.Map<java.lang.String,BTreeHeader<?,?>> currentBTreeHeaders
private java.util.Map<java.lang.String,BTreeHeader<?,?>> newBTreeHeaders
private java.util.concurrent.locks.ReadWriteLock btreeHeadersLock
private static final int ROLLBACKED_TXN
private java.util.concurrent.locks.ReentrantLock freePageLock
private PageReclaimer reclaimer
private int commitCount
private int pageReclaimerThreshold
private boolean disableReclaimer
public java.util.Map<java.lang.Long,java.lang.Integer> writeCounter
private static final byte[] HEX_CHAR
public RecordManager(java.lang.String fileName)
name - The file name, or a folder namepublic RecordManager(java.lang.String fileName,
int pageSize)
name - The file name, or a folder namepageSize - the size of a page on disk, in bytesprivate void runReclaimer()
private boolean createFile(java.io.File mavibotFile)
private void initRecordManager()
throws java.io.IOException
+--------------------------+ | PageSize | 4 bytes : The size of a physical page (default to 512) +--------------------------+ | NbTree | 4 bytes : The number of managed B-trees (zero or more) +--------------------------+ | FirstFree | 8 bytes : The offset of the first free page +--------------------------+ | current BoB offset | 8 bytes : The offset of the current BoB +--------------------------+ | previous BoB offset | 8 bytes : The offset of the previous BoB +--------------------------+ | current CP btree offset | 8 bytes : The offset of the current BoB +--------------------------+ | previous CP btree offset | 8 bytes : The offset of the previous BoB +--------------------------+We then store the B-tree managing the pages that have been copied when we have added or deleted an element in the B-tree. They are associated with a version. Last, we add the bTree that keep a track on each revision we can have access to.
java.io.IOExceptionprivate void createBtreeOfBtrees()
private void createCopiedPagesBtree()
private void loadRecordManager()
throws java.io.IOException,
java.lang.ClassNotFoundException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.IllegalArgumentException,
java.lang.SecurityException,
java.lang.NoSuchFieldException,
KeyNotFoundException
java.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundExceptionjava.lang.NoSuchFieldExceptionjava.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionjava.io.IOExceptionKeyNotFoundExceptionpublic void beginTransaction()
public void commit()
public boolean isContextOk()
private int getTxnLevel()
private void incrementTxnLevel()
private int decrementTxnLevel()
public void rollback()
PageIO[] readPageIOs(long position, long limit) throws java.io.IOException, EndOfFileExceededException
position - The position of the first pagelimit - The maximum bytes to read. Set this value to -1 when the size is unknown.java.io.IOExceptionEndOfFileExceededExceptionvoid checkOffset(long offset)
offset - The offset to checkInvalidOffsetException - If the offset is not validprivate <K,V> void loadBtree(PageIO[] pageIos, BTree<K,V> btree) throws EndOfFileExceededException, java.io.IOException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.NoSuchFieldException
pageIos - The list of pages containing the meta-databtree - The B-tree we have to initializejava.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundExceptionjava.lang.NoSuchFieldExceptionjava.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionEndOfFileExceededExceptionjava.io.IOException<K,V> void loadBtree(PageIO[] pageIos, BTree btree, BTree<K,V> parentBTree) throws EndOfFileExceededException, java.io.IOException, java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.NoSuchFieldException
pageIos - The list of pages containing the meta-databtree - The B-tree we have to initializejava.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundExceptionjava.lang.NoSuchFieldExceptionjava.lang.SecurityExceptionjava.lang.IllegalArgumentExceptionEndOfFileExceededExceptionjava.io.IOExceptionpublic <K,V> Page<K,V> deserialize(BTree<K,V> btree, long offset) throws EndOfFileExceededException, java.io.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 pagejava.io.IOExceptionprivate <K,V> Page<K,V> readPage(BTree<K,V> btree, PageIO[] pageIos) throws java.io.IOException
btree - The B-tree we want to read a page forpageIos - The PageIO containing the raw datajava.io.IOException - If the deserialization failedprivate <K,V> PersistedLeaf<K,V> readLeafKeysAndValues(BTree<K,V> btree, int nbElems, long revision, java.nio.ByteBuffer byteBuffer, PageIO[] pageIos)
private <K,V> PersistedNode<K,V> readNodeKeysAndValues(BTree<K,V> btree, int nbElems, long revision, java.nio.ByteBuffer byteBuffer, PageIO[] pageIos) throws java.io.IOException
java.io.IOExceptionjava.nio.ByteBuffer readBytes(PageIO[] pageIos, long position)
pageIos - The pages we want to read the byte[] fromposition - The position in the data stored in those pagesint readInt(PageIO[] pageIos, long position)
pageIos - The pages we want to read the int fromposition - The position in the data stored in those pagesprivate byte readByte(PageIO[] pageIos, long position)
pageIos - The pages we want to read the byte fromposition - The position in the data stored in those pageslong readLong(PageIO[] pageIos, long position)
pageIos - The pages we want to read the long fromposition - The position in the data stored in those pagespublic <K,V> void manage(BTree<K,V> btree) throws BTreeAlreadyManagedException, java.io.IOException
btree - The new B-tree to manage.treeType - flag indicating if this is an internal treeBTreeAlreadyManagedException - If the B-tree is already managedjava.io.IOException - if there was a problem while accessing the filepublic <K,V> void manageSubBtree(BTree<K,V> btree) throws BTreeAlreadyManagedException, java.io.IOException
btree - The new B-tree to manage.treeType - flag indicating if this is an internal treeBTreeAlreadyManagedException - If the B-tree is already managedjava.io.IOExceptionprivate <K,V> PageIO[] serializePage(BTree<K,V> btree, long revision, Page<K,V> page) throws java.io.IOException
revision - The node revisionkeys - The keys to serializechildren - The references to the childrenjava.io.IOExceptionprivate <K,V> int serializeNodeKey(PersistedNode<K,V> node, int pos, java.util.List<byte[]> serializedData)
private <K,V> int serializeNodeValue(PersistedNode<K,V> node, int pos, java.util.List<byte[]> serializedData) throws java.io.IOException
java.io.IOExceptionprivate <K,V> int serializeLeafKey(PersistedLeaf<K,V> leaf, int pos, java.util.List<byte[]> serializedData)
private <K,V> int serializeLeafValue(PersistedLeaf<K,V> leaf, int pos, java.util.List<byte[]> serializedData) throws java.io.IOException
java.io.IOExceptionprivate PageIO[] serializeRootPage(long revision) throws java.io.IOException
java.io.IOExceptionpublic 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 +---------------------+
private int writeData(byte[] buffer,
int position,
int value)
private int writeData(byte[] buffer,
int position,
long value)
<K,V> void addInBtreeOfBtrees(java.lang.String name,
long revision,
long btreeHeaderOffset)
throws java.io.IOException
name - The B-tree namerevision - The B-tree revisionbtreeHeaderOffset - The B-tree offsetjava.io.IOException - If the update failed<K,V> void addInCopiedPagesBtree(java.lang.String name,
long revision,
java.util.List<Page<K,V>> pages)
throws java.io.IOException
name - The B-tree namerevision - The B-tree revisionbtreeHeaderOffset - The B-tree offsetjava.io.IOException - If the update failedvoid setBtreeOfBtreesOffset(long btreeOfBtreesOffset)
btreeOfBtreesOffset - The new offset<K,V> long writeBtreeHeader(BTree<K,V> btree, BTreeHeader<K,V> btreeHeader) throws java.io.IOException
+------------+ | revision | The B-tree revision +------------+ | nbElems | The B-tree number of elements +------------+ | rootPage | The root page offset +------------+ | BtreeInfo | The B-tree info offset +------------+
btree - The B-tree which header has to be writtenbtreeInfoOffset - The offset of the B-tree informationsjava.io.IOException - If we weren't able to write the B-tree headerprivate <K,V> long writeBtreeInfo(BTree<K,V> btree) throws java.io.IOException
+------------+ | pageSize | The B-tree page size (ie, the number of elements per page max) +------------+ | nameSize | The B-tree name size +------------+ | name | The B-tree name +------------+ | keySerSize | The keySerializer FQCN size +------------+ | keySerFQCN | The keySerializer FQCN +------------+ | valSerSize | The Value serializer FQCN size +------------+ | valSerKQCN | The valueSerializer FQCN +------------+ | dups | The flags that tell if the dups are allowed +------------+
btree - The B-tree which header has to be writtenjava.io.IOException - If we weren't able to write the B-tree header<K,V> long updateBtreeHeader(BTree<K,V> btree, long btreeHeaderOffset) throws EndOfFileExceededException, java.io.IOException
btree - TheB-tree to updatebtreeHeaderOffset - The offset of the modified btree headerjava.io.IOException - If we weren't able to write the file on diskEndOfFileExceededException - If we tried to write after the end of the file<K,V> void updateBtreeHeaderOnPlace(BTree<K,V> btree, long btreeHeaderOffset) throws EndOfFileExceededException, java.io.IOException
btree - The B-tree to updatebtreeHeaderOffset - The offset of the modified btree headerjava.io.IOExceptionEndOfFileExceededExceptionprivate <K,V> long updateBtreeHeader(BTree<K,V> btree, long btreeHeaderOffset, boolean onPlace) throws EndOfFileExceededException, java.io.IOException
btree - The B-tree to updaterootPageOffset - The offset of the modified rootPageonPlace - Tells if we modify the B-tree on place, or if we create a copyEndOfFileExceededException - If we tried to write after the end of the filejava.io.IOException - If tehre were some error while writing the data on diskprivate void flushPages(PageIO... pageIos) throws java.io.IOException
pageIos - The list of pages to writejava.io.IOException - If the write failedprivate int computePageNb(long offset)
offset - The position in the dataprivate long store(long position,
byte[] bytes,
PageIO... pageIos)
position - The position in a virtual byte[] if all the pages were contiguousbytes - The byte[] to serializepageIos - The pageIOs we have to store the data inprivate long storeRaw(long position,
byte[] bytes,
PageIO... pageIos)
position - The position in a virtual byte[] if all the pages were contiguousbytes - The byte[] to serializepageIos - The pageIOs we have to store the data inprivate long store(long position,
int value,
PageIO... pageIos)
position - The position in a virtual byte[] if all the pages were contiguousvalue - The int to serializepageIos - The pageIOs we have to store the data inprivate long store(long position,
long value,
PageIO... pageIos)
position - The position in a virtual byte[] if all the pages were contiguousvalue - The long to serializepageIos - The pageIOs we have to store the data in<K,V> PageHolder<K,V> writePage(BTree<K,V> btree, Page<K,V> newPage, long newRevision) throws java.io.IOException
btree - The persistedBtree we will create a new PageHolder fornewPage - The page to write on disknewRevision - The page's revisionjava.io.IOException - If the page can't be written on diskstatic void logPageIos(PageIO[] pageIos)
private int computeNbPages(int dataSize)
dataSize - The size of the data we want to store in pagesprivate PageIO[] getFreePageIOs(int dataSize) throws java.io.IOException
dataSize - The data sizejava.io.IOExceptionprivate PageIO fetchNewPage() throws java.io.IOException
java.io.IOExceptionPageIO fetchPage(long offset) throws java.io.IOException, EndOfFileExceededException
offset - The position in the filejava.io.IOExceptionEndOfFileExceededExceptionpublic int getPageSize()
void setPageSize(int pageSize)
pageSize - The number of bytes for a pagepublic void close()
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String dump(byte octet)
private void dump(PageIO pageIo)
public void dump()
java.io.IOExceptionprivate void dumpFreePages(long freePageOffset)
throws EndOfFileExceededException,
java.io.IOException
EndOfFileExceededExceptionjava.io.IOExceptionprivate long dumpBtreeHeader(long btreeOffset)
throws EndOfFileExceededException,
java.io.IOException
EndOfFileExceededExceptionjava.io.IOExceptionpublic int getNbManagedTrees()
public java.util.Set<java.lang.String> getManagedTrees()
void storeCopiedPages(java.lang.String name,
long revision,
long[] copiedPages)
throws java.io.IOException
name - The B-tree namerevision - The revisioncopiedPages - The pages that have been copied while creating this revisionjava.io.IOException - If we weren't able to store the data on disk<K,V> void storeRootPage(BTree<K,V> btree, Page<K,V> rootPage) throws java.io.IOException
btree - The B-tree we want to keep an old RootPage forrootPage - The old rootPagejava.io.IOException - If we have an issue while writing on disk<K,V> Page<K,V> getRootPage(BTree<K,V> btree, long revision) throws KeyNotFoundException, java.io.IOException
btree - The B-tree we are interested inrevision - The revision we want to get backKeyNotFoundException - If we can't find the rootPage for this revision and this B-treejava.io.IOException - If we had an ise while accessing the data on diskprivate <K,V> Page<K,V> readRootPage(BTree<K,V> btree, long btreeHeaderOffset) throws EndOfFileExceededException, java.io.IOException
EndOfFileExceededExceptionjava.io.IOExceptionpublic <K,V> BTree<K,V> getManagedTree(java.lang.String name)
name - The B-tree name we are looking for<K,V> void freePages(BTree<K,V> btree, long revision, java.util.List<Page<K,V>> pages) throws EndOfFileExceededException, java.io.IOException
btree - The B-tree which were owning the pagesrevision - The current revisionpages - The pages to freejava.io.IOException - If we had a problem while updating the fileEndOfFileExceededException - If we tried to write after the end of the filevoid free(PageIO pageIo) throws java.io.IOException
pageIo - The page to freejava.io.IOException - If we weren't capable of updating the filevoid free(long... offsets) throws java.io.IOException
offsets - The offsets of the pages whose associated PageIOs will be fetched and freed.java.io.IOException - If we weren't capable of updating the filepublic boolean isKeepRevisions()
public void setKeepRevisions(boolean keepRevisions)
keepRevisions - the keepRevisions flag to setpublic <K,V> BTree<K,V> addBTree(java.lang.String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, boolean allowDuplicates) throws java.io.IOException, BTreeAlreadyManagedException
name - the name of the B-treekeySerializer - key serializervalueSerializer - value serializerallowDuplicates - flag for allowing duplicate keysjava.io.IOException - If we weren't able to update the file on diskBTreeAlreadyManagedException - If the B-tree is already managed<K,V> void releaseTransaction(ReadTransaction<K,V> readTransaction)
public BTreeHeader getBTreeHeader(java.lang.String name)
name - The Btree name we are looking the BtreeHeader forpublic BTreeHeader getNewBTreeHeader(java.lang.String name)
public void updateNewBTreeHeaders(BTreeHeader btreeHeader)
btreeHeader - The new BtreeHeaderprivate void swapCurrentBtreeHeaders()
private void revertBtreeHeaders()
<K,V> BTree<V,V> loadDupsBtree(long btreeHeaderOffset, BTree<K,V> parentBtree)
offset - the offset of the B-tree headerprivate void checkFreePages()
throws EndOfFileExceededException,
java.io.IOException
EndOfFileExceededExceptionjava.io.IOExceptionvoid setPageReclaimerThreshold(int pageReclaimerThreshold)
pageReclaimerThreshold - the number of commits before the reclaimer runsvoid _disableReclaimer(boolean toggle)
public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()