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§
sourcefn next(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_
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 callingkey
andvalue
. - If the position after calling this is invalid, this function WON’T return an
Err
. You should checkis_valid
before continuing the iteration.
§Panics
This function will panic if the iterator is invalid.
sourcefn key(&self) -> FullKey<&[u8]>
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.
sourcefn value(&self) -> HummockValue<&[u8]>
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
.
sourcefn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Indicates whether the iterator can be used.
Note:
- ONLY call
key
,value
, andnext
ifis_valid
returnstrue
. - This function should be straightforward and return immediately.
sourcefn rewind(&mut self) -> impl Future<Output = HummockResult<()>> + Send + '_
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 checkis_valid
before starting iteration.
sourcefn seek<'a>(
&'a mut self,
key: FullKey<&'a [u8]>,
) -> impl Future<Output = HummockResult<()>> + Send
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 checkis_valid
before starting iteration.
sourcefn collect_local_statistic(&self, _stats: &mut StoreLocalStatistic)
fn collect_local_statistic(&self, _stats: &mut StoreLocalStatistic)
take local statistic info from iterator to report metrics.
sourcefn value_meta(&self) -> ValueMeta
fn value_meta(&self) -> ValueMeta
Returns value meta.