summaryrefslogtreecommitdiffstats
path: root/src/messages/MMonSync.h
blob: a9e6184bef3b91c299d008b5c1ed6e2a6d01bf1d (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
// -*- 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) 2012 Inktank, Inc.
*
* 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_MMONSYNC_H
#define CEPH_MMONSYNC_H

#include "msg/Message.h"

class MMonSync : public Message {
private:
  static constexpr int HEAD_VERSION = 2;
  static constexpr int COMPAT_VERSION = 2;

public:
  /**
  * Operation types
  */
  enum {
    OP_GET_COOKIE_FULL = 1,   // -> start a session (full scan)
    OP_GET_COOKIE_RECENT = 2, // -> start a session (only recent paxos events)
    OP_COOKIE = 3,            // <- pass the iterator cookie, or
    OP_GET_CHUNK = 4,         // -> get some keys
    OP_CHUNK = 5,             // <- return some keys
    OP_LAST_CHUNK = 6,        // <- return the last set of keys
    OP_NO_COOKIE = 8,         // <- sorry, no cookie
  };

  /**
  * Obtain a string corresponding to the operation type @p op
  *
  * @param op Operation type
  * @returns A string
  */
  static const char *get_opname(int op) {
    switch (op) {
    case OP_GET_COOKIE_FULL: return "get_cookie_full";
    case OP_GET_COOKIE_RECENT: return "get_cookie_recent";
    case OP_COOKIE: return "cookie";
    case OP_GET_CHUNK: return "get_chunk";
    case OP_CHUNK: return "chunk";
    case OP_LAST_CHUNK: return "last_chunk";
    case OP_NO_COOKIE: return "no_cookie";
    default: ceph_abort_msg("unknown op type"); return NULL;
    }
  }

  uint32_t op = 0;
  uint64_t cookie = 0;
  version_t last_committed = 0;
  std::pair<std::string,std::string> last_key;
  ceph::buffer::list chunk_bl;
  entity_inst_t reply_to;

  MMonSync()
    : Message{MSG_MON_SYNC, HEAD_VERSION, COMPAT_VERSION}
  { }

  MMonSync(uint32_t op, uint64_t c = 0)
    : Message{MSG_MON_SYNC, HEAD_VERSION, COMPAT_VERSION},
      op(op),
      cookie(c),
      last_committed(0)
  { }

  std::string_view get_type_name() const override { return "mon_sync"; }

  void print(std::ostream& out) const override {
    out << "mon_sync(" << get_opname(op);
    if (cookie)
      out << " cookie " << cookie;
    if (last_committed > 0)
      out << " lc " << last_committed;
    if (chunk_bl.length())
      out << " bl " << chunk_bl.length() << " bytes";
    if (!last_key.first.empty() || !last_key.second.empty())
      out << " last_key " << last_key.first << "," << last_key.second;
    out << ")";
  }

  void encode_payload(uint64_t features) override {
    using ceph::encode;
    encode(op, payload);
    encode(cookie, payload);
    encode(last_committed, payload);
    encode(last_key.first, payload);
    encode(last_key.second, payload);
    encode(chunk_bl, payload);
    encode(reply_to, payload, features);
  }

  void decode_payload() override {
    using ceph::decode;
    auto p = payload.cbegin();
    decode(op, p);
    decode(cookie, p);
    decode(last_committed, p);
    decode(last_key.first, p);
    decode(last_key.second, p);
    decode(chunk_bl, p);
    decode(reply_to, p);
  }
private:
  template<class T, typename... Args>
  friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
};

#endif /* CEPH_MMONSYNC_H */