0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd:Ⓜ️:vm: Add db::txn allocation reservation options.

This commit is contained in:
Jason Volk 2018-04-16 14:24:56 -07:00
parent e009d6763e
commit dcacc5af0a
2 changed files with 30 additions and 6 deletions

View file

@ -41,14 +41,15 @@ namespace ircd::m::vm
///
struct ircd::m::vm::eval
{
const vm::opts *opts {&default_opts};
db::txn txn{*dbs::events};
const vm::opts *opts;
db::txn txn;
fault operator()(const event &);
eval(const event &, const vm::opts & = default_opts);
eval(const vm::opts &);
eval() = default;
eval(const vm::opts & = default_opts);
eval(eval &&) = delete;
eval(const eval &) = delete;
friend string_view reflect(const fault &);
};
@ -126,6 +127,17 @@ struct ircd::m::vm::opts
/// TODO: Y
bool head_must_exist {false};
/// Evaluators can set this value to optimize the creation of the database
/// transaction where the event will be stored. This value should be set
/// to the amount of space the event consumes; the JSON-serialized size is
/// a good value here.
size_t reserve_bytes {1024};
/// This value is added to reserve_bytes to account for indexing overhead
/// in the database transaction allocation. Most evaluators have little
/// reason to ever adjust this.
size_t reserve_index {1536};
/// Mask of faults that are not thrown as exceptions out of eval(). If
/// masked, the fault is returned from eval(). By default, the EXISTS
/// fault is masked which means existing events won't kill eval loops

View file

@ -173,6 +173,7 @@ ircd::m::vm::commit(const event &event,
auto opts_{opts};
opts_.verify = false;
opts_.reserve_bytes = serialized(event);
// Some functionality on this server may create an event on behalf
// of remote users. It's safe for us to mask this here, but eval'ing
@ -227,13 +228,24 @@ ircd::m::vm::notify_hook
};
ircd::m::vm::eval::eval(const vm::opts &opts)
:opts{&opts}
:opts
{
&opts
}
,txn
{
*dbs::events, db::txn::opts
{
opts.reserve_bytes + opts.reserve_index, // reserve_bytes
0, // max_bytes (no max)
}
}
{
}
ircd::m::vm::eval::eval(const event &event,
const vm::opts &opts)
:opts{&opts}
:eval{opts}
{
operator()(event);
}