0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::db: Concurrent row seek.

This commit is contained in:
Jason Volk 2018-08-18 20:59:28 -07:00
parent 89e920fdd4
commit 9165c71afd
2 changed files with 60 additions and 9 deletions

View file

@ -59,7 +59,8 @@ struct ircd::db::row
const vector_view<cell> &buf = {},
gopts opts = {});
template<class pos> friend size_t seek(row &, const pos &);
friend size_t seek(row &, const pos &);
friend size_t seek(row &, const string_view &);
};
namespace ircd::db

View file

@ -4523,20 +4523,17 @@ ircd::db::write(const row::delta *const &begin,
write(&deltas.front(), &deltas.front() + deltas.size(), sopts);
}
template<class pos>
size_t
ircd::db::seek(row &r,
const pos &p)
{
if(r.empty())
return 0;
#ifdef RB_DEBUG_DB_SEEK
const ircd::timer timer;
#endif
size_t ret{0};
ctx::latch latch{r.size()};
const ctx::uninterruptible ui;
for(auto &cell : r) request([&latch, &ret, &cell, &p]
{
ret += bool(seek(cell, p));
@ -4550,7 +4547,59 @@ ircd::db::seek(row &r,
const database &d(c);
log::debug
{
log, "'%s' %lu:%lu '%s' row SEEK %zu of %zu in %ld$us",
log, "'%s' %lu:%lu '%s' row SEEK POS %zu of %zu in %ld$us",
name(d),
sequence(d),
sequence(r[0]),
name(c),
ret,
r.size(),
timer.at<microseconds>().count()
};
#endif
assert(ret <= r.size());
return ret;
}
size_t
ircd::db::seek(row &r,
const string_view &key)
{
#ifdef RB_DEBUG_DB_SEEK
const ircd::timer timer;
#endif
size_t ret{0};
ctx::latch latch{r.size()};
const auto closure{[&latch, &ret, &key]
(auto &cell)
{
ret += bool(seek(cell, key));
latch.count_down();
}};
const ctx::uninterruptible ui;
for(auto &cell : r)
{
db::column &column(cell);
if(!exists(cache(column), key))
request([&closure, &cell]
{
closure(cell);
});
else
closure(cell);
}
latch.wait();
#ifdef RB_DEBUG_DB_SEEK
const column &c(r[0]);
const database &d(c);
log::debug
{
log, "'%s' %lu:%lu '%s' row SEEK KEY %zu of %zu in %ld$us",
name(d),
sequence(d),
sequence(r[0]),
@ -4564,8 +4613,6 @@ ircd::db::seek(row &r,
assert(ret <= r.size());
return ret;
}
template size_t ircd::db::seek<ircd::db::pos>(row &, const pos &);
template size_t ircd::db::seek<ircd::string_view>(row &, const string_view &);
//
// row
@ -4634,8 +4681,11 @@ ircd::db::row::row(database &d,
for(size_t i(0); i < this->size() && i < column_count; ++i)
{
std::unique_ptr<Iterator> it(iterators.at(i));
(*this)[i] = cell { *colptr[i], key, std::move(it), opts };
(*this)[i] = cell { *colptr[i], std::move(it), opts };
}
if(key)
seek(*this, key);
}
void