-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utilities: Add support for registering use cases
- Loading branch information
1 parent
7fdd7b9
commit 25945d7
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |