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
= 7;
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 map
<string
,string
> metadata
;
53 MMonElection() : Message(MSG_MON_ELECTION
, HEAD_VERSION
, COMPAT_VERSION
),
59 MMonElection(int o
, epoch_t e
, MonMap
*m
)
60 : Message(MSG_MON_ELECTION
, HEAD_VERSION
, COMPAT_VERSION
),
61 fsid(m
->fsid
), op(o
), epoch(e
),
65 // encode using full feature set; we will reencode for dest later,
67 m
->encode(monmap_bl
, CEPH_FEATURES_ALL
);
70 ~MMonElection() override
{}
73 const char *get_type_name() const override
{ return "election"; }
74 void print(ostream
& out
) const override
{
75 out
<< "election(" << fsid
<< " " << get_opname(op
) << " " << epoch
<< ")";
78 void encode_payload(uint64_t features
) override
{
79 if (monmap_bl
.length() && (features
!= CEPH_FEATURES_ALL
)) {
80 // reencode old-format monmap
84 t
.encode(monmap_bl
, features
);
87 ::encode(fsid
, payload
);
88 ::encode(op
, payload
);
89 ::encode(epoch
, payload
);
90 ::encode(monmap_bl
, payload
);
91 ::encode(quorum
, payload
);
92 ::encode(quorum_features
, payload
);
93 ::encode((version_t
)0, payload
); // defunct
94 ::encode((version_t
)0, payload
); // defunct
95 ::encode(sharing_bl
, payload
);
96 ::encode(mon_features
, payload
);
97 ::encode(metadata
, payload
);
99 void decode_payload() override
{
100 bufferlist::iterator p
= payload
.begin();
104 ::decode(monmap_bl
, p
);
106 ::decode(quorum_features
, p
);
108 version_t v
; // defunct fields from old encoding
112 ::decode(sharing_bl
, p
);
113 if (header
.version
>= 6)
114 ::decode(mon_features
, p
);
115 if (header
.version
>= 7)
116 ::decode(metadata
, p
);