]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMonElection.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / messages / MMonElection.h
CommitLineData
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
f67539c2 24class MMonElection final : public Message {
11fdf7f2 25private:
f67539c2 26 static constexpr int HEAD_VERSION = 9;
11fdf7f2 27 static constexpr int COMPAT_VERSION = 5;
7c673cae
FG
28
29public:
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 }
f67539c2 43
7c673cae
FG
44 uuid_d fsid;
45 int32_t op;
46 epoch_t epoch;
f67539c2
TL
47 ceph::buffer::list monmap_bl;
48 std::set<int32_t> quorum;
7c673cae
FG
49 uint64_t quorum_features;
50 mon_feature_t mon_features;
9f95a23c 51 ceph_release_t mon_release{ceph_release_t::unknown};
f67539c2
TL
52 ceph::buffer::list sharing_bl;
53 ceph::buffer::list scoring_bl;
54 uint8_t strategy;
55 std::map<std::string,std::string> metadata;
7c673cae 56
9f95a23c 57 MMonElection() : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION},
7c673cae
FG
58 op(0), epoch(0),
59 quorum_features(0),
f67539c2
TL
60 mon_features(0),
61 strategy(0)
7c673cae
FG
62 { }
63
f67539c2 64 MMonElection(int o, epoch_t e, const bufferlist& bl, uint8_t s, MonMap *m)
9f95a23c 65 : Message{MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION},
7c673cae
FG
66 fsid(m->fsid), op(o), epoch(e),
67 quorum_features(0),
f67539c2 68 mon_features(0), scoring_bl(bl), strategy(s)
7c673cae
FG
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 }
74private:
f67539c2 75 ~MMonElection() final {}
7c673cae 76
f67539c2 77public:
11fdf7f2 78 std::string_view get_type_name() const override { return "election"; }
f67539c2 79 void print(std::ostream& out) const override {
11fdf7f2
TL
80 out << "election(" << fsid << " " << get_opname(op)
81 << " rel " << (int)mon_release << " e" << epoch << ")";
7c673cae 82 }
f67539c2 83
7c673cae 84 void encode_payload(uint64_t features) override {
11fdf7f2 85 using ceph::encode;
7c673cae
FG
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
11fdf7f2
TL
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);
f67539c2
TL
106 encode(scoring_bl, payload);
107 encode(strategy, payload);
7c673cae
FG
108 }
109 void decode_payload() override {
f67539c2 110 using ceph::decode;
11fdf7f2
TL
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);
224ce89b
WB
118 {
119 version_t v; // defunct fields from old encoding
11fdf7f2
TL
120 decode(v, p);
121 decode(v, p);
224ce89b 122 }
11fdf7f2 123 decode(sharing_bl, p);
7c673cae 124 if (header.version >= 6)
11fdf7f2 125 decode(mon_features, p);
224ce89b 126 if (header.version >= 7)
11fdf7f2
TL
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);
f67539c2
TL
132 if (header.version >= 9) {
133 decode(scoring_bl, p);
134 decode(strategy, p);
135 } else {
136 strategy = MonMap::election_strategy::CLASSIC;
137 }
7c673cae 138 }
9f95a23c
TL
139private:
140 template<class T, typename... Args>
20effc67 141 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
7c673cae
FG
142};
143
144#endif