com.bigdata.cache
Class WeakReferenceGlobalLRU

java.lang.Object
  extended by com.bigdata.cache.WeakReferenceGlobalLRU
All Implemented Interfaces:
IGlobalLRU<Long,Object>

public class WeakReferenceGlobalLRU
extends Object
implements IGlobalLRU<Long,Object>

Implementation based on a shared HardReferenceQueue and WeakReferences in per-store ConcurrentWeakValueCache instances.

This implementation IS NOT recommended. First, there is no need for the use of WeakReferences to manage the cache. Second, the very large ring buffer allows lots of duplicates and therefore can not make efficient use of memory (it can under fill the allocated buffer space, which makes configuration and more haphazard, and the eviction of an entry from the cache is somewhat unpredictable because the cache contains duplicates). The other problem with this implementation is that it requires an estimate of the average record size to pre-size the backing ring buffer, and the record size can vary quite a bit by application, coding, and branching factor. The alternative implementations do not have this limitation.

Version:
$Id: WeakReferenceGlobalLRU.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.bigdata.cache.IGlobalLRU
IGlobalLRU.IGlobalLRUCounters, IGlobalLRU.ILRUCache<K,V>
 
Constructor Summary
WeakReferenceGlobalLRU(long maximumMemoryFootprint, int minimumCacheSetCapacity, int queueCapacity, int nscan, int initialCapacity, float loadFactor, int concurrencyLevel)
          Constructor with caller specified parameters.
 
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()
          Discard all hard reference in the #getGlobalLRU().
 IGlobalLRU.ILRUCache<Long,Object> 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.
 CounterSet getCounterSet()
          The counters for the global LRU.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WeakReferenceGlobalLRU

public WeakReferenceGlobalLRU(long maximumMemoryFootprint,
                              int minimumCacheSetCapacity,
                              int queueCapacity,
                              int nscan,
                              int initialCapacity,
                              float loadFactor,
                              int concurrencyLevel)
Constructor with caller specified parameters.

Parameters:
maximumMemoryFootprint - The maximum in-memory footprint for the buffered IDataRecordAccess objects.
minimumCacheSetCapacity - The #of caches for which we will force retention. E.g., a value of N implies that hard references will be retained to the LRU cache for N stores. In practice, stores will typically hold a hard reference to their LRU cache instance so many more LRU cache instances MAY be retained.
queueCapacity - The IHardReferenceQueue capacity.
nscan - The #of entries on the IHardReferenceQueue to scan for a match before adding a reference.
initialCapacity - The initial capacity of the per-store hash maps.
loadFactor - The load factor for the per store hash maps.
concurrencyLevel - The concurrency level of the per-store hash maps.
Method Detail

getCache

public IGlobalLRU.ILRUCache<Long,Object> 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<Long,Object>
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)

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<Long,Object>
Parameters:
uuid - The store's UUID.
See Also:
IRawStore.destroy(), IRawStore.deleteResources()

discardAllCaches

public void discardAllCaches()
Discard all hard reference in the #getGlobalLRU(). The per-store caches are not deleted, but they will empty as their weak references are cleared by the JVM. Depending on the garbage collector, the JVM may delay clearing weak references for objects in the old generation until the next full GC. The LRUCounters will be updated as the entries are cleared from the backing weak reference value maps.

Specified by:
discardAllCaches in interface IGlobalLRU<Long,Object>

getCounterSet

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

Specified by:
getCounterSet in interface IGlobalLRU<Long,Object>

toString

public String toString()
Overrides:
toString in class Object


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