From 7676bd0944c51a7bf2915e58180bb7cbc559dcfb Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 20 Sep 2018 15:57:15 -0700 Subject: [PATCH] ircd::db: Add a fileinfo wrapping interface. --- include/ircd/db/database/database.h | 1 + include/ircd/db/database/fileinfo.h | 43 ++++++++++++++++++++ include/ircd/db/database/rocksdb.h | 1 + include/ircd/db/db.h | 1 + ircd/db.cc | 62 +++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 include/ircd/db/database/fileinfo.h diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 74e7cb52c..b0859ec5e 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -79,6 +79,7 @@ struct ircd::db::database struct column; struct env; struct cache; + struct fileinfo; std::string name; uint64_t checkpoint; diff --git a/include/ircd/db/database/fileinfo.h b/include/ircd/db/database/fileinfo.h new file mode 100644 index 000000000..5ce12a74d --- /dev/null +++ b/include/ircd/db/database/fileinfo.h @@ -0,0 +1,43 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_DB_DATABASE_FILEINFO_H + +/// 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 +{ + struct vector; + + std::string name; + std::string path; + std::string column; + size_t size {0}; + uint64_t min_seq {0}; + uint64_t max_seq {0}; + std::string min_key; + std::string max_key; + uint64_t num_reads {0}; + int level {-1}; + bool compacting {false}; + + fileinfo() = default; + fileinfo(rocksdb::LiveFileMetaData &&); + fileinfo(const database &, const string_view &filename); +}; + +struct ircd::db::database::fileinfo::vector +:std::vector +{ + vector() = default; + explicit vector(const database &); +}; diff --git a/include/ircd/db/database/rocksdb.h b/include/ircd/db/database/rocksdb.h index 6f7a68dde..668b166c1 100644 --- a/include/ircd/db/database/rocksdb.h +++ b/include/ircd/db/database/rocksdb.h @@ -33,6 +33,7 @@ namespace rocksdb struct SstFileManager; struct PerfContext; struct IOStatsContext; + struct LiveFileMetaData; } // diff --git a/include/ircd/db/db.h b/include/ircd/db/db.h index 38170e9c2..5bdffc4a5 100644 --- a/include/ircd/db/db.h +++ b/include/ircd/db/db.h @@ -69,6 +69,7 @@ enum class ircd::db::pos #include "database/database.h" #include "database/options.h" #include "database/snapshot.h" +#include "database/fileinfo.h" #include "cache.h" #include "opts.h" #include "column.h" diff --git a/ircd/db.cc b/ircd/db.cc index fc29d328b..e58733401 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -2483,6 +2483,68 @@ const noexcept return db::name(*c).c_str(); } +/////////////////////////////////////////////////////////////////////////////// +// +// database::fileinfo +// + +// +// fileinfo::vector +// + +ircd::db::database::fileinfo::vector::vector(const database &d) +{ + std::vector v; + d.d->GetLiveFilesMetaData(&v); + + this->resize(v.size()); + std::transform(v.begin(), v.end(), this->begin(), [] + (auto &&info) + { + return std::move(info); + }); +} + +// +// fileinfo::fileinfo +// + +ircd::db::database::fileinfo::fileinfo(const database &d, + const string_view &filename) +{ + std::vector v; + d.d->GetLiveFilesMetaData(&v); + + for(auto &md : v) + if(md.name == filename) + { + new (this) fileinfo(std::move(md)); + return; + } + + throw not_found + { + "No file named '%s' is live in database '%s'", + filename, + d.name + }; +} + +ircd::db::database::fileinfo::fileinfo(rocksdb::LiveFileMetaData &&md) +:name{std::move(md.name)} +,path{std::move(md.db_path)} +,column{std::move(md.column_family_name)} +,size{md.size} +,min_seq{md.smallest_seqno} +,max_seq{md.largest_seqno} +,min_key{std::move(md.smallestkey)} +,max_key{std::move(md.largestkey)} +,num_reads{md.num_reads_sampled} +,level{md.level} +,compacting{md.being_compacted} +{ +} + /////////////////////////////////////////////////////////////////////////////// // // database::env