]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ObjectMap: use Index object for locking rather than path object
authorSamuel Just <rexludorum@gmail.com>
Tue, 13 Mar 2012 16:43:21 +0000 (09:43 -0700)
committerSamuel Just <samuel.just@dreamhost.com>
Fri, 16 Mar 2012 18:29:00 +0000 (11:29 -0700)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/os/CollectionIndex.h
src/os/DBObjectMap.cc
src/os/DBObjectMap.h
src/os/FileStore.cc
src/os/HashIndex.cc
src/os/IndexManager.cc
src/os/LFNIndex.h
src/os/ObjectMap.h
src/test/ObjectMap/test_object_map.cc

index 0efa6459ec805fc606883be33183ab4ad0d30734..30e877c49234811a39104290d6cc2fbb0c858c58 100644 (file)
@@ -64,6 +64,11 @@ protected:
 
     /// Getter for collection
     coll_t coll() const { return parent_coll; }
+
+    /// Getter for parent
+    std::tr1::shared_ptr<CollectionIndex> get_index() const {
+      return parent_ref;
+    }
   };
  public:
   /// Type of returned paths
index 0586cd719e8af4a18fa21fd0fc6de5cb057dd25f..f425d88223c80e586a115bc102d3e50ebc2545eb 100644 (file)
@@ -12,7 +12,7 @@
 #include <vector>
 #include <tr1/memory>
 
-#include "CollectionIndex.h"
+#include "IndexManager.h"
 #include "ObjectMap.h"
 #include "KeyValueDB.h"
 #include "DBObjectMap.h"
@@ -193,9 +193,9 @@ int DBObjectMap::DBObjectMapIteratorImpl::init()
 
 ObjectMap::ObjectMapIterator DBObjectMap::get_iterator(
   const hobject_t &hoid,
-  CollectionIndex::IndexedPath path)
+  Index index)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return ObjectMapIterator(new EmptyIteratorImpl());
   return _get_iterator(header);
@@ -379,11 +379,11 @@ int DBObjectMap::DBObjectMapIteratorImpl::status()
 }
 
 int DBObjectMap::set_keys(const hobject_t &hoid,
-                         CollectionIndex::IndexedPath path,
+                         Index index,
                          const map<string, bufferlist> &set)
 {
   KeyValueDB::Transaction t = db->get_transaction();
-  Header header = lookup_create_map_header(path->coll(), hoid, t);
+  Header header = lookup_create_map_header(index->coll(), hoid, t);
   if (!header)
     return -EINVAL;
 
@@ -393,11 +393,11 @@ int DBObjectMap::set_keys(const hobject_t &hoid,
 }
 
 int DBObjectMap::set_header(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            const bufferlist &bl)
 {
   KeyValueDB::Transaction t = db->get_transaction();
-  Header header = lookup_create_map_header(path->coll(), hoid, t);
+  Header header = lookup_create_map_header(index->coll(), hoid, t);
   if (!header)
     return -EINVAL;
   _set_header(header, bl, t);
@@ -413,10 +413,10 @@ void DBObjectMap::_set_header(Header header, const bufferlist &bl,
 }
 
 int DBObjectMap::get_header(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            bufferlist *bl)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header) {
     return 0;
   }
@@ -449,13 +449,13 @@ int DBObjectMap::_get_header(Header header,
 }
 
 int DBObjectMap::clear(const hobject_t &hoid,
-                      CollectionIndex::IndexedPath path)
+                      Index index)
 {
   KeyValueDB::Transaction t = db->get_transaction();
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
-  remove_map_header(path->coll(), hoid, header, t);
+  remove_map_header(index->coll(), hoid, header, t);
   assert(header->num_children > 0);
   header->num_children--;
   int r = _clear(header, t);
@@ -568,10 +568,10 @@ int DBObjectMap::need_parent(DBObjectMapIterator iter)
 }
 
 int DBObjectMap::rm_keys(const hobject_t &hoid,
-                        CollectionIndex::IndexedPath path,
+                        Index index,
                         const set<string> &to_clear)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   KeyValueDB::Transaction t = db->get_transaction();
