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

ircd::db: Improve opts, snapshot, and conversions for column::iterator.

This commit is contained in:
Jason Volk 2017-09-08 01:33:41 -07:00
parent fd3ae151b9
commit 1e7c0daed2
2 changed files with 36 additions and 29 deletions

View file

@ -103,6 +103,7 @@ struct ircd::db::column
public:
explicit operator const database &() const;
explicit operator const database::column &() const;
explicit operator const database::descriptor &() const;
explicit operator database &();
explicit operator database::column &();
@ -175,19 +176,19 @@ struct ircd::db::column::const_iterator
using value_type = column::value_type;
using iterator_category = std::bidirectional_iterator_tag;
private:
gopts opts;
protected:
database::column *c;
database::snapshot ss;
std::unique_ptr<rocksdb::Iterator> it;
mutable value_type val;
bool all_prefix;
friend class column;
const_iterator(database::column *const &, std::unique_ptr<rocksdb::Iterator> &&, gopts = {});
const_iterator(database::column *const &, std::unique_ptr<rocksdb::Iterator> &&, const gopts & = {});
public:
explicit operator const database::snapshot &() const;
explicit operator const database::column &() const;
explicit operator const gopts &() const;
explicit operator database::snapshot &();
explicit operator database::column &();
@ -223,14 +224,7 @@ database::column &()
inline ircd::db::column::const_iterator::operator
database::snapshot &()
{
return opts.snapshot;
}
inline ircd::db::column::const_iterator::operator
const gopts &()
const
{
return opts;
return ss;
}
inline ircd::db::column::const_iterator::operator
@ -244,7 +238,7 @@ inline ircd::db::column::const_iterator::operator
const database::snapshot &()
const
{
return opts.snapshot;
return ss;
}
inline ircd::db::column::operator

View file

@ -212,6 +212,7 @@ struct database::column
database *d;
std::type_index key_type;
std::type_index mapped_type;
struct descriptor descriptor;
comparator cmp;
prefix_transform prefix;
custom_ptr<rocksdb::ColumnFamilyHandle> handle;
@ -225,7 +226,7 @@ struct database::column
operator rocksdb::ColumnFamilyHandle *();
operator database &();
explicit column(database *const &d, descriptor);
explicit column(database *const &d, struct descriptor);
column() = delete;
column(column &&) = delete;
column(const column &) = delete;
@ -814,16 +815,17 @@ const
//
ircd::db::database::column::column(database *const &d,
descriptor desc)
struct descriptor descriptor)
:rocksdb::ColumnFamilyDescriptor
{
std::move(desc.name), database::options(desc.options)
descriptor.name, database::options(descriptor.options)
}
,d{d}
,key_type{desc.type.first}
,mapped_type{desc.type.second}
,cmp{d, std::move(desc.cmp)}
,prefix{d, std::move(desc.prefix)}
,key_type{descriptor.type.first}
,mapped_type{descriptor.type.second}
,descriptor{std::move(descriptor)}
,cmp{d, this->descriptor.cmp}
,prefix{d, this->descriptor.prefix}
,handle
{
nullptr, [this](rocksdb::ColumnFamilyHandle *const handle)
@ -835,7 +837,7 @@ ircd::db::database::column::column(database *const &d,
{
assert(d->columns.count(this->name) == 0);
if(!this->cmp.user.less)
if(!this->descriptor.cmp.less)
{
if(key_type == typeid(string_view))
this->cmp.user = cmp_string_view{};
@ -847,6 +849,7 @@ ircd::db::database::column::column(database *const &d,
key_type.name());
}
// Set the key comparator
this->options.comparator = &this->cmp;
// Set the prefix extractor
@ -2172,6 +2175,12 @@ const
return { *this, key };
}
ircd::db::column::operator
const database::descriptor &()
const
{
return c->descriptor;
}
///////////////////////////////////////////////////////////////////////////////
//
@ -2210,6 +2219,7 @@ ircd::db::column::cbegin(const gopts &gopts)
c, {}, gopts
};
ret.all_prefix = true;
seek(ret, pos::FRONT);
return std::move(ret);
}
@ -2251,10 +2261,11 @@ ircd::db::column::lower_bound(const string_view &key,
ircd::db::column::const_iterator::const_iterator(const_iterator &&o)
noexcept
:opts{std::move(o.opts)}
,c{std::move(o.c)}
:c{std::move(o.c)}
,ss{std::move(o.ss)}
,it{std::move(o.it)}
,val{std::move(o.val)}
,all_prefix{std::move(o.all_prefix)}
{
}
@ -2262,10 +2273,11 @@ ircd::db::column::const_iterator &
ircd::db::column::const_iterator::operator=(const_iterator &&o)
noexcept
{
opts = std::move(o.opts);
c = std::move(o.c);
ss = std::move(o.ss);
it = std::move(o.it);
val = std::move(o.val);
all_prefix = std::move(o.all_prefix);
return *this;
}
@ -2275,10 +2287,11 @@ ircd::db::column::const_iterator::const_iterator()
ircd::db::column::const_iterator::const_iterator(database::column *const &c,
std::unique_ptr<rocksdb::Iterator> &&it,
gopts opts)
:opts{std::move(opts)}
,c{c}
const gopts &gopts)
:c{c}
,ss{gopts.snapshot}
,it{std::move(it)}
,all_prefix{has_opt(gopts, db::get::ALL_PREFIX)}
{
//if(!has_opt(this->opts, get::READAHEAD))
// this->gopts.readahead_size = DEFAULT_READAHEAD;
@ -2407,12 +2420,12 @@ ircd::db::seek(column::const_iterator &it,
const pos &p)
{
database::column &c(it);
const gopts &gopts(it);
auto opts
{
make_opts(gopts, true)
make_opts({}, true)
};
opts.prefix_same_as_start = !it.all_prefix;
return seek(c, p, opts, it.it);
}
template bool ircd::db::seek<ircd::db::pos>(column::const_iterator &, const pos &);