@InterfaceAudience.Private public class FileIOEngine extends Object implements IOEngine
| Modifier and Type | Class and Description |
|---|---|
private static interface |
FileIOEngine.FileAccessor |
private static class |
FileIOEngine.FileReadAccessor |
private static class |
FileIOEngine.FileWriteAccessor |
| Modifier and Type | Field and Description |
|---|---|
private long |
capacity |
private ReentrantLock[] |
channelLocks |
static String |
FILE_DELIMITER |
private FileChannel[] |
fileChannels |
private String[] |
filePaths |
private static org.slf4j.Logger |
LOG |
private RandomAccessFile[] |
rafs |
private FileIOEngine.FileReadAccessor |
readAccessor |
private long |
sizePerFile |
private FileIOEngine.FileWriteAccessor |
writeAccessor |
| Constructor and Description |
|---|
FileIOEngine(long capacity,
boolean maintainPersistence,
String... filePaths) |
| Modifier and Type | Method and Description |
|---|---|
private void |
accessFile(FileIOEngine.FileAccessor accessor,
ByteBuffer buffer,
long globalOffset) |
(package private) void |
closeFileChannels() |
private long |
getAbsoluteOffsetInFile(int fileNum,
long globalOffset)
Get the absolute offset in given file with the relative global offset.
|
(package private) FileChannel[] |
getFileChannels() |
private int |
getFileNum(long offset) |
boolean |
isPersistent()
File IO engine is always able to support persistent storage for the cache
|
Cacheable |
read(long offset,
int length,
CacheableDeserializer<Cacheable> deserializer)
Transfers data from file to the given byte buffer
|
(package private) void |
refreshFileConnection(int accessFileNum,
IOException ioe) |
void |
shutdown()
Close the file
|
void |
sync()
Sync the data to file after writing
|
String |
toString() |
void |
write(ByteBuffer srcBuffer,
long offset)
Transfers data from the given byte buffer to file
|
void |
write(ByteBuff srcBuffer,
long offset)
Transfers the data from the given MultiByteBuffer to IOEngine
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitusesSharedMemoryprivate static final org.slf4j.Logger LOG
public static final String FILE_DELIMITER
private final FileChannel[] fileChannels
private final RandomAccessFile[] rafs
private final ReentrantLock[] channelLocks
private final long sizePerFile
private final long capacity
private FileIOEngine.FileReadAccessor readAccessor
private FileIOEngine.FileWriteAccessor writeAccessor
public FileIOEngine(long capacity, boolean maintainPersistence, String... filePaths) throws IOException
IOExceptionpublic boolean isPersistent()
isPersistent in interface IOEnginepublic Cacheable read(long offset, int length, CacheableDeserializer<Cacheable> deserializer) throws IOException
read in interface IOEngineoffset - The offset in the file where the first byte to be readlength - The length of buffer that should be allocated for reading
from the file channeldeserializer - The deserializer to be used to make a Cacheable from the data.IOExceptionvoid closeFileChannels()
public void write(ByteBuffer srcBuffer, long offset) throws IOException
write in interface IOEnginesrcBuffer - the given byte buffer from which bytes are to be readoffset - The offset in the file where the first byte to be writtenIOExceptionpublic void sync() throws IOException
sync in interface IOEngineIOExceptionpublic void write(ByteBuff srcBuffer, long offset) throws IOException
IOEnginewrite in interface IOEnginesrcBuffer - the given MultiBytebufffers from which bytes are to be readoffset - the offset in the IO engine where the first byte to be writtenIOExceptionprivate void accessFile(FileIOEngine.FileAccessor accessor, ByteBuffer buffer, long globalOffset) throws IOException
IOExceptionprivate long getAbsoluteOffsetInFile(int fileNum, long globalOffset)
fileNum - globalOffset - private int getFileNum(long offset)
FileChannel[] getFileChannels()
void refreshFileConnection(int accessFileNum, IOException ioe) throws IOException
IOExceptionCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.