diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index 2c69f7359..cb5ba0330 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -276,10 +276,10 @@ void TransactionDB::PrepareWrap( db_options->allow_2pc = true; } -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, +namespace { +template +Status WrapAnotherDBInternal( + DBType* db, const TransactionDBOptions& txn_db_options, const std::vector& compaction_enabled_cf_indices, const std::vector& handles, TransactionDB** dbptr) { assert(db != nullptr); @@ -309,6 +309,17 @@ Status TransactionDB::WrapDB( } 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& compaction_enabled_cf_indices, + const std::vector& handles, TransactionDB** dbptr) { + return WrapAnotherDBInternal(db, txn_db_options, + compaction_enabled_cf_indices, handles, dbptr); +} Status TransactionDB::WrapStackableDB( // 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, const std::vector& compaction_enabled_cf_indices, const std::vector& handles, TransactionDB** dbptr) { - assert(db != nullptr); - assert(dbptr != nullptr); - *dbptr = nullptr; - std::unique_ptr 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; + return WrapAnotherDBInternal(db, txn_db_options, + compaction_enabled_cf_indices, handles, dbptr); } // Let LockManager know that this column family exists so it can