mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
WritePrepared Txn: Add MultiGet to DB
Summary: This patch implements MultiGet API for WritePreparedTxnDB and update the existing unit tests. Closes https://github.com/facebook/rocksdb/pull/3196 Differential Revision: D6401493 Pulled By: maysamyabandeh fbshipit-source-id: 51501a1e32645fc2da8680e77a50035f6530f2cc
This commit is contained in:
parent
f0dde49cda
commit
b72b3c6f51
|
@ -305,6 +305,20 @@ class WritePreparedTransactionTest : public TransactionTest {
|
|||
} else {
|
||||
ASSERT_EQ(kv.second, "NOT_FOUND");
|
||||
}
|
||||
|
||||
// Try with MultiGet API too
|
||||
std::vector<std::string> values;
|
||||
auto s_vec = db->MultiGet(read_options, {db->DefaultColumnFamily()},
|
||||
{kv.first}, &values);
|
||||
ASSERT_EQ(1, values.size());
|
||||
ASSERT_EQ(1, s_vec.size());
|
||||
s = s_vec[0];
|
||||
ASSERT_TRUE(s.ok() || s.IsNotFound());
|
||||
if (s.ok()) {
|
||||
ASSERT_TRUE(kv.second == values[0]);
|
||||
} else {
|
||||
ASSERT_EQ(kv.second, "NOT_FOUND");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1081,6 +1095,19 @@ void ASSERT_SAME(TransactionDB* db, Status exp_s, PinnableSlice& exp_v,
|
|||
if (s.ok()) {
|
||||
ASSERT_TRUE(exp_v == v);
|
||||
}
|
||||
|
||||
// Try with MultiGet API too
|
||||
std::vector<std::string> values;
|
||||
auto s_vec =
|
||||
db->MultiGet(roptions, {db->DefaultColumnFamily()}, {key}, &values);
|
||||
ASSERT_EQ(1, values.size());
|
||||
ASSERT_EQ(1, s_vec.size());
|
||||
s = s_vec[0];
|
||||
ASSERT_TRUE(exp_s == s);
|
||||
ASSERT_TRUE(s.ok() || s.IsNotFound());
|
||||
if (s.ok()) {
|
||||
ASSERT_TRUE(exp_v == values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(WritePreparedTransactionTest, RollbackTest) {
|
||||
|
|
|
@ -75,6 +75,22 @@ Status WritePreparedTxnDB::Get(const ReadOptions& options,
|
|||
&callback);
|
||||
}
|
||||
|
||||
std::vector<Status> WritePreparedTxnDB::MultiGet(
|
||||
const ReadOptions& options,
|
||||
const std::vector<ColumnFamilyHandle*>& column_family,
|
||||
const std::vector<Slice>& keys, std::vector<std::string>* values) {
|
||||
assert(values);
|
||||
size_t num_keys = keys.size();
|
||||
values->resize(num_keys);
|
||||
|
||||
std::vector<Status> stat_list(num_keys);
|
||||
for (size_t i = 0; i < num_keys; ++i) {
|
||||
std::string* value = values ? &(*values)[i] : nullptr;
|
||||
stat_list[i] = this->Get(options, column_family[i], keys[i], value);
|
||||
}
|
||||
return stat_list;
|
||||
}
|
||||
|
||||
// Struct to hold ownership of snapshot and read callback for iterator cleanup.
|
||||
struct WritePreparedTxnDB::IteratorState {
|
||||
IteratorState(WritePreparedTxnDB* txn_db, SequenceNumber sequence,
|
||||
|
|
|
@ -72,6 +72,13 @@ class WritePreparedTxnDB : public PessimisticTransactionDB {
|
|||
ColumnFamilyHandle* column_family, const Slice& key,
|
||||
PinnableSlice* value) override;
|
||||
|
||||
using DB::MultiGet;
|
||||
virtual std::vector<Status> MultiGet(
|
||||
const ReadOptions& options,
|
||||
const std::vector<ColumnFamilyHandle*>& column_family,
|
||||
const std::vector<Slice>& keys,
|
||||
std::vector<std::string>* values) override;
|
||||
|
||||
using DB::NewIterator;
|
||||
virtual Iterator* NewIterator(const ReadOptions& options,
|
||||
ColumnFamilyHandle* column_family) override;
|
||||
|
|
Loading…
Reference in a new issue