]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/Throttler.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / tools / rbd_mirror / Throttler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RBD_MIRROR_THROTTLER_H
5 #define RBD_MIRROR_THROTTLER_H
6
7 #include <list>
8 #include <map>
9 #include <set>
10 #include <sstream>
11 #include <string>
12 #include <utility>
13
14 #include "common/ceph_mutex.h"
15 #include "common/config_obs.h"
16 #include "include/common_fwd.h"
17
18 class Context;
19
20 namespace ceph { class Formatter; }
21 namespace librbd { class ImageCtx; }
22
23 namespace rbd {
24 namespace mirror {
25
26 template <typename ImageCtxT = librbd::ImageCtx>
27 class Throttler : public md_config_obs_t {
28 public:
29 static Throttler *create(
30 CephContext *cct,
31 const std::string &config_key) {
32 return new Throttler(cct, config_key);
33 }
34 void destroy() {
35 delete this;
36 }
37
38 Throttler(CephContext *cct,
39 const std::string &config_key);
40 ~Throttler() override;
41
42 void set_max_concurrent_ops(uint32_t max);
43 void start_op(const std::string &ns, const std::string &id,
44 Context *on_start);
45 bool cancel_op(const std::string &ns, const std::string &id);
46 void finish_op(const std::string &ns, const std::string &id);
47 void drain(const std::string &ns, int r);
48
49 void print_status(ceph::Formatter *f);
50
51 private:
52 typedef std::pair<std::string, std::string> Id;
53
54 CephContext *m_cct;
55 const std::string m_config_key;
56 mutable const char* m_config_keys[2];
57
58 ceph::mutex m_lock;
59 uint32_t m_max_concurrent_ops;
60 std::list<Id> m_queue;
61 std::map<Id, Context *> m_queued_ops;
62 std::set<Id> m_inflight_ops;
63
64 const char **get_tracked_conf_keys() const override;
65 void handle_conf_change(const ConfigProxy& conf,
66 const std::set<std::string> &changed) override;
67 };
68
69 } // namespace mirror
70 } // namespace rbd
71
72 extern template class rbd::mirror::Throttler<librbd::ImageCtx>;
73
74 #endif // RBD_MIRROR_THROTTLER_H