0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd::db: Improve dbopts string manipulation related.

This commit is contained in:
Jason Volk 2018-04-09 11:51:36 -07:00
parent 6dcc7e29df
commit 343a1f38a3
2 changed files with 12 additions and 14 deletions

View file

@ -314,7 +314,7 @@ try
// describe all of the columns found in the database at path.
const auto opts
{
make_dbopts(std::string(this->optstr))
make_dbopts(this->optstr)
};
const auto required
@ -360,7 +360,7 @@ try
bool read_only{false};
auto opts
{
make_dbopts(this->optstr, &read_only, &fsck)
make_dbopts(this->optstr, &this->optstr, &read_only, &fsck)
};
// Setup sundry
@ -4862,17 +4862,9 @@ const
// Misc
//
template<class... args>
rocksdb::DBOptions
ircd::db::make_dbopts(const std::string &optstr,
args&&... a)
{
std::string _optstr(optstr);
return make_dbopts(_optstr, std::forward<args>(a)...);
}
rocksdb::DBOptions
ircd::db::make_dbopts(std::string &optstr,
ircd::db::make_dbopts(std::string optstr,
std::string *const &out,
bool *const read_only,
bool *const fsck)
{
@ -4880,11 +4872,15 @@ ircd::db::make_dbopts(std::string &optstr,
// to open the database as read_only and then remove that from the string.
if(read_only)
*read_only = optstr_find_and_remove(optstr, "read_only=true;"s);
else
optstr_find_and_remove(optstr, "read_only=true;"s);
// We also allow the user to specify fsck=true to run a repair operation on
// the db. This may be expensive to do by default every startup.
if(fsck)
*fsck = optstr_find_and_remove(optstr, "fsck=true;"s);
else
optstr_find_and_remove(optstr, "fsck=true;"s);
// Generate RocksDB options from string
rocksdb::DBOptions opts
@ -4892,6 +4888,9 @@ ircd::db::make_dbopts(std::string &optstr,
database::options(optstr)
};
if(out)
*out = std::move(optstr);
return opts;
}

View file

@ -37,8 +37,7 @@ namespace ircd::db
// Database options creator
bool optstr_find_and_remove(std::string &optstr, const std::string &what);
rocksdb::DBOptions make_dbopts(std::string &optstr, bool *read_only = nullptr, bool *fsck = nullptr);
template<class... args> rocksdb::DBOptions make_dbopts(const std::string &, args&&...);
rocksdb::DBOptions make_dbopts(std::string optstr, std::string *const &out = nullptr, bool *read_only = nullptr, bool *fsck = nullptr);
// Validation functors
bool valid(const rocksdb::Iterator &);