@ -17,9 +17,15 @@ namespace ROCKSDB_NAMESPACE {
class PinnedIteratorsManager ;
class PinnedIteratorsManager ;
enum class IterBoundCheck : char {
kUnknown = 0 ,
kOutOfBound ,
kInbound ,
} ;
struct IterateResult {
struct IterateResult {
Slice key ;
Slice key ;
bool may_be_out_of_upper_bound ;
IterBoundCheck bound_check_result = IterBoundCheck : : kUnknown ;
// If false, PrepareValue() needs to be called before value().
// If false, PrepareValue() needs to be called before value().
bool value_prepared = true ;
bool value_prepared = true ;
} ;
} ;
@ -69,7 +75,7 @@ class InternalIteratorBase : public Cleanable {
// Moves to the next entry in the source, and return result. Iterator
// Moves to the next entry in the source, and return result. Iterator
// implementation should override this method to help methods inline better,
// implementation should override this method to help methods inline better,
// or when MayBeOutOf UpperBound() is non-trivial.
// or when UpperBoundCheckResult () is non-trivial.
// REQUIRES: Valid()
// REQUIRES: Valid()
virtual bool NextAndGetResult ( IterateResult * result ) {
virtual bool NextAndGetResult ( IterateResult * result ) {
Next ( ) ;
Next ( ) ;
@ -77,11 +83,11 @@ class InternalIteratorBase : public Cleanable {
if ( is_valid ) {
if ( is_valid ) {
result - > key = key ( ) ;
result - > key = key ( ) ;
// Default may_be_out_of_upper_bound to true to avoid unnecessary virtual
// Default may_be_out_of_upper_bound to true to avoid unnecessary virtual
// call. If an implementation has non-trivial MayBeOutOf UpperBound(),
// call. If an implementation has non-trivial UpperBoundCheckResult (),
// it should also override NextAndGetResult().
// it should also override NextAndGetResult().
result - > may_be_out_of_upper_bound = true ;
result - > bound_check_result = IterBoundCheck : : kUnknown ;
result - > value_prepared = false ;
result - > value_prepared = false ;
assert ( MayBeOutOf UpperBound( ) ) ;
assert ( UpperBoundCheckResult ( ) ! = IterBoundCheck : : kOutOfBound ) ;
}
}
return is_valid ;
return is_valid ;
}
}
@ -126,19 +132,17 @@ class InternalIteratorBase : public Cleanable {
// REQUIRES: Valid()
// REQUIRES: Valid()
virtual bool PrepareValue ( ) { return true ; }
virtual bool PrepareValue ( ) { return true ; }
// True if the iterator is invalidated because it reached a key that is above
// the iterator upper bound. Used by LevelIterator to decide whether it should
// stop or move on to the next file.
// Important: if iterator reached the end of the file without encountering any
// keys above the upper bound, IsOutOfBound() must return false.
virtual bool IsOutOfBound ( ) { return false ; }
// Keys return from this iterator can be smaller than iterate_lower_bound.
// Keys return from this iterator can be smaller than iterate_lower_bound.
virtual bool MayBeOutOfLowerBound ( ) { return true ; }
virtual bool MayBeOutOfLowerBound ( ) { return true ; }
// Keys return from this iterator can be larger or equal to
// If the iterator has checked the key against iterate_upper_bound, returns
// iterate_upper_bound.
// the result here. The function can be used by user of the iterator to skip
virtual bool MayBeOutOfUpperBound ( ) { return true ; }
// their own checks. If Valid() = true, IterBoundCheck::kUnknown is always
// a valid value. If Valid() = false, IterBoundCheck::kOutOfBound indicates
// that the iterator is filtered out by upper bound checks.
virtual IterBoundCheck UpperBoundCheckResult ( ) {
return IterBoundCheck : : kUnknown ;
}
// Pass the PinnedIteratorsManager to the Iterator, most Iterators don't
// Pass the PinnedIteratorsManager to the Iterator, most Iterators don't
// communicate with PinnedIteratorsManager so default implementation is no-op
// communicate with PinnedIteratorsManager so default implementation is no-op