0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️:vm: Move vector eval related to execute unit.

This commit is contained in:
Jason Volk 2020-09-13 15:23:42 -07:00
parent a02bd474d7
commit bf8dd39144
4 changed files with 59 additions and 48 deletions

View file

@ -37,6 +37,7 @@ namespace ircd::m::vm
string_view loghead(const eval &); // single tls buffer
fault execute(eval &, const event &);
size_t execute(eval &, const vector_view<const event> &);
fault inject(eval &, json::iov &, const json::iov &);
}
@ -83,7 +84,7 @@ struct ircd::m::vm::eval
uint64_t sequence {0};
std::shared_ptr<db::txn> txn;
vector_view<m::event> pdus;
vector_view<const m::event> pdus;
const json::iov *issue {nullptr};
const event *event_ {nullptr};
string_view room_id;

View file

@ -385,7 +385,7 @@ ircd::m::vm::eval::eval(const vector_view<m::event> &events,
const vm::opts &opts)
:eval{opts}
{
operator()(events);
execute(*this, events);
}
ircd::m::vm::eval::~eval()
@ -399,47 +399,6 @@ noexcept
}
}
size_t
ircd::m::vm::eval::operator()(const vector_view<m::event> &events)
{
assert(opts);
const scope_restore eval_pdus
{
this->pdus, events
};
if(likely(opts->phase[phase::VERIFY] && opts->mfetch_keys))
mfetch_keys();
// Conduct each eval without letting any one exception ruin things for the
// others, including an interrupt. The only exception is a termination.
size_t ret(0), i(0);
for(auto it(begin(events)); it != end(events) && i < opts->limit; ++it, ++i) try
{
const m::event &event
{
*it
};
const auto status
{
operator()(event)
};
ret += status == fault::ACCEPT;
}
catch(const ctx::interrupted &e)
{
throw;
}
catch(const std::exception &e)
{
continue;
}
return ret;
}
/// Inject a new event originating from this server.
///
ircd::m::vm::fault
@ -449,6 +408,12 @@ ircd::m::vm::eval::operator()(json::iov &event,
return vm::inject(*this, event, contents);
}
size_t
ircd::m::vm::eval::operator()(const vector_view<m::event> &events)
{
return vm::execute(*this, events);
}
ircd::m::vm::fault
ircd::m::vm::eval::operator()(const event &event)
{

View file

@ -128,6 +128,51 @@ ircd::m::vm::effect_hook
// execute
//
size_t
ircd::m::vm::execute(eval &eval,
const vector_view<const event> &events)
{
assert(eval.opts);
const auto &opts
{
*eval.opts
};
const scope_restore eval_pdus
{
eval.pdus, events
};
if(likely(opts.phase[phase::VERIFY] && opts.mfetch_keys))
eval.mfetch_keys();
size_t ret(0), i(0);
for(auto it(begin(events)); it != end(events) && i < opts.limit; ++it, ++i) try
{
const m::event &event
{
*it
};
const auto status
{
execute(eval, event)
};
ret += status == fault::ACCEPT;
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &)
{
continue;
}
return ret;
}
ircd::m::vm::fault
ircd::m::vm::execute(eval &eval,
const event &event)

View file

@ -7246,9 +7246,9 @@ console_cmd__stage__eval(opt &out, const string_view &line)
if(id == -1)
for(size_t i(0); i < stage.size(); ++i)
eval(m::event{stage.at(i)});
execute(eval, m::event{stage.at(i)});
else
eval(m::event{stage.at(id)});
execute(eval, m::event{stage.at(id)});
return true;
}
@ -7274,9 +7274,9 @@ console_cmd__stage__commit(opt &out, const string_view &line)
if(id == -1)
for(size_t i(0); i < stage.size(); ++i)
eval(m::event{stage.at(i)});
execute(eval, m::event{stage.at(i)});
else
eval(m::event{stage.at(id)});
execute(eval, m::event{stage.at(id)});
return true;
}
@ -14069,7 +14069,7 @@ console_cmd__fed__sync(opt &out, const string_view &line)
};
for(const auto &event : events)
eval(event);
execute(eval, event);
return true;
}