Remove duplicate code (#8079)
Summary: The implementation of TransactionDB::WrapDB() and TransactionDB::WrapStackableDB() are almost identical, except for the type of the first argument `db`. This PR adds a new template function in anonymous namespace, and calls it in the above two functions. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8079 Test Plan: make check Reviewed By: lth Differential Revision: D27184575 Pulled By: riversand963 fbshipit-source-id: f2855a6db3a7e897d0d611f7050ca4b696c56a7a
This commit is contained in:
parent
7457c7cd00
commit
d6052d381e
@ -276,10 +276,10 @@ void TransactionDB::PrepareWrap(
|
|||||||
db_options->allow_2pc = true;
|
db_options->allow_2pc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status TransactionDB::WrapDB(
|
namespace {
|
||||||
// make sure this db is already opened with memtable history enabled,
|
template <typename DBType>
|
||||||
// auto compaction distabled and 2 phase commit enabled
|
Status WrapAnotherDBInternal(
|
||||||
DB* db, const TransactionDBOptions& txn_db_options,
|
DBType* db, const TransactionDBOptions& txn_db_options,
|
||||||
const std::vector<size_t>& compaction_enabled_cf_indices,
|
const std::vector<size_t>& compaction_enabled_cf_indices,
|
||||||
const std::vector<ColumnFamilyHandle*>& handles, TransactionDB** dbptr) {
|
const std::vector<ColumnFamilyHandle*>& handles, TransactionDB** dbptr) {
|
||||||
assert(db != nullptr);
|
assert(db != nullptr);
|
||||||
@ -309,6 +309,17 @@ Status TransactionDB::WrapDB(
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Status TransactionDB::WrapDB(
|
||||||
|
// make sure this db is already opened with memtable history enabled,
|
||||||
|
// auto compaction distabled and 2 phase commit enabled
|
||||||
|
DB* db, const TransactionDBOptions& txn_db_options,
|
||||||
|
const std::vector<size_t>& compaction_enabled_cf_indices,
|
||||||
|
const std::vector<ColumnFamilyHandle*>& handles, TransactionDB** dbptr) {
|
||||||
|
return WrapAnotherDBInternal(db, txn_db_options,
|
||||||
|
compaction_enabled_cf_indices, handles, dbptr);
|
||||||
|
}
|
||||||
|
|
||||||
Status TransactionDB::WrapStackableDB(
|
Status TransactionDB::WrapStackableDB(
|
||||||
// make sure this stackable_db is already opened with memtable history
|
// make sure this stackable_db is already opened with memtable history
|
||||||
@ -316,33 +327,8 @@ Status TransactionDB::WrapStackableDB(
|
|||||||
StackableDB* db, const TransactionDBOptions& txn_db_options,
|
StackableDB* db, const TransactionDBOptions& txn_db_options,
|
||||||
const std::vector<size_t>& compaction_enabled_cf_indices,
|
const std::vector<size_t>& compaction_enabled_cf_indices,
|
||||||
const std::vector<ColumnFamilyHandle*>& handles, TransactionDB** dbptr) {
|
const std::vector<ColumnFamilyHandle*>& handles, TransactionDB** dbptr) {
|
||||||
assert(db != nullptr);
|
return WrapAnotherDBInternal(db, txn_db_options,
|
||||||
assert(dbptr != nullptr);
|
compaction_enabled_cf_indices, handles, dbptr);
|
||||||
*dbptr = nullptr;
|
|
||||||
std::unique_ptr<PessimisticTransactionDB> txn_db;
|
|
||||||
|
|
||||||
switch (txn_db_options.write_policy) {
|
|
||||||
case WRITE_UNPREPARED:
|
|
||||||
txn_db.reset(new WriteUnpreparedTxnDB(
|
|
||||||
db, PessimisticTransactionDB::ValidateTxnDBOptions(txn_db_options)));
|
|
||||||
break;
|
|
||||||
case WRITE_PREPARED:
|
|
||||||
txn_db.reset(new WritePreparedTxnDB(
|
|
||||||
db, PessimisticTransactionDB::ValidateTxnDBOptions(txn_db_options)));
|
|
||||||
break;
|
|
||||||
case WRITE_COMMITTED:
|
|
||||||
default:
|
|
||||||
txn_db.reset(new WriteCommittedTxnDB(
|
|
||||||
db, PessimisticTransactionDB::ValidateTxnDBOptions(txn_db_options)));
|
|
||||||
}
|
|
||||||
txn_db->UpdateCFComparatorMap(handles);
|
|
||||||
Status s = txn_db->Initialize(compaction_enabled_cf_indices, handles);
|
|
||||||
// In case of a failure at this point, db is deleted via the txn_db destructor
|
|
||||||
// and set to nullptr.
|
|
||||||
if (s.ok()) {
|
|
||||||
*dbptr = txn_db.release();
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let LockManager know that this column family exists so it can
|
// Let LockManager know that this column family exists so it can
|
||||||
|
Loading…
Reference in New Issue
Block a user