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 "msg/Message.h"
20 #include "mon/MonMap.h"
21 #include "mon/mon_types.h"
23 class MMonElection
: public Message
{
25 static const int HEAD_VERSION
= 6;
26 static const int COMPAT_VERSION
= 5;
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
) {
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;
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
;
56 MMonElection() : Message(MSG_MON_ELECTION
, HEAD_VERSION
, COMPAT_VERSION
),
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
),
69 defunct_one(0), defunct_two(0)
71 // encode using full feature set; we will reencode for dest later,
73 m
->encode(monmap_bl
, CEPH_FEATURES_ALL
);
76 ~MMonElection() override
{}
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
<< ")";
84 void encode_payload(uint64_t features
) override
{
85 if (monmap_bl
.length() && (features
!= CEPH_FEATURES_ALL
)) {
86 // reencode old-format monmap
90 t
.encode(monmap_bl
, features
);
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
);
104 void decode_payload() override
{
105 bufferlist::iterator p
= payload
.begin();
109 ::decode(monmap_bl
, 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
);