From fae947d43333be0c151ebe5c8ef9c0264f08fb03 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 16 Dec 2018 18:00:54 -0800 Subject: [PATCH] ircd::db: Add a background cancel interface w/ console cmd. --- include/ircd/db/database/database.h | 1 + ircd/db.cc | 41 +++++++++++++++++++++++++++++ modules/console.cc | 29 ++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 7cad780c9..4592a64b7 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -48,6 +48,7 @@ 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 bgcancel(database &, const bool &blocking = true); void bgcontinue(database &); void bgpause(database &); void resume(database &); diff --git a/ircd/db.cc b/ircd/db.cc index d2f45ee5d..325f52abb 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -525,6 +525,47 @@ ircd::db::bgcontinue(database &d) }; } +void +ircd::db::bgcancel(database &d, + const bool &blocking) +{ + assert(d.d); + log::debug + { + log, "'%s': Canceling all background work...", + name(d) + }; + + rocksdb::CancelAllBackgroundWork(d.d.get(), blocking); + if(!blocking) + return; + + assert(d.env); + assert(d.env->st); + const ctx::uninterruptible::nothrow ui; + for(auto &pool : d.env->st->pool) + if(pool) + pool->wait(); + + const auto errors + { + property(d, rocksdb::DB::Properties::kBackgroundErrors) + }; + + const auto facility + { + errors? log::facility::ERROR : log::facility::DEBUG + }; + + log::logf + { + log, facility, + "'%s': Canceled all background work; errors:%lu", + name(d), + errors + }; +} + /// 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 209b3b242..3fd266dfa 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1441,6 +1441,35 @@ catch(const std::out_of_range &e) return true; } +bool +console_cmd__db__cancel(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", + }}; + + const auto dbname + { + param.at(0) + }; + + auto &database + { + db::database::get(dbname) + }; + + bgcancel(database); + out << "canceld 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