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

java.lang.Object
  extended by com.bigdata.cache.HardReferenceGlobalLRU<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 HardReferenceGlobalLRU<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. This implementation DOES NOT recycle the LRU Entry when it is evicted and therefore DOES NOT require us to obtain the lock before testing the inner LRUCacheImpl's map. In order to allow concurrent tests on that map, a ConcurrentHashMap is used. This allows higher concurrency on LRUCacheImpl#get(Object)l, but trades off by having a slower iterator. When compared to the HardReferenceGlobalLRURecycler, this implementation has approximately 10% higher throughput.

Version:
$Id: HardReferenceGlobalLRU.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
HardReferenceGlobalLRU(long maximumBytesInMemory, 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)
          Canonicalizing mapping and factory for a per-IRawStore cache instance.
 int getCacheSetSize()
          Return the #of cache instances.
 CounterSet getCounterSet()
          The counters for the global LRU.
 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

HardReferenceGlobalLRU

public HardReferenceGlobalLRU(long maximumBytesInMemory,
                              int minimumCacheSetCapacity,
                              int initialCacheCapacity,
                              float loadFactor)
Parameters:
maximumBytesInMemory - The maximum bytes in memory for the cached records across all cache instances.
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)
Canonicalizing mapping and factory for a per-IRawStore cache instance.

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>

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.