From 916597595313ecc4a3e0003fbf0f65dd472a28d0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 16 Sep 2020 23:31:19 -0700 Subject: [PATCH] ircd::m::dbs: Supersede index query tool with parallel impl. --- include/ircd/m/dbs/dbs.h | 12 ++++++++++++ matrix/dbs.cc | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/include/ircd/m/dbs/dbs.h b/include/ircd/m/dbs/dbs.h index 5d686bbff..400b1f513 100644 --- a/include/ircd/m/dbs/dbs.h +++ b/include/ircd/m/dbs/dbs.h @@ -201,5 +201,17 @@ struct ircd::m::dbs::init // Internal utils (here for now) namespace ircd::m::dbs { + size_t find_event_idx(const vector_view &out, const vector_view &in, const write_opts &); event::idx find_event_idx(const event::id &, const write_opts &); } + +inline ircd::m::event::idx +ircd::m::dbs::find_event_idx(const event::id &event_id, + const write_opts &wopts) +{ + event::idx ret{0}; + const vector_view out(&ret, 1); + const vector_view in(&event_id, 1); + find_event_idx(out, in, wopts); + return ret; +} diff --git a/matrix/dbs.cc b/matrix/dbs.cc index 7ba91e55c..ac8d330ab 100644 --- a/matrix/dbs.cc +++ b/matrix/dbs.cc @@ -390,16 +390,39 @@ ircd::m::dbs::_index_room_redact(db::txn &txn, } // NOTE: QUERY -ircd::m::event::idx -ircd::m::dbs::find_event_idx(const event::id &event_id, +size_t +ircd::m::dbs::find_event_idx(const vector_view &idx, + const vector_view &event_id, const write_opts &wopts) { - event::idx ret{0}; - if(wopts.interpose) - ret = wopts.interpose->val(db::op::SET, "_event_idx", event_id, 0UL); + const size_t num + { + std::min(idx.size(), event_id.size()) + }; - if(wopts.allow_queries && !ret) - ret = m::index(std::nothrow, event_id); // query + size_t ret(0); + if(wopts.interpose) + for(size_t i(0); i < num; ++i) + { + idx[i] = wopts.interpose->val(db::op::SET, "_event_idx", event_id[i], 0UL); + ret += idx[i] != 0; + } + + // Taken when everything satisfied by interpose + if(ret == num || !wopts.allow_queries) + return ret; + + // Only do parallel m::index() if there's no results from the prior + // queries; they'll get clobbered by the parallel m::index(). + if(likely(!ret)) + return m::index(idx, event_id); + + // Fallback to serial queries. + for(size_t i(0); i < num; ++i) + { + idx[i] = m::index(std::nothrow, event_id[i]); + ret += idx[i] != 0; + } return ret; }