HPFile

Struct HPFile 

Source
pub struct HPFile { /* private fields */ }
Expand description

Head-prunable file

Implementations§

Source§

impl HPFile

Source

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 append will 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.
Source

pub fn empty() -> HPFile

Create an empty HPFile that has no function and can only be used as placeholder.

Source

pub fn is_empty(&self) -> bool

Returns whether this HPFile is empty.

Source

pub fn size(&self) -> i64

Returns the size of the virtual large file, including the non-flushed bytes

Source

pub fn size_on_disk(&self) -> i64

Returns the flushed size of the virtual large file

Source

pub fn truncate(&self, size: i64) -> Result<()>

Truncate the file to make it smaller

§Parameters
  • size: the size of the virtual large file after truncation. It must be smaller than the original size.
§Returns

A Result which is:

  • Ok: It’s truncated successfully
  • Err: Encounted some file system error.
Source

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.
Source

pub fn close(&self)

Close the opened small files

Source

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.

Source

pub fn read_at(&self, bz: &mut [u8], offset: i64) -> Result<usize>

Read data from file at offset to fill bz

§Parameters
  • offset: the start position of a byteslice that was written before
§Returns

A Result which is:

  • Ok: Number of bytes that was filled into bz
  • Err: Encounted some file system error.
Source

pub fn read_range(&self, buf: &mut [u8], offset: i64) -> Result<()>

Source

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.
Source

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_size specified 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.
Source

pub fn prune_head(&self, offset: i64) -> Result<()>

Prune from the beginning to offset. This part of the file cannot be read hereafter.

Trait Implementations§

Source§

impl Debug for HPFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for HPFile

§

impl !RefUnwindSafe for HPFile

§

impl Send for HPFile

§

impl Sync for HPFile

§

impl Unpin for HPFile

§

impl UnwindSafe for HPFile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.