0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 20:28:52 +02:00

ircd::db: Add a fileinfo wrapping interface.

This commit is contained in:
Jason Volk 2018-09-20 15:57:15 -07:00
parent f80aaa7904
commit 7676bd0944
5 changed files with 108 additions and 0 deletions

View file

@ -79,6 +79,7 @@ struct ircd::db::database
struct column; struct column;
struct env; struct env;
struct cache; struct cache;
struct fileinfo;
std::string name; std::string name;
uint64_t checkpoint; uint64_t checkpoint;

View file

@ -0,0 +1,43 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// 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<fileinfo>
{
vector() = default;
explicit vector(const database &);
};

View file

@ -33,6 +33,7 @@ namespace rocksdb
struct SstFileManager; struct SstFileManager;
struct PerfContext; struct PerfContext;
struct IOStatsContext; struct IOStatsContext;
struct LiveFileMetaData;
} }
// //

View file

@ -69,6 +69,7 @@ enum class ircd::db::pos
#include "database/database.h" #include "database/database.h"
#include "database/options.h" #include "database/options.h"
#include "database/snapshot.h" #include "database/snapshot.h"
#include "database/fileinfo.h"
#include "cache.h" #include "cache.h"
#include "opts.h" #include "opts.h"
#include "column.h" #include "column.h"

View file

@ -2483,6 +2483,68 @@ const noexcept
return db::name(*c).c_str(); return db::name(*c).c_str();
} }
///////////////////////////////////////////////////////////////////////////////
//
// database::fileinfo
//
//
// fileinfo::vector
//
ircd::db::database::fileinfo::vector::vector(const database &d)
{
std::vector<rocksdb::LiveFileMetaData> 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<rocksdb::LiveFileMetaData> 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 // database::env