]>
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; | |
25 | class MPGStats; | |
26 | ||
27 | ||
28 | /** | |
29 | * Cluster-scope state (things like cluster maps) as opposed | |
30 | * to daemon-level state (things like perf counters and smart) | |
31 | */ | |
32 | class ClusterState | |
33 | { | |
34 | protected: | |
35 | MonClient *monc; | |
36 | Objecter *objecter; | |
37 | FSMap fsmap; | |
38 | mutable Mutex lock; | |
39 | ||
40 | PGMap pg_map; | |
41 | ||
42 | bufferlist health_json; | |
43 | bufferlist mon_status_json; | |
44 | ||
45 | public: | |
46 | ||
47 | void load_digest(MMgrDigest *m); | |
48 | void ingest_pgstats(MPGStats *stats); | |
49 | ||
50 | const bufferlist &get_health() const {return health_json;} | |
51 | const bufferlist &get_mon_status() const {return mon_status_json;} | |
52 | ||
53 | ClusterState(MonClient *monc_, Objecter *objecter_); | |
54 | ||
55 | void set_objecter(Objecter *objecter_); | |
56 | void set_fsmap(FSMap const &new_fsmap); | |
57 | ||
58 | void notify_osdmap(const OSDMap &osd_map); | |
59 | ||
60 | bool have_fsmap() const { | |
61 | Mutex::Locker l(lock); | |
62 | return fsmap.get_epoch() > 0; | |
63 | } | |
64 | ||
65 | template<typename Callback, typename...Args> | |
66 | void with_fsmap(Callback&& cb, Args&&...args) const | |
67 | { | |
68 | Mutex::Locker l(lock); | |
69 | std::forward<Callback>(cb)(fsmap, std::forward<Args>(args)...); | |
70 | } | |
71 | ||
72 | template<typename Callback, typename...Args> | |
73 | auto with_pgmap(Callback&& cb, Args&&...args) const -> | |
74 | decltype(cb(pg_map, std::forward<Args>(args)...)) | |
75 | { | |
76 | Mutex::Locker l(lock); | |
77 | return std::forward<Callback>(cb)(pg_map, std::forward<Args>(args)...); | |
78 | } | |
79 | ||
80 | template<typename... Args> | |
81 | void with_monmap(Args &&... args) const | |
82 | { | |
83 | Mutex::Locker l(lock); | |
84 | assert(monc != nullptr); | |
85 | monc->with_monmap(std::forward<Args>(args)...); | |
86 | } | |
87 | ||
88 | template<typename... Args> | |
89 | auto with_osdmap(Args &&... args) const -> | |
90 | decltype(objecter->with_osdmap(std::forward<Args>(args)...)) | |
91 | { | |
92 | assert(objecter != nullptr); | |
93 | return objecter->with_osdmap(std::forward<Args>(args)...); | |
94 | } | |
95 | ||
96 | }; | |
97 | ||
98 | #endif | |
99 |