]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 "common/Mutex.h" | |
19 | ||
20 | #include "osdc/Objecter.h" | |
21 | #include "mon/MonClient.h" | |
22 | #include "mon/PGMap.h" | |
23 | ||
24 | class MMgrDigest; | |
31f18b77 | 25 | class MMonMgrReport; |
7c673cae FG |
26 | class MPGStats; |
27 | ||
28 | ||
29 | /** | |
30 | * Cluster-scope state (things like cluster maps) as opposed | |
31 | * to daemon-level state (things like perf counters and smart) | |
32 | */ | |
33 | class ClusterState | |
34 | { | |
35 | protected: | |
36 | MonClient *monc; | |
37 | Objecter *objecter; | |
38 | FSMap fsmap; | |
39 | mutable Mutex lock; | |
40 | ||
31f18b77 | 41 | set<int64_t> existing_pools; ///< pools that exist, as of PGMap epoch |
7c673cae | 42 | PGMap pg_map; |
31f18b77 FG |
43 | PGMap::Incremental pending_inc; |
44 | ||
45 | PGMapStatService pgservice; | |
7c673cae FG |
46 | |
47 | bufferlist health_json; | |
48 | bufferlist mon_status_json; | |
49 | ||
50 | public: | |
51 | ||
52 | void load_digest(MMgrDigest *m); | |
53 | void ingest_pgstats(MPGStats *stats); | |
54 | ||
31f18b77 FG |
55 | void update_delta_stats(); |
56 | ||
7c673cae FG |
57 | const bufferlist &get_health() const {return health_json;} |
58 | const bufferlist &get_mon_status() const {return mon_status_json;} | |
59 | ||
60 | ClusterState(MonClient *monc_, Objecter *objecter_); | |
61 | ||
62 | void set_objecter(Objecter *objecter_); | |
63 | void set_fsmap(FSMap const &new_fsmap); | |
64 | ||
65 | void notify_osdmap(const OSDMap &osd_map); | |
66 | ||
67 | bool have_fsmap() const { | |
68 | Mutex::Locker l(lock); | |
69 | return fsmap.get_epoch() > 0; | |
70 | } | |
71 | ||
72 | template<typename Callback, typename...Args> | |
73 | void with_fsmap(Callback&& cb, Args&&...args) const | |
74 | { | |
75 | Mutex::Locker l(lock); | |
76 | std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...); | |
77 | } | |
78 | ||
79 | template<typename Callback, typename...Args> | |
80 | auto with_pgmap(Callback&& cb, Args&&...args) const -> | |
81 | decltype(cb(pg_map, std::forward<Args>(args)...)) | |
82 | { | |
83 | Mutex::Locker l(lock); | |
84 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); | |
85 | } | |
86 | ||
31f18b77 FG |
87 | template<typename Callback, typename...Args> |
88 | auto with_pgservice(Callback&& cb, Args&&...args) const -> | |
89 | decltype(cb(pgservice, std::forward<Args>(args)...)) | |
90 | { | |
91 | Mutex::Locker l(lock); | |
92 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); | |
93 | } | |
94 | ||
7c673cae FG |
95 | template<typename... Args> |
96 | void with_monmap(Args &&... args) const | |
97 | { | |
98 | Mutex::Locker l(lock); | |
99 | assert(monc != nullptr); | |
100 | monc->with_monmap(std::forward<Args>(args)...); | |
101 | } | |
102 | ||
103 | template<typename... Args> | |
104 | auto with_osdmap(Args &&... args) const -> | |
105 | decltype(objecter->with_osdmap(std::forward<Args>(args)...)) | |
106 | { | |
107 | assert(objecter != nullptr); | |
108 | return objecter->with_osdmap(std::forward<Args>(args)...); | |
109 | } | |
110 | ||
111 | }; | |
112 | ||
113 | #endif | |
114 |