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.
15 #ifndef CEPH_MMGRBEACON_H
16 #define CEPH_MMGRBEACON_H
18 #include "messages/PaxosServiceMessage.h"
19 #include "mon/MonCommand.h"
20 #include "mon/MgrMap.h"
22 #include "include/types.h"
25 class MMgrBeacon final
: public PaxosServiceMessage
{
27 static constexpr int HEAD_VERSION
= 11;
28 static constexpr int COMPAT_VERSION
= 8;
32 entity_addrvec_t server_addrs
;
37 // From active daemon to populate MgrMap::services
38 std::map
<std::string
, std::string
> services
;
40 // Only populated during activation
41 std::vector
<MonCommand
> command_descs
;
43 // Information about the modules found locally on this daemon
44 std::vector
<MgrMap::ModuleInfo
> modules
;
46 std::map
<std::string
,std::string
> metadata
; ///< misc metadata about this osd
48 std::multimap
<std::string
, entity_addrvec_t
> clients
;
50 uint64_t mgr_features
= 0; ///< reporting mgr's features
54 : PaxosServiceMessage
{MSG_MGR_BEACON
, 0, HEAD_VERSION
, COMPAT_VERSION
},
55 gid(0), available(false)
58 MMgrBeacon(const uuid_d
& fsid_
, uint64_t gid_
, const std::string
&name_
,
59 entity_addrvec_t server_addrs_
, bool available_
,
60 std::vector
<MgrMap::ModuleInfo
>&& modules_
,
61 std::map
<std::string
,std::string
>&& metadata_
,
62 std::multimap
<std::string
, entity_addrvec_t
>&& clients_
,
64 : PaxosServiceMessage
{MSG_MGR_BEACON
, 0, HEAD_VERSION
, COMPAT_VERSION
},
65 gid(gid_
), server_addrs(server_addrs_
), available(available_
), name(name_
),
66 fsid(fsid_
), modules(std::move(modules_
)), metadata(std::move(metadata_
)),
67 clients(std::move(clients_
)),
72 uint64_t get_gid() const { return gid
; }
73 entity_addrvec_t
get_server_addrs() const { return server_addrs
; }
74 bool get_available() const { return available
; }
75 const std::string
& get_name() const { return name
; }
76 const uuid_d
& get_fsid() const { return fsid
; }
77 const std::map
<std::string
,std::string
>& get_metadata() const {
80 const std::map
<std::string
,std::string
>& get_services() const {
83 uint64_t get_mgr_features() const { return mgr_features
; }
85 void set_services(const std::map
<std::string
, std::string
> &svcs
)
90 void set_command_descs(const std::vector
<MonCommand
> &cmds
)
95 const std::vector
<MonCommand
> &get_command_descs()
100 const std::vector
<MgrMap::ModuleInfo
> &get_available_modules() const
105 const auto& get_clients() const
111 ~MMgrBeacon() final
{}
115 std::string_view
get_type_name() const override
{ return "mgrbeacon"; }
117 void print(std::ostream
& out
) const override
{
118 out
<< get_type_name() << " mgr." << name
<< "(" << fsid
<< ","
119 << gid
<< ", " << server_addrs
<< ", " << available
123 void encode_payload(uint64_t features
) override
{
124 header
.version
= HEAD_VERSION
;
125 header
.compat_version
= COMPAT_VERSION
;
129 assert(HAVE_FEATURE(features
, SERVER_NAUTILUS
));
130 encode(server_addrs
, payload
, features
);
131 encode(gid
, payload
);
132 encode(available
, payload
);
133 encode(name
, payload
);
134 encode(fsid
, payload
);
136 // Fill out old-style list of module names (deprecated by
137 // later field of full ModuleInfos)
138 std::set
<std::string
> module_names
;
139 for (const auto &info
: modules
) {
140 module_names
.insert(info
.name
);
142 encode(module_names
, payload
);
144 encode(command_descs
, payload
);
145 encode(metadata
, payload
);
146 encode(services
, payload
);
148 encode(modules
, payload
);
149 encode(mgr_features
, payload
);
151 std::vector
<std::string
> clients_names
;
152 std::vector
<entity_addrvec_t
> clients_addrs
;
153 for (const auto& i
: clients
) {
154 clients_names
.push_back(i
.first
);
155 clients_addrs
.push_back(i
.second
);
157 // The address vector needs to be encoded first to produce a
158 // backwards compatible messsage for older monitors.
159 encode(clients_addrs
, payload
, features
);
160 encode(clients_names
, payload
, features
);
162 void decode_payload() override
{
164 auto p
= payload
.cbegin();
166 assert(header
.version
>= 8);
167 decode(server_addrs
, p
); // entity_addr_t for version < 8
169 decode(available
, p
);
172 std::set
<std::string
> module_name_list
;
173 decode(module_name_list
, p
);
174 decode(command_descs
, p
);
178 if (header
.version
>= 9) {
179 decode(mgr_features
, p
);
181 if (header
.version
>= 10) {
182 std::vector
<entity_addrvec_t
> clients_addrs
;
183 decode(clients_addrs
, p
);
185 if (header
.version
>= 11) {
186 std::vector
<std::string
> clients_names
;
187 decode(clients_names
, p
);
188 if (clients_names
.size() != clients_addrs
.size()) {
189 throw ceph::buffer::malformed_input(
190 "clients_names.size() != clients_addrs.size()");
192 auto cn
= clients_names
.begin();
193 auto ca
= clients_addrs
.begin();
194 for(; cn
!= clients_names
.end(); ++cn
, ++ca
) {
195 clients
.emplace(*cn
, *ca
);
198 for (const auto& i
: clients_addrs
) {
199 clients
.emplace("", i
);
205 template<class T
, typename
... Args
>
206 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);