0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-02-27 06:00:16 +01:00

ircd:Ⓜ️:vm: Remove the vm::phase; create fetch_hook.

This commit is contained in:
Jason Volk 2018-09-06 01:21:37 -07:00
parent 3b7f2f3fd3
commit d97a5ac571
6 changed files with 21 additions and 90 deletions

View file

@ -19,7 +19,6 @@ namespace ircd::m::vm
struct opts; struct opts;
struct copts; struct copts;
struct eval; struct eval;
struct phase;
struct accepted; struct accepted;
enum fault :uint; enum fault :uint;
using fault_t = std::underlying_type<fault>::type; using fault_t = std::underlying_type<fault>::type;
@ -58,7 +57,6 @@ struct ircd::m::vm::eval
string_view room_id; string_view room_id;
const json::iov *issue {nullptr}; const json::iov *issue {nullptr};
const event *event_ {nullptr}; const event *event_ {nullptr};
vm::phase *phase {nullptr};
uint64_t sequence {0}; uint64_t sequence {0};
db::txn *txn {nullptr}; db::txn *txn {nullptr};
event::id::buf event_id; event::id::buf event_id;
@ -248,17 +246,6 @@ struct ircd::m::vm::copts
bool infolog_postcommit {false}; bool infolog_postcommit {false};
}; };
struct ircd::m::vm::phase
:instance_list<phase>
{
string_view name;
std::function<void (eval &)> function;
void operator()(eval &);
phase(const string_view &name, decltype(function) = nullptr);
};
struct ircd::m::vm::accepted struct ircd::m::vm::accepted
:m::event :m::event
{ {

View file

@ -696,37 +696,6 @@ catch(...)
throw; throw;
} }
//
// vm::phase
//
/// Instance list linkage for all of the vm phases
template<>
decltype(ircd::util::instance_list<ircd::m::vm::phase>::list)
ircd::util::instance_list<ircd::m::vm::phase>::list
{};
ircd::m::vm::phase::phase(const string_view &name,
decltype(function) function)
:name{name}
,function{std::move(function)}
{
}
void
ircd::m::vm::phase::operator()(eval &eval)
{
auto theirs(eval.phase);
eval.phase = this;
const unwind _{[&eval, &theirs]
{
eval.phase = theirs;
}};
if(likely(function))
function(eval);
}
// //
// accepted // accepted
// //

View file

@ -8162,7 +8162,6 @@ console_cmd__vm__eval(opt &out, const string_view &line)
out << std::setw(9) << std::right << eval->id out << std::setw(9) << std::right << eval->id
<< " | " << std::setw(4) << std::right << id(*eval->ctx) << " | " << std::setw(4) << std::right << id(*eval->ctx)
<< " | " << std::setw(4) << std::right << eval->sequence << " | " << std::setw(4) << std::right << eval->sequence
<< " | " << std::setw(16) << std::left << (eval->phase? eval->phase->name : "")
<< " | " << std::setw(64) << std::left << eval->event_id << " | " << std::setw(64) << std::left << eval->event_id
; ;

View file

