From d52d6bc04213ce5f95b17c6d61422758e735432d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 3 Jan 2021 21:42:23 -0800 Subject: [PATCH] ircd::db: Add conf item to disable file deletion on open; add to -safe mode diagnostic. --- construct/construct.cc | 1 + include/ircd/db/database.h | 1 + ircd/db_database.cc | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/construct/construct.cc b/construct/construct.cc index f6fe9ce24..60f6a50b3 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -479,6 +479,7 @@ applyargs() nocompact = true; noautoapps = true; ircd::server::enable.set("false"); + ircd::db::auto_deletion.set("false"); } if(single && !bootstrap) diff --git a/include/ircd/db/database.h b/include/ircd/db/database.h index 51c5ddfab..1235772b6 100644 --- a/include/ircd/db/database.h +++ b/include/ircd/db/database.h @@ -20,6 +20,7 @@ namespace ircd::db extern conf::item open_repair; extern conf::item open_slave; extern conf::item auto_compact; + extern conf::item auto_deletion; // General information const std::string &name(const database &); diff --git a/ircd/db_database.cc b/ircd/db_database.cc index 18fc7f322..41864430e 100644 --- a/ircd/db_database.cc +++ b/ircd/db_database.cc @@ -70,6 +70,17 @@ ircd::db::auto_compact { "persist", false }, }; +/// Conf item toggles whether rocksdb is allowed to perform file deletion and +/// garbage collection operations as normal. This can be prevented for +/// diagnostic and safemode purposes. +decltype(ircd::db::auto_deletion) +ircd::db::auto_deletion +{ + { "name", "ircd.db.deletion.auto" }, + { "default", true }, + { "persist", false }, +}; + /// Conf item dictates whether databases will be opened in slave mode; this /// is a recent feature of RocksDB which may not be available. It allows two /// instances of a database, so long as only one is not opened as a slave. @@ -1232,6 +1243,12 @@ try return checkpointer; }()} { + // Disable file deletions here if ordered by the conf item (generally for + // -safe mode operation). If this can be done via DBOptions rather than + // here it would be better. + if(!db::auto_deletion) + db::fdeletions(*this, false); + // Conduct drops from schema changes. The database must be fully opened // as if they were not dropped first, then we conduct the drop operation // here. The drop operation has no effects until the database is next