]>
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) 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 | #ifndef CEPH_MBACKFILL_H | |
16 | #define CEPH_MBACKFILL_H | |
17 | ||
18 | #include "msg/Message.h" | |
11fdf7f2 | 19 | #include "messages/MOSDPeeringOp.h" |
9f95a23c | 20 | #include "osd/PGPeeringEvent.h" |
7c673cae | 21 | |
9f95a23c | 22 | class MBackfillReserve : public MOSDPeeringOp { |
11fdf7f2 TL |
23 | private: |
24 | static constexpr int HEAD_VERSION = 5; | |
25 | static constexpr int COMPAT_VERSION = 4; | |
7c673cae FG |
26 | public: |
27 | spg_t pgid; | |
28 | epoch_t query_epoch; | |
29 | enum { | |
11fdf7f2 TL |
30 | REQUEST = 0, // primary->replica: please reserve a slot |
31 | GRANT = 1, // replica->primary: ok, i reserved it | |
eafe8130 | 32 | REJECT_TOOFULL = 2, // replica->primary: too full, sorry, try again later (*) |
11fdf7f2 | 33 | RELEASE = 3, // primary->replcia: release the slot i reserved before |
eafe8130 | 34 | REVOKE_TOOFULL = 4, // replica->primary: too full, stop backfilling |
11fdf7f2 TL |
35 | REVOKE = 5, // replica->primary: i'm taking back the slot i gave you |
36 | // (*) NOTE: prior to luminous, REJECT was overloaded to also mean release | |
7c673cae FG |
37 | }; |
38 | uint32_t type; | |
39 | uint32_t priority; | |
11fdf7f2 TL |
40 | int64_t primary_num_bytes; |
41 | int64_t shard_num_bytes; | |
42 | ||
43 | spg_t get_spg() const { | |
44 | return pgid; | |
45 | } | |
46 | epoch_t get_map_epoch() const { | |
47 | return query_epoch; | |
48 | } | |
49 | epoch_t get_min_epoch() const { | |
50 | return query_epoch; | |
51 | } | |
52 | ||
53 | PGPeeringEvent *get_event() override { | |
54 | switch (type) { | |
55 | case REQUEST: | |
56 | return new PGPeeringEvent( | |
57 | query_epoch, | |
58 | query_epoch, | |
59 | RequestBackfillPrio(priority, primary_num_bytes, shard_num_bytes)); | |
60 | case GRANT: | |
61 | return new PGPeeringEvent( | |
62 | query_epoch, | |
63 | query_epoch, | |
64 | RemoteBackfillReserved()); | |
eafe8130 | 65 | case REJECT_TOOFULL: |
11fdf7f2 TL |
66 | // NOTE: this is replica -> primary "i reject your request" |
67 | // and also primary -> replica "cancel my previously-granted request" | |
68 | // (for older peers) | |
69 | // and also replica -> primary "i revoke your reservation" | |
70 | // (for older peers) | |
71 | return new PGPeeringEvent( | |
72 | query_epoch, | |
73 | query_epoch, | |
eafe8130 | 74 | RemoteReservationRejectedTooFull()); |
11fdf7f2 TL |
75 | case RELEASE: |
76 | return new PGPeeringEvent( | |
77 | query_epoch, | |
78 | query_epoch, | |
79 | RemoteReservationCanceled()); | |
eafe8130 | 80 | case REVOKE_TOOFULL: |
11fdf7f2 TL |
81 | return new PGPeeringEvent( |
82 | query_epoch, | |
83 | query_epoch, | |
84 | RemoteReservationRevokedTooFull()); | |
85 | case REVOKE: | |
86 | return new PGPeeringEvent( | |
87 | query_epoch, | |
88 | query_epoch, | |
89 | RemoteReservationRevoked()); | |
90 | default: | |
91 | ceph_abort(); | |
92 | } | |
93 | } | |
7c673cae FG |
94 | |
95 | MBackfillReserve() | |
9f95a23c | 96 | : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION}, |
11fdf7f2 TL |
97 | query_epoch(0), type(-1), priority(-1), primary_num_bytes(0), |
98 | shard_num_bytes(0) {} | |
7c673cae FG |
99 | MBackfillReserve(int type, |
100 | spg_t pgid, | |
11fdf7f2 TL |
101 | epoch_t query_epoch, unsigned prio = -1, |
102 | int64_t primary_num_bytes = 0, | |
103 | int64_t shard_num_bytes = 0) | |
9f95a23c | 104 | : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION}, |
7c673cae | 105 | pgid(pgid), query_epoch(query_epoch), |
11fdf7f2 TL |
106 | type(type), priority(prio), primary_num_bytes(primary_num_bytes), |
107 | shard_num_bytes(shard_num_bytes) {} | |
7c673cae | 108 | |
11fdf7f2 | 109 | std::string_view get_type_name() const override { |
7c673cae FG |
110 | return "MBackfillReserve"; |
111 | } | |
112 | ||
11fdf7f2 | 113 | void inner_print(ostream& out) const override { |
7c673cae FG |
114 | switch (type) { |
115 | case REQUEST: | |
11fdf7f2 | 116 | out << "REQUEST"; |
7c673cae FG |
117 | break; |
118 | case GRANT: | |
11fdf7f2 | 119 | out << "GRANT"; |
7c673cae | 120 | break; |
eafe8130 TL |
121 | case REJECT_TOOFULL: |
122 | out << "REJECT_TOOFULL"; | |
7c673cae | 123 | break; |
11fdf7f2 TL |
124 | case RELEASE: |
125 | out << "RELEASE"; | |
126 | break; | |
eafe8130 TL |
127 | case REVOKE_TOOFULL: |
128 | out << "REVOKE_TOOFULL"; | |
11fdf7f2 TL |
129 | break; |
130 | case REVOKE: | |
131 | out << "REVOKE"; | |
132 | break; | |
7c673cae | 133 | } |
11fdf7f2 | 134 | if (type == REQUEST) out << " prio: " << priority; |
7c673cae FG |
135 | return; |
136 | } | |
137 | ||
138 | void decode_payload() override { | |
11fdf7f2 TL |
139 | auto p = payload.cbegin(); |
140 | decode(pgid.pgid, p); | |
141 | decode(query_epoch, p); | |
142 | decode(type, p); | |
143 | decode(priority, p); | |
144 | decode(pgid.shard, p); | |
145 | if (header.version >= 5) { | |
146 | decode(primary_num_bytes, p); | |
147 | decode(shard_num_bytes, p); | |
148 | } else { | |
149 | primary_num_bytes = 0; | |
150 | shard_num_bytes = 0; | |
151 | } | |
7c673cae FG |
152 | } |
153 | ||
154 | void encode_payload(uint64_t features) override { | |
11fdf7f2 TL |
155 | using ceph::encode; |
156 | if (!HAVE_FEATURE(features, RECOVERY_RESERVATION_2)) { | |
157 | header.version = 3; | |
158 | header.compat_version = 3; | |
159 | encode(pgid.pgid, payload); | |
160 | encode(query_epoch, payload); | |
eafe8130 TL |
161 | encode((type == RELEASE || type == REVOKE_TOOFULL || type == REVOKE) ? |
162 | REJECT_TOOFULL : type, payload); | |
11fdf7f2 TL |
163 | encode(priority, payload); |
164 | encode(pgid.shard, payload); | |
165 | return; | |
166 | } | |
167 | header.version = HEAD_VERSION; | |
168 | header.compat_version = COMPAT_VERSION; | |
169 | encode(pgid.pgid, payload); | |
170 | encode(query_epoch, payload); | |
171 | encode(type, payload); | |
172 | encode(priority, payload); | |
173 | encode(pgid.shard, payload); | |
174 | encode(primary_num_bytes, payload); | |
175 | encode(shard_num_bytes, payload); | |
7c673cae FG |
176 | } |
177 | }; | |
178 | ||
179 | #endif |