org.apache.directory.mavibot.btree

## Class RecordManager

- java.lang.Object
- - org.apache.directory.mavibot.btree.AbstractTransactionManager
  - - org.apache.directory.mavibot.btree.RecordManager

- All Implemented Interfaces:
    TransactionManager

      public class RecordManager
      extends AbstractTransactionManager

  The RecordManager is used to manage the file in which we will store the B-trees. A RecordManager will manage more than one B-tree.
  It stores data in fixed size pages (default size is 512 bytes), which may be linked one to the other if the data we want to store is too big for a page.
  Author:
    Apache Directory Project

- - ### Field Summary

    Fields
    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 Summary

    Constructors
    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.

  - ### Method Summary

    Methods
    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 :

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### LOG

          protected static final org.slf4j.Logger LOG

      The LoggerFactory used by this class

    - #### TXN_LOG

          protected static final org.slf4j.Logger TXN_LOG

      The LoggerFactory used to trace TXN operations

    - #### LOG_PAGES

          protected static final org.slf4j.Logger LOG_PAGES

      The LoggerFactory used by this class

    - #### LOG_CHECK

          protected static final org.slf4j.Logger LOG_CHECK

      A dedicated logger for the check

    - #### nbFreedPages

          public AtomicLong nbFreedPages

      Some counters to track the number of free pages

    - #### nbCreatedPages

          public AtomicLong nbCreatedPages

    - #### nbReusedPages

          public AtomicLong nbReusedPages

    - #### nbUpdateRMHeader

          public AtomicLong nbUpdateRMHeader

    - #### nbUpdateBtreeHeader

          public AtomicLong nbUpdateBtreeHeader

    - #### nbUpdatePageIOs

          public AtomicLong nbUpdatePageIOs

    - #### NO_PAGE

          public static final long NO_PAGE

      A constant for an offset on a non existing page
      See Also:
        Constant Field Values

    - #### DEFAULT_PAGE_SIZE

          public static final int DEFAULT_PAGE_SIZE

      The default page size
      See Also:
        Constant Field Values

    - #### INTERNAL_BTREE

          public static final boolean INTERNAL_BTREE

      A flag used by internal btrees
      See Also:
        Constant Field Values

    - #### NORMAL_BTREE

          public static final boolean NORMAL_BTREE

      A flag used by internal btrees
      See Also:
        Constant Field Values

    - #### writeCounter

          public Map<Long,Integer> writeCounter

  - ### Constructor Detail

    - #### RecordManager

          public RecordManager(String fileName)

      Create a Record manager which will either create the underlying file or load an existing one. If a folder is provided, then we will create a file with a default name : mavibot.db
      Parameters:
        `name` - The file name, or a folder name

    - #### RecordManager

          public RecordManager(String fileName,
                       int pageSize)

      Create a Record manager which will either create the underlying file or load an existing one. If a folder is provider, then we will create a file with a default name : mavibot.db
      Parameters:
        `name` - The file name, or a folder name
        `pageSize` - the size of a page on disk, in bytes

  - ### Method Detail

    - #### beginTransaction

          public void beginTransaction()

      Starts a transaction

    - #### commit

          public void commit()

      Commits a transaction

    - #### isContextOk

          public boolean isContextOk()

    - #### rollback

          public void rollback()

      Rollback a transaction

    - #### deserialize

          public <K,V> org.apache.directory.mavibot.btree.Page<K,V> deserialize(BTree<K,V> btree,
                                                                       long offset)
                                                                   throws EndOfFileExceededException,
                                                                          IOException

      Deserialize a Page from a B-tree at a give position
      Parameters:
        `btree` - The B-tree we want to read a Page from
        `offset` - The position in the file for this page
      Returns:
        The read page
      Throws:
        `EndOfFileExceededException` - If we have reached the end of the file while reading the page
        `IOException`

    - #### manage

          public <K,V> void manage(BTree<K,V> btree)
                      throws BTreeAlreadyManagedException,
                             IOException

      Manage a B-tree. The btree will be added and managed by this RecordManager. We will create a new RootPage for this added B-tree, which will contain no data.
      This method is threadsafe. Managing a btree is a matter of storing an reference to the managed B-tree in the B-tree Of B-trees. We store a tuple of NameRevision (where revision is 0L) and a offset to the B-tree header. At the same time, we keep a track of the managed B-trees in a Map.
      Parameters:
        `btree` - The new B-tree to manage.
        `treeType` - flag indicating if this is an internal tree
      Throws:
        `BTreeAlreadyManagedException` - If the B-tree is already managed
        `IOException` - if there was a problem while accessing the file

    - #### manageSubBtree

          public <K,V> void manageSubBtree(BTree<K,V> btree)
                              throws BTreeAlreadyManagedException,
                                     IOException

      Managing a btree is a matter of storing an reference to the managed B-tree in the B-tree Of B-trees. We store a tuple of NameRevision (where revision is 0L) and a offset to the B-tree header. At the same time, we keep a track of the managed B-trees in a Map.
      Parameters:
        `btree` - The new B-tree to manage.
        `treeType` - flag indicating if this is an internal tree
      Throws:
        `BTreeAlreadyManagedException` - If the B-tree is already managed
        `IOException`

    - #### updateRecordManagerHeader

          public void updateRecordManagerHeader()

      Update the RecordManager header, injecting the following data :

           +---------------------+
           | 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
           +---------------------+

    - #### updateRecordManagerHeader

          public void updateRecordManagerHeader(long newBtreeOfBtreesOffset,
                                       long newCopiedPageBtreeOffset)

      Update the RecordManager header, injecting the following data :

           +---------------------+
           | 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
           +---------------------+

    - #### getPageSize

          public int getPageSize()

      Returns:
        the pageSize

    - #### close

          public void close()
                     throws IOException

      Close the RecordManager and flush everything on disk
      Throws:
        `IOException`

    - #### dump

          public static String dump(byte octet)

    - #### dump

          public void dump()

      Dump the RecordManager file
      Throws:
        `IOException`

    - #### getNbManagedTrees

          public int getNbManagedTrees()

      Get the number of managed trees. We don't count the CopiedPage B-tree and the B-tree of B-trees
      Returns:
        The number of managed B-trees

    - #### getManagedTrees

          public Set<String> getManagedTrees()

      Get the managed B-trees. We don't return the CopiedPage B-tree nor the B-tree of B-trees.
      Returns:
        The managed B-trees

    - #### getManagedTree

          public <K,V> BTree<K,V> getManagedTree(String name)

      Get one managed trees, knowing its name.
      Parameters:
        `name` - The B-tree name we are looking for
      Returns:
        The managed B-trees

    - #### isKeepRevisions

          public boolean isKeepRevisions()

      Returns:
        the keepRevisions flag

    - #### setKeepRevisions

          public void setKeepRevisions(boolean keepRevisions)

      Parameters:
        `keepRevisions` - the keepRevisions flag to set

    - #### addBTree

          public <K,V> BTree<K,V> addBTree(String name,
                                  ElementSerializer<K> keySerializer,
                                  ElementSerializer<V> valueSerializer,
                                  boolean allowDuplicates)
                              throws IOException,
                                     BTreeAlreadyManagedException

      Creates a B-tree and automatically adds it to the list of managed btrees
      Parameters:
        `name` - the name of the B-tree
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
        `allowDuplicates` - flag for allowing duplicate keys
      Returns:
        a managed B-tree
      Throws:
        `IOException` - If we weren't able to update the file on disk
        `BTreeAlreadyManagedException` - If the B-tree is already managed

    - #### getBTreeHeader

          public org.apache.directory.mavibot.btree.BTreeHeader getBTreeHeader(String name)

      Get the current BTreeHeader for a given Btree. It might not exist
      Parameters:
        `name` - The Btree name we are looking the BtreeHeader for
      Returns:
        the current BTreeHeader

    - #### getNewBTreeHeader

          public org.apache.directory.mavibot.btree.BTreeHeader getNewBTreeHeader(String name)

      Get the new BTreeHeader for a given Btree. It might not exist

    - #### updateNewBTreeHeaders

          public void updateNewBTreeHeaders(org.apache.directory.mavibot.btree.BTreeHeader btreeHeader)

      Updates the map of new BTreeHeaders
      Parameters:
        `btreeHeader` - The new BtreeHeader

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`
      See Also:
        `Object.toString()`

Copyright © 2012–2015 Apache Mavibot Project Parent. All rights reserved.