Skip to content

semi-async RaftLogReader::try_get_log_entries #1155

Open
@drmingdrmer

Description

@drmingdrmer

openraft/src/core/sm/worker.rs line 166 at r1 (raw file):

        let n_entries = end - since;

        let apply_results = self.state_machine.apply(entries).await?;

Now that this is in the same method, it would make sense to somehow overlap the processing. E.g., change the interface of getting log entries to a (semi-async) iterator (which can do prefetching as it sees fit for on-disk data) and feed this iterator to apply() directly? The result could be another (semi-async) iterator, which you can then use to get rid of applying_entries.

Originally posted by @schreter in #1154 (review)

Upgrade RaftLogReader::try_get_log_entries() -> Result<Vec<Entry>, StorageError> to return a pollable result, a Stream or an iterator of Future.
So that prefetch can be done before the caller consuming log entries.

trait RaftLogReader {
  // Return a Stream:
  async fn try_get_log_entries(&mut self, range) -> impl Stream<Item=Result<Entry, StorageError>>;

  // Or return an iterator of Future
  type Fu: Future<Item=Result<Entry, StorageError>>;
  async fn try_get_log_entries(&mut self, range) -> impl Iterator<Item=Fu>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions