mirror of
https://github.com/matrix-construct/construct
synced 2024-06-07 04:28:59 +02:00
ircd:Ⓜ️:dbs: Improve prefetch handlers; remove opts; split interface.
This commit is contained in:
parent
24d7a9220a
commit
54a591e45c
|
@ -29,6 +29,7 @@ namespace ircd::m::dbs
|
|||
extern std::shared_ptr<db::database> events;
|
||||
|
||||
// [SET (txn)] Basic write suite
|
||||
size_t prefetch(const event &, const write_opts &);
|
||||
size_t write(db::txn &, const event &, const write_opts &);
|
||||
}
|
||||
|
||||
|
@ -114,17 +115,6 @@ struct ircd::m::dbs::write_opts
|
|||
/// and "blacklist" they must know that `event_id => 0` was *found* to be
|
||||
/// zero.
|
||||
bool blacklist {false};
|
||||
|
||||
/// Whether index operations should be performed. This effectively toggles
|
||||
/// building of the transaction; if set to false, write() will not append
|
||||
/// to the transaction.
|
||||
bool index {true};
|
||||
|
||||
/// Perform a round of prefetches for data which may block queries made
|
||||
/// during indexing. Note that when index=false, only prefetches are made
|
||||
/// and write() should not have a reason to block; the return value becomes
|
||||
/// the number of prefetches launched.
|
||||
bool prefetch {true};
|
||||
};
|
||||
|
||||
/// Values which represent some element(s) included in a transaction or
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace ircd::m::dbs
|
|||
string_view event_horizon_key(const mutable_buffer &out, const id::event &);
|
||||
std::tuple<event::idx> event_horizon_key(const string_view &amalgam);
|
||||
|
||||
size_t _prefetch_event_horizon_resolve(db::txn &, const event &, const write_opts &);
|
||||
size_t _prefetch_event_horizon_resolve(const event &, const write_opts &);
|
||||
void _index_event_horizon_resolve(db::txn &, const event &, const write_opts &); //query
|
||||
void _index_event_horizon(db::txn &, const event &, const write_opts &, const id::event &);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace ircd::m::dbs
|
|||
string_view
|
||||
reflect(const ref &);
|
||||
|
||||
size_t _prefetch_event_refs(db::txn &, const event &, const write_opts &);
|
||||
size_t _prefetch_event_refs(const event &, const write_opts &);
|
||||
void _index_event_refs(db::txn &, const event &, const write_opts &);
|
||||
|
||||
// event_idx | ref_type, event_idx
|
||||
|
|
|
@ -197,7 +197,7 @@ ircd::m::dbs::write_opts::appendix_all{[]
|
|||
|
||||
namespace ircd::m::dbs
|
||||
{
|
||||
static size_t _prefetch(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch(const event &, const write_opts &);
|
||||
static size_t _index(db::txn &, const event &, const write_opts &);
|
||||
static size_t blacklist(db::txn &txn, const event::id &, const write_opts &);
|
||||
}
|
||||
|
@ -217,14 +217,7 @@ try
|
|||
"Cannot write to database: no index specified for event."
|
||||
};
|
||||
|
||||
size_t ret(0);
|
||||
if(prefetch_enable && opts.prefetch)
|
||||
ret = _prefetch(txn, event, opts);
|
||||
|
||||
if(likely(opts.index))
|
||||
ret = _index(txn, event, opts);
|
||||
|
||||
return ret;
|
||||
return _index(txn, event, opts);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
|
@ -238,6 +231,31 @@ catch(const std::exception &e)
|
|||
throw;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::prefetch(const event &event,
|
||||
const write_opts &opts)
|
||||
try
|
||||
{
|
||||
if(unlikely(opts.event_idx == 0))
|
||||
return false;
|
||||
|
||||
if(!prefetch_enable)
|
||||
return false;
|
||||
|
||||
return _prefetch(event, opts);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::error
|
||||
{
|
||||
log, "Event %s txn prefetching error :%s",
|
||||
string_view{event.event_id},
|
||||
e.what()
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::blacklist(db::txn &txn,
|
||||
const event::id &event_id,
|
||||
|
@ -274,13 +292,13 @@ ircd::m::dbs::blacklist(db::txn &txn,
|
|||
|
||||
namespace ircd::m::dbs
|
||||
{
|
||||
static size_t _prefetch_room_redact(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_room_redact(const event &, const write_opts &);
|
||||
static void _index_room_redact(db::txn &, const event &, const write_opts &);
|
||||
|
||||
static size_t _prefetch_room(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_room(const event &, const write_opts &);
|
||||
static void _index_room(db::txn &, const event &, const write_opts &);
|
||||
|
||||
static size_t _prefetch_event(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event(const event &, const write_opts &);
|
||||
static void _index_event(db::txn &, const event &, const write_opts &);
|
||||
}
|
||||
|
||||
|
@ -299,15 +317,14 @@ ircd::m::dbs::_index(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
size_t ret(0);
|
||||
ret += _prefetch_event(txn, event, opts);
|
||||
ret += _prefetch_event(event, opts);
|
||||
|
||||
if(json::get<"room_id"_>(event))
|
||||
ret += _prefetch_room(txn, event, opts);
|
||||
ret += _prefetch_room(event, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -343,8 +360,7 @@ ircd::m::dbs::_index_event(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
size_t ret(0);
|
||||
|
@ -367,10 +383,10 @@ ircd::m::dbs::_prefetch_event(db::txn &txn,
|
|||
;//ret += _prefetch_event_state(txn, event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::EVENT_REFS) && opts.event_refs.any())
|
||||
ret += _prefetch_event_refs(txn, event, opts);
|
||||
ret += _prefetch_event_refs(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::EVENT_HORIZON_RESOLVE) && opts.horizon_resolve.any())
|
||||
ret += _prefetch_event_horizon_resolve(txn, event, opts);
|
||||
ret += _prefetch_event_horizon_resolve(event, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -411,39 +427,38 @@ ircd::m::dbs::_index_room(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_room(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_room(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(!empty(json::get<"room_id"_>(event)));
|
||||
|
||||
size_t ret(0);
|
||||
if(opts.appendix.test(appendix::ROOM_EVENTS))
|
||||
;//ret += _prefetch_room_events(txn, event, opts);
|
||||
;//ret += _prefetch_room_events(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_TYPE))
|
||||
;//ret += _prefetch_room_type(txn, event, opts);
|
||||
;//ret += _prefetch_room_type(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_HEAD))
|
||||
;//ret += _prefetch_room_head(txn, event, opts);
|
||||
;//ret += _prefetch_room_head(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_HEAD_RESOLVE))
|
||||
;//ret += _prefetch_room_head_resolve(txn, event, opts);
|
||||
;//ret += _prefetch_room_head_resolve(event, opts);
|
||||
|
||||
if(defined(json::get<"state_key"_>(event)))
|
||||
{
|
||||
if(opts.appendix.test(appendix::ROOM_STATE))
|
||||
;//ret += _prefetch_room_state(txn, event, opts);
|
||||
;//ret += _prefetch_room_state(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_STATE_SPACE))
|
||||
;//ret += _prefetch_room_state_space(txn, event, opts);
|
||||
;//ret += _prefetch_room_state_space(event, opts);
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_JOINED) && at<"type"_>(event) == "m.room.member")
|
||||
;//ret += _prefetch_room_joined(txn, event, opts);
|
||||
;//ret += _prefetch_room_joined(event, opts);
|
||||
}
|
||||
|
||||
if(opts.appendix.test(appendix::ROOM_REDACT) && json::get<"type"_>(event) == "m.room.redaction")
|
||||
ret += _prefetch_room_redact(txn, event, opts);
|
||||
ret += _prefetch_room_redact(event, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -516,8 +531,7 @@ ircd::m::dbs::_index_room_redact(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_room_redact(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_room_redact(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::ROOM_REDACT));
|
||||
|
|
|
@ -190,8 +190,7 @@ ircd::m::dbs::_index_event_horizon_resolve(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_horizon_resolve(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_horizon_resolve(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_HORIZON_RESOLVE));
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
|
||||
namespace ircd::m::dbs
|
||||
{
|
||||
static size_t _prefetch_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_m_room_redaction(const event &, const write_opts &);
|
||||
static void _index_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &); //query
|
||||
static size_t _prefetch_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_m_receipt_m_read(const event &, const write_opts &);
|
||||
static void _index_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &); //query
|
||||
static size_t _prefetch_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_m_relates_m_reply(const event &, const write_opts &);
|
||||
static void _index_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &); //query
|
||||
static size_t _prefetch_event_refs_m_relates(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_m_relates(const event &, const write_opts &);
|
||||
static void _index_event_refs_m_relates(db::txn &, const event &, const write_opts &); //query
|
||||
static size_t _prefetch_event_refs_state(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_state(const event &, const write_opts &);
|
||||
static void _index_event_refs_state(db::txn &, const event &, const write_opts &); // query
|
||||
static size_t _prefetch_event_refs_auth(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_auth(const event &, const write_opts &);
|
||||
static void _index_event_refs_auth(db::txn &, const event &, const write_opts &); //query
|
||||
static size_t _prefetch_event_refs_prev(db::txn &, const event &, const write_opts &);
|
||||
static size_t _prefetch_event_refs_prev(const event &, const write_opts &);
|
||||
static void _index_event_refs_prev(db::txn &, const event &, const write_opts &); //query
|
||||
static bool event_refs__cmp_less(const string_view &a, const string_view &b);
|
||||
}
|
||||
|
@ -212,34 +212,33 @@ ircd::m::dbs::_index_event_refs(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
||||
size_t ret(0);
|
||||
if(opts.event_refs.test(uint(ref::NEXT)))
|
||||
ret += _prefetch_event_refs_prev(txn, event, opts);
|
||||
ret += _prefetch_event_refs_prev(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::NEXT_AUTH)))
|
||||
ret += _prefetch_event_refs_auth(txn, event, opts);
|
||||
ret += _prefetch_event_refs_auth(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::NEXT_STATE)) ||
|
||||
opts.event_refs.test(uint(ref::PREV_STATE)))
|
||||
ret += _prefetch_event_refs_state(txn, event, opts);
|
||||
ret += _prefetch_event_refs_state(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::M_RECEIPT__M_READ)))
|
||||
ret += _prefetch_event_refs_m_receipt_m_read(txn, event, opts);
|
||||
ret += _prefetch_event_refs_m_receipt_m_read(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::M_RELATES)))
|
||||
ret += _prefetch_event_refs_m_relates(txn, event, opts);
|
||||
ret += _prefetch_event_refs_m_relates(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::M_RELATES)))
|
||||
ret += _prefetch_event_refs_m_relates_m_reply(txn, event, opts);
|
||||
ret += _prefetch_event_refs_m_relates_m_reply(event, opts);
|
||||
|
||||
if(opts.event_refs.test(uint(ref::M_ROOM_REDACTION)))
|
||||
ret += _prefetch_event_refs_m_room_redaction(txn, event, opts);
|
||||
ret += _prefetch_event_refs_m_room_redaction(event, opts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -312,8 +311,7 @@ ircd::m::dbs::_index_event_refs_prev(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_prev(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_prev(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -404,8 +402,7 @@ ircd::m::dbs::_index_event_refs_auth(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_auth(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_auth(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -512,8 +509,7 @@ ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_state(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_state(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -603,8 +599,7 @@ ircd::m::dbs::_index_event_refs_m_receipt_m_read(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_m_receipt_m_read(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_m_receipt_m_read(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -711,8 +706,7 @@ ircd::m::dbs::_index_event_refs_m_relates(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_m_relates(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_m_relates(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -832,8 +826,7 @@ ircd::m::dbs::_index_event_refs_m_relates_m_reply(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_m_relates_m_reply(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_m_relates_m_reply(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
@ -934,8 +927,7 @@ ircd::m::dbs::_index_event_refs_m_room_redaction(db::txn &txn,
|
|||
}
|
||||
|
||||
size_t
|
||||
ircd::m::dbs::_prefetch_event_refs_m_room_redaction(db::txn &txn,
|
||||
const event &event,
|
||||
ircd::m::dbs::_prefetch_event_refs_m_room_redaction(const event &event,
|
||||
const write_opts &opts)
|
||||
{
|
||||
assert(opts.appendix.test(appendix::EVENT_REFS));
|
||||
|
|
Loading…
Reference in a new issue