]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
9f95a23c | 19 | #include "common/ceph_releases.h" |
7c673cae FG |
20 | #include "msg/Message.h" |
21 | #include "mon/MonMap.h" | |
22 | #include "mon/mon_types.h" | |
23 | ||
9f95a23c | 24 | class MMonElection : public Message { |
11fdf7f2 TL |
25 | private: |
26 | static constexpr int HEAD_VERSION = 8; | |
27 | static constexpr int COMPAT_VERSION = 5; | |
7c673cae FG |
28 | |
29 | public: | |
11fdf7f2 TL |
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; | |
7c673cae FG |
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 | bufferlist monmap_bl; | |
48 | set<int32_t> quorum; | |
49 | uint64_t quorum_features; | |
50 | mon_feature_t mon_features; | |
9f95a23c | 51 | ceph_release_t mon_release{ceph_release_t::unknown}; |
7c673cae | 52 | bufferlist sharing_bl; |
224ce89b | 53 | map<string,string> metadata; |
7c673cae | 54 | |
9f95a23c | 55 | MMonElection() : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION}, |
7c673cae FG |
56 | op(0), epoch(0), |
57 | quorum_features(0), | |
224ce89b | 58 | mon_features(0) |
7c673cae FG |
59 | { } |
60 | ||
61 | MMonElection(int o, epoch_t e, MonMap *m) | |
9f95a23c | 62 | : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION}, |
7c673cae FG |
63 | fsid(m->fsid), op(o), epoch(e), |
64 | quorum_features(0), | |
224ce89b | 65 | mon_features(0) |
7c673cae FG |
66 | { |
67 | // encode using full feature set; we will reencode for dest later, | |
68 | // if necessary | |
69 | m->encode(monmap_bl, CEPH_FEATURES_ALL); | |
70 | } | |
71 | private: | |
72 | ~MMonElection() override {} | |
73 | ||
74 | public: | |
11fdf7f2 | 75 | std::string_view get_type_name() const override { return "election"; } |
7c673cae | 76 | void print(ostream& out) const override { |
11fdf7f2 TL |
77 | out << "election(" << fsid << " " << get_opname(op) |
78 | << " rel " << (int)mon_release << " e" << epoch << ")"; | |
7c673cae FG |
79 | } |
80 | ||
81 | void encode_payload(uint64_t features) override { | |
11fdf7f2 | 82 | using ceph::encode; |
7c673cae FG |
83 | if (monmap_bl.length() && (features != CEPH_FEATURES_ALL)) { |
84 | // reencode old-format monmap | |
85 | MonMap t; | |
86 | t.decode(monmap_bl); | |
87 | monmap_bl.clear(); | |
88 | t.encode(monmap_bl, features); | |
89 | } | |
90 | ||
11fdf7f2 TL |
91 | encode(fsid, payload); |
92 | encode(op, payload); | |
93 | encode(epoch, payload); | |
94 | encode(monmap_bl, payload); | |
95 | encode(quorum, payload); | |
96 | encode(quorum_features, payload); | |
97 | encode((version_t)0, payload); // defunct | |
98 | encode((version_t)0, payload); // defunct | |
99 | encode(sharing_bl, payload); | |
100 | encode(mon_features, payload); | |
101 | encode(metadata, payload); | |
102 | encode(mon_release, payload); | |
7c673cae FG |
103 | } |
104 | void decode_payload() override { | |
11fdf7f2 TL |
105 | auto p = payload.cbegin(); |
106 | decode(fsid, p); | |
107 | decode(op, p); | |
108 | decode(epoch, p); | |
109 | decode(monmap_bl, p); | |
110 | decode(quorum, p); | |
111 | decode(quorum_features, p); | |
224ce89b WB |
112 | { |
113 | version_t v; // defunct fields from old encoding | |
11fdf7f2 TL |
114 | decode(v, p); |
115 | decode(v, p); | |
224ce89b | 116 | } |
11fdf7f2 | 117 | decode(sharing_bl, p); |
7c673cae | 118 | if (header.version >= 6) |
11fdf7f2 | 119 | decode(mon_features, p); |
224ce89b | 120 | if (header.version >= 7) |
11fdf7f2 TL |
121 | decode(metadata, p); |
122 | if (header.version >= 8) | |
123 | decode(mon_release, p); | |
124 | else | |
125 | mon_release = infer_ceph_release_from_mon_features(mon_features); | |
7c673cae | 126 | } |
9f95a23c TL |
127 | private: |
128 | template<class T, typename... Args> | |
129 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
7c673cae FG |
130 | }; |
131 | ||
132 | #endif |