@@ -641,11 +641,11 @@ int DBObjectMap::rm_keys(const hobject_t &hoid,
 }
 
 int DBObjectMap::get(const hobject_t &hoid,
-                    CollectionIndex::IndexedPath path,
+                    Index index,
                     bufferlist *_header,
                     map<string, bufferlist> *out)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   _get_header(header, _header);
@@ -659,13 +659,13 @@ int DBObjectMap::get(const hobject_t &hoid,
 }
 
 int DBObjectMap::get_keys(const hobject_t &hoid,
-                         CollectionIndex::IndexedPath path,
+                         Index index,
                          set<string> *keys)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
-  ObjectMapIterator iter = get_iterator(hoid, path);
+  ObjectMapIterator iter = get_iterator(hoid, index);
   for (; iter->valid(); iter->next()) {
     if (iter->status())
       return iter->status();
@@ -697,43 +697,43 @@ int DBObjectMap::scan(Header header,
 }
 
 int DBObjectMap::get_values(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            const set<string> &keys,
                            map<string, bufferlist> *out)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   return scan(header, keys, 0, out);;
 }
 
 int DBObjectMap::check_keys(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            const set<string> &keys,
                            set<string> *out)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   return scan(header, keys, out, 0);
 }
 
 int DBObjectMap::get_xattrs(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            const set<string> &to_get,
                            map<string, bufferlist> *out)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   return db->get(xattr_prefix(header), to_get, out);
 }
 
 int DBObjectMap::get_all_xattrs(const hobject_t &hoid,
-                               CollectionIndex::IndexedPath path,
+                               Index index,
                                set<string> *out)
 {
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   KeyValueDB::Iterator iter = db->get_iterator(xattr_prefix(header));
@@ -745,11 +745,11 @@ int DBObjectMap::get_all_xattrs(const hobject_t &hoid,
 }
 
 int DBObjectMap::set_xattrs(const hobject_t &hoid,
-                           CollectionIndex::IndexedPath path,
+                           Index index,
                            const map<string, bufferlist> &to_set)
 {
   KeyValueDB::Transaction t = db->get_transaction();
-  Header header = lookup_create_map_header(path->coll(), hoid, t);
+  Header header = lookup_create_map_header(index->coll(), hoid, t);
   if (!header)
     return -EINVAL;
   t->set(xattr_prefix(header), to_set);
@@ -757,11 +757,11 @@ int DBObjectMap::set_xattrs(const hobject_t &hoid,
 }
 
 int DBObjectMap::remove_xattrs(const hobject_t &hoid,
-                              CollectionIndex::IndexedPath path,
+                              Index index,
                               const set<string> &to_remove)
 {
   KeyValueDB::Transaction t = db->get_transaction();
-  Header header = lookup_map_header(path->coll(), hoid);
+  Header header = lookup_map_header(index->coll(), hoid);
   if (!header)
     return -ENOENT;
   t->rmkeys(xattr_prefix(header), to_remove);
@@ -769,26 +769,26 @@ int DBObjectMap::remove_xattrs(const hobject_t &hoid,
 }
 
 int DBObjectMap::clone(const hobject_t &hoid,
-                      CollectionIndex::IndexedPath path,
+                      Index index,
                       const hobject_t &target,
-                      CollectionIndex::IndexedPath target_path)
+                      Index target_index)
 {
   KeyValueDB::Transaction t = db->get_transaction();
   {
-    Header destination = lookup_map_header(target_path->coll(), target);
+    Header destination = lookup_map_header(target_index->coll(), target);
     if (destination) {
-      remove_map_header(target_path->coll(), target, destination, t);
+      remove_map_header(target_index->coll(), target, destination, t);
       destination->num_children--;
       _clear(destination, t);
     }
   }
 
-  Header parent = lookup_map_header(path->coll(), hoid);
+  Header parent = lookup_map_header(index->coll(), hoid);
   if (!parent)
     return db->submit_transaction(t);
 
-  Header source = generate_new_header(path->coll(), hoid, parent);
-  Header destination = generate_new_header(target_path->coll(), target, parent);
+  Header source = generate_new_header(index->coll(), hoid, parent);
+  Header destination = generate_new_header(target_index->coll(), target, parent);
   _Header lsource, ldestination;
   source->num_children = parent->num_children;
   lsource.parent = source->seq;
@@ -797,7 +797,7 @@ int DBObjectMap::clone(const hobject_t &hoid,
   set_header(parent, t);
   set_header(source, t);
   set_header(destination, t);
-  set_map_header(target_path->coll(), target, ldestination, t);
+  set_map_header(target_index->coll(), target, ldestination, t);
 
   map<string, bufferlist> to_set;
   KeyValueDB::Iterator xattr_iter = db->get_iterator(xattr_prefix(parent));
@@ -827,27 +827,27 @@ int DBObjectMap::clone(const hobject_t &hoid,
 }
 
 int DBObjectMap::link(const hobject_t &hoid,
-                     CollectionIndex::IndexedPath path,
+                     Index index,
                      const hobject_t &target,
-                     CollectionIndex::IndexedPath target_path)
+                     Index target_index)
 {
   KeyValueDB::Transaction t = db->get_transaction();
   {
-    Header destination = lookup_map_header(target_path->coll(), target);
+    Header destination = lookup_map_header(target_index->coll(), target);
     if (destination) {
-      remove_map_header(target_path->coll(), target, destination, t);
+      remove_map_header(target_index->coll(), target, destination, t);
       destination->num_children--;
       _clear(destination, t);
     }
   }
-  Header header = lookup_create_map_header(path->coll(), hoid, t);
+  Header header = lookup_create_map_header(index->coll(), hoid, t);
 
   assert(header->num_children > 0);
   header->num_children++;
   set_header(header, t);
   _Header ldestination;
   ldestination.parent = header->seq;
-  set_map_header(target_path->coll(), target, ldestination, t);
+  set_map_header(target_index->coll(), target, ldestination, t);
   return db->submit_transaction(t);
 }
 
index e26d7351fb63cac57f905889ff77a61681c3c544..2c3e66d1c5120a6ed52f2605d2d8259d850b182f 100644 (file)
@@ -12,7 +12,7 @@
 #include <tr1/memory>
 #include <boost/scoped_ptr.hpp>
 
-#include "CollectionIndex.h"
+#include "IndexManager.h"
 #include "ObjectMap.h"
 #include "KeyValueDB.h"
 #include "osd/osd_types.h"
@@ -82,97 +82,97 @@ public:
 
   int set_keys(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const map<string, bufferlist> &set
     );
 
   int set_header(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const bufferlist &bl
     );
 
   int get_header(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     bufferlist *bl
     );
 
   int clear(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path
+    Index index
     );
 
   int rm_keys(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const set<string> &to_clear
     );
 
   int get(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     bufferlist *header,
     map<string, bufferlist> *out
     );
 
   int get_keys(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     set<string> *keys
     );
 
   int get_values(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const set<string> &keys,
     map<string, bufferlist> *out
     );
 
   int check_keys(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const set<string> &keys,
     set<string> *out
     );
 
   int get_xattrs(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const set<string> &to_get,
     map<string, bufferlist> *out
     );
 
   int get_all_xattrs(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     set<string> *out
     );
 
   int set_xattrs(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const map<string, bufferlist> &to_set
     );
 
   int remove_xattrs(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const set<string> &to_remove
     );
 
   int clone(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const hobject_t &target,
-    CollectionIndex::IndexedPath target_path
+    Index target_index
     );
 
   int link(
     const hobject_t &hoid,
-    CollectionIndex::IndexedPath path,
+    Index index,
     const hobject_t &target,
-    CollectionIndex::IndexedPath target_path
+    Index target_index
     );
 
   /// Read initial state from backing store
@@ -185,7 +185,7 @@ public:
   int sync();
 
   ObjectMapIterator get_iterator(const hobject_t &hoid,
-                                CollectionIndex::IndexedPath path);
+                                Index index);
 
   static const string USER_PREFIX;
   static const string XATTR_PREFIX;
index f0833631f2cc8652b8ab615e8050d93471b0d94f..5b5f72d8b673b34b1c7f1df722a50aba6aa263f0 100644 (file)
@@ -345,7 +345,8 @@ int FileStore::lfn_link(coll_t c, coll_t cid, const hobject_t& o)
   if (r < 0)
     return -errno;
 
-  r = object_map->link(o, path_old, o, path_new);
+  r = object_map->link(o, path_old->get_index(),
+                      o, path_new->get_index());
   if (r < 0)
     return r;
 
@@ -367,7 +368,7 @@ int FileStore::lfn_unlink(coll_t cid, const hobject_t& o)
     r = index->lookup(o, &path, &exist);
     if (r < 0)
       return r;
-    object_map->clear(o, path);
+    object_map->clear(o, path->get_index());
     if (r < 0 && r != -ENOENT)
       return r;
   }
@@ -3061,7 +3062,7 @@ int FileStore::_clone(coll_t cid, const hobject_t& oldoid, const hobject_t& newo
   if (r < 0)
     r = -errno;
   dout(20) << "objectmap clone" << dendl;
-  r = object_map->clone(oldoid, from, newoid, to);
+  r = object_map->clone(oldoid, from->get_index(), newoid, to->get_index());
 
   // clone is non-idempotent; record our work.
   _set_replay_guard(n, spos);
@@ -4153,7 +4154,7 @@ int FileStore::omap_get(coll_t c, const hobject_t &hoid,
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->get(hoid, path, header, out);
+  return object_map->get(hoid, path->get_index(), header, out);
 }
 
 int FileStore::omap_get_header(coll_t c, const hobject_t &hoid,
@@ -4164,7 +4165,7 @@ int FileStore::omap_get_header(coll_t c, const hobject_t &hoid,
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->get_header(hoid, path, bl);
+  return object_map->get_header(hoid, path->get_index(), bl);
 }
 
 int FileStore::omap_get_keys(coll_t c, const hobject_t &hoid, set<string> *keys)
@@ -4174,7 +4175,7 @@ int FileStore::omap_get_keys(coll_t c, const hobject_t &hoid, set<string> *keys)
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->get_keys(hoid, path, keys);
+  return object_map->get_keys(hoid, path->get_index(), keys);
 }
 
 int FileStore::omap_get_values(coll_t c, const hobject_t &hoid,
@@ -4186,7 +4187,7 @@ int FileStore::omap_get_values(coll_t c, const hobject_t &hoid,
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->get_values(hoid, path, keys, out);
+  return object_map->get_values(hoid, path->get_index(), keys, out);
 }
 
 int FileStore::omap_check_keys(coll_t c, const hobject_t &hoid,
@@ -4198,7 +4199,7 @@ int FileStore::omap_check_keys(coll_t c, const hobject_t &hoid,
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->check_keys(hoid, path, keys, out);
+  return object_map->check_keys(hoid, path->get_index(), keys, out);
 }
 
 ObjectMap::ObjectMapIterator FileStore::get_omap_iterator(coll_t c,
@@ -4209,7 +4210,7 @@ ObjectMap::ObjectMapIterator FileStore::get_omap_iterator(coll_t c,
   int r = lfn_find(c, hoid, &path);
   if (r < 0)
     return ObjectMap::ObjectMapIterator();
-  return object_map->get_iterator(hoid, path);
+  return object_map->get_iterator(hoid, path->get_index());
 }
 
 int FileStore::_create_collection(coll_t c) 
@@ -4283,7 +4284,7 @@ int FileStore::_omap_clear(coll_t cid, const hobject_t &hoid) {
   int r = lfn_find(cid, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->clear(hoid, path);
+  return object_map->clear(hoid, path->get_index());
 }
 int FileStore::_omap_setkeys(coll_t cid, const hobject_t &hoid,
                             const map<string, bufferlist> &aset) {
@@ -4292,7 +4293,7 @@ int FileStore::_omap_setkeys(coll_t cid, const hobject_t &hoid,
   int r = lfn_find(cid, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->set_keys(hoid, path, aset);
+  return object_map->set_keys(hoid, path->get_index(), aset);
 }
 int FileStore::_omap_rmkeys(coll_t cid, const hobject_t &hoid,
                           const set<string> &keys) {
@@ -4301,7 +4302,7 @@ int FileStore::_omap_rmkeys(coll_t cid, const hobject_t &hoid,
   int r = lfn_find(cid, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->rm_keys(hoid, path, keys);
+  return object_map->rm_keys(hoid, path->get_index(), keys);
 }
 int FileStore::_omap_setheader(coll_t cid, const hobject_t &hoid,
                               const bufferlist &bl)
@@ -4311,7 +4312,7 @@ int FileStore::_omap_setheader(coll_t cid, const hobject_t &hoid,
   int r = lfn_find(cid, hoid, &path);
   if (r < 0)
     return r;
-  return object_map->set_header(hoid, path, bl);
+  return object_map->set_header(hoid, path->get_index(), bl);
 }
 
 
index c51f9d659270c2969c2e4e329bca120ecea4aa0f..a47f457e83bc13ea87ce67e32ff925574c2c581b 100644 (file)
@@ -15,6 +15,7 @@
 #include "include/types.h"
 #include "include/buffer.h"
 #include "osd/osd_types.h"
+#include <errno.h>
 
 #include "HashIndex.h"
 
index 808525edcc7d1aa043c9f6c6d71a5f2636401e7a..e1e226397b77a243d457a71f1bc888316cfc4f2f 100644 (file)
@@ -19,6 +19,8 @@
 #include <sys/param.h>
 #endif
 
+#include <errno.h>
+
 #include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/config.h"
index 54578a68dcf25c055b4fc0a89e303fe9a6eafd5d..542da55c3c1240e0e3aa821657c1a7006de7bdb2 100644 (file)
@@ -25,7 +25,6 @@
 #include "osd/osd_types.h"
 #include "include/object.h"
 #include "common/ceph_crypto.h"
-#include "ObjectStore.h"
 
 #include "CollectionIndex.h"
 
index d274fdbabc1d1d31d48ebc909481324c03908df2..0f3088e641ed5ec06d8f1b3ff97ee18bb6436a2e 100644 (file)
@@ -19,7 +19,7 @@
 #include <vector>
 #include <tr1/memory>
 
-#include "CollectionIndex.h"
+#include "IndexManager.h"
 
 /**
  * Encapsulates the FileStore key value store
@@ -31,41 +31,41 @@ public:
   /// Set keys and values from specified map
   virtual int set_keys(
     const hobject_t &hoid,              ///< [in] object containing map
-    CollectionIndex::IndexedPath path,  ///< [in] Path to hoid
+    Index index,                        ///< [in] Path to hoid
     const map<string, bufferlist> &set   ///< [in] key to value map to set
     ) = 0;
 
   /// Set header
   virtual int set_header(
     const hobject_t &hoid,              ///< [in] object containing map
-    CollectionIndex::IndexedPath path,  ///< [in] Path to hoid
+    Index index,                        ///< [in] Path to hoid
     const bufferlist &bl                ///< [in] header to set
     ) = 0;
 
   /// Retrieve header
   virtual int get_header(
     const hobject_t &hoid,              ///< [in] object containing map
-    CollectionIndex::IndexedPath path,  ///< [in] Path to hoid
+    Index index,                        ///< [in] Path to hoid
     bufferlist *bl                      ///< [out] header to set
     ) = 0;
 
   /// Clear all map keys and values from hoid
   virtual int clear(
     const hobject_t &hoid,              ///< [in] object containing map
-    CollectionIndex::IndexedPath path   ///< [in] Path to hoid
+    Index index                         ///< [in] Path to hoid
     ) = 0;
 
   /// Clear all map keys and values from hoid
   virtual int rm_keys(
     const hobject_t &hoid,              ///< [in] object containing map
-    CollectionIndex::IndexedPath path,  ///< [in] Path to hoid
+    Index index,                        ///< [in] Path to hoid
     const set<string> &to_clear         ///< [in] Keys to clear
     ) = 0;
 
   /// Get all keys and values
   virtual int get(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     bufferlist *header,                ///< [out] Returned Header
     map<string, bufferlist> *out       ///< [out] Returned keys and values
     ) = 0;
@@ -73,14 +73,14 @@ public:
   /// Get values for supplied keys
   virtual int get_keys(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     set<string> *keys                  ///< [out] Keys defined on hoid
     ) = 0;
 
   /// Get values for supplied keys
   virtual int get_values(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     const set<string> &keys,           ///< [in] Keys to get
     map<string, bufferlist> *out       ///< [out] Returned keys and values
     ) = 0;
@@ -88,7 +88,7 @@ public:
   /// Check key existence
   virtual int check_keys(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     const set<string> &keys,           ///< [in] Keys to check
     set<string> *out                   ///< [out] Subset of keys defined on hoid
     ) = 0;
@@ -96,7 +96,7 @@ public:
   /// Get xattrs
   virtual int get_xattrs(
     const hobject_t &hoid,             ///< [in] object
-    CollectionIndex::IndexedPath path, ///< [in] path to hoid
+    Index index,                       ///< [in] path to hoid
     const set<string> &to_get,         ///< [in] keys to get
     map<string, bufferlist> *out       ///< [out] subset of attrs/vals defined
     ) = 0;
@@ -104,21 +104,21 @@ public:
   /// Get all xattrs
   virtual int get_all_xattrs(
     const hobject_t &hoid,             ///< [in] object
-    CollectionIndex::IndexedPath path, ///< [in] path to hoid
+    Index index,                       ///< [in] path to hoid
     set<string> *out       ///< [out] attrs and values
     ) = 0;
 
   /// set xattrs in to_set
   virtual int set_xattrs(
     const hobject_t &hoid,                ///< [in] object
-    CollectionIndex::IndexedPath path,    ///< [in] path to object
+    Index index,                          ///< [in] path to object
     const map<string, bufferlist> &to_set ///< [in] attrs/values to set
     ) = 0;
 
   /// remove xattrs in to_remove
   virtual int remove_xattrs(
     const hobject_t &hoid,               ///< [in] object
-    CollectionIndex::IndexedPath path,   ///< [in] path to hoid
+    Index index,                         ///< [in] path to hoid
     const set<string> &to_remove         ///< [in] attrs to remove
     ) = 0;
 
@@ -126,17 +126,17 @@ public:
   /// Clone keys efficiently from hoid map to target map
   virtual int clone(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     const hobject_t &target,           ///< [in] target of clone
-    CollectionIndex::IndexedPath target_path ///< [in] path to target
+    Index target_index                 ///< [in] path to target
     ) { return 0; }
 
   /// Efficiently tie <target, target_path> to same key space as <hoid, path>
   virtual int link(
     const hobject_t &hoid,             ///< [in] object containing map
-    CollectionIndex::IndexedPath path, ///< [in] Path to hoid
+    Index index,                       ///< [in] Path to hoid
     const hobject_t &target,           ///< [in] target of link
-    CollectionIndex::IndexedPath target_path ///< [in] path to target
+    Index target_index                 ///< [in] path to target
     ) { return 0; }
 
   /// Ensure all previous writes are durable
@@ -158,7 +158,7 @@ public:
   };
   typedef std::tr1::shared_ptr<ObjectMapIteratorImpl> ObjectMapIterator;
   virtual ObjectMapIterator get_iterator(const hobject_t &hoid,
-                                        CollectionIndex::IndexedPath path) {
+                                        Index index) {
     return ObjectMapIterator();
   }
 
index ef91f1606d7c8aef5a83d88f88363d92fd98864e..ac551f5dd1bb3c4d9402e138bd0595771dd6873e 100644 (file)
@@ -1,13 +1,15 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 #include <tr1/memory>
 #include <map>
 #include <set>
 #include <boost/scoped_ptr.hpp>
 
-#include "os/CollectionIndex.h"
+#include "os/IndexManager.h"
 #include "include/buffer.h"
 #include "test/ObjectMap/KeyValueDBMemory.h"
 #include "os/KeyValueDB.h"
 #include "os/DBObjectMap.h"
+#include "os/HashIndex.h"
 #include "os/LevelDBStore.h"
 #include <sys/types.h>
 #include "global/global_init.h"
@@ -45,7 +47,7 @@ public:
   map<string, map<string, string> > omap;
   map<string, string > hmap;
   map<string, map<string, string> > xattrs;
-  CollectionIndex::IndexedPath def_collection;
+  Index def_collection;
   unsigned seq;
 
   ObjectMapTest() : db(), seq(0) {}
@@ -85,7 +87,7 @@ public:
              key, value);
   }
 
-  void set_key(hobject_t hoid, CollectionIndex::IndexedPath path,
+  void set_key(hobject_t hoid, Index path,
               string key, string value) {
     map<string, bufferlist> to_write;
     bufferptr bp(value.c_str(), value.size());
@@ -95,7 +97,7 @@ public:
     db->set_keys(hoid, path, to_write);
   }
 
-  void set_xattr(hobject_t hoid, CollectionIndex::IndexedPath path,
+  void set_xattr(hobject_t hoid, Index path,
                 string key, string value) {
     map<string, bufferlist> to_write;
     bufferptr bp(value.c_str(), value.size());
@@ -110,7 +112,7 @@ public:
               value);
   }
 
-  void set_header(hobject_t hoid, CollectionIndex::IndexedPath path,
+  void set_header(hobject_t hoid, Index path,
                  const string &value) {
     bufferlist header;
     header.append(bufferptr(value.c_str(), value.size() + 1));
@@ -122,7 +124,7 @@ public:
                      value);
   }
 
-  int get_header(hobject_t hoid, CollectionIndex::IndexedPath path,
+  int get_header(hobject_t hoid, Index path,
                 string *value) {
     bufferlist header;
     int r = db->get_header(hoid, path, &header);
@@ -140,7 +142,7 @@ public:
                     key, value);
   }
 
-  int get_xattr(hobject_t hoid, CollectionIndex::IndexedPath path,
+  int get_xattr(hobject_t hoid, Index path,
                string key, string *value) {
     set<string> to_get;
     to_get.insert(key);
@@ -160,7 +162,7 @@ public:
                   key, value);
   }
 
-  int get_key(hobject_t hoid, CollectionIndex::IndexedPath path,
+  int get_key(hobject_t hoid, Index path,
              string key, string *value) {
     set<string> to_get;
     to_get.insert(key);
@@ -180,7 +182,7 @@ public:
               key);
   }
 
-  void remove_key(hobject_t hoid, CollectionIndex::IndexedPath path,
+  void remove_key(hobject_t hoid, Index path,
                  string key) {
     set<string> to_remove;
     to_remove.insert(key);
@@ -192,7 +194,7 @@ public:
                 key);
   }
 
-  void remove_xattr(hobject_t hoid, CollectionIndex::IndexedPath path,
+  void remove_xattr(hobject_t hoid, Index path,
                    string key) {
     set<string> to_remove;
     to_remove.insert(key);
@@ -204,8 +206,8 @@ public:
          hobject_t(sobject_t(target, CEPH_NOSNAP)), def_collection);
   }
 
-  void clone(hobject_t hoid, CollectionIndex::IndexedPath path,
-            hobject_t hoid2, CollectionIndex::IndexedPath path2) {
+  void clone(hobject_t hoid, Index path,
+            hobject_t hoid2, Index path2) {
     db->clone(hoid, path, hoid2, path2);
   }
 
@@ -213,7 +215,7 @@ public:
     clear(hobject_t(sobject_t(objname, CEPH_NOSNAP)), def_collection);
   }
 
-  void clear(hobject_t hoid, CollectionIndex::IndexedPath path) {
+  void clear(hobject_t hoid, Index path) {
     db->clear(hoid, path);
   }
 
@@ -236,8 +238,11 @@ public:
   }
 
   void init_default_collection(const string &coll_name) {
-    def_collection = CollectionIndex::get_testing_path(
-      "/" + coll_name, coll_t(coll_name));
+    def_collection = Index(new HashIndex(coll_t(coll_name),
+                                        ("/" + coll_name).c_str(),
+                                        2,
+                                        2,
+                                        CollectionIndex::HASH_INDEX_TAG_2));
   }
 
   void auto_set_xattr(ostream &out) {
@@ -542,9 +547,11 @@ int main(int argc, char **argv) {
 
 TEST_F(ObjectMapTest, CreateOneObject) {
   hobject_t hoid(sobject_t("foo", CEPH_NOSNAP));
-  CollectionIndex::IndexedPath path = CollectionIndex::get_testing_path(
-    "/bar", coll_t("foo_coll"));
-
+  Index path = Index(new HashIndex(coll_t("foo_coll"),
+                                  string("/bar").c_str(),
+                                  2,
+                                  2,
+                                  CollectionIndex::HASH_INDEX_TAG_2));
   map<string, bufferlist> to_set;
   string key("test");
   string val("test_val");
@@ -582,8 +589,11 @@ TEST_F(ObjectMapTest, CreateOneObject) {
 TEST_F(ObjectMapTest, CloneOneObject) {
   hobject_t hoid(sobject_t("foo", CEPH_NOSNAP));
   hobject_t hoid2(sobject_t("foo2", CEPH_NOSNAP));
-  CollectionIndex::IndexedPath path = CollectionIndex::get_testing_path(
-    "/bar", coll_t("foo_coll"));
+  Index path = Index(new HashIndex(coll_t("foo_coll"),
+                                  string("/bar").c_str(),
+                                  2,
+                                  2,
+                                  CollectionIndex::HASH_INDEX_TAG_2));
 
   set_key(hoid, path, "foo", "bar");
   set_key(hoid, path, "foo2", "bar2");
@@ -646,9 +656,11 @@ TEST_F(ObjectMapTest, OddEvenClone) {
   hobject_t hoid(sobject_t("foo", CEPH_NOSNAP));
   hobject_t hoid2(sobject_t("foo2", CEPH_NOSNAP));
   hobject_t hoid_link(sobject_t("foo_link", CEPH_NOSNAP));
-  CollectionIndex::IndexedPath path = CollectionIndex::get_testing_path(
-    "/bar", coll_t("foo_coll"));
-
+  Index path = Index(new HashIndex(coll_t("foo_coll"),
+                                  string("/bar").c_str(),
+                                  2,
+                                  2,
+                                  CollectionIndex::HASH_INDEX_TAG_2));
 
   for (unsigned i = 0; i < 1000; ++i) {
     set_key(hoid, path, "foo" + num_str(i), "bar" + num_str(i));