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
|
|
|
|
|
|
|
// 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-04-18 04:14:39 +02:00
|
|
|
extern db::column event_idx;
|
2018-02-09 00:59:06 +01:00
|
|
|
extern db::index room_events;
|
2018-04-15 23:40:10 +02:00
|
|
|
extern db::index room_joined;
|
2018-03-04 08:39:24 +01:00
|
|
|
extern db::index room_state;
|
2018-04-18 04:14:39 +02:00
|
|
|
extern db::column state_node;
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
// Lowlevel util
|
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-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-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-01-26 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 07:03:06 +01:00
|
|
|
struct ircd::m::dbs::write_opts
|
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
uint64_t 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-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
|
|
|
|
extern const database::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-02-08 22:23:01 +01:00
|
|
|
extern const database::descriptor events_auth_events;
|
|
|
|
extern const database::descriptor events_content;
|
|
|
|
extern const database::descriptor events_depth;
|
|
|
|
extern const database::descriptor events_event_id;
|
|
|
|
extern const database::descriptor events_hashes;
|
|
|
|
extern const database::descriptor events_membership;
|
|
|
|
extern const database::descriptor events_origin;
|
|
|
|
extern const database::descriptor events_origin_server_ts;
|
|
|
|
extern const database::descriptor events_prev_events;
|
|
|
|
extern const database::descriptor events_prev_state;
|
2018-02-15 23:57:56 +01:00
|
|
|
extern const database::descriptor events_redacts;
|
2018-02-08 22:23:01 +01:00
|
|
|
extern const database::descriptor events_room_id;
|
|
|
|
extern const database::descriptor events_sender;
|
|
|
|
extern const database::descriptor events_signatures;
|
|
|
|
extern const database::descriptor events_state_key;
|
|
|
|
extern const database::descriptor events_type;
|
|
|
|
|
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
|
|
|
|
extern const database::descriptor events__event_idx;
|
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
// room events sequence
|
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-02-08 22:23:01 +01:00
|
|
|
extern const database::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-04-15 23:40:10 +02:00
|
|
|
extern const db::prefix_transform events__room_joined__pfx;
|
|
|
|
extern const database::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
|
|
|
|
extern const db::prefix_transform events__room_state__pfx;
|
|
|
|
extern const database::descriptor events__room_state;
|
|
|
|
|
2018-04-13 04:26:33 +02:00
|
|
|
// state btree node key-value store
|
|
|
|
extern const database::descriptor events__state_node;
|
2018-01-26 21:26:09 +01: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;
|
|
|
|
};
|