From cbfb105765d82f090b9b72dc7d8cd18eb20335ea Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 22 Mar 2018 19:35:50 -0700 Subject: [PATCH] ircd::db: Minor cleanup; interface const consistency on our side. --- include/ircd/db/column.h | 20 +++++++++---------- include/ircd/db/database/database.h | 9 +++++---- ircd/db.cc | 30 +++++++++++++++-------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/include/ircd/db/column.h b/include/ircd/db/column.h index 03e8720b9..592203b3c 100644 --- a/include/ircd/db/column.h +++ b/include/ircd/db/column.h @@ -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 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 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 & = {}); diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 542f7a17e..bf39d5179 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -15,11 +15,12 @@ namespace ircd::db { struct database; - template R property(database &, const string_view &name); - template<> uint64_t property(database &, const string_view &name); + template 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 diff --git a/ircd/db.cc b/ircd/db.cc index 56766615d..9da93df0f 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -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(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(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(column)); + database &d(const_cast(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(column)); + database &d(const_cast(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(column)); + database::column &c(const_cast(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(column)); + database::column &c(const_cast(column)); assert(bool(c.handle)); d.d->GetColumnFamilyMetaData(c.handle.get(), &cfm); return cfm.file_count;