]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/mon/MonClient.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / crimson / mon / MonClient.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #pragma once
4
5 #include <memory>
6
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>
11
12 #include "auth/KeyRing.h"
13
14 #include "crimson/net/Dispatcher.h"
15 #include "crimson/net/Fwd.h"
16
17 #include "mon/MonMap.h"
18
19 #include "mon/MonSub.h"
20
21 template<typename Message> using Ref = boost::intrusive_ptr<Message>;
22 namespace ceph::net {
23 class Messenger;
24 }
25
26 class AuthMethodList;
27 class MAuthReply;
28 struct MMonMap;
29 struct MMonSubscribeAck;
30 struct MMonGetVersionReply;
31 struct MMonCommandAck;
32 struct MLogAck;
33 struct MConfig;
34
35 namespace ceph::mon {
36
37 class Connection;
38
39 class Client : public ceph::net::Dispatcher {
40 EntityName entity_name;
41 KeyRing keyring;
42 std::unique_ptr<AuthMethodList> auth_methods;
43 const uint32_t want_keys;
44
45 MonMap monmap;
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;
51
52 ceph::net::Messenger& msgr;
53
54 // commands
55 using get_version_t = seastar::future<version_t, version_t>;
56
57 ceph_tid_t last_version_req_id = 0;
58 std::map<ceph_tid_t, typename get_version_t::promise_type> version_reqs;
59
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;
64
65 MonSub sub;
66
67 public:
68 Client(ceph::net::Messenger& messenger);
69 Client(Client&&);
70 ~Client();
71 seastar::future<> start();
72 seastar::future<> stop();
73
74 const uuid_d& get_fsid() const {
75 return monmap.fsid;
76 }
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();
86
87 private:
88 void tick();
89
90 seastar::future<> ms_dispatch(ceph::net::ConnectionRef conn,
91 MessageRef m) override;
92 seastar::future<> ms_handle_reset(ceph::net::ConnectionRef conn) override;
93
94 seastar::future<> handle_monmap(ceph::net::ConnectionRef conn,
95 Ref<MMonMap> m);
96 seastar::future<> handle_auth_reply(ceph::net::ConnectionRef conn,
97 Ref<MAuthReply> m);
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);
103
104 private:
105 seastar::future<> load_keyring();
106 seastar::future<> authenticate();
107
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);
112 };
113
114 } // namespace ceph::mon