From 9a3a5ebeafcf64776f78ce7cde280d40de8c7459 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 11 Dec 2019 10:13:41 +0100 Subject: [PATCH] crimson: create_n_propagate Signed-off-by: Radoslaw Zarzynski --- src/crimson/osd/ops_executer.cc | 10 ++++- src/crimson/osd/watch.h | 72 +++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/crimson/osd/ops_executer.cc b/src/crimson/osd/ops_executer.cc index 130663dd9ef..c1191f0c817 100644 --- a/src/crimson/osd/ops_executer.cc +++ b/src/crimson/osd/ops_executer.cc @@ -295,7 +295,15 @@ OpsExecuter::watch_errorator::future<> OpsExecuter::do_op_notify( return seastar::now(); }, [] (auto&& ctx, ObjectContextRef obc) { - return seastar::now(); + auto alive_watchers = obc->watchers | boost::adaptors::map_values + | boost::adaptors::filtered( + [] (const auto& w) { + // FIXME: filter as for the `is_ping` in `Watch::start_notify` + return w->is_alive(); + }); + return crimson::osd::Notify::create_n_propagate( + std::begin(alive_watchers), + std::end(alive_watchers)); }); } diff --git a/src/crimson/osd/watch.h b/src/crimson/osd/watch.h index ed8f4a84b15..f26c9cb1620 100644 --- a/src/crimson/osd/watch.h +++ b/src/crimson/osd/watch.h @@ -3,12 +3,18 @@ #pragma once +#include +#include + #include #include "crimson/net/Connection.h" namespace crimson::osd { +class Notify; +using NotifyRef = seastar::shared_ptr; + // NOTE: really need to have this public. Otherwise `shared_from_this()` // will abort. According to cppreference.com: // @@ -23,15 +29,27 @@ class Watch : public seastar::enable_shared_from_this { // used by create(). struct private_ctag_t{}; + struct NotifyCmp { + inline bool operator()(NotifyRef lhs, NotifyRef rhs) const; + }; + std::set in_progress_notifies; + crimson::net::ConnectionRef conn; + + seastar::future<> start_notify(NotifyRef); + seastar::future<> send_notify_msg(NotifyRef); + + friend Notify; + public: Watch(private_ctag_t) { } - seastar::future<> connect(crimson::net::ConnectionRef, bool) { - return seastar::now(); + seastar::future<> connect(crimson::net::ConnectionRef, bool); + bool is_alive() const { + return true; } bool is_connected() const { - return true; + return static_cast(conn); } void got_ping(utime_t) { // NOP @@ -57,4 +75,52 @@ public: using WatchRef = seastar::shared_ptr; +class Notify { + std::set watchers; + + uint64_t get_id() const { return 0; } + void propagate() {} + + template + Notify(WatchIteratorT begin, WatchIteratorT end); + // this is a private tag for the public constructor that turns it into + // de facto private one. The motivation behind the hack is make_shared + // used by create_n_propagate factory. + struct private_ctag_t{}; + + friend Watch; + +public: + template + Notify(private_ctag_t, Args&&... args) : Notify(std::forward(args)...) { + } + + template + static seastar::future<> create_n_propagate( + WatchIteratorT begin, + WatchIteratorT end); +}; + + +template +Notify::Notify(WatchIteratorT begin, WatchIteratorT end) + : watchers(begin, end) { +} + +template +seastar::future<> Notify::create_n_propagate( + WatchIteratorT begin, + WatchIteratorT end) +{ + static_assert( + std::is_same_v::value_type, + crimson::osd::WatchRef>); + auto notify = seastar::make_shared(private_ctag_t{}, begin, end); + seastar::do_for_each(begin, end, [=] (auto& watchref) { + return watchref->start_notify(notify); + }).then([notify = std::move(notify)] {; + notify->propagate(); + }); +} + } // namespace crimson::osd -- 2.39.5