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 inappendwill not exceed this sizesegment_size: The target size of the small filesdir_name: The name of the directory used to store the small filesdirectio: Enable directio for readonly files (only use this feature on Linux)
§Returns
A Result which is:
Ok: A successfully initializedHPFileErr: 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 callappend.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 successfullyErr: 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 fillednum_bytes: the wanted number of bytes to be readoffset: the start position of a byteslice that was written beforepre_reader: a PreReader used to take advantage of spatial locality
§Returns
A Result which is:
Ok: Number of bytes that was filled intobufErr: 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 thanwr_buf_sizespecified inHPFile::new.buffer: the write buffer. It will never be larger thanwr_buf_size.
§Returns
A Result which is:
Ok: the start position where this byteslice locates in the fileErr: 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.