@NotThreadSafe public final class LRFUEvictor extends AbstractEvictor
mAttenuationFactor
, t * mStepFactor
).
Each access to a block has a F(t) value and t is the time interval since that access to current.
As the formula of F(t) shows, when (1.0 / mStepFactor
) time units passed, F(t) will
cut to the (1.0 / mAttenuationFactor
) of the old value. So mStepFactor
controls the step and mAttenuationFactor
controls the attenuation. Actually, LRFU
combines LRU and LFU, it evicts blocks with small frequency or large recency. When
mStepFactor
is close to 0, LRFU is close to LFU. Conversely, LRFU is close to LRU
when mStepFactor
is close to 1.Evictor.Factory, Evictor.Mode
mAllocator, mMetadataView
Constructor and Description |
---|
LRFUEvictor(BlockMetadataEvictorView view,
Allocator allocator)
Creates a new instance of
LRFUEvictor . |
Modifier and Type | Method and Description |
---|---|
EvictionPlan |
freeSpaceWithView(long bytesToBeAvailable,
BlockStoreLocation location,
BlockMetadataEvictorView view,
Evictor.Mode mode)
Frees space in the given block store location and with the given view.
|
protected Iterator<Long> |
getBlockIterator()
Returns an iterator for evictor cache blocks.
|
void |
onAccessBlock(long userId,
long blockId)
Actions when accessing a block.
|
void |
onBlockLost(long blockId)
Actions when a block is lost.
|
void |
onCommitBlock(long userId,
long blockId,
BlockStoreLocation location)
Actions when committing a temporary block to a
BlockStoreLocation . |
void |
onRemoveBlockByClient(long userId,
long blockId)
Actions when removing an existing block.
|
void |
onRemoveBlockByWorker(long userId,
long blockId)
Actions when removing an existing block by worker.
|
protected void |
onRemoveBlockFromIterator(long blockId)
Performs additional cleanup when a block is removed from the iterator returned by
AbstractEvictor.getBlockIterator() . |
cascadingEvict, freeSpaceWithView, updateBlockStoreLocation
onAbortBlock, onMoveBlockByClient, onMoveBlockByWorker, onStorageLost
public LRFUEvictor(BlockMetadataEvictorView view, Allocator allocator)
LRFUEvictor
.view
- a view of block metadata informationallocator
- an allocation policy@Nullable public EvictionPlan freeSpaceWithView(long bytesToBeAvailable, BlockStoreLocation location, BlockMetadataEvictorView view, Evictor.Mode mode)
Evictor
StorageDir
in the location has the specific amount of free
space after eviction. The location can be a specific
StorageDir
, or BlockStoreLocation.anyTier()
or
BlockStoreLocation.anyDirInTier(String)
. The view is generated and passed by the
calling BlockStore
. This method returns null if Evictor
fails to propose a feasible plan to meet the requirement.
With the BEST_EFFORT mode, the evictor always returns an eviction plan with toMove and toEvict fields to indicate how to free space. Even if the tier does not have the amount of free space, the evictor returns the plan to free the max space.
If both toMove and toEvict of the plan are empty, it indicates that Evictor
has no
actions to take and the requirement is already met.
Throws an IllegalArgumentException
if the given block location is invalid.
freeSpaceWithView
in interface Evictor
freeSpaceWithView
in class AbstractEvictor
bytesToBeAvailable
- the amount of free space in bytes to be ensured after evictionlocation
- the location in block storeview
- generated and passed by block storemode
- the eviction modeEvictionPlan
(possibly with empty fields) to get the free space, or null
if no plan is feasibleprotected Iterator<Long> getBlockIterator()
AbstractEvictor
LRUEvictor
returns an iterator
that iterates through the block ids in LRU order.getBlockIterator
in class AbstractEvictor
public void onAccessBlock(long userId, long blockId)
BlockStoreEventListener
onAccessBlock
in interface BlockStoreEventListener
onAccessBlock
in class AbstractBlockStoreEventListener
userId
- the id of the session to access this blockblockId
- the id of the block to accesspublic void onCommitBlock(long userId, long blockId, BlockStoreLocation location)
BlockStoreEventListener
BlockStoreLocation
.onCommitBlock
in interface BlockStoreEventListener
onCommitBlock
in class AbstractBlockStoreEventListener
userId
- the id of the session to commit to this blockblockId
- the id of the block to commitlocation
- the location of the block to be committedpublic void onRemoveBlockByClient(long userId, long blockId)
BlockStoreEventListener
onRemoveBlockByClient
in interface BlockStoreEventListener
onRemoveBlockByClient
in class AbstractBlockStoreEventListener
userId
- the id of the session to remove this blockblockId
- the id of the block to be removedpublic void onRemoveBlockByWorker(long userId, long blockId)
BlockStoreEventListener
onRemoveBlockByWorker
in interface BlockStoreEventListener
onRemoveBlockByWorker
in class AbstractBlockStoreEventListener
userId
- the id of the session to remove this blockblockId
- the id of the block to be removedpublic void onBlockLost(long blockId)
BlockStoreEventListener
onBlockLost
in interface BlockStoreEventListener
onBlockLost
in class AbstractBlockStoreEventListener
blockId
- the id of the lost blockprotected void onRemoveBlockFromIterator(long blockId)
AbstractEvictor
AbstractEvictor.getBlockIterator()
.onRemoveBlockFromIterator
in class AbstractEvictor
Copyright © 2023. All Rights Reserved.