]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MBackfillReserve.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / messages / MBackfillReserve.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 #ifndef CEPH_MBACKFILL_H
16 #define CEPH_MBACKFILL_H
17
18 #include "msg/Message.h"
19 #include "messages/MOSDPeeringOp.h"
20 #include "osd/PGPeeringEvent.h"
21
22 class MBackfillReserve : public MOSDPeeringOp {
23 private:
24 static constexpr int HEAD_VERSION = 5;
25 static constexpr int COMPAT_VERSION = 4;
26 public:
27 spg_t pgid;
28 epoch_t query_epoch;
29 enum {
30 REQUEST = 0, // primary->replica: please reserve a slot
31 GRANT = 1, // replica->primary: ok, i reserved it
32 REJECT_TOOFULL = 2, // replica->primary: too full, sorry, try again later (*)
33 RELEASE = 3, // primary->replcia: release the slot i reserved before
34 REVOKE_TOOFULL = 4, // replica->primary: too full, stop backfilling
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
37 };
38 uint32_t type;
39 uint32_t priority;
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());
65 case REJECT_TOOFULL:
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,
74 RemoteReservationRejectedTooFull());
75 case RELEASE:
76 return new PGPeeringEvent(
77 query_epoch,
78 query_epoch,
79 RemoteReservationCanceled());
80 case REVOKE_TOOFULL:
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 }
94
95 MBackfillReserve()
96 : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION},
97 query_epoch(0), type(-1), priority(-1), primary_num_bytes(0),
98 shard_num_bytes(0) {}
99 MBackfillReserve(int type,
100 spg_t pgid,
101 epoch_t query_epoch, unsigned prio = -1,
102 int64_t primary_num_bytes = 0,
103 int64_t shard_num_bytes = 0)
104 : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION},
105 pgid(pgid), query_epoch(query_epoch),
106 type(type), priority(prio), primary_num_bytes(primary_num_bytes),
107 shard_num_bytes(shard_num_bytes) {}
108
109 std::string_view get_type_name() const override {
110 return "MBackfillReserve";
111 }
112
113 void inner_print(std::ostream& out) const override {
114 switch (type) {
115 case REQUEST:
116 out << "REQUEST";
117 break;
118 case GRANT:
119 out << "GRANT";
120 break;
121 case REJECT_TOOFULL:
122 out << "REJECT_TOOFULL";
123 break;
124 case RELEASE:
125 out << "RELEASE";
126 break;
127 case REVOKE_TOOFULL:
128 out << "REVOKE_TOOFULL";
129 break;
130 case REVOKE:
131 out << "REVOKE";
132 break;
133 }
134 if (type == REQUEST) out << " prio: " << priority;
135 return;
136 }
137
138 void decode_payload() override {
139 auto p = payload.cbegin();
140 using ceph::decode;
141 decode(pgid.pgid, p);
142 decode(query_epoch, p);
143 decode(type, p);
144 decode(priority, p);
145 decode(pgid.shard, p);
146 if (header.version >= 5) {
147 decode(primary_num_bytes, p);
148 decode(shard_num_bytes, p);
149 } else {
150 primary_num_bytes = 0;
151 shard_num_bytes = 0;
152 }
153 }
154
155 void encode_payload(uint64_t features) override {
156 using ceph::encode;
157 if (!HAVE_FEATURE(features, RECOVERY_RESERVATION_2)) {
158 header.version = 3;
159 header.compat_version = 3;
160 encode(pgid.pgid, payload);
161 encode(query_epoch, payload);
162 encode((type == RELEASE || type == REVOKE_TOOFULL || type == REVOKE) ?
163 REJECT_TOOFULL : type, payload);
164 encode(priority, payload);
165 encode(pgid.shard, payload);
166 return;
167 }
168 header.version = HEAD_VERSION;
169 header.compat_version = COMPAT_VERSION;
170 encode(pgid.pgid, payload);
171 encode(query_epoch, payload);
172 encode(type, payload);
173 encode(priority, payload);
174 encode(pgid.shard, payload);
175 encode(primary_num_bytes, payload);
176 encode(shard_num_bytes, payload);
177 }
178 };
179
180 #endif