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