From ac03c9a13bc934f55076e27a5c45aae09b50d1f3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 19 Aug 2019 21:17:42 -0700 Subject: [PATCH] ircd: Use bool return values through prefetching stack. --- include/ircd/db/column.h | 2 +- include/ircd/m/event/prefetch.h | 8 ++++---- ircd/db.cc | 9 ++++++--- ircd/m_event.cc | 34 +++++++++++++++++++++++---------- ircd/m_room.cc | 3 +-- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/include/ircd/db/column.h b/include/ircd/db/column.h index 5dd203238..08e5edf22 100644 --- a/include/ircd/db/column.h +++ b/include/ircd/db/column.h @@ -42,7 +42,7 @@ namespace ircd::db // [GET] Tests if key exists bool has(column &, const string_view &key, const gopts & = {}); bool cached(column &, const string_view &key, const gopts & = {}); - void prefetch(column &, const string_view &key, const gopts & = {}); + bool prefetch(column &, const string_view &key, const gopts & = {}); // [GET] Query space usage size_t bytes(column &, const std::pair &range, const gopts & = {}); diff --git a/include/ircd/m/event/prefetch.h b/include/ircd/m/event/prefetch.h index 238ae21ee..b4ac4b244 100644 --- a/include/ircd/m/event/prefetch.h +++ b/include/ircd/m/event/prefetch.h @@ -13,9 +13,9 @@ namespace ircd::m { - void prefetch(const event::idx &, const event::fetch::opts & = event::fetch::default_opts); - void prefetch(const event::idx &, const string_view &key); + bool prefetch(const event::idx &, const event::fetch::opts & = event::fetch::default_opts); + bool prefetch(const event::idx &, const string_view &key); - void prefetch(const event::id &, const event::fetch::opts & = event::fetch::default_opts); - void prefetch(const event::id &, const string_view &key); + bool prefetch(const event::id &, const event::fetch::opts & = event::fetch::default_opts); + bool prefetch(const event::id &, const string_view &key); } diff --git a/ircd/db.cc b/ircd/db.cc index a54bba1f1..4f38f6363 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -5784,22 +5784,25 @@ ircd::db::bytes(column &column, return ret[0]; } -void +bool ircd::db::prefetch(column &column, const string_view &key, const gopts &gopts) { if(cached(column, key, gopts)) - return; + return false; if(!request.avail()) - return; + return false; request([column(column), key(std::string(key)), gopts] () mutable { has(column, key, gopts); }); + + ctx::yield(); + return true; } #if 0 diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 2b5972bb0..1472bab91 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -789,32 +789,46 @@ const // event/prefetch.h // -void +bool ircd::m::prefetch(const event::id &event_id, const event::fetch::opts &opts) { - prefetch(index(event_id), opts); + return prefetch(index(event_id), opts); } -void +bool ircd::m::prefetch(const event::id &event_id, const string_view &key) { - prefetch(index(event_id), key); + return prefetch(index(event_id), key); } -void +bool ircd::m::prefetch(const event::idx &event_idx, const event::fetch::opts &opts) { - const event::keys keys{opts.keys}; - const vector_view cols{keys}; + if(event::fetch::should_seek_json(opts)) + return db::prefetch(dbs::event_json, byte_view{event_idx}); + + const event::keys keys + { + opts.keys + }; + + const vector_view cols + { + keys + }; + + bool ret{false}; for(const auto &col : cols) if(col) - prefetch(event_idx, col); + ret |= prefetch(event_idx, col); + + return ret; } -void +bool ircd::m::prefetch(const event::idx &event_idx, const string_view &key) { @@ -828,7 +842,7 @@ ircd::m::prefetch(const event::idx &event_idx, dbs::event_column.at(column_idx) }; - db::prefetch(column, byte_view{event_idx}); + return db::prefetch(column, byte_view{event_idx}); } /////////////////////////////////////////////////////////////////////////////// diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 2ffe88049..327232131 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -192,8 +192,7 @@ ircd::m::room::state::prefetch(const state &state, if(range.second && event_idx > range.second) return; - m::prefetch(event_idx, fopts); - ++ret; + ret += m::prefetch(event_idx, fopts); }}); return ret;