]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMonPaxos.h
4b21ee38a0ba910ff65183956372ad5e1eb47454
[ceph.git] / ceph / src / messages / MMonPaxos.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_MMONPAXOS_H
17 #define CEPH_MMONPAXOS_H
18
19 #include "messages/PaxosServiceMessage.h"
20 #include "mon/mon_types.h"
21 #include "include/ceph_features.h"
22
23 class MMonPaxos : public Message {
24
25 static const int HEAD_VERSION = 4;
26 static const int COMPAT_VERSION = 3;
27
28 public:
29 // op types
30 const static int OP_COLLECT = 1; // proposer: propose round
31 const static int OP_LAST = 2; // voter: accept proposed round
32 const static int OP_BEGIN = 3; // proposer: value proposed for this round
33 const static int OP_ACCEPT = 4; // voter: accept propsed value
34 const static int OP_COMMIT = 5; // proposer: notify learners of agreed value
35 const static int OP_LEASE = 6; // leader: extend peon lease
36 const static int OP_LEASE_ACK = 7; // peon: lease ack
37 const static char *get_opname(int op) {
38 switch (op) {
39 case OP_COLLECT: return "collect";
40 case OP_LAST: return "last";
41 case OP_BEGIN: return "begin";
42 case OP_ACCEPT: return "accept";
43 case OP_COMMIT: return "commit";
44 case OP_LEASE: return "lease";
45 case OP_LEASE_ACK: return "lease_ack";
46 default: ceph_abort(); return 0;
47 }
48 }
49
50 epoch_t epoch; // monitor epoch
51 __s32 op; // paxos op
52
53 version_t first_committed; // i've committed to
54 version_t last_committed; // i've committed to
55 version_t pn_from; // i promise to accept after
56 version_t pn; // with with proposal
57 version_t uncommitted_pn; // previous pn, if we are a LAST with an uncommitted value
58 utime_t lease_timestamp;
59 utime_t sent_timestamp;
60
61 version_t latest_version;
62 bufferlist latest_value;
63
64 map<version_t,bufferlist> values;
65
66 bufferlist feature_map;
67
68 MMonPaxos() : Message(MSG_MON_PAXOS, HEAD_VERSION, COMPAT_VERSION) { }
69 MMonPaxos(epoch_t e, int o, utime_t now) :
70 Message(MSG_MON_PAXOS, HEAD_VERSION, COMPAT_VERSION),
71 epoch(e),
72 op(o),
73 first_committed(0), last_committed(0), pn_from(0), pn(0), uncommitted_pn(0),
74 sent_timestamp(now),
75 latest_version(0) {
76 }
77
78 private:
79 ~MMonPaxos() override {}
80
81 public:
82 const char *get_type_name() const override { return "paxos"; }
83
84 void print(ostream& out) const override {
85 out << "paxos(" << get_opname(op)
86 << " lc " << last_committed
87 << " fc " << first_committed
88 << " pn " << pn << " opn " << uncommitted_pn;
89 if (latest_version)
90 out << " latest " << latest_version << " (" << latest_value.length() << " bytes)";
91 out << ")";
92 }
93
94 void encode_payload(uint64_t features) override {
95 header.version = HEAD_VERSION;
96 ::encode(epoch, payload);
97 ::encode(op, payload);
98 ::encode(first_committed, payload);
99 ::encode(last_committed, payload);
100 ::encode(pn_from, payload);
101 ::encode(pn, payload);
102 ::encode(uncommitted_pn, payload);
103 ::encode(lease_timestamp, payload);
104 ::encode(sent_timestamp, payload);
105 ::encode(latest_version, payload);
106 ::encode(latest_value, payload);
107 ::encode(values, payload);
108 ::encode(feature_map, payload);
109 }
110 void decode_payload() override {
111 bufferlist::iterator p = payload.begin();
112 ::decode(epoch, p);
113 ::decode(op, p);
114 ::decode(first_committed, p);
115 ::decode(last_committed, p);
116 ::decode(pn_from, p);
117 ::decode(pn, p);
118 ::decode(uncommitted_pn, p);
119 ::decode(lease_timestamp, p);
120 ::decode(sent_timestamp, p);
121 ::decode(latest_version, p);
122 ::decode(latest_value, p);
123 ::decode(values, p);
124 if (header.version >= 4) {
125 ::decode(feature_map, p);
126 }
127 }
128 };
129
130 #endif