diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a5df4213..759c8ab0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -657,6 +657,8 @@ set(SOURCES utilities/transactions/transaction_util.cc utilities/transactions/write_prepared_txn.cc utilities/transactions/write_prepared_txn_db.cc + utilities/transactions/write_unprepared_txn.cc + utilities/transactions/write_unprepared_txn_db.cc utilities/ttl/db_ttl_impl.cc utilities/write_batch_with_index/write_batch_with_index.cc utilities/write_batch_with_index/write_batch_with_index_internal.cc diff --git a/TARGETS b/TARGETS index 7bd3a45dc..1abe9b8ff 100644 --- a/TARGETS +++ b/TARGETS @@ -280,6 +280,8 @@ cpp_library( "utilities/transactions/transaction_util.cc", "utilities/transactions/write_prepared_txn.cc", "utilities/transactions/write_prepared_txn_db.cc", + "utilities/transactions/write_unprepared_txn.cc", + "utilities/transactions/write_unprepared_txn_db.cc", "utilities/ttl/db_ttl_impl.cc", "utilities/write_batch_with_index/write_batch_with_index.cc", "utilities/write_batch_with_index/write_batch_with_index_internal.cc", diff --git a/src.mk b/src.mk index bc84d24ba..bfe4a1eb5 100644 --- a/src.mk +++ b/src.mk @@ -208,6 +208,8 @@ LIB_SOURCES = \ utilities/transactions/transaction_util.cc \ utilities/transactions/write_prepared_txn.cc \ utilities/transactions/write_prepared_txn_db.cc \ + utilities/transactions/write_unprepared_txn.cc \ + utilities/transactions/write_unprepared_txn_db.cc \ utilities/ttl/db_ttl_impl.cc \ utilities/write_batch_with_index/write_batch_with_index.cc \ utilities/write_batch_with_index/write_batch_with_index_internal.cc \ diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index 1e72299fa..9fc8a8c08 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -26,6 +26,7 @@ #include "utilities/transactions/pessimistic_transaction.h" #include "utilities/transactions/transaction_db_mutex_impl.h" #include "utilities/transactions/write_prepared_txn_db.h" +#include "utilities/transactions/write_unprepared_txn_db.h" namespace rocksdb { @@ -264,7 +265,9 @@ Status TransactionDB::WrapDB( std::unique_ptr txn_db; switch (txn_db_options.write_policy) { case WRITE_UNPREPARED: - return Status::NotSupported("WRITE_UNPREPARED is not implemented yet"); + 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))); @@ -297,7 +300,9 @@ Status TransactionDB::WrapStackableDB( switch (txn_db_options.write_policy) { case WRITE_UNPREPARED: - return Status::NotSupported("WRITE_UNPREPARED is not implemented yet"); + 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))); diff --git a/utilities/transactions/write_unprepared_txn.cc b/utilities/transactions/write_unprepared_txn.cc new file mode 100644 index 000000000..3ed263039 --- /dev/null +++ b/utilities/transactions/write_unprepared_txn.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#ifndef ROCKSDB_LITE + +#include "utilities/transactions/write_unprepared_txn.h" + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +namespace rocksdb { + + +} // namespace rocksdb + +#endif // ROCKSDB_LITE diff --git a/utilities/transactions/write_unprepared_txn.h b/utilities/transactions/write_unprepared_txn.h new file mode 100644 index 000000000..bc5141437 --- /dev/null +++ b/utilities/transactions/write_unprepared_txn.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#pragma once + +#ifndef ROCKSDB_LITE + +#include "utilities/transactions/write_prepared_txn.h" + +namespace rocksdb { + +class WriteUnpreparedTxn : public WritePreparedTxn { + using WritePreparedTxn::WritePreparedTxn; + +}; + +} // namespace rocksdb + +#endif // ROCKSDB_LITE diff --git a/utilities/transactions/write_unprepared_txn_db.cc b/utilities/transactions/write_unprepared_txn_db.cc new file mode 100644 index 000000000..036e96d34 --- /dev/null +++ b/utilities/transactions/write_unprepared_txn_db.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#ifndef ROCKSDB_LITE + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#include "utilities/transactions/write_unprepared_txn_db.h" +#include "rocksdb/utilities/transaction_db.h" + +namespace rocksdb { + +Transaction* WriteUnpreparedTxnDB::BeginTransaction( +const WriteOptions& write_options, const TransactionOptions& txn_options, +Transaction* old_txn) { + if (old_txn != nullptr) { + ReinitializeTransaction(old_txn, write_options, txn_options); + return old_txn; + } else { + return new WriteUnpreparedTxn(this, write_options, txn_options); + } +} + +} // namespace rocksdb +#endif // ROCKSDB_LITE diff --git a/utilities/transactions/write_unprepared_txn_db.h b/utilities/transactions/write_unprepared_txn_db.h new file mode 100644 index 000000000..9bb6ad3d2 --- /dev/null +++ b/utilities/transactions/write_unprepared_txn_db.h @@ -0,0 +1,27 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#pragma once +#ifndef ROCKSDB_LITE + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#include "utilities/transactions/write_prepared_txn_db.h" + +#include "utilities/transactions/write_unprepared_txn.h" + +namespace rocksdb { + +class WriteUnpreparedTxnDB : public WritePreparedTxnDB { + using WritePreparedTxnDB::WritePreparedTxnDB; + + Transaction* BeginTransaction(const WriteOptions& write_options, const TransactionOptions& txn_options, + Transaction* old_txn) override; +}; + +} // namespace rocksdb +#endif // ROCKSDB_LITE