0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd:Ⓜ️:event: Start an event::horizon interface around dbs::event_horizon.

This commit is contained in:
Jason Volk 2019-05-16 23:57:51 -07:00
parent ff61342c01
commit 5721920957
4 changed files with 139 additions and 10 deletions

View file

@ -95,6 +95,7 @@ struct ircd::m::event
{
struct prev;
struct refs;
struct horizon;
struct auth;
struct fetch;
struct conforms;
@ -138,6 +139,7 @@ struct ircd::m::event
#include "prev.h"
#include "refs.h"
#include "horizon.h"
#include "auth.h"
#include "index.h"
#include "event_id.h"

View file

@ -0,0 +1,47 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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_EVENT_HORIZON_H
/// Interface to the set of unresolved events. This set contains event_id's
/// which the server does not have. For each event_id in the set, there is an
/// event::idx of an event which made a reference to the event_id. There may be
/// multiple entries for an event_id.
///
/// This information helps construct the dependency graph in event::refs out of
/// order; it is anti-reference which is removed after the event is processed.
/// Each event::idx for an event_id in the set is then able to be "reprocessed"
/// in some way; at a minimum the reprocessing removes the event_id|event::idx
/// entry (see: dbs/event_horizon related).
///
class ircd::m::event::horizon
{
event::id event_id;
public:
using closure_bool = event::closure_idx_bool;
bool for_each(const closure_bool &) const;
bool has(const event::idx &) const;
size_t count() const;
horizon(const event::id &);
static bool has(const event::id &);
static size_t rebuild();
};
inline
ircd::m::event::horizon::horizon(const event::id &event_id)
:event_id{event_id}
{
assert(event_id);
}

View file

@ -2555,6 +2555,89 @@ ircd::m::event::auth::chain::for_each(const auth::chain &c,
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// event/horizon.h
//
size_t
ircd::m::event::horizon::rebuild()
{
throw not_implemented{};
}
bool
ircd::m::event::horizon::has(const event::id &event_id)
{
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
const string_view &key
{
m::dbs::event_horizon_key(buf, event_id, 0UL)
};
auto it
{
m::dbs::event_horizon.begin(key)
};
return bool(it);
}
size_t
ircd::m::event::horizon::count()
const
{
size_t ret(0);
for_each([&ret](const auto &)
{
++ret;
return true;
});
return ret;
}
bool
ircd::m::event::horizon::has(const event::idx &event_idx)
const
{
return !for_each([&event_idx]
(const auto &_event_idx)
{
// false to break; true to continue.
return _event_idx == event_idx? false : true;
});
}
bool
ircd::m::event::horizon::for_each(const closure_bool &closure)
const
{
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
const string_view &key
{
m::dbs::event_horizon_key(buf, event_id, 0UL)
};
auto it
{
m::dbs::event_horizon.begin(key)
};
for(; it; ++it)
{
const auto &event_idx
{
std::get<0>(m::dbs::event_horizon_key(it->first))
};
if(!closure(event_idx))
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// event/refs.h

View file

@ -6454,19 +6454,14 @@ console_cmd__event__horizon(opt &out, const string_view &line)
return true;
}
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
const string_view &key
const m::event::horizon horizon
{
m::dbs::event_horizon_key(buf, event_id, 0UL)
event_id
};
for(auto it(m::dbs::event_horizon.begin(key)); it; ++it)
horizon.for_each([&out, &event_id]
(const auto &event_idx)
{
const auto &event_idx
{
std::get<0>(m::dbs::event_horizon_key(it->first))
};
const auto _event_id
{
m::event_id(event_idx, std::nothrow)
@ -6478,7 +6473,9 @@ console_cmd__event__horizon(opt &out, const string_view &line)
<< " "
<< _event_id
<< std::endl;
}
return true;
});
return true;
}