0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

ircd:Ⓜ️:events::refs: Add unbounded column scan w/ console cmd.

This commit is contained in:
Jason Volk 2020-10-11 17:06:33 -07:00
parent 325145ab29
commit 62fdaaa389
3 changed files with 154 additions and 0 deletions

View file

@ -83,6 +83,16 @@ namespace ircd::m::events::state
bool for_each(const closure &); bool for_each(const closure &);
} }
/// Interface to scan the refs of events
namespace ircd::m::events::refs
{
// (source, type, target)
using closure = std::function<bool (const event::idx &, const dbs::ref &, const event::idx &)>;
// Iterate events in range
bool for_each(const range &, const closure &);
}
/// Interface to scan the content of events /// Interface to scan the content of events
namespace ircd::m::events::content namespace ircd::m::events::content
{ {

View file

@ -408,6 +408,81 @@ ircd::m::events::content::for_each(const closure &closure)
return true; return true;
} }
//
// events::refs
//
namespace ircd::m::events::refs
{
extern conf::item<size_t> readahead;
}
decltype(ircd::m::events::refs::readahead)
ircd::m::events::refs::readahead
{
{ "name", "ircd.m.events.refs.readahead" },
{ "default", long(4_MiB) },
};
bool
ircd::m::events::refs::for_each(const range &range,
const closure &closure)
{
db::column &event_refs
{
dbs::event_refs
};
db::gopts gopts
{
db::get::NO_CACHE,
db::get::NO_CHECKSUM
};
gopts.readahead = size_t(readahead);
const auto start
{
std::min(range.first, range.second)
};
const auto stop
{
std::max(range.first, range.second)
};
auto it
{
event_refs.lower_bound(byte_view<string_view>(start), gopts)
};
for(; it; ++it)
{
const auto &key
{
it->first
};
const event::idx src
{
byte_view<event::idx, false>(key)
};
if(src >= stop)
break;
const auto &[type, tgt]
{
dbs::event_refs_key(key.substr(sizeof(event::idx)))
};
assert(tgt != src);
if(!closure(src, type, tgt))
return false;
}
return true;
}
// //
// events::state // events::state
// //

View file

@ -7785,6 +7785,75 @@ console_cmd__events__state(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__events__refs(opt &out, const string_view &line)
{
const params param{line, " ",
{
"start", "stop", "type", "limit"
}};
const m::event::idx start
{
param.at("start", m::vm::sequence::retired - 128)
};
const m::event::idx stop
{
param.at("stop", m::vm::sequence::retired + 1)
};
const string_view &typestr
{
param.at("type", "*"_sv)
};
size_t limit
{
param.at("limit", 2048UL)
};
m::dbs::ref type
{
typestr == "*"?
m::dbs::ref(-1):
m::dbs::ref(0)
};
if(type != m::dbs::ref(-1))
for(; uint8_t(type) < sizeof(m::dbs::ref) * 256; type = m::dbs::ref(uint8_t(type) + 1))
if(reflect(type) == typestr)
break;
m::events::refs::for_each({start, stop}, [&out, &limit]
(const auto &src, const auto &type, const auto &tgt)
-> bool
{
const auto src_id
{
m::event_id(std::nothrow, src)
};
const auto tgt_id
{
m::event_id(std::nothrow, tgt)
};
out
<< " " << std::right << std::setw(10) << src
<< " " << std::left << std::setw(45) << trunc(src_id? string_view{src_id}: "<index error>"_sv, 45)
<< " " << std::right << std::setw(12) << trunc(reflect(type), 12)
<< " -> " << std::right << std::setw(10) << tgt
<< " " << std::left << std::setw(45) << trunc(tgt_id? string_view{tgt_id}: "<index error>"_sv, 45)
<< std::endl
;
return --limit;
});
return true;
}
bool bool
console_cmd__events__dump(opt &out, const string_view &line) console_cmd__events__dump(opt &out, const string_view &line)
{ {