Package com._1c.g5.v8.xmdb.impl
Class TreeCacheReal
- java.lang.Object
-
- com._1c.g5.v8.xmdb.impl.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTreeCacheReal.CacheEntrystatic classTreeCacheReal.CacheNodeEntrystatic classTreeCacheReal.CacheObjectEntry
-
Field Summary
Fields Modifier and Type Field Description protected ConcurrentHashMap<Long,Long>cacheLongprotected SLRUCacheMT<Long,TreeCacheReal.CacheNodeEntry>cacheReadprotected SLRUCacheMT<Long,TreeCacheReal.CacheObjectEntry>cacheValueprotected Engineengineprotected intreadCacheSizeprotected intreadHitprotected intreadMissprotected booleanthreadSafeprotected intvalueBatchBSprotected intvalueCacheSizeprotected intvalueHitprotected intvalueMissprotected intwriteHit
-
Constructor Summary
Constructors Constructor Description TreeCacheReal(Engine engine, int writeCacheSize, int readCacheSize, int valueCacheSize, boolean threadSafe, int objectBatchBS)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longclone(long cLink)Clone element by cLink (new element should not be cached by default).voidclose()voiddropCaches()Drop all cachevoiddropCaches(int segment)Drop cache entry with specified segment idvoidevict()Evict (usually - write to disk, but not sync) all cache entry (from write node cache).voidevict(int segmentId)Don't use while writing in theese segment in another thread! Just for BTreeMap internal usagevoidflush()BNodeget(long cLink, boolean storeValuesInLeaf, int t, int segment)Read BNode from cache.bytegetByte(long offset)EnginegetEngine()Get underlying db engineintgetInt(long offset)longgetLong(long offset)byte[]getObject(long cLink, int segment)Read object from cache.intgetReadCacheSize()intgetValueCacheSize()booleanisThreadSafe()longput(long oldPos, BNode val, int segment, boolean valInLeaf, int preallocFreeSpace)Put (insert or update) BNode into cache.voidputByte(long offset, byte value)voidputInt(long offset, int value)voidputLong(long offset, int value)voidputLong(long offset, long value)longputObject(byte[] value, int segment)Put object (value) into cachelongputObject(ByteBuffer value, int segment)Put object (value) into cachebyte[]removeObject(long cLink, int segment)Removes object from cache.voidsync()Sync all write node cache entry and syncvoidsync(int segmentId)Write to disk (and sync) all cache entry (from write node cache) with specified segmentId.StringtoString()
-
-
-
Field Detail
-
readCacheSize
protected int readCacheSize
-
valueCacheSize
protected int valueCacheSize
-
valueBatchBS
protected int valueBatchBS
-
readHit
protected volatile int readHit
-
readMiss
protected volatile int readMiss
-
writeHit
protected volatile int writeHit
-
valueHit
protected volatile int valueHit
-
valueMiss
protected volatile int valueMiss
-
cacheRead
protected SLRUCacheMT<Long,TreeCacheReal.CacheNodeEntry> cacheRead
-
cacheValue
protected SLRUCacheMT<Long,TreeCacheReal.CacheObjectEntry> cacheValue
-
engine
protected Engine engine
-
cacheLong
protected ConcurrentHashMap<Long,Long> cacheLong
-
threadSafe
protected boolean threadSafe
-
-
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:ITreeCacheRead 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:
getObjectin interfaceITreeCache- Parameters:
cLink- object address (cLink)segment- segmentId- Returns:
- readed object
-
removeObject
public byte[] removeObject(long cLink, int segment)Description copied from interface:ITreeCacheRemoves object from cache.- Specified by:
removeObjectin interfaceITreeCache- Parameters:
cLink- object address (cLink)segment- segmentId- Returns:
- removed object
-
putObject
public long putObject(byte[] value, int segment)Description copied from interface:ITreeCachePut object (value) into cache- Specified by:
putObjectin interfaceITreeCache- Parameters:
value- value to storesegment- segment id- Returns:
- actual cLink to stored object
-
putObject
public long putObject(ByteBuffer value, int segment)
Description copied from interface:ITreeCachePut object (value) into cache- Specified by:
putObjectin interfaceITreeCache- Parameters:
value- value to storesegment- segment id- Returns:
- actual cLink to stored object
-
get
public BNode get(long cLink, boolean storeValuesInLeaf, int t, int segment)
Description copied from interface:ITreeCacheRead 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:
getin interfaceITreeCache- 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:ITreeCachePut (insert or update) BNode into cache. Cache return new adress of BNode (can be the same if BNode fit into allocated block)- Specified by:
putin interfaceITreeCache- Parameters:
oldPos- old cLink address of BNode or CompactLink.EMPTY_LINK if its first time save to current BNodeval- BNode to savesegment- segment idvalInLeaf- store value in leaf flagpreallocFreeSpace- 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:ITreeCacheSync all write node cache entry and sync- Specified by:
syncin interfaceITreeCache
-
sync
public void sync(int segmentId)
Description copied from interface:ITreeCacheWrite to disk (and sync) all cache entry (from write node cache) with specified segmentId. Writed segments will be moved to read cache.- Specified by:
syncin interfaceITreeCache- Parameters:
segmentId- segment to write
-
evict
public void evict()
Description copied from interface:ITreeCacheEvict (usually - write to disk, but not sync) all cache entry (from write node cache). Remove all cache entry from read/object caches.- Specified by:
evictin interfaceITreeCache
-
evict
public void evict(int segmentId)
Don't use while writing in theese segment in another thread! Just for BTreeMap internal usage- Specified by:
evictin interfaceITreeCache- Parameters:
segmentId-
-
flush
public void flush()
-
getEngine
public Engine getEngine()
Description copied from interface:ITreeCacheGet underlying db engine- Specified by:
getEnginein interfaceITreeCache- Returns:
- engine
-
getReadCacheSize
public int getReadCacheSize()
-
getValueCacheSize
public int getValueCacheSize()
-
isThreadSafe
public boolean isThreadSafe()
-
dropCaches
public void dropCaches(int segment)
Description copied from interface:ITreeCacheDrop cache entry with specified segment id- Specified by:
dropCachesin interfaceITreeCache- Parameters:
segment- segment id to drop
-
clone
public long clone(long cLink)
Description copied from interface:ITreeCacheClone element by cLink (new element should not be cached by default). Not for value body objects.- Specified by:
clonein interfaceITreeCache- Parameters:
cLink- link to original element to clone- Returns:
- link to clone of original element
-
dropCaches
public void dropCaches()
Description copied from interface:ITreeCacheDrop all cache- Specified by:
dropCachesin interfaceITreeCache
-
-