mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd:Ⓜ️:acquire: Add vm::opts to interface options; add per-operation eval opts.
This commit is contained in:
parent
b897071ce3
commit
e9fb24bdd9
4 changed files with 71 additions and 31 deletions
|
@ -25,6 +25,8 @@ struct ircd::m::acquire
|
|||
static log::log log;
|
||||
|
||||
const struct opts &opts;
|
||||
vm::opts head_vmopts;
|
||||
vm::opts history_vmopts;
|
||||
std::list<result> fetching;
|
||||
|
||||
private:
|
||||
|
@ -33,15 +35,15 @@ struct ircd::m::acquire
|
|||
bool handle();
|
||||
|
||||
bool started(const event::id &) const;
|
||||
bool start(const event::id &, const string_view &, const bool &, const size_t &);
|
||||
bool submit(const event::id &, const string_view &, const bool &, const size_t &);
|
||||
|
||||
bool fetch_missing(event::idx &);
|
||||
void acquire_missing();
|
||||
bool start(const event::id &, const string_view &, const bool &, const size_t &, const vm::opts *const &);
|
||||
bool submit(const event::id &, const string_view &, const bool &, const size_t &, const vm::opts *const &);
|
||||
|
||||
bool fetch_head(const m::event &, const int64_t &);
|
||||
void acquire_head();
|
||||
|
||||
bool fetch_history(event::idx &);
|
||||
void acquire_history();
|
||||
|
||||
public:
|
||||
acquire(const struct opts &);
|
||||
acquire(const acquire &) = delete;
|
||||
|
@ -51,7 +53,8 @@ struct ircd::m::acquire
|
|||
|
||||
struct ircd::m::acquire::opts
|
||||
{
|
||||
/// Room apropos.
|
||||
/// Room apropos; note that the event_id in this structure may have some
|
||||
/// effect on the result after deducing other options instead of defaults.
|
||||
m::room room;
|
||||
|
||||
/// Optional remote host first considered as the target for operations in
|
||||
|
@ -62,11 +65,19 @@ struct ircd::m::acquire::opts
|
|||
/// hint, and fails them if the hint is insufficient.
|
||||
bool hint_only {false};
|
||||
|
||||
/// Perform head acquisition prior to depthwise operations.
|
||||
/// Perform head acquisition. Setting to false will disable the ability
|
||||
/// to reconnoiter the latest events from remote servers. Note that setting
|
||||
/// a depth ceiling effectively makes this false.
|
||||
bool head {true};
|
||||
|
||||
/// Perform missing acquisition.
|
||||
bool missing {true};
|
||||
/// Perform history acquisition. Setting this to false disables operations
|
||||
/// which fill in gaps in the timeline below the head.
|
||||
bool history {true};
|
||||
|
||||
/// Perform state acquisition. Setting this to false may result in an
|
||||
/// acquisition that is missing state events and subject to inconsistency
|
||||
/// from the ABA problem etc.
|
||||
bool state {true};
|
||||
|
||||
/// Provide a viewport size; generally obtained from the eponymous conf
|
||||
/// item and used for initial backfill
|
||||
|
@ -89,10 +100,16 @@ struct ircd::m::acquire::opts
|
|||
|
||||
/// Limit the number of requests in flight at any given time.
|
||||
size_t fetch_width {128};
|
||||
|
||||
/// Default vm::opts to be used during eval; some options are
|
||||
/// unconditionally overriden to perform some evals. Use caution, setting
|
||||
/// options may cause results not expected from this interface.
|
||||
vm::opts vmopts;
|
||||
};
|
||||
|
||||
struct ircd::m::acquire::result
|
||||
{
|
||||
const m::vm::opts *vmopts {nullptr};
|
||||
ctx::future<fetch::result> future;
|
||||
event::id::buf event_id;
|
||||
};
|
||||
|
|
|
@ -32,14 +32,32 @@ ircd::util::instance_list<ircd::m::acquire>::list
|
|||
|
||||
ircd::m::acquire::acquire::acquire(const struct opts &opts)
|
||||
:opts{opts}
|
||||
,head_vmopts{opts.vmopts}
|
||||
,history_vmopts{opts.vmopts}
|
||||
{
|
||||
if(opts.head)
|
||||
{
|
||||
head_vmopts.notify_servers = false;
|
||||
head_vmopts.phase.set(m::vm::phase::FETCH_PREV, false);
|
||||
head_vmopts.phase.set(m::vm::phase::FETCH_STATE, opts.state);
|
||||
}
|
||||
|
||||
if(opts.history)
|
||||
{
|
||||
history_vmopts.notify_servers = false;
|
||||
history_vmopts.phase.set(m::vm::phase::NOTIFY, false);
|
||||
history_vmopts.phase.set(m::vm::phase::FETCH_PREV, false);
|
||||
history_vmopts.phase.set(m::vm::phase::FETCH_STATE, false);
|
||||
history_vmopts.wopts.appendix.set(dbs::appendix::ROOM_HEAD, false);
|
||||
}
|
||||
|
||||
// Branch to acquire head
|
||||
if(opts.head)
|
||||
acquire_head();
|
||||
|
||||
// Branch to acquire missing
|
||||
if(opts.missing)
|
||||
acquire_missing();
|
||||
// Branch to acquire history
|
||||
if(opts.history)
|
||||
acquire_history();
|
||||
|
||||
// Complete all work before returning, otherwise everything
|
||||
// will be cancelled on unwind.
|
||||
|
@ -53,7 +71,7 @@ noexcept
|
|||
}
|
||||
|
||||
void
|
||||
ircd::m::acquire::acquire_missing()
|
||||
ircd::m::acquire::acquire_history()
|
||||
{
|
||||
event::idx ref_min
|
||||
{
|
||||
|
@ -62,7 +80,7 @@ ircd::m::acquire::acquire_missing()
|
|||
|
||||
for(size_t i(0); i < opts.rounds; ++i)
|
||||
{
|
||||
if(!fetch_missing(ref_min))
|
||||
if(!fetch_history(ref_min))
|
||||
break;
|
||||
|
||||
if(ref_min > opts.ref.second)
|
||||
|
@ -71,7 +89,7 @@ ircd::m::acquire::acquire_missing()
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::acquire::fetch_missing(event::idx &ref_min)
|
||||
ircd::m::acquire::fetch_history(event::idx &ref_min)
|
||||
{
|
||||
const auto top
|
||||
{
|
||||
|
@ -185,7 +203,7 @@ ircd::m::acquire::fetch_missing(event::idx &ref_min)
|
|||
|
||||
const bool submitted
|
||||
{
|
||||
submit(event_id, opts.hint, false, limit)
|
||||
submit(event_id, opts.hint, false, limit, &history_vmopts)
|
||||
};
|
||||
|
||||
if(submitted)
|
||||
|
@ -261,7 +279,7 @@ ircd::m::acquire::fetch_head(const m::event &result,
|
|||
|
||||
const bool submitted
|
||||
{
|
||||
submit(result.event_id, hint, true, limit)
|
||||
submit(result.event_id, hint, true, limit, &head_vmopts)
|
||||
};
|
||||
|
||||
if(submitted)
|
||||
|
@ -282,12 +300,13 @@ bool
|
|||
ircd::m::acquire::submit(const m::event::id &event_id,
|
||||
const string_view &hint,
|
||||
const bool &hint_only,
|
||||
const size_t &limit)
|
||||
const size_t &limit,
|
||||
const vm::opts *const &vmopts)
|
||||
{
|
||||
const bool ret
|
||||
{
|
||||
!started(event_id)?
|
||||
start(event_id, hint, hint_only, limit):
|
||||
start(event_id, hint, hint_only, limit, vmopts):
|
||||
false
|
||||
};
|
||||
|
||||
|
@ -301,7 +320,8 @@ bool
|
|||
ircd::m::acquire::start(const m::event::id &event_id,
|
||||
const string_view &hint,
|
||||
const bool &hint_only,
|
||||
const size_t &limit)
|
||||
const size_t &limit,
|
||||
const vm::opts *const &vmopts)
|
||||
try
|
||||
{
|
||||
fetch::opts fopts;
|
||||
|
@ -313,7 +333,7 @@ try
|
|||
fopts.attempt_limit = hint_only;
|
||||
fetching.emplace_back(result
|
||||
{
|
||||
fetch::start(fopts), event_id
|
||||
vmopts, fetch::start(fopts), event_id
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -372,6 +392,7 @@ ircd::m::acquire::handle()
|
|||
full()? 5000: 50
|
||||
};
|
||||
|
||||
ctx::interruption_point();
|
||||
if(!next.wait(timeout, std::nothrow))
|
||||
return full();
|
||||
|
||||
|
@ -411,18 +432,17 @@ try
|
|||
string_view{opts.room.room_id},
|
||||
};
|
||||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.infolog_accept = true;
|
||||
vmopts.warnlog &= ~vm::fault::EXISTS;
|
||||
vmopts.notify_servers = false;
|
||||
vmopts.phase.set(m::vm::phase::NOTIFY, false);
|
||||
vmopts.phase.set(m::vm::phase::FETCH_PREV, false);
|
||||
vmopts.phase.set(m::vm::phase::FETCH_STATE, false);
|
||||
vmopts.wopts.appendix.set(dbs::appendix::ROOM_HEAD, false);
|
||||
ctx::interruption_point();
|
||||
assert(result.vmopts);
|
||||
assert
|
||||
(
|
||||
false
|
||||
|| result.vmopts == &this->head_vmopts
|
||||
|| result.vmopts == &this->history_vmopts
|
||||
);
|
||||
|
||||
m::vm::eval
|
||||
{
|
||||
pdus, vmopts
|
||||
pdus, *result.vmopts
|
||||
};
|
||||
|
||||
return true;
|
||||
|
|
|
@ -307,6 +307,8 @@ ircd::m::init::backfill::handle_room(const room::id &room_id)
|
|||
opts.room = room_id;
|
||||
opts.viewport_size = ssize_t(m::room::events::viewport_size);
|
||||
opts.viewport_size *= size_t(viewports);
|
||||
opts.vmopts.infolog_accept = true;
|
||||
opts.vmopts.warnlog &= ~vm::fault::EXISTS;
|
||||
m::acquire
|
||||
{
|
||||
opts
|
||||
|
|
|
@ -11090,6 +11090,7 @@ console_cmd__room__acquire(opt &out, const string_view &line)
|
|||
};
|
||||
|
||||
struct m::acquire::opts opts;
|
||||
opts.vmopts.infolog_accept = true;
|
||||
opts.room = room_id;
|
||||
opts.depth.first = depth_start;
|
||||
opts.depth.second = depth_stop;
|
||||
|
|
Loading…
Reference in a new issue