1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_MMONELECTION_H
17 #define CEPH_MMONELECTION_H
19 #include "common/ceph_releases.h"
20 #include "msg/Message.h"
21 #include "mon/MonMap.h"
22 #include "mon/mon_types.h"
24 class MMonElection final
: public Message
{
26 static constexpr int HEAD_VERSION
= 9;
27 static constexpr int COMPAT_VERSION
= 5;
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
) {
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;
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
;
55 std::map
<std::string
,std::string
> metadata
;
57 MMonElection() : Message
{MSG_MON_ELECTION
, HEAD_VERSION
, COMPAT_VERSION
},
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
),
68 mon_features(0), scoring_bl(bl
), strategy(s
)
70 // encode using full feature set; we will reencode for dest later,
72 m
->encode(monmap_bl
, CEPH_FEATURES_ALL
);
75 ~MMonElection() final
{}
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
<< ")";
84 void encode_payload(uint64_t features
) override
{
86 if (monmap_bl
.length() && (features
!= CEPH_FEATURES_ALL
)) {
87 // reencode old-format monmap
91 t
.encode(monmap_bl
, features
);
94 encode(fsid
, 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
);
109 void decode_payload() override
{
111 auto p
= payload
.cbegin();
115 decode(monmap_bl
, p
);
117 decode(quorum_features
, p
);
119 version_t v
; // defunct fields from old encoding
123 decode(sharing_bl
, p
);
124 if (header
.version
>= 6)
125 decode(mon_features
, p
);
126 if (header
.version
>= 7)
128 if (header
.version
>= 8)
129 decode(mon_release
, p
);
131 mon_release
= infer_ceph_release_from_mon_features(mon_features
);
132 if (header
.version
>= 9) {
133 decode(scoring_bl
, p
);
136 strategy
= MonMap::election_strategy::CLASSIC
;
140 template<class T
, typename
... Args
>
141 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);