Class BlockManager
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BlockManager
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
CachingBlockManager
Provides read access to the underlying file one block at a time.
This class is the simplest form of a
BlockManager that does
perform prefetching or caching.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRequests cancellation of any previously issued prefetch requests.voidclose()get(int blockNumber) Gets the block having the givenblockNumber.Gets block data information.abstract intread(ByteBuffer buffer, long startOffset, int size) Reads into the givenbuffersizebytes from the underlying file starting atstartOffset.voidrelease(BufferData data) Releases resources allocated to the given block.voidrequestCaching(BufferData data) Requests that the given block should be copied to the cache.voidrequestPrefetch(int blockNumber) Requests optional prefetching of the given block.
-
Constructor Details
-
BlockManager
Constructs an instance ofBlockManager.- Parameters:
blockData- information about each block of the underlying file.- Throws:
IllegalArgumentException- if blockData is null.
-
-
Method Details
-
getBlockData
Gets block data information.- Returns:
- instance of
BlockData.
-
get
Gets the block having the givenblockNumber. The entire block is read into memory and returned as aBufferData. The blocks are treated as a limited resource and must be released when one is done reading them.- Parameters:
blockNumber- the number of the block to be read and returned.- Returns:
BufferDatahaving data from the given block.- Throws:
IOException- if there an error reading the given block.IllegalArgumentException- if blockNumber is negative.
-
read
Reads into the givenbuffersizebytes from the underlying file starting atstartOffset.- Parameters:
buffer- the buffer to read data in to.startOffset- the offset at which reading starts.size- the number bytes to read.- Returns:
- number of bytes read.
- Throws:
IOException- if there an error reading the given block.
-
release
Releases resources allocated to the given block.- Parameters:
data- theBufferDatato release.- Throws:
IllegalArgumentException- if data is null.
-
requestPrefetch
public void requestPrefetch(int blockNumber) Requests optional prefetching of the given block.- Parameters:
blockNumber- the id of the block to prefetch.- Throws:
IllegalArgumentException- if blockNumber is negative.
-
cancelPrefetches
public void cancelPrefetches()Requests cancellation of any previously issued prefetch requests. -
requestCaching
Requests that the given block should be copied to the cache. Optional operation.- Parameters:
data- theBufferDatainstance to optionally cache.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-