diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index f6b3d9a77..7cad780c9 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -48,6 +48,8 @@ namespace ircd::db void setopt(database &, const string_view &key, const string_view &val); void fdeletions(database &, const bool &enable, const bool &force = false); uint64_t checkpoint(database &); + void bgcontinue(database &); + void bgpause(database &); void resume(database &); void check(database &); void compact(database &, const std::pair &level, const compactor & = {}); diff --git a/ircd/db.cc b/ircd/db.cc index 828333b52..bd788a884 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -497,6 +497,42 @@ ircd::db::resume(database &d) }; } +void +ircd::db::bgpause(database &d) +{ + assert(d.d); + const ctx::uninterruptible::nothrow ui; + + throw_on_error + { + d.d->PauseBackgroundWork() + }; + + log::debug + { + log, "'%s': Paused all background work", + name(d) + }; +} + +void +ircd::db::bgcontinue(database &d) +{ + assert(d.d); + const ctx::uninterruptible::nothrow ui; + + log::debug + { + log, "'%s': Continuing background work", + name(d) + }; + + throw_on_error + { + d.d->ContinueBackgroundWork() + }; +} + /// Writes a snapshot of this database to the directory specified. The /// snapshot consists of hardlinks to the bulk data files of this db, but /// copies the other stuff that usually gets corrupted. The directory can diff --git a/modules/console.cc b/modules/console.cc index 9c6b16179..b5656f954 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1324,6 +1324,64 @@ console_cmd__db__compressions(opt &out, const string_view &line) return true; } +bool +console_cmd__db__pause(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", + }}; + + const auto dbname + { + param.at(0) + }; + + auto &database + { + db::database::get(dbname) + }; + + bgpause(database); + out << "Paused background jobs for '" << dbname << "'" << std::endl; + return true; +} +catch(const std::out_of_range &e) +{ + out << "No open database by that name" << std::endl; + return true; +} + +bool +console_cmd__db__continue(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", + }}; + + const auto dbname + { + param.at(0) + }; + + auto &database + { + db::database::get(dbname) + }; + + bgcontinue(database); + out << "Resumed background jobs for '" << dbname << "'" << std::endl; + return true; +} +catch(const std::out_of_range &e) +{ + out << "No open database by that name" << std::endl; + return true; +} + bool console_cmd__db__sync(opt &out, const string_view &line) try