@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, wait
usesSharedMemory
private 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
IOException
public boolean isPersistent()
isPersistent
in interface IOEngine
public Cacheable read(long offset, int length, CacheableDeserializer<Cacheable> deserializer) throws IOException
read
in interface IOEngine
offset
- 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.IOException
void closeFileChannels()
public void write(ByteBuffer srcBuffer, long offset) throws IOException
write
in interface IOEngine
srcBuffer
- the given byte buffer from which bytes are to be readoffset
- The offset in the file where the first byte to be writtenIOException
public void sync() throws IOException
sync
in interface IOEngine
IOException
public void write(ByteBuff srcBuffer, long offset) throws IOException
IOEngine
write
in interface IOEngine
srcBuffer
- the given MultiBytebufffers from which bytes are to be readoffset
- the offset in the IO engine where the first byte to be writtenIOException
private void accessFile(FileIOEngine.FileAccessor accessor, ByteBuffer buffer, long globalOffset) throws IOException
IOException
private long getAbsoluteOffsetInFile(int fileNum, long globalOffset)
fileNum
- globalOffset
- private int getFileNum(long offset)
FileChannel[] getFileChannels()
void refreshFileConnection(int accessFileNum, IOException ioe) throws IOException
IOException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.