]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
explicitly specify comparator for all ghobject_t maps and sets
authorSage Weil <sage@redhat.com>
Thu, 23 Jul 2015 14:20:00 +0000 (10:20 -0400)
committerSage Weil <sage@redhat.com>
Fri, 7 Aug 2015 14:16:04 +0000 (10:16 -0400)
We no longer have operator<

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/DBObjectMap.h
src/os/FDCache.h
src/os/FileStore.h
src/os/HashIndex.cc
src/os/HashIndex.h
src/os/KeyValueStore.h
src/os/MemStore.cc
src/os/MemStore.h
src/os/ObjectStore.h
src/test/objectstore/store_test.cc

index de80d6f547ccc90df4acbde33cd43b3a0591ef25..ee252c1ccb1a7eabc4e665927df36f0cff0894af 100644 (file)
@@ -68,7 +68,7 @@ public:
    * Set of headers currently in use
    */
   set<uint64_t> in_use;
-  set<ghobject_t> map_header_in_use;
+  set<ghobject_t, ghobject_t::BitwiseComparator> map_header_in_use;
 
   /**
    * Takes the map_header_in_use entry in constructor, releases in
@@ -327,7 +327,7 @@ private:
   /// Implicit lock on Header->seq
   typedef ceph::shared_ptr<_Header> Header;
   Mutex cache_lock;
-  SimpleLRU<ghobject_t, _Header> caches;
+  SimpleLRU<ghobject_t, _Header, ghobject_t::BitwiseComparator> caches;
 
   string map_header_key(const ghobject_t &oid);
   string header_key(uint64_t seq);
index 8597265bbf125f5530f2814bfdd1e81ddc5ab706..635043b7e0613b849cc5e151d0365d3b1681df64 100644 (file)
@@ -52,14 +52,14 @@ public:
 private:
   CephContext *cct;
   const int registry_shards;
-  SharedLRU<ghobject_t, FD> *registry;
+  SharedLRU<ghobject_t, FD, ghobject_t::BitwiseComparator> *registry;
 
 public:
   FDCache(CephContext *cct) : cct(cct),
   registry_shards(cct->_conf->filestore_fd_cache_shards) {
     assert(cct);
     cct->_conf->add_observer(this);
-    registry = new SharedLRU<ghobject_t, FD>[registry_shards];
+    registry = new SharedLRU<ghobject_t, FD, ghobject_t::BitwiseComparator>[registry_shards];
     for (int i = 0; i < registry_shards; ++i) {
       registry[i].set_cct(cct);
       registry[i].set_size(
index 95882d3c7f3ace16795d39967c06d601e8142f71..744bdbd23f07023c7520e71874977f64cf67c5bb 100644 (file)
@@ -585,8 +585,8 @@ public:
 
   // DEBUG read error injection, an object is removed from both on delete()
   Mutex read_error_lock;
-  set<ghobject_t> data_error_set; // read() will return -EIO
-  set<ghobject_t> mdata_error_set; // getattr(),stat() will return -EIO
+  set<ghobject_t, ghobject_t::BitwiseComparator> data_error_set; // read() will return -EIO
+  set<ghobject_t, ghobject_t::BitwiseComparator> mdata_error_set; // getattr(),stat() will return -EIO
   void inject_data_error(const ghobject_t &oid);
   void inject_mdata_error(const ghobject_t &oid);
   void debug_obj_on_delete(const ghobject_t &oid);
index 9ee86ff88123dddc04171052a85f298073e10b3a..06894782004b88928a755edae7dd3e789fd13f06 100644 (file)
@@ -830,7 +830,7 @@ int HashIndex::get_path_contents_by_hash_bitwise(
   const vector<string> &path,
   const ghobject_t *next_object,
   set<string, CmpHexdigitStringBitwise> *hash_prefixes,
-  set<pair<string, ghobject_t> > *objects)
+  set<pair<string, ghobject_t>, CmpPairBitwise> *objects)
 {
   map<string, ghobject_t> rev_objects;
   int r;
@@ -963,7 +963,7 @@ int HashIndex::list_by_hash_bitwise(
   vector<string> next_path = path;
   next_path.push_back("");
   set<string, CmpHexdigitStringBitwise> hash_prefixes;
-  set<pair<string, ghobject_t> > objects;
+  set<pair<string, ghobject_t>, CmpPairBitwise> objects;
   int r = get_path_contents_by_hash_bitwise(path,
                                            next,
                                            &hash_prefixes,
@@ -974,7 +974,7 @@ int HashIndex::list_by_hash_bitwise(
        i != hash_prefixes.end();
        ++i) {
     dout(20) << __func__ << " prefix " << *i << dendl;
-    set<pair<string, ghobject_t> >::iterator j = objects.lower_bound(
+    set<pair<string, ghobject_t>, CmpPairBitwise>::iterator j = objects.lower_bound(
       make_pair(*i, ghobject_t()));
     if (j == objects.end() || j->first != *i) {
       *(next_path.rbegin()) = *(i->rbegin());
@@ -1029,7 +1029,7 @@ int HashIndex::list_by_hash_nibblewise(
   vector<string> next_path = path;
   next_path.push_back("");
   set<string> hash_prefixes;
-  set<pair<string, ghobject_t>, CmpPairNibblewise > objects;
+  set<pair<string, ghobject_t>, CmpPairNibblewise> objects;
   int r = get_path_contents_by_hash_nibblewise(path,
                                               next,
                                               &hash_prefixes,
index d6f605635a0299c65e794c90a764963a9bc35d37..cacdbc840f39f6c7e08123923b85ff9fb3fe8e5b 100644 (file)
@@ -365,6 +365,20 @@ private:
     }
   };
 
+  struct CmpPairBitwise {
+    bool operator()(const pair<string, ghobject_t>& l,
+                   const pair<string, ghobject_t>& r)
+    {
+      if (l.first < r.first)
+       return true;
+      if (l.first > r.first)
+       return false;
+      if (cmp_bitwise(l.second, r.second) < 0)
+       return true;
+      return false;
+    }
+  };
+
   struct CmpHexdigitStringBitwise {
     bool operator()(const string& l, const string& r) {
       return reverse_hexdigit_bits_string(l) < reverse_hexdigit_bits_string(r);
@@ -376,13 +390,13 @@ private:
     const vector<string> &path,             /// [in] Path to list
     const ghobject_t *next_object,          /// [in] list > *next_object
     set<string, CmpHexdigitStringBitwise> *hash_prefixes, /// [out] prefixes in dir
-    set<pair<string, ghobject_t> > *objects /// [out] objects
+    set<pair<string, ghobject_t>, CmpPairBitwise> *objects /// [out] objects
     );
   int get_path_contents_by_hash_nibblewise(
     const vector<string> &path,             /// [in] Path to list
     const ghobject_t *next_object,          /// [in] list > *next_object
     set<string> *hash_prefixes,             /// [out] prefixes in dir
-    set<pair<string, ghobject_t>, CmpPairNibblewise > *objects /// [out] objects
+    set<pair<string, ghobject_t>, CmpPairNibblewise> *objects /// [out] objects
     );
 
   /// List objects in collection in ghobject_t order
index ca4e09cd186da2c4255b6c507a9eafd72b0c679e..ae481030c8100ef190afce88ed220ded2898245e 100644 (file)
@@ -234,11 +234,27 @@ class KeyValueStore : public ObjectStore,
   // 4. Clone or rename
   struct BufferTransaction {
     typedef pair<coll_t, ghobject_t> uniq_id;
-    typedef map<uniq_id, StripObjectMap::StripObjectHeaderRef> StripHeaderMap;
+
+    struct CollGhobjectPairBitwiseComparator {
+      bool operator()(const uniq_id& l,
+                     const uniq_id& r) const {
+       if (l.first < r.first)
+         return true;
+       if (l.first != r.first)
+         return false;
+       if (cmp_bitwise(l.second, r.second) < 0)
+         return true;
+       return false;
+      }
+    };
+
+    typedef map<uniq_id, StripObjectMap::StripObjectHeaderRef,
+               CollGhobjectPairBitwiseComparator> StripHeaderMap;
 
     //Dirty records
     StripHeaderMap strip_headers;
-    map< uniq_id, map<pair<string, string>, bufferlist> > buffers;  // pair(prefix, key),to buffer updated data in one transaction
+    map< uniq_id, map<pair<string, string>, bufferlist>,
+        CollGhobjectPairBitwiseComparator> buffers;  // pair(prefix, key),to buffer updated data in one transaction
 
     list<Context*> finishes;
 
index be6fc77630cbb36e6167c781d3ecf3230f3e90ed..781564438729a5c97952bd7ee9117284ffb4688c 100644 (file)
@@ -132,7 +132,7 @@ void MemStore::dump(Formatter *f)
     f->close_section();
 
     f->open_array_section("objects");
-    for (map<ghobject_t,ObjectRef>::iterator q = p->second->object_map.begin();
+    for (map<ghobject_t,ObjectRef,ghobject_t::BitwiseComparator>::iterator q = p->second->object_map.begin();
         q != p->second->object_map.end();
         ++q) {
       f->open_object_section("object");
@@ -432,7 +432,7 @@ int MemStore::collection_list(coll_t cid, ghobject_t start, ghobject_t end,
     return -ENOENT;
   RWLock::RLocker l(c->lock);
 
-  map<ghobject_t,ObjectRef>::iterator p = c->object_map.lower_bound(start);
+  map<ghobject_t,ObjectRef,ghobject_t::BitwiseComparator>::iterator p = c->object_map.lower_bound(start);
   while (p != c->object_map.end() &&
          ls->size() < (unsigned)max &&
          p->first < end) {
@@ -1384,7 +1384,7 @@ int MemStore::_split_collection(coll_t cid, uint32_t bits, uint32_t match,
   RWLock::WLocker l1(MIN(&(*sc), &(*dc))->lock);
   RWLock::WLocker l2(MAX(&(*sc), &(*dc))->lock);
 
-  map<ghobject_t,ObjectRef>::iterator p = sc->object_map.begin();
+  map<ghobject_t,ObjectRef,ghobject_t::BitwiseComparator>::iterator p = sc->object_map.begin();
   while (p != sc->object_map.end()) {
     if (p->first.match(bits, match)) {
       dout(20) << " moving " << p->first << dendl;
index 6852bc11edc0ec3b528185aba8bbeb2f0f31b48a..477e8fde63ed1ea1a564600efa85704d33dccc90 100644 (file)
@@ -78,7 +78,7 @@ public:
 
   struct Collection {
     ceph::unordered_map<ghobject_t, ObjectRef> object_hash;  ///< for lookup
-    map<ghobject_t, ObjectRef> object_map;        ///< for iteration
+    map<ghobject_t, ObjectRef,ghobject_t::BitwiseComparator> object_map;        ///< for iteration
     map<string,bufferptr> xattr;
     RWLock lock;   ///< for object_{map,hash}
 
@@ -99,7 +99,7 @@ public:
       ::encode(xattr, bl);
       uint32_t s = object_map.size();
       ::encode(s, bl);
-      for (map<ghobject_t, ObjectRef>::const_iterator p = object_map.begin();
+      for (map<ghobject_t, ObjectRef,ghobject_t::BitwiseComparator>::const_iterator p = object_map.begin();
           p != object_map.end();
           ++p) {
        ::encode(p->first, bl);
@@ -125,7 +125,7 @@ public:
 
     uint64_t used_bytes() const {
       uint64_t result = 0;
-      for (map<ghobject_t, ObjectRef>::const_iterator p = object_map.begin();
+      for (map<ghobject_t, ObjectRef,ghobject_t::BitwiseComparator>::const_iterator p = object_map.begin();
           p != object_map.end();
           ++p) {
         result += p->second->data.length();
index 5ae7949b097078b144246aaf8af0cb00965e6f54..7dc94094920ee4fce310947ac27866ea8a3c51ba 100644 (file)
@@ -434,7 +434,7 @@ public:
     bufferlist tbl;
 
     map<coll_t, __le32> coll_index;
-    map<ghobject_t, __le32> object_index;
+    map<ghobject_t, __le32, ghobject_t::BitwiseComparator> object_index;
 
     __le32 coll_id;
     __le32 object_id;
@@ -660,7 +660,7 @@ public:
       }
 
       vector<__le32> om(other.object_index.size());
-      map<ghobject_t, __le32>::iterator object_index_p;
+      map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator object_index_p;
       for (object_index_p = other.object_index.begin();
            object_index_p != other.object_index.end();
            ++object_index_p) {
@@ -796,7 +796,7 @@ public:
           colls[coll_index_p->second] = coll_index_p->first;
         }
 
-        map<ghobject_t, __le32>::iterator object_index_p;
+        map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator object_index_p;
         for (object_index_p = t->object_index.begin();
              object_index_p != t->object_index.end();
              ++object_index_p) {
@@ -892,7 +892,7 @@ private:
       return index_id;
     }
     __le32 _get_object_id(const ghobject_t& oid) {
-      map<ghobject_t, __le32>::iterator o = object_index.find(oid);
+      map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator o = object_index.find(oid);
       if (o != object_index.end())
         return o->second;
 
index 2da47e7f39c62bcdeaaeb239dfadf843207cd586..b21d6a7cc19ff8bbba32d29eeaf1cfbd6b541481 100644 (file)
@@ -265,7 +265,7 @@ TEST_P(StoreTest, SimpleListTest) {
     r = store->apply_transaction(t);
     ASSERT_EQ(r, 0);
   }
-  set<ghobject_t> all;
+  set<ghobject_t, ghobject_t::BitwiseComparator> all;
   {
     ObjectStore::Transaction t;
     for (int i=0; i<200; ++i) {
@@ -282,7 +282,7 @@ TEST_P(StoreTest, SimpleListTest) {
     ASSERT_EQ(r, 0);
   }
   for (int bitwise=0; bitwise<2; ++bitwise) {
-    set<ghobject_t> saw;
+    set<ghobject_t, ghobject_t::BitwiseComparator> saw;
     vector<ghobject_t> objects;
     ghobject_t next, current;
     while (!next.is_max()) {
@@ -313,7 +313,7 @@ TEST_P(StoreTest, SimpleListTest) {
   }
   {
     ObjectStore::Transaction t;
-    for (set<ghobject_t>::iterator p = all.begin(); p != all.end(); ++p)
+    for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator p = all.begin(); p != all.end(); ++p)
       t.remove(cid, *p);
     t.remove_collection(cid);
     cerr << "Cleaning" << std::endl;
@@ -360,7 +360,7 @@ TEST_P(StoreTest, MultipoolListTest) {
     r = store->apply_transaction(t);
     ASSERT_EQ(r, 0);
   }
-  set<ghobject_t> all, saw;
+  set<ghobject_t, ghobject_t::BitwiseComparator> all, saw;
   {
     ObjectStore::Transaction t;
     for (int i=0; i<200; ++i) {
@@ -398,7 +398,7 @@ TEST_P(StoreTest, MultipoolListTest) {
   }
   {
     ObjectStore::Transaction t;
-    for (set<ghobject_t>::iterator p = all.begin(); p != all.end(); ++p)
+    for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator p = all.begin(); p != all.end(); ++p)
       t.remove(cid, *p);
     t.remove_collection(cid);
     cerr << "Cleaning" << std::endl;
@@ -572,7 +572,7 @@ TEST_P(StoreTest, ManyObjectTest) {
   coll_t cid;
   string base = "";
   for (int i = 0; i < 100; ++i) base.append("aaaaa");
-  set<ghobject_t> created;
+  set<ghobject_t, ghobject_t::BitwiseComparator> created;
   {
     ObjectStore::Transaction t;
     t.create_collection(cid);
@@ -593,14 +593,14 @@ TEST_P(StoreTest, ManyObjectTest) {
     ASSERT_EQ(r, 0);
   }
 
-  for (set<ghobject_t>::iterator i = created.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = created.begin();
        i != created.end();
        ++i) {
     struct stat buf;
     ASSERT_TRUE(!store->stat(cid, *i, &buf));
   }
 
-  set<ghobject_t> listed, listed2;
+  set<ghobject_t, ghobject_t::BitwiseComparator> listed, listed2;
   vector<ghobject_t> objects;
   r = store->collection_list(cid, ghobject_t(), ghobject_t::get_max(), true, INT_MAX, &objects, 0);
   ASSERT_EQ(r, 0);
@@ -668,13 +668,13 @@ TEST_P(StoreTest, ManyObjectTest) {
   ASSERT_TRUE(listed.size() == created.size());
   if (listed2.size())
     ASSERT_EQ(listed.size(), listed2.size());
-  for (set<ghobject_t>::iterator i = listed.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = listed.begin();
        i != listed.end();
        ++i) {
     ASSERT_TRUE(created.count(*i));
   }
 
-  for (set<ghobject_t>::iterator i = created.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = created.begin();
        i != created.end();
        ++i) {
     ObjectStore::Transaction t;
@@ -736,9 +736,9 @@ public:
   static const unsigned max_attr_value_len = 1024 * 4;
   coll_t cid;
   unsigned in_flight;
-  map<ghobject_t, Object> contents;
-  set<ghobject_t> available_objects;
-  set<ghobject_t> in_flight_objects;
+  map<ghobject_t, Object, ghobject_t::BitwiseComparator> contents;
+  set<ghobject_t, ghobject_t::BitwiseComparator> available_objects;
+  set<ghobject_t, ghobject_t::BitwiseComparator> in_flight_objects;
   ObjectGenerator *object_gen;
   gen_type *rng;
   ObjectStore *store;
@@ -830,7 +830,7 @@ public:
       cond.Wait(lock);
     boost::uniform_int<> choose(0, available_objects.size() - 1);
     int index = choose(*rng);
-    set<ghobject_t>::iterator i = available_objects.begin();
+    set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = available_objects.begin();
     for ( ; index > 0; --index, ++i) ;
     ghobject_t ret = *i;
     return ret;
@@ -1133,7 +1133,7 @@ public:
     while (in_flight)
       cond.Wait(lock);
     vector<ghobject_t> objects;
-    set<ghobject_t> objects_set, objects_set2;
+    set<ghobject_t, ghobject_t::BitwiseComparator> objects_set, objects_set2;
     ghobject_t next, current;
     while (1) {
       cerr << "scanning..." << std::endl;
@@ -1148,7 +1148,7 @@ public:
       current = next;
     }
     ASSERT_EQ(objects_set.size(), available_objects.size());
-    for (set<ghobject_t>::iterator i = objects_set.begin();
+    for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = objects_set.begin();
         i != objects_set.end();
         ++i) {
       ASSERT_GT(available_objects.count(*i), (unsigned)0);
@@ -1158,7 +1158,7 @@ public:
     ASSERT_EQ(r, 0);
     objects_set2.insert(objects.begin(), objects.end());
     ASSERT_EQ(objects_set2.size(), available_objects.size());
-    for (set<ghobject_t>::iterator i = objects_set2.begin();
+    for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = objects_set2.begin();
         i != objects_set2.end();
         ++i) {
       ASSERT_GT(available_objects.count(*i), (unsigned)0);
@@ -1329,7 +1329,7 @@ TEST_P(StoreTest, HashCollisionTest) {
   }
   string base = "";
   for (int i = 0; i < 100; ++i) base.append("aaaaa");
-  set<ghobject_t> created;
+  set<ghobject_t, ghobject_t::BitwiseComparator> created;
   for (int n = 0; n < 10; ++n) {
     char nbuf[100];
     sprintf(nbuf, "n%d", n);
@@ -1352,7 +1352,7 @@ TEST_P(StoreTest, HashCollisionTest) {
   vector<ghobject_t> objects;
   r = store->collection_list(cid, ghobject_t(), ghobject_t::get_max(), true, INT_MAX, &objects, 0);
   ASSERT_EQ(r, 0);
-  set<ghobject_t> listed(objects.begin(), objects.end());
+  set<ghobject_t, ghobject_t::BitwiseComparator> listed(objects.begin(), objects.end());
   cerr << "listed.size() is " << listed.size() << " and created.size() is " << created.size() << std::endl;
   ASSERT_TRUE(listed.size() == created.size());
   objects.clear();
@@ -1379,13 +1379,13 @@ TEST_P(StoreTest, HashCollisionTest) {
   }
   cerr << "listed.size() is " << listed.size() << std::endl;
   ASSERT_TRUE(listed.size() == created.size());
-  for (set<ghobject_t>::iterator i = listed.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = listed.begin();
        i != listed.end();
        ++i) {
     ASSERT_TRUE(created.count(*i));
   }
 
-  for (set<ghobject_t>::iterator i = created.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = created.begin();
        i != created.end();
        ++i) {
     ObjectStore::Transaction t;
@@ -1409,7 +1409,7 @@ TEST_P(StoreTest, ScrubTest) {
     ASSERT_EQ(r, 0);
   }
   string base = "aaaaa";
-  set<ghobject_t> created;
+  set<ghobject_t, ghobject_t::BitwiseComparator> created;
   for (int i = 0; i < 1000; ++i) {
     char buf[100];
     sprintf(buf, "%d", i);
@@ -1448,7 +1448,7 @@ TEST_P(StoreTest, ScrubTest) {
   r = store->collection_list(cid, ghobject_t(), ghobject_t::get_max(), true,
                             INT_MAX, &objects, 0);
   ASSERT_EQ(r, 0);
-  set<ghobject_t> listed(objects.begin(), objects.end());
+  set<ghobject_t, ghobject_t::BitwiseComparator> listed(objects.begin(), objects.end());
   cerr << "listed.size() is " << listed.size() << " and created.size() is " << created.size() << std::endl;
   ASSERT_TRUE(listed.size() == created.size());
   objects.clear();
@@ -1474,13 +1474,13 @@ TEST_P(StoreTest, ScrubTest) {
   }
   cerr << "listed.size() is " << listed.size() << std::endl;
   ASSERT_TRUE(listed.size() == created.size());
-  for (set<ghobject_t>::iterator i = listed.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = listed.begin();
        i != listed.end();
        ++i) {
     ASSERT_TRUE(created.count(*i));
   }
 
-  for (set<ghobject_t>::iterator i = created.begin();
+  for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator i = created.begin();
        i != created.end();
        ++i) {
     ObjectStore::Transaction t;