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
impl InodeAwareReader
Sourcepub fn from_rotated_logs(path: impl AsRef<Path>) -> Result<Self>
pub fn from_rotated_logs(path: impl AsRef<Path>) -> Result<Self>
Construct InodeAwareMultireader searching for up to two rotated logs.
Sourcepub fn from_rotated_logs_with_depth(
path: impl AsRef<Path>,
max_depth: usize,
) -> Result<Self>
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.
Sourcepub fn get_persistent_offset(&self) -> InodeAwareOffset
pub fn get_persistent_offset(&self) -> InodeAwareOffset
Get offset that can be used across restarts and log rotations.
Sourcepub fn seek_persistent(&mut self, offset: InodeAwareOffset) -> Result<()>
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.
Sourcepub fn get_inodes(&self) -> &[u64]
pub fn get_inodes(&self) -> &[u64]
Get slice of inodes for current execution.
pub fn into_inner(self) -> (Multireader<BufReader<File>>, Vec<u64>)
Sourcepub fn get_current_inode(&self) -> u64
pub fn get_current_inode(&self) -> u64
Get inode of an item that is currently read.
Sourcepub fn get_item_index_by_inode(&self, inode: u64) -> Option<usize>
pub fn get_item_index_by_inode(&self, inode: u64) -> Option<usize>
Search for item index by given inode.
Sourcepub fn compare_offsets(
&self,
first: InodeAwareOffset,
second: InodeAwareOffset,
) -> Option<Ordering>
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>>>§
Sourcepub fn get_global_offset(&self) -> u64
pub fn get_global_offset(&self) -> u64
Offset amoung all underlying items.
Sourcepub fn get_local_offset(&self) -> u64
pub fn get_local_offset(&self) -> u64
Offset inside current item.
Sourcepub fn get_current_item_index(&self) -> usize
pub fn get_current_item_index(&self) -> usize
index of an item that is currently read.
Sourcepub fn get_total_size(&mut self) -> Result<u64>
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.
Sourcepub fn seek_current_item(&mut self, pos: SeekFrom) -> Result<u64>
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.
Sourcepub fn seek_to_item_start(&mut self, item_index: usize) -> Result<u64>
pub fn seek_to_item_start(&mut self, item_index: usize) -> Result<u64>
Perform seek to 0 offset in item identified by item_index.
Sourcepub fn seek_by_local_index(
&mut self,
item_index: usize,
pos: SeekFrom,
) -> Result<u64>
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.
Sourcepub fn get_current_item_size(&self) -> Option<u64>
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.
Sourcepub fn get_bytes_before_current_item(&self) -> u64
pub fn get_bytes_before_current_item(&self) -> u64
Computes global offset from which current item starts.
Sourcepub fn get_last_item_size(&mut self) -> Result<u64>
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.