Skip to content

Commit 1d23b5c

Browse files
author
Feng Zhu
committed
remove_internal_filter_policy
Summary: 1. remove class InternalFilterPolicy in db/dbformat.h 2. Transformation from internal key to user key is done in filter_block.cc 3. This is a preparation for patch D20979 Test Plan: make all check valgrind ./db_test Reviewers: igor, yhchiang, ljin, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D22509
1 parent 2a8faf7 commit 1d23b5c

6 files changed

+9
-54
lines changed

db/dbformat.cc

-20
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,6 @@ void InternalKeyComparator::FindShortSuccessor(std::string* key) const {
127127
}
128128
}
129129

130-
const char* InternalFilterPolicy::Name() const {
131-
return user_policy_->Name();
132-
}
133-
134-
void InternalFilterPolicy::CreateFilter(const Slice* keys, int n,
135-
std::string* dst) const {
136-
// We rely on the fact that the code in table.cc does not mind us
137-
// adjusting keys[].
138-
Slice* mkey = const_cast<Slice*>(keys);
139-
for (int i = 0; i < n; i++) {
140-
mkey[i] = ExtractUserKey(keys[i]);
141-
// TODO(sanjay): Suppress dups?
142-
}
143-
user_policy_->CreateFilter(keys, n, dst);
144-
}
145-
146-
bool InternalFilterPolicy::KeyMayMatch(const Slice& key, const Slice& f) const {
147-
return user_policy_->KeyMayMatch(ExtractUserKey(key), f);
148-
}
149-
150130
LookupKey::LookupKey(const Slice& user_key, SequenceNumber s) {
151131
size_t usize = user_key.size();
152132
size_t needed = usize + 13; // A conservative estimate

db/dbformat.h

-13
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,6 @@ class InternalKeyComparator : public Comparator {
124124
int Compare(const ParsedInternalKey& a, const ParsedInternalKey& b) const;
125125
};
126126

127-
// Filter policy wrapper that converts from internal keys to user keys
128-
class InternalFilterPolicy : public FilterPolicy {
129-
private:
130-
std::shared_ptr<const FilterPolicy> shared_ptr_;
131-
const FilterPolicy* const user_policy_;
132-
public:
133-
explicit InternalFilterPolicy(std::shared_ptr<const FilterPolicy> p)
134-
: shared_ptr_(p), user_policy_(p.get()) {}
135-
virtual const char* Name() const;
136-
virtual void CreateFilter(const Slice* keys, int n, std::string* dst) const;
137-
virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const;
138-
};
139-
140127
// Modules in this directory should keep internal keys wrapped inside
141128
// the following class instead of plain strings so that we do not
142129
// incorrectly use string comparisons instead of an InternalKeyComparator.

table/block_based_table_builder.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ void BlockBasedTableBuilder::Add(const Slice& key, const Slice& value) {
492492
}
493493

494494
if (r->filter_block != nullptr) {
495-
r->filter_block->AddKey(key);
495+
r->filter_block->AddKey(ExtractUserKey(key));
496496
}
497497

498498
r->last_key.assign(key.data(), key.size());

table/block_based_table_factory.cc

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ BlockBasedTableFactory::BlockBasedTableFactory(
3838
table_options_.block_size_deviation > 100) {
3939
table_options_.block_size_deviation = 0;
4040
}
41-
if (table_options_.filter_policy) {
42-
auto* p = new InternalFilterPolicy(table_options_.filter_policy);
43-
table_options_.filter_policy.reset(p);
44-
}
4541
}
4642

4743
Status BlockBasedTableFactory::NewTableReader(

table/block_based_table_reader.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,8 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key) {
10671067
s = handle.DecodeFrom(&handle_value);
10681068
assert(s.ok());
10691069
auto filter_entry = GetFilter(true /* no io */);
1070-
may_match =
1071-
filter_entry.value == nullptr ||
1072-
filter_entry.value->PrefixMayMatch(handle.offset(), internal_prefix);
1070+
may_match = filter_entry.value == nullptr ||
1071+
filter_entry.value->PrefixMayMatch(handle.offset(), prefix);
10731072
filter_entry.Release(rep_->table_options.block_cache.get());
10741073
}
10751074

@@ -1105,9 +1104,8 @@ Status BlockBasedTable::Get(
11051104

11061105
BlockHandle handle;
11071106
bool may_not_exist_in_filter =
1108-
filter != nullptr &&
1109-
handle.DecodeFrom(&handle_value).ok() &&
1110-
!filter->KeyMayMatch(handle.offset(), key);
1107+
filter != nullptr && handle.DecodeFrom(&handle_value).ok() &&
1108+
!filter->KeyMayMatch(handle.offset(), ExtractUserKey(key));
11111109

11121110
if (may_not_exist_in_filter) {
11131111
// Not found

table/filter_block.cc

+4-10
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,14 @@ void FilterBlockBuilder::AddKey(const Slice& key) {
7171
}
7272

7373
// add prefix to filter if needed
74-
if (prefix_extractor_ && prefix_extractor_->InDomain(ExtractUserKey(key))) {
75-
// If prefix_extractor_, this filter_block layer assumes we only
76-
// operate on internal keys.
77-
Slice user_key = ExtractUserKey(key);
74+
if (prefix_extractor_ && prefix_extractor_->InDomain(key)) {
7875
// this assumes prefix(prefix(key)) == prefix(key), as the last
7976
// entry in entries_ may be either a key or prefix, and we use
8077
// prefix(last entry) to get the prefix of the last key.
81-
if (prev.size() == 0 ||
82-
!SamePrefix(user_key, ExtractUserKey(prev))) {
83-
Slice prefix = prefix_extractor_->Transform(user_key);
84-
InternalKey internal_prefix_tmp(prefix, 0, kTypeValue);
85-
Slice internal_prefix = internal_prefix_tmp.Encode();
78+
if (prev.size() == 0 || !SamePrefix(key, prev)) {
79+
Slice prefix = prefix_extractor_->Transform(key);
8680
start_.push_back(entries_.size());
87-
entries_.append(internal_prefix.data(), internal_prefix.size());
81+
entries_.append(prefix.data(), prefix.size());
8882
}
8983
}
9084
}

0 commit comments

Comments
 (0)