Skip to content

Commit

Permalink
LevelIterator handle hint_within_lower_bound by itself
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Wu <yiwu@pingcap.com>
  • Loading branch information
Yi Wu committed Apr 5, 2019
1 parent dc3728d commit c9be457
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 32 deletions.
9 changes: 4 additions & 5 deletions db/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ InternalIterator* TableCache::NewIterator(
TableReader** table_reader_ptr, HistogramImpl* file_read_hist,
bool for_compaction, Arena* arena, bool skip_filters, int level,
const InternalKey* smallest_compaction_key,
const InternalKey* largest_compaction_key, bool hint_within_lower_bound,
bool hint_within_upper_bound) {
const InternalKey* largest_compaction_key, bool hint_within_upper_bound) {
PERF_TIMER_GUARD(new_table_iterator_nanos);

Status s;
Expand Down Expand Up @@ -247,9 +246,9 @@ InternalIterator* TableCache::NewIterator(
!options.table_filter(*table_reader->GetTableProperties())) {
result = NewEmptyInternalIterator<Slice>(arena);
} else {
result = table_reader->NewIterator(
options, prefix_extractor, arena, skip_filters, for_compaction,
hint_within_lower_bound, hint_within_upper_bound);
result = table_reader->NewIterator(options, prefix_extractor, arena,
skip_filters, for_compaction,
hint_within_upper_bound);
}
if (create_new_table_reader) {
assert(handle == nullptr);
Expand Down
1 change: 0 additions & 1 deletion db/table_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class TableCache {
Arena* arena = nullptr, bool skip_filters = false, int level = -1,
const InternalKey* smallest_compaction_key = nullptr,
const InternalKey* largest_compaction_key = nullptr,
bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false);

// If a seek to internal key "k" in specified file finds an entry,
Expand Down
7 changes: 4 additions & 3 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class LevelIterator final : public InternalIterator {

bool HintWithinLowerBound() override {
assert(Valid());
return file_iter_.HintWithinLowerBound();
return hint_within_lower_bound_;
}

bool HintWithinUpperBound() override {
Expand Down Expand Up @@ -580,7 +580,7 @@ class LevelIterator final : public InternalIterator {
smallest_compaction_key = (*compaction_boundaries_)[file_index_].smallest;
largest_compaction_key = (*compaction_boundaries_)[file_index_].largest;
}
bool hint_within_lower_bound =
hint_within_lower_bound_ =
read_options_.iterate_lower_bound != nullptr &&
user_comparator_.Compare(ExtractUserKey(file_smallest_key(file_index_)),
*read_options_.iterate_lower_bound) >= 0;
Expand All @@ -594,7 +594,7 @@ class LevelIterator final : public InternalIterator {
nullptr /* don't need reference to table */, file_read_hist_,
for_compaction_, nullptr /* arena */, skip_filters_, level_,
smallest_compaction_key, largest_compaction_key,
hint_within_lower_bound, hint_within_upper_bound);
hint_within_upper_bound);
}

TableCache* table_cache_;
Expand All @@ -610,6 +610,7 @@ class LevelIterator final : public InternalIterator {
bool should_sample_;
bool for_compaction_;
bool skip_filters_;
bool hint_within_lower_bound_ = false;
size_t file_index_;
int level_;
RangeDelAggregator* range_del_agg_;
Expand Down
6 changes: 3 additions & 3 deletions table/block_based_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,7 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckOutOfBound() {
InternalIterator* BlockBasedTable::NewIterator(
const ReadOptions& read_options, const SliceTransform* prefix_extractor,
Arena* arena, bool skip_filters, bool for_compaction,
bool hint_within_lower_bound, bool hint_within_upper_bound) {
bool hint_within_upper_bound) {
bool need_upper_bound_check =
PrefixExtractorChanged(rep_->table_properties.get(), prefix_extractor);
const bool kIsNotIndex = false;
Expand All @@ -2580,7 +2580,7 @@ InternalIterator* BlockBasedTable::NewIterator(
prefix_extractor != nullptr,
need_upper_bound_check, prefix_extractor, kIsNotIndex,
true /*key_includes_seq*/, true /*index_key_is_full*/, for_compaction,
hint_within_lower_bound, hint_within_upper_bound);
hint_within_upper_bound);
} else {
auto* mem =
arena->AllocateAligned(sizeof(BlockBasedTableIterator<DataBlockIter>));
Expand All @@ -2591,7 +2591,7 @@ InternalIterator* BlockBasedTable::NewIterator(
prefix_extractor != nullptr,
need_upper_bound_check, prefix_extractor, kIsNotIndex,
true /*key_includes_seq*/, true /*index_key_is_full*/, for_compaction,
hint_within_lower_bound, hint_within_upper_bound);
hint_within_upper_bound);
}
}

Expand Down
12 changes: 0 additions & 12 deletions table/block_based_table_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class BlockBasedTable : public TableReader {
Arena* arena = nullptr,
bool skip_filters = false,
bool for_compaction = false,
bool within_lower_bound = false,
bool within_upper_bound = false) override;

FragmentedRangeTombstoneIterator* NewRangeTombstoneIterator(
Expand Down Expand Up @@ -580,7 +579,6 @@ class BlockBasedTableIterator : public InternalIteratorBase<TValue> {
bool key_includes_seq = true,
bool index_key_is_full = true,
bool for_compaction = false,
bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false)
: table_(table),
read_options_(read_options),
Expand All @@ -596,7 +594,6 @@ class BlockBasedTableIterator : public InternalIteratorBase<TValue> {
key_includes_seq_(key_includes_seq),
index_key_is_full_(index_key_is_full),
for_compaction_(for_compaction),
hint_within_lower_bound_(hint_within_lower_bound),
hint_within_upper_bound_(hint_within_upper_bound) {}

~BlockBasedTableIterator() { delete index_iter_; }
Expand Down Expand Up @@ -638,14 +635,6 @@ class BlockBasedTableIterator : public InternalIteratorBase<TValue> {
// Whether iterator invalidated for being out of bound.
bool IsOutOfBound() override { return is_out_of_bound_; }

bool HintWithinLowerBound() override {
assert(Valid());
assert(read_options_.iterate_lower_bound != nullptr);
// Potentially we can use index key for the previous block as lower bound
// of current block, and check if we are wihtin iterate_lower_bound.
return hint_within_lower_bound_;
}

bool HintWithinUpperBound() override {
assert(Valid());
assert(read_options_.iterate_upper_bound != nullptr);
Expand Down Expand Up @@ -725,7 +714,6 @@ class BlockBasedTableIterator : public InternalIteratorBase<TValue> {
bool index_key_is_full_;
// If this iterator is created for compaction
bool for_compaction_;
const bool hint_within_lower_bound_;
const bool hint_within_upper_bound_;
BlockHandle prev_index_value_;

Expand Down
2 changes: 1 addition & 1 deletion table/cuckoo_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ InternalIterator* CuckooTableReader::NewIterator(
const ReadOptions& /*read_options*/,
const SliceTransform* /* prefix_extractor */, Arena* arena,
bool /*skip_filters*/, bool /*for_compaction*/,
bool /*hint_within_lower_bound*/, bool /*hint_within_upper_bound*/) {
bool /*hint_within_upper_bound*/) {
if (!status().ok()) {
return NewErrorInternalIterator<Slice>(
Status::Corruption("CuckooTableReader status is not okay."), arena);
Expand Down
1 change: 0 additions & 1 deletion table/cuckoo_table_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CuckooTableReader: public TableReader {
Arena* arena = nullptr,
bool skip_filters = false,
bool for_compaction = false,
bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false) override;
void Prepare(const Slice& target) override;

Expand Down
2 changes: 1 addition & 1 deletion table/mock_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stl_wrappers::KVMap MakeMockFile(
InternalIterator* MockTableReader::NewIterator(
const ReadOptions&, const SliceTransform* /* prefix_extractor */,
Arena* /*arena*/, bool /*skip_filters*/, bool /*for_compaction*/,
bool /*hint_within_lower_bound*/, bool /*hint_within_upper_bound*/) {
bool /*hint_within_upper_bound*/) {
return new MockTableIterator(table_);
}

Expand Down
1 change: 0 additions & 1 deletion table/mock_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class MockTableReader : public TableReader {
Arena* arena = nullptr,
bool skip_filters = false,
bool for_compaction = false,
bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false) override;

Status Get(const ReadOptions& readOptions, const Slice& key,
Expand Down
2 changes: 1 addition & 1 deletion table/plain_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void PlainTableReader::SetupForCompaction() {
InternalIterator* PlainTableReader::NewIterator(
const ReadOptions& options, const SliceTransform* /* prefix_extractor */,
Arena* arena, bool /*skip_filters*/, bool /*for_compaction*/,
bool /*hint_within_lower_bound*/, bool /*hint_within_upper_bound*/) {
bool /*hint_within_upper_bound*/) {
bool use_prefix_seek = !IsTotalOrderMode() && !options.total_order_seek;
if (arena == nullptr) {
return new PlainTableIterator(this, use_prefix_seek);
Expand Down
1 change: 0 additions & 1 deletion table/plain_table_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class PlainTableReader: public TableReader {
Arena* arena = nullptr,
bool skip_filters = false,
bool for_compaction = false,
bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false) override;

void Prepare(const Slice& target) override;
Expand Down
3 changes: 1 addition & 2 deletions table/table_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class TableReader {
virtual InternalIterator* NewIterator(
const ReadOptions&, const SliceTransform* prefix_extractor,
Arena* arena = nullptr, bool skip_filters = false,
bool for_compaction = false, bool hint_within_lower_bound = false,
bool hint_within_upper_bound = false) = 0;
bool for_compaction = false, bool hint_within_upper_bound = false) = 0;

virtual FragmentedRangeTombstoneIterator* NewRangeTombstoneIterator(
const ReadOptions& /*read_options*/) {
Expand Down

0 comments on commit c9be457

Please sign in to comment.