]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/CollectionIndex: Add debugging constructor and Path::coll()
authorSamuel Just <rexludorum@gmail.com>
Fri, 3 Feb 2012 16:56:04 +0000 (08:56 -0800)
committerSamuel Just <samuel.just@dreamhost.com>
Thu, 1 Mar 2012 18:11:42 +0000 (10:11 -0800)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/os/CollectionIndex.h
src/os/FlatIndex.cc
src/os/FlatIndex.h
src/os/HashIndex.h
src/os/IndexManager.cc
src/os/LFNIndex.h

index caff6ac95f3c2cc91bca18e3edbc254aa124ffb8..0efa6459ec805fc606883be33183ab4ad0d30734 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "osd/osd_types.h"
 #include "include/object.h"
-#include "ObjectStore.h"
 
 /**
  * CollectionIndex provides an interface for manipulating indexed colelctions
@@ -45,19 +44,35 @@ protected:
     string full_path;
     /// Ref to parent Index
     std::tr1::shared_ptr<CollectionIndex> parent_ref;
-    /// Constructor
+    /// coll_t for parent Index
+    coll_t parent_coll;
+
+    /// Normal Constructor
     Path(
       string path,                              ///< [in] Path to return.
       std::tr1::weak_ptr<CollectionIndex> ref)  ///< [in] weak_ptr to parent.
-      : full_path(path), parent_ref(ref) {}
+      : full_path(path), parent_ref(ref), parent_coll(parent_ref->coll()) {}
+
+    /// Debugging Constructor
+    Path(
+      string path,                              ///< [in] Path to return.
+      coll_t coll)                              ///< [in] collection
+      : full_path(path), parent_coll(coll) {}
       
     /// Getter for the stored path.
     const char *path() const { return full_path.c_str(); }
+
+    /// Getter for collection
+    coll_t coll() const { return parent_coll; }
   };
  public:
   /// Type of returned paths
   typedef std::tr1::shared_ptr<Path> IndexedPath;
 
+  static IndexedPath get_testing_path(string path, coll_t collection) {
+    return IndexedPath(new Path(path, collection));
+  }
+
   static const uint32_t FLAT_INDEX_TAG = 0;
   static const uint32_t HASH_INDEX_TAG = 1;
   static const uint32_t HASH_INDEX_TAG_2 = 2;
@@ -68,6 +83,11 @@ protected:
    */
   virtual uint32_t collection_version() = 0;
 
+  /**
+   * Returns the collection managed by this CollectionIndex
+   */
+  virtual coll_t coll() const = 0;
+
   /** 
    * For setting the internal weak_ptr to a shared_ptr to this.
    *
index 0fecfe5b2d45570e9ee57d2be292f9b6cb81fa19..7a1bfba43adf7fff2ec5f6a067b045752b7d8a61 100644 (file)
@@ -21,6 +21,7 @@
 #include "CollectionIndex.h"
 #include "common/ceph_crypto.h"
 #include "osd/osd_types.h"
+#include <errno.h>
 
 using ceph::crypto::SHA1;
 
index fc6362139df96e48ea928fde7a92cfb8209a754c..7a10912dc2860378af97bcaa92cd2548ed4662a1 100644 (file)
 class FlatIndex : public CollectionIndex {
   std::tr1::weak_ptr<CollectionIndex> self_ref;
   string base_path;
+  coll_t collection;
 public:
-  FlatIndex(string base_path) : base_path(base_path) {}
+  FlatIndex(coll_t collection, string base_path) : base_path(base_path),
+                                                  collection(collection) {}
 
   /// @see CollectionIndex
   uint32_t collection_version() { return FLAT_INDEX_TAG; }
 
+  coll_t coll() const { return collection; }
+
   /// @see CollectionIndex
   void set_ref(std::tr1::shared_ptr<CollectionIndex> ref);
 
index 8f6ebfb11233c72c34e697b907ce8ead2b9f85d1..cb0a3d2da20ce46f7a45aaf403c3ce173c17e745 100644 (file)
@@ -130,11 +130,12 @@ private:
 public:
   /// Constructor.
   HashIndex(
+    coll_t collection,     ///< [in] Collection
     const char *base_path, ///< [in] Path to the index root.
     int merge_at,          ///< [in] Merge threshhold.
     int split_multiple,           ///< [in] Split threshhold.
     uint32_t index_version)///< [in] Index version
-    : LFNIndex(base_path, index_version), merge_threshold(merge_at),
+    : LFNIndex(collection, base_path, index_version), merge_threshold(merge_at),
       split_multiplier(split_multiple) {}
 
   /// @see CollectionIndex
index 0fab6fe6bd2d2d830ad02a6eb02129cb18c8a445..808525edcc7d1aa043c9f6c6d71a5f2636401e7a 100644 (file)
@@ -73,7 +73,7 @@ int IndexManager::init_index(coll_t c, const char *path, uint32_t version) {
   int r = set_version(path, version);
   if (r < 0)
     return r;
-  HashIndex index(path, g_conf->filestore_merge_threshold, 
+  HashIndex index(c, path, g_conf->filestore_merge_threshold,
                  g_conf->filestore_split_multiple,
                  CollectionIndex::HASH_INDEX_TAG_2);
   return index.init();
@@ -90,14 +90,14 @@ int IndexManager::build_index(coll_t c, const char *path, Index *index) {
 
     switch (version) {
     case CollectionIndex::FLAT_INDEX_TAG: {
-      *index = Index(new FlatIndex(path), 
+      *index = Index(new FlatIndex(c, path),
                     RemoveOnDelete(c, this));
       return 0;
     }
     case CollectionIndex::HASH_INDEX_TAG: // fall through
     case CollectionIndex::HASH_INDEX_TAG_2: {
       // Must be a HashIndex
-      *index = Index(new HashIndex(path, g_conf->filestore_merge_threshold,
+      *index = Index(new HashIndex(c, path, g_conf->filestore_merge_threshold,
                                   g_conf->filestore_split_multiple, version), 
                     RemoveOnDelete(c, this));
       return 0;
@@ -107,7 +107,7 @@ int IndexManager::build_index(coll_t c, const char *path, Index *index) {
 
   } else {
     // No need to check
-    *index = Index(new HashIndex(path, g_conf->filestore_merge_threshold,
+    *index = Index(new HashIndex(c, path, g_conf->filestore_merge_threshold,
                                 g_conf->filestore_split_multiple,
                                 CollectionIndex::HASH_INDEX_TAG_2), 
                   RemoveOnDelete(c, this));
index 767db8cd40404bac613083bc178ee23c5ba5c928..54578a68dcf25c055b4fc0a89e303fe9a6eafd5d 100644 (file)
@@ -81,13 +81,16 @@ protected:
 
 private:
   string lfn_attribute;
+  coll_t collection;
 
 public:
   /// Constructor
   LFNIndex(
+    coll_t collection,
     const char *base_path, ///< [in] path to Index root
     uint32_t index_version)
-    : base_path(base_path), index_version(index_version) {
+    : base_path(base_path), index_version(index_version),
+      collection(collection) {
     if (index_version == HASH_INDEX_TAG) {
       lfn_attribute = LFN_ATTR;
     } else {
@@ -97,6 +100,8 @@ public:
     }
   }
 
+  coll_t coll() const { return collection; }
+
   /// Virtual destructor
   virtual ~LFNIndex() {}