diff --git a/construct/construct.cc b/construct/construct.cc index fd3a9ed9b..cf4bbf453 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -24,6 +24,7 @@ bool single; bool debugmode; bool nolisten; bool noautomod; +bool nocompact; bool checkdb; bool pitrecdb; bool repairdb; @@ -54,6 +55,7 @@ lgetopt opts[] { "execute", &execute, lgetopt::STRINGS, "Execute command lines immediately after startup" }, { "nolisten", &nolisten, lgetopt::BOOL, "Normal execution but without listening sockets" }, { "noautomod", &noautomod, lgetopt::BOOL, "Normal execution but without autoloading modules" }, + { "nocompact", &nocompact, lgetopt::BOOL, "Disable automatic database compaction" }, { "checkdb", &checkdb, lgetopt::BOOL, "Perform complete checks of databases when opening" }, { "pitrecdb", &pitrecdb, lgetopt::BOOL, "Allow Point-In-Time-Recover if DB reports corruption after crash" }, { "repairdb", &repairdb, lgetopt::BOOL, "Perform full DB repair after deep block/file corruption" }, @@ -513,6 +515,9 @@ applyargs() else ircd::db::open_repair.set("false"); + if(nocompact) + ircd::db::auto_compact.set("false"); + if(nodirect) ircd::fs::fd::opts::direct_io_enable.set("false"); else diff --git a/include/ircd/db/database.h b/include/ircd/db/database.h index 190f3d506..3da318774 100644 --- a/include/ircd/db/database.h +++ b/include/ircd/db/database.h @@ -19,6 +19,7 @@ namespace ircd::db extern conf::item open_check; extern conf::item open_recover; extern conf::item open_repair; + extern conf::item auto_compact; // General information const std::string &name(const database &); diff --git a/ircd/db.cc b/ircd/db.cc index a19f05baa..d91e741bf 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -442,6 +442,17 @@ ircd::db::open_repair { "persist", false }, }; +/// Conf item toggles whether automatic compaction is enabled or disabled for +/// all databases upon opening. This is useful for developers, debugging and +/// valgrind etc to prevent these background jobs from spawning when unwanted. +decltype(ircd::db::auto_compact) +ircd::db::auto_compact +{ + { "name", "ircd.db.compact.auto" }, + { "default", true }, + { "persist", false }, +}; + void ircd::db::sync(database &d) { @@ -2014,6 +2025,10 @@ ircd::db::database::column::column(database &d, this->options.min_write_buffer_number_to_merge = 4; this->options.max_write_buffer_number_to_maintain = 0; + // Conf item can be set to disable automatic compactions. For developers + // and debugging; good for valgrind. + this->options.disable_auto_compactions = !bool(db::auto_compact); + // Set the compaction style; we don't override this in the descriptor yet. //this->options.compaction_style = rocksdb::kCompactionStyleNone; this->options.compaction_style = rocksdb::kCompactionStyleLevel; @@ -2033,7 +2048,6 @@ ircd::db::database::column::column(database &d, this->options.num_levels = 7; this->options.level0_file_num_compaction_trigger = 2; - this->options.disable_auto_compactions = false; this->options.level_compaction_dynamic_level_bytes = false; this->options.ttl = 0; #ifdef IRCD_DB_HAS_PERIODIC_COMPACTIONS