From ade4034a9d4d42caed8d9e635a905fdf1152b361 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Sat, 20 Dec 2014 12:46:37 +0100 Subject: [PATCH] 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 --- utilities/ttl/db_ttl_impl.cc | 14 ++++++++++++-- utilities/ttl/ttl_test.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/utilities/ttl/db_ttl_impl.cc b/utilities/ttl/db_ttl_impl.cc index 4d2d8406e..622e668b1 100644 --- a/utilities/ttl/db_ttl_impl.cc +++ b/utilities/ttl/db_ttl_impl.cc @@ -202,8 +202,18 @@ std::vector DBWithTTLImpl::MultiGet( const ReadOptions& options, const std::vector& column_family, const std::vector& keys, std::vector* values) { - return std::vector( - 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, diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index 66c8db50c..73756a704 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -194,6 +194,25 @@ class TtlTest { } } + // checks the whole kvmap_ to return correct values using MultiGet + void SimpleMultiGetTest() { + static ReadOptions ropts; + std::vector keys; + std::vector 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;