KeyMayExist for ttl

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
main
Mayank Agarwal 11 years ago
parent 7afdf5e9f8
commit f121c4f504
  1. 8
      utilities/ttl/db_ttl.cc
  2. 33
      utilities/ttl/ttl_test.cc

@ -158,7 +158,13 @@ bool DBWithTTL::KeyMayExist(const ReadOptions& options,
const Slice& key, const Slice& key,
std::string* value, std::string* value,
bool* value_found) { 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) { Status DBWithTTL::Delete(const WriteOptions& wopts, const Slice& key) {

@ -139,6 +139,26 @@ class TtlTest {
db_ttl_->CompactRange(nullptr, nullptr); 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 // Sleeps for slp_tim then runs a manual compaction
// Checks span starting from st_pos from kvmap_ in the db and // Checks span starting from st_pos from kvmap_ in the db and
// Gets should return true if check is true and false otherwise // Gets should return true if check is true and false otherwise
@ -461,6 +481,19 @@ TEST(TtlTest, CompactionFilter) {
CloseTtl(); 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 } // namespace leveldb
// A black-box test for the ttl wrapper around rocksdb // A black-box test for the ttl wrapper around rocksdb

Loading…
Cancel
Save