InodeAwareReader

Struct InodeAwareReader 

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

Reader that keeps track of what inode it reads from.

This reader supports persistent indexing using InodeAwareOffset. It allows easy persistent reading of rotated logs. Scheme of persistent is to be implemented by user. For a ready-to-use recipe with simple file storage see TrackedReader.

let mut reader = InodeAwareReader::from_rotated_logs("/var/log/mail.log")?;
reader.seek_persistent(load_state()?)?;
reader.read_exact(& mut buf)?;
save_state(reader.get_persistent_offset())?;

During initialization, this reader searches for rotated versions of provided path and notes their inodes. After that inodes can be used for simple persistent indexing when combined with local offset.

Implementations§

Source§

impl InodeAwareReader

Source

pub fn from_rotated_logs(path: impl AsRef<Path>) -> Result<Self>

Construct InodeAwareMultireader searching for up to two rotated logs.

Source

pub fn from_rotated_logs_with_depth( path: impl AsRef<Path>, max_depth: usize, ) -> Result<Self>

Construct InodeAwareMultireader searching for up to max_depth rotated logs.

Source

pub fn get_persistent_offset(&self) -> InodeAwareOffset

Get offset that can be used across restarts and log rotations.

Source

pub fn seek_persistent(&mut self, offset: InodeAwareOffset) -> Result<()>

Seek by persistent offset.

Will return NotFound io error if file with given inode was not found.

Source

pub fn get_inodes(&self) -> &[u64]

Get slice of inodes for current execution.

Source

pub fn into_inner(self) -> (Multireader<BufReader<File>>, Vec<u64>)

Source

pub fn get_current_inode(&self) -> u64

Get inode of an item that is currently read.

Source

pub fn get_item_index_by_inode(&self, inode: u64) -> Option<usize>

Search for item index by given inode.

Source

pub fn compare_offsets( &self, first: InodeAwareOffset, second: InodeAwareOffset, ) -> Option<Ordering>

Compare two offsets as if they were pointing into one large buffer. Returns None if any of the offsets do not belong to underlying files.

Methods from Deref<Target = Multireader<BufReader<File>>>§

Source

pub fn get_global_offset(&self) -> u64

Offset amoung all underlying items.

Source

pub fn get_local_offset(&self) -> u64

Offset inside current item.

Source

pub fn len(&self) -> usize

Number of underlying items.

Source

pub fn get_current_item_index(&self) -> usize

index of an item that is currently read.

Source

pub fn get_total_size(&mut self) -> Result<u64>

Get total size of underlying items.

Computes total size of underlying items. This method requires mut ref and returns io::Result because we need to seek inside last item to determine its size at the moment of call.

Source

pub fn seek_current_item(&mut self, pos: SeekFrom) -> Result<u64>

Seek current underlying reader properly updating any internal state.

Returns current local offset after seek.

Source

pub fn seek_to_item_start(&mut self, item_index: usize) -> Result<u64>

Perform seek to 0 offset in item identified by item_index.

Source

pub fn seek_by_local_index( &mut self, item_index: usize, pos: SeekFrom, ) -> Result<u64>

Seek globally by providing local pos inside item at index item_index.

Provided pos must be inside indexed item. Returns current local offset.

Source

pub fn get_current_item_size(&self) -> Option<u64>

Returns item size of item. If it is last, returns None instead.

To determine size of last item, use get_last_item_size.

Source

pub fn get_bytes_before_current_item(&self) -> u64

Computes global offset from which current item starts.

Source

pub fn get_last_item_size(&mut self) -> Result<u64>

Computes last item size.

Last file in this reader may still be written into, so this number may soon become invalid.

Trait Implementations§

Source§

impl Deref for InodeAwareReader

Source§

type Target = Multireader<BufReader<File>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for InodeAwareReader

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.