From f2228c0c9f7cade1b3b81ddddbf0db87a16782ea Mon Sep 17 00:00:00 2001 From: Adam Crume Date: Fri, 18 Jul 2014 13:42:43 -0700 Subject: [PATCH] rbd-replay: Change Worker::m_pending_ios from vector to map Signed-off-by: Adam Crume --- src/rbd_replay/Replayer.cc | 16 +++++++--------- src/rbd_replay/Replayer.hpp | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/rbd_replay/Replayer.cc b/src/rbd_replay/Replayer.cc index 6802c95c69788..86741ae3fe238 100644 --- a/src/rbd_replay/Replayer.cc +++ b/src/rbd_replay/Replayer.cc @@ -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 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::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(); } diff --git a/src/rbd_replay/Replayer.hpp b/src/rbd_replay/Replayer.hpp index be95a1050c544..a585f5615963a 100644 --- a/src/rbd_replay/Replayer.hpp +++ b/src/rbd_replay/Replayer.hpp @@ -59,7 +59,7 @@ private: Replayer &m_replayer; BoundedBuffer m_buffer; boost::shared_ptr m_thread; - std::vector m_pending_ios; + std::map m_pending_ios; boost::mutex m_pending_ios_mutex; boost::condition m_pending_ios_empty; bool m_done; -- 2.39.5