1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 John Spray <john.spray@inktank.com>
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.
14 #ifndef CLUSTER_STATE_H_
15 #define CLUSTER_STATE_H_
17 #include "mds/FSMap.h"
18 #include "mon/MgrMap.h"
19 #include "common/Mutex.h"
21 #include "osdc/Objecter.h"
22 #include "mon/MonClient.h"
23 #include "mon/PGMap.h"
24 #include "mgr/ServiceMap.h"
32 * Cluster-scope state (things like cluster maps) as opposed
33 * to daemon-level state (things like perf counters and smart)
41 ServiceMap servicemap
;
46 set
<int64_t> existing_pools
; ///< pools that exist, as of PGMap epoch
48 PGMap::Incremental pending_inc
;
50 PGMapStatService pgservice
;
52 bufferlist health_json
;
53 bufferlist mon_status_json
;
57 void load_digest(MMgrDigest
*m
);
58 void ingest_pgstats(MPGStats
*stats
);
60 void update_delta_stats();
62 const bufferlist
&get_health() const {return health_json
;}
63 const bufferlist
&get_mon_status() const {return mon_status_json
;}
65 ClusterState(MonClient
*monc_
, Objecter
*objecter_
, const MgrMap
& mgrmap
);
67 void set_objecter(Objecter
*objecter_
);
68 void set_fsmap(FSMap
const &new_fsmap
);
69 void set_mgr_map(MgrMap
const &new_mgrmap
);
70 void set_service_map(ServiceMap
const &new_service_map
);
72 void notify_osdmap(const OSDMap
&osd_map
);
74 bool have_fsmap() const {
75 Mutex::Locker
l(lock
);
76 return fsmap
.get_epoch() > 0;
79 template<typename Callback
, typename
...Args
>
80 void with_servicemap(Callback
&& cb
, Args
&&...args
) const
82 Mutex::Locker
l(lock
);
83 std::forward
<Callback
>(cb
)(servicemap
, std::forward
<Args
>(args
)...);
86 template<typename Callback
, typename
...Args
>
87 void with_fsmap(Callback
&& cb
, Args
&&...args
) const
89 Mutex::Locker
l(lock
);
90 std::forward
<Callback
>(cb
)(fsmap
, std::forward
<Args
>(args
)...);
93 template<typename Callback
, typename
...Args
>
94 void with_mgrmap(Callback
&& cb
, Args
&&...args
) const
96 Mutex::Locker
l(lock
);
97 std::forward
<Callback
>(cb
)(mgr_map
, std::forward
<Args
>(args
)...);
100 template<typename Callback
, typename
...Args
>
101 auto with_pgmap(Callback
&& cb
, Args
&&...args
) const ->
102 decltype(cb(pg_map
, std::forward
<Args
>(args
)...))
104 Mutex::Locker
l(lock
);
105 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
108 template<typename Callback
, typename
...Args
>
109 auto with_pgservice(Callback
&& cb
, Args
&&...args
) const ->
110 decltype(cb(pgservice
, std::forward
<Args
>(args
)...))
112 Mutex::Locker
l(lock
);
113 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
116 template<typename
... Args
>
117 void with_monmap(Args
&&... args
) const
119 Mutex::Locker
l(lock
);
120 assert(monc
!= nullptr);
121 monc
->with_monmap(std::forward
<Args
>(args
)...);
124 template<typename
... Args
>
125 auto with_osdmap(Args
&&... args
) const ->
126 decltype(objecter
->with_osdmap(std::forward
<Args
>(args
)...))
128 assert(objecter
!= nullptr);
129 return objecter
->with_osdmap(std::forward
<Args
>(args
)...);