mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::db: Add cache clear interface w/ console cmd.
This commit is contained in:
parent
7bfe9e94a1
commit
4ce29f1d22
3 changed files with 72 additions and 0 deletions
|
@ -41,6 +41,10 @@ namespace ircd::db
|
|||
void remove(rocksdb::Cache &, const string_view &key);
|
||||
void remove(rocksdb::Cache *const &, const string_view &key);
|
||||
|
||||
// Clear the cache (won't clear entries which are actively referenced)
|
||||
void clear(rocksdb::Cache &);
|
||||
void clear(rocksdb::Cache *const &);
|
||||
|
||||
// Iterate the cache entries.
|
||||
using cache_closure = std::function<void (const string_view &, const size_t &)>;
|
||||
void for_each(rocksdb::Cache &, const cache_closure &);
|
||||
|
|
13
ircd/db.cc
13
ircd/db.cc
|
@ -5178,6 +5178,19 @@ ircd::db::for_each(rocksdb::Cache &cache,
|
|||
false);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::db::clear(rocksdb::Cache *const &cache)
|
||||
{
|
||||
if(cache)
|
||||
clear(*cache);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::db::clear(rocksdb::Cache &cache)
|
||||
{
|
||||
cache.EraseUnRefEntries();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::db::remove(rocksdb::Cache *const &cache,
|
||||
const string_view &key)
|
||||
|
|
|
@ -1422,6 +1422,61 @@ catch(const std::out_of_range &e)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__db__cache__clear(opt &out, const string_view &line)
|
||||
try
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"dbname", "column"
|
||||
}};
|
||||
|
||||
const auto dbname
|
||||
{
|
||||
param.at(0)
|
||||
};
|
||||
|
||||
const auto colname
|
||||
{
|
||||
param[1]
|
||||
};
|
||||
|
||||
auto &database
|
||||
{
|
||||
*db::database::dbs.at(dbname)
|
||||
};
|
||||
|
||||
const auto clear{[&out, &database]
|
||||
(const string_view &colname)
|
||||
{
|
||||
db::column column
|
||||
{
|
||||
database, colname
|
||||
};
|
||||
|
||||
db::clear(cache(column));
|
||||
db::clear(cache_compressed(column));
|
||||
out << "Cleared caches for '" << name(database) << "' '" << colname << "'"
|
||||
<< std::endl;
|
||||
}};
|
||||
|
||||
if(!colname || colname == "**")
|
||||
{
|
||||
for(const auto &colname : database.column_names)
|
||||
clear(colname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
clear(colname);
|
||||
return true;
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
out << "No open database by that name" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__db__stats(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue