]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-replay: Change Worker::m_pending_ios from vector to map
authorAdam Crume <adamcrume@gmail.com>
Fri, 18 Jul 2014 20:42:43 +0000 (13:42 -0700)
committerSage Weil <sage@redhat.com>
Thu, 21 Aug 2014 17:57:29 +0000 (10:57 -0700)
Signed-off-by: Adam Crume <adamcrume@gmail.com>
src/rbd_replay/Replayer.cc
src/rbd_replay/Replayer.hpp

index 6802c95c69788467fe95e1c2f87e616353a40022..86741ae3fe2386463b3582c416e74d18c36e55ff 100644 (file)
@@ -49,7 +49,8 @@ void Worker::send(Action::ptr action) {
 
 void Worker::add_pending(PendingIO::ptr io) {
   boost::mutex::scoped_lock lock(m_pending_ios_mutex);
-  m_pending_ios.push_back(io);
+  assertf(m_pending_ios.count(io->id()) == 0, "id = %d", io->id());
+  m_pending_ios[io->id()] = io;
 }
 
 void Worker::run() {
@@ -67,8 +68,9 @@ void Worker::run() {
     while (!m_pending_ios.empty()) {
       if (!first_time) {
        dout(THREAD_LEVEL) << "Worker thread trying to stop, still waiting for " << m_pending_ios.size() << " pending IOs to complete:" << dendl;
-       BOOST_FOREACH(PendingIO::ptr p, m_pending_ios) {
-         dout(THREAD_LEVEL) << "> " << p->id() << dendl;
+       pair<action_id_t, PendingIO::ptr> p;
+       BOOST_FOREACH(p, m_pending_ios) {
+         dout(THREAD_LEVEL) << "> " << p.first << dendl;
        }
       }
       m_pending_ios_empty.timed_wait(lock, boost::posix_time::seconds(1));
@@ -82,12 +84,8 @@ void Worker::run() {
 void Worker::remove_pending(PendingIO::ptr io) {
   m_replayer.set_action_complete(io->id());
   boost::mutex::scoped_lock lock(m_pending_ios_mutex);
-  for (vector<PendingIO::ptr>::iterator itr = m_pending_ios.begin(); itr != m_pending_ios.end(); itr++) {
-    if (*itr == io) {
-      m_pending_ios.erase(itr);
-      break;
-    }
-  }
+  size_t num_erased = m_pending_ios.erase(io->id());
+  assertf(num_erased == 1, "id = %d", io->id());
   if (m_pending_ios.empty()) {
     m_pending_ios_empty.notify_all();
   }
index be95a1050c544930b34d22b14e5e79db353ea1bd..a585f5615963ac6d0ee732e4cf9444dbe5f9cfa2 100644 (file)
@@ -59,7 +59,7 @@ private:
   Replayer &m_replayer;
   BoundedBuffer<Action::ptr> m_buffer;
   boost::shared_ptr<boost::thread> m_thread;
-  std::vector<PendingIO::ptr> m_pending_ios;
+  std::map<action_id_t, PendingIO::ptr> m_pending_ios;
   boost::mutex m_pending_ios_mutex;
   boost::condition m_pending_ios_empty;
   bool m_done;