0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::db: Minor cleanup; interface const consistency on our side.

This commit is contained in:
Jason Volk 2018-03-22 19:35:50 -07:00
parent faefd5dd64
commit cbfb105765
3 changed files with 31 additions and 28 deletions

View file

@ -15,18 +15,18 @@ namespace ircd::db
{
struct column;
// Information about a column
uint32_t id(const column &);
const std::string &name(const column &);
const database::descriptor &describe(const column &);
size_t file_count(const column &);
size_t bytes(const column &);
// Get property data of a db column. R can optionally be uint64_t for some
// values. Refer to RocksDB documentation for more info.
template<class R = std::string> R property(column &, const string_view &name);
template<> std::string property(column &, const string_view &name);
template<> uint64_t property(column &, const string_view &name);
// Information about a column
const database::descriptor &describe(const column &);
const std::string &name(const column &);
uint32_t id(const column &);
size_t file_count(column &);
size_t bytes(column &);
template<class R = std::string> R property(const column &, const string_view &name);
template<> std::string property(const column &, const string_view &name);
template<> uint64_t property(const column &, const string_view &name);
// [GET] Tests if key exists
bool has(column &, const string_view &key, const gopts & = {});

View file

@ -15,11 +15,12 @@ namespace ircd::db
{
struct database;
template<class R = uint64_t> R property(database &, const string_view &name);
template<> uint64_t property(database &, const string_view &name);
template<class R = uint64_t> R property(const database &, const string_view &name);
template<> uint64_t property(const database &, const string_view &name);
const std::string &name(const database &);
uint64_t sequence(const database &); // Latest sequence number
void sync(database &); // Sync the write log (all columns)
uint64_t sequence(const database &); // Latest sequence number
void sync(database &);
}
/// Database instance

View file

@ -123,17 +123,19 @@ ircd::db::sync(database &d)
}
uint64_t
ircd::db::sequence(const database &d)
ircd::db::sequence(const database &cd)
{
database &d(const_cast<database &>(cd));
return d.d->GetLatestSequenceNumber();
}
template<>
uint64_t
ircd::db::property(database &d,
ircd::db::property(const database &cd,
const string_view &name)
{
uint64_t ret;
database &d(const_cast<database &>(cd));
if(!d.d->GetAggregatedIntProperty(slice(name), &ret))
ret = 0;
@ -3468,24 +3470,24 @@ ircd::db::read(column &column,
template<>
std::string
ircd::db::property(column &column,
ircd::db::property(const column &column,
const string_view &name)
{
std::string ret;
database &d(column);
database::column &c(column);
database::column &c(const_cast<db::column &>(column));
database &d(const_cast<db::column &>(column));
d.d->GetProperty(c, slice(name), &ret);
return ret;
}
template<>
uint64_t
ircd::db::property(column &column,
ircd::db::property(const column &column,
const string_view &name)
{
uint64_t ret;
database &d(column);
database::column &c(column);
database::column &c(const_cast<db::column &>(column));
database &d(const_cast<db::column &>(column));
if(!d.d->GetIntProperty(c, slice(name), &ret))
ret = 0;
@ -3493,22 +3495,22 @@ ircd::db::property(column &column,
}
size_t
ircd::db::bytes(column &column)
ircd::db::bytes(const column &column)
{
rocksdb::ColumnFamilyMetaData cfm;
database::column &c(column);
database &d(c);
database &d(const_cast<db::column &>(column));
database::column &c(const_cast<db::column &>(column));
assert(bool(c.handle));
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
return cfm.size;
}
size_t
ircd::db::file_count(column &column)
ircd::db::file_count(const column &column)
{
rocksdb::ColumnFamilyMetaData cfm;
database::column &c(column);
database &d(c);
database &d(const_cast<db::column &>(column));
database::column &c(const_cast<db::column &>(column));
assert(bool(c.handle));
d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm);
return cfm.file_count;