From 62874ff498cf7e1bf9376dba5de2fe84bb6cd396 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 12 Dec 2018 15:53:16 -0800 Subject: [PATCH] ircd::db: Add src and dst level arguments to db::compact files interface. --- include/ircd/db/column.h | 2 +- include/ircd/db/database/database.h | 2 +- ircd/db.cc | 16 ++++++++++++---- modules/console.cc | 7 ++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/ircd/db/column.h b/include/ircd/db/column.h index 69a11495a..c43dbb190 100644 --- a/include/ircd/db/column.h +++ b/include/ircd/db/column.h @@ -63,7 +63,7 @@ namespace ircd::db void ingest(column &, const string_view &path); void setopt(column &, const string_view &key, const string_view &val); void compact(column &, const std::pair &, const int &to_level = -1, const compactor & = {}); - void compact(column &, const int &level = -1, const compactor & = {}); + void compact(column &, const std::pair &level = {-1, -1}, const compactor & = {}); void sort(column &, const bool &blocking = false); void drop(column &); // danger } diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 691f3d58b..f6b3d9a77 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -50,7 +50,7 @@ namespace ircd::db uint64_t checkpoint(database &); void resume(database &); void check(database &); - void compact(database &, const int &level, const compactor & = {}); + void compact(database &, const std::pair &level, const compactor & = {}); void compact(database &, const compactor & = {}); void sort(database &, const bool &blocking = true); void flush(database &, const bool &sync = false); diff --git a/ircd/db.cc b/ircd/db.cc index 816e261b7..2f8c92f4c 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -441,7 +441,7 @@ ircd::db::compact(database &d, void ircd::db::compact(database &d, - const int &level, + const std::pair &level, const compactor &cb) { for(const auto &c : d.columns) @@ -9169,22 +9169,30 @@ ircd::db::sort(column &column, void ircd::db::compact(column &column, - const int &level_, + const std::pair &level, const compactor &cb) { database::column &c(column); database &d(*c.d); + const auto &dst_level{level.second}; + const auto &src_level{level.first}; + rocksdb::ColumnFamilyMetaData cfmd; d.d->GetColumnFamilyMetaData(c, &cfmd); for(const auto &level : cfmd.levels) { - if(level_ != -1 && level.level != level_) + if(src_level != -1 && src_level != level.level) continue; if(level.files.empty()) continue; + const auto &to_level + { + dst_level > -1? dst_level : level.level + }; + rocksdb::CompactionOptions opts; opts.output_file_size_limit = 1_GiB; //TODO: conf @@ -9233,7 +9241,7 @@ ircd::db::compact(column &column, throw_on_error { - d.d->CompactFiles(opts, c, files, level.level) + d.d->CompactFiles(opts, c, files, to_level) }; } } diff --git a/modules/console.cc b/modules/console.cc index 6efc25010..f4181fe82 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1560,7 +1560,7 @@ try { const params param{line, " ", { - "dbname", "[colname]", "[level]" + "dbname", "[colname]", "[srclevel]", "[dstlevel]" }}; const auto dbname @@ -1573,9 +1573,10 @@ try param[1] }; - const auto level + const std::pair level { - param.at(2, -1) + param.at(2, -1), + param.at(3, -1) }; auto &database