mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 16:34:13 +01:00
ircd::db: Employ c++1z extensions to namespacing.
This commit is contained in:
parent
3ef01bad59
commit
682686bcae
1 changed files with 77 additions and 89 deletions
166
ircd/db.cc
166
ircd/db.cc
|
@ -33,68 +33,67 @@
|
||||||
#include <rocksdb/env.h>
|
#include <rocksdb/env.h>
|
||||||
#include <rocksdb/slice_transform.h>
|
#include <rocksdb/slice_transform.h>
|
||||||
|
|
||||||
namespace ircd {
|
#include <ircd/m.h>
|
||||||
namespace db {
|
|
||||||
|
|
||||||
// Dedicated logging facility for the database subsystem
|
namespace ircd::db
|
||||||
struct log::log log
|
|
||||||
{
|
{
|
||||||
"db", 'D' // Database subsystem takes SNOMASK +D
|
const auto BLOCKING = rocksdb::ReadTier::kReadAllTier;
|
||||||
|
const auto NON_BLOCKING = rocksdb::ReadTier::kBlockCacheTier;
|
||||||
|
const auto DEFAULT_READAHEAD = 4_MiB;
|
||||||
|
|
||||||
|
struct throw_on_error
|
||||||
|
{
|
||||||
|
throw_on_error(const rocksdb::Status & = rocksdb::Status::OK());
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *reflect(const pos &);
|
||||||
|
const std::string &reflect(const rocksdb::Tickers &);
|
||||||
|
const std::string &reflect(const rocksdb::Histograms &);
|
||||||
|
rocksdb::Slice slice(const string_view &);
|
||||||
|
string_view slice(const rocksdb::Slice &);
|
||||||
|
|
||||||
|
// Frequently used get options and set options are separate from the string/map system
|
||||||
|
rocksdb::WriteOptions make_opts(const sopts &);
|
||||||
|
rocksdb::ReadOptions make_opts(const gopts &, const bool &iterator = false);
|
||||||
|
bool optstr_find_and_remove(std::string &optstr, const std::string &what);
|
||||||
|
|
||||||
|
// Validation functors
|
||||||
|
bool valid(const rocksdb::Iterator &);
|
||||||
|
bool operator!(const rocksdb::Iterator &);
|
||||||
|
void valid_or_throw(const rocksdb::Iterator &);
|
||||||
|
bool valid_equal(const rocksdb::Iterator &, const string_view &);
|
||||||
|
void valid_equal_or_throw(const rocksdb::Iterator &, const string_view &);
|
||||||
|
|
||||||
|
// [GET] seek suite
|
||||||
|
template<class pos> bool seek(database::column &, const pos &, rocksdb::ReadOptions &, std::unique_ptr<rocksdb::Iterator> &it);
|
||||||
|
template<class pos> bool seek(database::column &, const pos &, const gopts &, std::unique_ptr<rocksdb::Iterator> &it);
|
||||||
|
std::unique_ptr<rocksdb::Iterator> seek(column &, const gopts &);
|
||||||
|
std::unique_ptr<rocksdb::Iterator> seek(column &, const string_view &key, const gopts &);
|
||||||
|
std::vector<row::value_type> seek(database &, const gopts &);
|
||||||
|
|
||||||
|
std::pair<string_view, string_view> operator*(const rocksdb::Iterator &);
|
||||||
|
|
||||||
|
// [SET] writebatch suite
|
||||||
|
void commit(database &, rocksdb::WriteBatch &, const rocksdb::WriteOptions &);
|
||||||
|
void commit(database &, rocksdb::WriteBatch &, const sopts &);
|
||||||
|
void append(rocksdb::WriteBatch &, column &, const column::delta &delta);
|
||||||
|
void append(rocksdb::WriteBatch &, const cell::delta &delta);
|
||||||
|
|
||||||
|
std::vector<std::string> column_names(const std::string &path, const rocksdb::DBOptions &);
|
||||||
|
std::vector<std::string> column_names(const std::string &path, const std::string &options);
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::log::log ircd::db::log
|
||||||
|
{
|
||||||
|
// Dedicated logging facility for the database subsystem
|
||||||
|
"db", 'D'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Functor to wrap calls made to the rocksdb API to check for errors.
|
std::map<ircd::string_view, ircd::db::database *>
|
||||||
struct throw_on_error
|
ircd::db::database::dbs
|
||||||
{
|
{};
|
||||||
throw_on_error(const rocksdb::Status & = rocksdb::Status::OK());
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *reflect(const pos &);
|
struct ircd::db::database::logs
|
||||||
const std::string &reflect(const rocksdb::Tickers &);
|
|
||||||
const std::string &reflect(const rocksdb::Histograms &);
|
|
||||||
rocksdb::Slice slice(const string_view &);
|
|
||||||
string_view slice(const rocksdb::Slice &);
|
|
||||||
|
|
||||||
// Frequently used get options and set options are separate from the string/map system
|
|
||||||
rocksdb::WriteOptions make_opts(const sopts &);
|
|
||||||
rocksdb::ReadOptions make_opts(const gopts &, const bool &iterator = false);
|
|
||||||
bool optstr_find_and_remove(std::string &optstr, const std::string &what);
|
|
||||||
|
|
||||||
const auto BLOCKING = rocksdb::ReadTier::kReadAllTier;
|
|
||||||
const auto NON_BLOCKING = rocksdb::ReadTier::kBlockCacheTier;
|
|
||||||
|
|
||||||
// This is important to prevent thrashing the iterators which have to reset on iops
|
|
||||||
const auto DEFAULT_READAHEAD = 4_MiB;
|
|
||||||
|
|
||||||
// Validation functors
|
|
||||||
bool valid(const rocksdb::Iterator &);
|
|
||||||
bool operator!(const rocksdb::Iterator &);
|
|
||||||
void valid_or_throw(const rocksdb::Iterator &);
|
|
||||||
bool valid_equal(const rocksdb::Iterator &, const string_view &);
|
|
||||||
void valid_equal_or_throw(const rocksdb::Iterator &, const string_view &);
|
|
||||||
|
|
||||||
// Direct re-seekers. Internal only.
|
|
||||||
void _seek_(rocksdb::Iterator &, const rocksdb::Slice &);
|
|
||||||
void _seek_(rocksdb::Iterator &, const string_view &);
|
|
||||||
void _seek_(rocksdb::Iterator &, const pos &);
|
|
||||||
|
|
||||||
// Move an iterator
|
|
||||||
template<class pos> bool seek(database::column &, const pos &, rocksdb::ReadOptions &, std::unique_ptr<rocksdb::Iterator> &it);
|
|
||||||
template<class pos> bool seek(database::column &, const pos &, const gopts &, std::unique_ptr<rocksdb::Iterator> &it);
|
|
||||||
|
|
||||||
// Query for an iterator. Returns a lower_bound on a key
|
|
||||||
std::unique_ptr<rocksdb::Iterator> seek(column &, const gopts &);
|
|
||||||
std::unique_ptr<rocksdb::Iterator> seek(column &, const string_view &key, const gopts &);
|
|
||||||
std::vector<row::value_type> seek(database &, const gopts &);
|
|
||||||
|
|
||||||
std::pair<string_view, string_view> operator*(const rocksdb::Iterator &);
|
|
||||||
|
|
||||||
void append(rocksdb::WriteBatch &, column &, const column::delta &delta);
|
|
||||||
void append(rocksdb::WriteBatch &, const cell::delta &delta);
|
|
||||||
|
|
||||||
std::vector<std::string> column_names(const std::string &path, const rocksdb::DBOptions &);
|
|
||||||
std::vector<std::string> column_names(const std::string &path, const std::string &options);
|
|
||||||
|
|
||||||
struct database::logs
|
|
||||||
:std::enable_shared_from_this<struct database::logs>
|
:std::enable_shared_from_this<struct database::logs>
|
||||||
,rocksdb::Logger
|
,rocksdb::Logger
|
||||||
{
|
{
|
||||||
|
@ -110,8 +109,8 @@ struct database::logs
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::stats
|
struct ircd::db::database::stats
|
||||||
:std::enable_shared_from_this<struct database::stats>
|
:std::enable_shared_from_this<struct ircd::db::database::stats>
|
||||||
,rocksdb::Statistics
|
,rocksdb::Statistics
|
||||||
{
|
{
|
||||||
database *d;
|
database *d;
|
||||||
|
@ -131,8 +130,8 @@ struct database::stats
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::events
|
struct ircd::db::database::events
|
||||||
:std::enable_shared_from_this<struct database::events>
|
:std::enable_shared_from_this<struct ircd::db::database::events>
|
||||||
,rocksdb::EventListener
|
,rocksdb::EventListener
|
||||||
{
|
{
|
||||||
database *d;
|
database *d;
|
||||||
|
@ -150,8 +149,8 @@ struct database::events
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::mergeop
|
struct ircd::db::database::mergeop
|
||||||
:std::enable_shared_from_this<struct database::mergeop>
|
:std::enable_shared_from_this<struct ircd::db::database::mergeop>
|
||||||
,rocksdb::AssociativeMergeOperator
|
,rocksdb::AssociativeMergeOperator
|
||||||
{
|
{
|
||||||
database *d;
|
database *d;
|
||||||
|
@ -166,7 +165,7 @@ struct database::mergeop
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::comparator
|
struct ircd::db::database::comparator
|
||||||
:rocksdb::Comparator
|
:rocksdb::Comparator
|
||||||
{
|
{
|
||||||
using Slice = rocksdb::Slice;
|
using Slice = rocksdb::Slice;
|
||||||
|
@ -186,7 +185,7 @@ struct database::comparator
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::prefix_transform
|
struct ircd::db::database::prefix_transform
|
||||||
:rocksdb::SliceTransform
|
:rocksdb::SliceTransform
|
||||||
{
|
{
|
||||||
using Slice = rocksdb::Slice;
|
using Slice = rocksdb::Slice;
|
||||||
|
@ -205,7 +204,7 @@ struct database::prefix_transform
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database::column
|
struct ircd::db::database::column
|
||||||
:std::enable_shared_from_this<database::column>
|
:std::enable_shared_from_this<database::column>
|
||||||
,rocksdb::ColumnFamilyDescriptor
|
,rocksdb::ColumnFamilyDescriptor
|
||||||
{
|
{
|
||||||
|
@ -235,26 +234,16 @@ struct database::column
|
||||||
~column() noexcept;
|
~column() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<string_view, database *>
|
|
||||||
database::dbs
|
|
||||||
{};
|
|
||||||
|
|
||||||
} // namespace db
|
|
||||||
} // namespace ircd
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// init
|
// init
|
||||||
//
|
//
|
||||||
|
|
||||||
namespace ircd {
|
namespace ircd::db
|
||||||
namespace db {
|
{
|
||||||
|
static void init_directory();
|
||||||
static void init_directory();
|
static void init_version();
|
||||||
static void init_version();
|
}
|
||||||
|
|
||||||
} // namespace db
|
|
||||||
} // namespace ircd
|
|
||||||
|
|
||||||
static char ircd_db_version[64];
|
static char ircd_db_version[64];
|
||||||
const char *const ircd::db::version(ircd_db_version);
|
const char *const ircd::db::version(ircd_db_version);
|
||||||
|
@ -720,10 +709,13 @@ const
|
||||||
const string_view limit{_limit.data(), _limit.size()};
|
const string_view limit{_limit.data(), _limit.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ircd {
|
namespace ircd::db
|
||||||
namespace db {
|
{
|
||||||
|
struct cmp_string_view;
|
||||||
|
struct cmp_int64_t;
|
||||||
|
}
|
||||||
|
|
||||||
struct cmp_string_view
|
struct ircd::db::cmp_string_view
|
||||||
:db::comparator
|
:db::comparator
|
||||||
{
|
{
|
||||||
cmp_string_view()
|
cmp_string_view()
|
||||||
|
@ -741,7 +733,7 @@ struct cmp_string_view
|
||||||
}{}
|
}{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmp_int64_t
|
struct ircd::db::cmp_int64_t
|
||||||
:db::comparator
|
:db::comparator
|
||||||
{
|
{
|
||||||
cmp_int64_t()
|
cmp_int64_t()
|
||||||
|
@ -767,10 +759,6 @@ struct cmp_int64_t
|
||||||
}{}
|
}{}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace db
|
|
||||||
} // namespace ircd
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// database::prefix_transform
|
// database::prefix_transform
|
||||||
|
|
Loading…
Reference in a new issue