0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

modules/vm_fetch: Checkpoint cruft removal.

This commit is contained in:
Jason Volk 2018-10-01 13:59:17 -07:00
parent 450ec3523e
commit 88dfc8841d
4 changed files with 12 additions and 107 deletions

View file

@ -4574,41 +4574,21 @@ console_cmd__event__fetch(opt &out, const string_view &line)
m::room_id(param.at("room_id"))
};
const unique_buffer<mutable_buffer> buf
const net::hostport hostport
{
64_KiB
room_id.host()
};
using prototype = json::object (const m::room::id &,
const m::event::id &,
const mutable_buffer &);
const net::hostport &);
static mods::import<prototype> acquire
{
"vm_fetch", "acquire"
"vm_fetch", "state_fetch"
};
const m::event event
{
acquire(room_id, event_id, buf)
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
vmopts.prev_check_exists = false;
vmopts.head_must_exist = false;
vmopts.history = false;
vmopts.notify = false;
vmopts.verify = false;
m::vm::eval eval
{
vmopts
};
eval(event);
out << event << std::endl;
acquire(room_id, event_id, hostport);
return true;
}

View file

@ -10,7 +10,6 @@
namespace ircd::m::vm
{
extern hook::site<eval &> commit_hook; ///< Called when this server issues event
extern hook::site<eval &> fetch_hook; ///< Called to resolve dependencies
extern hook::site<eval &> eval_hook; ///< Called when evaluating event

View file

@ -130,77 +130,9 @@ m::vm::fetch::enter(const event &event,
// API interface
//
json::object
m::vm::fetch::acquire(const m::room::id &room_id,
const m::event::id &event_id,
const mutable_buffer &buf)
{
auto &request
{
_fetch(room_id, event_id)
};
request.dock.wait([&request]
{
return request.finished;
});
const unwind _remove_{[&event_id]
{
remove(event_id);
}};
if(request.eptr)
std::rethrow_exception(request.eptr);
const json::object &event
{
request
};
return json::object
{
data(buf), copy(buf, event)
};
}
bool
m::vm::fetch::prefetch(const m::room::id &room_id,
const m::event::id &event_id)
{
_fetch(room_id, event_id);
return true;
}
bool
ircd::m::vm::fetch::remove(const m::event::id &event_id)
{
const auto it
{
fetching.find(event_id)
};
if(it == end(fetching))
return false;
const request &r{*it};
if(!r.dock.empty())
return false;
for(auto it(begin(fetched)); it != end(fetched); ++it)
if(*it == &r)
{
fetched.erase(it);
break;
}
fetching.erase(it);
return true;
}
m::vm::fetch::request &
m::vm::fetch::_fetch(const m::room::id &room_id,
const m::event::id &event_id)
m::vm::fetch::fetch(const m::room::id &room_id,
const m::event::id &event_id)
{
auto it
{
@ -232,9 +164,6 @@ m::vm::fetch::dock;
decltype(m::vm::fetch::fetching)
m::vm::fetch::fetching;
decltype(m::vm::fetch::fetched)
m::vm::fetch::fetched;
/// The fetch context is an internal worker which drives the fetch process
/// and then indicates completion to anybody waiting on a fetch. This involves
/// handling errors/timeouts from a fetch attempt and retrying with another
@ -381,6 +310,10 @@ ircd::m::vm::fetch::request::select_random_origin()
const auto proffer{[this]
(const string_view &origin)
{
// Don't want to request from myself.
if(my_host(origin))
return false;
// Don't want to use a peer we already tried and failed with.
if(attempted.count(origin))
return false;
@ -456,7 +389,6 @@ void
ircd::m::vm::fetch::request::finish()
{
finished = ircd::time();
fetched.emplace_back(this);
dock.notify_all();
}

View file

@ -26,7 +26,6 @@ namespace ircd::m::vm::fetch
extern ctx::dock dock;
extern std::set<request, request> fetching;
extern std::deque<request *> fetched;
extern hookfn<eval &> hook;
extern ctx::context context;
@ -35,13 +34,8 @@ namespace ircd::m::vm::fetch
static bool handle();
static void worker();
// interface stack
static request &_fetch(const m::room::id &, const m::event::id &);
static bool remove(const m::event::id &);
extern "C" bool prefetch(const m::room::id &, const m::event::id &);
extern "C" json::object acquire(const m::room::id &, const m::event::id &, const mutable_buffer &);
static request &fetch(const m::room::id &, const m::event::id &);
// phase stack
static void enter(const event &, vm::eval &);
}