2019-09-27 04:28:25 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::log)
|
|
|
|
ircd::m::vm::log
|
|
|
|
{
|
|
|
|
"m.vm", 'v'
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::dock)
|
|
|
|
ircd::m::vm::dock;
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::ready)
|
|
|
|
ircd::m::vm::ready;
|
|
|
|
|
2019-10-03 19:51:29 +02:00
|
|
|
decltype(ircd::m::vm::default_copts)
|
|
|
|
ircd::m::vm::default_copts;
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::default_opts)
|
|
|
|
ircd::m::vm::default_opts;
|
|
|
|
|
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::vm::init::init()
|
|
|
|
{
|
|
|
|
id::event::buf event_id;
|
|
|
|
sequence::retired = sequence::get(event_id);
|
|
|
|
sequence::committed = sequence::retired;
|
|
|
|
sequence::uncommitted = sequence::committed;
|
|
|
|
|
|
|
|
vm::ready = true;
|
|
|
|
vm::dock.notify_all();
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "BOOT %s @%lu [%s] db:%lu",
|
|
|
|
server_name(my()),
|
|
|
|
sequence::retired,
|
|
|
|
sequence::retired?
|
|
|
|
string_view{event_id} : "NO EVENTS"_sv,
|
|
|
|
m::dbs::events?
|
|
|
|
db::sequence(*m::dbs::events) : 0UL,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::vm::init::~init()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
vm::ready = false;
|
|
|
|
|
2020-07-25 18:17:05 +02:00
|
|
|
if(eval::executing || eval::injecting)
|
2019-10-03 19:51:29 +02:00
|
|
|
log::warning
|
|
|
|
{
|
2020-07-25 18:17:05 +02:00
|
|
|
log, "Waiting for exec:%zu inject:%zu pending:%zu evaluations",
|
2019-10-03 19:51:29 +02:00
|
|
|
eval::executing,
|
|
|
|
eval::injecting,
|
|
|
|
sequence::pending,
|
|
|
|
};
|
|
|
|
|
2022-06-24 04:18:05 +02:00
|
|
|
vm::dock.wait([]() noexcept
|
2019-10-03 19:51:29 +02:00
|
|
|
{
|
|
|
|
return !eval::executing && !eval::injecting;
|
|
|
|
});
|
|
|
|
|
2020-03-21 01:18:44 +01:00
|
|
|
if(sequence::pending)
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
log, "Waiting for pending:%zu sequencing (retired:%zu committed:%zu uncommitted:%zu)",
|
|
|
|
sequence::pending,
|
|
|
|
sequence::retired,
|
|
|
|
sequence::committed,
|
|
|
|
sequence::uncommitted,
|
|
|
|
};
|
|
|
|
|
2022-06-24 04:18:05 +02:00
|
|
|
sequence::dock.wait([]() noexcept
|
2020-03-21 01:18:44 +01:00
|
|
|
{
|
|
|
|
return !sequence::pending;
|
|
|
|
});
|
2019-10-03 19:51:29 +02:00
|
|
|
|
|
|
|
event::id::buf event_id;
|
|
|
|
const auto retired
|
|
|
|
{
|
|
|
|
sequence::get(event_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
|
|
|
log, "HALT '%s' @%lu [%s] vm:%lu:%lu:%lu db:%lu",
|
|
|
|
server_name(my()),
|
|
|
|
retired,
|
|
|
|
retired?
|
|
|
|
string_view{event_id} : "NO EVENTS"_sv,
|
|
|
|
sequence::retired,
|
|
|
|
sequence::committed,
|
|
|
|
sequence::uncommitted,
|
|
|
|
m::dbs::events?
|
|
|
|
db::sequence(*m::dbs::events) : 0UL,
|
|
|
|
};
|
|
|
|
|
2020-07-28 06:57:35 +02:00
|
|
|
assert(retired == sequence::retired || ircd::read_only);
|
2019-10-03 19:51:29 +02:00
|
|
|
}
|
|
|
|
|
2023-03-23 09:12:38 +01:00
|
|
|
ircd::m::vm::phase
|
|
|
|
ircd::m::vm::phase_reflect(const string_view &str)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
phase ret{phase::NONE};
|
|
|
|
util::for_each<phase>([&ret, &str]
|
|
|
|
(const auto &phase)
|
|
|
|
{
|
|
|
|
if(reflect(phase) == str)
|
|
|
|
{
|
|
|
|
ret = phase;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-12 04:37:55 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::vm::reflect(const enum phase &code)
|
|
|
|
{
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case phase::NONE: return "NONE";
|
|
|
|
case phase::EXECUTE: return "EXECUTE";
|
|
|
|
case phase::CONFORM: return "CONFORM";
|
2020-12-10 10:49:27 +01:00
|
|
|
case phase::DUPWAIT: return "DUPWAIT";
|
|
|
|
case phase::DUPCHK: return "DUPCHK";
|
|
|
|
case phase::ISSUE: return "ISSUE";
|
2020-05-12 04:37:55 +02:00
|
|
|
case phase::ACCESS: return "ACCESS";
|
2020-12-16 23:22:21 +01:00
|
|
|
case phase::EMPTION: return "EMPTION";
|
2020-05-12 04:37:55 +02:00
|
|
|
case phase::VERIFY: return "VERIFY";
|
2020-05-12 05:24:54 +02:00
|
|
|
case phase::FETCH_AUTH: return "FETCH_AUTH";
|
|
|
|
case phase::AUTH_STATIC: return "AUTH_STATIC";
|
|
|
|
case phase::FETCH_PREV: return "FETCH_PREV";
|
|
|
|
case phase::FETCH_STATE: return "FETCH_STATE";
|
2020-05-12 04:37:55 +02:00
|
|
|
case phase::PRECOMMIT: return "PRECOMMIT";
|
2020-12-05 14:12:45 +01:00
|
|
|
case phase::PREINDEX: return "PREINDEX";
|
2020-05-12 05:24:54 +02:00
|
|
|
case phase::AUTH_RELA: return "AUTH_RELA";
|
2020-05-12 04:37:55 +02:00
|
|
|
case phase::COMMIT: return "COMMIT";
|
2020-05-12 05:24:54 +02:00
|
|
|
case phase::AUTH_PRES: return "AUTH_PRES";
|
2020-05-12 04:37:55 +02:00
|
|
|
case phase::EVALUATE: return "EVALUATE";
|
|
|
|
case phase::INDEX: return "INDEX";
|
|
|
|
case phase::POST: return "POST";
|
|
|
|
case phase::WRITE: return "WRITE";
|
|
|
|
case phase::RETIRE: return "RETIRE";
|
|
|
|
case phase::NOTIFY: return "NOTIFY";
|
|
|
|
case phase::EFFECTS: return "EFFECTS";
|
2020-07-25 18:12:00 +02:00
|
|
|
case phase::_NUM_: break;
|
2020-05-12 04:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|
|
|
|
|
2023-02-19 01:59:22 +01:00
|
|
|
ircd::http::code
|
|
|
|
ircd::m::vm::http_code(const fault &code)
|
|
|
|
{
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case fault::ACCEPT: return http::OK;
|
|
|
|
case fault::EXISTS: return http::CONFLICT;
|
|
|
|
case fault::INVALID: return http::BAD_REQUEST;
|
|
|
|
case fault::GENERAL: return http::UNAUTHORIZED;
|
|
|
|
case fault::AUTH: return http::FORBIDDEN;
|
|
|
|
case fault::STATE: return http::NOT_FOUND;
|
|
|
|
case fault::EVENT: return http::NOT_FOUND;
|
|
|
|
case fault::BOUNCE: break;
|
|
|
|
case fault::DONOTWANT: break;
|
2023-02-19 02:10:01 +01:00
|
|
|
case fault::DENIED: return http::FORBIDDEN;
|
2023-02-19 02:27:22 +01:00
|
|
|
case fault::IDENT: return http::UNAUTHORIZED;
|
2023-02-19 01:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return http::INTERNAL_SERVER_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-09-27 04:28:25 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::vm::reflect(const enum fault &code)
|
|
|
|
{
|
|
|
|
switch(code)
|
|
|
|
{
|
|
|
|
case fault::ACCEPT: return "#ACCEPT";
|
|
|
|
case fault::EXISTS: return "#EXISTS";
|
|
|
|
case fault::GENERAL: return "#GENERAL";
|
|
|
|
case fault::INVALID: return "#INVALID";
|
|
|
|
case fault::AUTH: return "#AUTH";
|
|
|
|
case fault::EVENT: return "#EVENT";
|
|
|
|
case fault::STATE: return "#STATE";
|
2021-01-08 18:00:48 +01:00
|
|
|
case fault::BOUNCE: return "#BOUNCE";
|
|
|
|
case fault::DONOTWANT: return "#DONOTWANT";
|
2023-02-19 02:10:01 +01:00
|
|
|
case fault::DENIED: return "#DENIED";
|
2023-02-19 02:27:22 +01:00
|
|
|
case fault::IDENT: return "#IDENT";
|
2019-09-27 04:28:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "??????";
|
|
|
|
}
|