mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 14:31:11 +01:00
ircd:Ⓜ️ Move multi-key fetch from vm:: to keys::; minor reorg.
This commit is contained in:
parent
8839f6d273
commit
b75f0ea1ef
5 changed files with 77 additions and 78 deletions
|
@ -55,6 +55,7 @@ struct ircd::m::keys
|
|||
{
|
||||
struct cache;
|
||||
|
||||
using pdus = vector_view<const event>;
|
||||
using queries = vector_view<const fed::key::server_key>; // <server, key_id>
|
||||
using closure = std::function<void (const json::object &)>;
|
||||
using closure_bool = std::function<bool (const json::object &)>;
|
||||
|
@ -64,6 +65,7 @@ struct ircd::m::keys
|
|||
static bool get(const string_view &server_name, const string_view &key_id, const closure &);
|
||||
static bool query(const string_view &query_server, const queries &, const closure_bool &);
|
||||
static size_t fetch(const queries &);
|
||||
static size_t fetch(const pdus &);
|
||||
|
||||
using super_type::tuple;
|
||||
using super_type::operator=;
|
||||
|
|
|
@ -15,15 +15,14 @@ namespace ircd::m::vm
|
|||
{
|
||||
struct eval;
|
||||
|
||||
string_view loghead(const mutable_buffer &, const eval &);
|
||||
string_view loghead(const eval &); // single tls buffer
|
||||
|
||||
const event *find_pdu(const eval &, const event::id &) noexcept;
|
||||
eval *find_parent(const eval &, const ctx::ctx & = ctx::cur()) noexcept;
|
||||
eval *find_root(const eval &, const ctx::ctx & = ctx::cur()) noexcept;
|
||||
|
||||
string_view loghead(const mutable_buffer &, const eval &);
|
||||
string_view loghead(const eval &); // single tls buffer
|
||||
|
||||
size_t prefetch_refs(const eval &);
|
||||
size_t fetch_keys(const eval &);
|
||||
}
|
||||
|
||||
/// Event Evaluation Device
|
||||
|
|
|
@ -284,6 +284,45 @@ ircd::m::keys_get_timeout
|
|||
{ "default", 20000L }
|
||||
};
|
||||
|
||||
size_t
|
||||
ircd::m::keys::fetch(const pdus &pdus)
|
||||
{
|
||||
using fed::key::server_key;
|
||||
|
||||
std::vector<server_key> q;
|
||||
for(const auto &event : pdus)
|
||||
for(const auto &[server_name, signatures] : json::get<"signatures"_>(event))
|
||||
for(const auto &[key_id, signature] : json::object(signatures))
|
||||
{
|
||||
const server_key query
|
||||
{
|
||||
json::get<"origin"_>(event), key_id
|
||||
};
|
||||
|
||||
// Check if we're already making a query.
|
||||
if(std::binary_search(begin(q), end(q), query))
|
||||
continue;
|
||||
|
||||
// Check if we already have the key.
|
||||
if(cache::has(json::get<"origin"_>(event), key_id))
|
||||
continue;
|
||||
|
||||
// If there's a cached error on the host we can skip here.
|
||||
if(fed::errant(json::get<"origin"_>(event)))
|
||||
continue;
|
||||
|
||||
q.emplace_back(query);
|
||||
std::sort(begin(q), end(q));
|
||||
}
|
||||
|
||||
const size_t fetched
|
||||
{
|
||||
fetch(queries(q))
|
||||
};
|
||||
|
||||
return fetched;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::keys::fetch(const queries &queries)
|
||||
{
|
||||
|
|
|
@ -37,47 +37,6 @@ ircd::m::vm::eval::executing;
|
|||
decltype(ircd::m::vm::eval::injecting)
|
||||
ircd::m::vm::eval::injecting;
|
||||
|
||||
size_t
|
||||
ircd::m::vm::fetch_keys(const eval &eval)
|
||||
{
|
||||
using m::fed::key::server_key;
|
||||
|
||||
std::vector<server_key> queries;
|
||||
for(const auto &event : eval.pdus)
|
||||
for(const auto &[server_name, signatures] : json::get<"signatures"_>(event))
|
||||
for(const auto &[key_id, signature] : json::object(signatures))
|
||||
{
|
||||
const server_key query
|
||||
{
|
||||
json::get<"origin"_>(event), key_id
|
||||
};
|
||||
|
||||
// Check if we're already making a query.
|
||||
if(std::binary_search(begin(queries), end(queries), query))
|
||||
continue;
|
||||
|
||||
// Check if we already have the key.
|
||||
if(m::keys::cache::has(json::get<"origin"_>(event), key_id))
|
||||
continue;
|
||||
|
||||
// If there's a cached error on the host we can skip here.
|
||||
if(m::fed::errant(json::get<"origin"_>(event)))
|
||||
continue;
|
||||
|
||||
queries.emplace_back(json::get<"origin"_>(event), key_id);
|
||||
std::sort(begin(queries), end(queries));
|
||||
}
|
||||
|
||||
const size_t fetched
|
||||
{
|
||||
!queries.empty()?
|
||||
m::keys::fetch(queries):
|
||||
0UL
|
||||
};
|
||||
|
||||
return fetched;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::vm::prefetch_refs(const eval &eval)
|
||||
{
|
||||
|
@ -99,38 +58,6 @@ ircd::m::vm::prefetch_refs(const eval &eval)
|
|||
return prefetched;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::vm::loghead(const eval &eval)
|
||||
{
|
||||
thread_local char buf[128];
|
||||
return loghead(buf, eval);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::vm::loghead(const mutable_buffer &buf,
|
||||
const eval &eval)
|
||||
{
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "vm:%lu:%lu:%lu parent:%lu %s eval:%lu %s seq:%lu %s",
|
||||
sequence::retired,
|
||||
sequence::committed,
|
||||
sequence::uncommitted,
|
||||
eval.parent?
|
||||
eval.parent->id:
|
||||
0UL,
|
||||
eval.parent?
|
||||
reflect(eval.parent->phase):
|
||||
reflect(phase::NONE),
|
||||
eval.id,
|
||||
reflect(eval.phase),
|
||||
sequence::get(eval),
|
||||
eval.event_?
|
||||
string_view{eval.event_->event_id}:
|
||||
"<unidentified>"_sv,
|
||||
};
|
||||
}
|
||||
|
||||
ircd::m::vm::eval *
|
||||
ircd::m::vm::find_root(const eval &a,
|
||||
const ctx::ctx &c)
|
||||
|
@ -185,6 +112,38 @@ noexcept
|
|||
return ret;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::vm::loghead(const eval &eval)
|
||||
{
|
||||
thread_local char buf[128];
|
||||
return loghead(buf, eval);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::vm::loghead(const mutable_buffer &buf,
|
||||
const eval &eval)
|
||||
{
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "vm:%lu:%lu:%lu parent:%lu %s eval:%lu %s seq:%lu %s",
|
||||
sequence::retired,
|
||||
sequence::committed,
|
||||
sequence::uncommitted,
|
||||
eval.parent?
|
||||
eval.parent->id:
|
||||
0UL,
|
||||
eval.parent?
|
||||
reflect(eval.parent->phase):
|
||||
reflect(phase::NONE),
|
||||
eval.id,
|
||||
reflect(eval.phase),
|
||||
sequence::get(eval),
|
||||
eval.event_?
|
||||
string_view{eval.event_->event_id}:
|
||||
"<unidentified>"_sv,
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// eval::eval
|
||||
//
|
||||
|
|
|
@ -218,7 +218,7 @@ ircd::m::vm::execute(eval &eval,
|
|||
const size_t prefetched_keys
|
||||
{
|
||||
prefetch_keys?
|
||||
fetch_keys(eval): 0UL
|
||||
keys::fetch(eval.pdus): 0UL
|
||||
};
|
||||
|
||||
const bool prefetch_refs
|
||||
|
|
Loading…
Reference in a new issue