2018-01-18 03:14:13 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 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
|
2018-02-04 03:22:01 +01:00
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
2018-12-12 18:53:16 +01:00
|
|
|
struct options;
|
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)
|
2018-05-24 03:43:47 +02:00
|
|
|
CHECKSUM = 0x0010, // Integrity of data will be checked (overrides conf).
|
|
|
|
NO_CHECKSUM = 0x0020, // Integrity of data will not be checked (overrides conf).
|
|
|
|
PREFIX = 0x0040, // (prefix_same_as_start); automatic for index columns with pfx
|
|
|
|
ORDERED = 0x0080, // (total_order_seek); relevant to index columns
|
2018-12-24 23:33:35 +01:00
|
|
|
NO_PARALLEL = 0x0100, // Don't submit requests in parallel (relevant to db::row)
|
|
|
|
NO_THROW = 0x0200, // Suppress exceptions if possible.
|
|
|
|
THROW = 0x0400, // Throw exceptions more than usual.
|
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
|
|
|
};
|
|
|
|
|
2018-12-12 18:53:16 +01:00
|
|
|
/// options for writing (set)
|
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
|
|
|
};
|
|
|
|
|
2018-12-12 18:53:16 +01:00
|
|
|
/// options for reading (get)
|
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;
|
2018-04-14 07:08:57 +02:00
|
|
|
const rocksdb::Slice *lower_bound { nullptr };
|
|
|
|
const rocksdb::Slice *upper_bound { nullptr };
|
|
|
|
size_t readahead { 0 };
|
|
|
|
uint64_t seqnum { 0 };
|
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
|
|
|
};
|
|
|
|
|
2018-12-12 18:53:16 +01:00
|
|
|
/// options <-> string
|
|
|
|
struct ircd::db::options
|
|
|
|
:std::string
|
|
|
|
{
|
|
|
|
struct map;
|
|
|
|
|
|
|
|
// Output of options structures from this string
|
|
|
|
explicit operator rocksdb::Options() const;
|
|
|
|
operator rocksdb::DBOptions() const;
|
|
|
|
operator rocksdb::ColumnFamilyOptions() const;
|
|
|
|
operator rocksdb::PlainTableOptions() const;
|
|
|
|
operator rocksdb::BlockBasedTableOptions() const;
|
|
|
|
|
|
|
|
// Input of options structures output to this string
|
|
|
|
explicit options(const rocksdb::ColumnFamilyOptions &);
|
|
|
|
explicit options(const rocksdb::DBOptions &);
|
|
|
|
explicit options(const database::column &);
|
|
|
|
explicit options(const database &);
|
|
|
|
|
|
|
|
// Input of options string from user
|
|
|
|
options(std::string string)
|
|
|
|
:std::string{std::move(string)}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// options <-> map
|
|
|
|
struct ircd::db::options::map
|
|
|
|
:std::unordered_map<std::string, std::string>
|
|
|
|
{
|
|
|
|
// Output of options structures from map
|
|
|
|
operator rocksdb::DBOptions() const;
|
|
|
|
operator rocksdb::ColumnFamilyOptions() const;
|
|
|
|
operator rocksdb::PlainTableOptions() const;
|
|
|
|
operator rocksdb::BlockBasedTableOptions() const;
|
|
|
|
|
|
|
|
// Convert option string to map
|
|
|
|
map(const options &);
|
|
|
|
|
|
|
|
// Input of options map from user
|
|
|
|
map(std::unordered_map<std::string, std::string> m)
|
|
|
|
:std::unordered_map<std::string, std::string>{std::move(m)}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|