From c05e391c5cf6cd180f78c4697e7db272876e77b7 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 27 Nov 2019 17:21:31 +0100 Subject: [PATCH] crimson: introduce watchers to ObjectContext. Signed-off-by: Radoslaw Zarzynski --- src/crimson/osd/object_context.h | 7 +++++ src/crimson/osd/watch.h | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/crimson/osd/watch.h diff --git a/src/crimson/osd/object_context.h b/src/crimson/osd/object_context.h index 69af42c2209..e0822e1c5bc 100644 --- a/src/crimson/osd/object_context.h +++ b/src/crimson/osd/object_context.h @@ -14,6 +14,7 @@ #include "osd/object_state.h" #include "crimson/common/config_proxy.h" #include "crimson/osd/osd_operation.h" +#include "crimson/osd/watch.h" namespace crimson::osd { @@ -35,6 +36,12 @@ public: ObjectState obs; std::optional ss; bool loaded : 1; + // the watch / notify machinery rather stays away from the hot and + // frequented paths. std::map is used mostly because of developer's + // convenience. + using watch_key_t = std::pair; + std::map watchers; + ObjectContext(const hobject_t &hoid) : obs(hoid), loaded(false) {} const hobject_t &get_oid() const { diff --git a/src/crimson/osd/watch.h b/src/crimson/osd/watch.h new file mode 100644 index 00000000000..3b03a81bae8 --- /dev/null +++ b/src/crimson/osd/watch.h @@ -0,0 +1,53 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include + +#include "crimson/net/Connection.h" + +namespace crimson::osd { + +// NOTE: really need to have this public. Otherwise `shared_from_this()` +// will abort. According to cppreference.com: +// +// "The constructors of std::shared_ptr detect the presence +// of an unambiguous and accessible (ie. public inheritance +// is mandatory) (since C++17) enable_shared_from_this base". +// +// I expect the `seastar::shared_ptr` shares this behaviour. +class Watch : public seastar::enable_shared_from_this { + // 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(). + struct private_ctag_t{}; + +public: + Watch(private_ctag_t) { + } + + seastar::future<> connect(crimson::net::ConnectionRef, bool) { + return seastar::now(); + } + bool is_connected() const { + return true; + } + void got_ping(utime_t) { + // NOP + } + + seastar::future<> remove(bool) { + return seastar::now(); + } + + template + static seastar::shared_ptr create(Args&&... args) { + return seastar::make_shared(private_ctag_t{}, + std::forward(args)...); + }; +}; + +using WatchRef = seastar::shared_ptr; + +} // namespace crimson::osd -- 2.39.5