]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/osd/SnapMapper.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / osd / SnapMapper.h
index 90b0c7c8d82e1b4c5141b8918e275f1ffa4a2e28..eb43a23c2b0e0b3373b5d3bba731c2f8eff68ab7 100644 (file)
 #ifndef SNAPMAPPER_H
 #define SNAPMAPPER_H
 
-#include <string>
+#include <cstring>
 #include <set>
+#include <string>
 #include <utility>
-#include <cstring>
 
-#include "common/map_cacher.hpp"
 #include "common/hobject.h"
+#include "common/map_cacher.hpp"
+#ifdef WITH_SEASTAR
+#  include "crimson/os/futurized_store.h"
+#  include "crimson/os/futurized_collection.h"
+#endif
 #include "include/buffer.h"
 #include "include/encoding.h"
 #include "include/object.h"
 #include "os/ObjectStore.h"
 #include "osd/OSDMap.h"
+#include "osd/SnapMapReaderI.h"
 
 class OSDriver : public MapCacher::StoreDriver<std::string, ceph::buffer::list> {
-  ObjectStore *os;
-  ObjectStore::CollectionHandle ch;
+#ifdef WITH_SEASTAR
+  using ObjectStoreT = crimson::os::FuturizedStore::Shard;
+  using CollectionHandleT = ObjectStoreT::CollectionRef;
+#else
+  using ObjectStoreT = ObjectStore;
+  using CollectionHandleT = ObjectStoreT::CollectionHandle;
+#endif
+
+  ObjectStoreT *os;
+  CollectionHandleT ch;
   ghobject_t hoid;
 
 public:
@@ -38,11 +51,11 @@ public:
     friend class OSDriver;
     coll_t cid;
     ghobject_t hoid;
-    ObjectStore::Transaction *t;
+    ceph::os::Transaction *t;
     OSTransaction(
       const coll_t &cid,
       const ghobject_t &hoid,
-      ObjectStore::Transaction *t)
+      ceph::os::Transaction *t)
       : cid(cid), hoid(hoid), t(t) {}
   public:
     void set_keys(
@@ -60,21 +73,28 @@ public:
   };
 
   OSTransaction get_transaction(
-    ObjectStore::Transaction *t) {
-    return OSTransaction(ch->cid, hoid, t);
+    ceph::os::Transaction *t) const {
+    return OSTransaction(ch->get_cid(), hoid, t);
   }
 
-  OSDriver(ObjectStore *os, const coll_t& cid, const ghobject_t &hoid) :
+#ifndef WITH_SEASTAR
+  OSDriver(ObjectStoreT *os, const coll_t& cid, const ghobject_t &hoid) :
+    OSDriver(os, os->open_collection(cid), hoid) {}
+#endif
+  OSDriver(ObjectStoreT *os, CollectionHandleT ch, const ghobject_t &hoid) :
     os(os),
-    hoid(hoid) {
-    ch = os->open_collection(cid);
-  }
+    ch(ch),
+    hoid(hoid) {}
+
   int get_keys(
     const std::set<std::string> &keys,
     std::map<std::string, ceph::buffer::list> *out) override;
   int get_next(
     const std::string &key,
     std::pair<std::string, ceph::buffer::list> *next) override;
+  int get_next_or_current(
+    const std::string &key,
+    std::pair<std::string, ceph::buffer::list> *next_or_current) override;
 };
 
 /**
@@ -99,8 +119,9 @@ public:
  * snap will sort together, and so that all objects in a pg for a
  * particular snap will group under up to 8 prefixes.
  */
