2018-01-26 21:26:09 +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
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_DBS_H
|
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
/// Database Schema
|
|
|
|
///
|
2018-01-26 21:26:09 +01:00
|
|
|
namespace ircd::m::dbs
|
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
struct init;
|
2018-03-03 07:03:06 +01:00
|
|
|
struct write_opts;
|
2018-02-08 22:23:01 +01:00
|
|
|
|
2018-09-15 10:12:47 +02:00
|
|
|
// General confs
|
|
|
|
extern conf::item<bool> events_cache_enable;
|
|
|
|
extern conf::item<bool> events_cache_comp_enable;
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// Database instance
|
|
|
|
extern std::shared_ptr<db::database> events;
|
|
|
|
|
|
|
|
// Event property columns
|
|
|
|
constexpr const auto event_columns{event::size()};
|
|
|
|
extern std::array<db::column, event_columns> event_column;
|
|
|
|
|
|
|
|
// Event metadata columns
|
2018-05-04 22:58:49 +02:00
|
|
|
extern db::column event_idx; // event_id => event_idx
|
2018-05-05 04:47:39 +02:00
|
|
|
extern db::index room_head; // room_id | event_id => event_idx
|
2018-05-04 22:58:49 +02:00
|
|
|
extern db::index room_events; // room_id | depth, event_idx => state_root
|
|
|
|
extern db::index room_joined; // room_id | origin, member => event_idx
|
|
|
|
extern db::index room_state; // room_id | type, state_key => event_idx
|
|
|
|
extern db::column state_node; // node_id => state::node
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
// Lowlevel util
|
2018-05-05 04:47:39 +02:00
|
|
|
constexpr size_t ROOM_HEAD_KEY_MAX_SIZE {id::MAX_SIZE + 1 + id::MAX_SIZE};
|
|
|
|
string_view room_head_key(const mutable_buffer &out, const id::room &, const id::event &);
|
|
|
|
string_view room_head_key(const string_view &amalgam);
|
|
|
|
|
2018-05-02 01:51:35 +02:00
|
|
|
constexpr size_t ROOM_STATE_KEY_MAX_SIZE {id::MAX_SIZE + 256 + 256};
|
2018-03-04 08:39:24 +01:00
|
|
|
string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type, const string_view &state_key);
|
|
|
|
string_view room_state_key(const mutable_buffer &out, const id::room &, const string_view &type);
|
2018-04-12 23:08:48 +02:00
|
|
|
std::pair<string_view, string_view> room_state_key(const string_view &amalgam);
|
2018-03-04 08:39:24 +01:00
|
|
|
|
2018-05-02 01:51:35 +02:00
|
|
|
constexpr size_t ROOM_JOINED_KEY_MAX_SIZE {id::MAX_SIZE + 256 + id::MAX_SIZE};
|
2018-04-15 23:40:10 +02:00
|
|
|
string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin, const id::user &member);
|
|
|
|
string_view room_joined_key(const mutable_buffer &out, const id::room &, const string_view &origin);
|
|
|
|
std::pair<string_view, string_view> room_joined_key(const string_view &amalgam);
|
2018-03-04 09:08:30 +01:00
|
|
|
|
2018-05-02 01:51:35 +02:00
|
|
|
constexpr size_t ROOM_EVENTS_KEY_MAX_SIZE {id::MAX_SIZE + 1 + 8 + 8};
|
2018-04-18 04:14:39 +02:00
|
|
|
string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth, const event::idx &);
|
2018-02-13 23:21:57 +01:00
|
|
|
string_view room_events_key(const mutable_buffer &out, const id::room &, const uint64_t &depth);
|
2018-04-18 04:14:39 +02:00
|
|
|
std::pair<uint64_t, event::idx> room_events_key(const string_view &amalgam);
|
|
|
|
|
|
|
|
// [GET] the state root for an event (with as much information as you have)
|
|
|
|
string_view state_root(const mutable_buffer &out, const id::room &, const event::idx &, const uint64_t &depth);
|
|
|
|
string_view state_root(const mutable_buffer &out, const id::room &, const event::id &, const uint64_t &depth);
|
|
|
|
string_view state_root(const mutable_buffer &out, const id::room &, const event::idx &);
|
|
|
|
string_view state_root(const mutable_buffer &out, const id::room &, const event::id &);
|
|
|
|
string_view state_root(const mutable_buffer &out, const event::idx &);
|
|
|
|
string_view state_root(const mutable_buffer &out, const event::id &);
|
2018-02-08 22:23:01 +01:00
|
|
|
string_view state_root(const mutable_buffer &out, const event &);
|
|
|
|
|
|
|
|
// [SET (txn)] Basic write suite
|
2018-03-03 07:03:06 +01:00
|
|
|
string_view write(db::txn &, const event &, const write_opts &);
|
2018-05-05 00:14:19 +02:00
|
|
|
void blacklist(db::txn &, const event::id &, const write_opts &);
|
2018-01-26 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 07:03:06 +01:00
|
|
|
struct ircd::m::dbs::write_opts
|
|
|
|
{
|
2018-05-18 08:47:05 +02:00
|
|
|
uint64_t event_idx {0};
|
2018-03-03 07:03:06 +01:00
|
|
|
string_view root_in;
|
|
|
|
mutable_buffer root_out;
|
2018-03-25 07:46:43 +02:00
|
|
|
db::op op {db::op::SET};
|
2018-03-03 07:03:06 +01:00
|
|
|
bool present {true};
|
2018-03-04 08:39:24 +01:00
|
|
|
bool history {true};
|
2018-04-29 04:05:17 +02:00
|
|
|
bool indexer {true};
|
2018-05-05 05:10:35 +02:00
|
|
|
bool head {true};
|
|
|
|
bool refs {true};
|
2018-03-03 07:03:06 +01:00
|
|
|
};
|
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
/// Database Schema Descriptors
|
|
|
|
///
|
2018-02-08 22:23:01 +01:00
|
|
|
namespace ircd::m::dbs::desc
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// Full description
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::description events;
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
//
|
2018-02-08 22:23:01 +01:00
|
|
|
// Direct columns
|
2018-04-13 04:26:33 +02:00
|
|
|
//
|
|
|
|
|
2018-11-02 17:01:23 +01:00
|
|
|
extern conf::item<size_t> events___event__meta_block__size;
|
2018-11-03 02:01:03 +01:00
|
|
|
extern conf::item<size_t> events___event__bloom__bits;
|
2018-11-02 17:01:23 +01:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__auth_events__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__auth_events__cache__size;
|
|
|
|
extern conf::item<size_t> events__auth_events__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_auth_events;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__content__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__content__cache__size;
|
|
|
|
extern conf::item<size_t> events__content__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_content;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__depth__block__size;
|
2018-10-21 09:19:42 +02:00
|
|
|
extern conf::item<size_t> events__depth__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__depth__cache__size;
|
|
|
|
extern conf::item<size_t> events__depth__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_depth;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__event_id__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__event_id__cache__size;
|
|
|
|
extern conf::item<size_t> events__event_id__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_event_id;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__hashes__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__hashes__cache__size;
|
|
|
|
extern conf::item<size_t> events__hashes__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_hashes;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__membership__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__membership__cache__size;
|
|
|
|
extern conf::item<size_t> events__membership__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_membership;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__origin__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__origin__cache__size;
|
|
|
|
extern conf::item<size_t> events__origin__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_origin;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__origin_server_ts__block__size;
|
2018-10-21 09:19:42 +02:00
|
|
|
extern conf::item<size_t> events__origin_server_ts__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__origin_server_ts__cache__size;
|
|
|
|
extern conf::item<size_t> events__origin_server_ts__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_origin_server_ts;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__prev_events__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__prev_events__cache__size;
|
|
|
|
extern conf::item<size_t> events__prev_events__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_prev_events;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__prev_state__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__prev_state__cache__size;
|
|
|
|
extern conf::item<size_t> events__prev_state__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_prev_state;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__redacts__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__redacts__cache__size;
|
|
|
|
extern conf::item<size_t> events__redacts__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_redacts;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__room_id__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__room_id__cache__size;
|
|
|
|
extern conf::item<size_t> events__room_id__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_room_id;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__sender__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__sender__cache__size;
|
|
|
|
extern conf::item<size_t> events__sender__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_sender;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__signatures__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__signatures__cache__size;
|
|
|
|
extern conf::item<size_t> events__signatures__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_signatures;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__state_key__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__state_key__cache__size;
|
|
|
|
extern conf::item<size_t> events__state_key__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_state_key;
|
2018-09-03 05:32:34 +02:00
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__type__block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__type__cache__size;
|
|
|
|
extern conf::item<size_t> events__type__cache_comp__size;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events_type;
|
2018-02-08 22:23:01 +01:00
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
//
|
2018-02-08 22:23:01 +01:00
|
|
|
// Metadata columns
|
2018-04-13 04:26:33 +02:00
|
|
|
//
|
2018-03-04 09:08:30 +01:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
// events index
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__event_idx__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__event_idx__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__event_idx__cache__size;
|
|
|
|
extern conf::item<size_t> events__event_idx__cache_comp__size;
|
2018-11-03 02:01:03 +01:00
|
|
|
extern conf::item<size_t> events__event_idx__bloom__bits;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__event_idx;
|
2018-04-18 04:14:39 +02:00
|
|
|
|
2018-05-05 04:47:39 +02:00
|
|
|
// room head mapping sequence
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__room_head__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__room_head__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__room_head__cache__size;
|
2018-05-05 04:47:39 +02:00
|
|
|
extern const db::prefix_transform events__room_head__pfx;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__room_head;
|
2018-05-05 04:47:39 +02:00
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
// room events sequence
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__room_events__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__room_events__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__room_events__cache__size;
|
|
|
|
extern conf::item<size_t> events__room_events__cache_comp__size;
|
2018-02-08 22:23:01 +01:00
|
|
|
extern const db::prefix_transform events__room_events__pfx;
|
2018-02-09 00:15:48 +01:00
|
|
|
extern const db::comparator events__room_events__cmp;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__room_events;
|
2018-03-04 09:08:30 +01:00
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
// room present joined members sequence
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__room_joined__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__room_joined__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__room_joined__cache__size;
|
|
|
|
extern conf::item<size_t> events__room_joined__cache_comp__size;
|
2018-11-03 02:01:03 +01:00
|
|
|
extern conf::item<size_t> events__room_joined__bloom__bits;
|
2018-04-15 23:40:10 +02:00
|
|
|
extern const db::prefix_transform events__room_joined__pfx;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__room_joined;
|
2018-03-04 08:39:24 +01:00
|
|
|
|
2018-04-16 23:20:50 +02:00
|
|
|
// room present state mapping sequence
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__room_state__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__room_state__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__room_state__cache__size;
|
|
|
|
extern conf::item<size_t> events__room_state__cache_comp__size;
|
2018-11-03 02:01:03 +01:00
|
|
|
extern conf::item<size_t> events__room_state__bloom__bits;
|
2018-04-16 23:20:50 +02:00
|
|
|
extern const db::prefix_transform events__room_state__pfx;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__room_state;
|
2018-04-16 23:20:50 +02:00
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
// state btree node key-value store
|
2018-09-18 08:35:38 +02:00
|
|
|
extern conf::item<size_t> events__state_node__block__size;
|
2018-10-16 22:40:03 +02:00
|
|
|
extern conf::item<size_t> events__state_node__meta_block__size;
|
2018-09-03 05:32:34 +02:00
|
|
|
extern conf::item<size_t> events__state_node__cache__size;
|
|
|
|
extern conf::item<size_t> events__state_node__cache_comp__size;
|
2018-11-03 02:01:03 +01:00
|
|
|
extern conf::item<size_t> events__state_node__bloom__bits;
|
2018-09-20 00:38:37 +02:00
|
|
|
extern const db::descriptor events__state_node;
|
2018-01-26 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
2018-05-06 03:54:02 +02:00
|
|
|
// Internal interface; not for public.
|
|
|
|
namespace ircd::m::dbs
|
|
|
|
{
|
|
|
|
void _index__room_state(db::txn &, const event &, const write_opts &);
|
|
|
|
void _index__room_events(db::txn &, const event &, const write_opts &, const string_view &);
|
|
|
|
void _index__room_joined(db::txn &, const event &, const write_opts &);
|
|
|
|
void _index__room_head(db::txn &, const event &, const write_opts &);
|
|
|
|
string_view _index_state(db::txn &, const event &, const write_opts &);
|
|
|
|
string_view _index_redact(db::txn &, const event &, const write_opts &);
|
|
|
|
string_view _index_ephem(db::txn &, const event &, const write_opts &);
|
2018-05-18 08:47:05 +02:00
|
|
|
void _index__event(db::txn &, const event &, const write_opts &);
|
2018-05-06 03:54:02 +02:00
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
struct ircd::m::dbs::init
|
|
|
|
{
|
2018-04-09 21:56:43 +02:00
|
|
|
init(std::string dbopts = {});
|
2018-02-08 22:23:01 +01:00
|
|
|
~init() noexcept;
|
|
|
|
};
|