]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MBackfillReserve.h
update sources to ceph Nautilus 14.2.1
[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
21 class MBackfillReserve : public MessageInstance<MBackfillReserve, MOSDPeeringOp> {
22 public:
23 friend factory;
24 private:
25 static constexpr int HEAD_VERSION = 5;
26 static constexpr int COMPAT_VERSION = 4;
27 public:
28 spg_t pgid;
29 epoch_t query_epoch;
30 enum {
31 REQUEST = 0, // primary->replica: please reserve a slot
32 GRANT = 1, // replica->primary: ok, i reserved it
33 REJECT = 2, // replica->primary: sorry, try again later (*)
34 RELEASE = 3, // primary->replcia: release the slot i reserved before
35 TOOFULL = 4, // replica->primary: too full, stop backfilling
36 REVOKE = 5, // replica->primary: i'm taking back the slot i gave you
37 // (*) NOTE: prior to luminous, REJECT was overloaded to also mean release
38 };
39 uint32_t type;
40 uint32_t priority;
41 int64_t primary_num_bytes;
42 int64_t shard_num_bytes;
43
44 spg_t get_spg() const {
45 return pgid;
46 }
47 epoch_t get_map_epoch() const {
48 return query_epoch;
49 }
50 epoch_t get_min_epoch() const {
51 return query_epoch;
52 }
53
54 PGPeeringEvent *get_event() override {
55 switch (type) {
56 case REQUEST:
57 return new PGPeeringEvent(
58 query_epoch,
59 query_epoch,
60 RequestBackfillPrio(priority, primary_num_bytes, shard_num_bytes));
61 case GRANT:
62 return new PGPeeringEvent(
63 query_epoch,
64 query_epoch,
65 RemoteBackfillReserved());
66 case REJECT:
67 // NOTE: this is replica -> primary "i reject your request"
68 // and also primary -> replica "cancel my previously-granted request"
69 // (for older peers)
70 // and also replica -> primary "i revoke your reservation"
71 // (for older peers)
72 return new PGPeeringEvent(
73 query_epoch,
74 query_epoch,
75 RemoteReservationRejected());
76 case RELEASE:
77 return new PGPeeringEvent(
78 query_epoch,
79 query_epoch,
80 RemoteReservationCanceled());
81 case TOOFULL:
82 return new PGPeeringEvent(
83 query_epoch,
84 query_epoch,
85 RemoteReservationRevokedTooFull());
86 case REVOKE:
87 return new PGPeeringEvent(
88 query_epoch,
89 query_epoch,
90 RemoteReservationRevoked());
91 default:
92 ceph_abort();
93 }
94 }
95
96 MBackfillReserve()
97 : MessageInstance(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
98 query_epoch(0), type(-1), priority(-1), primary_num_bytes(0),
99 shard_num_bytes(0) {}
100 MBackfillReserve(int type,
101 spg_t pgid,
102 epoch_t query_epoch, unsigned prio = -1,
103 int64_t primary_num_bytes = 0,
104 int64_t shard_num_bytes = 0)
105 : MessageInstance(MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION),
106 pgid(pgid), query_epoch(query_epoch),
107 type(type), priority(prio), primary_num_bytes(primary_num_bytes),
108 shard_num_bytes(shard_num_bytes) {}
109
110 std::string_view get_type_name() const override {
111 return "MBackfillReserve";
112 }
113
114 void inner_print(ostream& out) const override {
115 switch (type) {
116 case REQUEST:
117 out << "REQUEST";
118 break;
119 case GRANT:
120 out << "GRANT";
121 break;
122 case REJECT:
123 out << "REJECT ";
124 break;
125 case RELEASE:
126 out << "RELEASE";
127 break;
128 case TOOFULL:
129 out << "TOOFULL";
130 break;
131 case REVOKE:
132 out << "REVOKE";
133 break;
134 }
135 if (type == REQUEST) out << " prio: " << priority;
136 return;
137 }
138
139 void decode_payload() override {
140 auto p = payload.cbegin();
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 == TOOFULL || type == REVOKE) ?
163 REJECT : 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