0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:homeserver: Preliminary bootstrap from event vector.

This commit is contained in:
Jason Volk 2020-05-10 00:05:52 -07:00
parent 8a9954f181
commit b0776fd0f8
3 changed files with 82 additions and 2 deletions

View file

@ -41,6 +41,7 @@ bool soft_assert;
bool nomatrix; bool nomatrix;
bool matrix {true}; // matrix server by default. bool matrix {true}; // matrix server by default.
bool defaults; bool defaults;
const char *bootstrap;
lgetopt opts[] lgetopt opts[]
{ {
@ -70,6 +71,7 @@ lgetopt opts[]
{ "nomatrix", &nomatrix, lgetopt::BOOL, "Prevent loading the matrix application module" }, { "nomatrix", &nomatrix, lgetopt::BOOL, "Prevent loading the matrix application module" },
{ "matrix", &matrix, lgetopt::BOOL, "Allow loading the matrix application module" }, { "matrix", &matrix, lgetopt::BOOL, "Allow loading the matrix application module" },
{ "defaults", &defaults, lgetopt::BOOL, "Use configuration defaults without database load for this execution" }, { "defaults", &defaults, lgetopt::BOOL, "Use configuration defaults without database load for this execution" },
{ "bootstrap", &bootstrap, lgetopt::STRING, "Bootstrap fresh database from event vector" },
{ nullptr, nullptr, lgetopt::STRING, nullptr }, { nullptr, nullptr, lgetopt::STRING, nullptr },
}; };
@ -203,6 +205,7 @@ noexcept try
struct ircd::m::homeserver::opts opts; struct ircd::m::homeserver::opts opts;
opts.origin = origin; opts.origin = origin;
opts.server_name = server_name; opts.server_name = server_name;
opts.bootstrap_vector_path = bootstrap;
const ircd::custom_ptr<ircd::m::homeserver> homeserver const ircd::custom_ptr<ircd::m::homeserver> homeserver
{ {
// 6.1 // 6.1

View file

@ -143,4 +143,10 @@ struct ircd::m::homeserver::opts
/// be the origin itself; otherwise, SRV/well-known indirection is required /// be the origin itself; otherwise, SRV/well-known indirection is required
/// to reach the servername starting from the origin. /// to reach the servername starting from the origin.
string_view server_name; string_view server_name;
/// When instantiating a homeserver with a fresh database, the file found
/// at this path can supplement for any initial bootstrapping. This vector
/// may contain additional events as well; the server will continue its
/// operation after having processed these events.
string_view bootstrap_vector_path;
}; };

View file

@ -10,6 +10,7 @@
namespace ircd::m namespace ircd::m
{ {
static void bootstrap_event_vector(homeserver &);
static void bootstrap(homeserver &); static void bootstrap(homeserver &);
static void signon(homeserver &), signoff(homeserver &) noexcept; static void signon(homeserver &), signoff(homeserver &) noexcept;
@ -260,7 +261,12 @@ try
}}; }};
if(dbs::events && sequence(*dbs::events) == 0) if(dbs::events && sequence(*dbs::events) == 0)
bootstrap(*this); {
if(opts->bootstrap_vector_path)
bootstrap_event_vector(*this);
else
bootstrap(*this);
}
if(key && !key->verify_keys.empty()) if(key && !key->verify_keys.empty())
m::keys::cache::set(key->verify_keys); m::keys::cache::set(key->verify_keys);
@ -830,9 +836,74 @@ catch(...)
} }
// //
// bootstrap // bootstrap_vector
// //
void
ircd::m::bootstrap_event_vector(homeserver &homeserver)
try
{
const string_view &path
{
homeserver.opts->bootstrap_vector_path
};
fs::fd::opts fileopts(std::ios::in);
fileopts.sequential = true;
const fs::fd file
{
path, fileopts
};
log::notice
{
log, "Bootstrapping database from event vector @ `%s'",
path,
};
const unique_mutable_buffer mb
{
512_KiB
};
size_t events(0);
const_buffer buf;
fs::read_opts ropts; do
{
buf = read(file, mb, ropts);
ropts.offset += size(buf);
}
while(!!buf);
log::info
{
log, "Bootstrapped %zu events in %zu bytes from `%s'",
events,
ropts.offset,
path,
};
}
catch(const std::exception &e)
{
log::logf
{
log, log::level::CRITICAL,
"Failed to start server '%s' on network '%s'",
server_name(homeserver),
origin(homeserver),
e.what()
};
throw ircd::error
{
"bootstrap %s error :%s",
server_name(homeserver),
e.what()
};
}
void void
ircd::m::bootstrap(homeserver &homeserver) ircd::m::bootstrap(homeserver &homeserver)
try try