]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 2012 Inktank, Inc. | |
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 | #ifndef CEPH_MMONSYNC_H | |
14 | #define CEPH_MMONSYNC_H | |
15 | ||
16 | #include "msg/Message.h" | |
17 | ||
9f95a23c | 18 | class MMonSync : public Message { |
11fdf7f2 TL |
19 | private: |
20 | static constexpr int HEAD_VERSION = 2; | |
21 | static constexpr int COMPAT_VERSION = 2; | |
7c673cae FG |
22 | |
23 | public: | |
24 | /** | |
25 | * Operation types | |
26 | */ | |
27 | enum { | |
28 | OP_GET_COOKIE_FULL = 1, // -> start a session (full scan) | |
29 | OP_GET_COOKIE_RECENT = 2, // -> start a session (only recent paxos events) | |
30 | OP_COOKIE = 3, // <- pass the iterator cookie, or | |
31 | OP_GET_CHUNK = 4, // -> get some keys | |
32 | OP_CHUNK = 5, // <- return some keys | |
33 | OP_LAST_CHUNK = 6, // <- return the last set of keys | |
34 | OP_NO_COOKIE = 8, // <- sorry, no cookie | |
35 | }; | |
36 | ||
37 | /** | |
38 | * Obtain a string corresponding to the operation type @p op | |
39 | * | |
40 | * @param op Operation type | |
41 | * @returns A string | |
42 | */ | |
43 | static const char *get_opname(int op) { | |
44 | switch (op) { | |
45 | case OP_GET_COOKIE_FULL: return "get_cookie_full"; | |
46 | case OP_GET_COOKIE_RECENT: return "get_cookie_recent"; | |
47 | case OP_COOKIE: return "cookie"; | |
48 | case OP_GET_CHUNK: return "get_chunk"; | |
49 | case OP_CHUNK: return "chunk"; | |
50 | case OP_LAST_CHUNK: return "last_chunk"; | |
51 | case OP_NO_COOKIE: return "no_cookie"; | |
11fdf7f2 | 52 | default: ceph_abort_msg("unknown op type"); return NULL; |
7c673cae FG |
53 | } |
54 | } | |
55 | ||
d2e6a577 FG |
56 | uint32_t op = 0; |
57 | uint64_t cookie = 0; | |
58 | version_t last_committed = 0; | |
f67539c2 TL |
59 | std::pair<std::string,std::string> last_key; |
60 | ceph::buffer::list chunk_bl; | |
7c673cae FG |
61 | entity_inst_t reply_to; |
62 | ||
63 | MMonSync() | |
9f95a23c | 64 | : Message{MSG_MON_SYNC, HEAD_VERSION, COMPAT_VERSION} |
7c673cae FG |
65 | { } |
66 | ||
67 | MMonSync(uint32_t op, uint64_t c = 0) | |
9f95a23c | 68 | : Message{MSG_MON_SYNC, HEAD_VERSION, COMPAT_VERSION}, |
7c673cae FG |
69 | op(op), |
70 | cookie(c), | |
71 | last_committed(0) | |
72 | { } | |
73 | ||
11fdf7f2 | 74 | std::string_view get_type_name() const override { return "mon_sync"; } |
7c673cae | 75 | |
f67539c2 | 76 | void print(std::ostream& out) const override { |
7c673cae FG |
77 | out << "mon_sync(" << get_opname(op); |
78 | if (cookie) | |
79 | out << " cookie " << cookie; | |
80 | if (last_committed > 0) | |
81 | out << " lc " << last_committed; | |
82 | if (chunk_bl.length()) | |
83 | out << " bl " << chunk_bl.length() << " bytes"; | |
84 | if (!last_key.first.empty() || !last_key.second.empty()) | |
85 | out << " last_key " << last_key.first << "," << last_key.second; | |
86 | out << ")"; | |
87 | } | |
88 | ||
89 | void encode_payload(uint64_t features) override { | |
11fdf7f2 TL |
90 | using ceph::encode; |
91 | encode(op, payload); | |
92 | encode(cookie, payload); | |
93 | encode(last_committed, payload); | |
94 | encode(last_key.first, payload); | |
95 | encode(last_key.second, payload); | |
96 | encode(chunk_bl, payload); | |
97 | encode(reply_to, payload, features); | |
7c673cae FG |
98 | } |
99 | ||
100 | void decode_payload() override { | |
f67539c2 | 101 | using ceph::decode; |
11fdf7f2 TL |
102 | auto p = payload.cbegin(); |
103 | decode(op, p); | |
104 | decode(cookie, p); | |
105 | decode(last_committed, p); | |
106 | decode(last_key.first, p); | |
107 | decode(last_key.second, p); | |
108 | decode(chunk_bl, p); | |
109 | decode(reply_to, p); | |
7c673cae | 110 | } |
9f95a23c TL |
111 | private: |
112 | template<class T, typename... Args> | |
113 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
7c673cae FG |
114 | }; |
115 | ||
116 | #endif /* CEPH_MMONSYNC_H */ |