2019-01-03 17:21:02 -08:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_SYNC_H
|
|
|
|
|
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
struct client;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ircd::m::sync
|
|
|
|
{
|
|
|
|
struct args;
|
|
|
|
struct stats;
|
|
|
|
struct data;
|
|
|
|
struct item;
|
2019-01-08 15:10:06 -08:00
|
|
|
using item_closure = std::function<void (item &)>;
|
|
|
|
using item_closure_bool = std::function<bool (item &)>;
|
|
|
|
|
|
|
|
string_view loghead(const data &);
|
|
|
|
|
2020-01-06 12:51:34 -08:00
|
|
|
string_view make_since(const mutable_buffer &, const int64_t &);
|
|
|
|
string_view make_since(const mutable_buffer &, const m::events::range &);
|
|
|
|
|
2019-01-08 15:10:06 -08:00
|
|
|
bool apropos(const data &, const event::idx &);
|
|
|
|
bool apropos(const data &, const event::id &);
|
|
|
|
bool apropos(const data &, const event &);
|
|
|
|
|
|
|
|
bool for_each(const string_view &prefix, const item_closure_bool &);
|
|
|
|
bool for_each(const item_closure_bool &);
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
extern log::log log;
|
2019-01-08 15:10:06 -08:00
|
|
|
extern ctx::pool pool;
|
2019-02-22 11:13:55 -08:00
|
|
|
extern conf::item<bool> stats_info;
|
2019-01-03 17:21:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::m::sync::item
|
|
|
|
:instance_multimap<std::string, item, std::less<>>
|
|
|
|
{
|
2019-02-24 11:59:53 -08:00
|
|
|
using handle = std::function<bool (data &)>;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
2019-02-22 17:05:28 -08:00
|
|
|
std::string conf_name[2];
|
|
|
|
conf::item<bool> enable;
|
|
|
|
conf::item<bool> stats_debug;
|
2019-01-03 17:21:02 -08:00
|
|
|
handle _polylog;
|
|
|
|
handle _linear;
|
2019-04-08 01:53:09 -07:00
|
|
|
json::strung feature;
|
|
|
|
json::object opts;
|
2019-04-08 02:04:24 -07:00
|
|
|
bool phased;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
string_view name() const;
|
2019-01-08 15:10:06 -08:00
|
|
|
string_view member_name() const;
|
2019-07-06 20:42:45 -07:00
|
|
|
size_t children() const;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
2019-02-24 11:59:53 -08:00
|
|
|
bool linear(data &);
|
|
|
|
bool polylog(data &);
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
item(std::string name,
|
2019-04-08 01:53:09 -07:00
|
|
|
handle polylog = {},
|
|
|
|
handle linear = {},
|
|
|
|
const json::members & = {});
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
item(item &&) = delete;
|
|
|
|
item(const item &) = delete;
|
|
|
|
~item() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::m::sync::data
|
2019-07-06 20:17:42 -07:00
|
|
|
:instance_list<ircd::m::sync::data>
|
2019-01-03 17:21:02 -08:00
|
|
|
{
|
2019-01-10 13:19:07 -08:00
|
|
|
/// Range to synchronize. Starting index is inclusive, ending index is
|
|
|
|
/// exclusive. Generally the starting index is a since token, and ending
|
|
|
|
/// index is one beyond the vm::current_sequence and used for next_batch.
|
|
|
|
m::events::range range;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
2019-04-08 02:04:24 -07:00
|
|
|
/// Whether to enable phased sync mode. The range.first will be <= 0
|
|
|
|
/// in this case, and only handlers with the phased feature
|
|
|
|
bool phased {false};
|
|
|
|
|
2019-01-10 13:19:07 -08:00
|
|
|
/// Statistics tracking. If null, stats won't be accumulated for the sync.
|
|
|
|
sync::stats *stats {nullptr};
|
|
|
|
|
|
|
|
/// The client. This may be null if sync is being called internally.
|
|
|
|
ircd::client *client {nullptr};
|
2019-07-07 19:55:56 -07:00
|
|
|
const sync::args *args {nullptr};
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
// User related
|
|
|
|
const m::user user;
|
|
|
|
const m::user::room user_room;
|
2019-01-08 15:10:06 -08:00
|
|
|
const m::room::state user_state;
|
2019-01-03 17:21:02 -08:00
|
|
|
const m::user::rooms user_rooms;
|
|
|
|
const std::string filter_buf;
|
|
|
|
const m::filter filter;
|
2019-08-06 19:18:03 -07:00
|
|
|
const device::id device_id;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
2019-01-10 13:19:07 -08:00
|
|
|
/// The json::stack master object
|
2019-02-26 15:50:58 -08:00
|
|
|
json::stack *out {nullptr};
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
// apropos contextual
|
|
|
|
const m::event *event {nullptr};
|
|
|
|
const m::room *room {nullptr};
|
|
|
|
string_view membership;
|
2019-04-15 12:16:48 -07:00
|
|
|
int64_t room_depth {0}; // if *room
|
2019-02-26 17:02:21 -08:00
|
|
|
event::idx room_head {0}; // if *room
|
|
|
|
event::idx event_idx {0}; // if *event
|
2019-02-28 18:28:45 -08:00
|
|
|
string_view client_txnid;
|
2019-01-03 17:21:02 -08:00
|
|
|
|
2019-01-10 13:19:07 -08:00
|
|
|
data(const m::user &user,
|
|
|
|
const m::events::range &range,
|
|
|
|
ircd::client *const &client = nullptr,
|
2019-02-26 15:50:58 -08:00
|
|
|
json::stack *const &out = nullptr,
|
2019-01-10 13:19:07 -08:00
|
|
|
sync::stats *const &stats = nullptr,
|
2019-08-06 19:18:03 -07:00
|
|
|
const sync::args *const &args = nullptr,
|
|
|
|
const device::id &device_id = {});
|
2019-01-03 17:21:02 -08:00
|
|
|
|
|
|
|
data(data &&) = delete;
|
|
|
|
data(const data &) = delete;
|
|
|
|
~data() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::m::sync::stats
|
|
|
|
{
|
|
|
|
ircd::timer timer;
|
|
|
|
size_t flush_bytes {0};
|
|
|
|
size_t flush_count {0};
|
|
|
|
};
|