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) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 * Placement Group Monitor. Placement Groups are logical sets of objects
17 * that are replicated by the same set of devices.
20 #ifndef CEPH_PGMONITOR_H
21 #define CEPH_PGMONITOR_H
28 #include "PaxosService.h"
29 #include "include/types.h"
30 #include "include/utime.h"
31 #include "common/histogram.h"
32 #include "msg/Messenger.h"
33 #include "mon/MonitorDBStore.h"
42 class PGMonitor
: public PaxosService
{
47 PGMap::Incremental pending_inc
;
49 bool check_all_pgs
= false;
51 const char *pgmap_meta_prefix
;
52 const char *pgmap_pg_prefix
;
53 const char *pgmap_osd_prefix
;
55 void create_initial() override
;
56 void update_from_paxos(bool *need_bootstrap
) override
;
57 void upgrade_format() override
;
58 void on_upgrade() override
;
59 void post_paxos_update() override
;
60 void handle_osd_timeouts();
61 void create_pending() override
; // prepare a new pending
62 // propose pending update to peers
63 version_t
get_trim_to() override
;
66 void encode_pending(MonitorDBStore::TransactionRef t
) override
;
67 void read_pgmap_meta();
68 void read_pgmap_full();
69 void apply_pgmap_delta(bufferlist
& bl
);
71 bool preprocess_query(MonOpRequestRef op
) override
; // true if processed.
72 bool prepare_update(MonOpRequestRef op
) override
;
74 bool preprocess_pg_stats(MonOpRequestRef op
);
75 bool pg_stats_have_changed(int from
, const MPGStats
*stats
) const;
76 bool prepare_pg_stats(MonOpRequestRef op
);
77 void _updated_stats(MonOpRequestRef op
, MonOpRequestRef ack_op
);
81 void handle_statfs(MonOpRequestRef op
);
82 bool preprocess_getpoolstats(MonOpRequestRef op
);
84 bool preprocess_command(MonOpRequestRef op
);
85 bool prepare_command(MonOpRequestRef op
);
87 // when we last received PG stats from each osd
88 map
<int,utime_t
> last_osd_report
;
90 epoch_t
send_pg_creates(int osd
, Connection
*con
, epoch_t next
);
93 PGMonitor(Monitor
*mn
, Paxos
*p
, const string
& service_name
)
94 : PaxosService(mn
, p
, service_name
),
95 pgmap_meta_prefix("pgmap_meta"),
96 pgmap_pg_prefix("pgmap_pg"),
97 pgmap_osd_prefix("pgmap_osd")
99 ~PGMonitor() override
{ }
101 void get_store_prefixes(set
<string
>& s
) override
{
102 s
.insert(get_service_name());
103 s
.insert(pgmap_meta_prefix
);
104 s
.insert(pgmap_pg_prefix
);
105 s
.insert(pgmap_osd_prefix
);
108 void on_restart() override
;
110 /* Courtesy function provided by PaxosService, called when an election
111 * finishes and the cluster goes active. We use it here to make sure we
112 * haven't lost any PGs from new pools. */
113 void on_active() override
;
115 bool should_stash_full() override
{
116 return false; // never
118 void encode_full(MonitorDBStore::TransactionRef t
) override
{
119 assert(0 == "unimplemented encode_full");
123 void tick() override
; // check state, take actions
125 void check_osd_map(epoch_t epoch
);
127 void dump_info(Formatter
*f
) const;
129 int _warn_slow_request_histogram(const pow2_hist_t
& h
, string suffix
,
130 list
<pair
<health_status_t
,string
> >& summary
,
131 list
<pair
<health_status_t
,string
> > *detail
) const;
133 void get_health(list
<pair
<health_status_t
,string
> >& summary
,
134 list
<pair
<health_status_t
,string
> > *detail
,
135 CephContext
*cct
) const override
;
136 void check_full_osd_health(list
<pair
<health_status_t
,string
> >& summary
,
137 list
<pair
<health_status_t
,string
> > *detail
,
138 const set
<int>& s
, const char *desc
, health_status_t sev
) const;
141 bool check_sub(Subscription
*sub
);
144 // no copying allowed
145 PGMonitor(const PGMonitor
&rhs
);
146 PGMonitor
&operator=(const PGMonitor
&rhs
);
148 // we don't want to include gtest.h just for FRIEND_TEST
149 friend class pgmonitor_dump_object_stat_sum_0_Test
;
150 friend class pgmonitor_dump_object_stat_sum_1_Test
;
151 friend class pgmonitor_dump_object_stat_sum_2_Test
;