Package org.terracotta.offheapstore
Class AbstractOffHeapClockCache<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.terracotta.offheapstore.OffHeapHashMap<K,V>
-
- org.terracotta.offheapstore.AbstractLockedOffHeapHashMap<K,V>
-
- org.terracotta.offheapstore.AbstractOffHeapClockCache<K,V>
-
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Implemented Interfaces:
java.util.concurrent.ConcurrentMap<K,V>,java.util.concurrent.locks.ReadWriteLock,java.util.Map<K,V>,HashingMap<K,V>,MapInternals,PinnableCache<K,V>,PinnableSegment<K,V>,Segment<K,V>,StorageEngine.Owner
- Direct Known Subclasses:
AbstractPersistentOffHeapCache,ReadWriteLockedOffHeapClockCache,WriteLockedOffHeapClockCache
public abstract class AbstractOffHeapClockCache<K,V> extends AbstractLockedOffHeapHashMap<K,V> implements PinnableCache<K,V>, PinnableSegment<K,V>
An abstract off-heap cache implementation.Subclasses must implement the two
getEvictionIndex(...)methods to instruct the cache regarding which mappings to remove.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.terracotta.offheapstore.AbstractLockedOffHeapHashMap
AbstractLockedOffHeapHashMap.LockedEntryIterator, AbstractLockedOffHeapHashMap.LockedEntrySet, AbstractLockedOffHeapHashMap.LockedKeyIterator, AbstractLockedOffHeapHashMap.LockedKeySet
-
Nested classes/interfaces inherited from class org.terracotta.offheapstore.OffHeapHashMap
OffHeapHashMap.DirectEntry, OffHeapHashMap.EncodingIterator, OffHeapHashMap.EncodingSet, OffHeapHashMap.EntryIterator, OffHeapHashMap.EntrySet, OffHeapHashMap.HashIterator<T>, OffHeapHashMap.KeyIterator, OffHeapHashMap.KeySet, OffHeapHashMap.PendingPage
-
-
Field Summary
Fields Modifier and Type Field Description private intclockHandprivate static org.slf4j.LoggerLOGGERprivate static intPRESENT_CLOCKprivate java.util.Randomrndm-
Fields inherited from class org.terracotta.offheapstore.OffHeapHashMap
ENCODING, ENTRY_BIT_SHIFT, ENTRY_SIZE, hashtable, hashTablePage, KEY_HASHCODE, modCount, removedSlots, reprobeLimit, RESERVED_STATUS_BITS, size, STATUS, STATUS_REMOVED, STATUS_USED, storageEngine, tableSource
-
-
Constructor Summary
Constructors Constructor Description AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine)AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine, int tableSize)AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine)AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, boolean bootstrap)AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize)AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize, boolean bootstrap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanevict(int index, boolean shrink)protected booleanevictable(int status)VgetAndPin(K key)intgetEvictionIndex()Return the table offset of the to be evicted mapping.private intgetEvictionIndex(int start, int length)Return the table offset of the to be evicted mapping within the given probe sequence.protected voidhit(int position, java.nio.IntBuffer entry)booleanisPinned(java.lang.Object key)VputPinned(K key, V value)voidsetPinning(K key, boolean pinned)protected voidstorageEngineFailure(java.lang.Object failure)protected voidtableExpansionFailure(int start, int length)-
Methods inherited from class org.terracotta.offheapstore.AbstractLockedOffHeapHashMap
clear, computeIfAbsentWithMetadata, computeIfPresentWithMetadata, computeWithMetadata, containsKey, createEntrySet, createKeySet, destroy, fill, fill, get, getAndSetMetadata, getEncodingForHashAndBinary, getMetadata, getValueAndSetMetadata, installMappingForHashAndEncoding, put, put, putIfAbsent, readLock, remove, remove, removeAllWithHash, removeMapping, removeNoReturn, replace, replace, shrink, size, writeLock
-
Methods inherited from class org.terracotta.offheapstore.OffHeapHashMap
added, createEncodingSet, encodingSet, entrySet, fill, freePendingTables, getAllocatedMemory, getAtTableOffset, getDataAllocatedMemory, getDataOccupiedMemory, getDataSize, getDataVitalMemory, getEntryAtTableOffset, getOccupiedMemory, getRemovedSlotCount, getReprobeLength, getSize, getSlotForHashAndEncoding, getStorageEngine, getTableCapacity, getUsedSlotCount, getVitalMemory, indexFor, indexFor, isAvailable, isPresent, isRemoved, isRemoved, isTerminating, isTerminating, isThiefForTableAllocations, keySet, readLong, readLong, removeAtTableOffset, removed, shrinkTable, spread, tryIncreaseReprobe, updated, updateEncoding
-
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Methods inherited from interface org.terracotta.offheapstore.HashingMap
removeAllWithHash
-
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
-
Methods inherited from interface org.terracotta.offheapstore.MapInternals
getAllocatedMemory, getDataAllocatedMemory, getDataOccupiedMemory, getDataSize, getDataVitalMemory, getOccupiedMemory, getRemovedSlotCount, getReprobeLength, getSize, getTableCapacity, getUsedSlotCount, getVitalMemory
-
Methods inherited from interface org.terracotta.offheapstore.Segment
computeIfAbsentWithMetadata, computeIfPresentWithMetadata, computeWithMetadata, destroy, fill, fill, getAndSetMetadata, getLock, getMetadata, getValueAndSetMetadata, put, removeNoReturn, shrink
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
PRESENT_CLOCK
private static final int PRESENT_CLOCK
- See Also:
- Constant Field Values
-
rndm
private final java.util.Random rndm
-
clockHand
private int clockHand
-
-
Constructor Detail
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine)
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine)
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, boolean bootstrap)
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize)
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine, int tableSize)
-
AbstractOffHeapClockCache
public AbstractOffHeapClockCache(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize, boolean bootstrap)
-
-
Method Detail
-
storageEngineFailure
protected void storageEngineFailure(java.lang.Object failure)
- Overrides:
storageEngineFailurein classOffHeapHashMap<K,V>
-
tableExpansionFailure
protected void tableExpansionFailure(int start, int length)- Overrides:
tableExpansionFailurein classOffHeapHashMap<K,V>
-
hit
protected void hit(int position, java.nio.IntBuffer entry)- Overrides:
hitin classOffHeapHashMap<K,V>
-
getEvictionIndex
public int getEvictionIndex()
Return the table offset of the to be evicted mapping.The mapping to be evicted can occur anywhere in this cache's table.
- Returns:
- table offset of the mapping to be evicted
-
getEvictionIndex
private int getEvictionIndex(int start, int length)Return the table offset of the to be evicted mapping within the given probe sequence.The mapping to be evicted must occur within the given probe sequence.
- Parameters:
start- initial slot in probe sequencelength- number of slots in probe sequence- Returns:
- table offset of the mapping to be evicted
-
evictable
protected boolean evictable(int status)
-
evict
public boolean evict(int index, boolean shrink)- Specified by:
evictin interfaceStorageEngine.Owner- Overrides:
evictin classAbstractLockedOffHeapHashMap<K,V>
-
isPinned
public boolean isPinned(java.lang.Object key)
- Specified by:
isPinnedin interfacePinnableCache<K,V>
-
setPinning
public void setPinning(K key, boolean pinned)
- Specified by:
setPinningin interfacePinnableCache<K,V>
-
putPinned
public V putPinned(K key, V value)
- Specified by:
putPinnedin interfacePinnableCache<K,V>
-
-