]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: workloadgen: Don't linearly iterate over a map to obtain a collection
authorJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 24 Jul 2012 20:53:20 +0000 (21:53 +0100)
committerSage Weil <sage@inktank.com>
Sat, 28 Jul 2012 20:53:29 +0000 (13:53 -0700)
We were iterating over the collections map a certain amount of times, in
order to obtain the collection in that position. To avoid this kind of
behavior in a function that may be called a large amount of times, and
that may iterate over a rather large map, we now keep the collection ids
in a vector. In order to obtain a given collection on position X, we will
simply look for the collection id on position X of the vector, and then
obtain the collection from the map using its collection id.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/test/filestore/DeterministicOpSequence.cc
src/test/filestore/TestFileStoreState.cc
src/test/filestore/TestFileStoreState.h
src/test/filestore/workload_generator.cc

index cbfb0e4cdc6bf11f6e995beae04758a398bf3f24..c347df3b2a367f073dbfd8453b85544594e42a6c 100644 (file)
@@ -120,7 +120,7 @@ void DeterministicOpSequence::_print_status(int seq, int op)
 
 int DeterministicOpSequence::_gen_coll_id(rngen_t& gen)
 {
-  boost::uniform_int<> coll_rng(0, m_collections.size()-1);
+  boost::uniform_int<> coll_rng(0, m_collections_ids.size()-1);
   return coll_rng(gen);
 }
 
index b8ce898efe799771ed02f9326c08468b3c331bc5..728d6e4c0ed3af9fda6c957280f8acf00e7ee0ca 100644 (file)
@@ -65,6 +65,7 @@ void TestFileStoreState::init(int colls, int objs)
     inc_in_flight();
 
     m_collections.insert(make_pair(coll_id, entry));
+    m_collections_ids.push_back(coll_id);
     m_next_coll_nr++;
   }
   dout(5) << "init has " << m_in_flight.read() << "in-flight transactions" << dendl;
@@ -92,8 +93,13 @@ TestFileStoreState::get_coll(int key, bool erase)
   map<int, coll_entry_t*>::iterator it = m_collections.find(key);
   if (it != m_collections.end()) {
     entry = it->second;
-    if (erase)
+    if (erase) {
       m_collections.erase(it);
+      vector<int>::iterator cid_it = m_collections_ids.begin()+(entry->m_id);
+      dout(20) << __func__ << " removing key " << key << " coll_id " << entry->m_id
+             << " iterator's entry id " << (*cid_it) << dendl;
+      m_collections_ids.erase(cid_it);
+    }
   }
 
   dout(5) << "get_coll id " << key;
@@ -113,22 +119,23 @@ TestFileStoreState::get_coll_at(int pos, bool erase)
   if (m_collections.empty())
     return NULL;
 
-  coll_entry_t *entry = NULL;
-  map<int, coll_entry_t*>::iterator it = m_collections.begin();
-  for (int i = 0; it != m_collections.end(); it++, i++) {
-    if (i == pos) {
-      entry = it->second;
-      break;
-    }
-  }
+  assert((size_t) pos < m_collections_ids.size());
+
+  int coll_id = m_collections_ids[pos];
+  coll_entry_t *entry = m_collections[coll_id];
 
   if (entry == NULL) {
     dout(5) << "get_coll_at pos " << pos << " non-existent" << dendl;
     return NULL;
   }
 
-  if (erase)
-    m_collections.erase(it);
+  if (erase) {
+    m_collections.erase(coll_id);
+    vector<int>::iterator it = m_collections_ids.begin()+(pos);
+    dout(20) << __func__ << " removing pos " << pos << " coll_id " << coll_id
+           << " iterator's entry id " << (*it) << dendl;
+    m_collections_ids.erase(it);
+  }
 
   dout(5) << "get_coll_at pos " << pos << ": "
       << entry->m_coll << "(removed: " << erase << ")" << dendl;
index 78bcc96ebb89b57469face8cdc6560b46421b743..74276b03f70f8b06019dfc9b83be1191604e90e4 100644 (file)
@@ -18,6 +18,7 @@
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <map>
+#include <vector>
 
 class TestFileStoreState {
 public:
@@ -55,6 +56,7 @@ public:
  protected:
   boost::shared_ptr<ObjectStore> m_store;
   map<int, coll_entry_t*> m_collections;
+  vector<int> m_collections_ids;
   int m_next_coll_nr;
   int m_num_objs_per_coll;
 
index 4dd23ef40fa14ff5fbc9f3974f24210a6cd22458..f97bc66f10644b7bb7707c245a0b642e820bc69a 100644 (file)
@@ -195,13 +195,15 @@ int WorkloadGenerator::get_uniform_random_value(int min, int max)
 
 TestFileStoreState::coll_entry_t *WorkloadGenerator::get_rnd_coll_entry(bool erase = false)
 {
-  int index = get_uniform_random_value(0, m_collections.size()-1);
+  int index = get_uniform_random_value(0, m_collections_ids.size()-1);
   coll_entry_t *entry = get_coll_at(index, erase);
   return entry;
 }
 
 hobject_t *WorkloadGenerator::get_rnd_obj(coll_entry_t *entry)
 {
+  assert(entry != NULL);
+
   bool create =
       (get_uniform_random_value(0,100) < 50 || !entry->m_objects.size());
 
@@ -456,6 +458,7 @@ void WorkloadGenerator::run()
 
     destroy_collection = should_destroy_collection();
     entry = get_rnd_coll_entry(destroy_collection);
+    assert(entry != NULL);
 
     if (destroy_collection) {
       do_destroy_collection(t, entry, stat_state);