pub struct HPFile { /* private fields */ }Expand description
Head-prunable file
Implementations§
Source§impl HPFile
 
impl HPFile
Sourcepub fn new(
    wr_buf_size: i64,
    segment_size: i64,
    dir_name: String,
    directio: bool,
) -> Result<HPFile>
 
pub fn new( wr_buf_size: i64, segment_size: i64, dir_name: String, directio: bool, ) -> Result<HPFile>
Create a HPFile with a directory. If this directory was used by an old HPFile, the old
HPFile must have the same segment_size as this one.
§Parameters
- wr_buf_size: The write buffer used in- appendwill not exceed this size
- segment_size: The target size of the small files
- dir_name: The name of the directory used to store the small files
- directio: Enable directio for readonly files (only use this feature on Linux)
§Returns
A Result which is:
- Ok: A successfully initialized- HPFile
- Err: Encounted some file system error.
Sourcepub fn empty() -> HPFile
 
pub fn empty() -> HPFile
Create an empty HPFile that has no function and can only be used as placeholder.
Sourcepub fn size(&self) -> i64
 
pub fn size(&self) -> i64
Returns the size of the virtual large file, including the non-flushed bytes
Sourcepub fn size_on_disk(&self) -> i64
 
pub fn size_on_disk(&self) -> i64
Returns the flushed size of the virtual large file
Sourcepub fn flush(&self, buffer: &mut Vec<u8>, eof: bool) -> Result<()>
 
pub fn flush(&self, buffer: &mut Vec<u8>, eof: bool) -> Result<()>
Flush the remained data in buffer into file system
§Parameters
- buffer: the write buffer, which is used by the client to call- append.
- eof: indicates if this is the end of file. If so, padding may be added for alignment.
§Returns
A Result which is:
- Ok: It’s flushed successfully
- Err: Encounted some file system error.
Sourcepub fn get_file_and_pos(&self, offset: i64) -> (Arc<(File, bool)>, i64)
 
pub fn get_file_and_pos(&self, offset: i64) -> (Arc<(File, bool)>, i64)
Returns the corresponding file and in-file position given a logical offset. When we use io_uring to read data from HPFile, the underlying segment files must be exposed.
§Parameters
- offset: a logical offset of this HPFile
§Returns
A tuple. Its first entry is the underlying File and its readonly attribute, and its sencond entry is the position within this underlying File.
pub fn read_range(&self, buf: &mut [u8], offset: i64) -> Result<()>
Sourcepub fn read_at_with_pre_reader(
    &self,
    buf: &mut Vec<u8>,
    num_bytes: usize,
    offset: i64,
    pre_reader: &mut PreReader,
) -> Result<usize>
 
pub fn read_at_with_pre_reader( &self, buf: &mut Vec<u8>, num_bytes: usize, offset: i64, pre_reader: &mut PreReader, ) -> Result<usize>
Read at most num_bytes from file at offset to fill buf
§Parameters
- buf: a vector to be filled
- num_bytes: the wanted number of bytes to be read
- offset: the start position of a byteslice that was written before
- pre_reader: a PreReader used to take advantage of spatial locality
§Returns
A Result which is:
- Ok: Number of bytes that was filled into- buf
- Err: Encounted some file system error.
Sourcepub fn append(&self, bz: &[u8], buffer: &mut Vec<u8>) -> Result<i64>
 
pub fn append(&self, bz: &[u8], buffer: &mut Vec<u8>) -> Result<i64>
Append a byteslice to the file. This byteslice may be temporarily held in
buffer before flushing.
§Parameters
- bz: the byteslice to append. It cannot be longer than- wr_buf_sizespecified in- HPFile::new.
- buffer: the write buffer. It will never be larger than- wr_buf_size.
§Returns
A Result which is:
- Ok: the start position where this byteslice locates in the file
- Err: Encounted some file system error.
Sourcepub fn prune_head(&self, offset: i64) -> Result<()>
 
pub fn prune_head(&self, offset: i64) -> Result<()>
Prune from the beginning to offset. This part of the file cannot be read hereafter.