From: Fred Morcos Date: Tue, 30 Jul 2024 12:08:35 +0000 (+0200) Subject: Some cleanups to lmdb-typed.hh X-Git-Tag: rec-5.2.0-alpha1~61^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ecd8ed2c35f40e9970b0d98680e3c656cfde619;p=thirdparty%2Fpdns.git Some cleanups to lmdb-typed.hh Mostly automated formatting and renames with some documentation formatting and rewording. --- diff --git a/ext/lmdb-safe/lmdb-typed.hh b/ext/lmdb-safe/lmdb-typed.hh index ae32d78fd6..18cafa2c1f 100644 --- a/ext/lmdb-safe/lmdb-typed.hh +++ b/ext/lmdb-safe/lmdb-typed.hh @@ -1,8 +1,10 @@ #pragma once + #include #include +#include #include -#include "lmdb-safe.hh" + #include #include #include @@ -11,39 +13,38 @@ #include #include #include -#include -// using std::cout; -// using std::endl; +#include "lmdb-safe.hh" /* - Open issues: - - Everything should go into a namespace - What is an error? What is an exception? - could id=0 be magic? ('no such id') - yes - Is boost the best serializer? - good default - Perhaps use the separate index concept from multi_index - perhaps get eiter to be of same type so for(auto& a : x) works - make it more value "like" with unique_ptr -*/ - - -/** Return the highest ID used in a database. Returns 0 for an empty DB. - This makes us start everything at ID=1, which might make it possible to - treat id 0 as special -*/ + * OPEN ISSUES: + * + * - Everything should go into a namespace. + * - Decide on what is an error and what is an exception. + * - Could id=0 be magic? (e.g. 'no such id') - yes. + * - Is boost the best serializer? It's a good default. + * - Perhaps use the separate index concept from multi_index. + * - Perhaps get eiter to be of same type so that for(auto& a : x) works. + * - Make it more value-like with unique_ptr. + */ + +/** + * LMDB ID Vector Type. + */ +typedef std::vector LmdbIdVec; + +/** + * Return the highest ID used in a database. Returns 0 for an empty DB. This makes us + * start everything at ID=1, which might make it possible to treat id 0 as special. + */ unsigned int MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi); -/** Return a randomly generated ID that is unique and not zero. - May throw if the database is very full. -*/ +/** + * Return a randomly generated ID that is unique and not zero. May throw if the database + * is very full. + */ unsigned int MDBGetRandomID(MDBRWTransaction& txn, MDBDbi& dbi); -typedef std::vector LMDBIDvec; - /** This is our serialization interface. You can define your own serToString for your type if you know better */ @@ -304,7 +305,7 @@ public: // auto range = (*d_parent.d_txn)->prefix_range(domain); // auto range = prefix_range(key); - LMDBIDvec ids; + LmdbIdVec ids; // because we know we only want one item, pass onlyOldest=true to consistently get the same one out of a set of duplicates get_multi(key, ids, true); @@ -643,7 +644,7 @@ public: }; template - void get_multi(const typename std::tuple_element::type::type& key, LMDBIDvec& ids, bool onlyOldest=false) + void get_multi(const typename std::tuple_element::type::type& key, LmdbIdVec& ids, bool onlyOldest=false) { // std::cerr<<"in get_multi"<getCursor(std::get(d_parent.d_parent->d_tuple).d_idx); diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 6bf827ccf3..8f9171eacc 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -1327,7 +1327,7 @@ bool LMDBBackend::deleteDomain(const DNSName& domain) abortTransaction(); - LMDBIDvec idvec; + LmdbIdVec idvec; if (!d_handle_dups) { // get domain id @@ -1352,7 +1352,7 @@ bool LMDBBackend::deleteDomain(const DNSName& domain) { // Remove metadata auto txn = d_tmeta->getRWTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(domain, ids); @@ -1365,7 +1365,7 @@ bool LMDBBackend::deleteDomain(const DNSName& domain) { // Remove cryptokeys auto txn = d_tkdb->getRWTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(domain, ids); for (auto _id : ids) { @@ -1909,7 +1909,7 @@ bool LMDBBackend::getAllDomainMetadata(const DNSName& name, std::mapgetROTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); DomainMeta dm; @@ -1926,7 +1926,7 @@ bool LMDBBackend::setDomainMetadata(const DNSName& name, const std::string& kind { auto txn = d_tmeta->getRWTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); DomainMeta dmeta; @@ -1950,7 +1950,7 @@ bool LMDBBackend::setDomainMetadata(const DNSName& name, const std::string& kind bool LMDBBackend::getDomainKeys(const DNSName& name, std::vector& keys) { auto txn = d_tkdb->getROTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); KeyDataDB key; @@ -2567,7 +2567,7 @@ bool LMDBBackend::updateEmptyNonTerminals(uint32_t domain_id, set& inse bool LMDBBackend::getTSIGKey(const DNSName& name, DNSName& algorithm, string& content) { auto txn = d_ttsig->getROTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); TSIGKey key; @@ -2588,7 +2588,7 @@ bool LMDBBackend::setTSIGKey(const DNSName& name, const DNSName& algorithm, cons { auto txn = d_ttsig->getRWTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); TSIGKey key; @@ -2614,7 +2614,7 @@ bool LMDBBackend::deleteTSIGKey(const DNSName& name) { auto txn = d_ttsig->getRWTransaction(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(name, ids); TSIGKey key; @@ -2698,7 +2698,7 @@ string LMDBBackend::directBackendCmd(const string& query) auto id = iter.getID(); - LMDBIDvec ids; + LmdbIdVec ids; txn.get_multi<0>(di.zone, ids); if (ids.size() != 1) {