com.bigdata.cache
Class HardReferenceGlobalLRURecycler<K,V>

java.lang.Object
  extended by com.bigdata.cache.HardReferenceGlobalLRURecycler<K,V>
Type Parameters:
K - The generic type of the key.
V - The generic type of the value.
All Implemented Interfaces:
IGlobalLRU<K,V>, IHardReferenceGlobalLRU<K,V>

public class HardReferenceGlobalLRURecycler<K,V>
extends Object
implements IHardReferenceGlobalLRU<K,V>

A canonicalizing collection of weakly held hard reference hash maps backed by a single Least Recently Used (LRU) ordering over entries. This is used to impose a shared LRU policy on the cache for a set of IRawStores. The LRU Entry is recycled on eviction as the MRU Entry, which requires tests against the inner LRUCacheImpl's map to be made while holding the lock. This allows us to use a LinkedHashMap, which has a faster iterator, but requiring the lock to test the inner cache limits concurrency and has been observed to limit throughput by about 10%.

Version:
$Id: HardReferenceGlobalLRURecycler.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
TODO:
... Disallow anything where does not extend IDataRecordAccess since we can not measure the bytesInMemory for those objects and hence the LRU eviction policy will not account for their memory footprint?

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.bigdata.cache.IGlobalLRU
IGlobalLRU.IGlobalLRUCounters, IGlobalLRU.ILRUCache<K,V>
 
Constructor Summary
HardReferenceGlobalLRURecycler(long maximumBytesInMemory, long minCleared, int minimumCacheSetCapacity, int initialCacheCapacity, float loadFactor)
           
 
Method Summary
 void deleteCache(UUID uuid)
          Remove the cache for the IRawStore from the set of caches maintained by this class and clear any entries in that cache.
 void discardAllCaches()
          Clear all per-IRawStore cache instances.
 long getBytesInMemory()
          The #of bytes in memory across all cache instances.
 IGlobalLRU.ILRUCache<K,V> getCache(UUID uuid, IAddressManager am)
          An canonicalizing factory for cache instances supporting random access to decompressed IDataRecords, higher-level data structures wrapping those decompressed data records (INodeData and ILeafData ), or objects deserialized from those IDataRecords.
 int getCacheSetSize()
          Return the #of cache instances.
 CounterSet getCounterSet()
          The counters for the global LRU.
 long getEvictionByteCount()
           
 long getEvictionCount()
          The #of records which have been evicted from memory to date across all cache instances.
 int getRecordCount()
          The #of records in memory across all cache instances.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HardReferenceGlobalLRURecycler

public HardReferenceGlobalLRURecycler(long maximumBytesInMemory,
                                      long minCleared,
                                      int minimumCacheSetCapacity,
                                      int initialCacheCapacity,
                                      float loadFactor)
Parameters:
maximumBytesInMemory - The maximum bytes in memory for the cached records across all cache instances.
minCleared - The minimum number of bytes that will be cleared when evicting the LRU entry. When zero, only as many records will be evicted as are necessary to bring the bytes in memory below the configured maximum. When greater than zero, "batch" evictions can be performed. For example, several MB worth of records can be evicted each time the LRU is at its maximum capacity.
minimumCacheSetCapacity - The #of per-IRawStore ILRUCache instances that will be maintained by hard references unless their cache is explicitly discarded.
initialCacheCapacity - The initial capacity of each new cache instance.
loadFactor - The load factor for the cache instances.
Method Detail

getCache

public IGlobalLRU.ILRUCache<K,V> getCache(UUID uuid,
                                          IAddressManager am)
Description copied from interface: IGlobalLRU
An canonicalizing factory for cache instances supporting random access to decompressed IDataRecords, higher-level data structures wrapping those decompressed data records (INodeData and ILeafData ), or objects deserialized from those IDataRecords.

Specified by:
getCache in interface IGlobalLRU<K,V>
Parameters:
uuid - The store's UUID.
am - The IAddressManager for that store (optional, but used to compute the bytes on disk for record and hence highly desired).
Returns:
The cache for records in the store.
See Also:
AbstractBTree.readNodeOrLeaf(long), IndexSegmentStore.reopen(), LRUNexus.getCache(IRawStore)

getRecordCount

public int getRecordCount()
Description copied from interface: IHardReferenceGlobalLRU
The #of records in memory across all cache instances.

Specified by:
getRecordCount in interface IHardReferenceGlobalLRU<K,V>

getEvictionCount

public long getEvictionCount()
Description copied from interface: IHardReferenceGlobalLRU
The #of records which have been evicted from memory to date across all cache instances.

Specified by:
getEvictionCount in interface IHardReferenceGlobalLRU<K,V>

getEvictionByteCount

public long getEvictionByteCount()

getBytesInMemory

public long getBytesInMemory()
Description copied from interface: IHardReferenceGlobalLRU
The #of bytes in memory across all cache instances.

Specified by:
getBytesInMemory in interface IHardReferenceGlobalLRU<K,V>

getCacheSetSize

public int getCacheSetSize()
Description copied from interface: IHardReferenceGlobalLRU
Return the #of cache instances.

Specified by:
getCacheSetSize in interface IHardReferenceGlobalLRU<K,V>

deleteCache

public void deleteCache(UUID uuid)
Description copied from interface: IGlobalLRU
Remove the cache for the IRawStore from the set of caches maintained by this class and clear any entries in that cache. This method SHOULD be used when the persistent resources for the store are deleted. It SHOULD NOT be used if a store is simply closed in a context when the store COULD be re-opened. In such cases, the cache for that store will be automatically released after it has become only weakly reachable.

Specified by:
deleteCache in interface IGlobalLRU<K,V>
Parameters:
uuid - The store's UUID.
See Also:
IRawStore.destroy(), IRawStore.deleteResources()

discardAllCaches

public void discardAllCaches()
Description copied from interface: IGlobalLRU
Clear all per-IRawStore cache instances. This may be used if all bigdata instances in the JVM are closed, but SHOULD NOT be invoked if you are just closing some IRawStore.

Specified by:
discardAllCaches in interface IGlobalLRU<K,V>

getCounterSet

public CounterSet getCounterSet()
Description copied from interface: IGlobalLRU
The counters for the global LRU.

Specified by:
getCounterSet in interface IGlobalLRU<K,V>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.