Class BTreeMap<K,​V>

    • Field Detail

      • t

        public int t
      • t2

        public int t2
      • splitSeparator

        public int splitSeparator
      • preallocSplitLeftFS

        public int preallocSplitLeftFS
      • preallocMergeLeftFS

        public int preallocMergeLeftFS
    • Constructor Detail

      • BTreeMap

        public BTreeMap​(ITreeCache cache,
                        byte valueType,
                        int t,
                        int splitSeparator,
                        int mergeSeparator,
                        boolean threadSafe,
                        boolean valInLeaf,
                        int preallocFreeSpace,
                        int segment,
                        long rootCLink,
                        int size,
                        int nodeCount,
                        int height)
        BTree constructor
        Parameters:
        cache - the global cache to use
        valueType - the valut type to store
        t - the half of width of three nodes
        splitSeparator - number of values in left node after spliting
        mergeSeparator - number of values in left node after merging trees
        threadSafe - is current three should be a thread safe
        valInLeaf - is leaf node should store values innner
        preallocFreeSpace - number of bytes to allocate in leaf node for future values (if values stored in it)
        segment - the segment to use in global cache
        rootCLink - the compact link to root of tree (if new = EMPTY_LINK)
        size - number of elements, stored in three
        nodeCount - number of nodes in three
        height - height of three
    • Method Detail

      • newDirNode

        public BDirNode newDirNode()
        Construct new dir node, compatible with current tree
        Returns:
        new dir node
      • newLeafNode

        public BLeafNode newLeafNode()
        Construct new leaf node, compatible with current tree
        Returns:
        new leaf node
      • init

        public void init​(ITreeCache cache,
                         byte valueType,
                         int t,
                         int splitSeparator,
                         int mergeSeparator,
                         boolean threadSafe,
                         boolean valInLeaf,
                         int preallocFreeSpace,
                         int segment,
                         long rootCLink,
                         int size,
                         int nodeCount,
                         int height)
      • clear

        public void clear()
        Remove all element from index
        Specified by:
        clear in interface KeyValueStorage<K,​V>
      • put

        public void put​(long key,
                        byte[] value)
        Put new key/value pair in index (by long key)
        Specified by:
        put in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to put
        value - value to put
      • put

        public void put​(String key,
                        byte[] value)
        Put new key/value pair in index (by String key)
        Specified by:
        put in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to put
        value - value to put
      • isNodeFull

        public final boolean isNodeFull​(BNode node)
        Test: if specified node is full
        Parameters:
        node - the node to test
        Returns:
        value true if node is full false otherwise
      • isDirNodeFull

        public final boolean isDirNodeFull​(BDirNode node)
        Test: if speficied dir node is full
        Parameters:
        node - the dir node to test
        Returns:
        value true if node is full false otherwise
      • isLeafNodeFull

        public final boolean isLeafNodeFull​(BLeafNode node)
        Test: if speficied leaf node is full
        Parameters:
        node - the leaf node to test
        Returns:
        value true if node is full false otherwise
      • get

        public byte[] get​(long key)
        Get value by long key
        Specified by:
        get in interface KeyValueStorage<K,​V>
        Parameters:
        key - key
        Returns:
        value or null (if key doesn;t exist in index)
      • get

        public byte[] get​(String key)
        Get value by String key
        Specified by:
        get in interface KeyValueStorage<K,​V>
        Parameters:
        key - key
        Returns:
        value or null (if key doesn;t exist in index)
      • keySet

        public Set<? extends Object> keySet()
        Get keys set (clone all keys from index into new set)
        Specified by:
        keySet in interface KeyValueStorage<K,​V>
        Returns:
        keys set
      • size

        public int size()
        Get index size in elements
        Specified by:
        size in interface KeyValueStorage<K,​V>
        Returns:
        size
      • sync

        public void sync()
        Sync index state with internal store (to file). Force write cache to store to engine;
        Specified by:
        sync in interface KeyValueStorage<K,​V>
      • evict

        public void evict()
        Advice to XMDB (put all data from caches to files, but no sync fdatasync call). Not mandatory, just safe RAM & speedup another threads
        Specified by:
        evict in interface KeyValueStorage<K,​V>
      • close

        public void close()
        Close index (sync and clear caches)
        Specified by:
        close in interface KeyValueStorage<K,​V>
      • entrySet

        public Set entrySet()
        Get entry set from index
        Specified by:
        entrySet in interface KeyValueStorage<K,​V>
        Returns:
        entry set
      • putRAW

        public void putRAW​(long key,
                           byte[] rawValue)
        Put raw (complex) value to index with complex value type
        Specified by:
        putRAW in interface KeyValueStorage<K,​V>
        Parameters:
        key - long hash key of raw value
        rawValue - raw (complex) value
      • remove

        public byte[] remove​(long key)
        Remove long key from index
        Specified by:
        remove in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to remove
        Returns:
        old value (or null if key doesn;t exist in index)
      • remove

        public byte[] remove​(String key)
        Remove String key from index
        Specified by:
        remove in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to remove
        Returns:
        old value (or null if key doesn;t exist in index)
      • getInt

        public byte[] getInt​(String key)
      • getInt

        public byte[] getInt​(long key)
      • removeInt

        protected byte[] removeInt​(long key)
      • removeInt

        protected byte[] removeInt​(String key)
      • getT

        public int getT()
      • getSplitSeparator

        public int getSplitSeparator()
      • getMergeSeparator

        public int getMergeSeparator()
      • getValueType

        public byte getValueType()
      • isThreadSafe

        public boolean isThreadSafe()
      • detachStorage

        public void detachStorage()
        Temporary detach storage
      • attachStorage

        public void attachStorage()
        Reattach temporary detached storage
      • dropCaches

        public void dropCaches()
        Drop all cache without store write cache to disk
        Specified by:
        dropCaches in interface KeyValueStorage<K,​V>
      • getValInLeaf

        public boolean getValInLeaf()
        Get store values in leaf nodes flag
        Returns:
        value true if values stored in leaf node false otherwise
      • getPreallocFreeSpace

        public int getPreallocFreeSpace()
        Get preallocated free space amount
        Returns:
        preallocated free space (in bytes)
      • getSegment

        public int getSegment()
        Get segment id of index
        Specified by:
        getSegment in interface KeyValueStorage<K,​V>
        Returns:
        segment id
      • clone

        public KeyValueStorage clone​(int newSegment)
        Create clone of current index with new segmentId
        Specified by:
        clone in interface KeyValueStorage<K,​V>
        Parameters:
        newSegment - new segment id
        Returns:
        new index
      • cloneNode

        public long cloneNode​(BDirNode node,
                              int level,
                              int newSegment)
      • cloneHeader

        public KeyValueStorage cloneHeader​(int newSegment)
        Clone only header of current index with new segmentId
        Specified by:
        cloneHeader in interface KeyValueStorage<K,​V>
        Parameters:
        newSegment - new segment id
        Returns:
        new index (same as old, but with new index header and segment)
      • contains

        public boolean contains​(long key)
        Test if index contain specified key
        Specified by:
        contains in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to test
        Returns:
        "key exist in index" flag
      • contains

        public boolean contains​(String key)
        Test if index contain specified key
        Specified by:
        contains in interface KeyValueStorage<K,​V>
        Parameters:
        key - key to test
        Returns:
        "key exist in index" flag
      • merge

        public void merge​(KeyValueStorage<K,​byte[]> s1,
                          Map<K,​byte[]> s2)
        Merge KVS and Map into current index (first can be this index)
        Specified by:
        merge in interface KeyValueStorage<K,​V>
        Parameters:
        s1 - fist KVS, base
        s2 - second Map, updates