in common/rusty_leveldb_sgx/src/db_iter.rs [111:162]
fn find_prev_user_entry(&mut self) -> bool {
assert!(self.dir == Direction::Reverse);
let mut value_type = ValueType::TypeDeletion;
// The iterator should be already set to the previous entry if this is a direction change
// (i.e. first prev() call after advance()). savedkey is set to the key of that entry.
//
// We read the current entry, ignore it for comparison (because the initial value_type is
// Deletion), assign it to savedkey and savedval and go back another step (at the end of
// the loop).
//
// We repeat this until we hit the first entry with a different user key (possibly going
// through newer versions of the same key, because the newest entry is first in order),
// then break. The key and value of the latest entry for the desired key have been stored
// in the previous iteration to savedkey and savedval.
while self.iter.valid() {
self.iter.current(&mut self.keybuf, &mut self.valbuf);
let len = self.keybuf.len() + self.valbuf.len();
self.record_read_sample(len);
let (typ, seq, ukey) = parse_internal_key(&self.keybuf);
if seq > 0 && seq <= self.ss.sequence() {
if value_type != ValueType::TypeDeletion
&& self.cmp.cmp(ukey, &self.savedkey) == Ordering::Less
{
// We found a non-deleted entry for a previous key (in the previous iteration)
break;
}
value_type = typ;
if value_type == ValueType::TypeDeletion {
self.savedkey.clear();
self.savedval.clear();
} else {
self.savedkey.clear();
self.savedkey.extend_from_slice(ukey);
mem::swap(&mut self.savedval, &mut self.valbuf);
}
}
self.iter.prev();
}
if value_type == ValueType::TypeDeletion {
self.valid = false;
self.savedkey.clear();
self.savedval.clear();
self.dir = Direction::Forward;
} else {
self.valid = true;
}
true
}