Class TreeCacheReal

  • All Implemented Interfaces:
    ITreeCache

    public class TreeCacheReal
    extends Object
    implements ITreeCache
    Global database cache for all index in db. Implement SLRU object cache strategy in heap.
    • Constructor Detail

      • TreeCacheReal

        public TreeCacheReal​(Engine engine,
                             int writeCacheSize,
                             int readCacheSize,
                             int valueCacheSize,
                             boolean threadSafe,
                             int objectBatchBS)
    • Method Detail

      • getObject

        public byte[] getObject​(long cLink,
                                int segment)
        Description copied from interface: ITreeCache
        Read object from cache. If object won't be found in object cache - it will be load from disk into object cache before return
        Specified by:
        getObject in interface ITreeCache
        Parameters:
        cLink - object address (cLink)
        segment - segmentId
        Returns:
        readed object
      • removeObject

        public byte[] removeObject​(long cLink,
                                   int segment)
        Description copied from interface: ITreeCache
        Removes object from cache.
        Specified by:
        removeObject in interface ITreeCache
        Parameters:
        cLink - object address (cLink)
        segment - segmentId
        Returns:
        removed object
      • putObject

        public long putObject​(byte[] value,
                              int segment)
        Description copied from interface: ITreeCache
        Put object (value) into cache
        Specified by:
        putObject in interface ITreeCache
        Parameters:
        value - value to store
        segment - segment id
        Returns:
        actual cLink to stored object
      • putObject

        public long putObject​(ByteBuffer value,
                              int segment)
        Description copied from interface: ITreeCache
        Put object (value) into cache
        Specified by:
        putObject in interface ITreeCache
        Parameters:
        value - value to store
        segment - segment id
        Returns:
        actual cLink to stored object
      • get

        public BNode get​(long cLink,
                         boolean storeValuesInLeaf,
                         int t,
                         int segment)
        Description copied from interface: ITreeCache
        Read BNode from cache. If BNode won't be found in read/write node caches - it will be load from disk into read cache before return
        Specified by:
        get in interface ITreeCache
        Parameters:
        cLink - BNode address (cLink)
        storeValuesInLeaf - value in leaf flag (for deserialization, if node on disk)
        t - node width, t (for deserialization, if node on disk)
        segment - segment id
        Returns:
        readed BNode
      • put

        public long put​(long oldPos,
                        BNode val,
                        int segment,
                        boolean valInLeaf,
                        int preallocFreeSpace)
        Description copied from interface: ITreeCache
        Put (insert or update) BNode into cache. Cache return new adress of BNode (can be the same if BNode fit into allocated block)
        Specified by:
        put in interface ITreeCache
        Parameters:
        oldPos - old cLink address of BNode or CompactLink.EMPTY_LINK if its first time save to current BNode
        val - BNode to save
        segment - segment id
        valInLeaf - store value in leaf flag
        preallocFreeSpace - default prealloc space for current BTree
        Returns:
        actual cLink to stored BNode
      • getLong

        public long getLong​(long offset)
      • putLong

        public void putLong​(long offset,
                            long value)
      • putLong

        public void putLong​(long offset,
                            int value)
      • close

        public void close()
      • getInt

        public int getInt​(long offset)
      • putInt

        public void putInt​(long offset,
                           int value)
      • getByte

        public byte getByte​(long offset)
      • putByte

        public void putByte​(long offset,
                            byte value)
      • sync

        public void sync()
        Description copied from interface: ITreeCache
        Sync all write node cache entry and sync
        Specified by:
        sync in interface ITreeCache
      • sync

        public void sync​(int segmentId)
        Description copied from interface: ITreeCache
        Write to disk (and sync) all cache entry (from write node cache) with specified segmentId. Writed segments will be moved to read cache.
        Specified by:
        sync in interface ITreeCache
        Parameters:
        segmentId - segment to write
      • evict

        public void evict()
        Description copied from interface: ITreeCache
        Evict (usually - write to disk, but not sync) all cache entry (from write node cache). Remove all cache entry from read/object caches.
        Specified by:
        evict in interface ITreeCache
      • evict

        public void evict​(int segmentId)
        Don't use while writing in theese segment in another thread! Just for BTreeMap internal usage
        Specified by:
        evict in interface ITreeCache
        Parameters:
        segmentId -
      • flush

        public void flush()
      • getEngine

        public Engine getEngine()
        Description copied from interface: ITreeCache
        Get underlying db engine
        Specified by:
        getEngine in interface ITreeCache
        Returns:
        engine
      • getReadCacheSize

        public int getReadCacheSize()
      • getValueCacheSize

        public int getValueCacheSize()
      • isThreadSafe

        public boolean isThreadSafe()
      • dropCaches

        public void dropCaches​(int segment)
        Description copied from interface: ITreeCache
        Drop cache entry with specified segment id
        Specified by:
        dropCaches in interface ITreeCache
        Parameters:
        segment - segment id to drop
      • clone

        public long clone​(long cLink)
        Description copied from interface: ITreeCache
        Clone element by cLink (new element should not be cached by default). Not for value body objects.
        Specified by:
        clone in interface ITreeCache
        Parameters:
        cLink - link to original element to clone
        Returns:
        link to clone of original element
      • dropCaches

        public void dropCaches()
        Description copied from interface: ITreeCache
        Drop all cache
        Specified by:
        dropCaches in interface ITreeCache