Package org.apache.sysds.runtime.ooc.cache.legacy

# Class OOCLRUCacheScheduler

java.lang.Object
org.apache.sysds.runtime.ooc.cache.legacy.OOCLRUCacheScheduler

All Implemented Interfaces:
  `OOCCacheScheduler`

public class OOCLRUCacheScheduler extends Object implements OOCCacheScheduler

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.apache.sysds.runtime.ooc.cache.legacy.OOCCacheScheduler

`OOCCacheScheduler.HandoverHandle`

## Constructor Summary

Constructors
Constructor
Description
`OOCLRUCacheScheduler(OOCIOHandler ioHandler, long evictionLimit, long hardLimit, long readBuffer)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addReference(BlockKey key)`
Notifies the cache that there is another reference to the same block key.
`void`
`forget(BlockKey key)`
Forgets a block from the cache.
`long`
`getCacheSize()`
Returns the current cache size in bytes.
`long`
`getHardLimit()`
Returns the hard cache limit in bytes.
`long`
`getPinnedBytes()`
Returns the number of pinned bytes in the cache.
`OOCCacheScheduler.HandoverHandle`
`handover(BlockKey key, InMemoryQueueCallback callback)`
`boolean`
`isWithinLimits()`
Returns if the current cache size is within its defined memory limits.
`boolean`
`isWithinSoftLimits()`
Returns if the current cache size is within its soft memory limits.
`void`
`pin(BlockEntry entry)`
Pins a BlockEntry in cache to prevent eviction.
`void`
`prioritize(BlockKey key, double priority)`
Adds the given priority to any pending request accessing the key.
`BlockKey`
`put(BlockKey key, Object data, long size)`
Places a new block in the cache.
`BlockEntry`
`putAndPin(BlockKey key, Object data, long size)`
Places a new block in the cache and returns a pinned handle.
`BlockEntry`
`putAndPinSourceBacked(BlockKey key, Object data, long size, OOCIOHandler.SourceBlockDescriptor descriptor)`
Places a new source-backed block in the cache and returns a pinned handle.
`void`
`putSourceBacked(BlockKey key, Object data, long size, OOCIOHandler.SourceBlockDescriptor descriptor)`
Places a new source-backed block in the cache and registers the location with the IO handler.
`CompletableFuture<List<BlockEntry>>`
`request(List<BlockKey> keys)`
Requests a list of blocks from the cache that must be available at the same time.
`CompletableFuture<List<BlockEntry>>`
`request(List<BlockKey> keys, boolean onlyIfAvailable)`
`CompletableFuture<BlockEntry>`
`request(BlockKey key)`
Requests a single block from the cache.
`CompletableFuture<List<BlockEntry>>`
`requestAnyOf(List<BlockKey> keys, int n, List<BlockKey> selectionOut)`
Requests any n entries of the list of blocks, preferring an available item.
`void`
`shutdown()`
Shuts down the cache scheduler.
`Collection<BlockEntry>`
`snapshot()`
Creates a snapshot of the cache.
`List<BlockEntry>`
`tryRequest(List<BlockKey> keys)`
Tries to request a list of blocks from the cache that must be available at the same time.
`List<BlockEntry>`
`tryRequestAnyOf(List<BlockKey> keys, int n, List<BlockKey> selectionOut)`
Requests any n entries of the list of blocks, preferring an available item.
`void`
`unpin(BlockEntry entry)`
Unpins a pinned block.
`void`
`updateLimits(long evictionLimit, long hardLimit)`
Updates the cache limits.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.sysds.runtime.ooc.cache.legacy.OOCCacheScheduler

`tryRequest`

## Constructor Details

### OOCLRUCacheScheduler

public OOCLRUCacheScheduler(OOCIOHandler ioHandler, long evictionLimit, long hardLimit, long readBuffer)

## Method Details

### request

public CompletableFuture<BlockEntry> request(BlockKey key)
Description copied from interface: `OOCCacheScheduler`
Requests a single block from the cache.

Specified by:
  `request` in interface `OOCCacheScheduler`
Parameters:
  `key` - the requested key associated to the block
Returns:
  the available BlockEntry

### tryRequest

public List<BlockEntry> tryRequest(List<BlockKey> keys)
Description copied from interface: `OOCCacheScheduler`
Tries to request a list of blocks from the cache that must be available at the same time. Immediately returns the list of entries if present, otherwise null without scheduling reads.

Specified by:
  `tryRequest` in interface `OOCCacheScheduler`
Parameters:
  `keys` - the requested keys associated to the block
Returns:
  the list of available BlockEntries

### requestAnyOf

public CompletableFuture<List<BlockEntry>> requestAnyOf(List<BlockKey> keys, int n, List<BlockKey> selectionOut)
Description copied from interface: `OOCCacheScheduler`
Requests any n entries of the list of blocks, preferring an available item.

Specified by:
  `requestAnyOf` in interface `OOCCacheScheduler`

### tryRequestAnyOf

public List<BlockEntry> tryRequestAnyOf(List<BlockKey> keys, int n, List<BlockKey> selectionOut)
Description copied from interface: `OOCCacheScheduler`
Requests any n entries of the list of blocks, preferring an available item.

Specified by:
  `tryRequestAnyOf` in interface `OOCCacheScheduler`

### request

public CompletableFuture<List<BlockEntry>> request(List<BlockKey> keys)
Description copied from interface: `OOCCacheScheduler`
Requests a list of blocks from the cache that must be available at the same time.

Specified by:
  `request` in interface `OOCCacheScheduler`
