diff --git a/include/ircd/db/cache.h b/include/ircd/db/cache.h index 60a9a2519..d66a968f1 100644 --- a/include/ircd/db/cache.h +++ b/include/ircd/db/cache.h @@ -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 for_each(rocksdb::Cache &, const cache_closure &); diff --git a/ircd/db.cc b/ircd/db.cc index 741a18536..426d3d82a 100644 --- a/ircd/db.cc +++ b/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) diff --git a/modules/console.cc b/modules/console.cc index d2d371baf..b1f37966c 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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) {