]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/ImageSyncThrottler.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd_mirror / ImageSyncThrottler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 SUSE LINUX GmbH
7 *
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.
12 *
13 */
14
15 #ifndef CEPH_RBD_MIRROR_IMAGE_SYNC_THROTTLER_H
16 #define CEPH_RBD_MIRROR_IMAGE_SYNC_THROTTLER_H
17
18 #include <list>
19 #include <map>
20 #include <utility>
21 #include "common/Mutex.h"
22 #include "librbd/ImageCtx.h"
23 #include "include/Context.h"
24 #include "librbd/journal/TypeTraits.h"
25
26 class CephContext;
27 class Context;
28 class ContextWQ;
29 class SafeTimer;
30 namespace journal { class Journaler; }
31 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
32
33 namespace rbd {
34 namespace mirror {
35
36 template <typename> class ImageSync;
37
38 class ProgressContext;
39
40 /**
41 * Manage concurrent image-syncs
42 */
43 template <typename ImageCtxT = librbd::ImageCtx>
44 class ImageSyncThrottler : public md_config_obs_t {
45 public:
46
47 typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
48 typedef typename TypeTraits::Journaler Journaler;
49 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
50
51 ImageSyncThrottler();
52 ~ImageSyncThrottler() override;
53 ImageSyncThrottler(const ImageSyncThrottler&) = delete;
54 ImageSyncThrottler& operator=(const ImageSyncThrottler&) = delete;
55
56 void start_sync(ImageCtxT *local_image_ctx,
57 ImageCtxT *remote_image_ctx, SafeTimer *timer,
58 Mutex *timer_lock, const std::string &mirror_uuid,
59 Journaler *journaler, MirrorPeerClientMeta *client_meta,
60 ContextWQ *work_queue, Context *on_finish,
61 ProgressContext *progress_ctx = nullptr);
62
63 void cancel_sync(librados::IoCtx &local_io_ctx,
64 const std::string local_image_id);
65
66 void set_max_concurrent_syncs(uint32_t max);
67
68 void print_status(Formatter *f, std::stringstream *ss);
69
70 private:
71 typedef std::pair<int64_t, std::string> PoolImageId;
72
73 struct C_SyncHolder;
74
75 void handle_sync_finished(C_SyncHolder *sync_holder);
76
77 const char **get_tracked_conf_keys() const override;
78 void handle_conf_change(const struct md_config_t *conf,
79 const std::set<std::string> &changed) override;
80
81 uint32_t m_max_concurrent_syncs;
82 Mutex m_lock;
83 std::list<C_SyncHolder *> m_sync_queue;
84 std::map<PoolImageId, C_SyncHolder *> m_inflight_syncs;
85
86 };
87
88 } // namespace mirror
89 } // namespace rbd
90
91 #endif // CEPH_RBD_MIRROR_IMAGE_SYNC_THROTTLER_H