Skip to content

Commit

Permalink
Make level iterator customzied too.
Browse files Browse the repository at this point in the history
Customized BlockBasedTableIterator

Summary:
Use a customzied BlockBasedTableIterator to replace current implementation leveraging two level iterator. Hope the customized logic will make code easier to understand. As a side effect, we reduce the allocation for the data block iterator object, and avoid the virtual function call to it, because we can directly reference BlockIter, a final class. It also enabled further optimization.

The upper bound check is also moved from index block to data block. This implementation fits this iterator better. After the change, forwared iterator is slightly optimized to ensure we trim those iterators.

Test Plan: Run all existing tests using ASAN.

Simplify two-level-iterator

fix clang

Fix issues because of rebase

Address comments.

Fix a memory issue
  • Loading branch information
siying committed Feb 12, 2018
1 parent 3f1bb07 commit 5798e13
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 337 deletions.
32 changes: 15 additions & 17 deletions db/forward_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,13 @@ void ForwardIterator::SeekInternal(const Slice& internal_key,

if (!l0_iters_[i]->status().ok()) {
immutable_status_ = l0_iters_[i]->status();
} else if (l0_iters_[i]->Valid()) {
if (!IsOverUpperBound(l0_iters_[i]->key())) {
immutable_min_heap_.push(l0_iters_[i]);
} else {
has_iter_trimmed_for_upper_bound_ = true;
DeleteIterator(l0_iters_[i]);
l0_iters_[i] = nullptr;
}
} else if (l0_iters_[i]->Valid() &&
!IsOverUpperBound(l0_iters_[i]->key())) {
immutable_min_heap_.push(l0_iters_[i]);
} else {
has_iter_trimmed_for_upper_bound_ = true;
DeleteIterator(l0_iters_[i]);
l0_iters_[i] = nullptr;
}
}

Expand All @@ -417,15 +416,14 @@ void ForwardIterator::SeekInternal(const Slice& internal_key,

if (!level_iters_[level - 1]->status().ok()) {
immutable_status_ = level_iters_[level - 1]->status();
} else if (level_iters_[level - 1]->Valid()) {
if (!IsOverUpperBound(level_iters_[level - 1]->key())) {
immutable_min_heap_.push(level_iters_[level - 1]);
} else {
// Nothing in this level is interesting. Remove.
has_iter_trimmed_for_upper_bound_ = true;
DeleteIterator(level_iters_[level - 1]);
level_iters_[level - 1] = nullptr;
}
} else if (level_iters_[level - 1]->Valid() &&
!IsOverUpperBound(level_iters_[level - 1]->key())) {
immutable_min_heap_.push(level_iters_[level - 1]);
} else {
// Nothing in this level is interesting. Remove.
has_iter_trimmed_for_upper_bound_ = true;
DeleteIterator(level_iters_[level - 1]);
level_iters_[level - 1] = nullptr;
}
}
}
Expand Down
Loading

0 comments on commit 5798e13

Please sign in to comment.