0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 19:58:53 +02:00

ircd::db: Add internal interface around PinnableSlice queries.

This commit is contained in:
Jason Volk 2020-06-06 19:59:12 -07:00
parent 8b7fe333ec
commit 6ee817aec8
2 changed files with 115 additions and 2 deletions

View file

@ -7788,7 +7788,116 @@ ircd::db::has(const rocksdb::WriteBatch &wb,
}
//
// seek suite
// read suite
//
namespace ircd::db
{
static rocksdb::Status _seek(database::column &, rocksdb::PinnableSlice &, const string_view &, const rocksdb::ReadOptions &);
}
size_t
ircd::db::_read(column &column,
const string_view &key,
const rocksdb::ReadOptions &opts,
const column::view_closure &closure)
{
std::string buf;
rocksdb::PinnableSlice ps
{
&buf
};
database::column &c(column);
throw_on_error
{
_seek(c, ps, key, opts)
};
const string_view value
{
slice(ps)
};
if(likely(closure))
closure(value);
return size(value);
}
size_t
ircd::db::_read(std::nothrow_t,
column &column,
const string_view &key,
const rocksdb::ReadOptions &opts,
const column::view_closure &closure)
{
std::string buf;
rocksdb::PinnableSlice ps
{
&buf
};
database::column &c(column);
const auto status
{
_seek(c, ps, key, opts)
};
if(!valid(status))
return 0;
const string_view value
{
slice(ps)
};
if(likely(closure))
closure(value);
return size(value);
}
rocksdb::Status
ircd::db::_seek(database::column &c,
rocksdb::PinnableSlice &s,
const string_view &key,
const rocksdb::ReadOptions &ropts)
{
const ctx::uninterruptible::nothrow ui;
const ctx::stack_usage_assertion sua;
rocksdb::ColumnFamilyHandle *const &cf(c);
database &d(*c.d);
#ifdef RB_DEBUG_DB_SEEK
const ircd::timer timer;
#endif
const rocksdb::Status ret
{
d.d->Get(ropts, cf, slice(key), &s)
};
#ifdef RB_DEBUG_DB_SEEK
log::debug
{
log, "[%s] %lu:%lu SEEK %s in %ld$us '%s'",
name(d),
sequence(d),
sequence(opts.snapshot),
ret.ToString(),
timer.at<microseconds>().count(),
name(c)
};
#endif
return ret;
}
//
// iterator seek suite
//
namespace ircd::db

View file

@ -113,13 +113,17 @@ namespace ircd::db
void valid_or_throw(const rocksdb::Iterator &);
void valid_eq_or_throw(const rocksdb::Iterator &, const string_view &);
// [GET] seek suite
// [GET] iterator seek suite
template<class pos> bool seek(database::column &, const pos &, const rocksdb::ReadOptions &, std::unique_ptr<rocksdb::Iterator> &it);
std::unique_ptr<rocksdb::Iterator> seek(column &, const gopts &);
std::unique_ptr<rocksdb::Iterator> seek(column &, const string_view &key, const gopts &);
std::vector<row::value_type> seek(database &, const gopts &);
std::pair<string_view, string_view> operator*(const rocksdb::Iterator &);
// [GET] read suite
size_t _read(std::nothrow_t, column &, const string_view &key, const rocksdb::ReadOptions &, const column::view_closure & = {});
size_t _read(column &, const string_view &key, const rocksdb::ReadOptions &, const column::view_closure & = {});
// [SET] writebatch suite
std::string debug(const rocksdb::WriteBatch &);
bool has(const rocksdb::WriteBatch &, const op &);