java.io.Closeable, java.lang.AutoCloseable, BlockCachepublic class SingleFilePerBlockCache extends java.lang.Object implements BlockCache
| Constructor | Description |
|---|---|
SingleFilePerBlockCache(PrefetchingStatistics prefetchingStatistics,
int maxBlocksCount,
DurationTrackerFactory trackerFactory) |
Constructs an instance of a
SingleFilePerBlockCache. |
| Modifier and Type | Method | Description |
|---|---|---|
java.lang.Iterable<java.lang.Integer> |
blocks() |
Gets the blocks in this cache.
|
void |
close() |
|
boolean |
containsBlock(int blockNumber) |
Indicates whether the given block is in this cache.
|
void |
get(int blockNumber,
java.nio.ByteBuffer buffer) |
Gets the block having the given
blockNumber. |
protected java.nio.file.Path |
getCacheFilePath(Configuration conf,
LocalDirAllocator localDirAllocator) |
Return temporary file created based on the file path retrieved from local dir allocator.
|
static boolean |
isCacheSpaceAvailable(long fileSize,
Configuration conf,
LocalDirAllocator localDirAllocator) |
Determine if the cache space is available on the local FS.
|
void |
put(int blockNumber,
java.nio.ByteBuffer buffer,
Configuration conf,
LocalDirAllocator localDirAllocator) |
Puts the given block in this cache.
|
protected int |
readFile(java.nio.file.Path path,
java.nio.ByteBuffer buffer) |
|
int |
size() |
Gets the number of blocks in this cache.
|
java.lang.String |
toString() |
|
protected void |
writeFile(java.nio.file.Path path,
java.nio.ByteBuffer buffer) |
public SingleFilePerBlockCache(PrefetchingStatistics prefetchingStatistics, int maxBlocksCount, DurationTrackerFactory trackerFactory)
SingleFilePerBlockCache.prefetchingStatistics - statistics for this stream.maxBlocksCount - max blocks count to be kept in cache at any time.trackerFactory - tracker with statistics to updatepublic boolean containsBlock(int blockNumber)
containsBlock in interface BlockCacheblockNumber - the id of the given block.public java.lang.Iterable<java.lang.Integer> blocks()
blocks in interface BlockCachepublic int size()
size in interface BlockCachepublic void get(int blockNumber,
java.nio.ByteBuffer buffer)
throws java.io.IOException
blockNumber.get in interface BlockCacheblockNumber - the id of the desired block.buffer - contents of the desired block are copied to this buffer.java.lang.IllegalArgumentException - if buffer is null.java.io.IOException - if there is an error reading the given block.protected int readFile(java.nio.file.Path path,
java.nio.ByteBuffer buffer)
throws java.io.IOException
java.io.IOExceptionpublic void put(int blockNumber,
java.nio.ByteBuffer buffer,
Configuration conf,
LocalDirAllocator localDirAllocator)
throws java.io.IOException
put in interface BlockCacheblockNumber - the block number, used as a key for blocks map.buffer - buffer contents of the given block to be added to this cache.conf - the configuration.localDirAllocator - the local dir allocator instance.java.io.IOException - if either local dir allocator fails to allocate file or if IO error
occurs while writing the buffer content to the file.java.lang.IllegalArgumentException - if buffer is null, or if buffer.limit() is zero or negative.protected void writeFile(java.nio.file.Path path,
java.nio.ByteBuffer buffer)
throws java.io.IOException
java.io.IOExceptionprotected java.nio.file.Path getCacheFilePath(Configuration conf, LocalDirAllocator localDirAllocator) throws java.io.IOException
conf - The configuration object.localDirAllocator - Local dir allocator instance.java.io.IOException - if IO error occurs while local dir allocator tries to retrieve path
from local FS or file creation fails or permission set fails.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic static boolean isCacheSpaceAvailable(long fileSize,
Configuration conf,
LocalDirAllocator localDirAllocator)
fileSize - The size of the file.conf - The configuration.localDirAllocator - Local dir allocator instance.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.