提交 f121c4f5 编写于 作者: M Mayank Agarwal

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
上级 7afdf5e9
......@@ -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) {
......
......@@ -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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册