From b72b3c6f515674b7090b1f631ce7b2420bbe7d95 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Mon, 27 Nov 2017 08:49:30 -0800 Subject: [PATCH] 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 --- .../write_prepared_transaction_test.cc | 27 +++++++++++++++++++ .../transactions/write_prepared_txn_db.cc | 16 +++++++++++ .../transactions/write_prepared_txn_db.h | 7 +++++ 3 files changed, 50 insertions(+) diff --git a/utilities/transactions/write_prepared_transaction_test.cc b/utilities/transactions/write_prepared_transaction_test.cc index 3a731ae9c4..b1e0fdd583 100644 --- a/utilities/transactions/write_prepared_transaction_test.cc +++ b/utilities/transactions/write_prepared_transaction_test.cc @@ -305,6 +305,20 @@ class WritePreparedTransactionTest : public TransactionTest { } else { ASSERT_EQ(kv.second, "NOT_FOUND"); } + + // Try with MultiGet API too + std::vector 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 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) { diff --git a/utilities/transactions/write_prepared_txn_db.cc b/utilities/transactions/write_prepared_txn_db.cc index 43b578ebfd..c2b18b3268 100644 --- a/utilities/transactions/write_prepared_txn_db.cc +++ b/utilities/transactions/write_prepared_txn_db.cc @@ -75,6 +75,22 @@ Status WritePreparedTxnDB::Get(const ReadOptions& options, &callback); } +std::vector WritePreparedTxnDB::MultiGet( + const ReadOptions& options, + const std::vector& column_family, + const std::vector& keys, std::vector* values) { + assert(values); + size_t num_keys = keys.size(); + values->resize(num_keys); + + std::vector 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, diff --git a/utilities/transactions/write_prepared_txn_db.h b/utilities/transactions/write_prepared_txn_db.h index 004f1ef67f..454d7f827c 100644 --- a/utilities/transactions/write_prepared_txn_db.h +++ b/utilities/transactions/write_prepared_txn_db.h @@ -72,6 +72,13 @@ class WritePreparedTxnDB : public PessimisticTransactionDB { ColumnFamilyHandle* column_family, const Slice& key, PinnableSlice* value) override; + using DB::MultiGet; + virtual std::vector MultiGet( + const ReadOptions& options, + const std::vector& column_family, + const std::vector& keys, + std::vector* values) override; + using DB::NewIterator; virtual Iterator* NewIterator(const ReadOptions& options, ColumnFamilyHandle* column_family) override;