From a451e81e890c91833d8f0c66488f488647ed51b6 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Thu, 6 Jul 2023 12:28:22 +0200 Subject: [PATCH] auth lmdb: add index refresh-all backend command --- modules/lmdbbackend/lmdbbackend.cc | 64 +++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 506cd4783d..d9b94763ed 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -2625,7 +2625,7 @@ string LMDBBackend::directBackendCmd(const string& query) usage << "info show some information about the database" << endl; usage << "index check domains check zone<>ID indexes" << endl; usage << "index refresh domains refresh index for zone with this ID" << endl; - + usage << "index refresh-all domains refresh index for all zones with disconnected indexes" << endl; vector argv; stringtok(argv, query); @@ -2653,7 +2653,13 @@ string LMDBBackend::directBackendCmd(const string& query) string& subcmd = argv[1]; - if (subcmd == "check") { + if (subcmd == "check" || subcmd == "refresh-all") { + bool refresh = false; + + if (subcmd == "refresh-all") { + refresh = true; + } + if (argv.size() < 3) { return "need an index name\n"; } @@ -2662,30 +2668,50 @@ string LMDBBackend::directBackendCmd(const string& query) return "can only check the domains index\n"; } - auto txn = d_tdomains->getROTransaction(); + vector refreshQueue; + + { + auto txn = d_tdomains->getROTransaction(); + + for (auto iter = txn.begin(); iter != txn.end(); ++iter) { + DomainInfo di = *iter; - for (auto iter = txn.begin(); iter != txn.end(); ++iter) { - DomainInfo di = *iter; + auto id = iter.getID(); - auto id = iter.getID(); + LMDBIDvec ids; + txn.get_multi<0>(di.zone, ids); - LMDBIDvec ids; - txn.get_multi<0>(di.zone, ids); + if (ids.size() != 1) { + ret << "ID->zone index has " << id << "->" << di.zone << ", "; - if (ids.size() != 1) { - ret << "ID->zone index has " << id << "->" << di.zone << ", "; + if (ids.empty()) { + ret << "zone->ID index has no entry for " << di.zone << endl; + if (refresh) { + refreshQueue.push_back(id); + } + else { + ret << " suggested remedy: index refresh domains " << id << endl; + } + } + else { + // ids.size() > 1 + ret << "zone->ID index has multiple entries for " << di.zone << ": "; + for (auto id_ : ids) { + ret << id_ << " "; + } + ret << endl; + } + } + } + } - if (ids.empty()) { - ret << "zone->ID index has no entry for " << di.zone << endl; - ret << " suggested remedy: index refresh domains " << id << endl; + if (refresh) { + for (const auto& id : refreshQueue) { + if (genChangeDomain(id, [](DomainInfo& /* di */) {})) { + ret << "refreshed " << id << endl; } else { - // ids.size() > 1 - ret << "zone->ID index has multiple entries for " << di.zone << ": "; - for (auto id_ : ids) { - ret << id_ << " "; - } - ret << endl; + ret << "failed to refresh " << id << endl; } } } -- 2.47.2