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.
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Residence of the events database instance pointer.
|
|
|
|
decltype(ircd::m::dbs::events)
|
|
|
|
ircd::m::dbs::events
|
|
|
|
{};
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Linkage for a cache of the columns of the events database which directly
|
|
|
|
/// correspond to a property in the matrix event object. This array allows
|
|
|
|
/// for constant time access to a column the same way one can make constant
|
|
|
|
/// time access to a property in m::event.
|
|
|
|
decltype(ircd::m::dbs::event_column)
|
|
|
|
ircd::m::dbs::event_column
|
|
|
|
{};
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
/// Linkage for a reference to the event_seq column.
|
|
|
|
decltype(ircd::m::dbs::event_idx)
|
|
|
|
ircd::m::dbs::event_idx
|
|
|
|
{};
|
|
|
|
|
2019-01-15 22:01:29 +01:00
|
|
|
/// Linkage for a reference to the event_json column.
|
|
|
|
decltype(ircd::m::dbs::event_json)
|
|
|
|
ircd::m::dbs::event_json
|
|
|
|
{};
|
|
|
|
|
2019-02-06 02:18:53 +01:00
|
|
|
/// Linkage for a reference to the event_refs column.
|
|
|
|
decltype(ircd::m::dbs::event_refs)
|
|
|
|
ircd::m::dbs::event_refs
|
|
|
|
{};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
/// Linkage for a reference to the event_horizon column.
|
|
|
|
decltype(ircd::m::dbs::event_horizon)
|
|
|
|
ircd::m::dbs::event_horizon
|
|
|
|
{};
|
|
|
|
|
2019-04-16 22:41:55 +02:00
|
|
|
/// Linkage for a reference to the event_sender column.
|
|
|
|
decltype(ircd::m::dbs::event_sender)
|
|
|
|
ircd::m::dbs::event_sender
|
|
|
|
{};
|
|
|
|
|
2019-04-16 22:42:18 +02:00
|
|
|
/// Linkage for a reference to the event_type column.
|
|
|
|
decltype(ircd::m::dbs::event_type)
|
|
|
|
ircd::m::dbs::event_type
|
|
|
|
{};
|
|
|
|
|
2018-05-05 04:47:39 +02:00
|
|
|
/// Linkage for a reference to the room_head column
|
|
|
|
decltype(ircd::m::dbs::room_head)
|
|
|
|
ircd::m::dbs::room_head
|
2018-02-08 22:23:01 +01:00
|
|
|
{};
|
|
|
|
|
|
|
|
/// Linkage for a reference to the room_events column
|
|
|
|
decltype(ircd::m::dbs::room_events)
|
|
|
|
ircd::m::dbs::room_events
|
|
|
|
{};
|
|
|
|
|
2018-04-15 23:40:10 +02:00
|
|
|
/// Linkage for a reference to the room_joined column
|
|
|
|
decltype(ircd::m::dbs::room_joined)
|
|
|
|
ircd::m::dbs::room_joined
|
2018-03-03 07:03:06 +01:00
|
|
|
{};
|
|
|
|
|
2018-03-04 08:39:24 +01:00
|
|
|
/// Linkage for a reference to the room_state column
|
|
|
|
decltype(ircd::m::dbs::room_state)
|
|
|
|
ircd::m::dbs::room_state
|
|
|
|
{};
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
/// Linkage for a reference to the room_state_space column
|
|
|
|
decltype(ircd::m::dbs::room_state_space)
|
|
|
|
ircd::m::dbs::room_state_space
|
2019-05-12 02:48:35 +02:00
|
|
|
{};
|
|
|
|
|
2018-09-15 10:12:47 +02:00
|
|
|
/// Coarse variable for enabling the uncompressed cache on the events database;
|
|
|
|
/// note this conf item is only effective by setting an environmental variable
|
|
|
|
/// before daemon startup. It has no effect in any other regard.
|
|
|
|
decltype(ircd::m::dbs::events_cache_enable)
|
|
|
|
ircd::m::dbs::events_cache_enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.__cache_enable" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Coarse variable for enabling the compressed cache on the events database;
|
|
|
|
/// note this conf item is only effective by setting an environmental variable
|
|
|
|
/// before daemon startup. It has no effect in any other regard.
|
|
|
|
decltype(ircd::m::dbs::events_cache_comp_enable)
|
|
|
|
ircd::m::dbs::events_cache_comp_enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.__cache_comp_enable" },
|
|
|
|
{ "default", false },
|
|
|
|
};
|
|
|
|
|
2018-12-17 21:47:39 +01:00
|
|
|
/// Value determines the size of writes when creating SST files (i.e during
|
|
|
|
/// compaction). Consider that write calls are yield-points for IRCd and the
|
|
|
|
/// time spent filling the write buffer between calls may hog the CPU doing
|
|
|
|
/// compression during that time etc. (writable_file_max_buffer_size)
|
|
|
|
decltype(ircd::m::dbs::events_sst_write_buffer_size)
|
|
|
|
ircd::m::dbs::events_sst_write_buffer_size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.sst.write_buffer_size" },
|
|
|
|
{ "default", long(1_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
static const auto key{"writable_file_max_buffer_size"_sv};
|
|
|
|
const size_t &value{events_sst_write_buffer_size};
|
|
|
|
if(events)
|
|
|
|
db::setopt(*events, key, lex_cast(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The size of the memory buffer for new writes to the DB (backed by the WAL
|
|
|
|
/// on disk). When this buffer is full it is flushed to sorted SST files on
|
|
|
|
/// disk. If this is 0, a per-column value can be used; otherwise this value
|
|
|
|
/// takes precedence as a total value for all columns. (db_write_buffer_size)
|
|
|
|
decltype(ircd::m::dbs::events_mem_write_buffer_size)
|
|
|
|
ircd::m::dbs::events_mem_write_buffer_size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.mem.write_buffer_size" },
|
|
|
|
{ "default", 0L },
|
|
|
|
};
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Initializes the m::dbs subsystem; sets up the events database. Held/called
|
|
|
|
/// by m::init. Most of the extern variables in m::dbs are not ready until
|
|
|
|
/// this call completes.
|
2019-06-07 02:34:33 +02:00
|
|
|
///
|
|
|
|
/// We also update the fs::basepath for the database directory to include our
|
|
|
|
/// servername in the path component. The fs::base::DB setting was generated
|
|
|
|
/// during the build and install process, and is unaware of our servername
|
|
|
|
/// at runtime. This change deconflicts multiple instances of IRCd running in
|
|
|
|
/// the same installation prefix using different servernames (i.e clustering
|
|
|
|
/// on the same machine).
|
|
|
|
///
|
|
|
|
ircd::m::dbs::init::init(const string_view &servername,
|
|
|
|
std::string dbopts)
|
|
|
|
:our_dbpath
|
2018-02-08 22:23:01 +01:00
|
|
|
{
|
2019-06-07 02:34:33 +02:00
|
|
|
ircd::string(fs::PATH_MAX_LEN | SHRINK_TO_FIT, [&servername]
|
|
|
|
(const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return fs::path(buf, fs::base::DB, servername);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
,their_dbpath
|
|
|
|
{
|
|
|
|
// NOTE that this is a global change that leaks outside of ircd::m. The
|
|
|
|
// database directory for the entire process is being changed here.
|
|
|
|
fs::basepath::set(fs::base::DB, our_dbpath)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Recall the db directory init manually with the now-updated basepath
|
|
|
|
db::init::directory();
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// Open the events database
|
2019-06-07 02:34:33 +02:00
|
|
|
static const string_view &dbname{"events"};
|
2018-04-09 21:56:43 +02:00
|
|
|
events = std::make_shared<database>(dbname, std::move(dbopts), desc::events);
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
// Cache the columns for the event tuple in order for constant time lookup
|
|
|
|
assert(event_columns == event::size());
|
|
|
|
std::array<string_view, event::size()> keys; //TODO: why did this happen?
|
|
|
|
_key_transform(event{}, begin(keys), end(keys)); //TODO: how did this happen?
|
2019-01-16 22:47:45 +01:00
|
|
|
|
|
|
|
// Construct global convenience references for the event property columns.
|
2018-02-08 22:23:01 +01:00
|
|
|
for(size_t i(0); i < keys.size(); ++i)
|
2019-02-13 02:50:44 +01:00
|
|
|
event_column.at(i) = db::column
|
2018-02-08 22:23:01 +01:00
|
|
|
{
|
2019-02-13 02:50:44 +01:00
|
|
|
*events, keys.at(i), std::nothrow
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2019-01-16 22:47:45 +01:00
|
|
|
// Construct global convenience references for the metadata columns
|
2018-04-18 04:14:39 +02:00
|
|
|
event_idx = db::column{*events, desc::events__event_idx.name};
|
2019-01-15 22:01:29 +01:00
|
|
|
event_json = db::column{*events, desc::events__event_json.name};
|
2019-06-11 21:55:14 +02:00
|
|
|
event_refs = db::domain{*events, desc::events__event_refs.name};
|
|
|
|
event_horizon = db::domain{*events, desc::events__event_horizon.name};
|
|
|
|
event_sender = db::domain{*events, desc::events__event_sender.name};
|
|
|
|
event_type = db::domain{*events, desc::events__event_type.name};
|
|
|
|
room_head = db::domain{*events, desc::events__room_head.name};
|
|
|
|
room_events = db::domain{*events, desc::events__room_events.name};
|
|
|
|
room_joined = db::domain{*events, desc::events__room_joined.name};
|
|
|
|
room_state = db::domain{*events, desc::events__room_state.name};
|
|
|
|
room_state_space = db::domain{*events, desc::events__room_state_space.name};
|
2018-02-08 22:23:01 +01:00
|
|
|
}
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Shuts down the m::dbs subsystem; closes the events database. The extern
|
|
|
|
/// variables in m::dbs will no longer be functioning after this call.
|
|
|
|
ircd::m::dbs::init::~init()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
// Unref DB (should close)
|
|
|
|
events = {};
|
2019-06-07 02:34:33 +02:00
|
|
|
|
|
|
|
// restore the fs::base::DB path the way we found it.
|
|
|
|
fs::basepath::set(fs::base::DB, their_dbpath);
|
2018-02-08 22:23:01 +01:00
|
|
|
}
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
//
|
|
|
|
// write_opts
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::write_opts::event_refs_all)
|
2019-05-07 22:40:23 +02:00
|
|
|
ircd::m::dbs::write_opts::event_refs_all{[]
|
|
|
|
{
|
|
|
|
char full[event_refs_all.size()];
|
2019-02-14 22:11:37 +01:00
|
|
|
memset(full, '1', sizeof(full));
|
2019-05-07 22:40:23 +02:00
|
|
|
return decltype(event_refs_all)
|
|
|
|
{
|
|
|
|
full, sizeof(full)
|
|
|
|
};
|
2019-02-14 22:11:37 +01:00
|
|
|
}()};
|
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
decltype(ircd::m::dbs::write_opts::appendix_all)
|
|
|
|
ircd::m::dbs::write_opts::appendix_all{[]
|
|
|
|
{
|
|
|
|
char full[appendix_all.size()];
|
|
|
|
memset(full, '1', sizeof(full));
|
|
|
|
return decltype(appendix_all)
|
|
|
|
{
|
|
|
|
full, sizeof(full)
|
|
|
|
};
|
|
|
|
}()};
|
|
|
|
|
2018-05-06 03:54:02 +02:00
|
|
|
//
|
|
|
|
// Basic write suite
|
|
|
|
//
|
2018-01-28 17:45:09 +01:00
|
|
|
|
2019-05-11 23:30:15 +02:00
|
|
|
namespace ircd::m::dbs
|
|
|
|
{
|
2019-05-15 06:34:29 +02:00
|
|
|
static void _index_room_joined(db::txn &, const event &, const write_opts &);
|
2019-08-15 09:27:05 +02:00
|
|
|
static void _index_room_redact(db::txn &, const event &, const write_opts &); //query
|
2019-05-15 06:34:29 +02:00
|
|
|
static void _index_room_state_space(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_room_state(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_room_head_resolve(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_room_head(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_room_events(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_room(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event_type(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event_sender(db::txn &, const event &, const write_opts &);
|
2019-08-15 09:27:05 +02:00
|
|
|
static void _index_event_horizon_resolve(db::txn &, const event &, const write_opts &); //query
|
2019-05-15 06:34:29 +02:00
|
|
|
static void _index_event_horizon(db::txn &, const event &, const write_opts &, const id::event &);
|
2019-08-15 09:27:05 +02:00
|
|
|
static void _index_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &); //query
|
|
|
|
static void _index_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &); //query
|
|
|
|
static void _index_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &); //query
|
|
|
|
static void _index_event_refs_m_relates(db::txn &, const event &, const write_opts &); //query
|
|
|
|
static void _index_event_refs_state(db::txn &, const event &, const write_opts &); // query
|
|
|
|
static void _index_event_refs_auth(db::txn &, const event &, const write_opts &); //query
|
|
|
|
static void _index_event_refs_prev(db::txn &, const event &, const write_opts &); //query
|
2019-05-15 06:34:29 +02:00
|
|
|
static void _index_event_refs(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event_json(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event_cols(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event_id(db::txn &, const event &, const write_opts &);
|
|
|
|
static void _index_event(db::txn &, const event &, const write_opts &);
|
|
|
|
|
2019-05-11 23:30:15 +02:00
|
|
|
static void blacklist(db::txn &txn, const event::id &, const write_opts &);
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
void
|
2019-05-11 23:30:15 +02:00
|
|
|
ircd::m::dbs::write(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-05-13 21:46:38 +02:00
|
|
|
try
|
2019-05-11 23:30:15 +02:00
|
|
|
{
|
|
|
|
if(opts.event_idx == 0 && opts.blacklist)
|
2019-07-06 07:58:12 +02:00
|
|
|
return blacklist(txn, event.event_id, opts);
|
2019-05-11 23:30:15 +02:00
|
|
|
|
|
|
|
if(unlikely(opts.event_idx == 0))
|
|
|
|
throw panic
|
|
|
|
{
|
|
|
|
"Cannot write to database: no index specified for event."
|
|
|
|
};
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
_index_event(txn, event, opts);
|
|
|
|
if(json::get<"room_id"_>(event))
|
|
|
|
_index_room(txn, event, opts);
|
2019-05-11 23:30:15 +02:00
|
|
|
}
|
2019-05-13 21:46:38 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "Event %s txn building error :%s",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-05-13 21:46:38 +02:00
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2019-05-11 23:30:15 +02:00
|
|
|
|
2018-05-05 00:14:19 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::blacklist(db::txn &txn,
|
|
|
|
const event::id &event_id,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2018-11-03 03:11:52 +01:00
|
|
|
// An entry in the event_idx column with a value 0 is blacklisting
|
|
|
|
// because 0 is not a valid event_idx. Thus a value here can only
|
|
|
|
// have the value zero.
|
|
|
|
assert(opts.event_idx == 0);
|
|
|
|
assert(!event_id.empty());
|
|
|
|
|
|
|
|
static const m::event::idx &zero_idx{0UL};
|
|
|
|
static const byte_view<string_view> zero_value
|
|
|
|
{
|
|
|
|
zero_idx
|
|
|
|
};
|
|
|
|
|
2018-05-05 00:14:19 +02:00
|
|
|
db::txn::append
|
|
|
|
{
|
2018-11-03 03:11:52 +01:00
|
|
|
txn, event_idx,
|
2018-05-05 00:14:19 +02:00
|
|
|
{
|
|
|
|
opts.op,
|
|
|
|
string_view{event_id},
|
2018-11-03 03:11:52 +01:00
|
|
|
zero_value
|
2018-05-05 00:14:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-06 03:54:02 +02:00
|
|
|
//
|
|
|
|
// Internal interface
|
|
|
|
//
|
|
|
|
|
2019-05-10 04:03:30 +02:00
|
|
|
namespace ircd::m::dbs
|
|
|
|
{
|
|
|
|
static event::idx find_event_idx(const event::id &, const write_opts &);
|
|
|
|
}
|
|
|
|
|
2018-05-18 08:47:05 +02:00
|
|
|
void
|
2019-05-07 23:37:06 +02:00
|
|
|
ircd::m::dbs::_index_event(db::txn &txn,
|
2019-01-24 20:26:31 +01:00
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-01-23 23:39:04 +01:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_ID))
|
|
|
|
_index_event_id(txn, event, opts);
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_COLS))
|
|
|
|
_index_event_cols(txn, event, opts);
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_JSON))
|
|
|
|
_index_event_json(txn, event, opts);
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_SENDER))
|
|
|
|
_index_event_sender(txn, event, opts);
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_TYPE))
|
|
|
|
_index_event_type(txn, event, opts);
|
2019-06-05 05:43:23 +02:00
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_REFS) && opts.event_refs.any())
|
|
|
|
_index_event_refs(txn, event, opts);
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON_RESOLVE) && opts.horizon_resolve.any())
|
|
|
|
_index_event_horizon_resolve(txn, event, opts);
|
2019-05-07 23:37:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_id(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
|
|
|
assert(opts.appendix.test(appendix::EVENT_ID));
|
|
|
|
assert(opts.event_idx);
|
2019-07-06 07:58:12 +02:00
|
|
|
assert(event.event_id);
|
2019-05-07 23:37:06 +02:00
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_idx,
|
|
|
|
{
|
|
|
|
opts.op,
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-05-07 23:37:06 +02:00
|
|
|
byte_view<string_view>(opts.event_idx)
|
|
|
|
}
|
|
|
|
};
|
2019-07-10 09:01:25 +02:00
|
|
|
|
|
|
|
// For a v1 event, the "event_id" property will be saved into the `event_id`
|
|
|
|
// column by the direct property->column indexer.
|
|
|
|
if(json::get<"event_id"_>(event))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// For v3+ events, the direct column indexer won't see any "event_id"
|
|
|
|
// property. In this case we insert the `event.event_id` manually into
|
|
|
|
// that column here.
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, event_column.at(json::indexof<m::event, "event_id"_>()),
|
|
|
|
{
|
|
|
|
opts.op,
|
|
|
|
byte_view<string_view>(opts.event_idx),
|
|
|
|
string_view{event.event_id},
|
|
|
|
}
|
|
|
|
};
|
2019-05-07 23:37:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_cols(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
|
|
|
assert(opts.appendix.test(appendix::EVENT_COLS));
|
|
|
|
assert(opts.event_idx);
|
2019-01-24 00:05:12 +01:00
|
|
|
const byte_view<string_view> key
|
2019-01-23 23:39:04 +01:00
|
|
|
{
|
2019-01-24 00:05:12 +01:00
|
|
|
opts.event_idx
|
2019-01-23 23:39:04 +01:00
|
|
|
};
|
2019-01-24 00:05:12 +01:00
|
|
|
|
|
|
|
size_t i{0};
|
|
|
|
for_each(event, [&txn, &opts, &key, &i]
|
|
|
|
(const auto &, auto&& val)
|
|
|
|
{
|
|
|
|
auto &column
|
|
|
|
{
|
|
|
|
event_column.at(i++)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!column)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(value_required(opts.op) && !defined(json::value(val)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, column, db::column::delta
|
|
|
|
{
|
|
|
|
opts.op,
|
|
|
|
string_view{key},
|
|
|
|
value_required(opts.op)?
|
|
|
|
byte_view<string_view>{val}:
|
|
|
|
byte_view<string_view>{}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2019-01-23 23:39:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-07 23:37:06 +02:00
|
|
|
ircd::m::dbs::_index_event_json(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-01-15 22:01:29 +01:00
|
|
|
{
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
thread_local char buf[m::event::MAX_SIZE];
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_JSON));
|
|
|
|
assert(opts.event_idx);
|
2019-01-15 22:01:29 +01:00
|
|
|
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
byte_view<string_view>(opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &val
|
|
|
|
{
|
2019-01-16 23:36:08 +01:00
|
|
|
// If an already-strung json::object is carried by the event and
|
|
|
|
// the opts allow us, we use it directly. This is not the default
|
|
|
|
// path unless the developer knows the source JSON is good enough
|
|
|
|
// to store directly.
|
|
|
|
opts.op == db::op::SET && event.source && opts.json_source?
|
|
|
|
string_view{event.source}:
|
|
|
|
|
|
|
|
// If an already-strung json::object is carried by the event we
|
|
|
|
// re-stringify it into a temporary buffer. This is the common case
|
|
|
|
// because the original source might be crap JSON w/ spaces etc.
|
|
|
|
opts.op == db::op::SET && event.source?
|
|
|
|
json::stringify(mutable_buffer{buf}, event.source):
|
|
|
|
|
2019-01-24 20:26:31 +01:00
|
|
|
// If no source was given with the event we can generate it.
|
|
|
|
opts.op == db::op::SET?
|
2019-01-16 23:36:08 +01:00
|
|
|
json::stringify(mutable_buffer{buf}, event):
|
|
|
|
|
|
|
|
// Empty value; generally for a non-SET db::op
|
|
|
|
string_view{}
|
2019-01-15 22:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, event_json,
|
|
|
|
{
|
|
|
|
opts.op, // db::op
|
|
|
|
key, // key
|
|
|
|
val, // val
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-06 04:04:13 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
|
|
|
|
2019-05-10 07:43:28 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::NEXT)))
|
2019-02-14 22:11:37 +01:00
|
|
|
_index_event_refs_prev(txn, event, opts);
|
|
|
|
|
2019-05-10 07:43:28 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::NEXT_AUTH)))
|
2019-02-14 22:11:37 +01:00
|
|
|
_index_event_refs_auth(txn, event, opts);
|
|
|
|
|
2019-05-10 07:43:28 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::NEXT_STATE)) ||
|
2019-03-11 22:44:43 +01:00
|
|
|
opts.event_refs.test(uint(ref::PREV_STATE)))
|
2019-03-11 21:38:54 +01:00
|
|
|
_index_event_refs_state(txn, event, opts);
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
if(opts.event_refs.test(uint(ref::M_RECEIPT__M_READ)))
|
|
|
|
_index_event_refs_m_receipt_m_read(txn, event, opts);
|
|
|
|
|
2019-06-22 01:33:45 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::M_RELATES)))
|
|
|
|
_index_event_refs_m_relates(txn, event, opts);
|
|
|
|
|
2019-06-22 01:32:15 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::M_RELATES)))
|
2019-02-14 22:11:37 +01:00
|
|
|
_index_event_refs_m_relates_m_reply(txn, event, opts);
|
2019-03-10 22:52:11 +01:00
|
|
|
|
|
|
|
if(opts.event_refs.test(uint(ref::M_ROOM_REDACTION)))
|
|
|
|
_index_event_refs_m_room_redaction(txn, event, opts);
|
2019-02-14 22:11:37 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-02-14 22:11:37 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_prev(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-05-10 07:43:28 +02:00
|
|
|
assert(opts.event_refs.test(uint(ref::NEXT)));
|
2019-02-14 22:11:37 +01:00
|
|
|
|
2019-06-23 01:12:14 +02:00
|
|
|
const event::prev prev{event};
|
2019-02-06 04:04:13 +01:00
|
|
|
for(size_t i(0); i < prev.prev_events_count(); ++i)
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
const event::id &prev_id
|
|
|
|
{
|
|
|
|
prev.prev_event(i)
|
|
|
|
};
|
|
|
|
|
2019-02-06 04:04:13 +01:00
|
|
|
const event::idx &prev_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
find_event_idx(prev_id, opts)
|
2019-02-06 04:04:13 +01:00
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON) && !prev_idx)
|
|
|
|
{
|
|
|
|
_index_event_horizon(txn, event, opts, prev_id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if(!prev_idx)
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
2019-08-12 09:31:51 +02:00
|
|
|
log::dwarning
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
|
|
|
log, "No index found to ref %s PREV of %s",
|
|
|
|
string_view{prev_id},
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-03-28 23:00:16 +01:00
|
|
|
};
|
|
|
|
|
2019-02-06 04:04:13 +01:00
|
|
|
continue;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-06 04:04:13 +01:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && prev_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != prev_idx);
|
2019-02-06 04:04:13 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-05-10 07:43:28 +02:00
|
|
|
event_refs_key(buf, prev_idx, ref::NEXT, opts.event_idx)
|
2019-02-06 04:04:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-02-06 04:04:13 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-02-08 11:49:13 +01:00
|
|
|
void
|
2019-02-14 22:11:37 +01:00
|
|
|
ircd::m::dbs::_index_event_refs_auth(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-02-08 11:49:13 +01:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-05-10 07:43:28 +02:00
|
|
|
assert(opts.event_refs.test(uint(ref::NEXT_AUTH)));
|
2019-02-14 22:11:37 +01:00
|
|
|
if(!event::auth::is_power_event(event))
|
|
|
|
return;
|
2019-02-08 11:49:13 +01:00
|
|
|
|
2019-06-23 01:12:14 +02:00
|
|
|
const event::prev prev{event};
|
2019-02-08 11:49:13 +01:00
|
|
|
for(size_t i(0); i < prev.auth_events_count(); ++i)
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
const event::id &auth_id
|
|
|
|
{
|
|
|
|
prev.auth_event(i)
|
|
|
|
};
|
|
|
|
|
2019-02-08 11:49:13 +01:00
|
|
|
const event::idx &auth_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
find_event_idx(auth_id, opts)
|
2019-02-08 11:49:13 +01:00
|
|
|
};
|
|
|
|
|
2019-03-28 23:00:16 +01:00
|
|
|
if(unlikely(!auth_idx))
|
|
|
|
{
|
2019-05-09 09:02:33 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON))
|
|
|
|
_index_event_horizon(txn, event, opts, auth_id);
|
|
|
|
|
2019-03-28 23:00:16 +01:00
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "No index found to ref %s AUTH of %s",
|
|
|
|
string_view{auth_id},
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id}
|
2019-03-28 23:00:16 +01:00
|
|
|
};
|
|
|
|
|
2019-02-08 11:49:13 +01:00
|
|
|
continue;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-08 11:49:13 +01:00
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
2019-02-08 11:49:13 +01:00
|
|
|
assert(opts.event_idx != 0 && auth_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != auth_idx);
|
2019-02-08 11:49:13 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-05-10 07:43:28 +02:00
|
|
|
event_refs_key(buf, auth_idx, ref::NEXT_AUTH, opts.event_idx)
|
2019-02-08 11:49:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
txn, dbs::event_refs,
|
2019-02-08 11:49:13 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-02-08 11:49:13 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-03-11 21:38:54 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_state(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-05-10 07:43:28 +02:00
|
|
|
assert(opts.event_refs.test(uint(ref::NEXT_STATE)) ||
|
2019-03-11 22:44:43 +01:00
|
|
|
opts.event_refs.test(uint(ref::PREV_STATE)));
|
2019-03-11 21:38:54 +01:00
|
|
|
|
|
|
|
if(!json::get<"room_id"_>(event))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!json::get<"state_key"_>(event))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
at<"room_id"_>(event) //TODO: ABA ABA ABA ABA
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::state state
|
|
|
|
{
|
|
|
|
room
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx &prev_state_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
opts.allow_queries?
|
|
|
|
state.get(std::nothrow, at<"type"_>(event), at<"state_key"_>(event)): // query
|
|
|
|
0UL
|
2019-03-11 21:38:54 +01:00
|
|
|
};
|
|
|
|
|
2019-05-10 07:24:48 +02:00
|
|
|
// No previous state; nothing to do.
|
2019-05-09 09:02:33 +02:00
|
|
|
if(!prev_state_idx)
|
|
|
|
return;
|
|
|
|
|
2019-05-10 07:24:48 +02:00
|
|
|
// If the previous state's event_idx is greater than the event_idx of the
|
|
|
|
// event we're transacting this is almost surely a replay/rewrite. Bail
|
|
|
|
// out for now rather than corrupting the graph.
|
|
|
|
if(unlikely(prev_state_idx >= opts.event_idx))
|
2019-03-11 21:38:54 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && prev_state_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != prev_state_idx);
|
2019-03-11 22:44:43 +01:00
|
|
|
|
2019-05-10 07:43:28 +02:00
|
|
|
if(opts.event_refs.test(uint(ref::NEXT_STATE)))
|
2019-03-11 21:38:54 +01:00
|
|
|
{
|
2019-03-11 22:44:43 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-05-10 07:43:28 +02:00
|
|
|
event_refs_key(buf, prev_state_idx, ref::NEXT_STATE, opts.event_idx)
|
2019-03-11 22:44:43 +01:00
|
|
|
};
|
2019-03-11 21:38:54 +01:00
|
|
|
|
2019-03-11 22:44:43 +01:00
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-03-11 22:44:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opts.event_refs.test(uint(ref::PREV_STATE)))
|
2019-03-11 21:38:54 +01:00
|
|
|
{
|
2019-03-11 22:44:43 +01:00
|
|
|
const string_view &key
|
2019-03-11 21:38:54 +01:00
|
|
|
{
|
2019-03-11 22:44:43 +01:00
|
|
|
event_refs_key(buf, opts.event_idx, ref::PREV_STATE, prev_state_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-03-11 22:44:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-03-11 21:38:54 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-02-14 22:11:37 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_m_receipt_m_read(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-02-14 22:11:37 +01:00
|
|
|
assert(opts.event_refs.test(uint(ref::M_RECEIPT__M_READ)));
|
|
|
|
|
|
|
|
if(json::get<"type"_>(event) != "ircd.read")
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!my_host(json::get<"origin"_>(event)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//TODO: disallow local forge?
|
|
|
|
|
2019-03-28 23:00:16 +01:00
|
|
|
const json::string &event_id
|
2019-02-14 22:11:37 +01:00
|
|
|
{
|
2019-03-28 23:00:16 +01:00
|
|
|
json::get<"content"_>(event).get("event_id")
|
2019-02-14 22:11:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx &event_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
find_event_idx(event_id, opts)
|
2019-02-14 22:11:37 +01:00
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON) && !event_idx)
|
|
|
|
{
|
|
|
|
_index_event_horizon(txn, event, opts, event_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(!event_idx)
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
2019-08-12 09:31:51 +02:00
|
|
|
log::dwarning
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
|
|
|
log, "No index found to ref %s M_RECEIPT__M_READ of %s",
|
|
|
|
string_view{event_id},
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id}
|
2019-03-28 23:00:16 +01:00
|
|
|
};
|
2019-05-09 09:02:33 +02:00
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
return;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && event_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != event_idx);
|
2019-02-14 22:11:37 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_refs_key(buf, event_idx, ref::M_RECEIPT__M_READ, opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-02-14 22:11:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-06-22 01:33:45 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_m_relates(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
|
|
|
assert(opts.event_refs.test(uint(ref::M_RELATES)));
|
|
|
|
|
|
|
|
if(!json::get<"content"_>(event).has("m.relates_to"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(json::type(json::get<"content"_>(event).get("m.relates_to")) != json::OBJECT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const json::object &m_relates_to
|
|
|
|
{
|
|
|
|
json::get<"content"_>(event).get("m.relates_to")
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &event_id
|
|
|
|
{
|
|
|
|
m_relates_to.get("event_id")
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!event_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!valid(m::id::EVENT, event_id))
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "Cannot index m.relates_to in %s; '%s' is not an event_id.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-06-22 01:33:45 +02:00
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const event::idx &event_idx
|
|
|
|
{
|
|
|
|
find_event_idx(event_id, opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON) && !event_idx)
|
|
|
|
{
|
|
|
|
// If we don't have the event being related to yet, place a marker in
|
|
|
|
// the event_horizon indicating need for re-evaluation later.
|
|
|
|
_index_event_horizon(txn, event, opts, event_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(!event_idx)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "Cannot index m.relates_to in %s; referenced %s not found.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-06-22 01:33:45 +02:00
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && event_idx != 0);
|
|
|
|
assert(opts.event_idx != event_idx);
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_refs_key(buf, event_idx, ref::M_RELATES, opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
|
|
|
opts.op, key
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-02-14 22:11:37 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_m_relates_m_reply(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-06-22 01:32:15 +02:00
|
|
|
assert(opts.event_refs.test(uint(ref::M_RELATES)));
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
if(json::get<"type"_>(event) != "m.room.message")
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!json::get<"content"_>(event).has("m.relates_to"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(json::type(json::get<"content"_>(event).get("m.relates_to")) != json::OBJECT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const json::object &m_relates_to
|
|
|
|
{
|
|
|
|
json::get<"content"_>(event).get("m.relates_to")
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!m_relates_to.has("m.in_reply_to"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(json::type(m_relates_to.get("m.in_reply_to")) != json::OBJECT)
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "Cannot index m.in_reply_to in %s; not an OBJECT.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id}
|
2019-03-28 23:00:16 +01:00
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
return;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
const json::object &m_in_reply_to
|
|
|
|
{
|
|
|
|
m_relates_to.get("m.in_reply_to")
|
|
|
|
};
|
|
|
|
|
2019-03-28 23:00:16 +01:00
|
|
|
const json::string &event_id
|
2019-02-14 22:11:37 +01:00
|
|
|
{
|
2019-03-28 23:00:16 +01:00
|
|
|
m_in_reply_to.get("event_id")
|
2019-02-14 22:11:37 +01:00
|
|
|
};
|
|
|
|
|
2019-05-27 07:51:39 +02:00
|
|
|
if(!valid(m::id::EVENT, event_id))
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "Cannot index m.in_reply_to in %s; '%s' is not an event_id.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-03-28 23:00:16 +01:00
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
return;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
const event::idx &event_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
find_event_idx(event_id, opts)
|
2019-02-14 22:11:37 +01:00
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON) && !event_idx)
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
2019-05-09 09:02:33 +02:00
|
|
|
_index_event_horizon(txn, event, opts, event_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(!event_idx)
|
|
|
|
{
|
2019-08-12 09:31:51 +02:00
|
|
|
log::dwarning
|
2019-03-28 23:00:16 +01:00
|
|
|
{
|
|
|
|
log, "Cannot index m.in_reply_to in %s; referenced %s not found.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-03-28 23:00:16 +01:00
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
return;
|
2019-03-28 23:00:16 +01:00
|
|
|
}
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && event_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != event_idx);
|
2019-02-14 22:11:37 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-06-22 01:32:15 +02:00
|
|
|
event_refs_key(buf, event_idx, ref::M_RELATES, opts.event_idx)
|
2019-02-14 22:11:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-02-14 22:11:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-03-10 22:52:11 +01:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_refs_m_room_redaction(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_REFS));
|
2019-03-10 22:52:11 +01:00
|
|
|
assert(opts.event_refs.test(uint(ref::M_ROOM_REDACTION)));
|
|
|
|
|
|
|
|
if(json::get<"type"_>(event) != "m.room.redaction")
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!valid(m::id::EVENT, json::get<"redacts"_>(event)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto &event_id
|
|
|
|
{
|
|
|
|
json::get<"redacts"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx &event_idx
|
|
|
|
{
|
2019-05-10 04:03:30 +02:00
|
|
|
find_event_idx(event_id, opts)
|
2019-03-10 22:52:11 +01:00
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON) && !event_idx)
|
|
|
|
{
|
|
|
|
_index_event_horizon(txn, event, opts, event_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(!event_idx)
|
|
|
|
{
|
2019-08-12 09:31:51 +02:00
|
|
|
log::dwarning
|
2019-05-09 09:02:33 +02:00
|
|
|
{
|
|
|
|
log, "Cannot index m.room.redaction in %s; referenced %s not found.",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-05-09 09:02:33 +02:00
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
2019-03-10 22:52:11 +01:00
|
|
|
return;
|
2019-05-09 09:02:33 +02:00
|
|
|
}
|
2019-03-10 22:52:11 +01:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_REFS_KEY_MAX_SIZE];
|
|
|
|
assert(opts.event_idx != 0 && event_idx != 0);
|
2019-05-07 21:35:58 +02:00
|
|
|
assert(opts.event_idx != event_idx);
|
2019-03-10 22:52:11 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_refs_key(buf, event_idx, ref::M_ROOM_REDACTION, opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_refs,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-03-10 22:52:11 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_horizon(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts,
|
|
|
|
const m::event::id &unresolved_id)
|
|
|
|
{
|
|
|
|
thread_local char buf[EVENT_HORIZON_KEY_MAX_SIZE];
|
2019-05-09 15:47:49 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_HORIZON));
|
2019-05-09 09:02:33 +02:00
|
|
|
assert(opts.event_idx != 0 && unresolved_id);
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_horizon_key(buf, unresolved_id, opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_horizon,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-05-09 09:02:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-05-09 15:47:49 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_horizon_resolve(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-24 06:43:30 +02:00
|
|
|
char buf[EVENT_HORIZON_KEY_MAX_SIZE];
|
2019-05-09 15:47:49 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_HORIZON_RESOLVE));
|
|
|
|
assert(opts.event_idx != 0);
|
2019-07-06 07:58:12 +02:00
|
|
|
assert(event.event_id);
|
2019-05-09 15:47:49 +02:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-07-06 07:58:12 +02:00
|
|
|
event_horizon_key(buf, event.event_id)
|
2019-05-09 15:47:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
auto it
|
|
|
|
{
|
|
|
|
dbs::event_horizon.begin(key)
|
|
|
|
};
|
|
|
|
|
|
|
|
for(; it; ++it)
|
|
|
|
{
|
|
|
|
const auto parts
|
|
|
|
{
|
|
|
|
event_horizon_key(it->first)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &event_idx
|
|
|
|
{
|
|
|
|
std::get<0>(parts)
|
|
|
|
};
|
|
|
|
|
2019-05-17 10:36:38 +02:00
|
|
|
assert(event_idx != 0);
|
2019-05-09 15:47:49 +02:00
|
|
|
assert(event_idx != opts.event_idx);
|
|
|
|
const event::fetch _event
|
|
|
|
{
|
|
|
|
event_idx, std::nothrow
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!_event.valid)
|
2019-07-18 01:09:11 +02:00
|
|
|
{
|
|
|
|
log::dwarning
|
|
|
|
{
|
|
|
|
log, "Horizon resolve for %s @%lu not possible @%lu",
|
|
|
|
string_view{event.event_id},
|
|
|
|
opts.event_idx,
|
|
|
|
event_idx,
|
|
|
|
};
|
|
|
|
|
2019-05-09 15:47:49 +02:00
|
|
|
continue;
|
2019-07-18 01:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
log, "Horizon resolve for %s @%lu; remisé %s @%lu",
|
|
|
|
string_view{event.event_id},
|
|
|
|
opts.event_idx,
|
|
|
|
string_view{_event.event_id},
|
|
|
|
event_idx,
|
|
|
|
};
|
2019-05-09 15:47:49 +02:00
|
|
|
|
|
|
|
// Make the references on behalf of the future event
|
|
|
|
write_opts _opts;
|
|
|
|
_opts.op = opts.op;
|
|
|
|
_opts.event_idx = event_idx;
|
|
|
|
_opts.appendix.reset();
|
|
|
|
_opts.appendix.set(appendix::EVENT_REFS);
|
2019-08-12 09:43:18 +02:00
|
|
|
_opts.appendix.set(appendix::ROOM_REDACT);
|
2019-05-09 15:47:49 +02:00
|
|
|
_opts.event_refs = opts.horizon_resolve;
|
2019-05-10 04:02:06 +02:00
|
|
|
_opts.interpose = &txn;
|
2019-05-09 15:47:49 +02:00
|
|
|
write(txn, _event, _opts);
|
|
|
|
|
|
|
|
// Delete the event_horizon entry after resolving.
|
|
|
|
thread_local char buf[EVENT_HORIZON_KEY_MAX_SIZE];
|
|
|
|
const string_view &key
|
|
|
|
{
|
2019-07-06 07:58:12 +02:00
|
|
|
event_horizon_key(buf, event.event_id, event_idx)
|
2019-05-09 15:47:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_horizon,
|
|
|
|
{
|
|
|
|
opts.op == db::op::SET?
|
|
|
|
db::op::DELETE:
|
|
|
|
db::op::SET,
|
|
|
|
key
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 22:41:55 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_sender(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_SENDER));
|
2019-04-16 22:41:55 +02:00
|
|
|
assert(json::get<"sender"_>(event));
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.event_idx);
|
2019-04-16 22:41:55 +02:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_SENDER_KEY_MAX_SIZE];
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_sender_key(buf, at<"sender"_>(event), opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_sender,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-04-16 22:41:55 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-16 22:42:18 +02:00
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_event_type(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::EVENT_TYPE));
|
2019-04-16 22:42:18 +02:00
|
|
|
assert(json::get<"type"_>(event));
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.event_idx);
|
2019-04-16 22:42:18 +02:00
|
|
|
|
|
|
|
thread_local char buf[EVENT_TYPE_KEY_MAX_SIZE];
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
event_type_key(buf, at<"type"_>(event), opts.event_idx)
|
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, dbs::event_type,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, key
|
2019-04-16 22:42:18 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
void
|
2019-01-15 22:00:15 +01:00
|
|
|
ircd::m::dbs::_index_room(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(!empty(json::get<"room_id"_>(event)));
|
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::ROOM_EVENTS))
|
|
|
|
_index_room_events(txn, event, opts);
|
2019-05-07 23:37:06 +02:00
|
|
|
|
|
|
|
if(opts.appendix.test(appendix::ROOM_HEAD))
|
2019-05-13 21:12:23 +02:00
|
|
|
_index_room_head(txn, event, opts);
|
2019-01-15 22:00:15 +01:00
|
|
|
|
2019-05-12 00:20:58 +02:00
|
|
|
if(opts.appendix.test(appendix::ROOM_HEAD_RESOLVE))
|
2019-05-13 21:12:23 +02:00
|
|
|
_index_room_head_resolve(txn, event, opts);
|
2019-05-07 23:37:06 +02:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
if(defined(json::get<"state_key"_>(event)))
|
2019-02-18 22:08:11 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
if(opts.appendix.test(appendix::ROOM_STATE))
|
|
|
|
_index_room_state(txn, event, opts);
|
2019-02-18 22:08:11 +01:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
if(opts.appendix.test(appendix::ROOM_STATE_SPACE))
|
|
|
|
_index_room_state_space(txn, event, opts);
|
2019-05-07 23:37:06 +02:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
if(opts.appendix.test(appendix::ROOM_JOINED) && at<"type"_>(event) == "m.room.member")
|
|
|
|
_index_room_joined(txn, event, opts);
|
|
|
|
}
|
2019-02-18 22:08:11 +01:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
if(opts.appendix.test(appendix::ROOM_REDACT) && json::get<"type"_>(event) == "m.room.redaction")
|
|
|
|
_index_room_redact(txn, event, opts);
|
2018-02-08 22:23:01 +01:00
|
|
|
}
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
/// Adds the entry for the room_events column into the txn.
|
|
|
|
void
|
|
|
|
ircd::m::dbs::_index_room_events(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2018-02-28 07:42:25 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_EVENTS));
|
2018-02-28 07:42:25 +01:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
thread_local char buf[ROOM_EVENTS_KEY_MAX_SIZE];
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
const string_view &key
|
2018-02-28 07:42:25 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
room_events_key(buf, at<"room_id"_>(event), at<"depth"_>(event), opts.event_idx)
|
2019-02-18 22:08:11 +01:00
|
|
|
};
|
2018-02-28 07:42:25 +01:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
db::txn::append
|
2018-02-28 07:42:25 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
txn, room_events,
|
2019-05-07 23:37:06 +02:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op, // db::op
|
|
|
|
key, // key,
|
2019-05-07 23:37:06 +02:00
|
|
|
}
|
2018-02-28 07:42:25 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
2018-05-05 05:10:35 +02:00
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_head(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_HEAD));
|
|
|
|
assert(opts.event_idx);
|
2019-07-06 07:58:12 +02:00
|
|
|
assert(event.event_id);
|
2018-05-05 05:10:35 +02:00
|
|
|
|
2019-07-06 07:58:12 +02:00
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
thread_local char buf[ROOM_HEAD_KEY_MAX_SIZE];
|
2019-05-07 23:37:06 +02:00
|
|
|
const string_view &key
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-07-06 07:58:12 +02:00
|
|
|
room_head_key(buf, at<"room_id"_>(event), event.event_id)
|
2019-05-07 23:37:06 +02:00
|
|
|
};
|
2018-05-05 05:10:35 +02:00
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, room_head,
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
opts.op,
|
|
|
|
key,
|
|
|
|
byte_view<string_view>{opts.event_idx}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_head_resolve(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-05-07 23:37:06 +02:00
|
|
|
{
|
2019-05-12 00:20:58 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_HEAD_RESOLVE));
|
2018-05-05 05:10:35 +02:00
|
|
|
|
|
|
|
//TODO: If op is DELETE and we are deleting this event and thereby
|
|
|
|
//TODO: potentially creating a gap in the reference graph (just for us
|
|
|
|
//TODO: though) can we *re-add* the prev_events to the head?
|
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
if(opts.op != db::op::SET)
|
|
|
|
return;
|
|
|
|
|
2019-06-23 01:12:14 +02:00
|
|
|
const event::prev prev{event};
|
2019-07-10 12:02:00 +02:00
|
|
|
for(size_t i(0); i < prev.prev_events_count(); ++i)
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
const auto &event_id
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-07-10 12:02:00 +02:00
|
|
|
prev.prev_event(i)
|
2019-05-07 23:37:06 +02:00
|
|
|
};
|
2018-05-05 05:10:35 +02:00
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
thread_local char buf[ROOM_HEAD_KEY_MAX_SIZE];
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
const string_view &key
|
|
|
|
{
|
|
|
|
room_head_key(buf, at<"room_id"_>(event), event_id)
|
|
|
|
};
|
2018-05-05 05:10:35 +02:00
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, room_head,
|
2018-05-05 05:10:35 +02:00
|
|
|
{
|
2019-05-07 23:37:06 +02:00
|
|
|
db::op::DELETE,
|
|
|
|
key,
|
|
|
|
}
|
|
|
|
};
|
2018-05-05 05:10:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_state(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_STATE));
|
2019-05-07 23:37:06 +02:00
|
|
|
|
|
|
|
const ctx::critical_assertion ca;
|
2019-05-13 21:12:23 +02:00
|
|
|
thread_local char buf[ROOM_STATE_KEY_MAX_SIZE];
|
2018-02-08 22:23:01 +01:00
|
|
|
const string_view &key
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
room_state_key(buf, at<"room_id"_>(event), at<"type"_>(event), at<"state_key"_>(event))
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view val
|
|
|
|
{
|
|
|
|
byte_view<string_view>(opts.event_idx)
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
db::txn::append
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
txn, room_state,
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op,
|
|
|
|
key,
|
|
|
|
value_required(opts.op)? val : string_view{},
|
2018-03-03 07:03:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_state_space(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2018-03-03 07:03:06 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_STATE_SPACE));
|
2018-03-03 07:03:06 +01:00
|
|
|
|
2019-05-07 23:37:06 +02:00
|
|
|
const ctx::critical_assertion ca;
|
2019-05-13 21:12:23 +02:00
|
|
|
thread_local char buf[ROOM_STATE_SPACE_KEY_MAX_SIZE];
|
2018-03-03 07:03:06 +01:00
|
|
|
const string_view &key
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
room_state_space_key(buf, at<"room_id"_>(event), at<"type"_>(event), at<"state_key"_>(event), at<"depth"_>(event), opts.event_idx)
|
2018-03-03 07:03:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
txn, room_state_space,
|
2018-03-03 07:03:06 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
opts.op,
|
2018-03-03 07:03:06 +01:00
|
|
|
key,
|
2018-01-26 21:26:09 +01:00
|
|
|
}
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
|
|
|
}
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2018-03-04 08:39:24 +01:00
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_redact(db::txn &txn,
|
2018-03-04 08:39:24 +01:00
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_REDACT));
|
|
|
|
assert(json::get<"type"_>(event) == "m.room.redaction");
|
|
|
|
|
|
|
|
const auto &target_id
|
|
|
|
{
|
|
|
|
at<"redacts"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::event::idx target_idx
|
|
|
|
{
|
|
|
|
find_event_idx(target_id, opts)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(unlikely(!target_idx))
|
2019-08-12 09:43:18 +02:00
|
|
|
{
|
2019-08-12 09:31:51 +02:00
|
|
|
log::dwarning
|
2019-05-13 21:12:23 +02:00
|
|
|
{
|
|
|
|
"Redaction from '%s' missing redaction target '%s'",
|
2019-07-06 07:58:12 +02:00
|
|
|
string_view{event.event_id},
|
2019-05-13 21:12:23 +02:00
|
|
|
target_id
|
|
|
|
};
|
|
|
|
|
2019-08-12 09:43:18 +02:00
|
|
|
if(opts.appendix.test(appendix::EVENT_HORIZON))
|
|
|
|
_index_event_horizon(txn, event, opts, target_id);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
char state_key_buf[event::STATE_KEY_MAX_SIZE];
|
|
|
|
const string_view &state_key
|
|
|
|
{
|
|
|
|
m::get(std::nothrow, target_idx, "state_key", state_key_buf)
|
|
|
|
};
|
2019-05-07 23:37:06 +02:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
if(!state_key)
|
2018-03-04 08:39:24 +01:00
|
|
|
return;
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
char type_buf[event::TYPE_MAX_SIZE];
|
|
|
|
const string_view &type
|
2018-03-04 08:39:24 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
m::get(std::nothrow, target_idx, "type", type_buf)
|
2018-03-04 08:39:24 +01:00
|
|
|
};
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(!empty(type));
|
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
thread_local char buf[ROOM_STATE_SPACE_KEY_MAX_SIZE];
|
|
|
|
const string_view &key
|
2018-03-04 08:39:24 +01:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
room_state_key(buf, at<"room_id"_>(event), type, state_key)
|
2018-03-04 08:39:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
db::txn::append
|
|
|
|
{
|
|
|
|
txn, room_state,
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
db::op::DELETE,
|
2018-03-04 08:39:24 +01:00
|
|
|
key,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
/// Adds the entry for the room_joined column into the txn.
|
2019-05-12 02:48:35 +02:00
|
|
|
void
|
2019-05-13 21:12:23 +02:00
|
|
|
ircd::m::dbs::_index_room_joined(db::txn &txn,
|
|
|
|
const event &event,
|
|
|
|
const write_opts &opts)
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(opts.appendix.test(appendix::ROOM_JOINED));
|
|
|
|
assert(at<"type"_>(event) == "m.room.member");
|
2019-05-12 02:48:35 +02:00
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
thread_local char buf[ROOM_JOINED_KEY_MAX_SIZE];
|
2019-05-12 02:48:35 +02:00
|
|
|
const ctx::critical_assertion ca;
|
|
|
|
const string_view &key
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
room_joined_key(buf, at<"room_id"_>(event), at<"origin"_>(event), at<"state_key"_>(event))
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &membership
|
|
|
|
{
|
|
|
|
m::membership(event)
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
2019-05-13 21:12:23 +02:00
|
|
|
assert(!empty(membership));
|
|
|
|
|
|
|
|
db::op op;
|
|
|
|
if(opts.op == db::op::SET) switch(hash(membership))
|
|
|
|
{
|
|
|
|
case hash("join"):
|
|
|
|
op = db::op::SET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hash("ban"):
|
|
|
|
case hash("leave"):
|
|
|
|
op = db::op::DELETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(opts.op == db::op::DELETE)
|
|
|
|
op = opts.op;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2019-05-12 02:48:35 +02:00
|
|
|
db::txn::append
|
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
txn, room_joined,
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 21:12:23 +02:00
|
|
|
op,
|
|
|
|
key,
|
2019-05-12 02:48:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:27:05 +02:00
|
|
|
// NOTE: QUERY
|
2019-05-10 04:03:30 +02:00
|
|
|
ircd::m::event::idx
|
|
|
|
ircd::m::dbs::find_event_idx(const event::id &event_id,
|
|
|
|
const write_opts &wopts)
|
|
|
|
{
|
|
|
|
event::idx ret{0};
|
|
|
|
if(wopts.interpose)
|
|
|
|
ret = wopts.interpose->val(db::op::SET, "_event_idx", event_id, 0UL);
|
|
|
|
|
|
|
|
if(wopts.allow_queries && !ret)
|
|
|
|
ret = m::index(event_id, std::nothrow); // query
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
//
|
|
|
|
// Database descriptors
|
|
|
|
//
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2019-01-15 22:00:15 +01:00
|
|
|
//
|
|
|
|
// event_idx
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_idx__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_idx__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_idx.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-10-16 22:40:03 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_idx__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_idx__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_idx.meta_block.size" },
|
2019-01-24 23:31:35 +01:00
|
|
|
{ "default", 4096L },
|
2018-10-16 22:40:03 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_idx__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_idx__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_idx.cache.size" },
|
|
|
|
{ "default", long(64_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_idx__cache__size};
|
|
|
|
db::capacity(db::cache(event_idx), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_idx__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_idx__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_idx.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_idx__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_idx), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-03 02:01:03 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_idx__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events__event_idx__bloom__bits
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_idx.bloom.bits" },
|
2019-01-24 23:31:35 +01:00
|
|
|
{ "default", 10L },
|
2018-11-03 02:01:03 +01:00
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-04-18 04:14:39 +02:00
|
|
|
ircd::m::dbs::desc::events__event_idx
|
2018-04-16 23:20:50 +02:00
|
|
|
{
|
|
|
|
// name
|
2018-04-18 04:14:39 +02:00
|
|
|
"_event_idx",
|
2018-04-16 23:20:50 +02:00
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Maps matrix event_id strings into internal index numbers.
|
|
|
|
|
|
|
|
event_id => event_idx
|
2018-04-16 23:20:50 +02:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
The key is an event_id and the value is the index number to be used as the
|
2018-10-27 22:23:43 +02:00
|
|
|
key to all the event data columns. The index number is referred to as the
|
|
|
|
event_idx and is a fixed 8 byte unsigned integer. All other columns which
|
|
|
|
may key on an event_id string instead use this event_idx index number. The
|
|
|
|
index number was generated sequentially based on the order the event was
|
|
|
|
written to the database. Index numbers start at 1 because 0 is used as a
|
|
|
|
sentinel value and is not valid. The index numbers throughout the database
|
|
|
|
generally do not have gaps and can be iterated, however gaps may exist when
|
|
|
|
an event is erased from the database (which is rare for the matrix
|
|
|
|
application).
|
2018-04-16 23:20:50 +02:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(string_view), typeid(uint64_t)
|
2018-04-16 23:20:50 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
2018-04-18 04:14:39 +02:00
|
|
|
{},
|
2018-04-16 23:20:50 +02:00
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-16 23:20:50 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
2018-04-16 23:20:50 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-16 23:20:50 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events__event_idx__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_idx__block__size),
|
2018-10-16 22:40:03 +02:00
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_idx__meta_block__size),
|
2018-04-16 23:20:50 +02:00
|
|
|
};
|
|
|
|
|
2019-01-15 22:01:29 +01:00
|
|
|
//
|
|
|
|
// event_json
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_json__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_json__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_json.block.size" },
|
2019-01-24 22:34:34 +01:00
|
|
|
{ "default", 2048L },
|
2019-01-15 22:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_json__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_json__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_json.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_json__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_json__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_json.cache.size" },
|
2019-01-24 22:34:34 +01:00
|
|
|
{ "default", long(64_MiB) },
|
2019-01-15 22:01:29 +01:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_json__cache__size};
|
|
|
|
db::capacity(db::cache(event_json), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_json__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_json__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_json.cache_comp.size" },
|
2019-01-24 22:34:34 +01:00
|
|
|
{ "default", long(0_MiB) },
|
2019-01-15 22:01:29 +01:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_json__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_json), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_json__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events__event_json__bloom__bits
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_json.bloom.bits" },
|
2019-01-24 22:34:34 +01:00
|
|
|
{ "default", 9L },
|
2019-01-15 22:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__event_json
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_event_json",
|
|
|
|
|
|
|
|
// explanation
|
2019-01-24 01:11:26 +01:00
|
|
|
R"(Full JSON object of an event.
|
2019-01-15 22:01:29 +01:00
|
|
|
|
|
|
|
event_idx => event_json
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
size_t(events__event_json__bloom__bits),
|
|
|
|
|
|
|
|
// expect queries hit
|
2019-01-24 23:31:35 +01:00
|
|
|
true,
|
2019-01-15 22:01:29 +01:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_json__block__size),
|
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_json__meta_block__size),
|
|
|
|
};
|
|
|
|
|
2019-02-06 02:18:53 +01:00
|
|
|
//
|
|
|
|
// event_refs
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_refs__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_refs__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_refs.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_refs__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_refs__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_refs.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_refs__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_refs__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_refs.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_refs__cache__size};
|
|
|
|
db::capacity(db::cache(event_refs), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_refs__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_refs__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_refs.cache_comp.size" },
|
|
|
|
{ "default", long(0_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_refs__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_refs), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::reflect(const ref &type)
|
2019-02-06 02:18:53 +01:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
2019-05-10 07:43:28 +02:00
|
|
|
case ref::NEXT: return "NEXT";
|
|
|
|
case ref::NEXT_AUTH: return "NEXT_AUTH";
|
|
|
|
case ref::NEXT_STATE: return "NEXT_STATE";
|
|
|
|
case ref::PREV_STATE: return "PREV_STATE";
|
|
|
|
case ref::M_RECEIPT__M_READ: return "M_RECEIPT__M_READ";
|
2019-06-22 01:32:15 +02:00
|
|
|
case ref::M_RELATES: return "M_RELATES";
|
2019-05-10 07:43:28 +02:00
|
|
|
case ref::M_ROOM_REDACTION: return "M_ROOM_REDACTION";
|
2019-02-14 22:11:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "????";
|
|
|
|
}
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_refs_key(const mutable_buffer &out,
|
|
|
|
const event::idx &tgt,
|
2019-02-14 22:11:37 +01:00
|
|
|
const ref &type,
|
2019-02-06 02:18:53 +01:00
|
|
|
const event::idx &src)
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
assert((src & ref_mask) == 0);
|
2019-02-06 02:18:53 +01:00
|
|
|
assert(size(out) >= sizeof(event::idx) * 2);
|
|
|
|
event::idx *const &key
|
|
|
|
{
|
|
|
|
reinterpret_cast<event::idx *>(data(out))
|
|
|
|
};
|
|
|
|
|
|
|
|
key[0] = tgt;
|
|
|
|
key[1] = src;
|
2019-02-14 22:11:37 +01:00
|
|
|
key[1] |= uint64_t(type) << ref_shift;
|
2019-02-06 02:18:53 +01:00
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(out), data(out) + sizeof(event::idx) * 2
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
std::tuple<ircd::m::dbs::ref, ircd::m::event::idx>
|
2019-02-06 02:18:53 +01:00
|
|
|
ircd::m::dbs::event_refs_key(const string_view &amalgam)
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
const event::idx key
|
2019-02-06 02:18:53 +01:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
byte_view<event::idx>{amalgam}
|
2019-02-06 02:18:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
ref(key >> ref_shift), key & ~ref_mask
|
2019-02-06 02:18:53 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-07 06:26:57 +01:00
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__event_refs__pfx
|
|
|
|
{
|
|
|
|
"_event_refs",
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return size(key) >= sizeof(event::idx) * 2;
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
assert(size(key) >= sizeof(event::idx));
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(key), data(key) + sizeof(event::idx)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::comparator
|
|
|
|
ircd::m::dbs::desc::events__event_refs__cmp
|
|
|
|
{
|
|
|
|
"_event_refs",
|
|
|
|
|
|
|
|
// less
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
static const size_t half(sizeof(event::idx));
|
|
|
|
static const size_t full(half * 2);
|
|
|
|
|
|
|
|
assert(size(a) >= half);
|
|
|
|
assert(size(b) >= half);
|
|
|
|
const event::idx *const key[2]
|
|
|
|
{
|
|
|
|
reinterpret_cast<const event::idx *>(data(a)),
|
|
|
|
reinterpret_cast<const event::idx *>(data(b)),
|
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
key[0][0] < key[1][0]? true:
|
|
|
|
key[0][0] > key[1][0]? false:
|
|
|
|
size(a) < size(b)? true:
|
|
|
|
size(a) > size(b)? false:
|
|
|
|
size(a) == half? false:
|
|
|
|
key[0][1] < key[1][1]? true:
|
|
|
|
false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// equal
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
return size(a) == size(b) && memcmp(data(a), data(b), size(a)) == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-06 02:18:53 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__event_refs
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_event_refs",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(Inverse reference graph of events.
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
event_idx | ref, event_idx => --
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
The first part of the key is the event being referenced. The second part
|
|
|
|
of the key is the event which refers to the first event somewhere in its
|
2019-02-14 22:11:37 +01:00
|
|
|
prev_events references. The event_idx in the second part of the key also
|
|
|
|
contains a dbs::ref type in its highest order byte so we can store
|
|
|
|
different kinds of references.
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
The prefix transform is in effect; an event may be referenced multiple
|
2019-02-14 22:11:37 +01:00
|
|
|
times. We can find all the events we have which reference a target, and
|
|
|
|
why. The database must already contain both events (hence they have
|
|
|
|
event::idx numbers).
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
The value is currently unused/empty; we may eventually store metadata with
|
|
|
|
information about this reference (i.e. is depth adjacent? is the ref
|
|
|
|
redundant with another in the same event and should not be made? etc).
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
2019-02-07 06:26:57 +01:00
|
|
|
events__event_refs__cmp,
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
// prefix transform
|
2019-02-07 02:18:01 +01:00
|
|
|
events__event_refs__pfx,
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
2019-02-14 22:11:37 +01:00
|
|
|
0,
|
2019-02-06 02:18:53 +01:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_refs__block__size),
|
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_refs__meta_block__size),
|
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
//
|
|
|
|
// event_horizon
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_horizon__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_horizon__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_horizon.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_horizon__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_horizon__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_horizon.meta_block.size" },
|
|
|
|
{ "default", 1024L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_horizon__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_horizon__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_horizon.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_horizon__cache__size};
|
|
|
|
db::capacity(db::cache(event_horizon), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_horizon__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_horizon__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_horizon.cache_comp.size" },
|
|
|
|
{ "default", long(0_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_horizon__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_horizon), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-10 06:43:57 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_horizon_key(const mutable_buffer &out,
|
|
|
|
const event::id &event_id)
|
|
|
|
{
|
2019-05-17 10:36:38 +02:00
|
|
|
return event_horizon_key(out, event_id, 0UL);
|
2019-05-10 06:43:57 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_horizon_key(const mutable_buffer &out,
|
|
|
|
const event::id &event_id,
|
|
|
|
const event::idx &event_idx)
|
|
|
|
{
|
|
|
|
mutable_buffer buf(out);
|
|
|
|
consume(buf, copy(buf, event_id));
|
2019-05-17 10:36:38 +02:00
|
|
|
|
|
|
|
if(event_idx)
|
|
|
|
{
|
|
|
|
consume(buf, copy(buf, "\0"_sv));
|
|
|
|
consume(buf, copy(buf, byte_view<string_view>(event_idx)));
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:10:34 +02:00
|
|
|
const string_view ret
|
2019-05-09 09:02:33 +02:00
|
|
|
{
|
|
|
|
data(out), data(buf)
|
|
|
|
};
|
2019-05-24 22:10:34 +02:00
|
|
|
|
|
|
|
assert(size(ret) == size(event_id) || size(ret) == size(event_id) + sizeof(event::idx) + 1);
|
|
|
|
return ret;
|
2019-05-09 09:02:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<ircd::m::event::idx>
|
|
|
|
ircd::m::dbs::event_horizon_key(const string_view &amalgam)
|
|
|
|
{
|
2019-05-24 22:10:34 +02:00
|
|
|
assert(size(amalgam) == 1 + sizeof(event::idx));
|
|
|
|
assert(amalgam[0] == '\0');
|
|
|
|
|
|
|
|
const byte_view<event::idx> &event_idx
|
|
|
|
{
|
|
|
|
amalgam.substr(1)
|
|
|
|
};
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
return
|
|
|
|
{
|
2019-05-24 22:10:34 +02:00
|
|
|
static_cast<event::idx>(event_idx)
|
2019-05-09 09:02:33 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__event_horizon__pfx
|
|
|
|
{
|
|
|
|
"_event_horizon",
|
2019-05-24 22:10:34 +02:00
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
[](const string_view &key)
|
|
|
|
{
|
2019-05-24 22:10:34 +02:00
|
|
|
return has(key, '\0');
|
2019-05-09 09:02:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
assert(size(key) >= sizeof(event::idx));
|
2019-05-24 22:10:34 +02:00
|
|
|
return split(key, '\0').first;
|
2019-05-09 09:02:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__event_horizon
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_event_horizon",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(Unresolved references in the reverse reference graph of events.
|
|
|
|
|
|
|
|
event_id | event_idx => --
|
|
|
|
|
|
|
|
The first part of the key is an event_id which the server does not have.
|
|
|
|
The suffix of the key is the index number of an event which the server
|
|
|
|
does have and it contains a reference to event_id.
|
|
|
|
|
|
|
|
We use the information in this column to find all of the events which
|
|
|
|
have an unresolved reference to this event and complete the holes in the
|
|
|
|
event_refs graph which could not be completed without this event.
|
|
|
|
|
|
|
|
When a new event is written to the database the event_horizon column is
|
|
|
|
queried seeking the event's ID. Each entry in event_horizon is the index
|
|
|
|
of an event which we previously wrote to the database without knowing the
|
|
|
|
index of the event currently being written (an out-of-order write).
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
events__event_horizon__pfx,
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
0,
|
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_horizon__block__size),
|
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_horizon__meta_block__size),
|
|
|
|
};
|
|
|
|
|
2019-04-16 22:41:55 +02:00
|
|
|
//
|
|
|
|
// event_sender
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_sender__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_sender__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_sender.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_sender__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_sender__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_sender.meta_block.size" },
|
|
|
|
{ "default", 4096L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_sender__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_sender__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_sender.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_sender__cache__size};
|
|
|
|
db::capacity(db::cache(event_sender), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_sender__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_sender__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_sender.cache_comp.size" },
|
|
|
|
{ "default", long(0_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_sender__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_sender), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_sender_key(const mutable_buffer &out,
|
|
|
|
const user::id &user_id,
|
|
|
|
const event::idx &event_idx)
|
|
|
|
{
|
|
|
|
return event_sender_key(out, user_id.host(), user_id.local(), event_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_sender_key(const mutable_buffer &out_,
|
|
|
|
const string_view &origin,
|
|
|
|
const string_view &localpart,
|
|
|
|
const event::idx &event_idx)
|
|
|
|
{
|
|
|
|
assert(size(out_) >= EVENT_SENDER_KEY_MAX_SIZE);
|
|
|
|
assert(!event_idx || localpart);
|
|
|
|
assert(!localpart || startswith(localpart, '@'));
|
|
|
|
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, origin));
|
|
|
|
consume(out, copy(out, localpart));
|
|
|
|
|
|
|
|
if(localpart && event_idx)
|
|
|
|
{
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, byte_view<string_view>(event_idx)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<ircd::string_view, ircd::m::event::idx>
|
|
|
|
ircd::m::dbs::event_sender_key(const string_view &amalgam)
|
|
|
|
{
|
|
|
|
const auto &parts
|
|
|
|
{
|
|
|
|
split(amalgam, '\0')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
assert(!empty(parts.first) && !empty(parts.second));
|
|
|
|
assert(startswith(parts.first, '@'));
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
parts.first,
|
|
|
|
byte_view<event::idx>(parts.second),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__event_sender__pfx
|
|
|
|
{
|
|
|
|
"_event_sender",
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return has(key, '@');
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
const auto &parts
|
|
|
|
{
|
|
|
|
split(key, '@')
|
|
|
|
};
|
|
|
|
|
|
|
|
return parts.first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__event_sender
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_event_sender",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(Index of senders to their events.
|
|
|
|
|
|
|
|
origin | localpart, event_idx => --
|
|
|
|
|
2019-08-13 09:48:58 +02:00
|
|
|
The senders of events are indexed by this column. This allows for all
|
2019-04-16 22:41:55 +02:00
|
|
|
events from a sender to be iterated. Additionally, all events from a
|
|
|
|
server and all known servers can be iterated from this column.
|
|
|
|
|
2019-08-13 09:48:58 +02:00
|
|
|
The key is made from a user mxid and an event_id, where the mxid is
|
2019-04-16 22:41:55 +02:00
|
|
|
part-swapped so the origin comes first, and the @localpart comes after.
|
|
|
|
Lookups can be performed for an origin or a full user_mxid.
|
|
|
|
|
|
|
|
The prefix transform is in effect; the prefix domain is the origin. We
|
|
|
|
can efficiently iterate all events from an origin. We can slightly less
|
|
|
|
efficiently iterate all users from an origin, as well as iterate all
|
|
|
|
origins known.
|
|
|
|
|
|
|
|
Note that the indexer of this column ignores the actual "origin" field
|
|
|
|
of an event. Only the "sender" data is used here.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
events__event_sender__pfx,
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
0,
|
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_sender__block__size),
|
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_sender__meta_block__size),
|
|
|
|
};
|
|
|
|
|
2019-04-16 22:42:18 +02:00
|
|
|
//
|
|
|
|
// event_type
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_type__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_type__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_type.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_type__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_type__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_type.meta_block.size" },
|
|
|
|
{ "default", 4096L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_type__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_type__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_type.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_type__cache__size};
|
|
|
|
db::capacity(db::cache(event_type), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_type__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_type__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._event_type.cache_comp.size" },
|
|
|
|
{ "default", long(0_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__event_type__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(event_type), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::event_type_key(const mutable_buffer &out_,
|
|
|
|
const string_view &type,
|
|
|
|
const event::idx &event_idx)
|
|
|
|
{
|
|
|
|
assert(size(out_) >= EVENT_TYPE_KEY_MAX_SIZE);
|
|
|
|
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, type));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, byte_view<string_view>(event_idx)));
|
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<ircd::m::event::idx>
|
|
|
|
ircd::m::dbs::event_type_key(const string_view &amalgam)
|
|
|
|
{
|
|
|
|
assert(size(amalgam) == sizeof(event::idx) + 1);
|
|
|
|
const auto &key
|
|
|
|
{
|
|
|
|
amalgam.substr(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(size(key) == sizeof(event::idx));
|
|
|
|
return
|
|
|
|
{
|
|
|
|
byte_view<event::idx>(key)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__event_type__pfx
|
|
|
|
{
|
|
|
|
"_event_type",
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return has(key, '\0');
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
const auto &parts
|
|
|
|
{
|
|
|
|
split(key, '\0')
|
|
|
|
};
|
|
|
|
|
|
|
|
return parts.first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__event_type
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_event_type",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(Index of types of events.
|
|
|
|
|
|
|
|
type | event_idx => --
|
|
|
|
|
|
|
|
The types of events are indexed by this column. All events of a specific type can be
|
|
|
|
iterated efficiently. The type string forms the prefix domain.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
events__event_type__pfx,
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0, //uses conf item
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
0,
|
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_type__block__size),
|
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__event_type__meta_block__size),
|
|
|
|
};
|
|
|
|
|
2018-05-05 04:47:39 +02:00
|
|
|
//
|
|
|
|
// room_head
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_head__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_head__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_head.block.size" },
|
2018-10-17 19:04:42 +02:00
|
|
|
{ "default", 4096L },
|
2018-09-18 08:35:38 +02:00
|
|
|
};
|
|
|
|
|
2018-10-16 22:40:03 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_head__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_head__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_head.meta_block.size" },
|
2018-10-17 19:04:42 +02:00
|
|
|
{ "default", 4096L },
|
2018-10-16 22:40:03 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_head__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_head__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_head.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(8_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_head__cache__size};
|
|
|
|
db::capacity(db::cache(room_head), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-05 04:47:39 +02:00
|
|
|
/// prefix transform for room_id,event_id in room_id
|
|
|
|
///
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__room_head__pfx
|
|
|
|
{
|
|
|
|
"_room_head",
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return has(key, "\0"_sv);
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return split(key, "\0"_sv).first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::room_head_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const id::event &event_id)
|
|
|
|
{
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, event_id));
|
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::room_head_key(const string_view &amalgam)
|
|
|
|
{
|
|
|
|
const auto &key
|
|
|
|
{
|
|
|
|
lstrip(amalgam, "\0"_sv)
|
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
key
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This column stores unreferenced (head) events for a room.
|
|
|
|
///
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-05-05 04:47:39 +02:00
|
|
|
ircd::m::dbs::desc::events__room_head
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_room_head",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Unreferenced events in a room.
|
|
|
|
|
|
|
|
[room_id | event_id => event_idx]
|
|
|
|
|
|
|
|
The key is a room_id and event_id concatenation. The value is an event_idx
|
2019-04-07 03:17:54 +02:00
|
|
|
of the event_id in the key. The key amalgam was specifically selected to
|
2018-10-27 22:23:43 +02:00
|
|
|
allow for DELETES sent to the WAL "in the blind" for all prev_events when
|
|
|
|
any new event is saved to the database, without making any read IO's to
|
|
|
|
look up anything about the prev reference to remove.
|
|
|
|
|
|
|
|
This is a fast-moving column where unreferenced events are inserted and
|
|
|
|
then deleted the first time another event is seen which references it so
|
|
|
|
it collects a lot of DELETE commands in the WAL and has to be compacted
|
|
|
|
often to reduce them out.
|
2018-05-05 04:47:39 +02:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(uint64_t)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
events__room_head__pfx,
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-05-05 04:47:39 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-05-05 04:47:39 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-03 05:32:34 +02:00
|
|
|
0, //no compresed cache
|
2018-05-05 04:47:39 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
0, //table too ephemeral for bloom generation/usefulness
|
2018-05-05 04:47:39 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__room_head__block__size),
|
2018-10-16 22:40:03 +02:00
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__room_head__meta_block__size),
|
2018-11-03 02:31:20 +01:00
|
|
|
|
|
|
|
// compression
|
|
|
|
{}, // no compression for this column
|
2018-05-05 04:47:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// room_events
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_events__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_events__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_events.block.size" },
|
2018-10-17 19:04:42 +02:00
|
|
|
{ "default", 512L },
|
2018-10-16 22:40:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_events__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_events__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_events.meta_block.size" },
|
2018-10-18 07:11:28 +02:00
|
|
|
{ "default", 16384L },
|
2018-09-18 08:35:38 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_events__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_events__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_events.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(32_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_events__cache__size};
|
|
|
|
db::capacity(db::cache(room_events), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_events__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__room_events__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_events.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_events__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(room_events), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Prefix transform for the events__room_events. The prefix here is a room_id
|
|
|
|
/// and the suffix is the depth+event_id concatenation.
|
|
|
|
/// for efficient sequences
|
|
|
|
///
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__room_events__pfx
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
"_room_events",
|
|
|
|
|
|
|
|
[](const string_view &key)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-10 01:43:19 +02:00
|
|
|
return has(key, "\0"_sv);
|
2018-02-08 22:23:01 +01:00
|
|
|
},
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
[](const string_view &key)
|
|
|
|
{
|
2018-04-10 01:43:19 +02:00
|
|
|
return split(key, "\0"_sv).first;
|
2018-02-08 22:23:01 +01:00
|
|
|
}
|
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-09 00:15:48 +01:00
|
|
|
/// Comparator for the events__room_events. The goal here is to sort the
|
|
|
|
/// events within a room by their depth from highest to lowest, so the
|
|
|
|
/// highest depth is hit first when a room is sought from this column.
|
|
|
|
///
|
|
|
|
const ircd::db::comparator
|
|
|
|
ircd::m::dbs::desc::events__room_events__cmp
|
|
|
|
{
|
|
|
|
"_room_events",
|
|
|
|
|
|
|
|
// less
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
static const auto &pt
|
|
|
|
{
|
|
|
|
events__room_events__pfx
|
|
|
|
};
|
|
|
|
|
|
|
|
// Extract the prefix from the keys
|
|
|
|
const string_view pre[2]
|
|
|
|
{
|
|
|
|
pt.get(a),
|
|
|
|
pt.get(b),
|
|
|
|
};
|
|
|
|
|
2018-07-22 21:05:24 +02:00
|
|
|
if(size(pre[0]) != size(pre[1]))
|
|
|
|
return size(pre[0]) < size(pre[1]);
|
2018-04-10 01:43:19 +02:00
|
|
|
|
2018-02-09 00:15:48 +01:00
|
|
|
if(pre[0] != pre[1])
|
|
|
|
return pre[0] < pre[1];
|
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
// After the prefix is the depth + event_idx
|
2018-02-09 00:15:48 +01:00
|
|
|
const string_view post[2]
|
|
|
|
{
|
2018-07-22 21:05:24 +02:00
|
|
|
a.substr(size(pre[0])),
|
|
|
|
b.substr(size(pre[1])),
|
2018-02-09 00:15:48 +01:00
|
|
|
};
|
|
|
|
|
2018-04-22 22:49:02 +02:00
|
|
|
// These conditions are matched on some queries when the user only
|
|
|
|
// supplies a room id.
|
|
|
|
|
2018-02-09 00:15:48 +01:00
|
|
|
if(empty(post[0]))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(empty(post[1]))
|
|
|
|
return false;
|
|
|
|
|
2018-04-22 22:49:02 +02:00
|
|
|
// Distill out the depth and event_idx integers
|
|
|
|
const std::pair<uint64_t, event::idx> pair[2]
|
2018-02-09 00:15:48 +01:00
|
|
|
{
|
2018-04-22 22:49:02 +02:00
|
|
|
room_events_key(post[0]),
|
|
|
|
room_events_key(post[1])
|
2018-02-09 00:15:48 +01:00
|
|
|
};
|
|
|
|
|
2018-04-22 22:49:02 +02:00
|
|
|
// When two events are at the same depth sort by index (the sequence
|
|
|
|
// number given as they were admitted into the system) otherwise
|
|
|
|
// sort by depth. Note this is a reverse order comparison.
|
|
|
|
return std::get<0>(pair[1]) != std::get<0>(pair[0])?
|
|
|
|
std::get<0>(pair[1]) < std::get<0>(pair[0]):
|
|
|
|
std::get<1>(pair[1]) < std::get<1>(pair[0]);
|
2018-02-09 00:15:48 +01:00
|
|
|
},
|
2018-05-22 04:52:47 +02:00
|
|
|
|
|
|
|
// equal
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
2018-02-09 00:15:48 +01:00
|
|
|
};
|
|
|
|
|
2018-02-13 23:21:57 +01:00
|
|
|
ircd::string_view
|
2018-03-04 09:25:27 +01:00
|
|
|
ircd::m::dbs::room_events_key(const mutable_buffer &out_,
|
2018-02-13 23:21:57 +01:00
|
|
|
const id::room &room_id,
|
|
|
|
const uint64_t &depth)
|
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
const const_buffer depth_cb
|
|
|
|
{
|
|
|
|
reinterpret_cast<const char *>(&depth), sizeof(depth)
|
|
|
|
};
|
|
|
|
|
2018-03-04 09:25:27 +01:00
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
2018-04-18 04:14:39 +02:00
|
|
|
consume(out, copy(out, depth_cb));
|
2018-03-04 09:25:27 +01:00
|
|
|
return { data(out_), data(out) };
|
2018-02-13 23:21:57 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::string_view
|
2018-03-04 09:25:27 +01:00
|
|
|
ircd::m::dbs::room_events_key(const mutable_buffer &out_,
|
2018-02-08 22:23:01 +01:00
|
|
|
const id::room &room_id,
|
|
|
|
const uint64_t &depth,
|
2018-04-18 04:14:39 +02:00
|
|
|
const event::idx &event_idx)
|
2018-02-08 22:23:01 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
const const_buffer depth_cb
|
|
|
|
{
|
|
|
|
reinterpret_cast<const char *>(&depth), sizeof(depth)
|
|
|
|
};
|
|
|
|
|
|
|
|
const const_buffer event_idx_cb
|
|
|
|
{
|
|
|
|
reinterpret_cast<const char *>(&event_idx), sizeof(event_idx)
|
|
|
|
};
|
|
|
|
|
2018-03-04 09:25:27 +01:00
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
2018-04-18 04:14:39 +02:00
|
|
|
consume(out, copy(out, depth_cb));
|
|
|
|
consume(out, copy(out, event_idx_cb));
|
2018-03-04 09:25:27 +01:00
|
|
|
return { data(out_), data(out) };
|
2018-01-26 21:26:09 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
std::pair<uint64_t, ircd::m::event::idx>
|
2018-02-09 02:15:34 +01:00
|
|
|
ircd::m::dbs::room_events_key(const string_view &amalgam)
|
|
|
|
{
|
2018-12-11 00:56:09 +01:00
|
|
|
assert(size(amalgam) >= 1 + 8 + 8 || size(amalgam) == 1 + 8);
|
2018-04-18 04:14:39 +02:00
|
|
|
assert(amalgam.front() == '\0');
|
2018-03-04 09:25:27 +01:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
const uint64_t &depth
|
2018-02-09 02:15:34 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
*reinterpret_cast<const uint64_t *>(data(amalgam) + 1)
|
2018-02-09 02:15:34 +01:00
|
|
|
};
|
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
const event::idx &event_idx
|
2018-02-09 02:15:34 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
size(amalgam) >= 1 + 8 + 8?
|
|
|
|
*reinterpret_cast<const uint64_t *>(data(amalgam) + 1 + 8):
|
2018-04-25 04:41:32 +02:00
|
|
|
std::numeric_limits<uint64_t>::max()
|
2018-02-09 02:15:34 +01:00
|
|
|
};
|
2018-04-18 04:14:39 +02:00
|
|
|
|
|
|
|
// Make sure these are copied rather than ever returning references in
|
|
|
|
// a tuple because the chance the integers will be aligned is low.
|
|
|
|
return { depth, event_idx };
|
2018-02-09 02:15:34 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// This column stores events in sequence in a room. Consider the following:
|
|
|
|
///
|
2019-06-15 00:58:49 +02:00
|
|
|
/// [room_id | depth + event_idx]
|
2018-02-08 22:23:01 +01:00
|
|
|
///
|
|
|
|
/// The key is composed from three parts:
|
|
|
|
///
|
|
|
|
/// - `room_id` is the official prefix, bounding the sequence. That means we
|
|
|
|
/// make a blind query with just a room_id and get to the beginning of the
|
|
|
|
/// sequence, then iterate until we stop before the next room_id (upper bound).
|
|
|
|
///
|
|
|
|
/// - `depth` is the ordering. Within the sequence, all elements are ordered by
|
2018-02-09 00:15:48 +01:00
|
|
|
/// depth from HIGHEST TO LOWEST. The sequence will start at the highest depth.
|
2018-04-18 04:14:39 +02:00
|
|
|
/// NOTE: Depth is a fixed 8 byte binary integer.
|
2018-02-08 22:23:01 +01:00
|
|
|
///
|
2018-04-18 04:14:39 +02:00
|
|
|
/// - `event_idx` is the key suffix. This column serves to sequence all events
|
2018-02-08 22:23:01 +01:00
|
|
|
/// within a room ordered by depth. There may be duplicate room_id|depth
|
2018-04-18 04:14:39 +02:00
|
|
|
/// prefixing but the event_idx suffix gives the key total uniqueness.
|
|
|
|
/// NOTE: event_idx is a fixed 8 byte binary integer.
|
2018-02-08 22:23:01 +01:00
|
|
|
///
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events__room_events
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"_room_events",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// explanation
|
2019-06-15 00:58:49 +02:00
|
|
|
R"(Indexes events in timeline sequence for a room
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2019-06-15 00:58:49 +02:00
|
|
|
[room_id | depth + event_idx]
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(string_view), typeid(string_view)
|
2018-02-08 22:23:01 +01:00
|
|
|
},
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// options
|
|
|
|
{},
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-09 00:15:48 +01:00
|
|
|
// comparator
|
|
|
|
events__room_events__cmp,
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// prefix transform
|
|
|
|
events__room_events__pfx,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-15 08:00:56 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
0, // no bloom filter because of possible comparator issues
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__room_events__block__size),
|
2018-10-16 22:40:03 +02:00
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__room_events__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-03-04 09:08:30 +01:00
|
|
|
//
|
2018-04-15 23:40:10 +02:00
|
|
|
// joined sequential
|
2018-03-04 09:08:30 +01:00
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_joined__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_joined__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_joined.block.size" },
|
2018-10-17 19:04:42 +02:00
|
|
|
{ "default", 512L },
|
2018-09-18 08:35:38 +02:00
|
|
|
};
|
|
|
|
|
2018-10-16 22:40:03 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_joined__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_joined__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_joined.meta_block.size" },
|
2018-10-18 07:11:28 +02:00
|
|
|
{ "default", 8192L },
|
2018-10-16 22:40:03 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_joined__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_joined__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_joined.cache.size" },
|
|
|
|
{ "default", long(8_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_joined__cache__size};
|
|
|
|
db::capacity(db::cache(room_joined), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_joined__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__room_joined__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_joined.cache_comp.size" },
|
|
|
|
{ "default", long(8_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_joined__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(room_joined), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-03 02:01:03 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_joined__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events__room_joined__bloom__bits
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_joined.bloom.bits" },
|
|
|
|
{ "default", 6L },
|
|
|
|
};
|
|
|
|
|
2018-04-15 23:40:10 +02:00
|
|
|
/// Prefix transform for the events__room_joined
|
2018-03-03 07:03:06 +01:00
|
|
|
///
|
|
|
|
const ircd::db::prefix_transform
|
2018-04-15 23:40:10 +02:00
|
|
|
ircd::m::dbs::desc::events__room_joined__pfx
|
2018-03-03 07:03:06 +01:00
|
|
|
{
|
2018-04-15 23:40:10 +02:00
|
|
|
"_room_joined",
|
2018-03-03 07:03:06 +01:00
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
2018-04-10 01:43:19 +02:00
|
|
|
return has(key, "\0"_sv);
|
2018-03-03 07:03:06 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
2018-04-10 01:43:19 +02:00
|
|
|
return split(key, "\0"_sv).first;
|
2018-03-03 07:03:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-03 21:49:03 +02:00
|
|
|
ircd::string_view
|
2018-04-15 23:40:10 +02:00
|
|
|
ircd::m::dbs::room_joined_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const string_view &origin)
|
2018-04-03 21:49:03 +02:00
|
|
|
{
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, origin));
|
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
2018-03-03 07:03:06 +01:00
|
|
|
ircd::string_view
|
2018-04-15 23:40:10 +02:00
|
|
|
ircd::m::dbs::room_joined_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const string_view &origin,
|
|
|
|
const id::user &member)
|
2018-03-03 07:03:06 +01:00
|
|
|
{
|
2018-03-04 09:25:27 +01:00
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, origin));
|
|
|
|
consume(out, copy(out, member));
|
|
|
|
return { data(out_), data(out) };
|
2018-03-03 07:03:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-12 23:08:48 +02:00
|
|
|
std::pair<ircd::string_view, ircd::string_view>
|
2018-04-15 23:40:10 +02:00
|
|
|
ircd::m::dbs::room_joined_key(const string_view &amalgam)
|
2018-03-04 09:08:30 +01:00
|
|
|
{
|
|
|
|
const auto &key
|
|
|
|
{
|
2018-03-04 09:25:27 +01:00
|
|
|
lstrip(amalgam, "\0"_sv)
|
2018-03-04 09:08:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto &s
|
|
|
|
{
|
2018-03-04 09:25:27 +01:00
|
|
|
split(key, "@"_sv)
|
2018-03-04 09:08:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{ s.first },
|
2018-04-12 03:43:45 +02:00
|
|
|
!empty(s.second)?
|
|
|
|
string_view{begin(s.second) - 1, end(s.second)}:
|
|
|
|
string_view{}
|
2018-03-04 09:08:30 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-04-15 23:40:10 +02:00
|
|
|
ircd::m::dbs::desc::events__room_joined
|
2018-03-03 07:03:06 +01:00
|
|
|
{
|
|
|
|
// name
|
2018-04-15 23:40:10 +02:00
|
|
|
"_room_joined",
|
2018-03-03 07:03:06 +01:00
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Specifically indexes joined members of a room for fast iteration.
|
2018-03-03 07:03:06 +01:00
|
|
|
|
2018-10-27 22:23:43 +02:00
|
|
|
[room_id | origin + mxid] => event_idx
|
2018-03-03 07:03:06 +01:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(string_view), typeid(uint64_t)
|
2018-03-03 07:03:06 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
2018-04-15 23:40:10 +02:00
|
|
|
events__room_joined__pfx,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-15 08:00:56 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events__room_joined__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__room_joined__block__size),
|
2018-10-16 22:40:03 +02:00
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__room_joined__meta_block__size),
|
2018-03-03 07:03:06 +01:00
|
|
|
};
|
|
|
|
|
2018-03-04 08:39:24 +01:00
|
|
|
//
|
2019-05-12 02:48:35 +02:00
|
|
|
// room present state sequential
|
2018-03-04 08:39:24 +01:00
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_state.block.size" },
|
2018-10-16 22:40:03 +02:00
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_state__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_state.meta_block.size" },
|
2018-10-18 07:11:28 +02:00
|
|
|
{ "default", 8192L },
|
2018-09-18 08:35:38 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_state.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_state__cache__size};
|
|
|
|
db::capacity(db::cache(room_state), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_state__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_state.cache_comp.size" },
|
|
|
|
{ "default", long(8_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
const size_t &value{events__room_state__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(room_state), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-03 02:01:03 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events__room_state__bloom__bits
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events._room_state.bloom.bits" },
|
|
|
|
{ "default", 10L },
|
|
|
|
};
|
|
|
|
|
2018-03-04 08:39:24 +01:00
|
|
|
/// prefix transform for type,state_key in room_id
|
|
|
|
///
|
|
|
|
/// This transform is special for concatenating room_id with type and state_key
|
|
|
|
/// in that order with prefix being the room_id (this may change to room_id+
|
|
|
|
/// type
|
|
|
|
///
|
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__room_state__pfx
|
|
|
|
{
|
|
|
|
"_room_state",
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
2018-04-10 01:43:19 +02:00
|
|
|
return has(key, "\0"_sv);
|
2018-03-04 08:39:24 +01:00
|
|
|
},
|
2018-04-10 01:43:19 +02:00
|
|
|
|
2018-03-04 08:39:24 +01:00
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return split(key, "\0"_sv).first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::room_state_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
2018-10-24 03:04:21 +02:00
|
|
|
const string_view &type)
|
2018-03-04 08:39:24 +01:00
|
|
|
{
|
2018-10-24 03:04:21 +02:00
|
|
|
return room_state_key(out_, room_id, type, string_view{});
|
2018-03-04 08:39:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::room_state_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
2018-10-24 03:04:21 +02:00
|
|
|
const string_view &type,
|
|
|
|
const string_view &state_key)
|
2018-03-04 08:39:24 +01:00
|
|
|
{
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
2019-08-16 11:05:34 +02:00
|
|
|
assert(room_id);
|
2018-10-24 03:04:21 +02:00
|
|
|
|
|
|
|
if(likely(defined(type)))
|
|
|
|
{
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, type));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined(state_key))
|
|
|
|
{
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, state_key));
|
|
|
|
}
|
|
|
|
|
2018-03-04 08:39:24 +01:00
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
2018-04-12 23:08:48 +02:00
|
|
|
std::pair<ircd::string_view, ircd::string_view>
|
2018-03-04 08:39:24 +01:00
|
|
|
ircd::m::dbs::room_state_key(const string_view &amalgam)
|
|
|
|
{
|
|
|
|
const auto &key
|
|
|
|
{
|
|
|
|
lstrip(amalgam, "\0"_sv)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &s
|
|
|
|
{
|
|
|
|
split(key, "\0"_sv)
|
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
s.first, s.second
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-03-04 08:39:24 +01:00
|
|
|
ircd::m::dbs::desc::events__room_state
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_room_state",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(The present state of the room.
|
|
|
|
|
|
|
|
[room_id | type + state_key] => event_idx
|
|
|
|
|
|
|
|
This column is also known as the "present state table." It contains the
|
|
|
|
very important present state of the room for this server. The key contains
|
|
|
|
plaintext room_id, type and state_key elements for direct point-lookup as
|
|
|
|
well as iteration. The value is the index of the apropos state event.
|
2018-03-04 08:39:24 +01:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(string_view), typeid(uint64_t)
|
2018-03-04 08:39:24 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
events__room_state__pfx,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-15 08:00:56 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-15 08:00:56 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events__room_state__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__room_state__block__size),
|
2018-10-16 22:40:03 +02:00
|
|
|
|
|
|
|
// meta_block size
|
|
|
|
size_t(events__room_state__meta_block__size),
|
2018-03-04 08:39:24 +01:00
|
|
|
};
|
|
|
|
|
2019-05-12 02:48:35 +02:00
|
|
|
//
|
|
|
|
// room all states sequential
|
|
|
|
//
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state_space__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state_space__block__size
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
{ "name", "ircd.m.dbs.events._room_state_space.block.size" },
|
|
|
|
{ "default", 512L },
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state_space__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state_space__meta_block__size
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
{ "name", "ircd.m.dbs.events._room_state_space.meta_block.size" },
|
|
|
|
{ "default", 8192L },
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state_space__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state_space__cache__size
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
{ "name", "ircd.m.dbs.events._room_state_space.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
2019-05-12 02:48:35 +02:00
|
|
|
}, []
|
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
const size_t &value{events__room_state_space__cache__size};
|
|
|
|
db::capacity(db::cache(room_state_space), value);
|
2019-05-12 02:48:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state_space__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__room_state_space__cache_comp__size
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
{ "name", "ircd.m.dbs.events._room_state_space.cache_comp.size" },
|
|
|
|
{ "default", long(8_MiB) },
|
2019-05-12 02:48:35 +02:00
|
|
|
}, []
|
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
const size_t &value{events__room_state_space__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(room_state_space), value);
|
2019-05-12 02:48:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_state_space__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events__room_state_space__bloom__bits
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
{ "name", "ircd.m.dbs.events._room_state_space.bloom.bits" },
|
|
|
|
{ "default", 10L },
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
2019-06-16 00:20:00 +02:00
|
|
|
ircd::string_view
|
|
|
|
ircd::m::dbs::room_state_space_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id)
|
|
|
|
{
|
|
|
|
return room_state_space_key(out_, room_id, string_view{}, string_view{}, -1L, 0L);
|
|
|
|
}
|
|
|
|
|
2019-05-12 02:48:35 +02:00
|
|
|
ircd::string_view
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::room_state_space_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const string_view &type)
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-06-16 00:20:00 +02:00
|
|
|
return room_state_space_key(out_, room_id, type, string_view{}, -1L, 0L);
|
2019-05-12 02:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::room_state_space_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const string_view &type,
|
|
|
|
const string_view &state_key)
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-06-16 00:20:00 +02:00
|
|
|
return room_state_space_key(out_, room_id, type, state_key, -1L, 0L);
|
2019-05-12 02:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::room_state_space_key(const mutable_buffer &out_,
|
|
|
|
const id::room &room_id,
|
|
|
|
const string_view &type,
|
|
|
|
const string_view &state_key,
|
|
|
|
const int64_t &depth,
|
|
|
|
const event::idx &event_idx)
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
mutable_buffer out{out_};
|
|
|
|
consume(out, copy(out, room_id));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, type));
|
|
|
|
consume(out, copy(out, "\0"_sv));
|
|
|
|
consume(out, copy(out, state_key));
|
2019-06-16 09:12:06 +02:00
|
|
|
consume(out, copy(out, "\0"_sv));
|
2019-05-12 02:48:35 +02:00
|
|
|
consume(out, copy(out, byte_view<string_view>(depth)));
|
|
|
|
consume(out, copy(out, byte_view<string_view>(event_idx)));
|
|
|
|
return { data(out_), data(out) };
|
|
|
|
}
|
|
|
|
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::room_state_space_key_parts
|
|
|
|
ircd::m::dbs::room_state_space_key(const string_view &amalgam)
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
const auto &key
|
|
|
|
{
|
|
|
|
lstrip(amalgam, "\0"_sv)
|
|
|
|
};
|
|
|
|
|
2019-08-12 03:18:57 +02:00
|
|
|
const auto &[type, after_type]
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
split(key, "\0"_sv)
|
|
|
|
};
|
|
|
|
|
2019-08-12 03:18:57 +02:00
|
|
|
const auto &[state_key, after_state_key]
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-08-12 03:18:57 +02:00
|
|
|
split(after_type, "\0"_sv)
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const int64_t &depth
|
|
|
|
{
|
2019-08-12 03:18:57 +02:00
|
|
|
size(after_state_key) >= 8?
|
|
|
|
int64_t(byte_view<int64_t>(after_state_key.substr(0, 8))):
|
2019-06-16 09:58:43 +02:00
|
|
|
-1L
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const event::idx &event_idx
|
|
|
|
{
|
2019-08-12 03:18:57 +02:00
|
|
|
size(after_state_key) >= 16?
|
|
|
|
event::idx(byte_view<event::idx>(after_state_key.substr(8, 8))):
|
2019-06-16 09:58:43 +02:00
|
|
|
0UL
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
{
|
|
|
|
type, state_key, depth, event_idx
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const ircd::db::prefix_transform
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::desc::events__room_state_space__pfx
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
"_room_state_space",
|
2019-05-12 02:48:35 +02:00
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return has(key, "\0"_sv);
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
|
|
|
{
|
|
|
|
return split(key, "\0"_sv).first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::comparator
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::desc::events__room_state_space__cmp
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
"_room_state_space",
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// less
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
static const auto &pt
|
|
|
|
{
|
2019-05-13 19:29:20 +02:00
|
|
|
events__room_state_space__pfx
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const string_view pre[2]
|
|
|
|
{
|
|
|
|
pt.get(a),
|
|
|
|
pt.get(b),
|
|
|
|
};
|
|
|
|
|
|
|
|
if(size(pre[0]) != size(pre[1]))
|
|
|
|
return size(pre[0]) < size(pre[1]);
|
|
|
|
|
|
|
|
if(pre[0] != pre[1])
|
|
|
|
return pre[0] < pre[1];
|
|
|
|
|
|
|
|
const string_view post[2]
|
|
|
|
{
|
|
|
|
a.substr(size(pre[0])),
|
|
|
|
b.substr(size(pre[1])),
|
|
|
|
};
|
|
|
|
|
|
|
|
// These conditions are matched on some queries when the user only
|
|
|
|
// supplies a room_id.
|
|
|
|
if(empty(post[0]))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(empty(post[1]))
|
|
|
|
return false;
|
|
|
|
|
2019-06-16 00:20:32 +02:00
|
|
|
// Decompose the postfix of the key for granular sorting
|
|
|
|
const room_state_space_key_parts k[2]
|
|
|
|
{
|
|
|
|
room_state_space_key(post[0]),
|
|
|
|
room_state_space_key(post[1])
|
|
|
|
};
|
|
|
|
|
|
|
|
// type
|
|
|
|
if(std::get<0>(k[0]) < std::get<0>(k[1]))
|
|
|
|
return true;
|
|
|
|
else if(std::get<0>(k[0]) > std::get<0>(k[1]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// state_key
|
|
|
|
if(std::get<1>(k[0]) < std::get<1>(k[1]))
|
|
|
|
return true;
|
|
|
|
else if(std::get<1>(k[0]) > std::get<1>(k[1]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// depth (ORDER IS DESCENDING!)
|
2019-06-16 09:58:43 +02:00
|
|
|
if(uint64_t(std::get<2>(k[0])) > uint64_t(std::get<2>(k[1])))
|
2019-06-16 00:20:32 +02:00
|
|
|
return true;
|
2019-06-16 09:58:43 +02:00
|
|
|
else if(uint64_t(std::get<2>(k[0])) < uint64_t(std::get<2>(k[1])))
|
2019-06-16 00:20:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// event_idx (ORDER IS DESCENDING!)
|
|
|
|
if(std::get<3>(k[0]) > std::get<3>(k[1]))
|
|
|
|
return true;
|
|
|
|
else if(std::get<3>(k[0]) < std::get<3>(k[1]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return false;
|
2019-05-12 02:48:35 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// equal
|
|
|
|
[](const string_view &a, const string_view &b)
|
|
|
|
{
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ircd::db::descriptor
|
2019-05-13 19:29:20 +02:00
|
|
|
ircd::m::dbs::desc::events__room_state_space
|
2019-05-12 02:48:35 +02:00
|
|
|
{
|
|
|
|
// name
|
2019-05-13 19:29:20 +02:00
|
|
|
"_room_state_space",
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(All states of the room.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(uint64_t)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
2019-06-16 00:20:32 +02:00
|
|
|
events__room_state_space__cmp,
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// prefix transform
|
2019-05-13 19:29:20 +02:00
|
|
|
events__room_state_space__pfx,
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
|
|
|
// cache size
|
|
|
|
bool(events_cache_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
|
|
|
|
|
|
|
// bloom filter bits
|
2019-05-13 19:29:20 +02:00
|
|
|
size_t(events__room_state_space__bloom__bits),
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
|
|
|
|
|
|
|
// block size
|
2019-05-13 19:29:20 +02:00
|
|
|
size_t(events__room_state_space__block__size),
|
2019-05-12 02:48:35 +02:00
|
|
|
|
|
|
|
// meta_block size
|
2019-05-13 19:29:20 +02:00
|
|
|
size_t(events__room_state_space__meta_block__size),
|
2019-05-12 02:48:35 +02:00
|
|
|
};
|
|
|
|
|
2018-01-26 21:26:09 +01:00
|
|
|
//
|
2018-02-08 22:23:01 +01:00
|
|
|
// Direct column descriptors
|
2018-01-26 21:26:09 +01:00
|
|
|
//
|
|
|
|
|
2018-11-03 02:01:03 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events___event__bloom__bits)
|
|
|
|
ircd::m::dbs::desc::events___event__bloom__bits
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.__event.bloom.bits" },
|
|
|
|
{ "default", 8L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// event_id
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_id__block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_id__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.event_id.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_id__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__event_id__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.event_id.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__event_id__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__event_id__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.event_id.cache.size" },
|
|
|
|
{ "default", long(32_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "event_id"_>()));
|
|
|
|
const size_t &value{events__event_id__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__event_id__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__event_id__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.event_id.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "event_id"_>()));
|
|
|
|
const size_t &value{events__event_id__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_event_id
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"event_id",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the event_id property of an event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-10-27 22:23:43 +02:00
|
|
|
As with all direct event columns the key is an event_idx and the value
|
|
|
|
is the data for the event. It should be mentioned for this column
|
|
|
|
specifically that event_id's are already saved in the _event_idx column
|
|
|
|
however that is a mapping of event_id to event_idx whereas this is a
|
|
|
|
mapping of event_idx to event_id.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.4
|
|
|
|
MUST NOT exceed 255 bytes.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__event_id__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__event_id__meta_block__size),
|
2018-01-26 21:26:09 +01:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// type
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__type__block__size)
|
|
|
|
ircd::m::dbs::desc::events__type__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.type.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__type__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__type__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.type.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__type__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__type__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.type.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(32_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "type"_>()));
|
|
|
|
const size_t &value{events__type__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__type__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__type__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.type.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "type"_>()));
|
|
|
|
const size_t &value{events__type__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_type
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"type",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the type property of an event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.1
|
|
|
|
The type of event. This SHOULD be namespaced similar to Java package naming conventions
|
|
|
|
e.g. 'com.example.subdomain.event.type'.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.4
|
|
|
|
MUST NOT exceed 255 bytes.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__type__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__type__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// content
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__content__block__size)
|
|
|
|
ircd::m::dbs::desc::events__content__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.content.block.size" },
|
|
|
|
{ "default", 2048L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__content__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__content__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.content.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__content__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__content__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.content.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(48_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "content"_>()));
|
|
|
|
const size_t &value{events__content__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__content__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__content__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.content.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "content"_>()));
|
|
|
|
const size_t &value{events__content__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_content
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"content",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the content property of an event.
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
10.1
|
|
|
|
The fields in this object will vary depending on the type of event. When interacting
|
|
|
|
with the REST API, this is the HTTP body.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-03-02 17:32:42 +01:00
|
|
|
Since events must not exceed 64 KiB the maximum size for the content is the remaining
|
2018-02-08 22:23:01 +01:00
|
|
|
space after all the other fields for the event are rendered.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__content__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__content__meta_block__size),
|
2018-01-26 21:26:09 +01:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// room_id
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_id__block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_id__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.room_id.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_id__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__room_id__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.room_id.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__room_id__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__room_id__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.room_id.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(32_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "room_id"_>()));
|
|
|
|
const size_t &value{events__room_id__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__room_id__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__room_id__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.room_id.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "room_id"_>()));
|
|
|
|
const size_t &value{events__room_id__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_room_id
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"room_id",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the room_id property of an event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.2 (apropos room events)
|
|
|
|
Required. The ID of the room associated with this event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.4
|
|
|
|
MUST NOT exceed 255 bytes.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__room_id__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__room_id__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// sender
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__sender__block__size)
|
|
|
|
ircd::m::dbs::desc::events__sender__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.sender.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__sender__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__sender__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.sender.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__sender__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__sender__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.sender.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(32_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "sender"_>()));
|
|
|
|
const size_t &value{events__sender__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__sender__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__sender__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.sender.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "sender"_>()));
|
|
|
|
const size_t &value{events__sender__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_sender
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"sender",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the sender property of an event.
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
10.2 (apropos room events)
|
|
|
|
Required. Contains the fully-qualified ID of the user who sent this event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.4
|
|
|
|
MUST NOT exceed 255 bytes.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__sender__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__sender__meta_block__size),
|
2018-01-26 21:26:09 +01:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// state_key
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__state_key__block__size)
|
|
|
|
ircd::m::dbs::desc::events__state_key__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.state_key.block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2019-01-24 22:34:34 +01:00
|
|
|
decltype(ircd::m::dbs::desc::events__state_key__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__state_key__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.state_key.meta_block.size" },
|
|
|
|
{ "default", 512L },
|
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__state_key__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__state_key__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.state_key.cache.size" },
|
2018-09-26 06:14:11 +02:00
|
|
|
{ "default", long(32_MiB) },
|
2018-09-03 05:32:34 +02:00
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "state_key"_>()));
|
|
|
|
const size_t &value{events__state_key__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__state_key__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__state_key__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.state_key.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "state_key"_>()));
|
|
|
|
const size_t &value{events__state_key__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_state_key
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"state_key",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the state_key property of an event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.3 (apropos room state events)
|
|
|
|
A unique key which defines the overwriting semantics for this piece of room state.
|
|
|
|
This value is often a zero-length string. The presence of this key makes this event a
|
|
|
|
State Event. The key MUST NOT start with '_'.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
10.4
|
|
|
|
MUST NOT exceed 255 bytes.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
2019-01-24 23:31:35 +01:00
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__state_key__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__state_key__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// origin_server_ts
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__origin_server_ts__block__size)
|
|
|
|
ircd::m::dbs::desc::events__origin_server_ts__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.origin_server_ts.block.size" },
|
|
|
|
{ "default", 256L },
|
|
|
|
};
|
|
|
|
|
2018-10-21 09:19:42 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__origin_server_ts__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__origin_server_ts__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.origin_server_ts.meta_block.size" },
|
2019-01-24 23:31:35 +01:00
|
|
|
{ "default", 512L },
|
2018-10-21 09:19:42 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__origin_server_ts__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__origin_server_ts__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.origin_server_ts.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "origin_server_ts"_>()));
|
|
|
|
const size_t &value{events__origin_server_ts__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__origin_server_ts__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__origin_server_ts__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.origin_server_ts.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "origin_server_ts"_>()));
|
|
|
|
const size_t &value{events__origin_server_ts__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_origin_server_ts
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"origin_server_ts",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the origin_server_ts property of an event.
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
FEDERATION 4.1
|
|
|
|
Timestamp in milliseconds on origin homeserver when this PDU was created.
|
|
|
|
|
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number.
|
2018-02-08 22:23:01 +01:00
|
|
|
value is a machine integer (binary)
|
|
|
|
|
|
|
|
TODO: consider unsigned rather than time_t because of millisecond precision
|
|
|
|
|
|
|
|
)",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(time_t)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__origin_server_ts__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__origin_server_ts__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
// depth
|
|
|
|
//
|
|
|
|
|
2018-09-18 08:35:38 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__depth__block__size)
|
|
|
|
ircd::m::dbs::desc::events__depth__block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.depth.block.size" },
|
|
|
|
{ "default", 256L },
|
|
|
|
};
|
|
|
|
|
2018-10-21 09:19:42 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__depth__meta_block__size)
|
|
|
|
ircd::m::dbs::desc::events__depth__meta_block__size
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.depth.meta_block.size" },
|
2019-01-24 23:31:35 +01:00
|
|
|
{ "default", 512L },
|
2018-10-21 09:19:42 +02:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
decltype(ircd::m::dbs::desc::events__depth__cache__size)
|
|
|
|
ircd::m::dbs::desc::events__depth__cache__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.depth.cache.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "depth"_>()));
|
|
|
|
const size_t &value{events__depth__cache__size};
|
|
|
|
db::capacity(db::cache(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::dbs::desc::events__depth__cache_comp__size)
|
|
|
|
ircd::m::dbs::desc::events__depth__cache_comp__size
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.dbs.events.depth.cache_comp.size" },
|
|
|
|
{ "default", long(16_MiB) },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
auto &column(event_column.at(json::indexof<event, "depth"_>()));
|
|
|
|
const size_t &value{events__depth__cache_comp__size};
|
|
|
|
db::capacity(db::cache_compressed(column), value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events_depth
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
|
|
|
"depth",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(Stores the depth property of an event.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
### developer note:
|
2018-04-18 04:14:39 +02:00
|
|
|
key is event_idx number. value is long integer
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(int64_t)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-04-18 06:39:40 +02:00
|
|
|
// cache size
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// cache size for compressed assets
|
2018-09-15 10:12:47 +02:00
|
|
|
bool(events_cache_comp_enable)? -1 : 0,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// bloom filter bits
|
2018-11-03 02:01:03 +01:00
|
|
|
size_t(events___event__bloom__bits),
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
true,
|
2018-09-18 08:35:38 +02:00
|
|
|
|
|
|
|
// block size
|
|
|
|
size_t(events__depth__block__size),
|
2018-11-02 17:01:23 +01:00
|
|
|
|
|
|
|
// meta_block size
|
2019-01-24 22:34:34 +01:00
|
|
|
size_t(events__depth__meta_block__size),
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
|
|
|
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
2019-02-14 22:11:37 +01:00
|
|
|
// Other column descriptions
|
2018-09-03 05:32:34 +02:00
|
|
|
//
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
namespace ircd::m::dbs::desc
|
2018-09-18 08:35:38 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
// Deprecated / dropped columns.
|
|
|
|
//
|
|
|
|
// These have to be retained for users that have yet to open their
|
|
|
|
// database with a newly released schema which has dropped a column
|
|
|
|
// from the schema. If the legacy descriptor is not provided here then
|
|
|
|
// the database will not know how to open the descriptor in order to
|
|
|
|
// conduct the drop.
|
2018-09-18 08:35:38 +02:00
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
extern const ircd::db::descriptor events_auth_events;
|
|
|
|
extern const ircd::db::descriptor events_hashes;
|
|
|
|
extern const ircd::db::descriptor events_membership;
|
|
|
|
extern const ircd::db::descriptor events_origin;
|
|
|
|
extern const ircd::db::descriptor events_prev_events;
|
|
|
|
extern const ircd::db::descriptor events_prev_state;
|
|
|
|
extern const ircd::db::descriptor events_redacts;
|
|
|
|
extern const ircd::db::descriptor events_signatures;
|
|
|
|
extern const ircd::db::descriptor events__event_auth;
|
|
|
|
extern const ircd::db::comparator events__event_auth__cmp;
|
|
|
|
extern const ircd::db::prefix_transform events__event_auth__pfx;
|
|
|
|
extern const ircd::db::descriptor events__event_bad;
|
2019-06-15 00:58:49 +02:00
|
|
|
extern const ircd::db::descriptor events__state_node;
|
2019-02-14 22:11:37 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Required by RocksDB
|
|
|
|
//
|
|
|
|
|
|
|
|
extern const ircd::db::descriptor events__default;
|
2019-01-24 22:34:34 +01:00
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
const ircd::db::prefix_transform
|
|
|
|
ircd::m::dbs::desc::events__event_auth__pfx
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
"_event_auth",
|
|
|
|
[](const string_view &key)
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
return size(key) >= sizeof(event::idx) * 2;
|
|
|
|
},
|
|
|
|
|
|
|
|
[](const string_view &key)
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
assert(size(key) >= sizeof(event::idx));
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(key), data(key) + sizeof(event::idx)
|
|
|
|
};
|
2018-09-03 05:32:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
const ircd::db::comparator
|
|
|
|
ircd::m::dbs::desc::events__event_auth__cmp
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
"_event_auth",
|
|
|
|
|
|
|
|
// less
|
|
|
|
[](const string_view &a, const string_view &b)
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
static const size_t half(sizeof(event::idx));
|
|
|
|
static const size_t full(half * 2);
|
|
|
|
|
|
|
|
assert(size(a) >= half);
|
|
|
|
assert(size(b) >= half);
|
|
|
|
const event::idx *const key[2]
|
|
|
|
{
|
|
|
|
reinterpret_cast<const event::idx *>(data(a)),
|
|
|
|
reinterpret_cast<const event::idx *>(data(b)),
|
|
|
|
};
|
|
|
|
|
|
|
|
return
|
|
|
|
key[0][0] < key[1][0]? true:
|
|
|
|
key[0][0] > key[1][0]? false:
|
|
|
|
size(a) < size(b)? true:
|
|
|
|
size(a) > size(b)? false:
|
|
|
|
size(a) == half? false:
|
|
|
|
key[0][1] < key[1][1]? true:
|
|
|
|
false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// equal
|
|
|
|
[](const string_view &a, const string_view &b)
|
2018-09-03 05:32:34 +02:00
|
|
|
{
|
2019-02-14 22:11:37 +01:00
|
|
|
return size(a) == size(b) && memcmp(data(a), data(b), size(a)) == 0;
|
2018-09-03 05:32:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2019-02-14 22:11:37 +01:00
|
|
|
ircd::m::dbs::desc::events__event_auth
|
2018-02-08 22:23:01 +01:00
|
|
|
{
|
|
|
|
// name
|
2019-02-14 22:11:37 +01:00
|
|
|
"_event_auth",
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
// explanation
|
2019-02-14 22:11:37 +01:00
|
|
|
R"(Inverse reference graph of events.
|
|
|
|
|
|
|
|
event_idx | ref, event_idx => --
|
|
|
|
|
|
|
|
The first part of the key is the event being referenced. The second part
|
|
|
|
of the key is the event which refers to the first event somewhere in its
|
|
|
|
prev_events references. The event_idx in the second part of the key also
|
|
|
|
contains a dbs::ref type in its highest order byte so we can store
|
|
|
|
different kinds of references.
|
|
|
|
|
|
|
|
The prefix transform is in effect; an event may be referenced multiple
|
|
|
|
times. We can find all the events we have which reference a target, and
|
|
|
|
why. The database must already contain both events (hence they have
|
|
|
|
event::idx numbers).
|
|
|
|
|
|
|
|
The value is currently unused/empty; we may eventually store metadata with
|
|
|
|
information about this reference (i.e. is depth adjacent? is the ref
|
|
|
|
redundant with another in the same event and should not be made? etc).
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-04-18 04:14:39 +02:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
2019-02-14 22:11:37 +01:00
|
|
|
events__event_auth__cmp,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
|
|
|
// prefix transform
|
2019-02-14 22:11:37 +01:00
|
|
|
events__event_auth__pfx,
|
2018-04-18 06:39:40 +02:00
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
2018-04-18 06:39:40 +02:00
|
|
|
true,
|
2018-09-03 05:32:34 +02:00
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2019-01-24 01:11:26 +01:00
|
|
|
ircd::m::dbs::desc::events__event_bad
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
// name
|
2019-01-24 01:11:26 +01:00
|
|
|
"_event_bad",
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
// explanation
|
2019-01-24 01:11:26 +01:00
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
)",
|
2018-01-26 21:26:09 +01:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
// typing (key, value)
|
2018-01-26 21:26:09 +01:00
|
|
|
{
|
2019-01-24 01:11:26 +01:00
|
|
|
typeid(string_view), typeid(uint64_t)
|
2018-04-18 06:39:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
2018-11-03 02:31:20 +01:00
|
|
|
true,
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|
|
|
|
|
2019-01-24 22:05:48 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events_auth_events
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"auth_events",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2018-11-30 23:44:16 +01:00
|
|
|
const ircd::db::descriptor
|
2019-01-24 21:39:28 +01:00
|
|
|
ircd::m::dbs::desc::events_hashes
|
2018-11-30 23:44:16 +01:00
|
|
|
{
|
|
|
|
// name
|
2019-01-24 21:39:28 +01:00
|
|
|
"hashes",
|
2018-11-30 23:44:16 +01:00
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
2019-01-24 21:39:28 +01:00
|
|
|
typeid(uint64_t), typeid(string_view)
|
2018-11-30 23:44:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-01-24 20:12:15 +01:00
|
|
|
const ircd::db::descriptor
|
2019-01-24 21:39:28 +01:00
|
|
|
ircd::m::dbs::desc::events_membership
|
2019-01-24 20:12:15 +01:00
|
|
|
{
|
|
|
|
// name
|
2019-01-24 21:39:28 +01:00
|
|
|
"membership",
|
|
|
|
|
|
|
|
// explanation
|
2019-01-24 22:16:34 +01:00
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
2019-01-24 21:39:28 +01:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-01-26 02:37:30 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events_origin
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"origin",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-02-14 22:11:37 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events_prev_events
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"prev_events",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-01-24 21:39:28 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events_prev_state
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"prev_state",
|
2019-01-24 20:12:15 +01:00
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
2019-01-24 21:39:28 +01:00
|
|
|
typeid(uint64_t), typeid(ircd::string_view)
|
2019-01-24 20:12:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-01-24 21:45:16 +01:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events_redacts
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"redacts",
|
|
|
|
|
|
|
|
// explanation
|
2019-01-24 22:16:34 +01:00
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
2019-01-24 21:45:16 +01:00
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-01-24 20:12:41 +01:00
|
|
|
const ircd::db::descriptor
|
2019-01-24 21:39:28 +01:00
|
|
|
ircd::m::dbs::desc::events_signatures
|
2019-01-24 20:12:41 +01:00
|
|
|
{
|
|
|
|
// name
|
2019-01-24 21:39:28 +01:00
|
|
|
"signatures",
|
2019-01-24 20:12:41 +01:00
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(uint64_t), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2019-06-15 00:58:49 +02:00
|
|
|
const ircd::db::descriptor
|
|
|
|
ircd::m::dbs::desc::events__state_node
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"_state_node",
|
|
|
|
|
|
|
|
// explanation
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This column is deprecated and has been dropped from the schema. This
|
|
|
|
descriptor will erase its presence in the database upon next open.
|
|
|
|
|
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(ircd::string_view), typeid(ircd::string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
|
|
|
// drop column
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::descriptor
|
2018-05-15 03:09:20 +02:00
|
|
|
ircd::m::dbs::desc::events__default
|
|
|
|
{
|
|
|
|
// name
|
|
|
|
"default",
|
|
|
|
|
|
|
|
// explanation
|
2018-10-27 22:23:43 +02:00
|
|
|
R"(This column is unused but required by the database software.
|
|
|
|
|
2018-05-15 03:09:20 +02:00
|
|
|
)",
|
|
|
|
|
|
|
|
// typing (key, value)
|
|
|
|
{
|
|
|
|
typeid(string_view), typeid(string_view)
|
|
|
|
},
|
|
|
|
|
|
|
|
// options
|
|
|
|
{},
|
|
|
|
|
|
|
|
// comparator
|
|
|
|
{},
|
|
|
|
|
|
|
|
// prefix transform
|
|
|
|
{},
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
// drop column
|
|
|
|
false,
|
|
|
|
|
2018-05-15 03:09:20 +02:00
|
|
|
// cache size
|
|
|
|
0_MiB,
|
|
|
|
|
|
|
|
// cache size for compressed assets
|
|
|
|
0_MiB,
|
|
|
|
|
|
|
|
// bloom filter bits
|
|
|
|
0,
|
|
|
|
|
|
|
|
// expect queries hit
|
|
|
|
false,
|
|
|
|
};
|
|
|
|
|
2018-11-30 23:43:51 +01:00
|
|
|
//
|
|
|
|
// Description vector
|
|
|
|
//
|
|
|
|
|
2018-09-20 00:38:37 +02:00
|
|
|
const ircd::db::description
|
2018-02-08 22:23:01 +01:00
|
|
|
ircd::m::dbs::desc::events
|
|
|
|
{
|
|
|
|
// Requirement of RocksDB/LevelDB
|
2018-05-15 03:09:20 +02:00
|
|
|
events__default,
|
2018-02-08 22:23:01 +01:00
|
|
|
|
|
|
|
//
|
2018-04-18 04:14:39 +02:00
|
|
|
// These columns directly represent event fields indexed by event_idx
|
|
|
|
// number and the value is the actual event values. Some values may be
|
|
|
|
// JSON, like content.
|
2018-02-08 22:23:01 +01:00
|
|
|
//
|
2018-04-13 04:26:33 +02:00
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
events_content,
|
|
|
|
events_depth,
|
|
|
|
events_event_id,
|
|
|
|
events_origin,
|
|
|
|
events_origin_server_ts,
|
|
|
|
events_room_id,
|
|
|
|
events_sender,
|
|
|
|
events_state_key,
|
|
|
|
events_type,
|
|
|
|
|
|
|
|
//
|
2018-04-18 04:14:39 +02:00
|
|
|
// These columns are metadata oriented around the event data.
|
2018-02-08 22:23:01 +01:00
|
|
|
//
|
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
// event_id => uint64_t
|
|
|
|
// Mapping of event_id to index number.
|
|
|
|
events__event_idx,
|
|
|
|
|
2019-01-15 22:01:29 +01:00
|
|
|
// event_idx => json
|
|
|
|
// Mapping of event_idx to full json
|
|
|
|
events__event_json,
|
|
|
|
|
2019-02-06 02:18:53 +01:00
|
|
|
// event_idx | event_idx
|
|
|
|
// Reverse mapping of the event reference graph.
|
|
|
|
events__event_refs,
|
|
|
|
|
2019-05-09 09:02:33 +02:00
|
|
|
// event_idx | event_idx
|
|
|
|
// Mapping of unresolved event refs.
|
|
|
|
events__event_horizon,
|
|
|
|
|
2019-04-16 22:41:55 +02:00
|
|
|
// origin | sender, event_idx
|
|
|
|
// Mapping of senders to event_idx's they are the sender of.
|
|
|
|
events__event_sender,
|
|
|
|
|
2019-04-16 22:42:18 +02:00
|
|
|
// type | event_idx
|
|
|
|
// Mapping of type strings to event_idx's of that type.
|
|
|
|
events__event_type,
|
|
|
|
|
2019-06-15 00:58:49 +02:00
|
|
|
// (room_id, (depth, event_idx))
|
2018-02-08 22:23:01 +01:00
|
|
|
// Sequence of all events for a room, ever.
|
|
|
|
events__room_events,
|
2018-03-03 07:03:06 +01:00
|
|
|
|
2019-06-15 00:58:49 +02:00
|
|
|
// (room_id, (origin, user_id))
|
2018-04-15 23:40:10 +02:00
|
|
|
// Sequence of all PRESENTLY JOINED joined for a room.
|
|
|
|
events__room_joined,
|
2018-03-04 08:39:24 +01:00
|
|
|
|
2019-05-12 02:48:35 +02:00
|
|
|
// (room_id, (type, state_key)) => (event_idx)
|
2018-03-04 08:39:24 +01:00
|
|
|
// Sequence of the PRESENT STATE of the room.
|
|
|
|
events__room_state,
|
2018-04-03 11:11:49 +02:00
|
|
|
|
2019-05-12 02:48:35 +02:00
|
|
|
// (room_id, (type, state_key, depth, event_idx))
|
|
|
|
// Sequence of all states of the room.
|
2019-05-13 19:29:20 +02:00
|
|
|
events__room_state_space,
|
2019-05-12 02:48:35 +02:00
|
|
|
|
2018-09-03 05:33:39 +02:00
|
|
|
// (room_id, event_id) => (event_idx)
|
|
|
|
// Mapping of all current head events for a room.
|
|
|
|
events__room_head,
|
2018-11-30 23:44:16 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// These columns are legacy; they have been dropped from the schema.
|
|
|
|
//
|
|
|
|
|
2019-01-24 22:05:48 +01:00
|
|
|
events_auth_events,
|
2019-01-24 20:12:41 +01:00
|
|
|
events_hashes,
|
2019-01-24 21:39:28 +01:00
|
|
|
events_membership,
|
2019-02-14 22:11:37 +01:00
|
|
|
events_prev_events,
|
2019-01-24 01:11:26 +01:00
|
|
|
events_prev_state,
|
2019-01-24 21:45:16 +01:00
|
|
|
events_redacts,
|
2019-01-24 20:12:15 +01:00
|
|
|
events_signatures,
|
2019-02-14 22:11:37 +01:00
|
|
|
events__event_auth,
|
2019-01-24 22:16:34 +01:00
|
|
|
events__event_bad,
|
2019-06-15 00:58:49 +02:00
|
|
|
events__state_node,
|
2018-02-08 22:23:01 +01:00
|
|
|
};
|