-class SnapMapper {
-  friend class MapperVerifier;
+class SnapMapper : public Scrub::SnapMapReaderI {
+  friend class MapperVerifier; // unit-test support
+  friend class DirectMapper; // unit-test support
 public:
   CephContext* cct;
   struct object_snaps {
@@ -139,6 +160,7 @@ public:
   static const char *PURGED_SNAP_EPOCH_PREFIX;
   static const char *PURGED_SNAP_PREFIX;
 
+#ifndef WITH_SEASTAR
   struct Scrubber {
     CephContext *cct;
     ObjectStore *store;
@@ -185,27 +207,18 @@ public:
     ObjectStore::CollectionHandle& ch,
     ghobject_t hoid,
     unsigned max);
+#endif
 
   static void record_purged_snaps(
     CephContext *cct,
-    ObjectStore *store,
-    ObjectStore::CollectionHandle& ch,
-    ghobject_t hoid,
-    ObjectStore::Transaction *t,
+    OSDriver& backend,
+    OSDriver::OSTransaction&& txn,
     std::map<epoch_t,mempool::osdmap::map<int64_t,snap_interval_set_t>> purged_snaps);
-  static void scrub_purged_snaps(
-    CephContext *cct,
-    ObjectStore *store,
-    ObjectStore::CollectionHandle& ch,
-    ghobject_t mapper_hoid,
-    ghobject_t purged_snaps_hoid);
 
 private:
   static int _lookup_purged_snap(
     CephContext *cct,
-    ObjectStore *store,
-    ObjectStore::CollectionHandle& ch,
-    const ghobject_t& hoid,
+    OSDriver& backend,
     int64_t pool, snapid_t snap,
     snapid_t *begin, snapid_t *end);
   static void make_purged_snap_key_value(
@@ -213,8 +226,9 @@ private:
     snapid_t end, std::map<std::string,ceph::buffer::list> *m);
   static std::string make_purged_snap_key(int64_t pool, snapid_t last);
 
-
-  MapCacher::MapCacher<std::string, ceph::buffer::list> backend;
+  // note: marked 'mutable', as functions as a cache and used in some 'const'
+  // functions.
+  mutable MapCacher::MapCacher<std::string, ceph::buffer::list> backend;
 
   static std::string get_legacy_prefix(snapid_t snap);
   std::string to_legacy_raw_key(
@@ -223,19 +237,28 @@ private:
 
   static std::string get_prefix(int64_t pool, snapid_t snap);
   std::string to_raw_key(
-    const std::pair<snapid_t, hobject_t> &to_map);
+    const std::pair<snapid_t, hobject_t> &to_map) const;
+
+  std::string to_raw_key(snapid_t snap, const hobject_t& clone) const;
 
   std::pair<std::string, ceph::buffer::list> to_raw(
-    const std::pair<snapid_t, hobject_t> &to_map);
+    const std::pair<snapid_t, hobject_t> &to_map) const;
 
   static bool is_mapping(const std::string &to_test);
 
   static std::pair<snapid_t, hobject_t> from_raw(
     const std::pair<std::string, ceph::buffer::list> &image);
 
-  std::string to_object_key(const hobject_t &hoid);
+  static std::pair<snapid_t, hobject_t> from_raw(
+    const ceph::buffer::list& image);
+
+  std::string to_object_key(const hobject_t &hoid) const;
 
-  int get_snaps(const hobject_t &oid, object_snaps *out);
+  int get_snaps(const hobject_t &oid, object_snaps *out) const;
+
+  std::set<std::string> to_raw_keys(
+    const hobject_t &clone,
+    const std::set<snapid_t> &snaps) const;
 
   void set_snaps(
     const hobject_t &oid,
@@ -254,7 +277,11 @@ private:
     MapCacher::Transaction<std::string, ceph::buffer::list> *t ///< [out] transaction
     );
 
-public:
+  /// Get snaps (as an 'object_snaps' object) for oid
+  tl::expected<object_snaps, SnapMapReaderI::result_t> get_snaps_common(
+    const hobject_t &hoid) const;
+
+ public:
   static std::string make_shard_prefix(shard_id_t shard) {
     if (shard == shard_id_t::NO_SHARD)
       return std::string();
@@ -330,7 +357,20 @@ public:
   int get_snaps(
     const hobject_t &oid,     ///< [in] oid to get snaps for
     std::set<snapid_t> *snaps ///< [out] snaps
-    ); ///< @return error, -ENOENT if oid is not recorded
+    ) const; ///< @return error, -ENOENT if oid is not recorded
+
+  /// Get snaps for oid - alternative interface
+  tl::expected<std::set<snapid_t>, SnapMapReaderI::result_t> get_snaps(
+    const hobject_t &hoid) const final;
+
+  /**
+   * get_snaps_check_consistency
+   *
+   * Returns snaps for hoid as in get_snaps(), but additionally validates the
+   * snap->hobject_t mappings ('SNA_' entries).
+   */
+  tl::expected<std::set<snapid_t>, SnapMapReaderI::result_t>
+  get_snaps_check_consistency(const hobject_t &hoid) const final;
 };
 WRITE_CLASS_ENCODER(SnapMapper::object_snaps)
 WRITE_CLASS_ENCODER(SnapMapper::Mapping)