Skip to content

Commit

Permalink
utilities: Add support for registering use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AmnonHanuhov committed Aug 8, 2023
1 parent 7fdd7b9 commit 25945d7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 85 additions & 0 deletions utilities/use_cases.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <memory>

#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<DBCrashtestUseCase>(
SimpleDefaultParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new SimpleDefaultParams();
});
library.AddFactory<DBCrashtestUseCase>(
TxnParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new TxnParams();
});
library.AddFactory<DBCrashtestUseCase>(
BestEffortsRecoveryParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new BestEffortsRecoveryParams();
});
library.AddFactory<DBCrashtestUseCase>(
BlobParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new BlobParams();
});
library.AddFactory<DBCrashtestUseCase>(
TieredParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new TieredParams();
});
library.AddFactory<DBCrashtestUseCase>(
MultiopsTxnDefaultParams::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<DBCrashtestUseCase>* /*guard*/,
std::string* /*errmsg*/) {
return new MultiopsTxnDefaultParams();
});
return 1;
}

static int RegisterBuiltinUseCases(ObjectLibrary& library,
const std::string& arg) {
library.AddFactory<UseCase>(
DBCrashtestUseCase::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<UseCase>* /*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<UseCase*>(*result);
Status status =
LoadStaticObject<UseCase>(cfg_opts, value, &use_case);
if (status.ok()) {
*result = const_cast<UseCase*>(use_case);
}
return status;
}
} // namespace ROCKSDB_NAMESPACE

0 comments on commit 25945d7

Please sign in to comment.