pub struct JournalFile<M>where
M: MemoryMap,{
pub seal_options: Option<SealOptions>,
/* private fields */
}Expand description
A reader for systemd journal files that efficiently maps small regions of the file into memory.
§Memory Management
This implementation uses a window-based memory mapping strategy similar to systemd’s original implementation. Instead of mapping the entire file, it maintains a small set of memory-mapped windows and reuses them as needed.
§Concurrency and Safety
JournalFile uses interior mutability to provide a safe API with the following characteristics:
- The window manager is wrapped in a
GuardedCellwhich owns both theWindowManagerand its guard flag, providing interior mutability with integrated guard-based exclusion. - The guard flag ensures only one object can be active at a time.
- Methods like
data_object()return aValueGuard<T>that automatically releases the guard when dropped.
This design ensures that memory safety is maintained even though references to memory-mapped regions could be invalidated when new objects are created.
Fields§
§seal_options: Option<SealOptions>Implementations§
Source§impl<M> JournalFile<M>where
M: MemoryMap,
impl<M> JournalFile<M>where
M: MemoryMap,
pub fn visit_bucket<'a, H, V>( &'a self, hash_table: Option<H>, hash: u64, visitor: V, ) -> Result<Option<<V as BucketVisitor<'a>>::Output>, JournalError>
pub fn open( file: &File, window_size: u64, ) -> Result<JournalFile<M>, JournalError>
pub fn open_with_strategy( file: &File, window_size: u64, strategy: ExperimentalMmapStrategy, ) -> Result<JournalFile<M>, JournalError>
pub fn open_path( path: impl AsRef<Path>, window_size: u64, ) -> Result<JournalFile<M>, JournalError>
pub fn open_path_with_strategy( path: impl AsRef<Path>, window_size: u64, strategy: ExperimentalMmapStrategy, ) -> Result<JournalFile<M>, JournalError>
pub fn open_snapshot( file: &File, window_size: u64, strategy: ExperimentalMmapStrategy, ) -> Result<JournalFile<M>, JournalError>
pub fn open_path_snapshot( path: impl AsRef<Path>, window_size: u64, strategy: ExperimentalMmapStrategy, ) -> Result<JournalFile<M>, JournalError>
pub fn file(&self) -> &File
pub fn hash(&self, data: &[u8]) -> u64
pub fn hash_parts(&self, payload: PayloadParts<'_>) -> u64
pub fn entry_list(&self) -> Option<List>
pub fn entry_offsets( &self, offsets: &mut Vec<NonZero<u64>>, ) -> Result<(), JournalError>
pub fn entry_data_object_offsets( &self, entry_offset: NonZero<u64>, offsets: &mut Vec<NonZero<u64>>, ) -> Result<(), JournalError>
pub fn journal_header_ref(&self) -> &JournalHeader
pub fn data_hash_table_map(&self) -> Option<&M>
pub fn field_hash_table_map(&self) -> Option<&M>
pub fn data_hash_table_ref(&self) -> Option<DataHashTable<&[u8]>>
pub fn field_hash_table_ref(&self) -> Option<FieldHashTable<&[u8]>>
pub fn object_header_ref( &self, position: NonZero<u64>, ) -> Result<&ObjectHeader, JournalError>
Sourcepub fn read_bytes_at(
&self,
offset: u64,
size: u64,
) -> Result<Vec<u8>, JournalError>
pub fn read_bytes_at( &self, offset: u64, size: u64, ) -> Result<Vec<u8>, JournalError>
Reads raw bytes from the file at the given offset. Returns a copied Vec so no borrow on the window manager is held.
pub fn offset_array_ref( &self, offset: NonZero<u64>, ) -> Result<ValueGuard<'_, OffsetArrayObject<&[u8]>>, JournalError>
pub fn field_ref( &self, offset: NonZero<u64>, ) -> Result<ValueGuard<'_, FieldObject<&[u8]>>, JournalError>
pub fn entry_ref( &self, offset: NonZero<u64>, ) -> Result<ValueGuard<'_, EntryObject<&[u8]>>, JournalError>
pub fn data_ref( &self, offset: NonZero<u64>, ) -> Result<ValueGuard<'_, DataObject<&[u8]>>, JournalError>
pub fn tag_ref( &self, offset: NonZero<u64>, ) -> Result<ValueGuard<'_, TagObject<&[u8]>>, JournalError>
pub fn find_field_offset( &self, hash: u64, payload: &[u8], ) -> Result<Option<NonZero<u64>>, JournalError>
Sourcepub fn data_object_directed_partition_point<F>(
&self,
data_offset: NonZero<u64>,
predicate: F,
direction: Direction,
) -> Result<Option<NonZero<u64>>, JournalError>
pub fn data_object_directed_partition_point<F>( &self, data_offset: NonZero<u64>, predicate: F, direction: Direction, ) -> Result<Option<NonZero<u64>>, JournalError>
Run a directed partition point query on a data object’s entry array
This finds the first/last entry (depending on direction) that satisfies the given predicate in the entry array chain of the data object.
Sourcepub fn fields(&self) -> FieldIterator<'_, M>
pub fn fields(&self) -> FieldIterator<'_, M>
Creates an iterator over all field objects in the field hash table
Sourcepub fn field_data_objects<'a>(
&'a self,
field_name: &'a [u8],
) -> Result<FieldDataIterator<'a, M>, JournalError>
pub fn field_data_objects<'a>( &'a self, field_name: &'a [u8], ) -> Result<FieldDataIterator<'a, M>, JournalError>
Creates an iterator over all DATA objects for the specified field
Sourcepub fn field_data_objects_with_offsets<'a>(
&'a self,
field_name: &'a [u8],
) -> Result<FieldDataOffsetIterator<'a, M>, JournalError>
pub fn field_data_objects_with_offsets<'a>( &'a self, field_name: &'a [u8], ) -> Result<FieldDataOffsetIterator<'a, M>, JournalError>
Creates an iterator over all DATA objects for the specified field, including the on-disk DATA object offset.
Sourcepub fn entry_data_objects(
&self,
entry_offset: NonZero<u64>,
) -> Result<EntryDataIterator<'_, M>, JournalError>
pub fn entry_data_objects( &self, entry_offset: NonZero<u64>, ) -> Result<EntryDataIterator<'_, M>, JournalError>
Creates an iterator over all DATA objects for a specific entry
Sourcepub fn bucket_utilization(&self) -> Option<BucketUtilization>
pub fn bucket_utilization(&self) -> Option<BucketUtilization>
Get hash table bucket utilization statistics
Source§impl JournalFile<MmapMut>
impl JournalFile<MmapMut>
pub fn open_for_append( file: &File, window_size: u64, ) -> Result<JournalFile<MmapMut>, JournalError>
Source§impl<M> JournalFile<M>where
M: MemoryMapMut,
impl<M> JournalFile<M>where
M: MemoryMapMut,
Sourcepub fn sync(&mut self) -> Result<(), JournalError>
pub fn sync(&mut self) -> Result<(), JournalError>
Syncs all file data to disk, ensuring all changes are persisted
This performs a two-step sync process:
- Flushes memory-mapped regions to the file page cache (msync)
- Syncs the file page cache to physical disk (fdatasync)
Sourcepub fn post_change(&mut self) -> Result<(), JournalError>
pub fn post_change(&mut self) -> Result<(), JournalError>
Trigger a stock-reader-visible post-change notification after mmap append.
Sourcepub fn create_successor(
&self,
file: &File,
max_file_size: Option<u64>,
) -> Result<JournalFile<M>, JournalError>
pub fn create_successor( &self, file: &File, max_file_size: Option<u64>, ) -> Result<JournalFile<M>, JournalError>
Creates a successor journal file with optimized bucket sizes based on this file’s utilization