Skip to main content

LogRead

Trait LogRead 

Source
pub trait LogRead {
    // Required methods
    fn scan_with_options<'life0, 'async_trait>(
        &'life0 self,
        key: Bytes,
        seq_range: impl 'async_trait + RangeBounds<Sequence> + Send,
        options: ScanOptions,
    ) -> Pin<Box<dyn Future<Output = Result<LogIterator>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn count_with_options<'life0, 'async_trait>(
        &'life0 self,
        key: Bytes,
        seq_range: impl 'async_trait + RangeBounds<Sequence> + Send,
        options: CountOptions,
    ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list_keys<'life0, 'async_trait>(
        &'life0 self,
        segment_range: impl 'async_trait + RangeBounds<SegmentId> + Send,
    ) -> Pin<Box<dyn Future<Output = Result<LogKeyIterator>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list_segments<'life0, 'async_trait>(
        &'life0 self,
        seq_range: impl 'async_trait + RangeBounds<Sequence> + Send,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Segment>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn scan<'life0, 'async_trait>(
        &'life0 self,
        key: Bytes,
        seq_range: impl 'async_trait + RangeBounds<Sequence> + Send,
    ) -> Pin<Box<dyn Future<Output = Result<LogIterator>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn count<'life0, 'async_trait>(
        &'life0 self,
        key: Bytes,
        seq_range: impl 'async_trait + RangeBounds<Sequence> + Send,
    ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for read operations on the log.

This trait defines the common read interface shared by LogDb and LogDbReader. It provides methods for scanning entries and counting records within a key’s log.

§Implementors

  • LogDb: The main log interface with both read and write access.
  • LogDbReader: A read-only view of the log.

§Example

use log::{LogRead, Result};
use bytes::Bytes;

async fn process_log(reader: &(impl LogRead + Sync)) -> Result<()> {
    let mut iter = reader.scan(Bytes::from("orders"), ..).await?;
    while let Some(entry) = iter.next().await? {
        println!("seq={}: {:?}", entry.sequence, entry.value);
    }
    Ok(())
}

Required Methods§

Source

fn scan_with_options<'life0, 'async_trait>( &'life0 self, key: Bytes, seq_range: impl 'async_trait + RangeBounds<Sequence> + Send, options: ScanOptions, ) -> Pin<Box<dyn Future<Output = Result<LogIterator>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Scans entries for a key within a sequence number range with custom options.

Returns an iterator that yields entries in sequence number order. See scan for read visibility semantics.

§Arguments
  • key - The key identifying the log stream to scan.
  • seq_range - The sequence number range to scan.
  • options - Scan options controlling read behavior.
§Errors

Returns an error if the scan fails due to storage issues.

Source

fn count_with_options<'life0, 'async_trait>( &'life0 self, key: Bytes, seq_range: impl 'async_trait + RangeBounds<Sequence> + Send, options: CountOptions, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Counts entries for a key within a sequence number range with custom options.

§Arguments
  • key - The key identifying the log stream to count.
  • seq_range - The sequence number range to count.
  • options - Count options, including whether to return an approximate count.
§Errors

Returns an error if the count fails due to storage issues.

Source

fn list_keys<'life0, 'async_trait>( &'life0 self, segment_range: impl 'async_trait + RangeBounds<SegmentId> + Send, ) -> Pin<Box<dyn Future<Output = Result<LogKeyIterator>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists distinct keys within a segment range.

Returns an iterator over keys that have entries in the specified segments. Each key is returned exactly once, even if it appears in multiple segments.

Pass .. to list keys from all segments.

§Arguments
  • segment_range - The segment ID range to list keys from.
§Errors

Returns an error if the list operation fails due to storage issues.

§Example
// List all keys
let mut iter = log.list_keys(..).await?;

// List keys from specific segments
let segments = log.list_segments(100..200).await?;
let start = segments.first().map(|s| s.id).unwrap_or(0);
let end = segments.last().map(|s| s.id + 1).unwrap_or(0);
let mut iter = log.list_keys(start..end).await?;
Source

fn list_segments<'life0, 'async_trait>( &'life0 self, seq_range: impl 'async_trait + RangeBounds<Sequence> + Send, ) -> Pin<Box<dyn Future<Output = Result<Vec<Segment>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists segments overlapping a sequence number range.

Returns all segments that overlap the specified sequence range. This is a precise operation—segments have well-defined boundaries, so there is no approximation.

Pass .. to list all segments.

§Arguments
  • seq_range - The sequence number range to filter segments by.
§Errors

Returns an error if the operation fails due to storage issues.

§Example
// List all segments
let segments = log.list_segments(..).await?;

// List segments overlapping a specific range
let segments = log.list_segments(100..200).await?;

Provided Methods§

Source

fn scan<'life0, 'async_trait>( &'life0 self, key: Bytes, seq_range: impl 'async_trait + RangeBounds<Sequence> + Send, ) -> Pin<Box<dyn Future<Output = Result<LogIterator>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Scans entries for a key within a sequence number range.

Returns an iterator that yields entries in sequence number order. The range is specified using Rust’s standard range syntax.

This method uses default scan options. Use scan_with_options for custom read behavior.

§Read Visibility

An active scan may or may not see records appended after the initial call. However, all records returned will always respect the correct ordering of records (no reordering).

§Arguments
  • key - The key identifying the log stream to scan.
  • seq_range - The sequence number range to scan. Supports all Rust range types (.., start.., ..end, start..end, etc.).
§Errors

Returns an error if the scan fails due to storage issues.

Source

fn count<'life0, 'async_trait>( &'life0 self, key: Bytes, seq_range: impl 'async_trait + RangeBounds<Sequence> + Send, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Counts entries for a key within a sequence number range.

Returns the number of entries in the specified range. This is useful for computing lag (how far behind a consumer is) or progress metrics.

This method uses default count options (exact count). Use count_with_options for approximate counts.

§Arguments
  • key - The key identifying the log stream to count.
  • seq_range - The sequence number range to count.
§Errors

Returns an error if the count fails due to storage issues.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§