mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd::db: Add a fileinfo wrapping interface.
This commit is contained in:
parent
f80aaa7904
commit
7676bd0944
5 changed files with 108 additions and 0 deletions
|
@ -79,6 +79,7 @@ struct ircd::db::database
|
|||
struct column;
|
||||
struct env;
|
||||
struct cache;
|
||||
struct fileinfo;
|
||||
|
||||
std::string name;
|
||||
uint64_t checkpoint;
|
||||
|
|
43
include/ircd/db/database/fileinfo.h
Normal file
43
include/ircd/db/database/fileinfo.h
Normal 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 &);
|
||||
};
|
|
@ -33,6 +33,7 @@ namespace rocksdb
|
|||
struct SstFileManager;
|
||||
struct PerfContext;
|
||||
struct IOStatsContext;
|
||||
struct LiveFileMetaData;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -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"
|
||||
|
|
62
ircd/db.cc
62
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<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
|
||||
|
|
Loading…
Reference in a new issue