0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-04 06:38:58 +02:00

ircd::db: Improve row seek debugging and related.

This commit is contained in:
Jason Volk 2019-01-11 13:46:43 -08:00
parent 11f905274e
commit 0f20a6a6ba

View file

@ -9125,22 +9125,28 @@ ircd::db::write(const row::delta *const &begin,
write(&deltas.front(), &deltas.front() + deltas.size(), sopts); write(&deltas.front(), &deltas.front() + deltas.size(), sopts);
} }
// Developer can specifically use RB_DEBUG_DB_SEEK_ROW without RB_DEBUG_DB_SEEK
// to only see a report of the row seek as a whole. If RB_DEBUG_DB_SEEK is
// enabled that implies RB_DEBUG_DB_SEEK_ROW as well.
//
#if !defined(RB_DEBUG_DB_SEEK_ROW) && defined(RB_DEBUG_DB_SEEK_ROW)
#define RB_DEBUG_DB_SEEK_ROW
#endif
size_t size_t
ircd::db::seek(row &r, ircd::db::seek(row &r,
const string_view &key, const string_view &key,
const gopts &opts) const gopts &opts)
{ {
#ifdef RB_DEBUG_DB_SEEK // The following closure performs the seek() for a single cell in the row.
const ircd::timer timer; // It may be executed on another ircd::ctx if the data isn't cached and
#endif // blocking IO is required. This frame can't be interrupted because it may
// have requests pending in the request pool which must synchronize back
// This frame can't be interrupted because it may have requests // here.
// pending in the request pool which must synchronize back here.
const ctx::uninterruptible ui;
size_t ret{0}; size_t ret{0};
std::exception_ptr eptr; std::exception_ptr eptr;
ctx::latch latch{r.size()}; ctx::latch latch{r.size()};
const ctx::uninterruptible ui;
const auto closure{[&opts, &latch, &ret, &key, &eptr] const auto closure{[&opts, &latch, &ret, &key, &eptr]
(auto &cell) noexcept (auto &cell) noexcept
{ {
@ -9184,18 +9190,37 @@ ircd::db::seek(row &r,
latch.count_down(); latch.count_down();
}}; }};
#ifdef RB_DEBUG_DB_SEEK_ROW
const ircd::timer timer;
size_t submits{0};
#endif
// Submit all the requests // Submit all the requests
for(auto &cell : r) for(auto &cell : r)
{ {
db::column &column(cell); db::column &column(cell);
const auto reclosure{[&closure, &cell] const auto reclosure{[&closure, &cell]
() noexcept
{ {
closure(cell); closure(cell);
}}; }};
// Whether to submit the request to another ctx or execute it here.
// Explicit option to prevent submitting must not be set. If there
// is a chance the data is already in the cache, we can avoid the
// context switching and occupation of the request pool.
//TODO: should check a bloom filter on the cache for this branch //TODO: should check a bloom filter on the cache for this branch
//TODO: because right now double-querying the cache is gross. //TODO: because right now double-querying the cache is gross.
if(!test(opts, get::NO_PARALLEL) && !exists(cache(column), key)) const bool submit
{
!test(opts, get::NO_PARALLEL) && !exists(cache(column), key)
};
#ifdef RB_DEBUG_DB_SEEK_ROW
submits += submit;
#endif
if(submit)
request(reclosure); request(reclosure);
else else
reclosure(); reclosure();
@ -9205,21 +9230,25 @@ ircd::db::seek(row &r,
latch.wait(); latch.wait();
assert(ret <= r.size()); assert(ret <= r.size());
#ifdef RB_DEBUG_DB_SEEK #ifdef RB_DEBUG_DB_SEEK_ROW
const column &c(r[0]); if(likely(!r.empty()))
const database &d(c);
log::debug
{ {
log, "'%s' %lu:%lu '%s' row SEEK KEY %zu of %zu in %ld$us %s", const column &c(r[0]);
name(d), const database &d(c);
sequence(d), thread_local char tmbuf[32];
sequence(r[0]), log::debug
name(c), {
ret, log, "'%s' SEEK ROW seq:%lu:%-10lu cnt:%-2zu req:%-2zu ret:%-2zu in %s %s",
r.size(), name(d),
timer.at<microseconds>().count(), sequence(d),
what(eptr) sequence(opts.snapshot),
}; r.size(),
submits,
ret,
pretty(tmbuf, timer.at<microseconds>(), true),
what(eptr)
};
}
#endif #endif
if(eptr && !test(opts, get::NO_THROW)) if(eptr && !test(opts, get::NO_THROW))