]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMonElection.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / messages / MMonElection.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
16 #ifndef CEPH_MMONELECTION_H
17 #define CEPH_MMONELECTION_H
18
19 #include "common/ceph_releases.h"
20 #include "msg/Message.h"
21 #include "mon/MonMap.h"
22 #include "mon/mon_types.h"
23
24 class MMonElection final : public Message {
25 private:
26 static constexpr int HEAD_VERSION = 9;
27 static constexpr int COMPAT_VERSION = 5;
28
29 public:
30 static constexpr int OP_PROPOSE = 1;
31 static constexpr int OP_ACK = 2;
32 static constexpr int OP_NAK = 3;
33 static constexpr int OP_VICTORY = 4;
34 static const char *get_opname(int o) {
35 switch (o) {
36 case OP_PROPOSE: return "propose";
37 case OP_ACK: return "ack";
38 case OP_NAK: return "nak";
39 case OP_VICTORY: return "victory";
40 default: ceph_abort(); return 0;
41 }
42 }
43
44 uuid_d fsid;
45 int32_t op;
46 epoch_t epoch;
47 ceph::buffer::list monmap_bl;
48 std::set<int32_t> quorum;
49 uint64_t quorum_features;
50 mon_feature_t mon_features;
51 ceph_release_t mon_release{ceph_release_t::unknown};
52 ceph::buffer::list sharing_bl;
53 ceph::buffer::list scoring_bl;
54 uint8_t strategy;
55 std::map<std::string,std::string> metadata;
56
57 MMonElection() : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION},
58 op(0), epoch(0),
59 quorum_features(0),
60 mon_features(0),
61 strategy(0)
62 { }
63
64 MMonElection(int o, epoch_t e, const bufferlist& bl, uint8_t s, MonMap *m)
65 : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION},
66 fsid(m->fsid), op(o), epoch(e),
67 quorum_features(0),
68 mon_features(0), scoring_bl(bl), strategy(s)
69 {
70 // encode using full feature set; we will reencode for dest later,
71 // if necessary
72 m->encode(monmap_bl, CEPH_FEATURES_ALL);
73 }
74 private:
75 ~MMonElection() final {}
76
77 public:
78 std::string_view get_type_name() const override { return "election"; }
79 void print(std::ostream& out) const override {
80 out << "election(" << fsid << " " << get_opname(op)
81 << " rel " << (int)mon_release << " e" << epoch << ")";
82 }
83
84 void encode_payload(uint64_t features) override {
85 using ceph::encode;
86 if (monmap_bl.length() && (features != CEPH_FEATURES_ALL)) {
87 // reencode old-format monmap
88 MonMap t;
89 t.decode(monmap_bl);
90 monmap_bl.clear();
91 t.encode(monmap_bl, features);
92 }
93
94 encode(fsid, payload);
95 encode(op, payload);
96 encode(epoch, payload);
97 encode(monmap_bl, payload);
98 encode(quorum, payload);
99 encode(quorum_features, payload);
100 encode((version_t)0, payload); // defunct
101 encode((version_t)0, payload); // defunct
102 encode(sharing_bl, payload);
103 encode(mon_features, payload);
104 encode(metadata, payload);
105 encode(mon_release, payload);
106 encode(scoring_bl, payload);
107 encode(strategy, payload);
108 }
109 void decode_payload() override {
110 using ceph::decode;
111 auto p = payload.cbegin();
112 decode(fsid, p);
113 decode(op, p);
114 decode(epoch, p);
115 decode(monmap_bl, p);
116 decode(quorum, p);
117 decode(quorum_features, p);
118 {
119 version_t v; // defunct fields from old encoding
120 decode(v, p);
121 decode(v, p);
122 }
123 decode(sharing_bl, p);
124 if (header.version >= 6)
125 decode(mon_features, p);
126 if (header.version >= 7)
127 decode(metadata, p);
128 if (header.version >= 8)
129 decode(mon_release, p);
130 else
131 mon_release = infer_ceph_release_from_mon_features(mon_features);
132 if (header.version >= 9) {
133 decode(scoring_bl, p);
134 decode(strategy, p);
135 } else {
136 strategy = MonMap::election_strategy::CLASSIC;
137 }
138 }
139 private:
140 template<class T, typename... Args>
141 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
142 };
143
144 #endif