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