Package io.debezium.util
Class BoundedConcurrentHashMap.LIRS<K,V>
java.lang.Object
io.debezium.util.BoundedConcurrentHashMap.LIRS<K,V>
- All Implemented Interfaces:
BoundedConcurrentHashMap.EvictionPolicy<K,
V>
- Enclosing class:
- BoundedConcurrentHashMap<K,
V>
static final class BoundedConcurrentHashMap.LIRS<K,V>
extends Object
implements BoundedConcurrentHashMap.EvictionPolicy<K,V>
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ConcurrentLinkedQueue<BoundedConcurrentHashMap.LIRSHashEntry<K,
V>> The accessQueue for reducing lock contention See "BP-Wrapper: a system framework making any replacement algorithms (almost) lock contention free"private final float
private final BoundedConcurrentHashMap.LIRSHashEntry<K,
V> This header encompasses two data structures:private int
The actual number of hot entries.private static final float
The percentage of the cache which is dedicated to hot blocks.private final int
The maxBatchQueueSizeprivate final int
The maximum number of hot entries (L_lirs in the paper).private final int
The maximum number of resident entries (L in the paper).private final BoundedConcurrentHashMap.Segment<K,
V> The owning segmentprivate int
The number of LIRS entries in a segmentFields inherited from interface io.debezium.util.BoundedConcurrentHashMap.EvictionPolicy
MAX_BATCH_SIZE
-
Constructor Summary
ConstructorDescriptionLIRS
(BoundedConcurrentHashMap.Segment<K, V> s, int capacity, int maxBatchSize, float batchThresholdFactor) -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
calculateLIRSize
(int maximumSize) void
clear()
Invoked to notify EvictionPolicy implementation that all Segment entries have been cleared.createNewEntry
(K key, int hash, BoundedConcurrentHashMap.HashEntry<K, V> next, V value) execute()
Invokes eviction policy algorithm and returns set of evicted entries.boolean
Invoked to notify EvictionPolicy implementation that an entry in Segment has been accessed.Invoked to notify EvictionPolicy implementation that there has been an attempt to access an entry in Segment, however that entry was not present in Segment.void
Invoked to notify EvictionPolicy implementation that an entry e has been removed from Segment.private void
pruneStack
(Set<BoundedConcurrentHashMap.HashEntry<K, V>> evicted) Prunes HIR blocks in the bottom of the stack until an HOT block sits in the stack bottom.private BoundedConcurrentHashMap.LIRSHashEntry<K,
V> queueEnd()
Returns the entry at the end of the queue.private BoundedConcurrentHashMap.LIRSHashEntry<K,
V> Returns the entry at the front of the queue.private void
removeFromSegment
(Set<BoundedConcurrentHashMap.HashEntry<K, V>> evicted) private BoundedConcurrentHashMap.LIRSHashEntry<K,
V> Returns the entry at the bottom of the stack.strategy()
Returns type of eviction algorithm (strategy).boolean
Returns true if batching threshold has expired, false otherwise.
-
Field Details
-
L_LIRS
private static final float L_LIRSThe percentage of the cache which is dedicated to hot blocks. See section 5.1- See Also:
-
segment
The owning segment -
accessQueue
The accessQueue for reducing lock contention See "BP-Wrapper: a system framework making any replacement algorithms (almost) lock contention free" http://www.cse.ohio-state.edu/hpcs/WWW/HTML/publications/abs09-1.html -
maxBatchQueueSize
private final int maxBatchQueueSizeThe maxBatchQueueSize See "BP-Wrapper: a system framework making any replacement algorithms (almost) lock contention free" -
size
private int sizeThe number of LIRS entries in a segment -
batchThresholdFactor
private final float batchThresholdFactor -
header
This header encompasses two data structures:- The LIRS stack, S, which is maintains recency information. All hot entries are on the stack. All cold and non-resident entries which are more recent than the least recent hot entry are also stored in the stack (the stack is always pruned such that the last entry is hot, and all entries accessed more recently than the last hot entry are present in the stack). The stack is ordered by recency, with its most recently accessed entry at the top, and its least recently accessed entry at the bottom.
- The LIRS queue, Q, which enqueues all cold entries for eviction. Cold entries (by definition in the queue) may be absent from the stack (due to pruning of the stack). Cold entries are added to the end of the queue and entries are evicted from the front of the queue.
-
maximumHotSize
private final int maximumHotSizeThe maximum number of hot entries (L_lirs in the paper). -
maximumSize
private final int maximumSizeThe maximum number of resident entries (L in the paper). -
hotSize
private int hotSizeThe actual number of hot entries.
-
-
Constructor Details
-
LIRS
public LIRS(BoundedConcurrentHashMap.Segment<K, V> s, int capacity, int maxBatchSize, float batchThresholdFactor)
-
-
Method Details
-
calculateLIRSize
private static int calculateLIRSize(int maximumSize) -
execute
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Invokes eviction policy algorithm and returns set of evicted entries. Set cannot be null but could possibly be an empty set.- Specified by:
execute
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Returns:
- set of evicted entries.
-
pruneStack
Prunes HIR blocks in the bottom of the stack until an HOT block sits in the stack bottom. If pruned blocks were resident, then they remain in the queue; otherwise they are no longer referenced, and are thus removed from the backing map. -
onEntryMiss
public Set<BoundedConcurrentHashMap.HashEntry<K,V>> onEntryMiss(BoundedConcurrentHashMap.HashEntry<K, V> en) Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Invoked to notify EvictionPolicy implementation that there has been an attempt to access an entry in Segment, however that entry was not present in Segment.- Specified by:
onEntryMiss
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Parameters:
en
- accessed entry in Segment- Returns:
- non null set of evicted entries.
-
removeFromSegment
-
onEntryHit
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Invoked to notify EvictionPolicy implementation that an entry in Segment has been accessed. Returns true if batching threshold has been reached, false otherwise. Note that this method is potentially invoked without holding a lock on Segment.- Specified by:
onEntryHit
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Parameters:
e
- accessed entry in Segment- Returns:
- true if batching threshold has been reached, false otherwise.
-
thresholdExpired
public boolean thresholdExpired()Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Returns true if batching threshold has expired, false otherwise. Note that this method is potentially invoked without holding a lock on Segment.- Specified by:
thresholdExpired
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Returns:
- true if batching threshold has expired, false otherwise.
-
onEntryRemove
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Invoked to notify EvictionPolicy implementation that an entry e has been removed from Segment.- Specified by:
onEntryRemove
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Parameters:
e
- removed entry in Segment
-
clear
public void clear()Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Invoked to notify EvictionPolicy implementation that all Segment entries have been cleared.- Specified by:
clear
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V>
-
strategy
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicy
Returns type of eviction algorithm (strategy).- Specified by:
strategy
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V> - Returns:
- type of eviction algorithm
-
stackBottom
Returns the entry at the bottom of the stack. -
queueFront
Returns the entry at the front of the queue. -
queueEnd
Returns the entry at the end of the queue. -
createNewEntry
public BoundedConcurrentHashMap.HashEntry<K,V> createNewEntry(K key, int hash, BoundedConcurrentHashMap.HashEntry<K, V> next, V value) - Specified by:
createNewEntry
in interfaceBoundedConcurrentHashMap.EvictionPolicy<K,
V>
-