MultiGet for DBWithTTL

Summary: This is a feature request from rocksdb's user. I didn't even realize we don't support multigets on TTL DB :)

Test Plan: added a unit test

Reviewers: yhchiang, rven, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D30561
This commit is contained in:
Igor Canadi 2014-12-20 12:46:37 +01:00
parent fdb6be4e24
commit ade4034a9d
2 changed files with 42 additions and 2 deletions

View File

@ -202,8 +202,18 @@ std::vector<Status> DBWithTTLImpl::MultiGet(
const ReadOptions& options,
const std::vector<ColumnFamilyHandle*>& column_family,
const std::vector<Slice>& keys, std::vector<std::string>* values) {
return std::vector<Status>(
keys.size(), Status::NotSupported("MultiGet not supported with TTL"));
auto statuses = db_->MultiGet(options, column_family, keys, values);
for (size_t i = 0; i < keys.size(); ++i) {
if (!statuses[i].ok()) {
continue;
}
statuses[i] = SanityCheckTimestamp((*values)[i]);
if (!statuses[i].ok()) {
continue;
}
statuses[i] = StripTS(&(*values)[i]);
}
return statuses;
}
bool DBWithTTLImpl::KeyMayExist(const ReadOptions& options,

View File

@ -194,6 +194,25 @@ class TtlTest {
}
}
// checks the whole kvmap_ to return correct values using MultiGet
void SimpleMultiGetTest() {
static ReadOptions ropts;
std::vector<Slice> keys;
std::vector<std::string> values;
for (auto& kv : kvmap_) {
keys.emplace_back(kv.first);
}
auto statuses = db_ttl_->MultiGet(ropts, keys, &values);
size_t i = 0;
for (auto& kv : kvmap_) {
ASSERT_OK(statuses[i]);
ASSERT_EQ(values[i], kv.second);
++i;
}
}
// 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
@ -533,6 +552,17 @@ TEST(TtlTest, KeyMayExist) {
CloseTtl();
}
TEST(TtlTest, MultiGetTest) {
MakeKVMap(kSampleSize_);
OpenTtl();
PutValues(0, kSampleSize_, false);
SimpleMultiGetTest();
CloseTtl();
}
TEST(TtlTest, ColumnFamiliesTest) {
DB* db;
Options options;