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 "common/Mutex.h"
20 #include "osdc/Objecter.h"
21 #include "mon/MonClient.h"
22 #include "mon/PGMap.h"
30 * Cluster-scope state (things like cluster maps) as opposed
31 * to daemon-level state (things like perf counters and smart)
41 set
<int64_t> existing_pools
; ///< pools that exist, as of PGMap epoch
43 PGMap::Incremental pending_inc
;
45 PGMapStatService pgservice
;
47 bufferlist health_json
;
48 bufferlist mon_status_json
;
52 void load_digest(MMgrDigest
*m
);
53 void ingest_pgstats(MPGStats
*stats
);
55 void update_delta_stats();
57 const bufferlist
&get_health() const {return health_json
;}
58 const bufferlist
&get_mon_status() const {return mon_status_json
;}
60 ClusterState(MonClient
*monc_
, Objecter
*objecter_
);
62 void set_objecter(Objecter
*objecter_
);
63 void set_fsmap(FSMap
const &new_fsmap
);
65 void notify_osdmap(const OSDMap
&osd_map
);
67 bool have_fsmap() const {
68 Mutex::Locker
l(lock
);
69 return fsmap
.get_epoch() > 0;
72 template<typename Callback
, typename
...Args
>
73 void with_fsmap(Callback
&& cb
, Args
&&...args
) const
75 Mutex::Locker
l(lock
);
76 std::forward
<Callback
>(cb
)(fsmap
, std::forward
<Args
>(args
)...);
79 template<typename Callback
, typename
...Args
>
80 auto with_pgmap(Callback
&& cb
, Args
&&...args
) const ->
81 decltype(cb(pg_map
, std::forward
<Args
>(args
)...))
83 Mutex::Locker
l(lock
);
84 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
87 template<typename Callback
, typename
...Args
>
88 auto with_pgservice(Callback
&& cb
, Args
&&...args
) const ->
89 decltype(cb(pgservice
, std::forward
<Args
>(args
)...))
91 Mutex::Locker
l(lock
);
92 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
95 template<typename
... Args
>
96 void with_monmap(Args
&&... args
) const
98 Mutex::Locker
l(lock
);
99 assert(monc
!= nullptr);
100 monc
->with_monmap(std::forward
<Args
>(args
)...);
103 template<typename
... Args
>
104 auto with_osdmap(Args
&&... args
) const ->
105 decltype(objecter
->with_osdmap(std::forward
<Args
>(args
)...))
107 assert(objecter
!= nullptr);
108 return objecter
->with_osdmap(std::forward
<Args
>(args
)...);