2017-03-31 00:57:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Charybdis Development Team
|
|
|
|
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice is present in all copies.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_DB_OPTS_H
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
enum class set :uint64_t;
|
|
|
|
enum class get :uint64_t;
|
2017-08-28 23:51:22 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
template<class> struct opts;
|
2017-08-28 23:51:22 +02:00
|
|
|
struct sopts;
|
|
|
|
struct gopts;
|
2017-09-22 05:08:11 +02:00
|
|
|
|
|
|
|
template<class T> bool test(const opts<T> &, const typename std::underlying_type<T>::type &);
|
|
|
|
template<class T> bool test(const opts<T> &, const T &value);
|
|
|
|
|
|
|
|
template<class T> opts<T> &operator|=(opts<T> &, const opts<T> &);
|
|
|
|
template<class T> opts<T> &operator|=(opts<T> &, const T &value);
|
|
|
|
|
|
|
|
template<class T> opts<T> &operator&=(opts<T> &, const opts<T> &);
|
|
|
|
template<class T> opts<T> &operator&=(opts<T> &, const T &value);
|
2017-08-28 23:51:22 +02:00
|
|
|
}
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
enum class ircd::db::set
|
|
|
|
:uint64_t
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
FSYNC = 0x0001, // Uses kernel filesystem synchronization after write (slow)
|
|
|
|
NO_JOURNAL = 0x0002, // Write Ahead Log (WAL) for some crash recovery
|
|
|
|
MISSING_COLUMNS = 0x0004, // No exception thrown when writing to a deleted column family
|
2017-03-31 00:57:08 +02:00
|
|
|
};
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
enum class ircd::db::get
|
|
|
|
:uint64_t
|
2017-03-31 01:20:01 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
PIN = 0x0001, // Keep iter data in memory for iter lifetime (good for lots of ++/--)
|
|
|
|
CACHE = 0x0002, // Update the cache (CACHE is default for non-iterator operations)
|
|
|
|
NO_CACHE = 0x0004, // Do not update the cache (NO_CACHE is default for iterators)
|
|
|
|
NO_SNAPSHOT = 0x0008, // This iterator will have the latest data (tailing)
|
|
|
|
NO_CHECKSUM = 0x0010, // Integrity of data will be checked unless this is specified
|
|
|
|
PREFIX = 0x0020, // Iteration over a single prefix in column (prefix_same_as_start)
|
2017-03-31 01:20:01 +02:00
|
|
|
};
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
template<class T>
|
|
|
|
struct ircd::db::opts
|
2017-03-31 01:20:01 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
using flag_t = typename std::underlying_type<T>::type;
|
|
|
|
|
|
|
|
flag_t value {0};
|
|
|
|
|
|
|
|
opts() = default;
|
|
|
|
opts(const std::initializer_list<T> &list)
|
|
|
|
:value{combine_flags(list)}
|
2017-08-23 22:37:47 +02:00
|
|
|
{}
|
2017-03-31 01:20:01 +02:00
|
|
|
};
|
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
struct ircd::db::sopts
|
|
|
|
:opts<set>
|
2017-03-31 01:20:01 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
using opts<set>::opts;
|
2017-03-31 01:20:01 +02:00
|
|
|
};
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
struct ircd::db::gopts
|
2017-09-22 05:08:11 +02:00
|
|
|
:opts<get>
|
2017-03-31 01:20:01 +02:00
|
|
|
{
|
|
|
|
database::snapshot snapshot;
|
2017-09-22 05:08:11 +02:00
|
|
|
size_t readahead { 4_KiB };
|
|
|
|
const rocksdb::Slice *upper_bound {nullptr};
|
2017-03-31 01:20:01 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
using opts<get>::opts;
|
2017-03-31 01:20:01 +02:00
|
|
|
};
|
|
|
|
|
2017-03-31 00:57:08 +02:00
|
|
|
template<class T>
|
2017-09-22 05:08:11 +02:00
|
|
|
ircd::db::opts<T> &
|
|
|
|
ircd::db::operator&=(opts<T> &a,
|
|
|
|
const T &value)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
using flag_t = typename opts<T>::flag_t;
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
a.value &= flag_t(value);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
ircd::db::opts<T> &
|
|
|
|
ircd::db::operator&=(opts<T> &a,
|
|
|
|
const opts<T> &b)
|
|
|
|
{
|
|
|
|
a.value &= b.value;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
ircd::db::opts<T> &
|
|
|
|
ircd::db::operator|=(opts<T> &a,
|
|
|
|
const T &value)
|
|
|
|
{
|
|
|
|
using flag_t = typename opts<T>::flag_t;
|
|
|
|
|
|
|
|
a.value |= flag_t(value);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
ircd::db::opts<T> &
|
|
|
|
ircd::db::operator|=(opts<T> &a,
|
|
|
|
const opts<T> &b)
|
|
|
|
{
|
|
|
|
a.value |= b.value;
|
|
|
|
return a;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
bool
|
2017-09-22 05:08:11 +02:00
|
|
|
ircd::db::test(const opts<T> &a,
|
|
|
|
const T &value)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
using flag_t = typename opts<T>::flag_t;
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-09-22 05:08:11 +02:00
|
|
|
return a.value & flag_t(value);
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2017-09-22 05:08:11 +02:00
|
|
|
bool
|
|
|
|
ircd::db::test(const opts<T> &a,
|
|
|
|
const typename std::underlying_type<T>::type &value)
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
2017-09-22 05:08:11 +02:00
|
|
|
return (a.value & value) == value;
|
2017-03-31 00:57:08 +02:00
|
|
|
}
|