From 7834c86360ed93787d53dd91a1e1cbc5f4921177 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 21 Sep 2018 15:08:57 -0700 Subject: [PATCH] ircd::db: Add support for direct SST file ingestion. --- include/ircd/db/column.h | 1 + ircd/db.cc | 24 ++++++++++++++++++++++ modules/console.cc | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/include/ircd/db/column.h b/include/ircd/db/column.h index 2901789fd..2630c7bde 100644 --- a/include/ircd/db/column.h +++ b/include/ircd/db/column.h @@ -59,6 +59,7 @@ namespace ircd::db void del(column &, const string_view &key, const sopts & = {}); // [SET] Other operations + 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 & = {}); diff --git a/ircd/db.cc b/ircd/db.cc index 2e48de849..f278f1885 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -7580,6 +7580,30 @@ ircd::db::setopt(column &column, }; } +void +ircd::db::ingest(column &column, + const string_view &path) +{ + database &d(column); + database::column &c(column); + + rocksdb::IngestExternalFileOptions opts; + opts.allow_global_seqno = false; + opts.allow_blocking_flush = false; + + const std::vector files + { + { std::string{path} } + }; + + const std::lock_guard lock{write_mutex}; + const ctx::uninterruptible::nothrow ui; + throw_on_error + { + d.d->IngestExternalFile(c, files, opts) + }; +} + void ircd::db::del(column &column, const string_view &key, diff --git a/modules/console.cc b/modules/console.cc index 520f6b0ee..f04792dcc 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1893,6 +1893,49 @@ catch(const std::out_of_range &e) return true; } +bool +console_cmd__db__ingest(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", "column", "path" + }}; + + const auto dbname + { + param.at("dbname") + }; + + const auto colname + { + param.at("column") + }; + + const auto path + { + param.at("path") + }; + + auto &database + { + db::database::get(dbname) + }; + + db::column column + { + database, colname + }; + + db::ingest(column, path); + return true; +} +catch(const std::out_of_range &e) +{ + out << "No open database by that name" << std::endl; + return true; +} + bool console_cmd__db__files(opt &out, const string_view &line) try