]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMonElection.h
79503875e264490f3b08152b0ba7d5a1dff43d38
[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 "msg/Message.h"
20 #include "mon/MonMap.h"
21 #include "mon/mon_types.h"
22
23 class MMonElection : public Message {
24
25 static const int HEAD_VERSION = 6;
26 static const int COMPAT_VERSION = 5;
27
28 public:
29 static const int OP_PROPOSE = 1;
30 static const int OP_ACK = 2;
31 static const int OP_NAK = 3;
32 static const int OP_VICTORY = 4;
33 static const char *get_opname(int o) {
34 switch (o) {
35 case OP_PROPOSE: return "propose";
36 case OP_ACK: return "ack";
37 case OP_NAK: return "nak";
38 case OP_VICTORY: return "victory";
39 default: ceph_abort(); return 0;
40 }
41 }
42
43 uuid_d fsid;
44 int32_t op;
45 epoch_t epoch;
46 bufferlist monmap_bl;
47 set<int32_t> quorum;
48 uint64_t quorum_features;
49 mon_feature_t mon_features;
50 bufferlist sharing_bl;
51 /* the following were both used in the next branch for a while
52 * on user cluster, so we've left them in for compatibility. */
53 version_t defunct_one;
54 version_t defunct_two;
55
56 MMonElection() : Message(MSG_MON_ELECTION, HEAD_VERSION, COMPAT_VERSION),
57 op(0), epoch(0),
58 quorum_features(0),
59 mon_features(0),
60 defunct_one(0),
61 defunct_two(0)
62 { }
63
64 MMonElection(int o, epoch_t e, 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),
69 defunct_one(0), defunct_two(0)
70 {
71 // encode using full feature set; we will reencode for dest later,
72 // if necessary
73 m->encode(monmap_bl, CEPH_FEATURES_ALL);
74 }
75 private:
76 ~MMonElection() override {}
77
78 public:
79 const char *get_type_name() const override { return "election"; }
80 void print(ostream& out) const override {
81 out << "election(" << fsid << " " << get_opname(op) << " " << epoch << ")";
82 }
83
84 void encode_payload(uint64_t features) override {
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
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(defunct_one, payload);
100 ::encode(defunct_two, payload);
101 ::encode(sharing_bl, payload);
102 ::encode(mon_features, payload);
103 }
104 void decode_payload() override {
105 bufferlist::iterator p = payload.begin();
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);
112 ::decode(defunct_one, p);
113 ::decode(defunct_two, p);
114 ::decode(sharing_bl, p);
115 if (header.version >= 6)
116 ::decode(mon_features, p);
117 }
118
119 };
120
121 #endif