Skip to content

Commit

Permalink
KeyMayExist for ttl
Browse files Browse the repository at this point in the history
Summary: value needed to be filtered of timestamp

Test Plan: ./ttl_test

Reviewers: dhruba, haobo, vamsi

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D12657
  • Loading branch information
emayanke committed Sep 1, 2013
1 parent 7afdf5e commit f121c4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utilities/ttl/db_ttl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ bool DBWithTTL::KeyMayExist(const ReadOptions& options,
const Slice& key,
std::string* value,
bool* value_found) {
return db_->KeyMayExist(options, key, value, value_found);
bool ret = db_->KeyMayExist(options, key, value, value_found);
if (ret && value != nullptr && value_found != nullptr && *value_found) {
if (!SanityCheckTimestamp(*value).ok() || !StripTS(value).ok()) {
return false;
}
}
return ret;
}

Status DBWithTTL::Delete(const WriteOptions& wopts, const Slice& key) {
Expand Down
33 changes: 33 additions & 0 deletions utilities/ttl/ttl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ class TtlTest {
db_ttl_->CompactRange(nullptr, nullptr);
}

// checks the whole kvmap_ to return correct values using KeyMayExist
void SimpleKeyMayExistCheck() {
static ReadOptions ropts;
bool value_found;
std::string val;
for(auto &kv : kvmap_) {
bool ret = db_ttl_->KeyMayExist(ropts, kv.first, &val, &value_found);
if (ret == false || value_found == false) {
fprintf(stderr, "KeyMayExist could not find key=%s in the database but"
" should have\n", kv.first.c_str());
assert(false);
} else if (val.compare(kv.second) != 0) {
fprintf(stderr, " value for key=%s present in database is %s but"
" should be %s\n", kv.first.c_str(), val.c_str(),
kv.second.c_str());
assert(false);
}
}
}

// Sleeps for slp_tim then runs a manual compaction
// Checks span starting from st_pos from kvmap_ in the db and
// Gets should return true if check is true and false otherwise
Expand Down Expand Up @@ -461,6 +481,19 @@ TEST(TtlTest, CompactionFilter) {
CloseTtl();
}

// Insert some key-values which KeyMayExist should be able to get and check that
// values returned are fine
TEST(TtlTest, KeyMayExist) {
MakeKVMap(kSampleSize_);

OpenTtl();
PutValues(0, kSampleSize_);

SimpleKeyMayExistCheck();

CloseTtl();
}

} // namespace leveldb

// A black-box test for the ttl wrapper around rocksdb
Expand Down

0 comments on commit f121c4f

Please sign in to comment.