2018-01-18 03:14:13 +01:00
|
|
|
// Matrix Construct
|
2017-08-23 23:37:06 +02:00
|
|
|
//
|
2018-01-18 03:14:13 +01:00
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
2017-08-23 23:37:06 +02:00
|
|
|
//
|
2018-01-18 03:14:13 +01:00
|
|
|
// 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-01-19 02:59:22 +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.
|
2018-01-18 03:14:13 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_DB_DATABASE_H
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::db
|
|
|
|
{
|
|
|
|
struct database;
|
|
|
|
|
2018-12-09 00:17:13 +01:00
|
|
|
// Broad conf items
|
|
|
|
extern conf::item<bool> open_check;
|
|
|
|
extern conf::item<std::string> open_recover;
|
2020-01-12 04:14:32 +01:00
|
|
|
extern conf::item<bool> open_repair;
|
2020-06-11 06:49:27 +02:00
|
|
|
extern conf::item<bool> open_slave;
|
2020-06-10 13:29:12 +02:00
|
|
|
extern conf::item<bool> auto_compact;
|
2018-12-09 00:17:13 +01:00
|
|
|
|
2018-04-03 19:58:16 +02:00
|
|
|
// General information
|
2017-08-28 23:51:22 +02:00
|
|
|
const std::string &name(const database &);
|
2018-05-23 02:01:01 +02:00
|
|
|
const std::string &uuid(const database &);
|
2018-03-23 03:35:50 +01:00
|
|
|
uint64_t sequence(const database &); // Latest sequence number
|
2018-10-31 23:29:00 +01:00
|
|
|
const std::vector<std::string> &errors(const database &);
|
2018-04-03 20:44:57 +02:00
|
|
|
std::vector<std::string> files(const database &, uint64_t &msz);
|
|
|
|
std::vector<std::string> files(const database &);
|
2018-12-10 23:04:30 +01:00
|
|
|
std::vector<std::string> wals(const database &);
|
2018-04-17 23:13:36 +02:00
|
|
|
size_t file_count(const database &);
|
|
|
|
size_t bytes(const database &);
|
2018-12-12 18:57:46 +01:00
|
|
|
options getopt(const database &);
|
2018-12-19 21:52:08 +01:00
|
|
|
log::level loglevel(const database &);
|
2018-03-23 03:35:50 +01:00
|
|
|
|
2018-04-03 19:58:16 +02:00
|
|
|
// Property information interface
|
|
|
|
using prop_int = uint64_t;
|
|
|
|
using prop_str = std::string;
|
2018-04-09 21:55:22 +02:00
|
|
|
using prop_map = std::map<std::string, std::string>;
|
2018-04-03 19:58:16 +02:00
|
|
|
template<class R = prop_int> R property(const database &, const string_view &name);
|
|
|
|
template<> prop_int property(const database &, const string_view &name);
|
|
|
|
|
2018-05-15 01:17:43 +02:00
|
|
|
// Access to the database's row cache (see cache.h interface)
|
|
|
|
const rocksdb::Cache *cache(const database &);
|
|
|
|
rocksdb::Cache *cache(database &);
|
|
|
|
|
2018-04-03 19:58:16 +02:00
|
|
|
// Control panel
|
2018-12-19 21:52:08 +01:00
|
|
|
void loglevel(database &, const log::level &);
|
2018-04-20 23:10:59 +02:00
|
|
|
void setopt(database &, const string_view &key, const string_view &val);
|
2018-04-20 22:38:49 +02:00
|
|
|
void fdeletions(database &, const bool &enable, const bool &force = false);
|
2018-05-25 05:01:52 +02:00
|
|
|
uint64_t checkpoint(database &);
|
2018-12-17 03:00:54 +01:00
|
|
|
void bgcancel(database &, const bool &blocking = true);
|
2018-12-15 02:27:48 +01:00
|
|
|
void bgcontinue(database &);
|
|
|
|
void bgpause(database &);
|
2020-06-11 06:49:27 +02:00
|
|
|
void refresh(database &);
|
2018-10-31 23:03:32 +01:00
|
|
|
void resume(database &);
|
2020-01-08 20:23:47 +01:00
|
|
|
void check(database &, const string_view &file);
|
2018-05-23 01:52:34 +02:00
|
|
|
void check(database &);
|
2018-12-13 00:53:16 +01:00
|
|
|
void compact(database &, const std::pair<int, int> &level, const compactor & = {});
|
2018-09-20 01:36:01 +02:00
|
|
|
void compact(database &, const compactor & = {});
|
2018-12-19 22:50:42 +01:00
|
|
|
void sort(database &, const bool &blocking = true, const bool &now = true);
|
2018-04-27 02:19:29 +02:00
|
|
|
void flush(database &, const bool &sync = false);
|
2018-03-23 03:35:50 +01:00
|
|
|
void sync(database &);
|
2017-08-28 23:51:22 +02:00
|
|
|
}
|
|
|
|
|
2018-01-18 03:14:13 +01:00
|
|
|
/// Database instance
|
|
|
|
///
|
|
|
|
/// There can be only one instance of this class for each database, so it is
|
|
|
|
/// always shared and must be make_shared(). The database is open when an
|
|
|
|
/// instance is constructed and closed when the instance destructs.
|
|
|
|
///
|
|
|
|
/// The construction must have the same consistent descriptor set used every
|
|
|
|
/// time otherwise bad things happen.
|
|
|
|
///
|
|
|
|
/// The instance registers and deregisters itself in a global set of open
|
|
|
|
/// databases and can be found that way if necessary.
|
|
|
|
///
|
2018-09-03 02:29:44 +02:00
|
|
|
/// Internal structures declared within this class comprise the backend which
|
|
|
|
/// supports RocksDB; they are not involved in the standard include stack
|
|
|
|
/// beyond this declaration and not meant for IRCd developers merely using the
|
|
|
|
/// ircd::db interface.
|
|
|
|
///
|
2017-08-28 23:51:22 +02:00
|
|
|
struct ircd::db::database
|
2017-08-30 23:21:18 +02:00
|
|
|
:std::enable_shared_from_this<database>
|
2018-05-25 05:01:52 +02:00
|
|
|
,instance_list<database>
|
2017-03-31 00:57:08 +02:00
|
|
|
{
|
|
|
|
struct options;
|
2017-08-23 23:37:06 +02:00
|
|
|
struct events;
|
|
|
|
struct stats;
|
2018-12-10 22:26:46 +01:00
|
|
|
struct logger;
|
2017-08-23 23:37:06 +02:00
|
|
|
struct mergeop;
|
2017-03-31 00:57:08 +02:00
|
|
|
struct snapshot;
|
|
|
|
struct comparator;
|
2017-08-31 07:12:58 +02:00
|
|
|
struct prefix_transform;
|
2018-09-19 00:07:09 +02:00
|
|
|
struct compaction_filter;
|
2017-03-31 00:57:08 +02:00
|
|
|
struct column;
|
2018-01-18 03:34:20 +01:00
|
|
|
struct env;
|
2018-09-03 02:29:44 +02:00
|
|
|
struct cache;
|
2018-09-22 22:13:05 +02:00
|
|
|
struct sst;
|
2018-12-10 23:04:30 +01:00
|
|
|
struct wal;
|
2019-04-20 23:22:08 +02:00
|
|
|
struct wal_filter;
|
2020-05-05 05:30:47 +02:00
|
|
|
struct allocator;
|
2020-09-15 04:53:35 +02:00
|
|
|
struct rate_limiter;
|
2017-11-16 02:29:54 +01:00
|
|
|
|
2017-08-23 23:37:06 +02:00
|
|
|
std::string name;
|
2018-05-25 05:01:52 +02:00
|
|
|
uint64_t checkpoint;
|
|
|
|
std::string path;
|
2018-12-03 02:39:33 +01:00
|
|
|
std::string optstr;
|
2020-06-11 06:49:27 +02:00
|
|
|
bool fsck, slave, read_only;
|
2018-01-18 04:22:35 +01:00
|
|
|
std::shared_ptr<struct env> env;
|
2017-08-23 23:37:06 +02:00
|
|
|
std::shared_ptr<struct stats> stats;
|
2018-12-10 22:26:46 +01:00
|
|
|
std::shared_ptr<struct logger> logger;
|
2017-08-23 23:37:06 +02:00
|
|
|
std::shared_ptr<struct events> events;
|
|
|
|
std::shared_ptr<struct mergeop> mergeop;
|
2019-04-20 23:22:08 +02:00
|
|
|
std::unique_ptr<struct wal_filter> wal_filter;
|
2020-09-15 04:53:35 +02:00
|
|
|
std::shared_ptr<struct rate_limiter> rate_limiter;
|
2020-05-05 05:30:47 +02:00
|
|
|
std::shared_ptr<struct allocator> allocator;
|
2018-04-21 00:45:57 +02:00
|
|
|
std::shared_ptr<rocksdb::SstFileManager> ssts;
|
2018-09-03 02:29:44 +02:00
|
|
|
std::shared_ptr<rocksdb::Cache> row_cache;
|
2017-11-16 02:29:54 +01:00
|
|
|
std::vector<descriptor> descriptors;
|
2018-12-03 02:39:33 +01:00
|
|
|
std::unique_ptr<rocksdb::DBOptions> opts;
|
2018-10-22 16:09:55 +02:00
|
|
|
std::unordered_map<string_view, std::shared_ptr<column>> column_names;
|
2018-04-21 01:22:01 +02:00
|
|
|
std::unique_ptr<rocksdb::DB> d;
|
2018-10-22 16:09:55 +02:00
|
|
|
std::vector<std::shared_ptr<column>> column_index; // indexed by cfid
|
|
|
|
std::list<std::shared_ptr<column>> columns; // active only
|
2018-05-23 02:01:01 +02:00
|
|
|
std::string uuid;
|
2018-05-25 05:01:52 +02:00
|
|
|
std::unique_ptr<rocksdb::Checkpoint> checkpointer;
|
2018-10-31 23:29:00 +01:00
|
|
|
std::vector<std::string> errors;
|
2017-04-03 06:02:32 +02:00
|
|
|
|
|
|
|
operator std::shared_ptr<database>() { return shared_from_this(); }
|
2017-03-31 00:57:08 +02:00
|
|
|
operator const rocksdb::DB &() const { return *d; }
|
|
|
|
operator rocksdb::DB &() { return *d; }
|
|
|
|
|
2019-01-16 22:21:36 +01:00
|
|
|
// Lookup a column ID by name; throws not_found or returns -1.
|
|
|
|
int32_t cfid(const std::nothrow_t, const string_view &name) const;
|
|
|
|
uint32_t cfid(const string_view &name) const;
|
|
|
|
|
|
|
|
// Obtain a reference to a column or throw
|
2017-09-19 04:17:36 +02:00
|
|
|
const column &operator[](const uint32_t &id) const;
|
|
|
|
const column &operator[](const string_view &name) const;
|
|
|
|
column &operator[](const uint32_t &id);
|
|
|
|
column &operator[](const string_view &name);
|
2017-03-31 00:57:08 +02:00
|
|
|
|
2017-08-30 23:07:36 +02:00
|
|
|
// [SET] Perform operations in a sequence as a single transaction.
|
|
|
|
void operator()(const sopts &, const delta *const &begin, const delta *const &end);
|
|
|
|
void operator()(const sopts &, const std::initializer_list<delta> &);
|
|
|
|
void operator()(const sopts &, const delta &);
|
|
|
|
void operator()(const delta *const &begin, const delta *const &end);
|
|
|
|
void operator()(const std::initializer_list<delta> &);
|
|
|
|
void operator()(const delta &);
|
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
database(const string_view &name,
|
|
|
|
const uint64_t &checkpoint,
|
2018-01-19 02:59:22 +01:00
|
|
|
std::string options,
|
|
|
|
description);
|
2017-08-23 23:37:06 +02:00
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
database(const string_view &name,
|
|
|
|
std::string options,
|
|
|
|
description);
|
|
|
|
|
|
|
|
database(const string_view &name,
|
2018-01-19 02:59:22 +01:00
|
|
|
std::string options = {});
|
2017-03-31 00:57:08 +02:00
|
|
|
|
|
|
|
database() = default;
|
|
|
|
database(database &&) = delete;
|
|
|
|
database(const database &) = delete;
|
2018-01-19 02:59:22 +01:00
|
|
|
~database() noexcept;
|
2017-03-31 01:20:01 +02:00
|
|
|
|
2018-05-25 05:01:52 +02:00
|
|
|
// Find this instance by name (and checkpoint id) in the instance list
|
|
|
|
static database *get(std::nothrow_t, const string_view &name, const uint64_t &checkpoint);
|
|
|
|
static database *get(std::nothrow_t, const string_view &name); // optionally "name:checkpoint"
|
|
|
|
static database &get(const string_view &name, const uint64_t &checkpoint);
|
|
|
|
static database &get(const string_view &name); // optionally "name:checkpoint"
|
|
|
|
|
2017-08-23 23:37:06 +02:00
|
|
|
// Get this instance from any column.
|
2017-03-31 01:20:01 +02:00
|
|
|
static const database &get(const column &);
|
|
|
|
static database &get(column &);
|
2017-03-31 00:57:08 +02:00
|
|
|
};
|