@ -11,10 +11,9 @@
namespace ircd::m::vm namespace ircd::m::vm
{ {
extern hook::site<> commit_hook; extern hook::site<> commit_hook;
extern hook::site<eval &> fetch_hook;
extern hook::site<> eval_hook; extern hook::site<> eval_hook;
extern hook::site<> notify_hook; extern hook::site<> notify_hook;
extern phase enter;
extern phase leave;
static void write_commit(eval &); static void write_commit(eval &);
static fault _eval_edu(eval &, const event &); static fault _eval_edu(eval &, const event &);
@ -41,6 +40,12 @@ ircd::m::vm::commit_hook
{ "name", "vm.commit" } { "name", "vm.commit" }
}; };
decltype(ircd::m::vm::fetch_hook)
ircd::m::vm::fetch_hook
{
{ "name", "vm.fetch" }
};
decltype(ircd::m::vm::eval_hook) decltype(ircd::m::vm::eval_hook)
ircd::m::vm::eval_hook ircd::m::vm::eval_hook
{ {
@ -120,10 +125,8 @@ ircd::m::vm::eval__commit_room(eval &eval,
// eval is attempting to do. // eval is attempting to do.
eval.issue = &event; eval.issue = &event;
eval.room_id = room.room_id; eval.room_id = room.room_id;
eval.phase = &vm::enter;
const unwind deissue{[&eval] const unwind deissue{[&eval]
{ {
eval.phase = &vm::leave;
eval.room_id = {}; eval.room_id = {};
eval.issue = nullptr; eval.issue = nullptr;
}}; }};
@ -263,20 +266,14 @@ ircd::m::vm::eval__commit(eval &eval,
// eval is attempting to do. // eval is attempting to do.
assert(!eval.room_id || eval.issue == &event); assert(!eval.room_id || eval.issue == &event);
if(!eval.room_id) if(!eval.room_id)
{
eval.issue = &event; eval.issue = &event;
eval.phase = &enter;
}
const unwind deissue{[&eval] const unwind deissue{[&eval]
{ {
// issue is untouched when room_id is set; that indicates it was set // issue is untouched when room_id is set; that indicates it was set
// and will be unset by another eval function (i.e above). // and will be unset by another eval function (i.e above).
if(!eval.room_id) if(!eval.room_id)
{
eval.phase = &leave;
eval.issue = nullptr; eval.issue = nullptr;
}
}}; }};
assert(eval.issue); assert(eval.issue);
@ -410,14 +407,8 @@ try
// allows other parallel evals to have deep access to exactly what this // allows other parallel evals to have deep access to exactly what this
// eval is working on. The pointer must be nulled on the way out. // eval is working on. The pointer must be nulled on the way out.
eval.event_ = &event; eval.event_ = &event;
if(!eval.issue)
eval.phase = &enter;
const unwind null_event{[&eval] const unwind null_event{[&eval]
{ {
if(!eval.issue)
eval.phase = &leave;
eval.event_ = nullptr; eval.event_ = nullptr;
}}; }};
@ -655,7 +646,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
// Obtain sequence number here // Obtain sequence number here
eval.sequence = ++vm::current_sequence; eval.sequence = ++vm::current_sequence;
eval_hook(event); // Fetch dependencies
fetch_hook(event, eval);
int64_t top; int64_t top;
id::event::buf head; id::event::buf head;
@ -672,7 +664,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
"vm_fetch", "phase" "vm_fetch", "phase"
}; };
fetch(eval); // Evaluation by module hooks
eval_hook(event);
if(!opts.write) if(!opts.write)
return fault::ACCEPT; return fault::ACCEPT;
@ -777,23 +770,3 @@ ircd::m::vm::retired_sequence(event::id::buf &event_id)
event_id = it->second; event_id = it->second;
return ret; return ret;
} }
//
// phase enter
//
decltype(ircd::m::vm::enter)
ircd::m::vm::enter
{
"enter"
};
//
// phase leave
//
decltype(ircd::m::vm::leave)
ircd::m::vm::leave
{
"leave"
};

View file

@ -54,16 +54,19 @@ _fini()
// fetch_phase // fetch_phase
// //
decltype(m::vm::fetch::phase) decltype(m::vm::fetch::hook)
m::vm::fetch::phase m::vm::fetch::hook
{ {
"fetch", enter enter,
{
{ "_site", "vm.fetch" }
}
}; };
void void
m::vm::fetch::enter(eval &eval) m::vm::fetch::enter(const event &event,
eval &eval)
{ {
assert(eval.event_);
assert(eval.opts); assert(eval.opts);
const event::prev prev const event::prev prev

View file

@ -27,8 +27,8 @@ namespace ircd::m::vm::fetch
extern ctx::dock dock; extern ctx::dock dock;
extern std::set<request, request> fetching; extern std::set<request, request> fetching;
extern std::deque<request *> fetched; extern std::deque<request *> fetched;
extern hookfn<eval &> hook;
extern ctx::context context; extern ctx::context context;
extern "C" vm::phase phase;
// worker stack // worker stack
static bool requesting(); static bool requesting();
@ -42,7 +42,7 @@ namespace ircd::m::vm::fetch
extern "C" json::object acquire(const m::room::id &, const m::event::id &, const mutable_buffer &); extern "C" json::object acquire(const m::room::id &, const m::event::id &, const mutable_buffer &);
// phase stack // phase stack
static void enter(m::vm::eval &); static void enter(const event &, vm::eval &);
} }
/// Fetch entity state /// Fetch entity state