summaryrefslogtreecommitdiffstats
path: root/src/messages/MMonPaxos.h
blob: 8c709ddb8e60ed467b037210062aca87b81aa2ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */


#ifndef CEPH_MMONPAXOS_H
#define CEPH_MMONPAXOS_H

#include "messages/PaxosServiceMessage.h"
#include "mon/mon_types.h"
#include "include/ceph_features.h"

class MMonPaxos : public Message {

  static const int HEAD_VERSION = 3;
  static const int COMPAT_VERSION = 3;

 public:
  // op types
  const static int OP_COLLECT =   1; // proposer: propose round
  const static int OP_LAST =      2; // voter:    accept proposed round
  const static int OP_BEGIN =     3; // proposer: value proposed for this round
  const static int OP_ACCEPT =    4; // voter:    accept propsed value
  const static int OP_COMMIT =    5; // proposer: notify learners of agreed value
  const static int OP_LEASE =     6; // leader: extend peon lease
  const static int OP_LEASE_ACK = 7; // peon: lease ack
  const static char *get_opname(int op) {
    switch (op) {
    case OP_COLLECT: return "collect";
    case OP_LAST: return "last";
    case OP_BEGIN: return "begin";
    case OP_ACCEPT: return "accept";
    case OP_COMMIT: return "commit";
    case OP_LEASE: return "lease";
    case OP_LEASE_ACK: return "lease_ack";
    default: ceph_abort(); return 0;
    }
  }

  epoch_t epoch;   // monitor epoch
  __s32 op;          // paxos op

  version_t first_committed;  // i've committed to
  version_t last_committed;  // i've committed to
  version_t pn_from;         // i promise to accept after
  version_t pn;              // with with proposal
  version_t uncommitted_pn;     // previous pn, if we are a LAST with an uncommitted value
  utime_t lease_timestamp;
  utime_t sent_timestamp;

  version_t latest_version;
  bufferlist latest_value;

  map<version_t,bufferlist> values;

  MMonPaxos() : Message(MSG_MON_PAXOS, HEAD_VERSION, COMPAT_VERSION) { }
  MMonPaxos(epoch_t e, int o, utime_t now) : 
    Message(MSG_MON_PAXOS, HEAD_VERSION, COMPAT_VERSION),
    epoch(e),
    op(o),
    first_committed(0), last_committed(0), pn_from(0), pn(0), uncommitted_pn(0),
    sent_timestamp(now),
    latest_version(0) {
  }

private:
  ~MMonPaxos() override {}

public:  
  const char *get_type_name() const override { return "paxos"; }
  
  void print(ostream& out) const override {
    out << "paxos(" << get_opname(op) 
	<< " lc " << last_committed
	<< " fc " << first_committed
	<< " pn " << pn << " opn " << uncommitted_pn;
    if (latest_version)
      out << " latest " << latest_version << " (" << latest_value.length() << " bytes)";
    out <<  ")";
  }

  void encode_payload(uint64_t features) override {
    header.version = HEAD_VERSION;
    ::encode(epoch, payload);
    ::encode(op, payload);
    ::encode(first_committed, payload);
    ::encode(last_committed, payload);
    ::encode(pn_from, payload);
    ::encode(pn, payload);
    ::encode(uncommitted_pn, payload);
    ::encode(lease_timestamp, payload);
    ::encode(sent_timestamp, payload);
    ::encode(latest_version, payload);
    ::encode(latest_value, payload);
    ::encode(values, payload);
  }
  void decode_payload() override {
    bufferlist::iterator p = payload.begin();
    ::decode(epoch, p);
    ::decode(op, p);
    ::decode(first_committed, p);
    ::decode(last_committed, p);
    ::decode(pn_from, p);   
    ::decode(pn, p);   
    ::decode(uncommitted_pn, p);
    ::decode(lease_timestamp, p);
    ::decode(sent_timestamp, p);
    ::decode(latest_version, p);
    ::decode(latest_value, p);
    ::decode(values, p);
  }
};

#endif