]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MBackfillReserve.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / messages / MBackfillReserve.h
CommitLineData
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 22class MBackfillReserve : public MOSDPeeringOp {
11fdf7f2
TL
23private:
24 static constexpr int HEAD_VERSION = 5;
25 static constexpr int COMPAT_VERSION = 4;
7c673cae
FG
26public:
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
f67539c2 113 void inner_print(std::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 139 auto p = payload.cbegin();
f67539c2 140 using ceph::decode;
11fdf7f2
TL
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 }
7c673cae
FG
153 }
154
155 void encode_payload(uint64_t features) override {
11fdf7f2
TL
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);
eafe8130
TL
162 encode((type == RELEASE || type == REVOKE_TOOFULL || type == REVOKE) ?
163 REJECT_TOOFULL : type, payload);
11fdf7f2
TL
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);
7c673cae
FG
177 }
178};
179
180#endif