diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b2f3fb13f..9f3e728734 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1003,6 +1003,7 @@ set(SOURCES utilities/transactions/write_unprepared_txn.cc utilities/transactions/write_unprepared_txn_db.cc utilities/ttl/db_ttl_impl.cc + utilities/use_cases.cc utilities/wal_filter.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/use_cases.cc b/utilities/use_cases.cc new file mode 100644 index 0000000000..821f49d362 --- /dev/null +++ b/utilities/use_cases.cc @@ -0,0 +1,85 @@ +#include + +#include "rocksdb/db_crashtest_use_case.h" +#include "rocksdb/options.h" +#include "rocksdb/use_case.h" +#include "rocksdb/utilities/customizable_util.h" +#include "rocksdb/utilities/options_type.h" + +namespace ROCKSDB_NAMESPACE { +static int RegisterBuiltinDBCrashtestUseCases(ObjectLibrary& library, + const std::string& arg) { + library.AddFactory( + SimpleDefaultParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new SimpleDefaultParams(); + }); + library.AddFactory( + TxnParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new TxnParams(); + }); + library.AddFactory( + BestEffortsRecoveryParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new BestEffortsRecoveryParams(); + }); + library.AddFactory( + BlobParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new BlobParams(); + }); + library.AddFactory( + TieredParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new TieredParams(); + }); + library.AddFactory( + MultiopsTxnDefaultParams::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new MultiopsTxnDefaultParams(); + }); + return 1; +} + +static int RegisterBuiltinUseCases(ObjectLibrary& library, + const std::string& arg) { + library.AddFactory( + DBCrashtestUseCase::kClassName(), + [](const std::string& /*uri*/, + std::unique_ptr* /*guard*/, + std::string* /*errmsg*/) { + return new DBCrashtestUseCase(); + }); + RegisterBuiltinDBCrashtestUseCases(library, arg); + return 1; +} + +Status UseCase::CreateFromString(const ConfigOptions& cfg_opts, + const std::string& value, + const UseCase** result) { + static std::once_flag once; + std::call_once(once, [&]() { + RegisterBuiltinUseCases(*(ObjectLibrary::Default().get()), ""); + }); + UseCase* use_case = const_cast(*result); + Status status = + LoadStaticObject(cfg_opts, value, &use_case); + if (status.ok()) { + *result = const_cast(use_case); + } + return status; +} +} // namespace ROCKSDB_NAMESPACE \ No newline at end of file