From 99ff78f5c791d4f7002b1cf966d0c5578791e3be Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 22 Sep 2018 13:13:05 -0700 Subject: [PATCH] ircd::db: Create an sst utility space; move fileinfo into sst. --- include/ircd/db/database/database.h | 2 +- .../ircd/db/database/{fileinfo.h => sst.h} | 34 ++++++++++++------- include/ircd/db/db.h | 2 +- ircd/db.cc | 28 ++++++++------- modules/console.cc | 10 +++--- 5 files changed, 44 insertions(+), 32 deletions(-) rename include/ircd/db/database/{fileinfo.h => sst.h} (58%) diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index b0859ec5e..de1d3c2b4 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -79,7 +79,7 @@ struct ircd::db::database struct column; struct env; struct cache; - struct fileinfo; + struct sst; std::string name; uint64_t checkpoint; diff --git a/include/ircd/db/database/fileinfo.h b/include/ircd/db/database/sst.h similarity index 58% rename from include/ircd/db/database/fileinfo.h rename to include/ircd/db/database/sst.h index a510ee41a..dc72b5b0b 100644 --- a/include/ircd/db/database/fileinfo.h +++ b/include/ircd/db/database/sst.h @@ -9,17 +9,25 @@ // full license for this software is available in the LICENSE file. #pragma once -#define HAVE_IRCD_DB_DATABASE_FILEINFO_H +#define HAVE_IRCD_DB_DATABASE_SST_H -namespace ircd::db +struct ircd::db::database::sst { - void sst_dump(const vector_view &args); -} + struct info; -/// Database snapshot object. Maintaining this object will maintain a -/// consistent state of access to the database at the sequence number -/// from when it's acquired. -struct ircd::db::database::fileinfo + static void dump(const vector_view &args); +}; + +struct ircd::db::database::sst::writer +{ + using key_range = std::pair; + + writer(const database &, const column &, const key_range & = {}); +}; + +/// Get info about an SST file. +/// +struct ircd::db::database::sst::info { struct vector; @@ -35,13 +43,13 @@ struct ircd::db::database::fileinfo int level {-1}; bool compacting {false}; - fileinfo() = default; - fileinfo(rocksdb::LiveFileMetaData &&); - fileinfo(const database &, const string_view &filename); + info() = default; + info(rocksdb::LiveFileMetaData &&); + info(const database &, const string_view &filename); }; -struct ircd::db::database::fileinfo::vector -:std::vector +struct ircd::db::database::sst::info::vector +:std::vector { vector() = default; explicit vector(const database &); diff --git a/include/ircd/db/db.h b/include/ircd/db/db.h index 5bdffc4a5..28bc5544d 100644 --- a/include/ircd/db/db.h +++ b/include/ircd/db/db.h @@ -69,7 +69,7 @@ enum class ircd::db::pos #include "database/database.h" #include "database/options.h" #include "database/snapshot.h" -#include "database/fileinfo.h" +#include "database/sst.h" #include "cache.h" #include "opts.h" #include "column.h" diff --git a/ircd/db.cc b/ircd/db.cc index 039ec6914..5e68f1f8b 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -2486,25 +2486,29 @@ const noexcept /////////////////////////////////////////////////////////////////////////////// // -// database::fileinfo +// database::sst // void -ircd::db::sst_dump(const vector_view &args) +ircd::db::database::sst::dump(const vector_view &args) { - thread_local char arg[16][256] + static const size_t ARG_MAX {16}; + static const size_t ARG_MAX_LEN {256}; + + thread_local char arg[ARG_MAX][ARG_MAX_LEN] { "./sst_dump" }; size_t i(0); - char *argv[16] { arg[i++] }; - for(; i < 15 && i - 1 < args.size(); ++i) + char *argv[ARG_MAX] { arg[i++] }; + for(; i < ARG_MAX - 1 && i - 1 < args.size(); ++i) { strlcpy(arg[i], args.at(i - 1)); argv[i] = arg[i]; } - argv[i] = nullptr; + argv[i++] = nullptr; + assert(i <= ARG_MAX); rocksdb::SSTDumpTool tool; const int ret @@ -2520,10 +2524,10 @@ ircd::db::sst_dump(const vector_view &args) } // -// fileinfo::vector +// sst::info::vector // -ircd::db::database::fileinfo::vector::vector(const database &d) +ircd::db::database::sst::info::vector::vector(const database &d) { std::vector v; d.d->GetLiveFilesMetaData(&v); @@ -2540,8 +2544,8 @@ ircd::db::database::fileinfo::vector::vector(const database &d) // fileinfo::fileinfo // -ircd::db::database::fileinfo::fileinfo(const database &d, - const string_view &filename) +ircd::db::database::sst::info::info(const database &d, + const string_view &filename) { std::vector v; d.d->GetLiveFilesMetaData(&v); @@ -2549,7 +2553,7 @@ ircd::db::database::fileinfo::fileinfo(const database &d, for(auto &md : v) if(md.name == filename) { - new (this) fileinfo(std::move(md)); + new (this) info(std::move(md)); return; } @@ -2561,7 +2565,7 @@ ircd::db::database::fileinfo::fileinfo(const database &d, }; } -ircd::db::database::fileinfo::fileinfo(rocksdb::LiveFileMetaData &&md) +ircd::db::database::sst::info::info(rocksdb::LiveFileMetaData &&md) :name{std::move(md.name)} ,path{std::move(md.db_path)} ,column{std::move(md.column_family_name)} diff --git a/modules/console.cc b/modules/console.cc index 2a16cc5c4..d7fa9e0ae 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1945,7 +1945,7 @@ console_cmd__db__sstdump(opt &out, const string_view &line) buf, tokens(line, " ", buf) }; - db::sst_dump(args); + db::database::sst::dump(args); return true; } @@ -1986,7 +1986,7 @@ try << std::endl; const auto print{[&out] - (const db::database::fileinfo &f) + (const db::database::sst::info &f) { const uint64_t &min_key { @@ -2018,7 +2018,7 @@ try { const auto fileinfos { - db::database::fileinfo::vector(database) + db::database::sst::info::vector(database) }; for(const auto &fileinfo : fileinfos) @@ -2032,7 +2032,7 @@ try if(startswith(colname, "/")) { - print(db::database::fileinfo{database, colname}); + print(db::database::sst::info{database, colname}); return true; } @@ -2047,7 +2047,7 @@ try }; for(const auto &file : files) - print(db::database::fileinfo{database, file}); + print(db::database::sst::info{database, file}); return true; }