]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ClusterState.cc
8bc88c530f04fd492521745bf1562b68cbbb7276
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 #include "messages/MMgrDigest.h"
15 #include "messages/MMonMgrReport.h"
16 #include "messages/MPGStats.h"
18 #include "mgr/ClusterState.h"
20 #define dout_context g_ceph_context
21 #define dout_subsys ceph_subsys_mgr
23 #define dout_prefix *_dout << "mgr " << __func__ << " "
25 ClusterState::ClusterState(MonClient
*monc_
, Objecter
*objecter_
)
26 : monc(monc_
), objecter(objecter_
), lock("ClusterState"), pgservice(pg_map
)
29 void ClusterState::set_objecter(Objecter
*objecter_
)
31 Mutex::Locker
l(lock
);
36 void ClusterState::set_fsmap(FSMap
const &new_fsmap
)
38 Mutex::Locker
l(lock
);
43 void ClusterState::load_digest(MMgrDigest
*m
)
45 health_json
= std::move(m
->health_json
);
46 mon_status_json
= std::move(m
->mon_status_json
);
49 void ClusterState::ingest_pgstats(MPGStats
*stats
)
51 Mutex::Locker
l(lock
);
53 const int from
= stats
->get_orig_source().num();
55 objecter
->with_osdmap([&is_in
, from
](const OSDMap
&osd_map
){
56 is_in
= osd_map
.is_in(from
);
60 pending_inc
.update_stat(from
, stats
->epoch
, std::move(stats
->osd_stat
));
62 pending_inc
.update_stat(from
, stats
->epoch
, osd_stat_t());
65 for (auto p
: stats
->pg_stat
) {
67 const auto &pg_stats
= p
.second
;
69 // In case we're hearing about a PG that according to last
70 // OSDMap update should not exist
71 if (existing_pools
.count(pgid
.pool()) == 0) {
72 dout(15) << " got " << pgid
73 << " reported at " << pg_stats
.reported_epoch
<< ":"
74 << pg_stats
.reported_seq
75 << " state " << pg_state_string(pg_stats
.state
)
76 << " but pool not in " << existing_pools
80 // In case we already heard about more recent stats from this PG
82 if (pg_map
.pg_stat
[pgid
].get_version_pair() > pg_stats
.get_version_pair()) {
83 dout(15) << " had " << pgid
<< " from "
84 << pg_map
.pg_stat
[pgid
].reported_epoch
<< ":"
85 << pg_map
.pg_stat
[pgid
].reported_seq
<< dendl
;
89 pending_inc
.pg_stat_updates
[pgid
] = pg_stats
;
93 void ClusterState::update_delta_stats()
95 pending_inc
.stamp
= ceph_clock_now();
96 pending_inc
.version
= pg_map
.version
+ 1; // to make apply_incremental happy
97 dout(10) << " v" << pending_inc
.version
<< dendl
;
99 dout(30) << " pg_map before:\n";
100 JSONFormatter
jf(true);
101 jf
.dump_object("pg_map", pg_map
);
104 dout(30) << " incremental:\n";
105 JSONFormatter
jf(true);
106 jf
.dump_object("pending_inc", pending_inc
);
110 pg_map
.apply_incremental(g_ceph_context
, pending_inc
);
111 pending_inc
= PGMap::Incremental();
114 void ClusterState::notify_osdmap(const OSDMap
&osd_map
)
116 Mutex::Locker
l(lock
);
118 pending_inc
.stamp
= ceph_clock_now();
119 pending_inc
.version
= pg_map
.version
+ 1; // to make apply_incremental happy
120 dout(10) << " v" << pending_inc
.version
<< dendl
;
122 PGMapUpdater::check_osd_map(g_ceph_context
, osd_map
, pg_map
, &pending_inc
);
124 // update our list of pools that exist, so that we can filter pg_map updates
125 // in synchrony with this OSDMap.
126 existing_pools
.clear();
127 for (auto& p
: osd_map
.get_pools()) {
128 existing_pools
.insert(p
.first
);
131 // brute force this for now (don't bother being clever by only
132 // checking osds that went up/down)
133 set
<int> need_check_down_pg_osds
;
134 PGMapUpdater::check_down_pgs(osd_map
, pg_map
, true,
135 need_check_down_pg_osds
, &pending_inc
);
137 dout(30) << " pg_map before:\n";
138 JSONFormatter
jf(true);
139 jf
.dump_object("pg_map", pg_map
);
142 dout(30) << " incremental:\n";
143 JSONFormatter
jf(true);
144 jf
.dump_object("pending_inc", pending_inc
);
148 pg_map
.apply_incremental(g_ceph_context
, pending_inc
);
149 pending_inc
= PGMap::Incremental();
150 // TODO: Complete the separation of PG state handling so
151 // that a cut-down set of functionality remains in PGMonitor
152 // while the full-blown PGMap lives only here.