Parameters:
  `keys` - the requested keys associated to the block
Returns:
  the list of available BlockEntries

### request

public CompletableFuture<List<BlockEntry>> request(List<BlockKey> keys, boolean onlyIfAvailable)

### prioritize

public void prioritize(BlockKey key, double priority)
Description copied from interface: `OOCCacheScheduler`
Adds the given priority to any pending request accessing the key. Multi-requests are prioritized partially.

Specified by:
  `prioritize` in interface `OOCCacheScheduler`

### put

public BlockKey put(BlockKey key, Object data, long size)
Description copied from interface: `OOCCacheScheduler`
Places a new block in the cache. Note that objects are immutable and cannot be overwritten. The object data should now only be accessed via cache, as ownership has been transferred.

Specified by:
  `put` in interface `OOCCacheScheduler`
Parameters:
  `key` - the associated key of the block
  `data` - the block data
  `size` - the size of the data

### putAndPin

public BlockEntry putAndPin(BlockKey key, Object data, long size)
Description copied from interface: `OOCCacheScheduler`
Places a new block in the cache and returns a pinned handle. Note that objects are immutable and cannot be overwritten.

Specified by:
  `putAndPin` in interface `OOCCacheScheduler`
Parameters:
  `key` - the associated key of the block
  `data` - the block data
  `size` - the size of the data

### handover

public OOCCacheScheduler.HandoverHandle handover(BlockKey key, InMemoryQueueCallback callback)

Specified by:
  `handover` in interface `OOCCacheScheduler`

### putSourceBacked

public void putSourceBacked(BlockKey key, Object data, long size, OOCIOHandler.SourceBlockDescriptor descriptor)
Description copied from interface: `OOCCacheScheduler`
Places a new source-backed block in the cache and registers the location with the IO handler. The entry is treated as backed by disk, so eviction does not schedule spill writes.

Specified by:
  `putSourceBacked` in interface `OOCCacheScheduler`
Parameters:
  `key` - the associated key of the block
  `data` - the block data
  `size` - the size of the data
  `descriptor` - the source location descriptor

### putAndPinSourceBacked

public BlockEntry putAndPinSourceBacked(BlockKey key, Object data, long size, OOCIOHandler.SourceBlockDescriptor descriptor)
Description copied from interface: `OOCCacheScheduler`
Places a new source-backed block in the cache and returns a pinned handle.

Specified by:
  `putAndPinSourceBacked` in interface `OOCCacheScheduler`
Parameters:
  `key` - the associated key of the block
  `data` - the block data
  `size` - the size of the data
  `descriptor` - the source location descriptor

### addReference

public void addReference(BlockKey key)
Description copied from interface: `OOCCacheScheduler`
Notifies the cache that there is another reference to the same block key. This will prevent forget(key) from removing the block from cache. A block will only be forgotten after all referencing instances called forget(key).

Specified by:
  `addReference` in interface `OOCCacheScheduler`

### forget

public void forget(BlockKey key)
Description copied from interface: `OOCCacheScheduler`
Forgets a block from the cache.

Specified by:
  `forget` in interface `OOCCacheScheduler`
Parameters:
  `key` - the associated key of the block

### pin

public void pin(BlockEntry entry)
Description copied from interface: `OOCCacheScheduler`
Pins a BlockEntry in cache to prevent eviction.

Specified by:
  `pin` in interface `OOCCacheScheduler`
Parameters:
  `entry` - the entry to be pinned

### unpin

public void unpin(BlockEntry entry)
Description copied from interface: `OOCCacheScheduler`
Unpins a pinned block.

Specified by:
  `unpin` in interface `OOCCacheScheduler`
Parameters:
  `entry` - the entry to be unpinned

### getCacheSize

public long getCacheSize()
Description copied from interface: `OOCCacheScheduler`
Returns the current cache size in bytes.

Specified by:
  `getCacheSize` in interface `OOCCacheScheduler`

### getPinnedBytes

public long getPinnedBytes()
Description copied from interface: `OOCCacheScheduler`
Returns the number of pinned bytes in the cache.

Specified by:
  `getPinnedBytes` in interface `OOCCacheScheduler`

### getHardLimit

public long getHardLimit()
Description copied from interface: `OOCCacheScheduler`
Returns the hard cache limit in bytes.

Specified by:
  `getHardLimit` in interface `OOCCacheScheduler`

### isWithinLimits

public boolean isWithinLimits()
Description copied from interface: `OOCCacheScheduler`
Returns if the current cache size is within its defined memory limits.

Specified by:
  `isWithinLimits` in interface `OOCCacheScheduler`

### isWithinSoftLimits

public boolean isWithinSoftLimits()
Description copied from interface: `OOCCacheScheduler`
Returns if the current cache size is within its soft memory limits.

Specified by:
  `isWithinSoftLimits` in interface `OOCCacheScheduler`

### shutdown

public void shutdown()
Description copied from interface: `OOCCacheScheduler`
Shuts down the cache scheduler.

Specified by:
  `shutdown` in interface `OOCCacheScheduler`

### updateLimits

public void updateLimits(long evictionLimit, long hardLimit)
Description copied from interface: `OOCCacheScheduler`
Updates the cache limits.

Specified by:
  `updateLimits` in interface `OOCCacheScheduler`

### snapshot

public Collection<BlockEntry> snapshot()
Description copied from interface: `OOCCacheScheduler`
Creates a snapshot of the cache. Should only be used for debugging or diagnoses.

Specified by:
  `snapshot` in interface `OOCCacheScheduler`