]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMonJoin.h
cf662f514187d9b7d732a2946069afc96aede506
[ceph.git] / ceph / src / messages / MMonJoin.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
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.
12 *
13 */
14
15 #ifndef CEPH_MMONJOIN_H
16 #define CEPH_MMONJOIN_H
17
18 #include "messages/PaxosServiceMessage.h"
19
20 class MMonJoin final : public PaxosServiceMessage {
21 public:
22 static constexpr int HEAD_VERSION = 3;
23 static constexpr int COMPAT_VERSION = 2;
24
25 uuid_d fsid;
26 std::string name;
27 entity_addrvec_t addrs;
28 /* The location members are for stretch mode. crush_loc is the location
29 * (generally just a "datacenter=<foo>" statement) of the monitor. The
30 * force_loc is whether the mon cluster should replace a previously-known
31 * location. Generally the monitor will force an update if it's given a
32 * location from the CLI on boot-up, and then never force again (so that it
33 * can be moved/updated via the ceph tool from elsewhere). */
34 map<string,string> crush_loc;
35 bool force_loc{false};
36
37 MMonJoin() : PaxosServiceMessage{MSG_MON_JOIN, 0, HEAD_VERSION, COMPAT_VERSION} {}
38 MMonJoin(uuid_d &f, std::string n, const entity_addrvec_t& av)
39 : PaxosServiceMessage{MSG_MON_JOIN, 0, HEAD_VERSION, COMPAT_VERSION},
40 fsid(f), name(n), addrs(av)
41 { }
42 MMonJoin(uuid_d &f, std::string n, const entity_addrvec_t& av, const map<string,string>& cloc, bool force)
43 : PaxosServiceMessage{MSG_MON_JOIN, 0, HEAD_VERSION, COMPAT_VERSION},
44 fsid(f), name(n), addrs(av), crush_loc(cloc), force_loc(force)
45 { }
46
47 private:
48 ~MMonJoin() final {}
49
50 public:
51 std::string_view get_type_name() const override { return "mon_join"; }
52 void print(std::ostream& o) const override {
53 o << "mon_join(" << name << " " << addrs << " " << crush_loc << ")";
54 }
55
56 void encode_payload(uint64_t features) override {
57 using ceph::encode;
58 paxos_encode();
59 encode(fsid, payload);
60 encode(name, payload);
61 if (HAVE_FEATURE(features, SERVER_NAUTILUS)) {
62 header.version = HEAD_VERSION;
63 header.compat_version = COMPAT_VERSION;
64 encode(addrs, payload, features);
65 encode(crush_loc, payload);
66 encode(force_loc, payload);
67 } else {
68 header.version = 1;
69 header.compat_version = 1;
70 encode(addrs.legacy_addr(), payload, features);
71 }
72 }
73 void decode_payload() override {
74 using ceph::decode;
75 auto p = payload.cbegin();
76 paxos_decode(p);
77 decode(fsid, p);
78 decode(name, p);
79 if (header.version == 1) {
80 entity_addr_t addr;
81 decode(addr, p);
82 addrs = entity_addrvec_t(addr);
83 } else {
84 decode(addrs, p);
85 if (header.version >= 3) {
86 decode(crush_loc, p);
87 decode(force_loc, p);
88 }
89 }
90 }
91 };
92
93 #endif