From 8083a5d71cb227c9cdd3a219e72f2212a9777b7a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 26 Apr 2018 17:19:29 -0700 Subject: [PATCH] ircd::db: Add WAL fflush; move table flushes to "sort()"; adjust interfaces. --- include/ircd/db/column.h | 2 +- include/ircd/db/database/database.h | 5 +-- ircd/db.cc | 54 +++++++++++++++++++---------- modules/console.cc | 36 ++++++++++++++++++- 4 files changed, 75 insertions(+), 22 deletions(-) diff --git a/include/ircd/db/column.h b/include/ircd/db/column.h index a0650d532..2cf6d413b 100644 --- a/include/ircd/db/column.h +++ b/include/ircd/db/column.h @@ -48,7 +48,7 @@ namespace ircd::db // [SET] Other operations void setopt(column &, const string_view &key, const string_view &val); void compact(column &, const string_view &begin = {}, const string_view &end = {}); - void flush(column &, const bool &blocking = false); + void sort(column &, const bool &blocking = false); } /// Columns add the ability to run multiple LevelDB's in synchrony under the same diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 4f097f59b..055c0dcf4 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -44,10 +44,11 @@ namespace ircd::db // Control panel void setopt(database &, const string_view &key, const string_view &val); - void compact(database &); void fdeletions(database &, const bool &enable, const bool &force = false); void checkpoint(database &, const string_view &dir); - void flush(database &, const bool &blocking = true); + void compact(database &); + void sort(database &, const bool &blocking = true); + void flush(database &, const bool &sync = false); void sync(database &); } diff --git a/ircd/db.cc b/ircd/db.cc index c66224b8c..d5224cf60 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -135,12 +135,36 @@ ircd::db::sync(database &d) /// each column individually. void ircd::db::flush(database &d, - const bool &blocking) + const bool &sync) +{ + throw_on_error + { + d.d->FlushWAL(sync) + }; +} + +/// Moves memory structures to SST files for all columns. This doesn't +/// necessarily sort anything that wasn't previously sorted, but it may create +/// new SST files and shouldn't be confused with a typical fflush(). +/// Note that if blocking=true, blocking may occur for each column individually. +void +ircd::db::sort(database &d, + const bool &blocking) { for(const auto &c : d.columns) { db::column column{*c}; - db::flush(column, blocking); + db::sort(column, blocking); + } +} + +void +ircd::db::compact(database &d) +{ + for(const auto &c : d.columns) + { + db::column column{*c}; + compact(column, string_view{}, string_view{}); } } @@ -190,16 +214,6 @@ ircd::db::fdeletions(database &d, }; } -void -ircd::db::compact(database &d) -{ - for(const auto &c : d.columns) - { - db::column column{*c}; - compact(column, string_view{}, string_view{}); - } -} - void ircd::db::setopt(database &d, const string_view &key, @@ -628,12 +642,16 @@ noexcept try path); rocksdb::CancelAllBackgroundWork(d.get(), true); // true = blocking - this->checkpoint.reset(nullptr); - this->columns.clear(); - log.debug("'%s': closed columns; background_errors: %lu; synchronizing...", + log.debug("'%s': background_errors: %lu; flushing...", name, property(*this, rocksdb::DB::Properties::kBackgroundErrors)); + flush(*this); + this->checkpoint.reset(nullptr); + this->columns.clear(); + log.debug("'%s': closed columns; synchronizing...", + name); + sync(*this); log.debug("'%s': synchronized with hardware.", name); @@ -3944,14 +3962,14 @@ ircd::db::describe(const column &column) } void -ircd::db::flush(column &column, - const bool &blocking) +ircd::db::sort(column &column, + const bool &blocking) { database::column &c(column); database &d(*c.d); rocksdb::FlushOptions opts; opts.wait = blocking; - log.debug("'%s':'%s' @%lu FLUSH", + log.debug("'%s':'%s' @%lu FLUSH (sort)", name(d), name(c), sequence(d)); diff --git a/modules/console.cc b/modules/console.cc index 3c89b2c97..dbf9d1e4e 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -818,6 +818,40 @@ catch(const std::out_of_range &e) bool console_cmd__db__flush(opt &out, const string_view &line) try +{ + const params param{line, " ", + { + "dbname", "[sync]" + }}; + + const auto dbname + { + param.at(0) + }; + + const auto sync + { + param.at(1, false) + }; + + auto &database + { + *db::database::dbs.at(dbname) + }; + + flush(database, sync); + out << "done" << 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__sort(opt &out, const string_view &line) +try { const params param{line, " ", { @@ -839,7 +873,7 @@ try *db::database::dbs.at(dbname) }; - flush(database, blocking); + sort(database, blocking); out << "done" << std::endl; return true; }