1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef _INCLUDED_RBD_REPLAY_REPLAYER_HPP
16 #define _INCLUDED_RBD_REPLAY_REPLAYER_HPP
18 #include <boost/thread/mutex.hpp>
19 #include <boost/thread/shared_mutex.hpp>
20 #include "rbd_replay/ActionTypes.h"
21 #include "BoundedBuffer.hpp"
22 #include "ImageNameMap.hpp"
23 #include "PendingIO.hpp"
25 namespace rbd_replay {
30 Performs Actions within a single thread.
32 class Worker : public ActionCtx {
34 explicit Worker(Replayer &replayer);
38 /// Should only be called by StopThreadAction
43 void send(Action::ptr action);
45 void add_pending(PendingIO::ptr io) override;
47 void remove_pending(PendingIO::ptr io) override;
49 librbd::Image* get_image(imagectx_id_t imagectx_id) override;
51 void put_image(imagectx_id_t imagectx_id, librbd::Image* image) override;
53 void erase_image(imagectx_id_t imagectx_id) override;
55 librbd::RBD* rbd() override;
57 librados::IoCtx* ioctx() override;
59 void set_action_complete(action_id_t id) override;
61 bool readonly() const override;
63 rbd_loc map_image_name(std::string image_name, std::string snap_name) const override;
69 BoundedBuffer<Action::ptr> m_buffer;
70 boost::shared_ptr<boost::thread> m_thread;
71 std::map<action_id_t, PendingIO::ptr> m_pending_ios;
72 boost::mutex m_pending_ios_mutex;
73 boost::condition m_pending_ios_empty;
80 explicit Replayer(int num_action_trackers);
84 void run(const std::string &replay_file);
86 librbd::RBD* get_rbd() {
90 librados::IoCtx* get_ioctx() {
94 librbd::Image* get_image(imagectx_id_t imagectx_id);
96 void put_image(imagectx_id_t imagectx_id, librbd::Image *image);
98 void erase_image(imagectx_id_t imagectx_id);
100 void set_action_complete(action_id_t id);
102 bool is_action_complete(action_id_t id);
104 void wait_for_actions(const action::Dependencies &deps);
106 std::string pool_name() const;
108 void set_pool_name(std::string pool_name);
110 void set_latency_multiplier(float f);
112 bool readonly() const;
114 void set_readonly(bool readonly);
116 void set_image_name_map(const ImageNameMap &map) {
117 m_image_name_map = map;
120 void set_dump_perf_counters(bool dump_perf_counters) {
121 m_dump_perf_counters = dump_perf_counters;
124 const ImageNameMap &image_name_map() const {
125 return m_image_name_map;
129 struct action_tracker_d {
130 /// Maps an action ID to the time the action completed
131 std::map<action_id_t, boost::system_time> actions;
132 boost::shared_mutex mutex;
133 boost::condition condition;
138 action_tracker_d &tracker_for(action_id_t id);
141 Replayer(const Replayer& rhs);
142 /// Disallow assignment
143 const Replayer& operator=(const Replayer& rhs);
146 librados::IoCtx* m_ioctx;
147 std::string m_pool_name;
148 float m_latency_multiplier;
150 ImageNameMap m_image_name_map;
151 bool m_dump_perf_counters;
153 std::map<imagectx_id_t, librbd::Image*> m_images;
154 boost::shared_mutex m_images_mutex;
156 /// Actions are hashed across the trackers by ID.
157 /// Number of trackers should probably be larger than the number of cores and prime.
158 /// Should definitely be odd.
159 const int m_num_action_trackers;
160 action_tracker_d* m_action_trackers;