Class SegmentedEviction

  • All Implemented Interfaces:
    NeedsClose, Eviction

    public class SegmentedEviction
    extends Object
    implements Eviction
    Forwards eviction operations to segments based on the hash code.
    Author:
    Jens Wilke
    • Constructor Detail

      • SegmentedEviction

        public SegmentedEviction​(Eviction[] segments)
    • Method Detail

      • startNewIdleScanRound

        public long startNewIdleScanRound()
        Description copied from interface: Eviction
        Start new idle scan round and return current scan counter
        Specified by:
        startNewIdleScanRound in interface Eviction
        See Also:
        IdleScan
      • updateWeight

        public boolean updateWeight​(Entry e)
        Description copied from interface: Eviction
        Updates the weight on the entry and recalculates the total weight if needed.

        Expected not to hold the entry lock, which means, that this does not run in sync with the actual update. That is okay as long as it runs after every update.

        Since we need to lock the eviction structure, this can happen in a separate thread.

        Specified by:
        updateWeight in interface Eviction
        Returns:
        hint whether eviction should be run. for a bulk operation we want to do eviction once, so not do it within this method
      • submitWithoutTriggeringEviction

        public boolean submitWithoutTriggeringEviction​(Entry e)
        Description copied from interface: Eviction
        Submit to eviction for inserting or removing from the replacement list. However, eviction should not be triggered (which in turn triggers a hash table update) since the hash segment lock is hold at the moment.
        Specified by:
        submitWithoutTriggeringEviction in interface Eviction
      • evictEventuallyBeforeInsertOnSegment

        public void evictEventuallyBeforeInsertOnSegment​(int hashCodeHint)
        Description copied from interface: Eviction
        Evict if needed, focused on the segment addressed by the hash code. Called before a new entry is inserted (changed from after in v1.4)
        Specified by:
        evictEventuallyBeforeInsertOnSegment in interface Eviction
      • evictEventuallyBeforeInsert

        public void evictEventuallyBeforeInsert()
        Description copied from interface: Eviction
        Evict if needed, checks all segments. Called before a new entry is inserted (changed from after in v1.4)
        Specified by:
        evictEventuallyBeforeInsert in interface Eviction
      • evictEventually

        public void evictEventually()
        Description copied from interface: Eviction
        Evict if needed, checks all segments.
        Specified by:
        evictEventually in interface Eviction
      • evictIdleEntries

        public long evictIdleEntries​(int maxScan)
        Scan all segments for idlers. Maybe a round robin approach is more efficient.
        Specified by:
        evictIdleEntries in interface Eviction
        Returns:
        number of evicted entries
        See Also:
        IdleScan
      • removeAll

        public long removeAll()
        Description copied from interface: Eviction
        Remove all entries from the eviction data structure.
        Specified by:
        removeAll in interface Eviction
        Returns:
        entry count
      • runLocked

        public <T> T runLocked​(Supplier<T> j)
        Description copied from interface: Eviction
        Runs job making sure concurrent evictions operations pause.
        Specified by:
        runLocked in interface Eviction
      • getMetrics

        public EvictionMetrics getMetrics()
        Description copied from interface: Eviction
        Get metrics related to the eviction. No lock is needed before calling this method. Best efforts are made to extract consistent statistics and keep interruption short.
        Specified by:
        getMetrics in interface Eviction
      • changeCapacity

        public void changeCapacity​(long entryCountOrWeight)
        Description copied from interface: Eviction
        Change the capacity. If capacity is reduced, it will evict entries before returning.
        Specified by:
        changeCapacity in interface Eviction