Fix WriteBatchWithIndex::GetFromBatchAndDB not allowing StackableDB

Summary: Closes https://github.com/facebook/rocksdb/pull/2881

Differential Revision: D5829682

Pulled By: yiwu-arbug

fbshipit-source-id: abb8fa14b58cea7c416282f9be19e8b1a7961c6e
main
Yi Wu 7 years ago committed by Facebook Github Bot
parent a843df668b
commit 9a970c81af
  1. 13
      utilities/write_batch_with_index/write_batch_with_index.cc

@ -19,6 +19,7 @@
#include "rocksdb/comparator.h" #include "rocksdb/comparator.h"
#include "rocksdb/iterator.h" #include "rocksdb/iterator.h"
#include "util/arena.h" #include "util/arena.h"
#include "util/cast_util.h"
#include "utilities/write_batch_with_index/write_batch_with_index_internal.h" #include "utilities/write_batch_with_index/write_batch_with_index_internal.h"
namespace rocksdb { namespace rocksdb {
@ -790,14 +791,11 @@ Status WriteBatchWithIndex::GetFromBatchAndDB(DB* db,
Status WriteBatchWithIndex::GetFromBatchAndDB( Status WriteBatchWithIndex::GetFromBatchAndDB(
DB* db, const ReadOptions& read_options, ColumnFamilyHandle* column_family, DB* db, const ReadOptions& read_options, ColumnFamilyHandle* column_family,
const Slice& key, PinnableSlice* pinnable_val, ReadCallback* callback) { const Slice& key, PinnableSlice* pinnable_val, ReadCallback* callback) {
if (UNLIKELY(db->GetRootDB() != db)) {
return Status::NotSupported("The DB must be of DBImpl type");
// Otherwise the cast below would fail
}
Status s; Status s;
MergeContext merge_context; MergeContext merge_context;
const ImmutableDBOptions& immuable_db_options = const ImmutableDBOptions& immuable_db_options =
reinterpret_cast<DBImpl*>(db)->immutable_db_options(); static_cast_with_check<DBImpl, DB>(db->GetRootDB())
->immutable_db_options();
// Since the lifetime of the WriteBatch is the same as that of the transaction // Since the lifetime of the WriteBatch is the same as that of the transaction
// we cannot pin it as otherwise the returned value will not be available // we cannot pin it as otherwise the returned value will not be available
@ -833,8 +831,9 @@ Status WriteBatchWithIndex::GetFromBatchAndDB(
if (!callback) { if (!callback) {
s = db->Get(read_options, column_family, key, pinnable_val); s = db->Get(read_options, column_family, key, pinnable_val);
} else { } else {
s = reinterpret_cast<DBImpl*>(db)->GetImpl(read_options, column_family, key, s = static_cast_with_check<DBImpl, DB>(db->GetRootDB())
pinnable_val, nullptr, callback); ->GetImpl(read_options, column_family, key, pinnable_val, nullptr,
callback);
} }
if (s.ok() || s.IsNotFound()) { // DB Get Succeeded if (s.ok() || s.IsNotFound()) { // DB Get Succeeded

Loading…
Cancel
Save