risingwave_storage::hummock::iterator

Trait HummockIterator

source
pub trait HummockIterator: Send {
    type Direction: HummockIteratorDirection;

    // Required methods
    fn next(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_;
    fn key(&self) -> FullKey<&[u8]>;
    fn value(&self) -> HummockValue<&[u8]>;
    fn is_valid(&self) -> bool;
    fn rewind(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_;
    fn seek<'a>(
        &'a mut self,
        key: FullKey<&'a [u8]>,
    ) -> impl Future<Output = HummockResult<()>> + Send;
    fn collect_local_statistic(&self, _stats: &mut StoreLocalStatistic);
    fn value_meta(&self) -> ValueMeta;
}
Expand description

HummockIterator defines the interface of all iterators, including SstableIterator, MergeIterator, UserIterator and ConcatIterator.

After creating the iterator instance,

  • if you want to iterate from the beginning, you need to then call its rewind method.
  • if you want to iterate from some specific position, you need to then call its seek method.

Required Associated Types§

Required Methods§

source

fn next(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_

Moves a valid iterator to the next key.

Note:

  • Before calling this function, makes sure the iterator is_valid.
  • After calling this function, you may first check whether the iterator is_valid again, then get the new data by calling key and value.
  • If the position after calling this is invalid, this function WON’T return an Err. You should check is_valid before continuing the iteration.
§Panics

This function will panic if the iterator is invalid.

source

fn key(&self) -> FullKey<&[u8]>

Retrieves the current key.

Note:

  • Before calling this function, makes sure the iterator is_valid.
  • This function should be straightforward and return immediately.
§Panics

This function will panic if the iterator is invalid.

source

fn value(&self) -> HummockValue<&[u8]>

Retrieves the current value, decoded as HummockValue.

Note:

  • Before calling this function, makes sure the iterator is_valid.
  • This function should be straightforward and return immediately.
§Panics

This function will panic if the iterator is invalid, or the value cannot be decoded into HummockValue.

source

fn is_valid(&self) -> bool

Indicates whether the iterator can be used.

Note:

  • ONLY call key, value, and next if is_valid returns true.
  • This function should be straightforward and return immediately.
source

fn rewind(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_

Resets the position of the iterator.

Note:

  • Do not decide whether the position is valid or not by checking the returned error of this function. This function WON’T return an Err if invalid. You should check is_valid before starting iteration.
source

fn seek<'a>( &'a mut self, key: FullKey<&'a [u8]>, ) -> impl Future<Output = HummockResult<()>> + Send

Resets iterator and seeks to the first position where the key >= provided key, or key <= provided key if this is a backward iterator.

Note:

  • Do not decide whether the position is valid or not by checking the returned error of this function. This function WON’T return an Err if invalid. You should check is_valid before starting iteration.
source

fn collect_local_statistic(&self, _stats: &mut StoreLocalStatistic)

take local statistic info from iterator to report metrics.

source

fn value_meta(&self) -> ValueMeta

Returns value meta.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<I: HummockIterator> HummockIterator for Box<I>

source§

type Direction = <I as HummockIterator>::Direction

source§

async fn next(&mut self) -> HummockResult<()>

source§

fn key(&self) -> FullKey<&[u8]>

source§

fn value(&self) -> HummockValue<&[u8]>

source§

fn is_valid(&self) -> bool

source§

async fn rewind(&mut self) -> HummockResult<()>

source§

async fn seek<'a>(&'a mut self, key: FullKey<&'a [u8]>) -> HummockResult<()>

source§

fn collect_local_statistic(&self, stats: &mut StoreLocalStatistic)

source§

fn value_meta(&self) -> ValueMeta

Implementors§