]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: introduce watchers to ObjectContext.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 27 Nov 2019 16:21:31 +0000 (17:21 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 13 Feb 2020 23:11:35 +0000 (00:11 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/osd/object_context.h
src/crimson/osd/watch.h [new file with mode: 0644]

index 69af42c22092f11c7d432acec470d888f5eaf9c4..e0822e1c5bc22073b7f62cb3a6b34d3fb779500d 100644 (file)
@@ -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<SnapSet> 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<uint64_t, entity_name_t>;
+  std::map<watch_key_t, crimson::osd::WatchRef> 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 (file)
index 0000000..3b03a81
--- /dev/null
@@ -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 <seastar/core/shared_ptr.hh>
+
+#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<Watch> {
+  // 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 <class... Args>
+  static seastar::shared_ptr<Watch> create(Args&&... args) {
+    return seastar::make_shared<Watch>(private_ctag_t{},
+                                       std::forward<Args>(args)...);
+  };
+};
+
+using WatchRef = seastar::shared_ptr<Watch>;
+
+} // namespace crimson::osd