1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
7 #include <seastar/core/future.hh>
8 #include <seastar/core/gate.hh>
9 #include <seastar/core/lowres_clock.hh>
10 #include <seastar/core/timer.hh>
12 #include "auth/KeyRing.h"
14 #include "crimson/net/Dispatcher.h"
15 #include "crimson/net/Fwd.h"
17 #include "mon/MonMap.h"
19 #include "mon/MonSub.h"
21 template<typename Message
> using Ref
= boost::intrusive_ptr
<Message
>;
29 struct MMonSubscribeAck
;
30 struct MMonGetVersionReply
;
31 struct MMonCommandAck
;
39 class Client
: public ceph::net::Dispatcher
{
40 EntityName entity_name
;
42 std::unique_ptr
<AuthMethodList
> auth_methods
;
43 const uint32_t want_keys
;
46 seastar::promise
<MessageRef
> reply
;
47 std::unique_ptr
<Connection
> active_con
;
48 std::vector
<Connection
> pending_conns
;
49 seastar::timer
<seastar::lowres_clock
> timer
;
50 seastar::gate tick_gate
;
52 ceph::net::Messenger
& msgr
;
55 using get_version_t
= seastar::future
<version_t
, version_t
>;
57 ceph_tid_t last_version_req_id
= 0;
58 std::map
<ceph_tid_t
, typename
get_version_t::promise_type
> version_reqs
;
60 ceph_tid_t last_mon_command_id
= 0;
61 using command_result_t
=
62 seastar::future
<std::int32_t, string
, ceph::bufferlist
>;
63 std::map
<ceph_tid_t
, typename
command_result_t::promise_type
> mon_commands
;
68 Client(ceph::net::Messenger
& messenger
);
71 seastar::future
<> start();
72 seastar::future
<> stop();
74 const uuid_d
& get_fsid() const {
77 get_version_t
get_version(const std::string
& map
);
78 command_result_t
run_command(const std::vector
<std::string
>& cmd
,
79 const bufferlist
& bl
);
80 seastar::future
<> send_message(MessageRef
);
81 bool sub_want(const std::string
& what
, version_t start
, unsigned flags
);
82 void sub_got(const std::string
& what
, version_t have
);
83 void sub_unwant(const std::string
& what
);
84 bool sub_want_increment(const std::string
& what
, version_t start
, unsigned flags
);
85 seastar::future
<> renew_subs();
90 seastar::future
<> ms_dispatch(ceph::net::ConnectionRef conn
,
91 MessageRef m
) override
;
92 seastar::future
<> ms_handle_reset(ceph::net::ConnectionRef conn
) override
;
94 seastar::future
<> handle_monmap(ceph::net::ConnectionRef conn
,
96 seastar::future
<> handle_auth_reply(ceph::net::ConnectionRef conn
,
98 seastar::future
<> handle_subscribe_ack(Ref
<MMonSubscribeAck
> m
);
99 seastar::future
<> handle_get_version_reply(Ref
<MMonGetVersionReply
> m
);
100 seastar::future
<> handle_mon_command_ack(Ref
<MMonCommandAck
> m
);
101 seastar::future
<> handle_log_ack(Ref
<MLogAck
> m
);
102 seastar::future
<> handle_config(Ref
<MConfig
> m
);
105 seastar::future
<> load_keyring();
106 seastar::future
<> authenticate();
108 bool is_hunting() const;
109 seastar::future
<> reopen_session(int rank
);
110 std::vector
<unsigned> get_random_mons(unsigned n
) const;
111 seastar::future
<> _add_conn(unsigned rank
, uint64_t global_id
);
114 } // namespace ceph::mon