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
rewindmethod. - if you want to iterate from some specific position, you need to then call its
seekmethod.
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_validagain, then get the new data by callingkeyandvalue. - If the position after calling this is invalid, this function WON’T return an
Err. You should checkis_validbefore 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, andnextifis_validreturnstrue. - 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
Errif invalid. You should checkis_validbefore 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
Errif invalid. You should checkis_validbefore 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.
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.