]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ClusterState.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / mgr / ClusterState.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) 2014 John Spray <john.spray@inktank.com>
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 #ifndef CLUSTER_STATE_H_
15 #define CLUSTER_STATE_H_
16
17 #include "mds/FSMap.h"
18 #include "mon/MgrMap.h"
19 #include "common/ceph_mutex.h"
20
21 #include "osdc/Objecter.h"
22 #include "mon/MonClient.h"
23 #include "mon/PGMap.h"
24 #include "mgr/ServiceMap.h"
25
26 class MMgrDigest;
27 class MMonMgrReport;
28 class MPGStats;
29
30
31 /**
32 * Cluster-scope state (things like cluster maps) as opposed
33 * to daemon-level state (things like perf counters and smart)
34 */
35 class ClusterState
36 {
37 protected:
38 MonClient *monc;
39 Objecter *objecter;
40 FSMap fsmap;
41 ServiceMap servicemap;
42 mutable ceph::mutex lock = ceph::make_mutex("ClusterState");
43
44 MgrMap mgr_map;
45
46 std::map<int64_t,unsigned> existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch
47 PGMap pg_map;
48 PGMap::Incremental pending_inc;
49
50 bufferlist health_json;
51 bufferlist mon_status_json;
52
53 class ClusterSocketHook *asok_hook;
54
55 public:
56
57 void load_digest(MMgrDigest *m);
58 void ingest_pgstats(ceph::ref_t<MPGStats> stats);
59
60 void update_delta_stats();
61
62 ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap);
63
64 void set_objecter(Objecter *objecter_);
65 void set_fsmap(FSMap const &new_fsmap);
66 void set_mgr_map(MgrMap const &new_mgrmap);
67 void set_service_map(ServiceMap const &new_service_map);
68
69 void notify_osdmap(const OSDMap &osd_map);
70
71 bool have_fsmap() const {
72 std::lock_guard l(lock);
73 return fsmap.get_epoch() > 0;
74 }
75
76 template<typename Callback, typename...Args>
77 auto with_servicemap(Callback&& cb, Args&&...args) const
78 {
79 std::lock_guard l(lock);
80 return std::forward<Callback>(cb)(servicemap, std::forward<Args>(args)...);
81 }
82
83 template<typename Callback, typename...Args>
84 auto with_fsmap(Callback&& cb, Args&&...args) const
85 {
86 std::lock_guard l(lock);
87 return std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...);
88 }
89
90 template<typename Callback, typename...Args>
91 auto with_mgrmap(Callback&& cb, Args&&...args) const
92 {
93 std::lock_guard l(lock);
94 return std::forward<Callback>(cb)(mgr_map, std::forward<Args>(args)...);
95 }
96
97 template<typename Callback, typename...Args>
98 auto with_pgmap(Callback&& cb, Args&&...args) const ->
99 decltype(cb(pg_map, std::forward<Args>(args)...))
100 {
101 std::lock_guard l(lock);
102 return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...);
103 }
104
105 template<typename Callback, typename...Args>
106 auto with_mutable_pgmap(Callback&& cb, Args&&...args) ->
107 decltype(cb(pg_map, std::forward<Args>(args)...))
108 {
109 std::lock_guard l(lock);
110 return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...);
111 }
112
113 template<typename... Args>
114 auto with_monmap(Args &&... args) const
115 {
116 std::lock_guard l(lock);
117 ceph_assert(monc != nullptr);
118 return monc->with_monmap(std::forward<Args>(args)...);
119 }
120
121 template<typename... Args>
122 auto with_osdmap(Args &&... args) const ->
123 decltype(objecter->with_osdmap(std::forward<Args>(args)...))
124 {
125 ceph_assert(objecter != nullptr);
126 return objecter->with_osdmap(std::forward<Args>(args)...);
127 }
128
129 // call cb(osdmap, pg_map, ...args) with the appropriate locks
130 template <typename Callback, typename ...Args>
131 auto with_osdmap_and_pgmap(Callback&& cb, Args&& ...args) const {
132 ceph_assert(objecter != nullptr);
133 std::lock_guard l(lock);
134 return objecter->with_osdmap(
135 std::forward<Callback>(cb),
136 pg_map,
137 std::forward<Args>(args)...);
138 }
139
140 template<typename Callback, typename...Args>
141 auto with_health(Callback&& cb, Args&&...args) const
142 {
143 std::lock_guard l(lock);
144 return std::forward<Callback>(cb)(health_json, std::forward<Args>(args)...);
145 }
146
147 template<typename Callback, typename...Args>
148 auto with_mon_status(Callback&& cb, Args&&...args) const
149 {
150 std::lock_guard l(lock);
151 return std::forward<Callback>(cb)(mon_status_json, std::forward<Args>(args)...);
152 }
153
154 void final_init();
155 void shutdown();
156 bool asok_command(std::string_view admin_command,
157 const cmdmap_t& cmdmap,
158 Formatter *f,
159 std::ostream& ss);
160 };
161
162 #endif
163