Skip to content

Commit

Permalink
Fix BlobDB::Get which only get out the value offset
Browse files Browse the repository at this point in the history
Summary:
Blob db use StackableDB::get which only get out the
value offset, but not the value.
Fix by making BlobDB::Get override the designated getter.
Closes #2553

Differential Revision: D5396823

Pulled By: yiwu-arbug

fbshipit-source-id: 5a7d1cf77ee44490f836a6537225955382296878
  • Loading branch information
foolenough authored and facebook-github-bot committed Jul 13, 2017
1 parent 70440f7 commit 21b17d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion utilities/blob_db/blob_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BlobDB : public StackableDB {
using rocksdb::StackableDB::Get;
virtual Status Get(const ReadOptions& options,
ColumnFamilyHandle* column_family, const Slice& key,
std::string* value) override = 0;
PinnableSlice* value) override = 0;

using rocksdb::StackableDB::MultiGet;
virtual std::vector<Status> MultiGet(
Expand Down
5 changes: 3 additions & 2 deletions utilities/blob_db/blob_db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ Status BlobDBImpl::CommonGet(const ColumnFamilyData* cfd, const Slice& key,

Status BlobDBImpl::Get(const ReadOptions& options,
ColumnFamilyHandle* column_family, const Slice& key,
std::string* value) {
PinnableSlice* value) {
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
auto cfd = cfh->cfd();

Expand All @@ -1341,7 +1341,8 @@ Status BlobDBImpl::Get(const ReadOptions& options,
return s;
}

s = CommonGet(cfd, key, index_entry, value);
s = CommonGet(cfd, key, index_entry, value->GetSelf());
value->PinSelf();
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion utilities/blob_db/blob_db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class BlobDBImpl : public BlobDB {

using rocksdb::StackableDB::Get;
Status Get(const ReadOptions& options, ColumnFamilyHandle* column_family,
const Slice& key, std::string* value) override;
const Slice& key, PinnableSlice* value) override;

using rocksdb::StackableDB::NewIterator;
virtual Iterator* NewIterator(const ReadOptions& opts,
Expand Down
22 changes: 22 additions & 0 deletions utilities/blob_db/blob_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ TEST_F(BlobDBTest, Put) {
VerifyDB(data);
}

TEST_F(BlobDBTest, StackableDBGet) {
Random rnd(301);
BlobDBOptionsImpl bdb_options;
bdb_options.disable_background_tasks = true;
Open(bdb_options);
std::map<std::string, std::string> data;
for (size_t i = 0; i < 100; i++) {
PutRandom("key" + ToString(i), &rnd, &data);
}
for (size_t i = 0; i < 100; i++) {
StackableDB *db = blob_db_;
ColumnFamilyHandle *column_family = db->DefaultColumnFamily();
std::string key = "key" + ToString(i);
PinnableSlice pinnable_value;
ASSERT_OK(db->Get(ReadOptions(), column_family, key, &pinnable_value));
std::string string_value;
ASSERT_OK(db->Get(ReadOptions(), column_family, key, &string_value));
ASSERT_EQ(string_value, pinnable_value.ToString());
ASSERT_EQ(string_value, data[key]);
}
}

TEST_F(BlobDBTest, WriteBatch) {
Random rnd(301);
BlobDBOptionsImpl bdb_options;
Expand Down

0 comments on commit 21b17d7

Please sign in to comment.